Copyright 2008-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Michael J. Rubinsky (mrubinsk@horde.org)
コード例 #1
0
ファイル: DateGallery.php プロジェクト: jubinpatel/horde
 /**
  * Outputs the html for a DateGallery tile.
  *
  * @param Ansel_Gallery_Decorator_Date $dgallery  The Ansel_Gallery_Date we are
  *                                     displaying.
  * @param Ansel_Style $style  A style object.
  * @param boolean $mini       Force the use of a mini thumbail?
  * @param array $params       An array containing additional parameters.
  *                            Currently, gallery_view_url and image_view_url
  *                            are used to override the respective urls.
  *                            %g and %i are replaced with image id and
  *                            gallery id, respectively.
  *
  * @return string  The HTML for the tile.
  */
 public function getTile(Ansel_Gallery_Decorator_Date $dgallery, Ansel_Style $style = null, $mini = false, array $params = array())
 {
     $view = $GLOBALS['injector']->createInstance('Horde_View');
     $view->addTemplatePath(ANSEL_TEMPLATES . '/tile');
     // User's preferred date format
     $date_format = $GLOBALS['prefs']->getValue('date_format');
     $date_array = $dgallery->getDate();
     if (empty($date_array['month'])) {
         $date_array['month'] = 1;
     }
     if (empty($date_array['day'])) {
         $date_array['day'] = 1;
     }
     $full_date = new Horde_Date($date_array);
     // Need the unaltered date part array
     $date_array = $dgallery->getDate();
     // Figure out the needed link for the next drill down level. We *must*
     // have at least a year since we are in a date tile.
     if (empty($date_array['month'])) {
         // unit == year
         $view->caption = $full_date->strftime('%Y');
         $next_date = array('year' => (int) $view->caption);
     } elseif (empty($date_array['day'])) {
         // unit == month
         $view->caption = $full_date->strftime('%B %Y');
         $next_date = array('year' => date('Y', $full_date->timestamp()), 'month' => date('n', $full_date->timestamp()));
     } else {
         // unit == day
         $view->caption = $full_date->strftime($date_format);
         $next_date = array('year' => date('Y', $full_date->timestamp()), 'month' => date('n', $full_date->timestamp()), 'day' => date('j', $full_date->timestamp()));
     }
     // Check permissions on the gallery and get appropriate tile image
     if ($dgallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
         if (is_null($style)) {
             $style = $dgallery->getStyle();
         }
         $thumbstyle = $mini ? 'mini' : 'thumb';
         $view->gallery_image = Ansel::getImageUrl($dgallery->getKeyImage(), $thumbstyle, true, $style);
     } else {
         $view->gallery_image = Horde_Themes::img('thumb-error.png');
     }
     /* Check for being called via the api and generate correct view links */
     if (!isset($params['gallery_view_url'])) {
         if (empty($params['style'])) {
             $gstyle = $dgallery->getStyle();
         } else {
             $gstyle = $params['style'];
         }
         $params = array('gallery' => $dgallery->id, 'view' => 'Gallery', 'slug' => $dgallery->get('slug'));
         $view->view_link = Ansel::getUrlFor('view', array_merge($params, $next_date));
     } else {
         $view->view_link = new Horde_Url(str_replace(array('%g', '%s'), array($dgallery->id, $dgallery->get('slug')), urldecode($params['gallery_view_url'])));
         $view->view_link->add($next_date);
     }
     $view->gallery_count = $dgallery->countImages(true);
     return $view->render('dategallery');
 }
