Exemple #1
0
 protected function initPost($year, $month_name, $shortname)
 {
     if (!array_key_exists($month_name, BlorgPageFactory::$months_by_name)) {
         throw new SiteNotFoundException('Post 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('extended_bodytext');
     $loader->addSelectField('shortname');
     $loader->addSelectField('publish_date');
     $loader->addSelectField('author');
     $loader->addSelectField('comment_status');
     $loader->addSelectField('visible_comment_count');
     $loader->setLoadFiles(true);
     $loader->setLoadTags(true);
     $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.');
     }
 }
Exemple #2
0
 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.'));
     }
 }