From 3471f7c6684b12b63626af33ae408fd13544cae9 Mon Sep 17 00:00:00 2001
From: Michael Foster
Date: Wed, 18 Sep 2013 08:47:34 +1000
Subject: [PATCH 1/3] Optionally show post user was banned for
---
inc/bans.php | 20 ++++++++++++++------
inc/config.php | 7 +++++--
inc/functions.php | 19 ++++++++++++++++---
inc/mod/pages.php | 8 +++++---
templates/banned.html | 7 +++++++
5 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/inc/bans.php b/inc/bans.php
index 652d42cc..853332a0 100644
--- a/inc/bans.php
+++ b/inc/bans.php
@@ -33,7 +33,7 @@ class Bans {
return array(inet_pton($range[0]), inet_pton($range[1]));
}
- private static function parse_time($str) {
+ public static function parse_time($str) {
if (empty($str))
return false;
@@ -141,6 +141,8 @@ class Bans {
$query->bindValue(':id', $ban['id'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
} else {
+ if ($ban['post'])
+ $ban['post'] = json_decode($ban['post'], true);
$ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend']));
$ban_list[] = $ban;
}
@@ -197,8 +199,8 @@ class Bans {
return true;
}
- static public function new_ban($mask, $reason, $length = false, $board = false, $mod_id = false) {
- global $mod, $pdo;
+ static public function new_ban($mask, $reason, $length = false, $ban_board = false, $mod_id = false, $post = false) {
+ global $mod, $pdo, $board;
if ($mod_id === false) {
$mod_id = isset($mod['id']) ? $mod['id'] : -1;
@@ -207,7 +209,7 @@ class Bans {
$range = self::parse_range($mask);
$mask = self::range_to_string($range);
- $query = prepare("INSERT INTO ``bans`` VALUES (NULL, :ipstart, :ipend, :time, :expires, :board, :mod, :reason, 0, NULL)");
+ $query = prepare("INSERT INTO ``bans`` VALUES (NULL, :ipstart, :ipend, :time, :expires, :board, :mod, :reason, 0, :post)");
$query->bindValue(':ipstart', $range[0]);
if ($range[1] !== false && $range[1] != $range[0])
@@ -236,11 +238,17 @@ class Bans {
$query->bindValue(':expires', null, PDO::PARAM_NULL);
}
- if ($board)
- $query->bindValue(':board', $board);
+ if ($ban_board)
+ $query->bindValue(':board', $ban_board);
else
$query->bindValue(':board', null, PDO::PARAM_NULL);
+ if ($post) {
+ $post['board'] = $board['uri'];
+ $query->bindValue(':post', json_encode($post));
+ } else
+ $query->bindValue(':post', null, PDO::PARAM_NULL);
+
$query->execute() or error(db_error($query));
if (isset($mod['id']) && $mod['id'] == $mod_id) {
diff --git a/inc/config.php b/inc/config.php
index d7bb8ecc..84de9cfb 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -821,14 +821,17 @@
// Automatically remove unnecessary whitespace when compiling HTML files from templates.
$config['minify_html'] = true;
+ // Show the post the user was banned for on the "You are banned" page.
+ $config['ban_show_post'] = false;
+
// Optional HTML to append to "You are banned" pages. For example, you could include instructions and/or
// a link to an email address or IRC chat room to appeal the ban.
$config['ban_page_extra'] = '';
-
+
// Display flags (when available). This config option has no effect unless poster flags are enabled (see
// $config['country_flags']). Disable this if you want all previously-assigned flags to be hidden.
$config['display_flags'] = true;
-
+
// Location of post flags/icons (where "%s" is the flag name). Defaults to static/flags/%s.png.
// $config['uri_flags'] = 'http://static.example.org/flags/%s.png';
diff --git a/inc/functions.php b/inc/functions.php
index f7421f68..bc159e88 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -617,22 +617,35 @@ function ago($timestamp) {
}
function displayBan($ban) {
- global $config;
+ global $config, $board;
if (!$ban['seen']) {
Bans::seen($ban['id']);
}
$ban['ip'] = $_SERVER['REMOTE_ADDR'];
-
+ if ($ban['post'] && isset($ban['post']['board'], $ban['post']['id'])) {
+ openBoard($ban['post']['board']);
+
+ $query = query(sprintf("SELECT `thumb`, `file` FROM ``posts_%s`` WHERE `id` = " . (int)$ban['post']['id'], $board['uri']));
+ if ($_post = $query->fetch(PDO::FETCH_ASSOC)) {
+ $ban['post'] = array_merge($ban['post'], $_post);
+ } else {
+ $ban['post']['file'] = 'deleted';
+ $ban['post']['thumb'] = false;
+ }
+ $post = new Post($ban['post']);
+ }
// Show banned page and exit
die(
Element('page.html', array(
'title' => _('Banned!'),
'config' => $config,
+ 'nojavascript' => true,
'body' => Element('banned.html', array(
'config' => $config,
- 'ban' => $ban
+ 'ban' => $ban,
+ 'post' => isset($post) ? $post->build() : false
)
))
));
diff --git a/inc/mod/pages.php b/inc/mod/pages.php
index c1f35c87..525a3d16 100644
--- a/inc/mod/pages.php
+++ b/inc/mod/pages.php
@@ -1167,7 +1167,8 @@ function mod_ban_post($board, $delete, $post, $token = false) {
$security_token = make_secure_link_token($board . '/ban/' . $post);
- $query = prepare(sprintf('SELECT `ip`, `thread` FROM ``posts_%s`` WHERE `id` = :id', $board));
+ $query = prepare(sprintf('SELECT ' . ($config['ban_show_post'] ? '*' : '`ip`, `thread`') .
+ ' FROM ``posts_%s`` WHERE `id` = :id', $board));
$query->bindValue(':id', $post);
$query->execute() or error(db_error($query));
if (!$_post = $query->fetch(PDO::FETCH_ASSOC))
@@ -1182,11 +1183,12 @@ function mod_ban_post($board, $delete, $post, $token = false) {
if (isset($_POST['ip']))
$ip = $_POST['ip'];
- Bans::new_ban($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'] == '*' ? false : $_POST['board']);
+ Bans::new_ban($_POST['ip'], $_POST['reason'], $_POST['length'], $_POST['board'] == '*' ? false : $_POST['board'],
+ false, $config['ban_show_post'] ? $_post : false);
if (isset($_POST['public_message'], $_POST['message'])) {
// public ban message
- $length_english = parse_time($_POST['length']) ? 'for ' . until(parse_time($_POST['length'])) : 'permanently';
+ $length_english = Bans::parse_time($_POST['length']) ? 'for ' . until(Bans::parse_time($_POST['length'])) : 'permanently';
$_POST['message'] = preg_replace('/[\r\n]/', '', $_POST['message']);
$_POST['message'] = str_replace('%length%', $length_english, $_POST['message']);
$_POST['message'] = str_replace('%LENGTH%', strtoupper($length_english), $_POST['message']);
diff --git a/templates/banned.html b/templates/banned.html
index 065d61e2..55dbffe0 100644
--- a/templates/banned.html
+++ b/templates/banned.html
@@ -77,6 +77,13 @@
{% trans %}Your IP address is{% endtrans %} {{ ban.ip }}.
+ {% if post %}
+
+ You were banned for the following post:
+ {{ post }}
+
+ {% endif %}
+
{% if config.ban_page_extra %}
{{ config.ban_page_extra }}
{% endif %}
From 57e4292e9de44682d128e96397397d72b7bd3ede Mon Sep 17 00:00:00 2001
From: Michael Foster
Date: Wed, 18 Sep 2013 08:56:04 +1000
Subject: [PATCH 2/3] Improvements to showing post in ban
---
inc/functions.php | 10 ++++++++--
templates/banned.html | 2 +-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/inc/functions.php b/inc/functions.php
index bc159e88..cfde4640 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -634,7 +634,12 @@ function displayBan($ban) {
$ban['post']['file'] = 'deleted';
$ban['post']['thumb'] = false;
}
- $post = new Post($ban['post']);
+
+ if ($ban['post']['thread']) {
+ $post = new Post($ban['post']);
+ } else {
+ $post = new Thread($ban['post'], null, false, false);
+ }
}
// Show banned page and exit
die(
@@ -645,7 +650,8 @@ function displayBan($ban) {
'body' => Element('banned.html', array(
'config' => $config,
'ban' => $ban,
- 'post' => isset($post) ? $post->build() : false
+ 'board' => $board,
+ 'post' => isset($post) ? $post->build(true) : false
)
))
));
diff --git a/templates/banned.html b/templates/banned.html
index 55dbffe0..79648156 100644
--- a/templates/banned.html
+++ b/templates/banned.html
@@ -79,7 +79,7 @@
{% if post %}
- You were banned for the following post:
+ You were banned for the following post on {{ board.url }}:
{{ post }}
{% endif %}
From 840e8cd0936ad9577a6cecf56120716af77bdf6a Mon Sep 17 00:00:00 2001
From: Michael Foster
Date: Wed, 18 Sep 2013 08:59:36 +1000
Subject: [PATCH 3/3] use own class's delete function when removing expiring
ban
---
inc/bans.php | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/inc/bans.php b/inc/bans.php
index 853332a0..cf24f097 100644
--- a/inc/bans.php
+++ b/inc/bans.php
@@ -137,9 +137,7 @@ class Bans {
while ($ban = $query->fetch(PDO::FETCH_ASSOC)) {
if ($ban['expires'] && ($ban['seen'] || !$config['require_ban_view']) && $ban['expires'] < time()) {
- $query = prepare("DELETE FROM ``bans`` WHERE `id` = :id");
- $query->bindValue(':id', $ban['id'], PDO::PARAM_INT);
- $query->execute() or error(db_error($query));
+ self::delete($ban['id']);
} else {
if ($ban['post'])
$ban['post'] = json_decode($ban['post'], true);