diff options
| -rw-r--r-- | inc/config.php | 3 | ||||
| -rw-r--r-- | inc/contrib/Twig/Extensions/Extension/Tinyboard.php | 15 | ||||
| -rw-r--r-- | inc/functions.php | 82 | ||||
| -rw-r--r-- | inc/template.php | 2 | ||||
| -rw-r--r-- | templates/banned.html | 70 |
5 files changed, 99 insertions, 73 deletions
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 = '<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 ( 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'] .= '<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']);
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 #} +<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 %} |
