pages.php: basic format for mod_merge
This commit is contained in:
parent
60866725c4
commit
baf0e030ed
1 changed files with 32 additions and 28 deletions
|
|
@ -1716,11 +1716,13 @@ function mod_move(Context $ctx, $originBoard, $postID) {
|
|||
function mod_merge(Context $ctx, $originBoard, $postID) {
|
||||
global $board, $config, $pdo;
|
||||
|
||||
if (!openBoard($originBoard))
|
||||
if (!openBoard($originBoard)) {
|
||||
error($config['error']['noboard']);
|
||||
}
|
||||
|
||||
if (!hasPermission($config['mod']['merge'], $originBoard))
|
||||
if (!hasPermission($config['mod']['merge'], $originBoard)) {
|
||||
error($config['error']['noaccess']);
|
||||
}
|
||||
|
||||
$query = prepare(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = :id AND `thread` IS NULL', $originBoard));
|
||||
$query->bindValue(':id', (int)$postID, \PDO::PARAM_INT);
|
||||
|
|
@ -1729,32 +1731,29 @@ function mod_merge(Context $ctx, $originBoard, $postID) {
|
|||
error($config['error']['404']);
|
||||
}
|
||||
$sourceOp = "";
|
||||
if ($post['thread']){
|
||||
if ($post['thread']) {
|
||||
$sourceOp = $post['thread'];
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$sourceOp = $post['id'];
|
||||
}
|
||||
$newpost = "";
|
||||
$newpost = "";
|
||||
$boards = listBoards();
|
||||
|
||||
if (isset($_POST['board'])) {
|
||||
$targetBoard = $_POST['board'];
|
||||
$shadow = isset($_POST['shadow']);
|
||||
$targetOp = "";
|
||||
$targetOp = "";
|
||||
|
||||
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
|
||||
if (!$newpost = $query->fetch(PDO::FETCH_ASSOC)){
|
||||
error($config['error']['404']);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($newpost['thread']){
|
||||
$targetOp = $newpost['thread'];
|
||||
}
|
||||
else{
|
||||
} else{
|
||||
$targetOp = $newpost['id'];
|
||||
}
|
||||
}
|
||||
|
|
@ -1771,8 +1770,6 @@ function mod_merge(Context $ctx, $originBoard, $postID) {
|
|||
file_unlink($board['dir'] . $config['dir']['res'] . link_for($post) );
|
||||
file_unlink($board['dir'] . $config['dir']['res'] . link_for($post, true) ); // noko50
|
||||
file_unlink($board['dir'] . $config['dir']['res'] . sprintf('%d.json', $post['id']));
|
||||
//deletePost($postID);
|
||||
//modLog("Deleted post #{$postID}");
|
||||
buildIndex();
|
||||
|
||||
// build new thread
|
||||
|
|
@ -1784,22 +1781,24 @@ function mod_merge(Context $ctx, $originBoard, $postID) {
|
|||
|
||||
// redirect
|
||||
header('Location: ?/' . sprintf($config['board_path'], $board['uri']) . $config['dir']['res'] . link_for($newpost) . '#' . $targetOp, true, $config['redirect_http']);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Move thread to new board without shadow thread and then update the thread id for all posts in that thread to new op
|
||||
// indicate that the post is a thread
|
||||
if (count($boards) <= 1)
|
||||
if (count($boards) <= 1) {
|
||||
error(_('Impossible to merge thread to different board; there is only one board.'));
|
||||
}
|
||||
$post['op'] = true;
|
||||
|
||||
if ($post['files']) {
|
||||
$post['files'] = json_decode($post['files'], TRUE);
|
||||
$post['has_file'] = true;
|
||||
foreach ($post['files'] as $i => &$file) {
|
||||
if ($file['file'] !== 'deleted')
|
||||
if ($file['file'] !== 'deleted') {
|
||||
$file['file_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file'];
|
||||
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file')))
|
||||
}
|
||||
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file'))) {
|
||||
$file['thumb_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$post['has_file'] = false;
|
||||
|
|
@ -1808,8 +1807,9 @@ function mod_merge(Context $ctx, $originBoard, $postID) {
|
|||
// allow thread to keep its same traits (stickied, locked, etc.)
|
||||
$post['mod'] = true;
|
||||
|
||||
if (!openBoard($targetBoard))
|
||||
if (!openBoard($targetBoard)) {
|
||||
error($config['error']['noboard']);
|
||||
}
|
||||
|
||||
// create the new thread
|
||||
$newID = post($post);
|
||||
|
|
@ -1823,10 +1823,12 @@ function mod_merge(Context $ctx, $originBoard, $postID) {
|
|||
if ($post['has_file']) {
|
||||
// copy image
|
||||
foreach ($post['files'] as $i => &$file) {
|
||||
if ($file['file'] !== 'deleted')
|
||||
if ($file['file'] !== 'deleted') {
|
||||
clone_wrapped_with_exist_check($clone, $file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
|
||||
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file')))
|
||||
}
|
||||
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file'))) {
|
||||
clone_wrapped_with_exist_check($clone, $file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1847,10 +1849,12 @@ function mod_merge(Context $ctx, $originBoard, $postID) {
|
|||
$post['files'] = json_decode($post['files'], TRUE);
|
||||
$post['has_file'] = true;
|
||||
foreach ($post['files'] as $i => &$file) {
|
||||
if ($file['file'] !== 'deleted')
|
||||
if ($file['file'] !== 'deleted') {
|
||||
$file['file_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file'];
|
||||
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file')))
|
||||
}
|
||||
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file'))) {
|
||||
$file['thumb_path'] = sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$post['has_file'] = false;
|
||||
|
|
@ -1889,10 +1893,12 @@ function mod_merge(Context $ctx, $originBoard, $postID) {
|
|||
if ($post['has_file']) {
|
||||
// copy image
|
||||
foreach ($post['files'] as $i => &$file) {
|
||||
if ($file['file'] !== 'deleted')
|
||||
if ($file['file'] !== 'deleted') {
|
||||
clone_wrapped_with_exist_check($clone, $file['file_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['img'] . $file['file']);
|
||||
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file')))
|
||||
}
|
||||
if (isset($file['thumb']) && !in_array($file['thumb'], array('spoiler', 'deleted', 'file'))) {
|
||||
clone_wrapped_with_exist_check($clone, $file['thumb_path'], sprintf($config['board_path'], $board['uri']) . $config['dir']['thumb'] . $file['thumb']);
|
||||
}
|
||||
}
|
||||
}
|
||||
// insert reply
|
||||
|
|
@ -1921,8 +1927,6 @@ function mod_merge(Context $ctx, $originBoard, $postID) {
|
|||
// trigger themes
|
||||
rebuildThemes('post', $targetBoard);
|
||||
|
||||
$newboard = $board;
|
||||
|
||||
// return to original board
|
||||
openBoard($originBoard);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue