From 1613f6baeab1a61ced5678bf2e6742cef36df4d9 Mon Sep 17 00:00:00 2001 From: Kureva Date: Mon, 14 Oct 2019 03:45:39 -0300 Subject: [PATCH] Option to reset thread `bump` after last post deleted. --- inc/config.php | 3 +++ inc/functions.php | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/inc/config.php b/inc/config.php index 91ce678c..5053a7ce 100644 --- a/inc/config.php +++ b/inc/config.php @@ -222,6 +222,9 @@ // Skip checking certain IP addresses against blacklists (for troubleshooting or whatever) $config['dnsbl_exceptions'][] = '127.0.0.1'; + + // To prevent bump atacks; returns the thread to last position after the last post is deleted. + $config['anti_bump_flood'] = false; /* * Introduction to Tinyboard's spam filter: diff --git a/inc/functions.php b/inc/functions.php index e730a9ce..2d3c4582 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1227,7 +1227,8 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { // Delete posts and maybe replies while ($post = $query->fetch(PDO::FETCH_ASSOC)) { event('delete', $post); - + + $thread_id = $post['thread']; if (!$post['thread']) { // Delete thread HTML page file_unlink($board['dir'] . $config['dir']['res'] . link_for($post) ); @@ -1279,6 +1280,18 @@ function deletePost($id, $error_if_doesnt_exist=true, $rebuild_after=true) { $query->bindValue(':board', $board['uri']); $query->execute() or error(db_error($query)); + if ($config['anti_bump_flood']) { + $query = prepare(sprintf("SELECT `time` FROM ``posts_%s`` WHERE (`thread` = :thread OR `id` = :thread) AND `sage` = 0 ORDER BY `time` DESC LIMIT 1", $board['uri'])); + $query->bindValue(':thread', $thread_id); + $query->execute() or error(db_error($query)); + $bump = $query->fetchColumn(); + + $query = prepare(sprintf("UPDATE ``posts_%s`` SET `bump` = :bump WHERE `id` = :thread", $board['uri'])); + $query->bindValue(':bump', $bump); + $query->bindValue(':thread', $thread_id); + $query->execute() or error(db_error($query)); + } + if (isset($rebuild) && $rebuild_after) { buildThread($rebuild); buildIndex();