1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-12 01:50:48 +01:00

report queue

This commit is contained in:
Michael Save 2012-04-16 17:28:57 +10:00
parent ad55a634bf
commit 41e1a2481b
5 changed files with 155 additions and 1 deletions

View File

@ -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']);
}

View File

@ -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();
}

View File

@ -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

26
templates/mod/report.html Normal file
View File

@ -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>

View File

@ -0,0 +1,5 @@
{% if reports %}
{{ reports }}
{% else %}
<p style="text-align:center" class="unimportant">(There are no reports.)</p>
{% endif %}