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; }
/** * Displays the blog entry * * @param boolean edit If true, show edit link * @param boolean summarized If true, this is a summarized entry */ public function view($edit = true, $summarized = true) { if (!$this->id) { PHPWS_Core::errorPage(404); } $key = new Key($this->key_id); if (!$key->allowView() || !Blog_User::allowView()) { Current_User::requireLogin(); return dgettext('blog', 'You do not have permission to view this entry.'); } $template['TITLE'] = sprintf('<a href="%s" rel="bookmark">%s</a>', $this->getViewLink(true), $this->title); $template['TITLE_NO_LINK'] = $this->title; if ($this->publish_date > time()) { $template['UNPUBLISHED'] = dgettext('blog', 'Unpublished'); } elseif ($this->expire_date && $this->expire_date < time()) { $template['UNPUBLISHED'] = dgettext('blog', 'Expired'); } $template['LOCAL_DATE'] = $this->getPublishDate(); $summary = $this->getSummary(true); $entry = $this->getEntry(true); if ($summarized) { if (empty($summary)) { $template['SUMMARY'] = PHPWS_Text::parseTag($entry); } else { if (!empty($entry)) { $template['READ_MORE'] = PHPWS_Text::rewriteLink(Icon::get('chevron-circle-down') . ' ' . dgettext('blog', 'Read more'), 'blog', array('id' => $this->id), null, 'Read more of this entry', 'btn btn-default'); } $template['SUMMARY'] = PHPWS_Text::parseTag($summary); } } else { $template['SUMMARY'] = PHPWS_Text::parseTag($summary); $template['ENTRY'] = PHPWS_Text::parseTag($entry); } $template['IMAGE'] = $this->getFile($this->thumbnail && $summarized); if ($edit && (Current_User::allow('blog', 'edit_blog', $this->id, 'entry') || Current_User::allow('blog', 'edit_blog') && $this->author_id == Current_User::getId())) { $vars['blog_id'] = $this->id; $vars['action'] = 'admin'; $vars['command'] = 'edit'; $template['EDIT_LINK'] = PHPWS_Text::secureLink(dgettext('blog', 'Edit'), 'blog', $vars); $template['EDIT_URI'] = PHPWS_Text::linkAddress('blog', $vars, true); if (!$summarized) { MiniAdmin::add('blog', array(PHPWS_Text::secureLink(dgettext('blog', 'Edit blog'), 'blog', $vars))); } } // Check setting for showing when the entry was posted if (PHPWS_Settings::get('blog', 'show_posted_by')) { $template['POSTED_BY'] = dgettext('blog', 'By'); $template['AUTHOR'] = $this->author; } // Check settings for showing the author of the entry if (PHPWS_Settings::get('blog', 'show_posted_date')) { $template['PUBLISHED'] = dgettext('blog', 'Published'); $template['POSTED_ON'] = dgettext('blog', 'Posted on'); $template['PUBLISHED_DATE'] = $this->getPublishDateShort(); } if ($summarized) { $view_tpl = 'view_list.tpl'; } else { $template['COMMENT_SCRIPT'] = PHPWS_Settings::get('blog', 'comment_script'); $key->flag(); $view_tpl = 'view_full.tpl'; } return PHPWS_Template::process($template, 'blog', $view_tpl); }