Browse Source

Optionally show post user was banned for

pull/40/head
Michael Foster 11 years ago
parent
commit
3471f7c668
  1. 20
      inc/bans.php
  2. 3
      inc/config.php
  3. 17
      inc/functions.php
  4. 8
      inc/mod/pages.php
  5. 7
      templates/banned.html

20
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) {

3
inc/config.php

@ -821,6 +821,9 @@
// 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'] = '';

17
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
)
))
));

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

7
templates/banned.html

@ -77,6 +77,13 @@
</p>
<p>{% trans %}Your IP address is{% endtrans %} <strong>{{ ban.ip }}</strong>.</p>
{% if post %}
<hr>
<p>You were banned for the following post:</p>
{{ post }}
<br>
{% endif %}
{% if config.ban_page_extra %}
<p>{{ config.ban_page_extra }}</p>
{% endif %}

Loading…
Cancel
Save