pages.php: format mod_reports

This commit is contained in:
Zankaria 2024-10-19 19:56:23 +02:00
parent 82391e0f83
commit e7518dfe25

View file

@ -2892,15 +2892,18 @@ function mod_reports() {
if (!hasPermission($config['mod']['reports'])) if (!hasPermission($config['mod']['reports']))
error($config['error']['noaccess']); error($config['error']['noaccess']);
$reports_limit = $config['mod']['recent_reports'];
$query = prepare("SELECT * FROM ``reports`` ORDER BY `time` DESC LIMIT :limit"); $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)); $query->execute() or error(db_error($query));
$reports = $query->fetchAll(PDO::FETCH_ASSOC); $reports = $query->fetchAll(PDO::FETCH_ASSOC);
$report_queries = []; $report_queries = [];
foreach ($reports as $report) { 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_queries[$report['board']][] = $report['post']; $report_queries[$report['board']][] = $report['post'];
} }
@ -2908,7 +2911,7 @@ function mod_reports() {
foreach ($report_queries as $board => $posts) { foreach ($report_queries as $board => $posts) {
$report_posts[$board] = []; $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)) { while ($post = $query->fetch(PDO::FETCH_ASSOC)) {
$report_posts[$board][$post['id']] = $post; $report_posts[$board][$post['id']] = $post;
} }
@ -2951,23 +2954,24 @@ function mod_reports() {
// Bug fix for https://github.com/savetheinternet/Tinyboard/issues/21 // 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>')); $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 // still too long; temporarily increase limit in the config
$__old_body_truncate_char = $config['body_truncate_char']; $__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; $po->body .= $append_html;
$body .= $po->build(true) . '<hr>'; $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; $config['body_truncate_char'] = $__old_body_truncate_char;
}
$count++; $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) { function mod_report_dismiss($id, $all = false) {