From cff26e609d5f6416755e3d800c7922ee3e46b8d2 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 5 May 2021 19:55:18 -0700 Subject: [PATCH] Add TINYIB_AUTOHIDE --- imgboard.php | 2 ++ inc/database/flatfile.php | 10 +++++++++- inc/database/pdo.php | 14 +++++++------- inc/database/sqlite.php | 2 +- inc/database/sqlite3.php | 2 +- inc/defines.php | 3 +++ inc/functions.php | 14 ++++++++++++++ inc/html.php | 6 ++++++ settings.default.php | 1 + 9 files changed, 44 insertions(+), 10 deletions(-) diff --git a/imgboard.php b/imgboard.php index 3a8351e..0edf629 100644 --- a/imgboard.php +++ b/imgboard.php @@ -506,6 +506,7 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name']) if ($report_post) { $report = array('ip' => $post['ip'], 'post' => $post['id']); insertReport($report); + checkAutoHide($post); } if ($post['moderated'] == '1') { @@ -638,6 +639,7 @@ EOF; $report = array('ip' => remoteAddress(), 'post' => $post['id']); insertReport($report); + checkAutoHide($post); fancyDie(__('Post reported.'), $go_back); // Check if the request is to delete a post and/or its associated image diff --git a/inc/database/flatfile.php b/inc/database/flatfile.php index 9afd463..09bdd4a 100644 --- a/inc/database/flatfile.php +++ b/inc/database/flatfile.php @@ -360,7 +360,15 @@ function postsInThreadByID($id, $moderated_only = true) { $compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON)); $compClause->add(new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON)); - $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, -1, new OrderBy(POST_ID, ASCENDING, INTEGER_COMPARISON)); + if ($moderated_only) { + $compClause2 = new AndWhereClause(); + $compClause2->add($compClause); + $compClause2->add(new SimpleWhereClause(POST_MODERATED, '>', 0, INTEGER_COMPARISON)); + } else { + $compClause2 = $compClause; + } + + $rows = $GLOBALS['db']->selectWhere(POSTS_FILE, $compClause2, -1, new OrderBy(POST_ID, ASCENDING, INTEGER_COMPARISON)); return convertPostsToSQLStyle($rows); } diff --git a/inc/database/pdo.php b/inc/database/pdo.php index 6bc0766..6997ad6 100644 --- a/inc/database/pdo.php +++ b/inc/database/pdo.php @@ -143,7 +143,7 @@ function postByID($id) { } function threadExistsByID($id) { - $result = pdoQuery("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE id = ? AND parent = 0 AND moderated = 1", array($id)); + $result = pdoQuery("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE id = ? AND parent = 0 AND moderated > 0", array($id)); return $result->fetchColumn() != 0; } @@ -177,13 +177,13 @@ function lockThreadByID($id, $setlock) { } function countThreads() { - $result = pdoQuery("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated = 1"); + $result = pdoQuery("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated > 0"); return (int)$result->fetchColumn(); } function allThreads() { $threads = array(); - $results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated = 1 ORDER BY stickied DESC, bumped DESC"); + $results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated > 0 ORDER BY stickied DESC, bumped DESC"); while ($row = $results->fetch()) { $threads[] = $row; } @@ -191,13 +191,13 @@ function allThreads() { } function numRepliesToThreadByID($id) { - $result = pdoQuery("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = ? AND moderated = 1", array($id)); + $result = pdoQuery("SELECT COUNT(*) FROM " . TINYIB_DBPOSTS . " WHERE parent = ? AND moderated > 0", array($id)); return (int)$result->fetchColumn(); } function postsInThreadByID($id, $moderated_only = true) { $posts = array(); - $results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = ? OR parent = ?)" . ($moderated_only ? " AND moderated = 1" : "") . " ORDER BY id ASC", array($id, $id)); + $results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = ? OR parent = ?)" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC", array($id, $id)); while ($row = $results->fetch(PDO::FETCH_ASSOC)) { $posts[] = $row; } @@ -217,7 +217,7 @@ function imagesInThreadByID($id, $moderated_only = true) { function postsByHex($hex) { $posts = array(); - $results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE file_hex = ? AND moderated = 1 LIMIT 1", array($hex)); + $results = pdoQuery("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE file_hex = ? AND moderated > 0 LIMIT 1", array($hex)); while ($row = $results->fetch(PDO::FETCH_ASSOC)) { $posts[] = $row; } @@ -240,7 +240,7 @@ function deletePostByID($id) { function trimThreads() { $limit = (int)TINYIB_MAXTHREADS; if ($limit > 0) { - $results = pdoQuery("SELECT id FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated = 1 ORDER BY stickied DESC, bumped DESC LIMIT 100 OFFSET " . $limit); + $results = pdoQuery("SELECT id FROM " . TINYIB_DBPOSTS . " WHERE parent = 0 AND moderated > 0 ORDER BY stickied DESC, bumped DESC LIMIT 100 OFFSET " . $limit); /* old mysql, sqlite3: SELECT id FROM $table ORDER BY bumped LIMIT $limit,100 mysql, postgresql, sqlite3: SELECT id FROM $table ORDER BY bumped LIMIT 100 OFFSET $limit diff --git a/inc/database/sqlite.php b/inc/database/sqlite.php index a45bacf..f0972a0 100644 --- a/inc/database/sqlite.php +++ b/inc/database/sqlite.php @@ -186,7 +186,7 @@ function numRepliesToThreadByID($id) { function postsInThreadByID($id, $moderated_only = true) { $posts = array(); - $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE id = " . $id . " OR parent = " . $id . " ORDER BY id ASC"), SQLITE_ASSOC); + $result = sqlite_fetch_all(sqlite_query($GLOBALS["db"], "SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = " . $id . " OR parent = " . $id . ")" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC"), SQLITE_ASSOC); foreach ($result as $post) { $posts[] = $post; } diff --git a/inc/database/sqlite3.php b/inc/database/sqlite3.php index aea036e..c06371c 100644 --- a/inc/database/sqlite3.php +++ b/inc/database/sqlite3.php @@ -218,7 +218,7 @@ function numRepliesToThreadByID($id) { function postsInThreadByID($id, $moderated_only = true) { global $db; $posts = array(); - $result = $db->query("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE id = " . $id . " OR parent = " . $id . " ORDER BY id ASC"); + $result = $db->query("SELECT * FROM " . TINYIB_DBPOSTS . " WHERE (id = " . $id . " OR parent = " . $id . ")" . ($moderated_only ? " AND moderated > 0" : "") . " ORDER BY id ASC"); while ($post = $result->fetchArray()) { $posts[] = $post; } diff --git a/inc/defines.php b/inc/defines.php index 0f0a355..1520a31 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -73,6 +73,9 @@ if (!defined('TINYIB_MANAGECAPTCHA')) { if (!defined('TINYIB_REPORT')) { define('TINYIB_REPORT', false); } +if (!defined('TINYIB_AUTOHIDE')) { + define('TINYIB_AUTOHIDE', 0); +} if (!defined('TINYIB_REQMOD')) { define('TINYIB_REQMOD', ''); } diff --git a/inc/functions.php b/inc/functions.php index 1158e09..eebf8ce 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -345,6 +345,20 @@ function checkMessageSize() { } } +function checkAutoHide($post) { + if (TINYIB_AUTOHIDE <= 0) { + return; + } + + $reports = reportsByPost($post['id']); + if (count($reports) >= TINYIB_AUTOHIDE) { + approvePostByID($post['id'], 0); + + $parent_id = $post['parent'] == TINYIB_NEWTHREAD ? $post['id'] : $post['parent']; + threadUpdated($parent_id); + } +} + function manageCheckLogIn($requireKey) { $account = array(); $loggedin = false; diff --git a/inc/html.php b/inc/html.php index 476bf0b..d615b5d 100644 --- a/inc/html.php +++ b/inc/html.php @@ -741,6 +741,12 @@ function rebuildIndexes() { function rebuildThread($id) { $id = intval($id); + $post = postByID($id); + if ($post['moderated'] == 0) { + @unlink('res/' . $id . '.html'); + return; + } + $posts = postsInThreadByID($id); if (count($posts) == 0) { @unlink('res/' . $id . '.html'); diff --git a/settings.default.php b/settings.default.php index 595c387..6a091b9 100644 --- a/settings.default.php +++ b/settings.default.php @@ -28,6 +28,7 @@ define('TINYIB_CAPTCHA', ''); // Reduce spam by requiring users to pass define('TINYIB_REPORTCAPTCHA', ''); // Reduce invalid reports by requiring users to pass a CAPTCHA when reporting: simple / hcaptcha / recaptcha ['' to disable] define('TINYIB_MANAGECAPTCHA', ''); // Improve security by requiring users to pass a CAPTCHA when logging in to the management panel: simple / hcaptcha / recaptcha ['' to disable] 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_AUTOREFRESH', 30); // Delay (in seconds) between attempts to refresh a thread automatically [0 to disable] define('TINYIB_CLOUDFLARE', false); // Only enable when the site is served via Cloudflare to identify IP addresses correctly