protected function displayContent()
 {
     $stats = $this->getPhotoStats();
     if ($stats->last_date === null) {
         echo Pinhole::_('No photos have been added.');
     } else {
         $locale = SwatI18NLocale::get();
         $first_date = new SwatDate($stats->first_date);
         $last_date = new SwatDate($stats->last_date);
         echo '<ul>';
         $li_tag = new SwatHtmlTag('li');
         $li_tag->setContent(sprintf(Pinhole::_('%s photos have been uploaded since ' . '<a href="%stag?date.date=%s">%s</a>'), $locale->formatNumber($stats->photo_count), $this->app->config->pinhole->path, $first_date->formatLikeIntl('yyyy-MM-dd'), $first_date->formatLikeIntl(SwatDate::DF_DATE)), 'text/xml');
         $li_tag->display();
         $days = $last_date->diff($first_date)->days;
         $avg = round((double) $stats->photo_count / (double) $days, 2);
         $li_tag = new SwatHtmlTag('li');
         $li_tag->setContent(sprintf(Pinhole::_('Approximately %s photos have been uploaded ' . 'per day'), $locale->formatNumber($avg)));
         $li_tag->display();
         $li_tag->setContent(sprintf(Pinhole::_('Last photo uploaded on ' . '<a href="%stag?date=%s">%s</a>'), $this->app->config->pinhole->path, $last_date->formatLikeIntl('yyyy-MM-dd'), $last_date->formatLikeIntl(SwatDate::DF_DATE)), 'text/xml');
         $li_tag->display();
         $tag_stats = $this->getTagStats();
         if ($tag_stats->tag_count > 0) {
             $li_tag = new SwatHtmlTag('li');
             $li_tag->setContent(sprintf(Pinhole::_('<a href="%s/tags/alphabetical">%s tags</a> ' . 'have been added'), $this->app->config->pinhole->path, $locale->formatNumber($tag_stats->tag_count)), 'text/xml');
             $li_tag->display();
             $a_tag = new SwatHtmlTag('a');
             $a_tag->setContent($tag_stats->popular_tag_title);
             $a_tag->href = $this->app->config->pinhole->path . 'tag?' . SwatString::minimizeEntities($tag_stats->popular_tag_name);
             $li_tag = new SwatHtmlTag('li');
             $li_tag->setContent(sprintf(Pinhole::_('The most popular tag “%s” has %s photos'), (string) $a_tag, $locale->formatNumber($tag_stats->popular_tag_count)), 'text/xml');
             $li_tag->display();
         }
         echo '</ul>';
     }
 }
 protected function displayByDateAdded(PinholeTagList $tag_list)
 {
     $now = new SwatDate();
     $now->convertTZById($this->app->config->date->time_zone);
     $store = new SwatTableStore();
     foreach ($tag_list as $tag) {
         $ds = new SwatDetailsStore();
         $ds->tag = $tag;
         $tag_date = $tag->getDataObject()->first_modified;
         $tag_date->convertTZById($this->app->config->date->time_zone);
         $days_past = $now->diff($tag_date)->days;
         if ($days_past <= 1) {
             $ds->date_part = Pinhole::_('Today');
         } elseif ($days_past <= $now->getDayOfWeek() + 1) {
             $ds->date_part = Pinhole::_('This Week');
         } elseif ($days_past <= $now->getDay()) {
             $ds->date_part = Pinhole::_('This Month');
         } elseif ($days_past <= $now->getDayOfYear()) {
             $ds->date_part = Pinhole::_('This Year');
         } else {
             $ds->date_part = sprintf(Pinhole::_('%s'), $tag_date->getYear());
         }
         $store->add($ds);
     }
     $ul_tag = new SwatHtmlTag('ul');
     $li_tag = new SwatHtmlTag('li');
     $ul_tag->open();
     $part = null;
     foreach ($store as $ds) {
         if ($part !== $ds->date_part) {
             if ($part !== null) {
                 $li_tag->close();
             }
             $li_tag->open();
             $h2_tag = new SwatHtmlTag('h2');
             $h2_tag->class = 'pinhole-tag-entity';
             $h2_tag->setContent($ds->date_part);
             $h2_tag->display();
         } elseif ($part !== null) {
             echo ', ';
         }
         $this->displayTag($ds->tag);
         $part = $ds->date_part;
     }
     $li_tag->close();
     $ul_tag->close();
 }
