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_Gallery_Mode_Normal:: Class for encapsulating gallery methods that
  4:  * depend on the current display mode of the gallery.
  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_Normal extends Ansel_GalleryMode_Base
 15: {
 16:     /**
 17:      * The array of supported features
 18:      *
 19:      * @var array
 20:      */
 21:     protected $_features = array('subgalleries', 'stacks', 'sort_images',
 22:                                  'image_captions', 'faces', 'slideshow',
 23:                                  'zipdownload', 'upload');
 24: 
 25:     /**
 26:      * Get the children of this gallery.
 27:      *
 28:      * @param integer $perm   The permissions to limit to.
 29:      * @param integer $from   The child to start at.
 30:      * @param integer $count  The number of children to return.
 31:      *
 32:      * @return array  A mixed array of Ansel_Gallery and Ansel_Image objects
 33:      *                that are children of this gallery.
 34:      */
 35:     public function getGalleryChildren($perm = Horde_Perms::SHOW, $from = 0, $to = 0)
 36:     {
 37:         $galleries = array();
 38:         $num_galleries = 0;
 39:         if ($this->hasSubGalleries()) {
 40:             $storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
 41:             /* Get the number of images and galleries */
 42:             $numimages = $this->countImages();
 43:             $num_galleries = $storage->countGalleries(
 44:                 $GLOBALS['registry']->getAuth(),
 45:                 array('parent' => $this->_gallery, 'all_levels' => false));
 46: 
 47:             /* Now fetch the subgalleries, but only if we need to */
 48:             if ($num_galleries > $from) {
 49:                 $galleries = $storage->listGalleries(
 50:                         array('parent' => $this->_gallery->id,
 51:                               'all_levels' => false,
 52:                               'from' => $from,
 53:                               'count' => $to));
 54:             }
 55:         }
 56: 
 57:         /* Now grab any images if we still have room */
 58:         if (($to - count($galleries) > 0) || ($from == 0 && $to == 0) &&
 59:              $this->_gallery->get('images')) {
 60: 
 61:             try {
 62:                 $images = $this->getImages(max(0, $from - $num_galleries), $to - count($galleries));
 63:             } catch (Ansel_Exception $e) {
 64:                 Horde::logMessage($e->getMessage(), 'ERR');
 65:                 $images = array();
 66:             }
 67:         } else {
 68:             $images = array();
 69:         }
 70: 
 71:         return array_merge($galleries, $images);
 72:     }
 73: 
 74:     /**
 75:      * Get an array describing where this gallery is in a breadcrumb trail.
 76:      *
 77:      * @return  An array of 'title' and 'navdata' hashes with the [0] element
 78:      *          being the deepest part.
 79:      */
 80:     public function getGalleryCrumbData()
 81:     {
 82:         $trail = array();
 83:         $text = htmlspecialchars($this->_gallery->get('name'));
 84:         $navdata = array('view' => 'Gallery',
 85:                          'gallery' => $this->_gallery->id,
 86:                          'slug' => $this->_gallery->get('slug'));
 87:         $trail[] = array('title' => $text, 'navdata' => $navdata);
 88:         $parent_list = array_reverse($this->_gallery->getParents());
 89:         foreach ($parent_list as $p) {
 90:             $text = htmlspecialchars($p->get('name'));
 91:             $navdata = array('view' => 'Gallery',
 92:                              'gallery' => $p->id,
 93:                              'slug' => $p->get('slug'));
 94:             $trail[] = array('title' => $text, 'navdata' => $navdata);
 95:         }
 96: 
 97:         return $trail;
 98:     }
 99: 
100:     /**
101:      * Return the count this gallery's children
102:      *
103:      * @param integer $perm            The permissions to require.
104:      * @param boolean $galleries_only  Only include galleries, no images.
105:      *
106:      * @return integer The count of this gallery's children.
107:      */
108:     public function countGalleryChildren($perm = Horde_Perms::SHOW, $galleries_only = false)
109:     {
110:         if (!$galleries_only && !$this->hasSubGalleries()) {
111:             return $this->_gallery->get('images');
112:         }
113: 
114:         $gCnt = $GLOBALS['injector']->getInstance('Ansel_Storage')
115:                 ->countGalleries(
116:                     $GLOBALS['registry']->getAuth(),
117:                     array('perm' => $perm,
118:                           'parent' => $this->_gallery,
119:                           'all_levels' => false));
120: 
121:         if (!$galleries_only) {
122:             $iCnt = $this->countImages(false);
123:         } else {
124:             $iCnt = 0;
125:         }
126: 
127:         return $gCnt + $iCnt;
128:     }
129: 
130:     /**
131:      * Lists a slice of the image ids in this gallery.
132:      *
133:      * @param integer $from  The image to start listing.
134:      * @param integer $count The numer of images to list.
135:      *
136:      * @return array  An array of image_ids
137:      */
138:     public function listImages($from = 0, $count = 0)
139:     {
140:         return $GLOBALS['injector']
141:             ->getInstance('Ansel_Storage')
142:             ->listImages(array(
143:                 'gallery_id' => $this->_gallery->id,
144:                 'offset' => $from,
145:                 'limit' => $count));
146:     }
147: 
148:     /**
149:      * Move images from this gallery to another.
150:      *
151:      * @param array $images           The image ids to move.
152:      * @param Ansel_Gallery $gallery  The gallery to move images into.
153:      *
154:      * @return boolean
155:      * @throws Ansel_Exception
156:      * @throws Horde_Exception_PermissionDenied
157:      */
158:     public function moveImagesTo($images, $gallery)
159:     {
160:         if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
161:           throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied moving photos to \"%s\"."), $newGallery->get('name')));
162:         } elseif (!$this->_gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
163:             throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied removing photos from \"%s\"."), $gallery->get('name')));
164:         }
165: 
166:         /* Sanitize image ids, and see if we're removing our key image. */
167:         $ids = array();
168:         foreach ($images as $imageId) {
169:             $ids[] = (int)$imageId;
170:             if ($imageId == $this->_gallery->get('default')) {
171:                 $this->_gallery->set('default', null, true);
172:             }
173:         }
174: 
175:         $GLOBALS['injector']->getInstance('Ansel_Storage')->setImagesGallery($ids, $gallery->id);
176:         $this->_gallery->updateImageCount(count($ids), false);
177:         $gallery->updateImageCount(count($ids), true);
178: 
179:         /* Expire the cache since we have no reason to save() the gallery */
180:         if ($GLOBALS['conf']['ansel_cache']['usecache']) {
181:             $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $gallery->id);
182:             $GLOBALS['injector']->getInstance('Horde_Cache')->expire('Ansel_Gallery' . $this->_gallery->id);
183:         }
184: 
185:         return count($ids);
186:     }
187: 
188:     /**
189:      * Remove an image from Ansel.
190:      *
191:      * @param integer | Ansel_Image $image  The image id or object
192:      * @param boolean $isStack              This represents a stack image
193:      *
194:      * @return boolean
195:      * @throws Horde_Exception_NotFound
196:      */
197:     public function removeImage($image, $isStack)
198:     {
199:         // Make sure $image is an Ansel_Image; if not, try loading it.
200:         if (!($image instanceof Ansel_Image)) {
201:             $image = $this->_gallery->getImage($image);
202:         } else {
203:             // Make sure the image is in this gallery.
204:             if (abs($image->gallery) != $this->_gallery->id) {
205:                 throw new Horde_Exception_NotFound(_("Image not found in gallery."));
206:             }
207:         }
208: 
209:         /* Was this image the gallery's key image? */
210:         if ($this->_gallery->get('default') == $image->id) {
211:             $this->_gallery->set('default', null);
212:             $this->_gallery->set('default_type', 'auto');
213:         }
214: 
215:         /* Delete cached files from VFS. */
216:         $image->deleteCache();
217: 
218:         /* Delete original image from VFS. */
219:         try {
220:             $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->deleteFile($image->getVFSPath('full'), $image->getVFSName('full'));
221:         } catch (Horde_Vfs_Exception $e) {}
222: 
223:         /* Delete from storage */
224:         $GLOBALS['injector']->getInstance('Ansel_Storage')->removeImage($image->id);
225:         if (!$isStack) {
226:             $this->_gallery->updateImageCount(1, false);
227:         }
228: 
229:         /* Update the modified flag if we are not a stack image */
230:         if (!$isStack) {
231:             $this->_gallery->set('last_modified', time());
232:         }
233: 
234:         /* Save all gallery changes */
235:         $this->_gallery->save();
236: 
237:         /* Clear the image's tags */
238:         $image->setTags(array());
239: 
240:         /* Clear the image's faces */
241:         if ($image->facesCount) {
242:             Ansel_Faces::delete($image);
243:         }
244: 
245:         /* Clear any comments */
246:         if (($GLOBALS['conf']['comments']['allow'] == 'all' || ($GLOBALS['conf']['comments']['allow'] == 'authenticated' && $GLOBALS['registry']->getAuth())) &&
247:             $GLOBALS['registry']->hasMethod('forums/deleteForum')) {
248: 
249:             try {
250:                 $result = $GLOBALS['registry']->forums->deleteForum('ansel', $image->id);
251:             } catch (Horde_Exception $e) {
252:                 Horde::logMessage($e, 'ERR');
253:                 return false;
254:             }
255:         }
256: 
257:         return true;
258:     }
259: 
260:     /**
261:      * Gets a slice of the images in this gallery.
262:      *
263:      * @param integer $from  The image to start fetching.
264:      * @param integer $count The numer of images to return.
265:      *
266:      * @param array An array of Ansel_Image objects
267:      */
268:     public function getImages($from = 0, $count = 0)
269:     {
270:         $images = $GLOBALS['injector']->getInstance('Ansel_Storage')
271:             ->getImages(array('gallery_id' => $this->_gallery->id,
272:                               'count' => $count,
273:                               'from' => $from));
274: 
275:         return array_values($images);
276:     }
277: 
278:     /**
279:      * Checks if the gallery has any subgallery
280:      *
281:      * @return boolean
282:      */
283:     public function hasSubGalleries()
284:     {
285:         return $this->_gallery->get('has_subgalleries') == 1;
286:     }
287: 
288:     /**
289:      * Returns the number of images in this gallery and, optionally, all
290:      * sub-galleries.
291:      *
292:      * @param boolean $subgalleries  Determines whether subgalleries should
293:      *                               be counted or not.
294:      *
295:      * @return integer number of images in this gallery
296:      */
297:     public function countImages($subgalleries = false)
298:     {
299:         if ($subgalleries && $this->hasSubGalleries()) {
300:             $count = $this->countImages(false);
301:             $galleries = $GLOBALS['injector']
302:                 ->getInstance('Ansel_Storage')
303:                 ->listGalleries(array('parent' => $this->_gallery->id));
304: 
305:             foreach ($galleries as $galleryId => $gallery) {
306:                 $count += $gallery->countImages();
307:             }
308: 
309:             return $count;
310:         }
311: 
312:         return $this->_gallery->get('images');
313:     }
314: }
315: 
API documentation generated by ApiGen