Ban appeals: limit by board, make more efficient, enable in infinity

This commit is contained in:
8chan 2015-01-06 01:34:27 -08:00
parent 437ff83696
commit 0a2dfedb0e
4 changed files with 29 additions and 28 deletions

View File

@ -355,7 +355,7 @@ class Post {
} }
if (isset($this->files) && $this->files) { if (isset($this->files) && $this->files) {
$this->files = json_decode($this->files); $this->files = is_string($this->files) ? json_decode($this->files) : $this->files;
// Compatibility for posts before individual file hashing // Compatibility for posts before individual file hashing
foreach ($this->files as $i => &$file) { foreach ($this->files as $i => &$file) {
if (empty($file)) { if (empty($file)) {
@ -453,7 +453,7 @@ class Thread extends Post {
} }
if (isset($this->files)) if (isset($this->files))
$this->files = json_decode($this->files); $this->files = is_string($this->files) ? json_decode($this->files) : $this->files;
$this->subject = utf8tohtml($this->subject); $this->subject = utf8tohtml($this->subject);
$this->name = utf8tohtml($this->name); $this->name = utf8tohtml($this->name);

View File

@ -228,6 +228,7 @@ $config['early_404_page'] = 5;
$config['early_404_replies'] = 10; $config['early_404_replies'] = 10;
$config['cron_bans'] = true; $config['cron_bans'] = true;
$config['mask_db_error'] = true; $config['mask_db_error'] = true;
$config['ban_appeals'] = true;
// 8chan specific mod pages // 8chan specific mod pages
require '8chan-mod-pages.php'; require '8chan-mod-pages.php';

View File

@ -1046,7 +1046,7 @@ function mod_bans_json() {
} }
function mod_ban_appeals() { function mod_ban_appeals() {
global $config, $board; global $config, $board, $mod;
if (!hasPermission($config['mod']['view_ban_appeals'])) if (!hasPermission($config['mod']['view_ban_appeals']))
error($config['error']['noaccess']); error($config['error']['noaccess']);
@ -1065,6 +1065,9 @@ function mod_ban_appeals() {
if (!$ban = $query->fetch(PDO::FETCH_ASSOC)) { if (!$ban = $query->fetch(PDO::FETCH_ASSOC)) {
error(_('Ban appeal not found!')); error(_('Ban appeal not found!'));
} }
if (!in_array($ban['board'], $mod['boards']))
error($config['error']['noaccess']);
$ban['mask'] = Bans::range_to_string(array($ban['ipstart'], $ban['ipend'])); $ban['mask'] = Bans::range_to_string(array($ban['ipstart'], $ban['ipend']));
@ -1080,11 +1083,18 @@ function mod_ban_appeals() {
header('Location: ?/ban-appeals', true, $config['redirect_http']); header('Location: ?/ban-appeals', true, $config['redirect_http']);
return; return;
} }
$local = ($mod['type'] == MOD || $mod["type"] == BOARDVOLUNTEER);
$query = query("SELECT *, ``ban_appeals``.`id` AS `id` FROM ``ban_appeals`` $query = prepare("SELECT *, ``ban_appeals``.`id` AS `id` FROM ``ban_appeals``
LEFT JOIN ``bans`` ON `ban_id` = ``bans``.`id` LEFT JOIN ``bans`` ON `ban_id` = ``bans``.`id`
LEFT JOIN ``mods`` ON ``bans``.`creator` = ``mods``.`id` LEFT JOIN ``mods`` ON ``bans``.`creator` = ``mods``.`id`
WHERE `denied` != 1 ORDER BY `time`") or error(db_error()); WHERE `denied` != 1 ".($local ? " AND ``bans``.`board` = :board " : "")." ORDER BY `time`");
if ($local) {
$query->bindValue(':board', $mod['boards'][0]);
}
$query->execute() or error(db_error());
$ban_appeals = $query->fetchAll(PDO::FETCH_ASSOC); $ban_appeals = $query->fetchAll(PDO::FETCH_ASSOC);
foreach ($ban_appeals as &$ban) { foreach ($ban_appeals as &$ban) {
if ($ban['post']) if ($ban['post'])
@ -1092,29 +1102,14 @@ function mod_ban_appeals() {
$ban['mask'] = Bans::range_to_string(array($ban['ipstart'], $ban['ipend'])); $ban['mask'] = Bans::range_to_string(array($ban['ipstart'], $ban['ipend']));
if ($ban['post'] && isset($ban['post']['board'], $ban['post']['id'])) { if ($ban['post'] && isset($ban['post']['board'], $ban['post']['id'])) {
if (openBoard($ban['post']['board'])) { openBoard($ban['post']['board']);
$query = query(sprintf("SELECT `num_files`, `files` FROM ``posts_%s`` WHERE `id` = " .
(int)$ban['post']['id'], $board['uri']));
if ($_post = $query->fetch(PDO::FETCH_ASSOC)) {
$_post['files'] = $_post['files'] ? json_decode($_post['files']) : array();
$ban['post'] = array_merge($ban['post'], $_post);
} else {
$ban['post']['files'] = array(array());
$ban['post']['files'][0]['file'] = 'deleted';
$ban['post']['files'][0]['thumb'] = false;
$ban['post']['num_files'] = 1;
}
} else {
$ban['post']['files'] = array(array());
$ban['post']['files'][0]['file'] = 'deleted';
$ban['post']['files'][0]['thumb'] = false;
$ban['post']['num_files'] = 1;
}
if ($ban['post']['thread']) { if ($ban['post']['thread']) {
$ban['post'] = new Post($ban['post']); $po = new Post($ban['post']);
$ban['post'] = $po->build(true);
} else { } else {
$ban['post'] = new Thread($ban['post'], null, false, false); $po = new Thread($ban['post'], null, false, false);
$ban['post'] = $po->build(true);
} }
} }
} }

View File

@ -18,6 +18,11 @@
<th>{% trans 'IP' %}</th> <th>{% trans 'IP' %}</th>
<td>{{ ban.mask }}</td> <td>{{ ban.mask }}</td>
</tr> </tr>
{% elseif mod|hasPermission(config.mod.show_ip_less, board.uri) %}
<tr>
<th>{% trans 'IP' %}</th>
<td>{{ ban.mask|less_ip }}</td>
</tr>
{% endif %} {% endif %}
<tr> <tr>
<th>{% trans 'Reason' %}</th> <th>{% trans 'Reason' %}</th>
@ -98,10 +103,10 @@
{% if ban.post %} {% if ban.post %}
<div style=""> <div style="">
{{ ban.post.build(true) }} {{ ban.post }}
</div> </div>
{% endif %} {% endif %}
</form> </form>
<hr> <hr>
{% endfor %} {% endfor %}