diff --git a/inc/config.php b/inc/config.php index 3dd770ab..c46b4fc9 100644 --- a/inc/config.php +++ b/inc/config.php @@ -712,6 +712,7 @@ $config['mod']['link_unlock'] = '[-Lock]'; $config['mod']['link_bumplock'] = '[Sage]'; $config['mod']['link_bumpunlock'] = '[-Sage]'; + $config['mod']['link_editpost'] = '[Edit]'; $config['mod']['link_move'] = '[Move]'; // Moderator capcodes @@ -827,6 +828,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; + // Edit posts (EXPERIMENTAL) + $config['mod']['editpost'] = DISABLED; // "Move" a thread to another board (EXPERIMENTAL; has some known bugs) $config['mod']['move'] = DISABLED; // Post bypass unoriginal content check on robot-enabled boards diff --git a/inc/display.php b/inc/display.php index b8a91676..f307bb91 100644 --- a/inc/display.php +++ b/inc/display.php @@ -287,6 +287,10 @@ if(!empty($this->file) && hasPermission($config['mod']['deletefile'], $board['uri'], $this->mod)) $built .= ' ' . $config['mod']['link_deletefile'] . ''; + // Edit post + if(hasPermission($config['mod']['editpost'], $board['uri'], $this->mod)) + $built .= ' ' . $config['mod']['link_editpost'] . ''; + if(!empty($built)) $built = '' . $built . ''; } @@ -399,6 +403,10 @@ if(hasPermission($config['mod']['move'], $board['uri'], $this->mod)) $built .= ' ' . $config['mod']['link_move'] . ''; + // Edit post + if(hasPermission($config['mod']['editpost'], $board['uri'], $this->mod)) + $built .= ' ' . $config['mod']['link_editpost'] . ''; + if(!empty($built)) $built = '' . $built . ''; } diff --git a/mod.php b/mod.php index d601ddb9..66ff4673 100644 --- a/mod.php +++ b/mod.php @@ -2106,6 +2106,99 @@ $page = buildThread($thread, true, $mod); echo $page; + } elseif(preg_match('/^\/' . $regex['board'] . 'edit\/(\d+)$/', $query, $matches)) { + // Edit post body + + $boardName = &$matches[1]; + + // Open board + if(!openBoard($boardName)) + error($config['error']['noboard']); + + if(!hasPermission($config['mod']['editpost'], $boardName)) error($config['error']['noaccess']); + + $postID = &$matches[2]; + + $query = prepare(sprintf("SELECT `body_nomarkup`, `name`, `subject`, `thread` FROM `posts_%s` WHERE `id` = :id", $board['uri'])); + $query->bindValue(':id', $postID, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + $post = $query->fetch() or error($config['error']['invalidpost']); + + if(isset($_POST['submit']) && isset($_POST['body']) && isset($_POST['subject'])) { + if(mb_strlen($_POST['subject']) > 100) + error(sprintf($config['error']['toolong'], 'subject')); + + $body = $_POST['body']; + $body_nomarkup = $body; + + wordfilters($body); + $tracked_cites = markup($body, true); + + $query = prepare("DELETE FROM `cites` WHERE `board` = :board AND `post` = :post"); + $query->bindValue(':board', $board['uri']); + $query->bindValue(':post', $postID, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + $query = prepare(sprintf("UPDATE `posts_%s` SET `body` = :body, `body_nomarkup` = :body_nomarkup, `subject` = :subject WHERE `id` = :id", $board['uri'])); + $query->bindValue(':id', $postID, PDO::PARAM_INT); + $query->bindValue(':body', $body); + $query->bindValue(':body_nomarkup', $body_nomarkup); + $query->bindValue(':subject', utf8tohtml($_POST['subject'])); + $query->execute() or error(db_error($query)); + + if(isset($tracked_cites)) { + foreach($tracked_cites as $cite) { + $query = prepare('INSERT INTO `cites` VALUES (:board, :post, :target_board, :target)'); + $query->bindValue(':board', $board['uri']); + $query->bindValue(':post', $postID, PDO::PARAM_INT); + $query->bindValue(':target_board',$cite[0]); + $query->bindValue(':target', $cite[1], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + } + } + + // Record the action + modLog("Edited post #{$postID}"); + + buildThread($post['thread'] ? $post['thread'] : $postID); + + // Rebuild board + buildIndex(); + + // Redirect + header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); + exit; + } + + $body = '
' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '' . + '
Name' . utf8tohtml($post['name']) . '
Subject' . + '' . + '' . + '
Body' . + '' . + '
' . + '
'; + + echo Element('page.html', Array( + 'config' => $config, + 'body' => $body, + 'title' => 'Edit Post #' . $postID + )); } elseif(preg_match('/^\/' . $regex['board'] . 'deletefile\/(\d+)$/', $query, $matches)) { // Delete file from post @@ -2128,7 +2221,6 @@ // Rebuild board buildIndex(); - // Redirect header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']); } elseif(preg_match('/^\/' . $regex['board'] . 'delete\/(\d+)$/', $query, $matches)) {