protected function displayComments() { if ($this->post->comment_status != SiteCommentStatus::CLOSED) { Blorg::displayAd($this->app, 'post_comments'); $div_tag = new SwatHtmlTag('div'); $div_tag->id = 'comments'; $div_tag->class = 'entry-comments'; $div_tag->open(); $comments = $this->post->getVisibleComments(); $view = SiteViewFactory::get($this->app, 'post-comment'); $count = count($comments); if ($count > 0) { echo '<h3 class="comments-title">', Blorg::_('Comments'), '</h3>'; } // display message for locked comments if ($this->post->comment_status == SiteCommentStatus::LOCKED) { $div_tag = new SwatHtmlTag('div'); $div_tag->class = 'comments-locked-message'; $div_tag->setContent(Blorg::_('Comments are locked. No additional comments may be ' . 'posted.')); $div_tag->display(); } foreach ($comments as $i => $comment) { if ($i == $count - 1) { $div_tag = new SwatHtmlTag('div'); $div_tag->id = 'last_comment'; $div_tag->open(); $view->display($comment); $div_tag->close(); } else { $view->display($comment); } } $div_tag->close(); } }
protected function initComments($year, $month_name, $shortname, $page) { if (!array_key_exists($month_name, BlorgPageFactory::$months_by_name)) { throw new SiteNotFoundException(Blorg::_('Page not found.')); } // Date parsed from URL is in locale time. $date = new SwatDate(); $date->setTZ($this->app->default_time_zone); $date->setDate($year, BlorgPageFactory::$months_by_name[$month_name], 1); $date->setTime(0, 0, 0); $memcache = isset($this->app->memcache) ? $this->app->memcache : null; $loader = new BlorgPostLoader($this->app->db, $this->app->getInstance(), $memcache); $loader->addSelectField('title'); $loader->addSelectField('bodytext'); $loader->addSelectField('shortname'); $loader->addSelectField('publish_date'); $loader->addSelectField('author'); $loader->addSelectField('visible_comment_count'); $loader->setWhereClause(sprintf('enabled = %s', $this->app->db->quote(true, 'boolean'))); $this->post = $loader->getPostByDateAndShortname($date, $shortname); if ($this->post === null) { throw new SiteNotFoundException('Post not found.'); } $this->total_count = $this->post->getVisibleCommentCount(); $this->comments = false; if (isset($this->app->memcache)) { $key = $this->getCommentsCacheKey(); $this->comments = $this->app->memcache->getNs('posts', $key); } if ($this->comments === false) { $offset = ($page - 1) * $this->getPageSize(); $this->comments = $this->post->getVisibleComments($this->getPageSize(), $offset); if (isset($this->app->memcache)) { $this->app->memcache->setNs('posts', $key, $this->comments); } } else { $this->comments->setDatabase($this->app->db); } if ($page > 1 && count($this->comments) === 0) { throw new SiteNotFoundException(Blorg::_('Page not found.')); } }