cached noticeboard preview on dashboard
This commit is contained in:
parent
c2e1f4feac
commit
68acbb8821
95
mod.php
95
mod.php
@ -86,52 +86,59 @@
|
|||||||
$fieldset['Boards'] .= ulBoards();
|
$fieldset['Boards'] .= ulBoards();
|
||||||
|
|
||||||
if(hasPermission($config['mod']['noticeboard'])) {
|
if(hasPermission($config['mod']['noticeboard'])) {
|
||||||
$query = prepare("SELECT `noticeboard`.*, `username` FROM `noticeboard` LEFT JOIN `mods` ON `mods`.`id` = `mod` ORDER BY `id` DESC LIMIT :limit");
|
if(!$config['cache']['enabled'] || !($fieldset['Noticeboard'] = cache::get('noticeboard_preview'))) {
|
||||||
$query->bindValue(':limit', $config['mod']['noticeboard_dashboard'], PDO::PARAM_INT);
|
|
||||||
$query->execute() or error(db_error($query));
|
|
||||||
|
|
||||||
$fieldset['Noticeboard'] .= '<li>';
|
$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));
|
||||||
|
|
||||||
$_body = '';
|
$fieldset['Noticeboard'] .= '<li>';
|
||||||
while($notice = $query->fetch()) {
|
|
||||||
$_body .= '<li><a href="?/noticeboard#' .
|
$_body = '';
|
||||||
$notice['id'] .
|
while($notice = $query->fetch()) {
|
||||||
'">' .
|
$_body .= '<li><a href="?/noticeboard#' .
|
||||||
($notice['subject'] ?
|
$notice['id'] .
|
||||||
$notice['subject']
|
'">' .
|
||||||
:
|
($notice['subject'] ?
|
||||||
'<em>' . _('no subject') . '</em>'
|
$notice['subject']
|
||||||
) .
|
:
|
||||||
'</a><span class="unimportant"> — by ' .
|
'<em>' . _('no subject') . '</em>'
|
||||||
(isset($notice['username']) ?
|
) .
|
||||||
utf8tohtml($notice['username'])
|
'</a><span class="unimportant"> — by ' .
|
||||||
: '<em>???</em>') .
|
(isset($notice['username']) ?
|
||||||
' at ' .
|
utf8tohtml($notice['username'])
|
||||||
strftime($config['post_date'], $notice['time']) .
|
: '<em>???</em>') .
|
||||||
'</span></li>';
|
' at ' .
|
||||||
|
strftime($config['post_date'], $notice['time']) .
|
||||||
|
'</span></li>';
|
||||||
|
}
|
||||||
|
if(!empty($_body)) {
|
||||||
|
$fieldset['Noticeboard'] .= '<ul>' . $_body . '</ul></li><li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$fieldset['Noticeboard'] .= '<a href="?/noticeboard">' . _('View all entires') . '</a></li>';
|
||||||
|
|
||||||
|
$query = prepare("SELECT COUNT(*) AS `count` FROM `pms` WHERE `to` = :id AND `unread` = 1");
|
||||||
|
$query->bindValue(':id', $mod['id']);
|
||||||
|
$query->execute() or error(db_error($query));
|
||||||
|
$count = $query->fetch();
|
||||||
|
$count = $count['count'];
|
||||||
|
|
||||||
|
$fieldset['Noticeboard'] .= '<li><a href="?/inbox">' . _('PM Inbox') .
|
||||||
|
($count > 0
|
||||||
|
?
|
||||||
|
' <strong>(' . $count . ' unread)</strong>'
|
||||||
|
: '') .
|
||||||
|
'</a></li>';
|
||||||
|
|
||||||
|
$fieldset['Noticeboard'] .= '<li><a href="?/news">' . _('News') . '</a></li>';
|
||||||
|
|
||||||
|
if($config['cache']['enabled'])
|
||||||
|
cache::set('noticeboard_preview', $fieldset['Noticeboard']);
|
||||||
}
|
}
|
||||||
if(!empty($_body)) {
|
|
||||||
$fieldset['Noticeboard'] .= '<ul>' . $_body . '</ul></li><li>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$fieldset['Noticeboard'] .= '<a href="?/noticeboard">' . _('View all entires') . '</a></li>';
|
|
||||||
|
|
||||||
$query = prepare("SELECT COUNT(*) AS `count` FROM `pms` WHERE `to` = :id AND `unread` = 1");
|
|
||||||
$query->bindValue(':id', $mod['id']);
|
|
||||||
$query->execute() or error(db_error($query));
|
|
||||||
$count = $query->fetch();
|
|
||||||
$count = $count['count'];
|
|
||||||
|
|
||||||
$fieldset['Noticeboard'] .= '<li><a href="?/inbox">' . _('PM Inbox') .
|
|
||||||
($count > 0
|
|
||||||
?
|
|
||||||
' <strong>(' . $count . ' unread)</strong>'
|
|
||||||
: '') .
|
|
||||||
'</a></li>';
|
|
||||||
|
|
||||||
$fieldset['Noticeboard'] .= '<li><a href="?/news">' . _('News') . '</a></li>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user