diff options
| author | ctrlcctrlv <wizardchan@hush.com> | 2013-08-08 21:08:01 +0000 |
|---|---|---|
| committer | ctrlcctrlv <wizardchan@hush.com> | 2013-08-08 21:08:01 +0000 |
| commit | ddbe562f9c3bc646fb85da0a0252eff711d050bb (patch) | |
| tree | cc54ad8e1648dc42ccc66ada885d967c2e8ccf44 /inc/mod | |
| parent | 001989876f02cd5cc2b032daeec09428d25b1786 (diff) | |
Optionally allow the moving of single replies
Diffstat (limited to 'inc/mod')
| -rw-r--r-- | inc/mod/pages.php | 97 |
1 files changed, 95 insertions, 2 deletions
diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 8b0c400e..4f876b45 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -1002,6 +1002,99 @@ function mod_bumplock($board, $unbumplock, $post) { header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); } +function mod_move_reply($originBoard, $postID) { + global $board, $config, $mod; + + if (!openBoard($originBoard)) + error($config['error']['noboard']); + + if (!hasPermission($config['mod']['move'], $originBoard)) + error($config['error']['noaccess']); + + $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `id` = :id', $originBoard)); + $query->bindValue(':id', $postID); + $query->execute() or error(db_error($query)); + if (!$post = $query->fetch(PDO::FETCH_ASSOC)) + error($config['error']['404']); + + if (isset($_POST['board'])) { + $targetBoard = $_POST['board']; + + if ($_POST['target_thread']) { + $query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `id` = :id', $targetBoard)); + $query->bindValue(':id', $_POST['target_thread']); + $query->execute() or error(db_error($query)); // If it fails, thread probably does not exist + $post['op'] = false; + $post['thread'] = $_POST['target_thread']; + } + else { + $post['op'] = true; + } + + if ($post['file']) { + $post['has_file'] = true; + $post['width'] = &$post['filewidth']; + $post['height'] = &$post['fileheight']; + + $file_src = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $post['file']; + $file_thumb = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $post['thumb']; + } else { + $post['has_file'] = false; + } + + // allow thread to keep its same traits (stickied, locked, etc.) + $post['mod'] = true; + + if (!openBoard($targetBoard)) + error($config['error']['noboard']); + + // create the new post + $newID = post($post); + + if ($post['has_file']) { + // move the image + rename($file_src, sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $post['file']); + rename($file_thumb, sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $post['thumb']); + } + + buildIndex(); + + // trigger themes + rebuildThemes($post['op'] ? 'post-thread' : 'post'); + // mod log + modLog("Moved post #${postID} to " . sprintf($config['board_abbreviation'], $targetBoard) . " (#${newID})", $originBoard); + + // return to original board + openBoard($originBoard); + + // delete original post + deletePost($postID); + buildIndex(); + + // open target board for redirect + openBoard($targetBoard); + + // Find new thread on our target board + $query = prepare(sprintf('SELECT thread FROM `posts_%s` WHERE `id` = :id', $targetBoard)); + $query->bindValue(':id', $newID); + $query->execute() or error(db_error($query)); + $post = $query->fetch(PDO::FETCH_ASSOC); + + // redirect + header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $newID) . '#' . $newID, true, $config['redirect_http']); + } + + else { + $boards = listBoards(); + + $security_token = make_secure_link_token($originBoard . '/move_reply/' . $postID); + + mod_page(_('Move reply'), 'mod/move_reply.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards, 'token' => $security_token)); + + } + +} + function mod_move($originBoard, $postID) { global $board, $config, $mod; @@ -1115,8 +1208,8 @@ function mod_move($originBoard, $postID) { if ($post['has_file']) { // copy image - $clone($post['file_src'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $post['file']); - $clone($post['file_thumb'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $post['thumb']); + copy($post['file_src'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $post['file']); + copy($post['file_thumb'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $post['thumb']); } foreach ($post['tracked_cites'] as $cite) { |
