protected function getContainer() { if (isset($this->app->memcache)) { $cache_key = sprintf('PinholeMetaDataGadget.getContainer.%s', $this->app->session->isLoggedIn() ? 'private' : 'public'); $container = $this->app->memcache->getNs('photos', $cache_key); if ($container !== false) { return $container; } } $sections = $this->getMetaDataSections(); $values = $this->getMetaDataValues(); $locale = SwatI18NLocale::get(); $container = new SwatContainer(); foreach ($sections as $section) { $disclosure = new SwatDisclosure(); $disclosure->title = $section->title; $disclosure->open = false; ob_start(); echo '<ul>'; foreach ($values as $value) { if ($value->meta_data == $section->id) { echo '<li class="clearfix"><div>'; $a_tag = new SwatHtmlTag('a'); $a_tag->href = sprintf('%stag?meta.%s=%s', $this->app->config->pinhole->path, $section->shortname, PinholePhotoMetaDataBinding::escapeValue($value->value)); $a_tag->setContent(PinholePhotoMetaDataBinding::getFormattedValue($section->shortname, $value->value)); $a_tag->display(); echo ' <span>' . $locale->formatNumber($value->photo_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 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; }