From e7518dfe257a154beb36303eafb74e63acf2afce Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 19 Oct 2024 19:56:23 +0200 Subject: [PATCH 1/3] pages.php: format mod_reports --- inc/mod/pages.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index eb981076..625a66e6 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2892,15 +2892,18 @@ function mod_reports() { if (!hasPermission($config['mod']['reports'])) error($config['error']['noaccess']); + $reports_limit = $config['mod']['recent_reports']; + $query = prepare("SELECT * FROM ``reports`` ORDER BY `time` DESC LIMIT :limit"); - $query->bindValue(':limit', $config['mod']['recent_reports'], PDO::PARAM_INT); + $query->bindValue(':limit', $reports_limit + 1, PDO::PARAM_INT); $query->execute() or error(db_error($query)); $reports = $query->fetchAll(PDO::FETCH_ASSOC); $report_queries = []; foreach ($reports as $report) { - if (!isset($report_queries[$report['board']])) + if (!isset($report_queries[$report['board']])) { $report_queries[$report['board']] = []; + } $report_queries[$report['board']][] = $report['post']; } @@ -2908,7 +2911,7 @@ function mod_reports() { foreach ($report_queries as $board => $posts) { $report_posts[$board] = []; - $query = query(sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error()); + $query = query(\sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = ' . \implode(' OR `id` = ', $posts), $board)) or error(db_error()); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { $report_posts[$board][$post['id']] = $post; } @@ -2951,23 +2954,24 @@ function mod_reports() { // Bug fix for https://github.com/savetheinternet/Tinyboard/issues/21 $po->body = truncate($po->body, $po->link(), $config['body_truncate'] - substr_count($append_html, '
')); - if (mb_strlen($po->body) + mb_strlen($append_html) > $config['body_truncate_char']) { + if (\mb_strlen($po->body) + \mb_strlen($append_html) > $config['body_truncate_char']) { // still too long; temporarily increase limit in the config $__old_body_truncate_char = $config['body_truncate_char']; - $config['body_truncate_char'] = mb_strlen($po->body) + mb_strlen($append_html); + $config['body_truncate_char'] = \mb_strlen($po->body) + \mb_strlen($append_html); } $po->body .= $append_html; $body .= $po->build(true) . '
'; - if (isset($__old_body_truncate_char)) + if (isset($__old_body_truncate_char)) { $config['body_truncate_char'] = $__old_body_truncate_char; + } $count++; } - mod_page(sprintf('%s (%d)', _('Report queue'), $count), 'mod/reports.html', array('reports' => $body, 'count' => $count)); + mod_page(\sprintf('%s (%d)', _('Report queue'), $count), 'mod/reports.html', [ 'reports' => $body, 'count' => $count ]); } function mod_report_dismiss($id, $all = false) { From c94a7cb40342777d23433a38d29ba17fa2390981 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 19 Oct 2024 21:25:15 +0200 Subject: [PATCH 2/3] pages.php: mod_reports signal if there are more reports than the limit --- inc/mod/pages.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 625a66e6..aee684e4 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2917,10 +2917,11 @@ function mod_reports() { } } - $count = 0; - $body = ''; + $to_build = []; foreach ($reports as $report) { - if (!isset($report_posts[$report['board']][$report['post']])) { + if (isset($report_posts[$report['board']][$report['post']])) { + $to_build[] = $report; + } else { // Invalid report (post has since been deleted) if ($config['auto_maintenance'] != false) { $query = prepare("DELETE FROM ``reports`` WHERE `post` = :id AND `board` = :board"); @@ -2930,7 +2931,17 @@ function mod_reports() { } continue; } + } + if (\count($to_build) > $reports_limit) { + \array_pop($to_build); + $has_extra = true; + } else { + $has_extra = false; + } + + $body = ''; + foreach ($to_build as $report) { openBoard($report['board']); $post = &$report_posts[$report['board']][$report['post']]; @@ -2967,11 +2978,16 @@ function mod_reports() { if (isset($__old_body_truncate_char)) { $config['body_truncate_char'] = $__old_body_truncate_char; } - - $count++; } - mod_page(\sprintf('%s (%d)', _('Report queue'), $count), 'mod/reports.html', [ 'reports' => $body, 'count' => $count ]); + $count = \count($to_build); + $header_count = $has_extra ? "{$count}+" : (string)$count; + + mod_page( + \sprintf('%s (%s)', _('Report queue'), $header_count), + 'mod/reports.html', + [ 'reports' => $body, 'count' => $count ] + ); } function mod_report_dismiss($id, $all = false) { From 09075b146541f01c44edbb876a9a33e55ddbf12b Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 19 Oct 2024 21:42:18 +0200 Subject: [PATCH 3/3] pages.php: mod_reports rework query --- inc/mod/pages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/mod/pages.php b/inc/mod/pages.php index aee684e4..f45fd839 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2911,7 +2911,7 @@ function mod_reports() { foreach ($report_queries as $board => $posts) { $report_posts[$board] = []; - $query = query(\sprintf('SELECT * FROM ``posts_%s`` WHERE `id` = ' . \implode(' OR `id` = ', $posts), $board)) or error(db_error()); + $query = query(\sprintf('SELECT * FROM ``posts_%s`` WHERE `id` IN (' . \implode(',', $posts) . ')', $board)) or error(db_error()); while ($post = $query->fetch(PDO::FETCH_ASSOC)) { $report_posts[$board][$post['id']] = $post; }