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 %}