/**
  * Gets translatable string resources for the JavaScript object for
  * this gadget
  *
  * @return string translatable JavaScript string resources for this gadget.
  */
 protected function getInlineJavaScriptTranslations()
 {
     $throbber_text = Blorg::_('loading …');
     $visit_text = Blorg::_('Visit the Last.fm page for this track');
     $none_text = Blorg::_('‹none›');
     $months = array();
     $short_months = array();
     $date = new SwatDate('2000-01-01T00:00:00Z');
     for ($i = 1; $i <= 12; $i++) {
         $months[] = SwatString::quoteJavaScriptString($date->formatLikeIntl('MMMM'));
         $short_months[] = SwatString::quoteJavaScriptString($date->formatLikeIntl('MMM'));
         $date->setMonth($i + 1);
     }
     $months = implode(', ', $months);
     $short_months = implode(', ', $short_months);
     return sprintf("BlorgLastFmGadget.throbber_text = '%s';\n" . "BlorgLastFmGadget.visit_text = '%s';\n" . "BlorgLastFmGadget.none_text = '%s';\n" . "BlorgLastFmGadget.months = [%s];\n" . "BlorgLastFmGadget.short_months = [%s];\n", $throbber_text, $visit_text, $none_text, $months, $short_months);
 }
 protected function displayArchive()
 {
     $years = $this->getYears();
     if (count($years) === 0) {
         return;
     }
     $current_year = date('Y');
     $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 ($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);
         $year_anchor_tag->display();
         $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'])));
         $post_count_span->display();
         // show month links for current year
         if ($year == $current_year) {
             $month_ul_tag = new SwatHtmlTag('ul');
             $month_ul_tag->open();
             foreach ($values['months'] as $month => $post_count) {
                 $date = new SwatDate();
                 $date->setMonth($month);
                 $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->formatLikeIntl('MMMM'));
                 $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();
 }
Exemple #3
0
 /**
  * Checks whether or not this date tag applies to a given photo
  *
  * @param PinholePhoto the photo to check.
  *
  * @return boolean true if this tag applies to the given photo and false if
  *                  this tag does not apply to the given photo.
  */
 public function appliesToPhoto(PinholePhoto $photo)
 {
     switch ($this->name) {
         case 'date':
             $date = new SwatDate($this->value);
             // database content is always UTC
             $date->setTime(0, 0, 0);
             $date->toUTC();
             $applies = SwatDate::compare($photo->photo_date, $date) == 0;
             break;
         case 'week':
             if (ctype_digit($this->value)) {
                 // get date by week number
                 $days = ($this->value - 1) * 7;
                 $start_date = new SwatDate();
                 $start_date->setMonth(1);
                 $start_date->setDay(1);
                 $start_date->addDays($days);
                 // beginning of next week
                 $end_date = clone $start_date;
                 $end_date->addDays(7 - $end_date->getDayOfWeek());
             } else {
                 // beginning of week
                 $start_date = new SwatDate($this->value);
                 $start_date->subtractDays($start_date->getDayOfWeek());
                 // beginning of next week
                 $end_date = new SwatDate($this->value);
                 $end_date->addDays(7 - $end_date->getDayOfWeek());
             }
             // database content is always UTC
             $start_date->setTime(0, 0, 0);
             $end_date->setTime(0, 0, 0);
             $start_date->toUTC();
             $end_date->toUTC();
             $applies = SwatDate::compare($photo->photo_date, $start_date) >= 0 && SwatDate::compare($photo->photo_date, $end_date) <= 0;
             break;
         case 'year':
             $local_photo_date = clone $photo->photo_date;
             $local_photo_date->convertTZById($photo->photo_time_zone);
             $applies = $local_photo_date->getYear() == $this->value;
             break;
         case 'month':
             $local_photo_date = clone $photo->photo_date;
             $local_photo_date->convertTZById($photo->photo_time_zone);
             $applies = $local_photo_date->getMonth() == $this->value;
             break;
         case 'day':
             $local_photo_date = clone $photo->photo_date;
             $local_photo_date->convertTZById($photo->photo_time_zone);
             $applies = $local_photo_date->getDay() == $this->value;
             break;
         default:
             $applies = false;
             break;
     }
     return $applies;
 }
 /**
  * Displays date.date tags for all the photos in the site instance of
  * this date tag browser's tag list
  *
  * The <i>$start_date</i> and <i>$end_date</i> are used to tell which
  * day, month and year are currently selected.
  *
  * @param SwatDate $start_date the start date of the photos in this date
  *                              tag browser's tag list.
  * @param SwatDate $end_date the end date of the photos in this date
  *                              tag browser's tag list.
  */
 protected function displayDays(SwatDate $start_date, SwatDate $end_date)
 {
     $date = new SwatDate();
     /*
      * Setting the month and year to the $start_date month and year makes
      * sense because the day list is only displayed if the start year and
      * month are the same as the end year and month.
      */
     $date->setMonth($start_date->getMonth());
     $date->setYear($start_date->getYear());
     // get selected day if it exists
     if ($start_date->getDay() == $end_date->getDay()) {
         $selected_day = $start_date->getDay();
     } else {
         $selected_day = null;
     }
     // create base tag list that new date.month tags will be added to
     $tag_list = $this->tag_list->filter(array('PinholeDateTag'));
     $tag_list->add(sprintf('date.year=%s', $date->formatLikeIntl('yyyy')));
     $tag_list->add(sprintf('date.month=%s', $date->formatLikeIntl('MM')));
     $photos = $tag_list->getPhotoCountByDate('day');
     // Filter again since the day list uses date.date tags instead of
     // combined date.year, date.month and date.day tags.
     $tag_list = $this->tag_list->filter(array('PinholeDateTag'));
     // display date.date tags for each day
     $div_tag = new SwatHtmlTag('div');
     $div_tag->class = 'days clearfix';
     $div_tag->open();
     $days_in_month = $date->getDaysInMonth();
     for ($i = 1; $i <= $days_in_month; $i++) {
         $date->setDay($i);
         $key = $date->formatLikeIntl('yyyy-MM-dd');
         $tag_string = sprintf('date.date=%s', $date->formatLikeIntl('yyyy-MM-dd'));
         $tag_list->add($tag_string);
         if ($selected_day === $i) {
             $span_tag = new SwatHtmlTag('span');
             $span_tag->setContent($date->formatLikeIntl('dd'));
             $span_tag->class = 'selected';
             $span_tag->display();
         } elseif (array_key_exists($key, $photos)) {
             $a_tag = new SwatHtmlTag('a');
             $a_tag->href = $this->base . '?' . $tag_list->__toString();
             $a_tag->title = sprintf(Pinhole::ngettext('1 photo', '%s photos', $photos[$key]), SwatString::numberFormat($photos[$key]));
             $a_tag->setContent($date->formatLikeIntl('dd'));
             $a_tag->display();
         } else {
             $span_tag = new SwatHtmlTag('span');
             $span_tag->setContent($date->formatLikeIntl('dd'));
             $span_tag->display();
         }
         $tag_list->remove($tag_string);
     }
     $div_tag->close();
 }