summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/mod/pages.php121
-rw-r--r--inc/template.php2
-rw-r--r--mod.php2
-rw-r--r--templates/mod/report.html26
-rw-r--r--templates/mod/reports.html5
5 files changed, 155 insertions, 1 deletions
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, '<br>'));
+
+ 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) . '<hr>';
+
+ 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 <a href=\"?/IP/$ip\">$ip</a>");
+ 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 @@
+<div class="report">
+ <hr>
+ Board: <a href="?/{{ report.board }}/{{ config.file_index }}">{{ config.board_abbreviation|sprintf(report.board) }}</a>
+ <br>
+ Reason: {{ report.reason }}
+ <br>
+ Report date: {{ report.time|date(config.post_date) }}
+ <br>
+ {% if mod|hasPermission(config.mod.show_ip, report.board) %}
+ Reported by: <a href="?/IP/{{ report.ip }}">{{ report.ip }}</a>
+ <br>
+ {% endif %}
+ {% if mod|hasPermission(config.mod.report_dismiss, report.board) or mod|hasPermission(config.mod.report_dismiss_ip, report.board) %}
+ <hr>
+ {% if mod|hasPermission(config.mod.report_dismiss, report.board) %}
+ <a title="Discard abuse report" href="?/reports/{{ report.id }}/dismiss">Dismiss</a>
+ {% endif %}
+ {% if mod|hasPermission(config.mod.report_dismiss_ip, report.board) %}
+ {% if mod|hasPermission(config.mod.report_dismiss, report.board) %}
+ |
+ {% endif %}
+ <a title="Discard all abuse reports by this IP address" href="?/reports/{{ report.id }}/dismissall">Dismiss+</a>
+ {% endif %}
+ {% endif %}
+</div>
+
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 %}
+ <p style="text-align:center" class="unimportant">(There are no reports.)</p>
+{% endif %}