Merge branch '27-improve-reports' into 'config'

Resolve "Increase the number of reports displayed in the reports page"

Closes #27

See merge request leftypol/leftypol!5
This commit is contained in:
Zankaria Auxa 2024-11-12 13:20:58 +00:00
commit aaa725dd06

View file

@ -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,16 +2911,17 @@ 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;
}
}
$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");
@ -2927,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']];
@ -2951,23 +2965,29 @@ 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, '<br>'));
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) . '<hr>';
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));
$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) {