From 351375185e5351299ac52f24261d02700f5ac631 Mon Sep 17 00:00:00 2001 From: 8chan Date: Wed, 31 Dec 2014 22:33:31 -0800 Subject: [PATCH] Early 404 option in clean() --- inc/functions.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/inc/functions.php b/inc/functions.php index ca58bbfa..d2417f74 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -1158,11 +1158,26 @@ function clean() { // I too wish there was an easier way of doing this... $query = prepare(sprintf("SELECT `id` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri'])); $query->bindValue(':offset', $offset, PDO::PARAM_INT); - $query->execute() or error(db_error($query)); + while ($post = $query->fetch(PDO::FETCH_ASSOC)) { deletePost($post['id'], false, false); } + + // Bump off threads with X replies earlier, spam prevention method + if ($config['early_404']) { + $offset = round($config['early_404_page']*$config['threads_per_page']); + $query = prepare(sprintf("SELECT `id` AS `thread_id`, (SELECT COUNT(`id`) FROM ``posts_%s`` WHERE `thread` = `thread_id`) AS `reply_count` FROM ``posts_%s`` WHERE `thread` IS NULL ORDER BY `sticky` DESC, `bump` DESC LIMIT :offset, 9001", $board['uri'], $board['uri'])); + $query->bindValue(':offset', $offset, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + while ($post = $query->fetch(PDO::FETCH_ASSOC)) { + if ($post['reply_count'] < $config['early_404_replies']) { + deletePost($post['thread_id'], false, false); + } + } + } + } function thread_find_page($thread) {