From 13aff83a30f9e3add94e37f50635ef9c56c0261f Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 7 Jul 2021 23:04:29 -0700 Subject: [PATCH] Add TINYIB_UPDATEBUMPED Update thread position when a reply is deleted. Resolves #120. --- inc/database/flatfile.php | 10 ++++++++++ inc/database/mysql.php | 4 ++++ inc/database/mysqli.php | 5 +++++ inc/database/pdo.php | 4 ++++ inc/database/sqlite.php | 4 ++++ inc/database/sqlite3.php | 5 +++++ inc/defines.php | 3 +++ inc/functions.php | 31 +++++++++++++++++++++++++++++-- settings.default.php | 1 + 9 files changed, 65 insertions(+), 2 deletions(-) diff --git a/inc/database/flatfile.php b/inc/database/flatfile.php index 3dc182b..45237cd 100644 --- a/inc/database/flatfile.php +++ b/inc/database/flatfile.php @@ -269,6 +269,16 @@ function updatePostMessage($id, $message) { } } +function updatePostBumped($id, $bumped) { + $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON), 1); + if (count($rows) > 0) { + foreach ($rows as $post) { + $post[POST_BUMPED] = $bumped; + $GLOBALS['db']->updateRowById(POSTS_FILE, POST_ID, $post); + } + } +} + function approvePostByID($id, $moderated) { $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON), 1); if (count($rows) > 0) { diff --git a/inc/database/mysql.php b/inc/database/mysql.php index 0a3d59d..8bf5fa6 100644 --- a/inc/database/mysql.php +++ b/inc/database/mysql.php @@ -177,6 +177,10 @@ function updatePostMessage($id, $message) { mysql_query("UPDATE `" . TINYIB_DBPOSTS . "` SET `message` = '" . mysql_real_escape_string($message) . "' WHERE `id` = " . $id . " LIMIT 1"); } +function updatePostBumped($id, $bumped) { + mysql_query("UPDATE `" . TINYIB_DBPOSTS . "` SET `bumped` = '" . mysql_real_escape_string($bumped) . "' WHERE `id` = " . $id . " LIMIT 1"); +} + function approvePostByID($id, $moderated) { mysql_query("UPDATE `" . TINYIB_DBPOSTS . "` SET `moderated` = $moderated WHERE `id` = " . $id . " LIMIT 1"); } diff --git a/inc/database/mysqli.php b/inc/database/mysqli.php index 1d9286d..effa09d 100644 --- a/inc/database/mysqli.php +++ b/inc/database/mysqli.php @@ -204,6 +204,11 @@ function updatePostMessage($id, $message) { mysqli_query($link, "UPDATE `" . TINYIB_DBPOSTS . "` SET `message` = '" . mysqli_real_escape_string($link, $message) . "' WHERE `id` = " . $id . " LIMIT 1"); } +function updatePostBumped($id, $bumped) { + global $link; + mysqli_query($link, "UPDATE `" . TINYIB_DBPOSTS . "` SET `bumped` = '" . mysqli_real_escape_string($link, $bumped) . "' WHERE `id` = " . $id . " LIMIT 1"); +} + function approvePostByID($id, $moderated) { global $link; mysqli_query($link, "UPDATE `" . TINYIB_DBPOSTS . "` SET `moderated` = " . $moderated . " WHERE `id` = " . $id . " LIMIT 1"); diff --git a/inc/database/pdo.php b/inc/database/pdo.php index 90021c9..49cc7ce 100644 --- a/inc/database/pdo.php +++ b/inc/database/pdo.php @@ -163,6 +163,10 @@ function updatePostMessage($id, $message) { pdoQuery("UPDATE " . TINYIB_DBPOSTS . " SET message = ? WHERE id = ?", array($message, $id)); } +function updatePostBumped($id, $bumped) { + pdoQuery("UPDATE " . TINYIB_DBPOSTS . " SET bumped = ? WHERE id = ?", array($bumped, $id)); +} + function approvePostByID($id, $moderated) { pdoQuery("UPDATE " . TINYIB_DBPOSTS . " SET moderated = ? WHERE id = ?", array($moderated, $id)); } diff --git a/inc/database/sqlite.php b/inc/database/sqlite.php index eace0ef..73b0a47 100644 --- a/inc/database/sqlite.php +++ b/inc/database/sqlite.php @@ -155,6 +155,10 @@ function updatePostMessage($id, $message) { sqlite_query($GLOBALS["db"], "UPDATE " . TINYIB_DBPOSTS . " SET message = '" . sqlite_escape_string($message) . "' WHERE id = " . $id); } +function updatePostBumped($id, $bumped) { + sqlite_query($GLOBALS["db"], "UPDATE " . TINYIB_DBPOSTS . " SET bumped = '" . sqlite_escape_string($bumped) . "' WHERE id = " . $id); +} + function approvePostByID($id, $moderated) { sqlite_query($GLOBALS["db"], "UPDATE " . TINYIB_DBPOSTS . " SET moderated = " . $moderated . " WHERE id = " . $id); } diff --git a/inc/database/sqlite3.php b/inc/database/sqlite3.php index 44827d5..17cf7a5 100644 --- a/inc/database/sqlite3.php +++ b/inc/database/sqlite3.php @@ -180,6 +180,11 @@ function updatePostMessage($id, $message) { $db->exec("UPDATE " . TINYIB_DBPOSTS . " SET message = '" . $db->escapeString($message) . "' WHERE id = " . $id); } +function updatePostBumped($id, $bumped) { + global $db; + $db->exec("UPDATE " . TINYIB_DBPOSTS . " SET bumped = '" . $db->escapeString($bumped) . "' WHERE id = " . $id); +} + function approvePostByID($id, $moderated) { global $db; $db->exec("UPDATE " . TINYIB_DBPOSTS . " SET moderated = " . $moderated . " WHERE id = " . $id); diff --git a/inc/defines.php b/inc/defines.php index 60cee0b..9c0b96e 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -82,6 +82,9 @@ if (!defined('TINYIB_REQMOD')) { if (!defined('TINYIB_BANMESSAGE')) { define('TINYIB_BANMESSAGE', true); } +if (!defined('TINYIB_UPDATEBUMPED')) { + define('TINYIB_UPDATEBUMPED', true); +} if (!defined('TINYIB_SPOILERTEXT')) { define('TINYIB_SPOILERTEXT', false); } diff --git a/inc/functions.php b/inc/functions.php index f85b792..1718dc7 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -212,13 +212,20 @@ function deletePostImages($post) { function deletePost($id) { $id = intval($id); + $is_op = false; - $posts = postsInThreadByID($id, false); + $parent = 0; $op = array(); + $posts = postsInThreadByID($id, false); foreach ($posts as $post) { if ($post['parent'] == TINYIB_NEWTHREAD) { + if ($post['id'] == $id) { + $is_op = true; + } $op = $post; continue; + } else if ($post['id'] == $id) { + $parent = $post['parent']; } deletePostImages($post); @@ -231,7 +238,27 @@ function deletePost($id) { deletePostByID($op['id']); } - @unlink('res/' . $id . '.html'); + if ($is_op) { + @unlink('res/' . $id . '.html'); + return; + } + + $current_bumped = 0; + $new_bumped = 0; + $posts = postsInThreadByID($parent, false); + foreach ($posts as $post) { + if ($post['parent'] == TINYIB_NEWTHREAD) { + $current_bumped = $post['bumped']; + } else if ($post['id'] == $id || strtolower($post['email']) == 'sage') { + continue; + } + $new_bumped = $post['timestamp']; + } + if ($new_bumped >= $current_bumped) { + return; + } + updatePostBumped($parent, $new_bumped); + rebuildIndexes(); } function checkCAPTCHA($mode) { diff --git a/settings.default.php b/settings.default.php index f07b1ef..eb7e1d8 100644 --- a/settings.default.php +++ b/settings.default.php @@ -33,6 +33,7 @@ define('TINYIB_REPORT', false); // Allow users to report posts define('TINYIB_AUTOHIDE', 0); // Amount of reports which will cause a post to be hidden until it is approved [0 to disable] define('TINYIB_REQMOD', ''); // Require moderation before displaying posts: files / all ['' to disable] define('TINYIB_BANMESSAGE', true); // Allow staff to append a custom message to posts when banning users +define('TINYIB_UPDATEBUMPED', true); // Update thread position when a reply is deleted define('TINYIB_SPOILERTEXT', false); // Allow users to hide text until it is hovered over using the tags text here or text here define('TINYIB_SPOILERIMAGE', false); // Allow users to blur thumbnails via a "Spoiler" checkbox define('TINYIB_AUTOREFRESH', 30); // Delay (in seconds) between attempts to refresh a thread automatically [0 to disable]