From 9fad32dff7f387dbaf4043e7dedffb09d9cf5de2 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Thu, 11 Mar 2021 14:11:24 -0800 Subject: [PATCH] Add reports page to management panel --- imgboard.php | 9 ++++ inc/defines.php | 2 +- inc/html.php | 111 +++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 100 insertions(+), 22 deletions(-) diff --git a/imgboard.php b/imgboard.php index 97bb146..9f555fd 100644 --- a/imgboard.php +++ b/imgboard.php @@ -571,6 +571,11 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name']) } rebuildIndexes(); $text .= manageInfo(__('Rebuilt board.')); + } else if (isset($_GET['reports'])) { + if (!TINYIB_REPORT) { + fancyDie(__('Reporting is disabled.')); + } + $text .= manageReportsPage($_GET['reports']); } elseif (isset($_GET['bans'])) { clearExpiredBans(); @@ -581,6 +586,10 @@ if (!isset($_GET['delete']) && !isset($_GET['manage']) && (isset($_POST['name']) fancyDie(__('Sorry, there is already a ban on record for that IP address.')); } + if (TINYIB_REPORT) { + deleteReportsByIP($_POST['ip']); + } + $ban = array(); $ban['ip'] = $_POST['ip']; $ban['expire'] = ($_POST['expire'] > 0) ? (time() + $_POST['expire']) : 0; diff --git a/inc/defines.php b/inc/defines.php index 4c74320..24c5c60 100644 --- a/inc/defines.php +++ b/inc/defines.php @@ -53,7 +53,7 @@ if (!defined('TINYIB_MANAGECAPTCHA')) { define('TINYIB_MANAGECAPTCHA', ''); } if (!defined('TINYIB_REPORT')) { - define('TINYIB_REPORT', ''); + define('TINYIB_REPORT', false); } if (!defined('TINYIB_REQMOD')) { define('TINYIB_REQMOD', ''); diff --git a/inc/html.php b/inc/html.php index 1b5db6c..3f50636 100644 --- a/inc/html.php +++ b/inc/html.php @@ -748,6 +748,9 @@ function adminBar() { $output = '[' . __('Status') . '] ['; if ($isadmin) { + if (TINYIB_REPORT) { + $output .= '' . __('Reports') . '] ['; + } $output .= '' . __('Bans') . '] ['; $output .= '' . __('Keywords') . '] ['; } @@ -849,6 +852,74 @@ function manageLogInForm() { EOF; } +function manageReportsPage($ip) { + $reports = allReports(); + $report_counts = array(); + $posts = array(); + foreach ($reports as $report) { + if ($ip != '' && $report['ip'] != $ip && $report['ip'] != hashData($ip)) { + continue; + } + + $post = postByID($report['post']); + if (empty($post)) { + continue; + } + + if ($ip == '') { + $post['reportedby'] = $report['ip']; + + if (!isset($report_counts[$report['ip']])) { + $report_counts[$report['ip']] = 0; + } + $report_counts[$report['ip']]++; + } + + $posts[] = $post; + } + + $txt_reported = __('Reported posts'); + if ($ip != '') { + if (count($posts) == 1) { + $format = __('%1$d report by %2$s'); + } else { + $format = __('%1$d reports by %2$s'); + } + $txt_reported = sprintf($format, count($posts), '' . htmlentities($ip) . ''); + } + + $post_html = ''; + foreach ($posts as $post) { + if ($post_html != '') { + $post_html .= '
'; + } + + if (isset($post['reportedby'])) { + $reportedby_html = '' . htmlentities($post['reportedby']) . ''; + if ($report_counts[$post['reportedby']] > 1) { + $reportedby_html .= ' (' . sprintf(__('%d reports'), $report_counts[$post['reportedby']]) . ')'; + } + + $post_html .= '' . sprintf(__('Reported by %s'), $reportedby_html) . ''; + } + + $post_html .= '' . buildPost($post, TINYIB_INDEXPAGE) . '
'; + } + + if ($post_html == '') { + $post_html = '' . __('There are currently no reported posts.') . ''; + } + + return << + $txt_reported + + $post_html +
+ +EOF; +} + function manageBanForm() { $txt_ban = __('Add a ban'); $txt_ban_ip = __('IP Address'); @@ -1187,25 +1258,28 @@ EOF; } if (TINYIB_REPORT && !empty($reports)) { - $posts = array(); - foreach ($reports as $report) { - $post = postByID($report['post']); - if (empty($post)) { - continue; - } - $posts[] = $post; - } - $txt_recent_posts = __('Reported posts'); + $status_html = manageReportsPage(''); } else { $posts = latestPosts(true); $txt_recent_posts = __('Recent posts'); - } - $post_html = ''; - foreach ($posts as $post) { - if ($post_html != '') { - $post_html .= '
'; + + $post_html = ''; + foreach ($posts as $post) { + if ($post_html != '') { + $post_html .= '
'; + } + + $post_html .= '' . buildPost($post, TINYIB_INDEXPAGE) . '
'; } - $post_html .= '' . buildPost($post, TINYIB_INDEXPAGE) . '
'; + + $status_html = << + $txt_recent_posts + + $post_html +
+ +EOF; } $txt_status = __('Status'); @@ -1228,12 +1302,7 @@ EOF; $reqmod_html -
- $txt_recent_posts - - $post_html -
-
+ $status_html