Paginate ?/noticeboard

This commit is contained in:
Michael Save 2012-04-21 15:15:32 +10:00
parent 2c1f14d24b
commit 2a301de29f
7 changed files with 125 additions and 10 deletions

View File

@ -832,8 +832,8 @@
// Maximum number of results to display for a search, per board
$config['mod']['search_results'] = 75;
// Maximum number of notices to display on the moderator noticeboard
$config['mod']['noticeboard_display'] = 50;
// How many entries to show per page in the moderator noticeboard
$config['mod']['noticeboard_page'] = 50;
// Number of entries to summarize and display on the dashboard
$config['mod']['noticeboard_dashboard'] = 5;

View File

@ -37,6 +37,7 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
{
return Array(
'time' => new Twig_Filter_Function('time'),
'floor' => new Twig_Filter_Function('floor'),
'timezone' => new Twig_Filter_Function('twig_timezone_function'),
'hiddenInputs' => new Twig_Filter_Function('hiddenInputs'),
'hiddenInputsHash' => new Twig_Filter_Function('hiddenInputsHash'),

View File

@ -67,14 +67,14 @@ function mod_dashboard() {
$args['boards'] = listBoards();
if(hasPermission($config['mod']['noticeboard'])) {
if(!$config['cache']['enabled'] || !$args['noticeboard'] = cache::get('noticeboard_preview')) {
if (hasPermission($config['mod']['noticeboard'])) {
if (!$config['cache']['enabled'] || !$args['noticeboard'] = cache::get('noticeboard_preview')) {
$query = prepare("SELECT `noticeboard`.*, `username` FROM `noticeboard` LEFT JOIN `mods` ON `mods`.`id` = `mod` ORDER BY `id` DESC LIMIT :limit");
$query->bindValue(':limit', $config['mod']['noticeboard_dashboard'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$args['noticeboard'] = $query->fetchAll(PDO::FETCH_ASSOC);
if($config['cache']['enabled'])
if ($config['cache']['enabled'])
cache::set('noticeboard_preview', $args['noticeboard']);
}
}
@ -82,6 +82,47 @@ function mod_dashboard() {
mod_page('Dashboard', 'mod/dashboard.html', $args);
}
function mod_noticeboard($page_no = 1) {
global $config, $pdo, $mod;
if (!hasPermission($config['mod']['noticeboard']))
error($config['error']['noaccess']);
if (isset($_POST['subject'], $_POST['body'])) {
if (!hasPermission($config['mod']['noticeboard_post']))
error($config['error']['noaccess']);
markup($_POST['body']);
$query = prepare('INSERT INTO `noticeboard` VALUES (NULL, :mod, :time, :subject, :body)');
$query->bindValue(':mod', $mod['id']);
$query->bindvalue(':time', time());
$query->bindValue(':subject', $_POST['subject']);
$query->bindValue(':body', $_POST['body']);
$query->execute() or error(db_error($query));
if($config['cache']['enabled'])
cache::delete('noticeboard_preview');
header('Location: ?/noticeboard#' . $pdo->lastInsertId(), true, $config['redirect_http']);
}
$query = prepare("SELECT `noticeboard`.*, `username` FROM `noticeboard` LEFT JOIN `mods` ON `mods`.`id` = `mod` ORDER BY `id` DESC LIMIT :offset, :limit");
$query->bindValue(':limit', $config['mod']['noticeboard_page'], PDO::PARAM_INT);
$query->bindValue(':offset', ($page_no - 1) * $config['mod']['noticeboard_page'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
$noticeboard = $query->fetchAll(PDO::FETCH_ASSOC);
if (empty($noticeboard))
error($config['error']['404']);
$query = prepare("SELECT COUNT(*) FROM `noticeboard`");
$query->execute() or error(db_error($query));
$count = $query->fetchColumn(0);
mod_page('Noticeboard', 'mod/noticeboard.html', array('noticeboard' => $noticeboard, 'count' => $count));
}
function mod_log($page_no = 1) {
global $config;
@ -94,7 +135,10 @@ function mod_log($page_no = 1) {
$query->execute() or error(db_error($query));
$logs = $query->fetchAll(PDO::FETCH_ASSOC);
$query = prepare("SELECT COUNT(*) AS `count` FROM `modlogs`");
if (empty($logs))
error($config['error']['404']);
$query = prepare("SELECT COUNT(*) FROM `modlogs`");
$query->execute() or error(db_error($query));
$count = $query->fetchColumn(0);
@ -300,6 +344,9 @@ function mod_bans($page_no = 1) {
$query->execute() or error(db_error($query));
$bans = $query->fetchAll(PDO::FETCH_ASSOC);
if (empty($bans))
error($config['error']['404']);
$query = prepare("SELECT COUNT(*) FROM `bans`");
$query->execute() or error(db_error($query));
$count = $query->fetchColumn(0);

View File

@ -24,8 +24,6 @@ $pages = array(
'!^$!' => ':?/', // redirect to dashboard
'!^/$!' => 'dashboard', // dashboard
'!^/confirm/(.+)$!' => 'confirm', // confirm action (if javascript didn't work)
'!^/log$!' => 'log', // modlog
'!^/log/(\d+)$!' => 'log', // modlog
'!^/users$!' => 'users', // manage users
'!^/users/(\d+)$!' => 'user', // edit user
@ -33,6 +31,10 @@ $pages = array(
'!^/new_PM/([^/]+)$!' => 'new_pm', // create a new pm
'!^/PM/(\d+)(/reply)?$!' => 'pm', // read a pm
'!^/noticeboard$!' => 'noticeboard', // view noticeboard
'!^/noticeboard/(\d+)$!' => 'noticeboard', // view noticeboard
'!^/log$!' => 'log', // modlog
'!^/log/(\d+)$!' => 'log', // modlog
'!^/rebuild$!' => 'rebuild', // rebuild static files
'!^/reports$!' => 'reports', // report queue
'!^/reports/(\d+)/dismiss(all)?$!' => 'report_dismiss', // dismiss a report

View File

@ -75,7 +75,7 @@
{% if count > bans|count %}
<p class="unimportant" style="text-align:center;word-wrap:break-word">
{% for i in range(0, count / config.mod.modlog_page) %}
{% for i in range(0, (count - 1) / config.mod.modlog_page) %}
<a href="?/bans/{{ i + 1 }}">[{{ i + 1 }}]</a>
{% endfor %}
</p>

View File

@ -33,7 +33,7 @@
{% if count > logs|count %}
<p class="unimportant" style="text-align:center;word-wrap:break-word">
{% for i in range(0, count / config.mod.modlog_page) %}
{% for i in range(0, (count - 1) / config.mod.modlog_page) %}
<a href="?/log/{{ i + 1 }}">[{{ i + 1 }}]</a>
{% endfor %}
</p>

View File

@ -0,0 +1,65 @@
{% if mod|hasPermission(config.mod.noticeboard_post) %}
<fieldset>
<legend>{% trans 'New post' %}</legend>
<form style="margin:0" action="" method="post">
<table>
<tr>
<th>{% trans 'Name' %}</th>
<td>{{ mod.username|e }}</td>
</tr>
<tr>
<th><label for="subject">{% trans 'Subject' %}</label></th>
<td><input type="text" size="55" name="subject" id="subject" /></td>
</tr>
<tr>
<th>{% trans 'Body' %}</th>
<td><textarea name="body" style="width:100%;height:100px"></textarea></td>
</tr>
</table>
<p style="text-align:center">
<input type="submit" value="{% trans 'Post to noticeboard' %}" />
</p>
</form>
</fieldset>
{% endif %}
{% for post in noticeboard %}
<div class="ban">
{% if mod|hasPermission(config.mod.noticeboard_delete) %}
<span style="float:right;padding:2px">
<a class="unimportant" href="?/noticeboard/delete/{{ post.id }}">[{% trans 'delete' %}]</a>
</span>
{% endif %}
<h2 id="{{ post.id }}">
<small class="unimportant">
<a href="#{{ post.id }}">#</a>
</small>
{% if post.subject %}
{{ post.subject|e }}
{% else %}
<em>{% trans 'no subject' %}</em>
{% endif %}
<small class="unimportant">
&mdash; by
{% if post.username %}
{{ post.username }}
{% else %}
<em>deleted?</em>
{% endif %}
at
{{ notice.time|date(config.post_date) }}
</small>
</h2>
<p>
{{ post.body }}
</p>
</div>
{% endfor %}
{% if count > noticeboard|count %}
<p class="unimportant" style="text-align:center;word-wrap:break-word">
{% for i in range(0, (count - 1) / config.mod.noticeboard_page) %}
<a href="?/noticeboard/{{ i + 1 }}">[{{ i + 1 }}]</a>
{% endfor %}
</p>
{% endif %}