public static function show($start_date = null, $end_date = null) { if (!Blog_User::allowView()) { return null; } $db = new PHPWS_DB('blog_entries'); if ($start_date) { $db->addWhere('publish_date', $start_date, '>=', 'and', 2); } if ($end_date) { $db->addWhere('publish_date', $end_date, '<=', 'and', 2); } $db->addWhere('approved', 1); $db->addWhere('publish_date', time(), '<'); $db->addWhere('expire_date', time(), '>', 'and', 1); $db->addWhere('expire_date', 0, '=', 'or', 1); $db->setGroupConj(1, 'and'); Key::restrictView($db, 'blog'); $total_entries = Blog_User::totalEntries($db); $limit = PHPWS_Settings::get('blog', 'blog_limit'); if (isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 0; } if (!is_numeric($page) || $page < 2) { $offset = $page = 0; } else { $offset = ($page - 1) * $limit; } Layout::addStyle('blog'); $result = Blog_User::getEntries($db, $limit, $offset); if ($page > 0 && empty($result)) { PHPWS_Core::reroute('blog/action/view/page/1'); } if (PHPWS_Error::isError($result)) { PHPWS_Error::log($result); return NULL; } if (empty($result)) { if (Current_User::allow('blog')) { MiniAdmin::add('blog', PHPWS_Text::secureLink(dgettext('blog', 'Create first blog entry!'), 'blog', array('action' => 'admin', 'command' => 'new'))); } return NULL; } if ($page < 2) { $past_entries = PHPWS_Settings::get('blog', 'past_entries'); if ($past_entries) { $db->setLimit($past_entries, $limit); $past = $db->getObjects('Blog'); if (PHPWS_Error::isError($past)) { PHPWS_Error::log($past); } elseif ($past) { Blog_User::showPast($past); } } } $rss = false; foreach ($result as $blog) { if (!$rss) { if (PHPWS_Core::moduleExists('rss')) { PHPWS_Core::initModClass('rss', 'RSS.php'); $key = new Key($blog->key_id); RSS::showIcon($key); $rss = true; } } $view = $blog->view(); if (!empty($view)) { $list[] = $view; } } $page_vars['action'] = 'view'; if ($page > 1) { $page_vars['page'] = $page - 1; $tpl['PREV_PAGE'] = PHPWS_Text::moduleLink(dgettext('blog', 'Previous page'), 'blog', $page_vars); if ($limit + $offset < $total_entries) { $page_vars['page'] = $page + 1; $tpl['NEXT_PAGE'] = PHPWS_Text::moduleLink(dgettext('blog', 'Next page'), 'blog', $page_vars); } } elseif ($limit + $offset < $total_entries) { $page_vars['page'] = 2; $tpl['NEXT_PAGE'] = PHPWS_Text::moduleLink(dgettext('blog', 'Next page'), 'blog', $page_vars); } $tpl['ENTRIES'] = implode('', $list); $content = PHPWS_Template::process($tpl, 'blog', 'list_view.tpl'); if (Current_User::allow('blog', 'edit_blog')) { Blog_User::miniAdminList(); $vars['action'] = 'admin'; $vars['command'] = 'new'; $link[] = PHPWS_Text::secureLink(dgettext('blog', 'Add new blog'), 'blog', $vars); MiniAdmin::add('blog', $link); } return $content; }
<?php /** * @author Matthew McNaney <mcnaney at gmail dot com> * @version $Id$ */ $key = Key::getCurrent(); if (empty($key) || $key->isDummy() || $key->restricted) { return; } PHPWS_Core::initModClass('rss', 'RSS.php'); RSS::showIcon($key);