protected function getContainer() { $date = new SwatDate(); if (isset($this->app->memcache)) { $cache_key = sprintf('PinholeDateBrowserGadget.getContent.%s.%s', $date->formatLikeIntl('MM/yyyy'), $this->app->session->isLoggedIn() ? 'private' : 'public'); $container = $this->app->memcache->getNs('photos', $cache_key); if ($container !== false) { return $container; } } $container = new SwatContainer(); $months = $this->getMonths(); if (count($months) == 0) { $content = new SwatContentBlock(); $content->content = Pinhole::_('No photos have been uploaded yet.'); $container->add($content); return $container; } $months_array = array(); foreach ($months as $month) { $date = new SwatDate($month->photo_date); $key = $date->getYear() . '/' . $date->getMonth(); $months_array[$key] = $month; } $locale = SwatI18NLocale::get(); $start_date = new SwatDate($months->getFirst()->photo_date); $start_year = $start_date->getYear(); $index = count($months) - 1; $end_date = new SwatDate($months->getByIndex($index)->photo_date); $end_year = $end_date->getYear(); $date = new SwatDate(); $date->clearTime(); for ($year = $start_year; $year >= $end_year; $year--) { $year_count = 0; $disclosure = new SwatDisclosure(); $disclosure->title = $year; $disclosure->open = false; ob_start(); echo '<ul>'; for ($i = 1; $i <= 12; $i++) { echo '<li class="clearfix"><div>'; $date->setDate($year, $i, 1); if (isset($months_array[$year . '/' . $i])) { $a_tag = new SwatHtmlTag('a'); $a_tag->setContent($date->getMonthName()); $a_tag->href = $this->app->config->pinhole->path . 'tag?date.year=' . $year . '/date.month=' . $i; $a_tag->display(); $photo_count = $months_array[$year . '/' . $i]->photo_count; echo '<span>' . $locale->formatNumber($photo_count) . '</span>'; $year_count += $photo_count; } else { $div_tag = new SwatHtmlTag('div'); $div_tag->setContent($date->getMonthName()); $div_tag->display(); } echo '</div></li>'; if ($i == 12 && $year_count > 0) { echo '<li class="clearfix"><div>'; $a_tag = new SwatHtmlTag('a'); $a_tag->setContent(sprintf(Pinhole::_('View all photos from %s'), $year)); $a_tag->href = $this->app->config->pinhole->path . 'tag?date.year=' . $year; $a_tag->display(); echo '<span>' . $locale->formatNumber($year_count) . '</span>'; echo '</div></li>'; } } echo '</ul>'; $content = new SwatContentBlock(); $content->content_type = 'text/xml'; $content->content = ob_get_clean(); $disclosure->add($content); $container->add($disclosure); } if (isset($this->app->memcache)) { $this->app->memcache->setNs('photos', $cache_key, $container); } return $container; }
protected function buildNavBar() { $path = $this->app->config->blorg->path . 'archive'; $this->layout->navbar->createEntry(Blorg::_('Archive'), $path); $path .= '/' . $this->year; $this->layout->navbar->createEntry($this->year, $path); $date = new SwatDate(); $date->setDate(2010, $this->month, 1); $month_title = $date->getMonthName(); $month_name = BlorgPageFactory::$month_names[$this->month]; $path .= '/' . $month_name; $this->layout->navbar->createEntry($month_title, $path); }
protected function displayMonths() { $path = $this->app->config->blorg->path . 'archive'; $view = SiteViewFactory::get($this->app, 'post'); $view->setPartMode('title', SiteView::MODE_SUMMARY); $view->setPartMode('bodytext', SiteView::MODE_NONE); $view->setPartMode('extended_bodytext', SiteView::MODE_NONE); $view->setPartMode('tags', SiteView::MODE_NONE); $view->setPartMode('files', SiteView::MODE_NONE); $ul_tag = new SwatHtmlTag('ul'); $ul_tag->class = 'blorg-archive-months'; $ul_tag->open(); foreach ($this->months as $month => $posts) { $li_tag = new SwatHtmlTag('li'); $li_tag->open(); $heading_tag = new SwatHtmlTag('h4'); $heading_tag->class = 'blorg-archive-month-title'; $heading_tag->open(); $date = new SwatDate(); $date->setDate(2010, $month, 1); $anchor_tag = new SwatHtmlTag('a'); $anchor_tag->href = sprintf('%s/%s/%s', $path, $this->year, BlorgPageFactory::$month_names[$month]); $anchor_tag->setContent($date->getMonthName()); $anchor_tag->display(); $heading_tag->close(); $post_ul_tag = new SwatHtmlTag('ul'); $post_ul_tag->class = 'entries'; $post_ul_tag->open(); foreach ($posts as $post) { $post_li_tag = new SwatHtmlTag('li'); $post_li_tag->open(); $view->display($post); $post_li_tag->close(); } $post_ul_tag->close(); $li_tag->close(); } $ul_tag->close(); }
protected function displayArchive() { $path = $this->app->config->blorg->path . 'archive'; $locale = SwatI18NLocale::get(); $year_ul_tag = new SwatHtmLTag('ul'); $year_ul_tag->class = 'blorg-archive-years'; $year_ul_tag->open(); foreach ($this->years as $year => $values) { $year_li_tag = new SwatHtmlTag('li'); $year_li_tag->open(); $year_anchor_tag = new SwatHtmlTag('a'); $year_anchor_tag->href = sprintf('%s/%s', $path, $year); $year_anchor_tag->setContent($year); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $values['post_count']), $locale->formatNumber($values['post_count']))); $year_heading_tag = new SwatHtmlTag('h4'); $year_heading_tag->class = 'blorg-archive-year-title'; $year_heading_tag->open(); $year_anchor_tag->display(); $post_count_span->display(); $year_heading_tag->close(); $month_ul_tag = new SwatHtmlTag('ul'); $month_ul_tag->open(); foreach ($values['months'] as $month => $post_count) { $date = new SwatDate(); // Set year and day so we're sure it's a valid date, otherwise // the month may not be set. $date->setDate(2010, $month, 1); $month_li_tag = new SwatHtmlTag('li'); $month_li_tag->open(); $month_anchor_tag = new SwatHtmlTag('a'); $month_anchor_tag->href = sprintf('%s/%s/%s', $path, $year, BlorgPageFactory::$month_names[$month]); $month_anchor_tag->setContent($date->getMonthName()); $month_anchor_tag->display(); $post_count_span = new SwatHtmlTag('span'); $post_count_span->setContent(sprintf(Blorg::ngettext(' (%s post)', ' (%s posts)', $post_count), $locale->formatNumber($post_count))); $post_count_span->display(); $month_li_tag->close(); } $month_ul_tag->close(); $year_li_tag->close(); } $year_ul_tag->close(); }