Use template instead of inline HTML for ban messages.
This commit is contained in:
parent
7ecebe4616
commit
51cdaaccd1
@ -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';
|
||||
|
@ -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))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -453,81 +453,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate($timestamp) {
|
||||
return date('jS F, Y', $timestamp);
|
||||
}
|
||||
|
||||
function displayBan($ban) {
|
||||
global $config;
|
||||
|
||||
$body = '<div class="ban">
|
||||
<h2>You are banned! ;_;</h2>
|
||||
<p>You have been banned from ' .
|
||||
(!isset($ban['uri']) ?
|
||||
'all boards':
|
||||
'<strong>' . sprintf($config['board_abbreviation'], $ban['uri']) . '</strong>'
|
||||
) .
|
||||
' ' .
|
||||
($ban['reason'] ? 'for the following reason:' : 'for an unspecified reason.') .
|
||||
'</p>' .
|
||||
($ban['reason'] ?
|
||||
'<p class="reason">' .
|
||||
$ban['reason'] .
|
||||
'</p>'
|
||||
: '') .
|
||||
'<p>Your ban was filed on <strong>' .
|
||||
formatDate($ban['set']) .
|
||||
'</strong>, and <span id="expires">' .
|
||||
($ban['expires'] ?
|
||||
'expires <span id="countdown">' . until($ban['expires']) . '</span> from now, which is on <strong>' .
|
||||
formatDate($ban['expires']) .
|
||||
'</strong>
|
||||
<script>
|
||||
// return date("jS F, Y", $timestamp);
|
||||
var secondsLeft = ' . ($ban['expires'] - time()) . '
|
||||
var end = new Date().getTime() + secondsLeft*1000;
|
||||
function updateExpiresTime() {
|
||||
countdown.firstChild.nodeValue = until(end);
|
||||
}
|
||||
function until(end) {
|
||||
var now = new Date().getTime();
|
||||
var diff = Math.round((end - now) / 1000); // in seconds
|
||||
if (diff < 0) {
|
||||
document.getElementById("expires").innerHTML = "has since expired. Refresh the page to continue.";
|
||||
//location.reload(true);
|
||||
clearInterval(int);
|
||||
return "";
|
||||
} else if (diff < 60) {
|
||||
return diff + " second" + (diff == 1 ? "" : "s");
|
||||
} else if (diff < 60*60) {
|
||||
return (num = Math.round(diff/(60))) + " minute" + (num == 1 ? "" : "s");
|
||||
} else if (diff < 60*60*24) {
|
||||
return (num = Math.round(diff/(60*60))) + " hour" + (num == 1 ? "" : "s");
|
||||
} else if (diff < 60*60*24*7) {
|
||||
return (num = Math.round(diff/(60*60*24))) + " day" + (num == 1 ? "" : "s");
|
||||
} else if (diff < 60*60*24*365) {
|
||||
return (num = Math.round(diff/(60*60*24*7))) + " week" + (num == 1 ? "" : "s");
|
||||
} else {
|
||||
return (num = Math.round(diff/(60*60*24*365))) + " year" + (num == 1 ? "" : "s");
|
||||
}
|
||||
}
|
||||
var countdown = document.getElementById("countdown");
|
||||
|
||||
updateExpiresTime();
|
||||
var int = setInterval(updateExpiresTime, 1000);
|
||||
</script>'
|
||||
: '<em>will not expire</em>.' ) .
|
||||
'</span></p>
|
||||
<p>Your IP address is <strong>' . $_SERVER['REMOTE_ADDR'] . '</strong>.</p>
|
||||
</div>';
|
||||
$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 (
|
||||
|
@ -28,7 +28,7 @@
|
||||
unset($debug['start']);
|
||||
|
||||
}
|
||||
$options['body'] .= '<h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' . str_replace("\n", '<br/>', print_r($debug, true)) . '</pre><hr/>';
|
||||
$options['body'] .= '<hr/><h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' . str_replace("\n", '<br/>', print_r($debug, true)) . '</pre>';
|
||||
}
|
||||
|
||||
$loader->setPaths($config['dir']['template']);
|
||||
|
70
templates/banned.html
Normal file
70
templates/banned.html
Normal file
@ -0,0 +1,70 @@
|
||||
{% filter remove_whitespace %}
|
||||
{# Automatically removes unnecessary whitespace #}
|
||||
<div class="ban">
|
||||
<h2>You are banned! ;_;</h2>
|
||||
<p>
|
||||
You have been banned from
|
||||
{% if ban.uri %}
|
||||
<strong>{{ config.board_abbreviation|sprintf(ban.uri) }}</strong>
|
||||
{% else %}
|
||||
all boards
|
||||
{% endif %}
|
||||
{% if ban.reason %}
|
||||
for the following reason:
|
||||
{% else %}
|
||||
for an unspecified reason.
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if ban.reason %}
|
||||
<p class="reason">
|
||||
{{ ban.reason }}
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
Your ban was filed on
|
||||
<strong>{{ ban.set|date(config.ban_date) }}</strong> and <span id="expires">
|
||||
{% if ban.expires %}
|
||||
expires <span id="countdown">{{ ban.expires|until }}</span> from now, which is on
|
||||
<strong>
|
||||
{{ ban.expires|date(config.ban_date) }}
|
||||
</strong>
|
||||
<script>
|
||||
var secondsLeft = {{ ban.expires - time() }};
|
||||
var end = new Date().getTime() + secondsLeft*1000;
|
||||
function updateExpiresTime() {
|
||||
countdown.firstChild.nodeValue = until(end);
|
||||
}
|
||||
function until(end) {
|
||||
var now = new Date().getTime();
|
||||
var diff = Math.round((end - now) / 1000);
|
||||
if (diff < 0) {
|
||||
document.getElementById("expires").innerHTML = "has since expired. Refresh the page to continue.";
|
||||
clearInterval(int);
|
||||
return "";
|
||||
} else if (diff < 60) {
|
||||
return diff + " second" + (diff == 1 ? "" : "s");
|
||||
} else if (diff < 60*60) {
|
||||
return (num = Math.round(diff/(60))) + " minute" + (num == 1 ? "" : "s");
|
||||
} else if (diff < 60*60*24) {
|
||||
return (num = Math.round(diff/(60*60))) + " hour" + (num == 1 ? "" : "s");
|
||||
} else if (diff < 60*60*24*7) {
|
||||
return (num = Math.round(diff/(60*60*24))) + " day" + (num == 1 ? "" : "s");
|
||||
} else if (diff < 60*60*24*365) {
|
||||
return (num = Math.round(diff/(60*60*24*7))) + " week" + (num == 1 ? "" : "s");
|
||||
} else {
|
||||
return (num = Math.round(diff/(60*60*24*365))) + " year" + (num == 1 ? "" : "s");
|
||||
}
|
||||
}
|
||||
var countdown = document.getElementById("countdown");
|
||||
|
||||
updateExpiresTime();
|
||||
var int = setInterval(updateExpiresTime, 1000);
|
||||
</script>
|
||||
{% else %}
|
||||
<em>will not expire</em>.
|
||||
{% endif %}
|
||||
</span>
|
||||
</p>
|
||||
<p>Your IP address is <strong>{{ ban.ip }}</strong>.</p>
|
||||
</div>
|
||||
{% endfilter %}
|
Loading…
Reference in New Issue
Block a user