예제 #1
0
 public static function displayCalendarBody(SiteWebApplication $app, SwatDate $date)
 {
     if (isset($app->memcache)) {
         $cache_key = sprintf('PinholeCalendarGadget.%s.%s.%s', 'displayCalendarBody', $date->getISO8601(), $app->session->isLoggedIn() ? 'private' : 'public');
         $body = $app->memcache->getNs('photos', $cache_key);
         if ($body !== false) {
             echo $body;
             return;
         }
     }
     ob_start();
     $day_count = self::getPhotoCountPerDay($app, $date);
     echo '<table>';
     $wd = new SwatDate();
     $wd->setDate(1995, 1, 1);
     echo '<tr class="days-of-week">';
     for ($i = 1; $i <= 7; $i++) {
         echo '<td>' . $wd->formatLikeIntl('EEE') . '</td>';
         $wd->setDay($i + 1);
     }
     echo '</tr>';
     $locale = SwatI18NLocale::get();
     $start = -1 * $date->getDayOfWeek() + 1;
     $current_date = clone $date;
     for ($i = 0; $i <= 41; $i++) {
         $day = $i + $start;
         if ($i == 0) {
             echo '<tr>';
         } elseif ($i % 7 == 0) {
             echo '</tr><tr>';
         }
         if ($day > 0 && $day <= $date->getDaysInMonth()) {
             $current_date->setDay($day);
             if (array_key_exists($day, $day_count)) {
                 printf('<td class="has-photos">' . '<a href="%stag?date.date=%s" ' . 'title="%s %s">%s</a></td>', $app->config->pinhole->path, $current_date->formatLikeIntl('yyyy-MM-dd'), $locale->formatNumber($day_count[$day]), Pinhole::ngettext('Photo', 'Photos', $day_count[$day]), $day);
             } else {
                 echo '<td>' . $day . '</td>';
             }
         } else {
             echo '<td>&nbsp;</td>';
         }
     }
     echo '</tr></table>';
     $body = ob_get_clean();
     if (isset($app->memcache)) {
         $app->memcache->setNs('photos', $cache_key, $body);
     }
     echo $body;
 }
예제 #2
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;
 }
예제 #3
0
 /**
  * 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();
 }