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.')); } }
protected function buildPost(XML_Atom_Feed $feed, BlorgPost $post) { $site_base_href = $this->app->getBaseHref(); $blorg_base_href = $site_base_href . $this->app->config->blorg->path; $path = $blorg_base_href . 'archive'; $date = clone $post->publish_date; $date->convertTZ($this->app->default_time_zone); $year = $date->getYear(); $month_name = BlorgPageFactory::$month_names[$date->getMonth()]; $post_uri = sprintf('%s/%s/%s/%s', $path, $year, $month_name, $post->shortname); $entry = new XML_Atom_Entry($post_uri, $post->getTitle(), $post->publish_date); if ($post->extended_bodytext != '') { $full_bodytext = $post->bodytext . $post->extended_bodytext; $entry->setSummary($post->bodytext, 'html'); $entry->setContent($full_bodytext, 'html'); } else { $entry->setContent($post->bodytext, 'html'); } foreach ($post->getTags() as $tag) { $entry->addCategory($tag->shortname, $blorg_base_href, $tag->title); } $entry->addLink($post_uri, 'alternate', 'text/html'); foreach ($post->getVisibleFiles() as $file) { $link = new XML_Atom_Link($site_base_href . $file->getRelativeUri($this->app->config->blorg->path), 'enclosure', $file->mime_type); $link->setTitle($file->getDescription()); $link->setLength($file->filesize); $entry->addLink($link); } if ($post->author->visible) { $author_uri = $blorg_base_href . 'author/' . $post->author->shortname; } else { $author_uri = ''; } $entry->addAuthor($post->author->name, $author_uri, $post->author->email); $visible_comment_count = $post->getVisibleCommentCount(); if ($post->comment_status == SiteCommentStatus::OPEN || $post->comment_status == SiteCommentStatus::MODERATED || $post->comment_status == SiteCommentStatus::LOCKED && $visible_comment_count > 0) { $entry->addLink($post_uri . '#comments', 'comments', 'text/html'); } $feed->addEntry($entry); }
/** * Displays the number of comments for a weblog post */ protected function displayCommentCount(BlorgPost $post) { if ($this->getMode('comment_count') > SiteView::MODE_NONE) { $link = $this->getLink('comment_count'); $count = $post->getVisibleCommentCount(); if ($link === false) { $comment_count_tag = new SwatHtmlTag('span'); } else { $comment_count_tag = new SwatHtmlTag('a'); if (is_string($link)) { $comment_count_tag->href = $link; } else { $comment_count_tag->href = $this->getRelativeUri($post) . '#comments'; } switch ($post->comment_status) { case SiteCommentStatus::LOCKED: $comment_count_tag->title = sprintf(Blorg::_('View comments for %s'), $post->getTitle()); break; case SiteCommentStatus::OPEN: case SiteCommentStatus::MODERATED: $comment_count_tag->title = sprintf(Blorg::_('Comment on %s'), $post->getTitle()); break; } } $comment_count_tag->class = 'comment-count'; if ($count == 0) { $comment_count_tag->setContent(Blorg::_('leave a comment')); } else { $locale = SwatI18NLocale::get(); $comment_count_tag->setContent(sprintf(Blorg::ngettext('%s comment', '%s comments', $count), $locale->formatNumber($count))); } $comment_count_tag->display(); } }