From 68acbb8821c60a7dc37c9922658cbdbe36377c27 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Sun, 4 Dec 2011 11:20:14 +1100 Subject: [PATCH] cached noticeboard preview on dashboard --- mod.php | 89 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/mod.php b/mod.php index 9b5aad4e..f7504611 100644 --- a/mod.php +++ b/mod.php @@ -86,52 +86,59 @@ $fieldset['Boards'] .= ulBoards(); 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"); - $query->bindValue(':limit', $config['mod']['noticeboard_dashboard'], PDO::PARAM_INT); - $query->execute() or error(db_error($query)); + if(!$config['cache']['enabled'] || !($fieldset['Noticeboard'] = cache::get('noticeboard_preview'))) { - $fieldset['Noticeboard'] .= '
  • '; + $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 = ''; - while($notice = $query->fetch()) { - $_body .= '
  • ' . - ($notice['subject'] ? - $notice['subject'] - : - '' . _('no subject') . '' - ) . - ' — by ' . - (isset($notice['username']) ? - utf8tohtml($notice['username']) - : '???') . - ' at ' . - strftime($config['post_date'], $notice['time']) . - '
  • '; - } - if(!empty($_body)) { - $fieldset['Noticeboard'] .= '
  • '; - } + $fieldset['Noticeboard'] .= '
  • '; + + $_body = ''; + while($notice = $query->fetch()) { + $_body .= '
  • ' . + ($notice['subject'] ? + $notice['subject'] + : + '' . _('no subject') . '' + ) . + ' — by ' . + (isset($notice['username']) ? + utf8tohtml($notice['username']) + : '???') . + ' at ' . + strftime($config['post_date'], $notice['time']) . + '
  • '; + } + if(!empty($_body)) { + $fieldset['Noticeboard'] .= '
  • '; + } - $fieldset['Noticeboard'] .= '' . _('View all entires') . '
  • '; + $fieldset['Noticeboard'] .= '' . _('View all entires') . ''; - $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']; + $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'] .= '
  • ' . _('PM Inbox') . - ($count > 0 - ? - ' (' . $count . ' unread)' - : '') . - '
  • '; + $fieldset['Noticeboard'] .= '
  • ' . _('PM Inbox') . + ($count > 0 + ? + ' (' . $count . ' unread)' + : '') . + '
  • '; + + $fieldset['Noticeboard'] .= '
  • ' . _('News') . '
  • '; - $fieldset['Noticeboard'] .= '
  • ' . _('News') . '
  • '; + if($config['cache']['enabled']) + cache::set('noticeboard_preview', $fieldset['Noticeboard']); + } } + if(hasPermission($config['mod']['reports'])) { $fieldset['Administration'] .= '
  • ' . _('Report queue') . '
  • '; } @@ -543,6 +550,9 @@ $query->bindValue(':id', $match[1], PDO::PARAM_INT); $query->execute() or error(db_error($query)); + if($config['cache']['enabled']) + cache::delete('noticeboard_preview'); + header('Location: ?/noticeboard', true, $config['redirect_http']); } elseif(preg_match('/^\/noticeboard$/', $query)) { if(!hasPermission($config['mod']['noticeboard'])) error($config['error']['noaccess']); @@ -559,6 +569,9 @@ $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']); } else {