Exemple #3
0
    protected function getInfo()
    {
        $instance_id = $this->app->getInstanceId();
        $sql = sprintf('select count(1) as post_count,
			sum(visible_comment_count) as comment_count,
			min(publish_date) as start_date from BlorgPost
				left outer join BlorgPostVisibleCommentCountView as v on
					BlorgPost.id = v.post and BlorgPost.instance = v.instance
			where BlorgPost.instance %s %s and BlorgPost.enabled = %s and
				BlorgPost.publish_date is not null', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'), $this->app->db->quote(true, 'boolean'));
        $post_info = SwatDB::queryRow($this->app->db, $sql, array('integer', 'integer', 'date'));
        $sql = sprintf('select sum(post_count) as tag_count from
			BlorgTagVisiblePostCountView as v
				inner join BlorgTag on BlorgTag.id = v.tag
			where instance %s %s', SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
        $tag_info = SwatDB::queryRow($this->app->db, $sql, array('integer'));
        $start_date = new SwatDate($post_info->start_date);
        $now = new SwatDate();
        $start_month = $start_date->getMonth();
        $end_month = $now->getMonth();
        $start_year = $start_date->getYear();
        $end_year = $now->getYear();
        if ($start_month > $end_month) {
            $end_month += 12;
            $end_year--;
        }
        $months = $end_month - $start_month + ($end_year - $start_year) * 12;
        $days = $now->diff($start_date)->days;
        $posts_per_month = $months == 0 ? 0 : $post_info->post_count / $months;
        $comments_per_day = $days == 0 ? 0 : $post_info->comment_count / $days;
        return array('post_count' => $post_info->post_count, 'posts_per_month' => $posts_per_month, 'comment_count' => $post_info->comment_count, 'comments_per_day' => $comments_per_day, 'tag_count' => $tag_info->tag_count);
    }
 protected function getPhotoTableStore()
 {
     if (count($this->tag_list) == 0) {
         $tag_path = '';
     } else {
         $tag_path = '?' . $this->tag_list->__toString();
     }
     $photos = $this->tag_list->getPhotos('thumbnail');
     // throw exception or else tags that have only private photos would be
     // exposed.
     if (count($this->tag_list->getByType('PinholeTag')) > 0 && count($photos) == 0) {
         throw new SiteNotFoundException(sprintf('There are no photos in the current tag intersection: %s.', (string) $this->tag_list));
     }
     $store = new SwatTableStore();
     foreach ($photos as $photo) {
         $ds = new SwatDetailsStore();
         $ds->root_path = $this->app->config->pinhole->path;
         $ds->path = $photo->id . $tag_path;
         $ds->photo = $photo;
         $ds->display_title = $this->app->config->pinhole->browser_index_titles;
         $now = new SwatDate();
         $now->convertTZById($this->app->config->date->time_zone);
         $now->setTime(0, 0, 0);
         if (count($this->tag_list) == 0) {
             $publish_date = $photo->publish_date;
             $publish_date->convertTZbyID($this->app->config->date->time_zone);
             $days_past = $now->diff($publish_date)->days;
             if ($days_past <= 1) {
                 $period = Pinhole::_('Today');
             } elseif ($days_past <= 2) {
                 $period = Pinhole::_('Yesterday');
             } elseif ($days_past <= 7) {
                 $period = sprintf(Pinhole::_('%d Days Ago'), floor($days_past));
             } else {
                 $period = $publish_date->formatLikeIntl(SwatDate::DF_DATE_LONG);
             }
             $ds->publish_period = sprintf(Pinhole::_('Added %s'), $period);
         } else {
             $ds->publish_period = null;
         }
         $store->add($ds);
     }
     return $store;
 }