From 51cdaaccd1489e7f62d90058d12aa6bceafb2d3f Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Wed, 23 Nov 2011 16:12:19 +1100 Subject: [PATCH] Use template instead of inline HTML for ban messages. --- inc/config.php | 3 + .../Twig/Extensions/Extension/Tinyboard.php | 15 +++- inc/functions.php | 82 +++---------------- inc/template.php | 2 +- templates/banned.html | 70 ++++++++++++++++ 5 files changed, 99 insertions(+), 73 deletions(-) create mode 100644 templates/banned.html diff --git a/inc/config.php b/inc/config.php index d6b10f0e..40382918 100644 --- a/inc/config.php +++ b/inc/config.php @@ -447,6 +447,9 @@ // http://www.php.net/manual/en/function.strftime.php $config['post_date'] = '%m/%d/%y (%a) %H:%M:%S'; + // Same as above, but used for "you are banned' pages. + $config['ban_date'] = '%A, %e %B, %Y'; + // The names on the post buttons. (On most imageboards, these are both "Post") $config['button_newtopic'] = 'New Topic'; $config['button_reply'] = 'New Reply'; diff --git a/inc/contrib/Twig/Extensions/Extension/Tinyboard.php b/inc/contrib/Twig/Extensions/Extension/Tinyboard.php index cb6f46b8..49db4046 100644 --- a/inc/contrib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/contrib/Twig/Extensions/Extension/Tinyboard.php @@ -20,7 +20,20 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension 'date' => new Twig_Filter_Function('twig_date_filter', array('needs_environment' => false)), 'poster_id' => new Twig_Filter_Function('poster_id', array('needs_environment' => false)), 'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter', array('needs_environment' => false)), - 'count' => new Twig_Filter_Function('count', array('needs_environment' => false)) + 'count' => new Twig_Filter_Function('count', array('needs_environment' => false)), + 'until' => new Twig_Filter_Function('until', array('needs_environment' => false)) + ); + } + + /** + * Returns a list of functions to add to the existing list. + * + * @return array An array of filters + */ + public function getFunctions() + { + return Array( + 'time' => new Twig_Filter_Function('time', array('needs_environment' => false)) ); } diff --git a/inc/functions.php b/inc/functions.php index 7934a53a..ef3a7ef9 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -453,81 +453,21 @@ } } - function formatDate($timestamp) { - return date('jS F, Y', $timestamp); - } - function displayBan($ban) { global $config; - $body = '
-

You are banned! ;_;

-

You have been banned from ' . - (!isset($ban['uri']) ? - 'all boards': - '' . sprintf($config['board_abbreviation'], $ban['uri']) . '' - ) . - ' ' . - ($ban['reason'] ? 'for the following reason:' : 'for an unspecified reason.') . - '

' . - ($ban['reason'] ? - '

' . - $ban['reason'] . - '

' - : '') . - '

Your ban was filed on ' . - formatDate($ban['set']) . - ', and ' . - ($ban['expires'] ? - 'expires ' . until($ban['expires']) . ' from now, which is on ' . - formatDate($ban['expires']) . - ' - ' - : 'will not expire.' ) . - '

-

Your IP address is ' . $_SERVER['REMOTE_ADDR'] . '.

-
'; - + $ban['ip'] = $_SERVER['REMOTE_ADDR']; + // Show banned page and exit - die(Element('page.html', Array( + die( + Element('page.html', Array( + 'title' => 'Banned!', 'config' => $config, - 'title' => 'Banned', - 'subtitle' => 'You are banned!', - 'body' => $body - ) + 'body' => Element('banned.html', Array( + 'config' => $config, + 'ban' => $ban + ) + )) )); } @@ -549,7 +489,7 @@ $query->bindValue(':board', $board); $query->execute() or error(db_error($query)); } - if($query->rowCount() < 1 && $config['ban_cidr']) { + if($query->rowCount() < 1 && $config['ban_cidr'] && !isIPv6()) { // my most insane SQL query yet $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri`, `bans`.`id` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` WHERE (`board` IS NULL OR `uri` = :board) AND ( diff --git a/inc/template.php b/inc/template.php index 228629bb..33febdbc 100644 --- a/inc/template.php +++ b/inc/template.php @@ -28,7 +28,7 @@ unset($debug['start']); } - $options['body'] .= '

Debug

' . str_replace("\n", '
', print_r($debug, true)) . '

'; + $options['body'] .= '

Debug

' . str_replace("\n", '
', print_r($debug, true)) . '
'; } $loader->setPaths($config['dir']['template']); diff --git a/templates/banned.html b/templates/banned.html new file mode 100644 index 00000000..9b9ad35c --- /dev/null +++ b/templates/banned.html @@ -0,0 +1,70 @@ +{% filter remove_whitespace %} +{# Automatically removes unnecessary whitespace #} +
+

You are banned! ;_;

+

+ You have been banned from + {% if ban.uri %} + {{ config.board_abbreviation|sprintf(ban.uri) }} + {% else %} + all boards + {% endif %} + {% if ban.reason %} + for the following reason: + {% else %} + for an unspecified reason. + {% endif %} +

+ {% if ban.reason %} +

+ {{ ban.reason }} +

+ {% endif %} +

+ Your ban was filed on + {{ ban.set|date(config.ban_date) }} and + {% if ban.expires %} + expires {{ ban.expires|until }} from now, which is on + + {{ ban.expires|date(config.ban_date) }} + + + {% else %} + will not expire. + {% endif %} + +

+

Your IP address is {{ ban.ip }}.

+
+{% endfilter %}