summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-02-15 20:11:09 +1100
committerMichael Save <savetheinternet@tinyboard.org>2012-02-15 20:11:09 +1100
commit3f1c279ce31ed9e70b85c62cf4dc7e58de2ad321 (patch)
treee9fed60f2d64244b478ab3fdb0190ac28928455b
parente3f322e2135b6010e7c89a27122b96584acfd1a5 (diff)
experimental post editing (for mods)
-rw-r--r--inc/config.php3
-rw-r--r--inc/display.php8
-rw-r--r--mod.php94
3 files changed, 104 insertions, 1 deletions
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 .= ' <a title="Remove file" href="?/' . $board['uri'] . '/deletefile/' . $this->id . '">' . $config['mod']['link_deletefile'] . '</a>';
+ // Edit post
+ if(hasPermission($config['mod']['editpost'], $board['uri'], $this->mod))
+ $built .= ' <a title="Edit post" href="?/' . $board['uri'] . '/edit/' . $this->id . '">' . $config['mod']['link_editpost'] . '</a>';
+
if(!empty($built))
$built = '<span class="controls">' . $built . '</span>';
}
@@ -399,6 +403,10 @@
if(hasPermission($config['mod']['move'], $board['uri'], $this->mod))
$built .= ' <a title="Move thread to another board" href="?/' . $board['uri'] . '/move/' . $this->id . '">' . $config['mod']['link_move'] . '</a>';
+ // Edit post
+ if(hasPermission($config['mod']['editpost'], $board['uri'], $this->mod))
+ $built .= ' <a title="Edit post" href="?/' . $board['uri'] . '/edit/' . $this->id . '">' . $config['mod']['link_editpost'] . '</a>';
+
if(!empty($built))
$built = '<span class="controls op">' . $built . '</span>';
}
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 = '<form name="post" action="" method="post">' .
+ '<table>' .
+ '<tr>' .
+ '<th>Name</th>' .
+ '<td>' . utf8tohtml($post['name']) . '</td>' .
+ '</tr>' .
+ '<tr>' .
+ '<th>Subject</th>' .
+ '<td>' .
+ '<input style="float:left;" type="text" name="subject" size="25" maxlength="50" value="' . str_replace('"', '&quot;', $post['subject']) . '"/>' .
+ '<input style="margin-left:2px;" type="submit" name="submit" value="Edit Post"/>' .
+ '</td>' .
+ '</tr>' .
+ '<tr>' .
+ '<th>Body</th>' .
+ '<td>' .
+ '<textarea name="body" rows="8" cols="38">' .
+ utf8tohtml($post['body_nomarkup']) .
+ '</textarea>' .
+ '</td>' .
+ '</tr>' .
+ '</table>' .
+ '</form>';
+
+ 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)) {