コード例 #2
0
ファイル: Date.php プロジェクト: horde/horde
 /**
  * Get the children of this gallery.
  *
  * @param integer $perm    The permissions to limit to.
  * @param integer $from    The child to start at.
  * @param integer $to      The child to end with.
  * @param boolean $noauto  Whether or not to automatically drill down to the
  *                         first grouping with more then one group.
  *
  * @return array A mixed array of Ansel_Gallery_Decorator_Date and
  *               Ansel_Image objects.
  */
 public function getGalleryChildren($perm = Horde_Perms::SHOW, $from = 0, $to = 0, $noauto = false)
 {
     // Cache the results
     static $children = array();
     $fullkey = md5($noauto . $perm . $this->_gallery->id . serialize($this->_date) . 0 . 0);
     $cache_key = md5($noauto . $perm . $this->_gallery->id . serialize($this->_date) . $from . $to);
     if (!empty($children[$cache_key])) {
         return $children[$cache_key];
     } elseif (!empty($children[$fullkey])) {
         return $this->_getArraySlice($children[$fullkey], $from, $to, true);
     }
     $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
     // Get a list of all the subgalleries
     $this->_loadSubGalleries();
     $params = array('fields' => array('image_id', 'image_original_date'));
     if (count($this->_subGalleries)) {
         $params['gallery_id'] = array_merge($this->_subGalleries, array($this->_gallery->id));
     } else {
         $params['gallery_id'] = $this->_gallery->id;
     }
     $sorted_dates = array();
     // See how specific the date is
     if (!count($this->_date) || empty($this->_date['year'])) {
         // All available images - grouped by year
         $images = $ansel_storage->listImages($params);
         $dates = array();
         foreach ($images as $key => $image) {
             $dates[date('Y', $image['image_original_date'])][] = $key;
         }
         $keys = array_keys($dates);
         // Drill down further if we only have a single group
         if (!$noauto && count($keys) == 1) {
             $this->_date['year'] = array_pop($keys);
             return $this->getGalleryChildren($perm, $from, $to, $noauto);
         }
         sort($keys, SORT_NUMERIC);
         foreach ($keys as $key) {
             $sorted_dates[$key] = $dates[$key];
         }
         $display_unit = 'year';
     } elseif (empty($this->_date['month'])) {
         // Specific year - grouped by month
         $start = new Horde_Date(array('year' => $this->_date['year'], 'month' => 1, 'day' => 1));
         // Last second of the year
         $end = new Horde_Date($start);
         $end->mday = 31;
         $end->month = 12;
         $end->hour = 23;
         $end->min = 59;
         $end->sec = 59;
         // Get the image ids and dates
         $params['filter'] = array(array('property' => 'originalDate', 'op' => '<=', 'value' => (int) $end->timestamp()), array('property' => 'originalDate', 'op' => '>=', 'value' => (int) $start->timestamp()));
         $images = $ansel_storage->listImages($params);
         $dates = array();
         foreach ($images as $key => $image) {
             $dates[date('n', $image['image_original_date'])][] = $key;
         }
         $keys = array_keys($dates);
         // Only 1 date grouping here, automatically drill down
         if (!$noauto && count($keys) == 1) {
             $this->_date['month'] = array_pop($keys);
             return $this->getGalleryChildren($perm, $from, $to, $noauto);
         }
         sort($keys, SORT_NUMERIC);
         foreach ($keys as $key) {
             $sorted_dates[$key] = $dates[$key];
         }
         $display_unit = 'month';
     } elseif (empty($this->_date['day'])) {
         // A single month - group by day
         $start = new Horde_Date(array('year' => $this->_date['year'], 'month' => $this->_date['month'], 'day' => 1));
         // Last second of the month
         $end = new Horde_Date($start);
         $end->mday = Horde_Date_Utils::daysInMonth($end->month, $end->year);
         $end->hour = 23;
         $end->min = 59;
         $end->sec = 59;
         $params['filter'] = array(array('property' => 'originalDate', 'op' => '<=', 'value' => (int) $end->timestamp()), array('property' => 'originalDate', 'op' => '>=', 'value' => (int) $start->timestamp()));
         $images = $ansel_storage->listImages($params);
         $dates = array();
         foreach ($images as $key => $image) {
             $dates[date('d', $image['image_original_date'])][] = $key;
         }
         $keys = array_keys($dates);
         // Only a single grouping, go deeper
         if (!$noauto && count($keys) == 1) {
             $this->_date['day'] = array_pop($keys);
             return $this->getGalleryChildren($perm, $from, $to, $noauto);
         }
         sort($keys, SORT_NUMERIC);
         foreach ($keys as $key) {
             $sorted_dates[$key] = $dates[$key];
         }
         $dates = $sorted_dates;
         $display_unit = 'day';
     } else {
         // We are down to a specific day
         $start = new Horde_Date($this->_date);
         // Last second of this day
         $end = new Horde_Date($start->timestamp());
         $end->hour = 23;
         $end->min = 59;
         $end->sec = 59;
         // Filter for this day
         $params['filter'] = array(array('property' => 'originalDate', 'op' => '<=', 'value' => (int) $end->timestamp()), array('property' => 'originalDate', 'op' => '>=', 'value' => (int) $start->timestamp()));
         // Only get what we need
         $params['offset'] = $from;
         $params['limit'] = $to;
         // Default to asking for just image_ids
         unset($params['fields']);
         // Get the image list
         $images = $ansel_storage->listImages($params);
         if ($images) {
             $results = $ansel_storage->getImages(array('ids' => $images, 'preserve' => true));
         } else {
             $results = array();
         }
         if ($this->_gallery->get('has_subgalleries')) {
             $images = array();
             foreach ($results as $id => $image) {
                 $image->gallery = $this->_gallery->id;
                 $images[$id] = $image;
             }
             $children[$cache_key] = $images;
         } else {
             $children[$cache_key] = $results;
         }
         return $children[$cache_key];
     }
     $results = array();
     foreach ($sorted_dates as $key => $images) {
         /* Get the new date parameter */
         switch ($display_unit) {
             case 'year':
                 $date = array('year' => $key);
                 break;
             case 'month':
                 $date = array('year' => $this->_date['year'], 'month' => (int) $key);
                 break;
             case 'day':
                 $date = array('year' => (int) $this->_date['year'], 'month' => (int) $this->_date['month'], 'day' => (int) $key);
         }
         $obj = new Ansel_Gallery_Decorator_Date($this->_gallery, $images);
         $obj->setDate($date);
         $results[$key] = $obj;
     }
     $children[$cache_key] = $results;
     if ($from > 0 || $to > 0) {
         return $this->_getArraySlice($results, $from, $to, true);
     }
     return $results;
 }