Merge branch 'master' of https://github.com/savetheinternet/Tinyboard into vichan-devel-4.5

Conflicts:
	inc/config.php
This commit is contained in:
czaks 2013-09-17 19:12:19 -04:00
commit 8ca495e5b8
5 changed files with 54 additions and 17 deletions

View File

@ -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;
@ -137,10 +137,10 @@ 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);
$ban['mask'] = self::range_to_string(array($ban['ipstart'], $ban['ipend']));
$ban_list[] = $ban;
}
@ -197,8 +197,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 +207,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 +236,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) {

View File

@ -854,14 +854,17 @@
// 'bottom' => '',
// );
// 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';

View File

@ -620,22 +620,41 @@ 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;
}
if ($ban['post']['thread']) {
$post = new Post($ban['post']);
} else {
$post = new Thread($ban['post'], null, false, false);
}
}
// 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,
'board' => $board,
'post' => isset($post) ? $post->build(true) : false
)
))
));

View File

@ -1275,7 +1275,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))
@ -1290,11 +1291,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']);

View File

@ -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 on {{ board.url }}:</p>
{{ post }}
<br>
{% endif %}
{% if config.ban_page_extra %}
<p>{{ config.ban_page_extra }}</p>
{% endif %}