diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 60f101ea..2532e2e7 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -469,3 +469,124 @@ function mod_rebuild() { mod_page("Rebuild", 'mod/rebuild.html', array('boards' => listBoards())); } +function mod_reports() { + global $config, $mod; + + if (!hasPermission($config['mod']['reports'])) + error($config['error']['noaccess']); + + $query = prepare("SELECT * FROM `reports` ORDER BY `time` DESC LIMIT :limit"); + $query->bindValue(':limit', $config['mod']['recent_reports'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + $reports = $query->fetchAll(PDO::FETCH_ASSOC); + + $report_queries = array(); + foreach ($reports as $report) { + if (!isset($report_queries[$report['board']])) + $report_queries[$report['board']] = array(); + $report_queries[$report['board']][] = $report['post']; + } + + $report_posts = array(); + foreach ($report_queries as $board => $posts) { + $report_posts[$board] = array(); + + $query = query(sprintf('SELECT * FROM `posts_%s` WHERE `id` = ' . implode(' OR `id` = ', $posts), $board)) or error(db_error()); + while ($post = $query->fetch()) { + $report_posts[$board][$post['id']] = $post; + } + } + + $body = ''; + foreach ($reports as $report) { + if (!isset($report_posts[$report['board']][$report['post']])) { + // // Invalid report (post has since been deleted) + $query = prepare("DELETE FROM `reports` WHERE `post` = :id AND `board` = :board"); + $query->bindValue(':id', $report['post'], PDO::PARAM_INT); + $query->bindValue(':board', $report['board']); + $query->execute() or error(db_error($query)); + continue; + } + + openBoard($report['board']); + + $post = &$report_posts[$report['board']][$report['post']]; + + if (!$post['thread']) { + // Still need to fix this: + $po = new Thread( + $post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], + $post['capcode'], $post['body'], $post['time'], $post['thumb'], + $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], + $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], + $post['locked'], $post['sage'], $post['embed'], '?/', $mod, false + ); + } else { + $po = new Post( + $post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], + $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], + $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod + ); + } + + // a little messy and inefficient + $append_html = Element('mod/report.html', array('report' => $report, 'config' => $config, 'mod' => $mod)); + + // 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']) { + // 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); + } + + $po->body .= $append_html; + + $body .= $po->build(true) . '
'; + + if(isset($__old_body_truncate_char)) + $config['body_truncate_char'] = $__old_body_truncate_char; + } + + mod_page("Report queue", 'mod/reports.html', array('reports' => $body)); +} + +function mod_report_dismiss($id, $all = false) { + global $config; + + $query = prepare("SELECT `post`, `board`, `ip` FROM `reports` WHERE `id` = :id"); + $query->bindValue(':id', $id); + $query->execute() or error(db_error($query)); + if ($report = $query->fetch(PDO::FETCH_ASSOC)) { + $ip = $report['ip']; + $board = $report['board']; + $post = $report['post']; + } else + error($config['error']['404']); + + if (!$all && !hasPermission($config['mod']['report_dismiss'], $board)) + error($config['error']['noaccess']); + + if ($all && !hasPermission($config['mod']['report_dismiss_ip'], $board)) + error($config['error']['noaccess']); + + if ($all) { + $query = prepare("DELETE FROM `reports` WHERE `ip` = :ip"); + $query->bindValue(':ip', $ip); + } else { + $query = prepare("DELETE FROM `reports` WHERE `id` = :id"); + $query->bindValue(':id', $id); + } + $query->execute() or error(db_error($query)); + + + if ($all) + modLog("Dismissed all reports by $ip"); + else + modLog("Dismissed a report for post #{$id}", $board); + + header('Location: ?/reports', true, $config['redirect_http']); +} + + diff --git a/inc/template.php b/inc/template.php index 8d679d25..5355e18c 100644 --- a/inc/template.php +++ b/inc/template.php @@ -39,7 +39,7 @@ function Element($templateFile, array $options) { if (!$twig) load_twig(); - if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod']))) { + if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) { $options['pm'] = create_pm_header(); } diff --git a/mod.php b/mod.php index 6fc216f8..78205bd3 100644 --- a/mod.php +++ b/mod.php @@ -33,6 +33,8 @@ $pages = array( '!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm '!^/rebuild$!' => 'rebuild', // rebuild static files + '!^/reports$!' => 'reports', // report queue + '!^/reports/(\d+)/dismiss(all)?$!' => 'report_dismiss', // dismiss a report '!^/ban$!' => 'ban', // new ban '!^/IP/([\w.:]+)$!' => 'ip', // view ip address diff --git a/templates/mod/report.html b/templates/mod/report.html new file mode 100644 index 00000000..c84e3c89 --- /dev/null +++ b/templates/mod/report.html @@ -0,0 +1,26 @@ +
+
+ Board: {{ config.board_abbreviation|sprintf(report.board) }} +
+ Reason: {{ report.reason }} +
+ Report date: {{ report.time|date(config.post_date) }} +
+ {% if mod|hasPermission(config.mod.show_ip, report.board) %} + Reported by: {{ report.ip }} +
+ {% endif %} + {% if mod|hasPermission(config.mod.report_dismiss, report.board) or mod|hasPermission(config.mod.report_dismiss_ip, report.board) %} +
+ {% if mod|hasPermission(config.mod.report_dismiss, report.board) %} + Dismiss + {% endif %} + {% if mod|hasPermission(config.mod.report_dismiss_ip, report.board) %} + {% if mod|hasPermission(config.mod.report_dismiss, report.board) %} + | + {% endif %} + Dismiss+ + {% endif %} + {% endif %} +
+ diff --git a/templates/mod/reports.html b/templates/mod/reports.html new file mode 100644 index 00000000..37322e35 --- /dev/null +++ b/templates/mod/reports.html @@ -0,0 +1,5 @@ +{% if reports %} + {{ reports }} +{% else %} +

(There are no reports.)

+{% endif %}