This commit is contained in:
Michael Save 2012-05-19 18:27:45 +10:00
parent 750fed8a47
commit 970c6cd95b
4 changed files with 227 additions and 2 deletions

View File

@ -716,13 +716,13 @@ function post(array $post) {
$query->bindValue(':password', $post['password']); $query->bindValue(':password', $post['password']);
$query->bindValue(':ip', isset($post['ip']) ? $post['ip'] : $_SERVER['REMOTE_ADDR']); $query->bindValue(':ip', isset($post['ip']) ? $post['ip'] : $_SERVER['REMOTE_ADDR']);
if ($post['mod'] && $post['sticky']) { if ($post['op'] && $post['mod'] && $post['sticky']) {
$query->bindValue(':sticky', 1, PDO::PARAM_INT); $query->bindValue(':sticky', 1, PDO::PARAM_INT);
} else { } else {
$query->bindValue(':sticky', 0, PDO::PARAM_INT); $query->bindValue(':sticky', 0, PDO::PARAM_INT);
} }
if ($post['mod'] && $post['locked']) { if ($post['op'] && $post['mod'] && $post['locked']) {
$query->bindValue(':locked', 1, PDO::PARAM_INT); $query->bindValue(':locked', 1, PDO::PARAM_INT);
} else { } else {
$query->bindValue(':locked', 0, PDO::PARAM_INT); $query->bindValue(':locked', 0, PDO::PARAM_INT);

View File

@ -693,6 +693,189 @@ function mod_bumplock($board, $unbumplock, $post) {
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']); header('Location: ?/' . sprintf($config['board_path'], $board) . $config['file_index'], true, $config['redirect_http']);
} }
function mod_move($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 AND `thread` IS NULL', $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'];
$shadow = isset($_POST['shadow']);
if ($targetBoard === $originBoard)
error(_('Target and source board are the same.'));
// copy() if leaving a shadow thread behind; else, rename().
$clone = $shadow ? 'copy' : 'rename';
// indicate that the post is a thread
$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 thread
$newID = post($post);
if($post['has_file']) {
// copy image
$clone($file_src, sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $post['file']);
$clone($file_thumb, sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $post['thumb']);
}
// go back to the original board to fetch replies
openBoard($originBoard);
$query = prepare(sprintf('SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id`', $originBoard));
$query->bindValue(':id', $postID, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$replies = array();
while($post = $query->fetch()) {
$post['mod'] = true;
$post['thread'] = $newID;
if($post['file']) {
$post['has_file'] = true;
$post['width'] = &$post['filewidth'];
$post['height'] = &$post['fileheight'];
$post['file_src'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $post['file'];
$post['file_thumb'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $post['thumb'];
} else {
$post['has_file'] = false;
}
$replies[] = $post;
}
$newIDs = array($postID => $newID);
openBoard($targetBoard);
foreach($replies as &$post) {
$query = prepare('SELECT `target` FROM `cites` WHERE `target_board` = :board AND `board` = :board AND `post` = :post');
$query->bindValue(':board', $originBoard);
$query->bindValue(':post', $post['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($qurey));
// correct >>X links
while($cite = $query->fetch(PDO::FETCH_ASSOC)) {
if(isset($newIDs[$cite['target']])) {
$post['body_nomarkup'] = preg_replace(
'/(>>(>\/' . preg_quote($originBoard, '/') . '\/)?)' . preg_quote($cite['target'], '/') . '/',
'>>' . $newIDs[$cite['target']],
$post['body_nomarkup']);
$post['body'] = $post['body_nomarkup'];
}
}
$post['body'] = $post['body_nomarkup'];
$post['op'] = false;
$post['tracked_cites'] = markup($post['body'], true);
// insert reply
$newIDs[$post['id']] = $newPostID = post($post);
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']);
}
foreach($post['tracked_cites'] as $cite) {
$query = prepare('INSERT INTO `cites` VALUES (:board, :post, :target_board, :target)');
$query->bindValue(':board', $board['uri']);
$query->bindValue(':post', $newPostID, PDO::PARAM_INT);
$query->bindValue(':target_board',$cite[0]);
$query->bindValue(':target', $cite[1], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
}
}
// build new hread
buildThread($newID);
buildIndex();
// trigger themes
rebuildThemes('post');
// return to original board
openBoard($originBoard);
if($shadow) {
// lock old thread
$query = prepare(sprintf('UPDATE `posts_%s` SET `locked` = 1 WHERE `id` = :id', $originBoard));
$query->bindValue(':id', $postID, PDO::PARAM_INT);
$query->execute() or error(db_error($query));
// leave a reply, linking to the new thread
$post = array(
'mod' => true,
'subject' => '',
'email' => '',
'name' => $config['mod']['shadow_name'],
'capcode' => $config['mod']['shadow_capcode'],
'trip' => '',
'password' => '',
'has_file' => false,
// attach to original thread
'thread' => $postID,
'op' => false
);
$post['body'] = $post['body_nomarkup'] = sprintf($config['mod']['shadow_mesage'], '>>>/' . $targetBoard . '/' . $newID);
markup($post['body']);
$botID = post($post);
buildThread($postID);
header('Location: ?/' . sprintf($config['board_path'], $originBoard) . $config['dir']['res'] .sprintf($config['file_page'], $postID) .
'#' . $botID, true, $config['redirect_http']);
} else {
deletePost($postID);
buildIndex();
openBoard($targetBoard);
header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . sprintf($config['file_page'], $newID), true, $config['redirect_http']);
}
}
$boards = listBoards();
if (count($boards) <= 1)
error(_('Impossible to move thread; there is only one board.'));
mod_page("Move thread", 'mod/move.html', array('post' => $postID, 'board' => $originBoard, 'boards' => $boards));
}
function mod_ban_post($board, $delete, $post) { function mod_ban_post($board, $delete, $post) {
global $config, $mod; global $config, $mod;

View File

@ -63,6 +63,7 @@ $pages = array(
'/(\w+)/(un)?lock/(\d+)' => 'lock', // lock thread '/(\w+)/(un)?lock/(\d+)' => 'lock', // lock thread
'/(\w+)/(un)?sticky/(\d+)' => 'sticky', // sticky thread '/(\w+)/(un)?sticky/(\d+)' => 'sticky', // sticky thread
'/(\w+)/bump(un)?lock/(\d+)' => 'bumplock', // "bumplock" thread '/(\w+)/bump(un)?lock/(\d+)' => 'bumplock', // "bumplock" thread
'/(\w+)/move/(\d+)' => 'move', // move thread
// these pages aren't listed in the dashboard without $config['debug'] // these pages aren't listed in the dashboard without $config['debug']
'/debug/antispam' => 'debug_antispam', '/debug/antispam' => 'debug_antispam',

41
templates/mod/move.html Normal file
View File

@ -0,0 +1,41 @@
<form action="?/{{ board }}/move/{{ post }}" method="post">
<table>
<tr>
<th>
{% trans 'Thread ID' %}
</th>
<td>
&gt;&gt;&gt;{{ config.board_abbreviation|sprintf(board) }}{{ post }}
</td>
</tr>
<tr>
<th>
{% trans 'Leave shadow thread' %}
</th>
<td>
<input type="checkbox" name="shadow" checked>
<span class="unimportant">({% trans 'locks thread; replies to it with a link.' %})</span>
</td>
</tr>
<tr>
<th>{% trans 'Target board' %}</th>
<td>
<ul style="list-style:none;padding:0">
{% for targetboard in boards if targetboard.uri != board %}
<li>
<input type="radio" name="board" value="{{ targetboard.uri }}" id="ban-board-{{ targetboard.uri }}">
<label style="display:inline" for="ban-board-{{ targetboard.uri }}">
{{ config.board_abbreviation|sprintf(targetboard.uri) }} - {{ targetboard.title|e }}
</label>
</li>
{% endfor %}
</ul>
</td>
</tr>
</table>
<ul style="padding:0;text-align:center;list-style:none">
<li><input type="submit" value="{% trans 'Move thread' %}"></li>
</ul>
</form>