cached noticeboard preview on dashboard

This commit is contained in:
Savetheinternet 2011-12-04 11:20:14 +11:00
parent c2e1f4feac
commit 68acbb8821

13
mod.php
View File

@ -86,6 +86,8 @@
$fieldset['Boards'] .= ulBoards(); $fieldset['Boards'] .= ulBoards();
if(hasPermission($config['mod']['noticeboard'])) { if(hasPermission($config['mod']['noticeboard'])) {
if(!$config['cache']['enabled'] || !($fieldset['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 = 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->bindValue(':limit', $config['mod']['noticeboard_dashboard'], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
@ -130,7 +132,12 @@
'</a></li>'; '</a></li>';
$fieldset['Noticeboard'] .= '<li><a href="?/news">' . _('News') . '</a></li>'; $fieldset['Noticeboard'] .= '<li><a href="?/news">' . _('News') . '</a></li>';
if($config['cache']['enabled'])
cache::set('noticeboard_preview', $fieldset['Noticeboard']);
} }
}
if(hasPermission($config['mod']['reports'])) { if(hasPermission($config['mod']['reports'])) {
$fieldset['Administration'] .= '<li><a href="?/reports">' . _('Report queue') . '</a></li>'; $fieldset['Administration'] .= '<li><a href="?/reports">' . _('Report queue') . '</a></li>';
@ -543,6 +550,9 @@
$query->bindValue(':id', $match[1], PDO::PARAM_INT); $query->bindValue(':id', $match[1], PDO::PARAM_INT);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if($config['cache']['enabled'])
cache::delete('noticeboard_preview');
header('Location: ?/noticeboard', true, $config['redirect_http']); header('Location: ?/noticeboard', true, $config['redirect_http']);
} elseif(preg_match('/^\/noticeboard$/', $query)) { } elseif(preg_match('/^\/noticeboard$/', $query)) {
if(!hasPermission($config['mod']['noticeboard'])) error($config['error']['noaccess']); if(!hasPermission($config['mod']['noticeboard'])) error($config['error']['noaccess']);
@ -559,6 +569,9 @@
$query->bindValue(':body', $_POST['body']); $query->bindValue(':body', $_POST['body']);
$query->execute() or error(db_error($query)); $query->execute() or error(db_error($query));
if($config['cache']['enabled'])
cache::delete('noticeboard_preview');
header('Location: ?/noticeboard#' . $pdo->lastInsertId(), true, $config['redirect_http']); header('Location: ?/noticeboard#' . $pdo->lastInsertId(), true, $config['redirect_http']);
} else { } else {