From d8fe3ff8d82b5437fd83de3716728cdff0885d03 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sat, 19 Nov 2011 01:35:22 +1100 Subject: [PATCH] Ability to "move" a thread to another board (2/3 done) --- inc/config.php | 6 ++ inc/display.php | 3 + inc/functions.php | 4 +- mod.php | 149 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 2 deletions(-) diff --git a/inc/config.php b/inc/config.php index 9711990f..67158c5a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -691,6 +691,7 @@ $config['mod']['link_unlock'] = '[-Lock]'; $config['mod']['link_bumplock'] = '[Sage]'; $config['mod']['link_bumpunlock'] = '[-Sage]'; + $config['mod']['link_move'] = '[Move]'; // Moderator capcodes $config['capcode'] = ' ## %s'; @@ -754,6 +755,7 @@ define('JANITOR', 0, true); define('MOD', 1, true); define('ADMIN', 2, true); + define('DISABLED', 3, true); } /* @@ -761,6 +763,8 @@ * Mod permissions * ==================== */ + + // Set any of the below to "DISABLED" to make them unavailable for everyone. // Don't worry about per-board moderators. Let all mods moderate any board. $config['mod']['skip_per_board'] = true; @@ -790,6 +794,8 @@ $config['mod']['bumplock'] = MOD; // View whether a thread has been bumplocked ("-1" to allow non-mods to see too) $config['mod']['view_bumplock'] = MOD; + // "Move" a thread to another board + $config['mod']['move'] = MOD; // Post bypass unoriginal content check on robot-enabled boards $config['mod']['postunoriginal'] = ADMIN; // Bypass flood check diff --git a/inc/display.php b/inc/display.php index 93afd59d..ed5f403b 100644 --- a/inc/display.php +++ b/inc/display.php @@ -376,6 +376,9 @@ else $built .= ' ' . $config['mod']['link_lock'] . ''; + if(hasPermission($config['mod']['move'], $board['uri'], $this->mod)) + $built .= ' ' . $config['mod']['link_move'] . ''; + if(!empty($built)) $built = '' . $built . ''; } diff --git a/inc/functions.php b/inc/functions.php index f9b16c8a..c59f6036 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -614,9 +614,9 @@ $query->bindValue(':name', $post['name']); $query->bindValue(':trip', $post['trip']); $query->bindValue(':body', $post['body']); - $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':time', $post['time'] ? $post['time'] : time(), PDO::PARAM_INT); $query->bindValue(':password', $post['password']); - $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':ip', $post['ip'] ? $post['ip'] : $_SERVER['REMOTE_ADDR']); if($post['mod'] && $post['sticky']) { $query->bindValue(':sticky', 1, PDO::PARAM_INT); diff --git a/mod.php b/mod.php index adb121c8..f25a0969 100644 --- a/mod.php +++ b/mod.php @@ -2168,6 +2168,155 @@ else header('Location: ?/', true, $config['redirect_http']); } + } elseif(preg_match('/^\/' . $regex['board'] . 'move\/(\d+)$/', $query, $matches)) { + + $boardName = &$matches[1]; + $postID = $matches[2]; + + // Open board + if(!openBoard($boardName)) + error($config['error']['noboard']); + + if(!hasPermission($config['mod']['move'], $boardName)) error($config['error']['noaccess']); + + if(isset($_POST['board'])) { + $targetBoard = $_POST['board']; + $shadow = isset($_POST['shadow']); + + // copy() if leaving a shadow thread behind. otherwise, rename(). + $clone = $shadow ? 'copy' : 'rename'; + + $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` IS NULL AND `id` = :id", $board['uri'])); + $query->bindValue(':id', $postID, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + if(!$post = $query->fetch()) { + error($config['error']['nonexistant']); + } + + 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']); + + $newID = post($post, true); + + if($post['has_file']) { + $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']); + } + + // move replies too... + openBoard($boardName); + + $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id`", $board['uri'])); + $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; + } + + openBoard($targetBoard); + foreach($replies as &$post) { + var_dump(post($post, false)); + if($post['has_file']) { + $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']); + } + } + + // build thread + buildThread($newID); + buildIndex(); + + // trigger themes + rebuildThemes('post'); + + if($shadow) { + // do something + } else { + openBoard($boardName); + deletePost($postID); + buildIndex(); + } + + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); + } else { + + $body = '
Move thread' . + '
' . + '' + ; + + $boards = listBoards(); + + $__boards = ''; + foreach($boards as &$_board) { + $__boards .= '
  • ' . + '' . + '' . + '
  • '; + } + + $body .= '' . + '' . + '' . + '' . + + '' . + '' . + '' . + '' . + + '' . + '' . + '' . + '' . + + '' . + '' . + '' . + '' . + '
    Thread ID
    ' . + '' . + ' (locks thread; replies to it with a link.)' . + '
    Target board
      ' . $__boards . '
    ' . + '
    '; + + echo Element('page.html', Array( + 'config'=>$config, + 'title'=>'Move #' . $postID, + 'body'=>$body, + 'mod'=>true + ) + ); + } } elseif(preg_match('/^\/' . $regex['board'] . 'ban(&delete)?\/(\d+)$/', $query, $matches)) { // Ban by post