forked from leftypol/leftypol
Optionally allow the moving of single replies
This commit is contained in:
parent
001989876f
commit
ddbe562f9c
4 changed files with 104 additions and 2 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue