Overview

Packages

  • Ansel
  • None

Classes

  • Ansel
  • Ansel_Ajax_Application
  • Ansel_Ajax_Imple_EditCaption
  • Ansel_Ajax_Imple_EditFaces
  • Ansel_Ajax_Imple_EditGalleryFaces
  • Ansel_Ajax_Imple_Embed
  • Ansel_Ajax_Imple_GallerySlugCheck
  • Ansel_Ajax_Imple_ImageSaveGeotag
  • Ansel_Ajax_Imple_LocationAutoCompleter
  • Ansel_Ajax_Imple_MapLayerSelect
  • Ansel_Ajax_Imple_TagActions
  • Ansel_Ajax_Imple_ToggleGalleryActions
  • Ansel_Ajax_Imple_ToggleOtherGalleries
  • Ansel_Ajax_Imple_UploadNotification
  • Ansel_Api
  • Ansel_Exception
  • Ansel_Faces
  • Ansel_Faces_Base
  • Ansel_Faces_Facedetect
  • Ansel_Faces_User
  • Ansel_Factory_Faces
  • Ansel_Factory_Storage
  • Ansel_Factory_Styles
  • Ansel_Form_Ecard
  • Ansel_Form_Image
  • Ansel_Form_ImageDate
  • Ansel_Form_Upload
  • Ansel_Gallery
  • Ansel_Gallery_Decorator_Date
  • Ansel_GalleryMode_Base
  • Ansel_GalleryMode_Date
  • Ansel_GalleryMode_Normal
  • Ansel_Image
  • Ansel_ImageGenerator
  • Ansel_ImageGenerator_Mini
  • Ansel_ImageGenerator_PolaroidThumb
  • Ansel_ImageGenerator_PolaroidThumbStack
  • Ansel_ImageGenerator_RoundedThumb
  • Ansel_ImageGenerator_RoundedThumbStack
  • Ansel_ImageGenerator_Screen
  • Ansel_ImageGenerator_ShadowThumb
  • Ansel_ImageGenerator_ShadowThumbStack
  • Ansel_ImageGenerator_SquareThumb
  • Ansel_ImageGenerator_Thumb
  • Ansel_LoginTasks_SystemTask_Upgrade
  • Ansel_Report
  • Ansel_Report_letter
  • Ansel_Report_mail
  • Ansel_Report_tickets
  • Ansel_Search
  • Ansel_Search_exif
  • Ansel_Search_Tag
  • Ansel_Storage
  • Ansel_Style
  • Ansel_Tagger
  • Ansel_Test
  • Ansel_Tile_DateGallery
  • Ansel_Tile_Gallery
  • Ansel_Tile_Image
  • Ansel_View_Ansel
  • Ansel_View_Base
  • Ansel_View_EmbeddedRenderer_GalleryLink
  • Ansel_View_EmbeddedRenderer_Mini
  • Ansel_View_EmbeddedRenderer_Slideshow
  • Ansel_View_Gallery
  • Ansel_View_GalleryProperties
  • Ansel_View_GalleryRenderer_Base
  • Ansel_View_GalleryRenderer_Gallery
  • Ansel_View_GalleryRenderer_GalleryLightbox
  • Ansel_View_Image
  • Ansel_View_List
  • Ansel_View_Results
  • Ansel_View_Slideshow
  • Ansel_View_Upload
  • Ansel_Widget
  • Ansel_Widget_Actions
  • Ansel_Widget_Base
  • Ansel_Widget_GalleryFaces
  • Ansel_Widget_Geotag
  • Ansel_Widget_ImageFaces
  • Ansel_Widget_Links
  • Ansel_Widget_OtherGalleries
  • Ansel_Widget_OwnerFaces
  • Ansel_Widget_SimilarPhotos
  • Ansel_Widget_Tags
  • Ansel_XPPublisher
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Ansel_GalleryMode_Date:: Class for encapsulating gallery methods that
  4:  * depend on the current display mode of the gallery being Date.
  5:  *
  6:  * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @author Michael J. Rubinsky <mrubinsk@horde.org>
 12:  * @package Ansel
 13:  */
 14: class Ansel_GalleryMode_Date extends Ansel_GalleryMode_Base
 15: {
 16:     /**
 17:      * The date part array for the current grouping.
 18:      *
 19:      * @var array
 20:      */
 21:     protected $_date = array();
 22: 
 23:     /**
 24:      * Supported features
 25:      *
 26:      * @var array
 27:      */
 28:     protected $_features = array('slideshow', 'zipdownload', 'upload');
 29: 
 30:     /**
 31:      * The subgalleries whose images need to be included in this date grouping.
 32:      *
 33:      * @var array
 34:      */
 35:     protected $_subGalleries = null;
 36: 
 37:     /**
 38:      * See if a feature is supported.
 39:      *
 40:      * @param string $feature  The feature
 41:      *
 42:      * @return boolean
 43:      */
 44:     public function hasFeature($feature)
 45:     {
 46:         /* First, some special cases */
 47:         switch ($feature) {
 48:         case 'sort_images':
 49:         case 'image_captions':
 50:         case 'faces':
 51:             /* Only allowed when we are on a specific day */
 52:             return !empty($this->_date['day']);
 53: 
 54:         default:
 55:             return parent::hasFeature($feature);
 56:         }
 57:     }
 58: 
 59:     /**
 60:      * Get an array describing where this gallery is in a breadcrumb trail.
 61:      *
 62:      * @return array  An array of 'title' and 'navdata' hashes with the [0]
 63:      *                element being the deepest part.
 64:      */
 65:     public function getGalleryCrumbData()
 66:     {
 67:         $year = !empty($this->_date['year']) ? $this->_date['year'] : 0;
 68:         $month = !empty($this->_date['month']) ? $this->_date['month'] : 0;
 69:         $day = !empty($this->_date['day']) ? $this->_date['day'] : 0;
 70:         $trail = array();
 71: 
 72:         // Do we have any date parts?
 73:         if (!empty($year)) {
 74:             if (!empty($day)) {
 75:                 $date = new Horde_Date($this->_date);
 76:                 $text = $date->strftime('%e');
 77: 
 78:                 $navdata =  array(
 79:                     'view' => 'Gallery',
 80:                     'gallery' => $this->_gallery->id,
 81:                     'slug' => $this->_gallery->get('slug'),
 82:                     'year' => $year,
 83:                     'month' => $month,
 84:                     'day' => $day);
 85:                 $trail[] = array('title' => $text, 'navdata' => $navdata);
 86:             }
 87: 
 88:             if (!empty($month)) {
 89:                 $date = new Horde_Date(
 90:                     array(
 91:                         'year' => $year,
 92:                         'month' => $month,
 93:                         'day' => 1));
 94:                 $text = $date->strftime('%B');
 95:                 $navdata = array(
 96:                     'view' => 'Gallery',
 97:                     'gallery' => $this->_gallery->id,
 98:                     'slug' => $this->_gallery->get('slug'),
 99:                     'year' => $year,
100:                     'month' => $month);
101:                 $trail[] = array('title' => $text, 'navdata' => $navdata);
102:             }
103: 
104:             $navdata = array(
105:                 'view' => 'Gallery',
106:                 'gallery' => $this->_gallery->id,
107:                 'slug' => $this->_gallery->get('slug'),
108:                 'year' => $year);
109:             $trail[] = array('title' => $year, 'navdata' => $navdata);
110:         } else {
111:             // This is the first level of a date mode gallery.
112:             $navdata = array(
113:                 'view' => 'Gallery',
114:                 'gallery' => $this->_gallery->id,
115:                 'slug' => $this->_gallery->get('slug'));
116:             $trail[] = array('title' => _("All dates"), 'navdata' => $navdata);
117:         }
118: 
119:         $text = htmlspecialchars($this->_gallery->get('name'));
120:         $navdata = array(
121:             'view' => 'Gallery',
122:             'gallery' => $this->_gallery->id,
123:             'slug' => $this->_gallery->get('slug'));
124:         $trail[] = array('title' => $text, 'navdata' => $navdata);
125: 
126:         return $trail;
127:     }
128: 
129:     /**
130:      * Getter for date
131:      *
132:      * @return array  A date parts array.
133:      */
134:     public function getDate()
135:     {
136:         return $this->_date;
137:     }
138: 
139:     /**
140:      * Setter for date
141:      *
142:      * @param array $date
143:      */
144:     public function setDate($date = array())
145:     {
146:         $this->_date = $date;
147:     }
148: 
149:     /**
150:      * Get the children of this gallery.
151:      *
152:      * @param integer $perm    The permissions to limit to.
153:      * @param integer $from    The child to start at.
154:      * @param integer $to      The child to end with.
155:      * @param boolean $noauto  Whether or not to automatically drill down to the
156:      *                         first grouping with more then one group.
157:      *
158:      * @return array A mixed array of Ansel_Gallery_Decorator_Date and
159:      *               Ansel_Image objects.
160:      */
161:     public function getGalleryChildren(
162:         $perm = Horde_Perms::SHOW, $from = 0, $to = 0, $noauto = false)
163:     {
164:         // Cache the results
165:         static $children = array();
166: 
167:         $fullkey = md5($noauto . $perm . $this->_gallery->id . serialize($this->_date) . 0 . 0);
168:         $cache_key = md5($noauto . $perm . $this->_gallery->id . serialize($this->_date) . $from . $to);
169:         if (!empty($children[$cache_key])) {
170:             return $children[$cache_key];
171:         } elseif (!empty($children[$fullkey])) {
172:             return $this->_getArraySlice($children[$fullkey], $from, $to, true);
173:         }
174: 
175:         $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
176: 
177:         // Get a list of all the subgalleries
178:         $this->_loadSubGalleries();
179:         $params = array(
180:             'fields' => array('image_id', 'image_original_date')
181:         );
182:         if (count($this->_subGalleries)) {
183:             $params['gallery_id'] = array_merge(
184:                 $this->_subGalleries,
185:                 array($this->_gallery->id));
186:         } else {
187:             $params['gallery_id'] = $this->_gallery->id;
188:         }
189:         $sorted_dates = array();
190: 
191:         // See how specific the date is
192:         if (!count($this->_date) || empty($this->_date['year'])) {
193:             // All available images - grouped by year
194:             $images = $ansel_storage->listImages($params);
195:             $dates = array();
196:             foreach ($images as $key => $image) {
197:                 $dates[date('Y', $image['image_original_date'])][] = $key;
198:             }
199:             $keys = array_keys($dates);
200: 
201:             // Drill down further if we only have a single group
202:             if (!$noauto && count($keys) == 1) {
203:                 $this->_date['year'] = array_pop($keys);
204:                 return $this->getGalleryChildren($perm, $from, $to, $noauto);
205:             }
206: 
207:             sort($keys, SORT_NUMERIC);
208:             foreach ($keys as $key) {
209:                 $sorted_dates[$key] = $dates[$key];
210:             }
211:             $display_unit = 'year';
212:         } elseif (empty($this->_date['month'])) {
213:             // Specific year - grouped by month
214:             $start = new Horde_Date(
215:                 array(
216:                     'year' => $this->_date['year'],
217:                     'month' => 1,
218:                     'day' => 1)
219:             );
220: 
221:             // Last second of the year
222:             $end = new Horde_Date($start);
223:             $end->mday = 31;
224:             $end->month = 12;
225:             $end->hour = 23;
226:             $end->min = 59;
227:             $end->sec = 59;
228: 
229:             // Get the image ids and dates
230:             $params['filter'] = array(
231:                 array(
232:                     'property' => 'originalDate',
233:                     'op' => '<=',
234:                     'value' => (int)$end->timestamp()
235:                 ),
236:                 array(
237:                     'property' => 'originalDate',
238:                     'op' => '>=',
239:                     'value' => (int)$start->timestamp()
240:                 )
241:             );
242:             $images= $ansel_storage->listImages($params);
243:             $dates = array();
244:             foreach ($images as $key => $image) {
245:                 $dates[date('n', $image['image_original_date'])][] = $key;
246:             }
247:             $keys = array_keys($dates);
248: 
249:             // Only 1 date grouping here, automatically drill down
250:             if (!$noauto && count($keys) == 1) {
251:                 $this->_date['month'] = array_pop($keys);
252:                 return $this->getGalleryChildren($perm, $from, $to, $noauto);
253:             }
254: 
255:             sort($keys, SORT_NUMERIC);
256:             foreach ($keys as $key) {
257:                 $sorted_dates[$key] = $dates[$key];
258:             }
259:             $display_unit = 'month';
260:         } elseif (empty($this->_date['day'])) {
261:             // A single month - group by day
262:             $start = new Horde_Date(
263:                 array(
264:                     'year' => $this->_date['year'],
265:                     'month' => $this->_date['month'],
266:                     'day' => 1)
267:             );
268: 
269:             // Last second of the month
270:             $end = new Horde_Date($start);
271:             $end->mday = Horde_Date_Utils::daysInMonth($end->month, $end->year);
272:             $end->hour = 23;
273:             $end->min = 59;
274:             $end->sec = 59;
275: 
276:             $params['filter'] = array(
277:                 array(
278:                     'property' => 'originalDate',
279:                     'op' => '<=',
280:                     'value' => (int)$end->timestamp()
281:                 ),
282:                 array(
283:                     'property' => 'originalDate',
284:                     'op' => '>=',
285:                     'value' => (int)$start->timestamp()
286:                 )
287:             );
288:             $images= $ansel_storage->listImages($params);
289:             $dates = array();
290:             foreach ($images as $key => $image) {
291:                 $dates[date('d', $image['image_original_date'])][] = $key;
292:             }
293:             $keys = array_keys($dates);
294: 
295:             // Only a single grouping, go deeper
296:             if (!$noauto && count($keys) == 1) {
297:                 $this->_date['day'] = array_pop($keys);
298:                 return $this->getGalleryChildren($perm, $from, $to, $noauto);
299:             }
300: 
301:             sort($keys, SORT_NUMERIC);
302:             foreach ($keys as $key) {
303:                 $sorted_dates[$key] = $dates[$key];
304:             }
305:             $dates = $sorted_dates;
306:             $display_unit = 'day';
307:         } else {
308:             // We are down to a specific day
309:             $start = new Horde_Date($this->_date);
310: 
311:             // Last second of this day
312:             $end = new Horde_Date($start->timestamp());
313:             $end->hour = 23;
314:             $end->min = 59;
315:             $end->sec = 59;
316: 
317:             // Filter for this day
318:             $params['filter'] = array(
319:                 array(
320:                     'property' => 'originalDate',
321:                     'op' => '<=',
322:                     'value' => (int)$end->timestamp()
323:                 ),
324:                 array(
325:                     'property' => 'originalDate',
326:                     'op' => '>=',
327:                     'value' => (int)$start->timestamp()
328:                 )
329:             );
330: 
331:             // Only get what we need
332:             $params['offset'] = $from;
333:             $params['limit'] = $to;
334: 
335:             // Default to asking for just image_ids
336:             unset($params['fields']);
337: 
338:             // Get the image list
339:             $images = $ansel_storage->listImages($params);
340:             if ($images) {
341:                 $results = $ansel_storage->getImages(
342:                     array('ids' => $images, 'preserve' => true));
343:             } else {
344:                 $results = array();
345:             }
346: 
347:             if ($this->_gallery->get('has_subgalleries')) {
348:                 $images = array();
349:                 foreach ($results as $id => $image) {
350:                     $image->gallery = $this->_gallery->id;
351:                     $images[$id] = $image;
352:                 }
353:                 $children[$cache_key] = $images;
354:             } else {
355:                 $children[$cache_key] = $results;
356:             }
357: 
358:             return $children[$cache_key];
359:         }
360: 
361:         $results = array();
362:         foreach ($sorted_dates as $key => $images) {
363:             /* Get the new date parameter */
364:             switch ($display_unit) {
365:             case 'year':
366:                 $date = array('year' => $key);
367:                 break;
368:             case 'month':
369:                 $date = array(
370:                     'year' => $this->_date['year'],
371:                     'month' => (int)$key);
372:                 break;
373:             case 'day':
374:                 $date = array(
375:                     'year' => (int)$this->_date['year'],
376:                     'month' => (int)$this->_date['month'],
377:                     'day' => (int)$key);
378:             }
379: 
380:             $obj = new Ansel_Gallery_Decorator_Date($this->_gallery, $images);
381:             $obj->setDate($date);
382:             $results[$key] = $obj;
383:         }
384: 
385:         $children[$cache_key] = $results;
386:         if ($from > 0 || $to > 0) {
387:             return $this->_getArraySlice($results, $from, $to, true);
388:         }
389: 
390:         return $results;
391:     }
392: 
393:     /**
394:      * Return the count of this gallery's children
395:      *
396:      * @param integer $perm            The permissions to require.
397:      * @param boolean $galleries_only  Only include galleries, no images.
398:      *                                 (Ignored since this makes no sense for a
399:      *                                  gallery grouped by dates).
400:      * @param boolean $noauto          Auto navigate down to the first populated
401:      *                                 date grouping.
402:      *
403:      * @return integer The count of this gallery's children. The count is either
404:      *                 a count of of the number of date groupings (months, days,
405:      *                 etc..) that need to be displayed, or a count of all the
406:      *                 images in the current date grouping (for a specific day).
407:      */
408:     public function countGalleryChildren($perm = Horde_Perms::SHOW,
409:                                          $galleries_only = false, $noauto = true)
410:     {
411:         $results = $this->getGalleryChildren($perm, 0, 0, $noauto);
412:         return count($results);
413:     }
414: 
415:     /**
416:      * Lists a slice of the image ids in this gallery.
417:      * In Date mode, this only makes sense if we are currently viewing a
418:      * specific day, otherwise we return 0.
419:      *
420:      * @param integer $from  The image to start listing.
421:      * @param integer $count The numer of images to list.
422:      *
423:      * @return array  An array of image_ids
424:      */
425:     public function listImages($from = 0, $count = 0)
426:     {
427:         /* Get all of this grouping's children. */
428:         $children = $this->getGalleryChildren();
429: 
430:         /* At day level, these are all Ansel_Images */
431:         if (!empty($this->_date['day'])) {
432:             $images = array_keys($children);
433:         } else {
434:             $images = array();
435:             // typeof $child == Ansel_Gallery_Decorator_Date
436:             foreach ($children as $child) {
437:                 $images = array_merge($images, $child->getImagesByGrouping());
438:             }
439:         }
440: 
441:         return $this->_getArraySlice($images, $from, $count);
442:     }
443: 
444:     /**
445:      * Moves images from one gallery to another. Since we're viewing by date
446:      * some images might belong to a subgallery so we need to take care to
447:      * udate the appropriate gallery data.
448:      *
449:      * @param array $images           An array of image_ids to move.
450:      * @param Ansel_Gallery $gallery  The Ansel_Gallery to move them to.
451:      *
452:      * @return boolean
453:      */
454:     public function moveImagesTo($images, $gallery)
455:     {
456:         if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
457:             throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied moving photos to \"%s\"."), $newGallery->get('name')));
458:         } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
459:             throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied removing photos from \"%s\"."), $gallery->get('name')));
460:         }
461: 
462:         /* Sanitize image ids, and see if we're removing our key image. */
463:         $ids = array();
464:         foreach ($images as $imageId) {
465:             $ids[] = (int)$imageId;
466:             if ($imageId == $this->_gallery->get('default')) {
467:                 $this->_gallery->set('default', null, true);
468:             }
469:         }
470: 
471:         /* If we have subgalleries, we need to go the more expensive route. Note
472:          * we can't use $gallery->hasSubgalleries() since that would be
473:          * overridden here since we are in date mode and thus would return false
474:          */
475:         if ($this->_gallery->get('has_subgalleries')) {
476:             $gallery_ids = array();
477:             $images = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImages(array('ids' => $ids));
478:             foreach ($images as $image) {
479:                 if (empty($gallery_ids[$image->gallery])) {
480:                     $gallery_ids[$image->gallery] = 1;
481:                 } else {
482:                     $gallery_ids[$image->gallery]++;
483:                 }
484:             }
485:         }
486: 
487:         /* Bulk update the images to their new gallery_id */
488:         $GLOBALS['injector']->getInstance('Ansel_Storage')->setImagesGallery($ids, $gallery->id);
489: 
490:         /* Update the gallery counts for each affected gallery */
491:         if ($this->_gallery->get('has_subgalleries')) {
492:             foreach ($gallery_ids as $id => $count) {
493:                 $GLOBALS['injector']->getInstance('Ansel_Storage')
494:                     ->getGallery($id)
495:                     ->updateImageCount($count, false);
496:             }
497:         } else {
498:             $this->_gallery->updateImageCount(count($ids), false);
499:         }
500:         $gallery->updateImageCount(count($ids), true);
501: 
502:         /* Expire the cache since we have no reason to save() the gallery */
503:         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
504:             $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
505:             $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id);
506:         }
507: 
508:         return count($ids);
509:     }
510: 
511:     /**
512:      * Remove an image from this gallery. Note that the image might actually
513:      * belong to a subgallery of this gallery since we are viewing by date.
514:      * Need to take care of updating correct subgallery's image count etc...
515:      *
516:      * @param mixed $image      An image_id or Ansel_Image object to delete.
517:      * @param boolean $isStack  Image is a stack image (doesn't update count).
518:      *
519:      * @return boolean
520:      * @throws Horde_Exception_NotFound, Ansel_Exception
521:      */
522:     public function removeImage($image, $isStack)
523:     {
524:         // Make sure $image is an Ansel_Image; if not, try loading it.
525:         if (!($image instanceof Ansel_Image)) {
526:             $image = $GLOBALS['injector']
527:                 ->getInstance('Ansel_Storage')
528:                 ->getImage($image);
529:         }
530: 
531:         // If image is a stack image, $gallery will be negative.
532:         $image_gallery = abs($image->gallery);
533: 
534:         // Make sure the image is in this gallery.
535:         if ($image_gallery != $this->_gallery->id) {
536:             $this->_loadSubGalleries();
537:             if (!in_array($image_gallery, $this->_subGalleries)) {
538:                 throw new Horde_Exception_NotFound(_("Image not found in gallery."));
539:             }
540:         }
541: 
542:         /* Change gallery info. */
543:         if ($this->_gallery->get('default') == $image->id) {
544:             $this->_gallery->set('default', null);
545:             $this->_gallery->set('default_type' , 'auto');
546:         }
547: 
548:         /* Delete cached files from VFS. */
549:         $image->deleteCache();
550: 
551:         /* Delete original image from VFS. */
552:         try {
553:             $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->deleteFile($image->getVFSPath('full'),
554:                                               $image->getVFSName('full'));
555:         } catch (Horde_Vfs_Exception $e) {}
556: 
557:         /* Delete from storage */
558:         $GLOBALS['injector']->getInstance('Ansel_Storage')->removeImage($image->id);
559: 
560:         if (!$isStack) {
561:             $GLOBALS['injector']->getInstance('Ansel_Storage')
562:                     ->getGallery($image_gallery)
563:                     ->updateImageCount(1, false);
564:         }
565: 
566:         /* Update the modified flag if we are not a stack image */
567:         if (!$isStack) {
568:             $this->_gallery->set('last_modified', time());
569:         }
570: 
571:         /* Save all gallery changes */
572:         $this->_gallery->save();
573: 
574:         /* Clear the image's tags */
575:         $image->setTags(array());
576: 
577:         /* Clear the image's faces */
578:         if ($image->facesCount) {
579:             Ansel_Faces::delete($image);
580:         }
581: 
582:         /* Clear any comments */
583:         if (($GLOBALS['conf']['comments']['allow'] == 'all' || ($GLOBALS['conf']['comments']['allow'] == 'authenticated' && $GLOBALS['registry']->getAuth())) &&
584:             $GLOBALS['registry']->hasMethod('forums/deleteForum')) {
585:             try {
586:                 $GLOBALS['registry']->call('forums/deleteForum', array('ansel', $image->id));
587:             } catch (Horde_Exception $e) {
588:                 Horde::logMessage($e, 'ERR');
589:                 return false;
590:             }
591:         }
592: 
593:         return true;
594:     }
595: 
596:     /**
597:      * Gets a slice of the images in this gallery.
598:      *
599:      * @param integer $from  The image to start fetching.
600:      * @param integer $count The numer of images to return.
601:      *
602:      * @param array An array of Ansel_Image objects
603:      */
604:     public function getImages($from = 0, $count = 0)
605:     {
606:         if (!empty($this->_date['day'])) {
607:             // Get all of this grouping's children. At day level, these are all
608:             // Ansel_Images.
609:             $children = $this->getGalleryChildren(Horde_Perms::SHOW);
610:             return $this->_getArraySlice($children, $from, $count, true);
611:         } else {
612:             // We don't want to work with any images at this level in a DateMode
613:             // gallery.
614:             return array();
615:         }
616:     }
617: 
618:     /**
619:      * Checks if the gallery has any subgalleries. This will always be false
620:      * for a gallery in date view.
621:      *
622:      * @return boolean
623:      */
624:     public function hasSubGalleries()
625:     {
626:         return false;
627:     }
628: 
629:     /**
630:      * Returns the number of images in this gallery and, optionally, all
631:      * sub-galleries.
632:      *
633:      * @param boolean $subgalleries  Determines whether subgalleries should
634:      *                               be counted or not.
635:      *
636:      * @return integer number of images in this gallery
637:      */
638:     public function countImages($subgalleries = false)
639:     {
640:         return count($this->listImages());
641:     }
642: 
643:     /**
644:      * Helper function to get an array slice while preserving keys.
645:      *
646:      * @param unknown_type $array
647:      * @param unknown_type $from
648:      * @param unknown_type $count
649:      * @return unknown
650:      */
651:     protected function _getArraySlice($array, $from, $count, $preserve = false)
652:     {
653:         if ($from == 0 && $count == 0) {
654:             return $array;
655:         }
656: 
657:         return array_slice($array, $from, $count, $preserve);
658:     }
659: 
660:     /**
661:      * Get this gallery's subgalleries. Populates the private member
662:      *  _subGalleries
663:      */
664:     protected function _loadSubGalleries()
665:     {
666:         // Note: We set $this->_subGalleries to null by default so we don't
667:         // have to perform this check again, even if the gallery contains no
668:         // subgalleries (and thus _subGalleries would be an empty array).
669:         if (!is_array($this->_subGalleries)) {
670:             $this->_subGalleries = array();
671:             $subs = $GLOBALS['injector']
672:                 ->getInstance('Ansel_Storage')
673:                 ->listGalleries(array('parent' => $this->_gallery->id));
674:             foreach ($subs as $sub) {
675:                 $this->_subGalleries[] = $sub->id;
676:             }
677:         }
678:     }
679: }
680: 
API documentation generated by ApiGen