First round of function parameter cleanups.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 17 Jun 2010 16:58:19 +0000 (12:58 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 17 Jun 2010 16:58:19 +0000 (12:58 -0400)
This is a change to the API function signatures, so any app using the Ansel
API may require refactoring.

25 files changed:
ansel/lib/Ansel.php
ansel/lib/Api.php
ansel/lib/Block/gallery.php
ansel/lib/Block/my_galleries.php
ansel/lib/Block/recent_comments.php
ansel/lib/Block/recently_added.php
ansel/lib/Block/recently_added_geodata.php
ansel/lib/Gallery.php
ansel/lib/GalleryMode/Date.php
ansel/lib/GalleryMode/Normal.php
ansel/lib/ImageView.php
ansel/lib/Storage.php
ansel/lib/View/List.php
ansel/lib/Widget/OtherGalleries.php
ansel/perms.php
ansel/rss.php
ansel/scripts/recursive_import.php
ansel/scripts/remote_import.php
ansel/templates/gallery/gallery.inc
ansel/templates/group/category.inc
ansel/templates/group/owner.inc
ansel/templates/view/gallery.inc
ansel/templates/view/gallerylightbox.inc
ansel/templates/view/results.inc
ansel/templates/xppublish/list.inc

index db9684e..1b1aac0 100644 (file)
  */
 class Ansel
 {
+    /* Sort constants */
+    const SORT_ASCENDING = 0;
+    const SORT_DESCENDING = 1;
+
     /**
      * Build initial Ansel javascript object.
      *
@@ -58,48 +62,45 @@ class Ansel
      * Return a string containing an <option> listing of the given
      * gallery array.
      *
-     * @param array $selected     The gallery_id of the  gallery that is
-     *                            selected by default in the returned option
-     *                            list.
-     * @param integer $perm       The permissions filter to use.
-     * @param mixed $attributes   Restrict the galleries returned to those
-     *                            matching $attributes. An array of
-     *                            attribute/values pairs or a gallery owner
-     *                            username.
-     * @param string $parent      The parent share to start listing at.
-     * @param integer $from       The gallery to start listing at.
-     * @param integer $count      The number of galleries to return.
-     * @param integer $ignore     An Ansel_Gallery id to ignore when building
-     *                            the tree.
+     * @param array $params  An array of options:
+     *   <pre>
+     *     (integer)selected  The gallery_id of the gallery that is selected
+     *     (integer)perm      The permissions filter to use [Horde_Perms::SHOW]
+     *     (mixed)filter      Restrict the galleries returned to those matching
+     *                        the filters. Can be an array of attribute/values
+     *                        pairs or a gallery owner username.
+     *     (boolean)allLevels
+     *     (integer)parent    The parent share to start listing at.
+     *     (integer)from      The gallery to start listing at.
+     *     (integer)count     The number of galleries to return.
+     *     (integer)ignore    An Ansel_Gallery id to ignore when building the tree.
+     *   </pre>
      *
-     * @return string  The <option> list.
+     * @return string  The HTML to display the option list.
      */
-    static public function selectGalleries($selected = null, $perm = Horde_Perms::SHOW,
-                             $attributes = null, $parent = null,
-                             $allLevels = true, $from = 0, $count = 0,
-                             $ignore = null)
+    static public function selectGalleries($params = array())
     {
-        $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()
-                ->listGalleries($perm, $attributes, $parent, $allLevels, $from, $count);
+        $params = new Horde_Support_Array($params);
+        $galleries = $GLOBALS['injector']
+            ->getInstance('Ansel_Storage')
+            ->getScope()
+            ->listGalleries($params);
+
         $tree = Horde_Tree::factory('gallery_tree', 'Select');
 
-        if (!empty($ignore)) {
-           unset($galleries[$ignore]);
-           if ($selected == $ignore) {
-               $selected = null;
+        /* Remove the ignored gallery, make sure it's also not the selected gallery */
+        if ($params->ignore) {
+           if ($params->selected == $params->ignore) {
+               $params->selected = null;
            }
         }
+
         foreach ($galleries as $gallery_id => $gallery) {
             // We don't use $gallery->getParents() on purpose since we
             // only need the count of parents. This potentially saves a number
             // of DB queries.
             $parents = $gallery->get('parents');
-            if (empty($parents)) {
-                $indents = 0;
-            } else {
-                $indents = substr_count($parents, ':') + 1;
-            }
-
+            $indents = empty($parents) ? 0 : substr_count($parents, ':') + 1;
             $gallery_name = $gallery->get('name');
             $len = Horde_String::length($gallery_name);
             if ($len > 30) {
@@ -107,14 +108,14 @@ class Ansel
             } else {
                 $label = $gallery_name;
             }
-
-            $params['selected'] = ($gallery_id == $selected);
+            $treeparams = array();
+            $treeparams['selected'] = $gallery_id == $params->selected;
             $parent = $gallery->getParent();
-            $parent = (is_null($parent)) ? $parent : $parent->id;
-            if ((!empty($parent) && !empty($galleries[$parent])) ||
-                (empty($parent))) {
-                $tree->addNode($gallery->id, $parent, $label, $indents, true,
-                               $params);
+            $parent = (empty($params['parent'])) ? null : $params['parent']->id;
+            if ((!empty($params['parent']) && !empty($galleries[$params['parent']])) ||
+                (empty($params['parent']))) {
+                
+                $tree->addNode($gallery->id, $parent, $label, $indents, true, $treeparams);
             }
         }
 
@@ -151,7 +152,7 @@ class Ansel
         global $prefs;
 
         $rewrite = isset($GLOBALS['conf']['urls']['pretty']) &&
-            $GLOBALS['conf']['urls']['pretty'] == 'rewrite';
+                   $GLOBALS['conf']['urls']['pretty'] == 'rewrite';
 
         switch ($controller ) {
         case 'view':
index f84868a..6ec546e 100644 (file)
@@ -36,9 +36,10 @@ class Ansel_Api extends Horde_Registry_Api
         $path = trim($path, '/');
         $parts = explode('/', $path);
 
+        $storage = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope();
         if (empty($path)) {
             $owners = array();
-            $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, null, null, false);
+            $galleries = $storage->listGalleries(array('allLevels' => false));
             foreach ($galleries  as $gallery) {
                 $owners[$gallery->data['share_owner'] ? $gallery->data['share_owner'] : '-system-'] = true;
             }
@@ -72,7 +73,8 @@ class Ansel_Api extends Horde_Registry_Api
         } else {
             if (count($parts) == 1) {
                 // This request is for all galleries owned by the requested user.
-                $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, $parts[0], null, false);
+                $galleries = $storage->listGalleries(array('filter' => $parts[0],
+                                                           'allLevels' => false));
                 $images = array();
             } elseif ($this->galleryExists(null, end($parts))) {
                 // This request if for a certain gallery, list all sub-galleries
@@ -84,7 +86,8 @@ class Ansel_Api extends Horde_Registry_Api
 
                     throw new Horde_Exception_NotFound(_("Invalid gallery specified."));
                 }
-                $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, null, $gallery_id, false);
+                $galleries = $storage->listGalleries(array('parent' => $gallery_id,
+                                                           'allLevels' => false));
                 $images = $this->listImages(null, $gallery_id, Horde_Perms::SHOW, 'mini');
 
             } elseif (count($parts) > 2 &&
@@ -285,33 +288,35 @@ class Ansel_Api extends Horde_Registry_Api
     /**
      * Stores an image in a gallery and returns gallery and image data.
      *
-     * @param integer $app         Application used if null then use default.
      * @param integer $gallery_id  The gallery id to add the image to.
      * @param array $image         Image data array.  This can either be the return
      *                             from Horde_Form_Type_image:: or an array with
      *                             the following four fields:
      *                             'filename', 'description', 'data', 'type'
-     * @param integer $default     Set this image as default in the gallery?
-     * @param array $gallery_data  Any gallery parameters to change at this time.
-     * @param string $encoding     The encoding type for the image data.
-     *                             (none, base64, or binhex)
-     * @param string $slug         Use gallery slug instead of id. (Pass '0' or null
-     *                             to gallery_id parameter).
-     * @param string $compression  The compression type for the image data.
-     *                             (none, gzip, or lzf)
      *
-     * @return mixed  An array of image/gallery data || PEAR_Error
+     * @param array $params  An array of additional parameters:
+     * <pre>
+     *   (string)slug         If set, use this as the gallery slug (ignores $gallery_id)
+     *   (string)scope        The scope to use, if not the default.
+     *   (boolean)default     Set this as the key gallery image.
+     *   (array)gallery_data  Any gallery parameters to change at this time.
+     *   (string)encoding     The encoding type for the image data (base64 or binhex)
+     *   (string)compression  The compression type for image data (gzip,lzf)
+     *   (boolean)skiphook    Don't call the postupload hook(s).
+     * </pre>
+     *
+     * @return array  An array of image/gallery data
+     * @throws InvalidArgumentException
+     * @throws Horde_Exception_PermissionDenied
      */
-    public function saveImage($app = null, $gallery_id, $image, $default = false,
-                              $gallery_data = null, $encoding = null, $slug = null,
-                              $compression = 'none', $skiphook = false)
+    public function saveImage($gallery_id, $image, $params = array())
     {
         /* Set application scope */
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set($app);
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set($params['scope']);
         }
-        $image_data = null;
-       
+
+        /* Build image upload structure */
         if (isset($image['filename']) &&
             isset($image['description']) &&
             isset($image['data']) &&
@@ -320,31 +325,36 @@ class Ansel_Api extends Horde_Registry_Api
                 $image_data = array('image_filename' => $image['filename'],
                                     'image_caption' => $image['description'],
                                     'image_type' => $image['type'],
-                                    'data' => $this->_getImageData($image['data'], $encoding, $compression, true));
+                                    'data' => $this->_getImageData($image['data'], (empty($params['encoding']) ? 'none' : $params['encoding']), (empty($params['compression']) ? 'none' : $params['compression']), true));
         }
 
-        if (is_null($image_data) && getimagesize($image['file']) === false) {
+        /* Validate the image data and other requirements */
+        if (empty($image_data) && getimagesize($image['file']) === false) {
             throw new InvalidArgumentException(_("The file you uploaded does not appear to be a valid photo."));
         }
-        if (empty($slug) && empty($gallery_id)) {
+        if (empty($params['slug']) && empty($gallery_id)) {
             throw new InvalidArgumentException(_("A gallery to add this photo to is required."));
         }
-        if (!empty($slug)) {
-            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGalleryBySlug($slug);
+        if (!empty($params['slug'])) {
+            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGalleryBySlug($params['slug']);
         } elseif ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->galleryExists($gallery_id)) {
             $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_id);
         }
+
+        /* Check perms for requested gallery */
         if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
             throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied adding photos to \"%s\"."), $gallery->get('name')));
         }
-        if (!empty($gallery_data)) {
-            foreach ($gallery_data as $key => $value) {
+
+        /* Changing any values while we are at it? */
+        if (!empty($params['gallery_data'])) {
+            foreach ($params['gallery_data'] as $key => $value) {
                 $gallery->set($key, $value);
             }
             $gallery->save();
         }
 
-        if (is_null($image_data)) {
+        if (empty($image_data)) {
             $image_data = array(
                 'image_filename' => $image['name'],
                 'image_caption' => $image['name'],
@@ -356,10 +366,10 @@ class Ansel_Api extends Horde_Registry_Api
         if (isset($image['tags']) && is_array($image['tags']) && count($image['tags'])) {
             $image_data['tags'] = $image['tags'];
         }
-        $image_id = $gallery->addImage($image_data, $default);
+        $image_id = $gallery->addImage($image_data, !empty($params['default']));
 
-        // Call the postupload hook if needed
-        if (!empty($GLOBALS['conf']['hooks']['postupload']) && !$skiphook) {
+        /* Call the postupload hook if needed */
+        if (!empty($GLOBALS['conf']['hooks']['postupload']) && empty($params['skiphook'])) {
             try {
                 Horde::callHook('postupload', array($image_id));
             } catch (Horde_Exception_HookNotSet $e) {}
@@ -388,19 +398,26 @@ class Ansel_Api extends Horde_Registry_Api
     /**
      * Removes an image from a gallery.
      *
-     * @param string $app         Application scope to use, if not the default.
      * @param integer $gallery_id The id of gallery.
      * @param string $image_id    The id of image to remove.
+     * @param array $params       Additional parameters:
+     * <pre>
+     *   (string)scope  The scope to use, if not the default.
+     * </pre>
+     *
+     * @return boolean
+     * @throws Horde_Exception_PermissionDenied
      */
-    public function removeImage($app = null, $gallery_id, $image_id)
+    public function removeImage($gallery_id, $image_id, $params = array())
     {
         /* Check global Ansel permissions */
         if (!$GLOBALS['injector']->getInstance('Horde_Perms')->getPermissions('ansel')) {
             throw new Horde_Exception_PermissionDenied(_("Access denied deleting galleries."));
         }
 
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
+        /* Set a custom scope, if needed */
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
         }
 
         $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getImage($image_id);
@@ -408,24 +425,28 @@ class Ansel_Api extends Horde_Registry_Api
         if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
             throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied deleting photos from \"%s\"."), $gallery->get('name')));
         }
+
         return $gallery->removeImage($image);
     }
 
     /**
-     * Add a new gallery to any arbitrary application's Ansel_Shares.
+     * Add a new gallery to any application scope.
      *
-     * @param string $app            Application scope to use, if not the default.
-     * @param array $attributes      The gallery attributes
-     *                               (@see Ansel_Storage::createGallery).
-     * @param array $perm            An array of permission data if Ansel's defaults
-     *                               are not desired. Takes an array like:
-     *                               array('guest' => Horde_Perms::SHOW | Horde_Perms::READ,
-     *                                     'default' => Horde_Perms::SHOW | Horde_Perms::READ);
-     * @param integer $parent        The gallery id of the parent gallery, if any.
-     *
-     * @return mixed  The gallery id of the new gallery | PEAR_Error
+     * @param array $attributes  The gallery attributes
+     * @param array $params      Additional (optional) parameters:
+     *  <pre>
+     *    (string)scope    The scope to use, if not the default.
+     *    (array)perm      An array of permission data if Ansel's defaults are
+     *                     not desired. Takes an array like:
+                               array('guest' => Horde_Perms::SHOW | Horde_Perms::READ,
+                                     'default' => Horde_Perms::SHOW | Horde_Perms::READ);
+     *    (integer)parent  The gallery id of the parent gallery, if not a top level gallery.
+     *
+     *
+     * @return integer  The gallery id of the new gallery
+     * @throws Horde_Exception_PermissionDenied
      */
-    public function createGallery($app = null, $attributes = array(), $perm = null, $parent = null)
+    public function createGallery($attributes, $params = array())
     {
         if (!($GLOBALS['registry']->isAdmin() ||
             (!$GLOBALS['injector']->getInstance('Horde_Perms')->exists('ansel') && $GLOBALS['registry']->getAuth()) ||
@@ -434,11 +455,13 @@ class Ansel_Api extends Horde_Registry_Api
             throw new Horde_Exception_PermissionDenied(_("Access denied creating new galleries."));
         }
 
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
+        /* Custom scope? */
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
         }
 
-        if (!empty($perm)) {
+        /* Non-default perms? */
+        if (!empty($params['perm'])) {
             // The name is inconsequential; it is only used as a container to
             // represent permissions when passed to the Ansel backend.
             $permobj = new Horde_Perms_Permission('');
@@ -447,6 +470,7 @@ class Ansel_Api extends Horde_Registry_Api
             $permobj = null;
         }
 
+        /* Create the gallery */
         $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->createGallery($attributes, $permobj, $parent);
 
         return $gallery->id;
@@ -455,33 +479,32 @@ class Ansel_Api extends Horde_Registry_Api
     /**
      * Removes a gallery and its images.
      *
-     * @param string $app          Application scope to use, if not the default.
      * @param integer $gallery_id  The id of gallery.
+     * @param array $params        Any additional, optional, parameters:
+     *  <pre>
+     *    (string)scope  the scope to use, if not the default
+     *  </pre>
      *
-     * @return mixed boolean true | PEAR_Error
+     * @return boolean true
+     * @throws Horde_Exception_PermissionDenied
      */
-    public function removeGallery($app = null, $gallery_id)
+    public function removeGallery($gallery_id, $params = array())
     {
         /* Check global Ansel permissions */
         if (!$GLOBALS['injector']->getInstance('Horde_Perms')->getPermissions('ansel')) {
             throw new Horde_Exception_PermissionDenied(_("Access denied deleting galleries."));
         }
 
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
+        /* Custom scope, if needed */
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
         }
 
+        /* Get, and check perms on the gallery */
         $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_id);
         if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
             throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied deleting gallery \"%s\"."), $gallery->get('name')));
         } else {
-            $imageList = $gallery->listImages();
-            if ($imageList) {
-                foreach ($imageList as $id) {
-                    $gallery->removeImage($id);
-                }
-            }
-
             return $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->removeGallery($gallery);
         }
     }
@@ -489,20 +512,24 @@ class Ansel_Api extends Horde_Registry_Api
     /**
      * Returns the number of images in a gallery.
      *
-     * @param integer $app          Application used; if null then use default.
      * @param integer $gallery_id   The gallery id.
-     * @param string  $slug         The gallery slug.
+     * @param array $params         Array of optional parameters:
+     *  <pre>
+     *    (string)scope  Scope to use, if not the default.
+     *    (string)slug   If set, ignore gallery_id and use this as the slug.
+     *  </pre>
      *
      * @return integer  The number of images in the gallery.
      */
-    public function count($app = null, $gallery_id = null, $slug = '')
+    public function count($gallery_id = null, $params = array())
     {
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
         }
+
         try {
-            if (!empty($slug)) {
-                $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGalleryBySlug($slug);
+            if (!empty($params['slug'])) {
+                $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGalleryBySlug($params['slug']);
             } else {
                 $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_id);
             }
@@ -513,71 +540,81 @@ class Ansel_Api extends Horde_Registry_Api
     }
 
     /**
-     * Returns the default image id of a gallery.
+     * Returns the id of the specified gallery's key image.
      *
-     * @param string $app            Application scope to use, if not the default.
-     * @param integer $gallery_id    The gallery id.
-     * @param string $style          The named style.
-     * @param string $slug           The gallery slug.
+     * @param integer $gallery_id  The gallery id.
+     * @param array $params        Additional parameters:
+     *   <pre>
+     *     (string)scope   Application scope, if not the default
+     *     (string)style   A named style to use, if not ansel_default
+     *     (string)slug    Ignore gallery_id, and use this as the slug
+     *   </pre>
      *
      * @return integer  The default image id.
      */
-    public function getDefaultImage($app = null, $gallery_id = null,
-        $style = 'ansel_default', $slug = '')
+    public function getGalleryKeyImage($gallery_id, $params = array())
     {
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
         }
 
-        if (!empty($slug)) {
-            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGalleryBySlug($slug);
+        if (!empty($params['slug'])) {
+            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGalleryBySlug($params['slug']);
         } else {
             $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_id);
         }
 
-        return $gallery->getDefaultImage($style);
+        return $gallery->getDefaultImage(empty($params['style']) ? 'ansel_default' : $params['style']);
     }
 
     /**
-     * Returns image URL.
+     * Returns the URL to the specified image.
      *
-     * @param integer $app       Application used.
      * @param integer $image_id  The id of the image.
-     * @param string $view       The view ('screen', 'thumb', 'full', etc) to show.
-     * @param boolean $full      Return a path that includes the server name?
-     * @param string $style      Use this gallery style
+     * @param array $params      Additional optional parameters:
+     *  <pre>
+     *    (string)scope  The application scope, if not the default.
+     *    (string)view   The image view type to return (screen, thumb, etc...)
+     *    (string)full   Return a fully qualified path?
+     *    (string)style  Use this gallery style instead of ansel_default.
+     *  </pre>
      *
      * @return string  The image path.
      */
-    public function getImageUrl($app = null, $image_id, $view = 'screen', $full = false, $style = null)
+    public function getImageUrl($image_id, $params = array())
     {
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
         }
 
-        return (string)Ansel::getImageUrl($image_id, $view, $full, $style);
+        return (string)Ansel::getImageUrl($image_id,
+                                          empty($params['view']) ? 'screen': $params['view'],
+                                          empty($params['full']) ? : $params['full'],
+                                          empty($params['style']) ? 'ansel_default' : $params['style']);
     }
 
     /**
-     * Returns image file content.
+     * Returns raw image data in specified encoding/compression format.
+     *
+     * @TODO: See about using a stream
      *
      * @param integer $image_id  The id of the image.
-     * @param string $view       The view ('screen', 'thumb', 'full', etc) to show.
-     * @param string $style      Force use of this gallery style.
-     * @param integer $app       Application used.
-     * @param string $encoding     The encoding type for the image data.
-     *                             (none, base64, or binhex)
-     * @param string $compression  The compression type for the image data.
-     *                             (none, gzip, or lzf)
+     * @param array $params      Optional parameters:
+     *   <pre>
+     *    (string)scope        Application scope, if not default.
+     *    (string)view         The image view type to return (screen, thumb etc...)
+     *    (string)style        Force the use of this gallery style
+     *    (string)encoding     Encoding type (base64, binhex)
+     *    (string)compression  Compression type (gzip, lzf)
+     *   </pre>
      *
-     * @return string  The image path.
+     * @return string  The raw image data.
+     * @throws Horde_Exception_Permission_Denied
      */
-    public function getImageContent($image_id, $view = 'screen', $style = null,
-                                    $app = null, $encoding = null,
-                                    $compression = 'none')
+    public function getImageContent($image_id, $params = array())
     {
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
         }
 
         /* Get image and gallery */
@@ -586,14 +623,16 @@ class Ansel_Api extends Horde_Registry_Api
 
         /* Check age and password */
         if (!$gallery->hasPasswd() || !$gallery->isOldEnough()) {
-            throw new Horde_Exception(_("Locked galleries are not viewable via the api."));
+            throw new Horde_Exception_PermissionDenied(_("Locked galleries are not viewable via the api."));
         }
 
         if ($view == 'full') {
             /* Check permissions for full view */
             if (!$gallery->canDownload()) {
-                throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied downloading photos from \"%s\"."), $gallery->get('name')));
+                throw new Horde_Exception_PermissionDenied(sprintf(_("Access denied downloading full sized photos from \"%s\"."), $gallery->get('name')));
             }
+
+            /* Try reading the data */
             try {
                 $data = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images')->read($image->getVFSPath('full'), $image->getVFSName('full'));
             } catch (VFS_Exception $e) {
@@ -611,36 +650,39 @@ class Ansel_Api extends Horde_Registry_Api
     /**
      * Returns a list of all galleries.
      *
-     * @param string $app         Application scope to use, if not the default.
-     * @param integer $perm       The level of permissions to require for a gallery
-     *                            to be returned.
-     * @param integer $parent     The parent gallery id to start searching from.
-     *                            This should be either a gallery id or null.
-     * @param boolean $allLevels  Return all levels, or just the direct children of
-     *                            $parent?
-     * @param integer $from       The gallery to start listing at.
-     * @param integer $count      The number of galleries to return.
-     * @param array $attributes   Restrict the returned galleries to those matching
-     *                            $attributes. An array of attribute names => values
+    * @param array $params  Optional parameters:
+    *   <pre>
+     *    (string)scope      The application scope, if not default.
+    *     (integer)perm      The permissions filter to use [Horde_Perms::SHOW]
+    *     (mixed)filter      Restrict the galleries returned to those matching
+    *                        the filters. Can be an array of attribute/values
+    *                        pairs or a gallery owner username.
+    *     (integer)parent    The parent share to start listing at.
+    *     (boolean)allLevels If set, return all levels below parent, not just
+    *                        direct children [TRUE]
+    *     (integer)from      The gallery to start listing at.
+    *     (integer)count     The number of galleries to return.
+    *     (string)sort_by    Attribute to sort by
+    *     (integer)direction The direction to sort by [Ansel::SORT_ASCENDING]
+    *   </pre>
      *
      * @return array  An array of gallery information.
      */
-    public function listGalleries($app = null, $perm = Horde_Perms::SHOW,
-                                  $parent = null, $allLevels = true, $from = 0,
-                                  $count = 0, $attributes = null, $sort_by = null,
-                                  $direction = 0)
+    public function listGalleries($params = array())
     {
         /* If no app is given use Ansel's own gallery which is initialized in
         base.php */
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $params['scope']);
         }
-        $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(
-            $perm, $attributes, $parent, $allLevels, $from, $count, $sort_by, $direction);
-
+        $galleries = $GLOBALS['injector']
+            ->getInstance('Ansel_Storage')
+            ->getScope()
+            ->listGalleries($params);
         $return = array();
         foreach ($galleries as $gallery) {
-            $return[$gallery->id] = array_merge($gallery->data, array('crumbs' => $gallery->getGalleryCrumbData()));
+            $return[$gallery->id] = array_merge($gallery->data,
+                                                array('crumbs' => $gallery->getGalleryCrumbData()));
         }
 
         return $return;
@@ -683,26 +725,28 @@ class Ansel_Api extends Horde_Registry_Api
      * Returns a 'select' menu from the list of galleries created by
      * listGalleries().
      *
-     * @param integer $app        Application used if null then use default.
-     * @param integer $perm       The permissions filter to use.
-     * @param string $parent      The parent share to start listing at.
-     * @param boolean $allLevels  Return all levels, or just the direct
-     * @param integer $from       The gallery to start listing at.
-     * @param integer $count      The number of galleries to return.
-     * @param boolean $default    The gallery_id of the  gallery that is
-     *                            selected by default in the returned option
-     *                            list.
+     * @param array $params  Optional parameters:
+     *   <pre>
+     *     (string)scope      Application scope, if not default.
+     *     (integer)selected  The gallery_id of the gallery that is selected
+     *     (integer)perm      The permissions filter to use [Horde_Perms::SHOW]
+     *     (mixed)filter      Restrict the galleries returned to those matching
+     *                        the filters. Can be an array of attribute/values
+     *                        pairs or a gallery owner username.
+     *     (integer)parent    The parent share to start listing at.
+     *     (integer)from      The gallery to start listing at.
+     *     (integer)count     The number of galleries to return.
+     *     (integer)ignore    An Ansel_Gallery id to ignore when building the tree.
+     *   </pre>
      */
-    public function selectGalleries($app = null, $perm = Horde_Perms::SHOW,
-        $parent = null,
-        $allLevels = true, $from = 0, $count = 0,
-        $default = null)
+    public function selectGalleries($params = array())
     {
-        if (!is_null($app)) {
-            $GLOBALS['injector']->getInstance('Ansel_Config')->set($app);
+        if (!empty($params['scope'])) {
+            $GLOBALS['injector']->getInstance('Ansel_Config')->set($params['scope']);
+            unset($params['scope']);
         }
 
-        return Ansel::selectGalleries($default, $perm, null, $parent, $allLevels, $from, $count);
+        return Ansel::selectGalleries($params);
     }
 
     /**
@@ -732,11 +776,11 @@ class Ansel_Api extends Horde_Registry_Api
         if (!is_null($app)) {
             $GLOBALS['injector']->getInstance('Ansel_Config')->set('scope', $app);
         }
-
+        $storage = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope();
         /* Determine the default gallery when none is given. The first gallery in
         the list is the default gallery. */
         if (is_null($gallery_id) && empty($slug)) {
-            $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries($perm);
+            $galleries = $storage->listGalleries(array('perm' => $perm));
             if (!count($galleries)) {
                 return array();
             }
@@ -744,9 +788,9 @@ class Ansel_Api extends Horde_Registry_Api
             $gallery_names = array_keys($galleries[$keys[0]]['galleries']);
             $gallery_id = $gallery_names[0];
         } elseif (!empty($slug)) {
-            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGalleryBySlug($slug);
+            $gallery = $storage->getGalleryBySlug($slug);
         } else {
-            $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getGallery($gallery_id);
+            $gallery = $storage->getGallery($gallery_id);
         }
 
         $images = $gallery->listImages();
@@ -754,7 +798,7 @@ class Ansel_Api extends Horde_Registry_Api
         $counter = 0;
         $imagelist = array();
         foreach ($images as $id) {
-            $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getImage($id);
+            $image = $storage->getImage($id);
             $imagelist[$id]['name'] = $image->filename;
             $imagelist[$id]['caption'] = $image->caption;
             $imagelist[$id]['type'] = $image->type;
index 411b4d8..37b5524 100644 (file)
@@ -15,8 +15,8 @@ $block_name = _("Gallery");
  * @author  Marcus Ryan <marcus@horde.org>
  * @package Horde_Block
  */
-class Horde_Block_ansel_gallery extends Horde_Block {
-
+class Horde_Block_ansel_gallery extends Horde_Block
+{
     var $_app = 'ansel';
     var $_gallery = null;
 
@@ -35,9 +35,9 @@ class Horde_Block_ansel_gallery extends Horde_Block {
                             'name' => _("Use a lightbox to view photos"),
                             'type' => 'checkbox',
                             'default' => true));
-
-        if ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::READ) < $GLOBALS['conf']['gallery']['listlimit']) {
-            foreach ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries() as $gal) {
+        $storage = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope();
+        if ($storage->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::READ) < $GLOBALS['conf']['gallery']['listlimit']) {
+            foreach ($storage->listGalleries() as $gal) {
                 $params['gallery']['values'][$gal->id] = $gal->get('name');
             }
         }
index a906c9d..cda1ea6 100644 (file)
@@ -40,10 +40,13 @@ class Horde_Block_ansel_my_galleries extends Horde_Block {
         Horde::addScriptFile('tooltips.js', 'horde');
         /* Get the top level galleries */
         try {
-            $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(
-                Horde_Perms::EDIT, $GLOBALS['registry']->getAuth(), null, false, 0,
-                empty($this->_params['limit']) ? 0 : $this->_params['limit'],
-                'last_modified', 1);
+            $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')
+                ->getScope()->listGalleries(array('perm' => Horde_Perms::EDIT,
+                                                  'filter' => $GLOBALS['registry']->getAuth(),
+                                                  'allLevels' => false,
+                                                  'count' => empty($this->_params['limit']) ? 0 : $this->_params['limit'],
+                                                  'sort_by' => 'last_modified',
+                                                  'direction' => Ansel::SORT_DESCENDING));
 
         } catch (Ansel_Exception $e) {
             return $e->getMessage();
index d09a901..7daf8c7 100644 (file)
@@ -16,7 +16,8 @@ if ($GLOBALS['registry']->call('images/hasComments') &&
  * @author  Michael Rubinsky <mrubinsk@horde.org>
  * @package Horde_Block
  */
-class Horde_Block_ansel_recent_comments extends Horde_Block {
+class Horde_Block_ansel_recent_comments extends Horde_Block
+{
 
     var $_app = 'ansel';
     var $_gallery = null;
@@ -24,13 +25,13 @@ class Horde_Block_ansel_recent_comments extends Horde_Block {
     function _params()
     {
         $params = array('gallery' => array(
-                            'name' => _("Gallery"),
-                            'type' => 'enum',
-                            'default' => '__random',
-                            'values' => array('all' => 'All')));
-
-        if ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::READ) < $GLOBALS['conf']['gallery']['listlimit']) {
-            foreach ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::READ) as $id => $gal) {
+                        'name' => _("Gallery"),
+                        'type' => 'enum',
+                        'default' => '__random',
+                        'values' => array('all' => 'All')));
+        $storage = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope();
+        if ($storage->getScope()->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::READ) < $GLOBALS['conf']['gallery']['listlimit']) {
+            foreach ($storage->listGalleries(array('perm' => Horde_Perms::READ)) as $id => $gal) {
                 $params['gallery']['values'][$id] = $gal->get('name');
             }
         }
index e8e4fea..db3511c 100644 (file)
@@ -13,8 +13,8 @@ $block_name = _("Recently Added Photos");
  * @author  Michael Rubinsky <mrubinsk@horde.org>
  * @package Horde_Block
  */
-class Horde_Block_ansel_recently_added extends Horde_Block {
-
+class Horde_Block_ansel_recently_added extends Horde_Block
+{
     var $_app = 'ansel';
     var $_gallery = null;
 
@@ -32,7 +32,7 @@ class Horde_Block_ansel_recently_added extends Horde_Block {
         );
 
         if ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::READ) < $GLOBALS['conf']['gallery']['listlimit']) {
-            foreach ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::READ) as $id => $gal) {
+            foreach ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(array('perm' => Horde_Perms::READ)) as $id => $gal) {
                 if (!$gal->hasPasswd() && $gal->isOldEnough()) {
                     $params['gallery']['values'][$id] = $gal->get('name');
                 }
index 27a70e1..417a6c1 100644 (file)
@@ -36,7 +36,7 @@ class Horde_Block_ansel_recently_added_geodata extends Horde_Block {
         );
 
         if ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::READ) < $GLOBALS['conf']['gallery']['listlimit']) {
-            foreach ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::READ) as $id => $gal) {
+            foreach ($GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(array('perm' => Horde_Perms::READ)) as $id => $gal) {
                 if (!$gal->hasPasswd() && $gal->isOldEnough()) {
                     $params['gallery']['values'][$id] = $gal->get('name');
                 }
index f74bde1..a8e8f7d 100644 (file)
@@ -695,7 +695,10 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical
             if ($this->hasSubGalleries()) {
                 // Fall through to a default image of a sub gallery.
                 try {
-                    $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, null, $this, false);
+                    $galleries = $GLOBALS['injector']
+                        ->getInstance('Ansel_Storage')
+                        ->getScope()
+                        ->listGalleries(array('parent' => $this, 'allLevels' => false));
                 } catch (Horde_Exception $e) {
                     return false;
                 }
index 33b76ae..56bd32b 100644 (file)
@@ -156,7 +156,10 @@ class Ansel_GalleryMode_Date
     {
         if (!is_array($this->_subGalleries)) {
             /* Get a list of all the subgalleries */
-            $subs = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, null, $this->_gallery);
+            $subs = $GLOBALS['injector']
+                ->getInstance('Ansel_Storage')
+                ->getScope()
+                ->listGalleries(array('parent' => $this->_gallery));
             $this->_subGalleries = array_keys($subs);
         }
     }
index cfac65a..508a9e4 100644 (file)
@@ -49,29 +49,30 @@ class Ansel_GalleryMode_Normal {
     /**
      * 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 integer $perm   The permissions to limit to.
+     * @param integer $from   The child to start at.
+     * @param integer $count  The number of children to return.
      *
-     * @return A mixed array of Ansel_Gallery and Ansel_Image objects that are
-     *         children of this gallery.
+     * @return array  A mixed array of Ansel_Gallery and Ansel_Image objects
+     *                that are children of this gallery.
      */
     function getGalleryChildren($perm = Horde_Perms::SHOW, $from = 0, $to = 0)
     {
         $galleries = array();
         $num_galleries = 0;
-
         if ($this->hasSubGalleries()) {
-
+            $storage = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope();
             /* Get the number of images and galleries */
             $numimages = $this->countImages();
-            $num_galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->countGalleries(
-                $GLOBALS['registry']->getAuth(), Horde_Perms::SHOW, null, $this->_gallery, false);
+            $num_galleries = $storage->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW, null, $this->_gallery, false);
 
             /* Now fetch the subgalleries, but only if we need to */
             if ($num_galleries > $from) {
-                $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(
-                    Horde_Perms::SHOW, null, $this->_gallery, false, $from, $to);
+                $galleries = $storage->listGalleries(
+                        array('parent' => $this->_gallery,
+                              'allLevels' => false,
+                              'from' => $from,
+                              'count' => $to));
             }
         }
 
@@ -325,10 +326,10 @@ class Ansel_GalleryMode_Normal {
     {
         if ($subgalleries && $this->hasSubGalleries()) {
             $count = $this->countImages(false);
-            $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW,
-                                                                  false,
-                                                                  $this->_gallery,
-                                                                  true);
+            $galleries = $GLOBALS['injector']
+                ->getInstance('Ansel_Storage')
+                ->getScope()
+                ->listGalleries(array('parent' => $this->_gallery));
 
             foreach ($galleries as $galleryId => $gallery) {
                 $count += $gallery->countImages();
index ec89ab1..5f09eea 100644 (file)
@@ -127,8 +127,10 @@ class Ansel_ImageView
      */
     protected function _getGalleryWithImages($parent)
     {
-        $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(
-            Horde_Perms::SHOW, null, $parent, false);
+        $galleries = $GLOBALS['injector']
+            ->getInstance('Ansel_Storage')
+            ->getScope()
+            ->listGalleries(array('parent' => $parent, 'allLevels' => false));
 
         foreach ($galleries as $gallery) {
             if ($gallery->countImages()) {
index 2fcc451..34f68cf 100644 (file)
@@ -884,40 +884,37 @@ class Ansel_Storage
    /**
     * Retrieves the current user's gallery list from storage.
     *
-    * @param integer $perm         The level of permissions to require for a
-    *                              gallery to return it.
-    * @param mixed   $attributes   Restrict the galleries counted to those
-    *                              matching $attributes. An array of
-    *                              attribute/values pairs or a gallery owner
-    *                              username.
-    * @param mixed   $parent       The parent gallery to start listing at.
-    *                              (Ansel_Gallery, gallery id or null)
-    * @param boolean $allLevels    Return all levels, or just the direct
-    *                              children of $parent?
-    * @param integer $from         The gallery to start listing at.
-    * @param integer $count        The number of galleries to return.
-    * @param string  $sort_by      The field to order the results by.
-    * @param integer $direction    Sort direction:
-    *                               0 - ascending
-    *                               1 - descending
+    * @param array $params  Optional parameters:
+    *   <pre>
+    *     (integer)perm      The permissions filter to use [Horde_Perms::SHOW]
+    *     (mixed)filter      Restrict the galleries returned to those matching
+    *                        the filters. Can be an array of attribute/values
+    *                        pairs or a gallery owner username.
+    *     (integer)parent    The parent share to start listing at.
+    *     (boolean)allLevels If set, return all levels below parent, not just
+    *                        direct children [TRUE]
+    *     (integer)from      The gallery to start listing at.
+    *     (integer)count     The number of galleries to return.
+    *     (string)sort_by    Attribute to sort by
+    *     (integer)direction The direction to sort by [Ansel::SORT_ASCENDING]
+    *   </pre>
     *
-    * @return array of Ansel_Gallery objects
+    * @return array An array of Ansel_Gallery objects
     * @throws Ansel_Exception
     */
-    public function listGalleries($perm = Horde_Perms::SHOW,
-                           $attributes = null,
-                           $parent = null,
-                           $allLevels = true,
-                           $from = 0,
-                           $count = 0,
-                           $sort_by = null,
-                           $direction = 0)
+    public function listGalleries($params = array())
     {
         try {
-            $shares = $this->_shares->listShares($GLOBALS['registry']->getAuth(), $perm, $attributes,
-                                                 $from, $count, $sort_by, $direction,
-                                                 $parent, $allLevels);
-
+            $shares = $this->_shares->listShares(
+                $GLOBALS['registry']->getAuth(),
+                (empty($params['perm']) ? Horde_Perms::SHOW : $params['perm']),
+                (empty($params['filter']) ? null : $params['filter']),
+                (empty($params['from']) ? 0 : $params['from']),
+                (empty($params['count']) ? 0 : $params['count']),
+                (empty($params['sort_by']) ? null : $params['sort_by']),
+                (empty($params['direction']) ? Ansel::SORT_ASCENDING : $params['direction']),
+                (empty($params['parent']) ? null : $params['parent']),
+                (!array_key_exists('allLevels', $params) ? true : $params['allLevels']));
         } catch (Horde_Share_Exception $e) {
             throw new Ansel_Exception($e);
         }
@@ -1004,21 +1001,20 @@ class Ansel_Storage
      *
      * @see Ansel_Storage::listGalleries()
      */
-    public function getRandomGallery($perm = Horde_Perms::SHOW, $attributes = null,
-                              $parent = null, $allLevels = true)
+    public function getRandomGallery($params = array())
     {
-        $num_galleries = $this->countGalleries($GLOBALS['registry']->getAuth(), $perm,
-                                               $attributes, $parent,
-                                               $allLevels);
+        $params = new Horde_Support_Array($params);
+        $num_galleries = $this->countGalleries($GLOBALS['registry']->getAuth(),
+                                               $params->perm,
+                                               $params->filter,
+                                               $params->parent,
+                                               $params->allLevels);
         if (!$num_galleries) {
             return $num_galleries;
         }
-
-        $galleries = $this->listGalleries($perm, $attributes, $parent,
-                                          $allLevels,
-                                          rand(0, $num_galleries - 1),
-                                          1);
+        $galleries = $this->listGalleries($params);
         $gallery = array_pop($galleries);
+
         return $gallery;
     }
 
@@ -1123,16 +1119,17 @@ class Ansel_Storage
      * images from the current user. Useful for providing images to help locate
      * images at the same place.
      *
-     * @param string $user  Limit images to this user
+     * @param string $user    Limit images to this user
      * @param integer $start  Start a slice at this image number
-     * @param integer @count  Include this many images
+     * @param integer $count  Include this many images
      *
      * @return array An array of image ids
      *
      */
     public function getRecentImagesGeodata($user = null, $start = 0, $count = 8)
     {
-        $galleries = $this->listGalleries(Horde_Perms::EDIT, $user);
+        $galleries = $this->listGalleries(array('perm' => Horde_Perms::EDIT,
+                                                'filter' => $user));
         if (empty($galleries)) {
             return array();
         }
index bc0d4df..1faad19 100644 (file)
@@ -136,10 +136,14 @@ class Ansel_View_List extends Ansel_View_Base
                 $this->_galleryList = array();
             } else {
                 $this->_galleryList = $ansel_storage->listGalleries(
-                    Horde_Perms::SHOW, $filter, null, false, $this->_page * $this->_g_perPage,
-                    $this->_g_perPage, $this->_sortBy, $this->_sortDir);
+                    array('perm' => Horde_Perms::SHOW,
+                          'filter' => $filter,
+                          'allLevels' => false,
+                          'from' => $this->_page * $this->_g_perPage,
+                          'count' => $this->_g_perPage,
+                          'sort_by' => $this->_sortBy,
+                          'direction' => $this->_sortDir));
             }
-
         }
     }
 
index 2305df4..73a6a8a 100644 (file)
@@ -37,15 +37,20 @@ class Ansel_Widget_OtherGalleries extends Ansel_Widget_Base
      */
     public function html()
     {
-        if ($GLOBALS['conf']['ansel_cache']['usecache'] &&
-            ($widget = $GLOBALS['injector']->getInstance('Horde_Cache')->get('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'))) !== false) {
-            return $widget;
-        }
+          // The cache breaks this block for some reason, disable until figured
+          // out.
+//        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
+//            $widget = $GLOBALS['injector']->getInstance('Horde_Cache')->get('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'));
+//            if ($widget !== false) {
+//                //var_dump($widget);
+//                return $widget;
+//            }
+//        }
 
         $widget = $this->_htmlBegin() . $this->_getOtherGalleries() . $this->_htmlEnd();
-        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
-            $GLOBALS['injector']->getInstance('Horde_Cache')->set('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'), $widget);
-        }
+//        if ($GLOBALS['conf']['ansel_cache']['usecache']) {
+//            $GLOBALS['injector']->getInstance('Horde_Cache')->set('Ansel_OtherGalleries' . $this->_view->gallery->get('owner'), $widget);
+//        }
 
         return $widget;
     }
@@ -64,11 +69,11 @@ class Ansel_Widget_OtherGalleries extends Ansel_Widget_Base
         $tree->setOption(array('class' => 'anselWidgets'));
 
         try {
-            $gals = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, $owner,
-                                                             null, true, 0, 0,
-                                                            'name', 0);
+            $gals = $GLOBALS['injector']->getInstance('Ansel_Storage')
+                    ->getScope()
+                    ->listGalleries(array('filter' => $owner));
         } catch (Ansel_Exception $e) {
-            Horde::logMessage($gal, 'ERR');
+            Horde::logMessage($e, 'ERR');
             return '';
         }
 
index 22aca8d..af4442a 100644 (file)
@@ -250,7 +250,11 @@ case 'editforminherit':
 if (empty($share)) {
     $title = _("Edit Permissions");
 } else {
-    $children = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::READ, false, $share);
+    $children = $GLOBALS['injector']
+        ->getInstance('Ansel_Storage')
+        ->getScope()
+        ->listGalleries(array('perm' => Horde_Perms::READ,
+                              'parent' => $share));
     $title = sprintf(_("Edit Permissions for %s"), $share->get('name'));
 }
 
index 3325681..726f359 100644 (file)
@@ -81,9 +81,10 @@ if (empty($rss)) {
             !$gallery->hasPasswd() && $gallery->isOldEnough()) {
 
             if (!$gallery->countImages() && $gallery->hasSubGalleries()) {
-                $subgalleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW,
-                                                              null,
-                                                              $gallery);
+                $subgalleries = $GLOBALS['injector']
+                    ->getInstance('Ansel_Storage')
+                    ->getScope()
+                    ->listGalleries(array('parent' => $gallery));
                 $subs = array();
                 foreach ($subgalleries as $subgallery) {
                     $subs[] = $subgallery->id;
@@ -125,7 +126,10 @@ if (empty($rss)) {
     case 'user':
         $galleries = array();
         try {
-            $shares = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, $id);
+            $shares = $GLOBALS['injector']
+                ->getInstance('Ansel_Storage')
+                ->getScope()
+                ->listGalleries(array('filter' => $id));
             foreach ($shares as $gallery) {
                 if ($gallery->isOldEnough() && !$gallery->hasPasswd()) {
                     $galleries[] = $gallery->id;
@@ -137,7 +141,10 @@ if (empty($rss)) {
         $images = array();
         if (isset($galleries) && count($galleries)) {
             try {
-                $images = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->getRecentImages($galleries);
+                $images = $GLOBALS['injector']
+                    ->getInstance('Ansel_Storage')
+                    ->getScope()
+                    ->getRecentImages($galleries);
             } catch (Ansel_Exception $e) {
                  Horde::logMessage($e->getMessage(), 'ERR');
             }
index a1e2621..ab5db7c 100755 (executable)
@@ -91,7 +91,10 @@ exit;
 function emptyGalleryCheck($gallery)
 {
     if ($gallery->hasSubGalleries()) {
-        $children = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, null, $gallery, false);
+        $children = $GLOBALS['injector']
+            ->getInstance('Ansel_Storage')
+            ->getScope()
+            ->listGalleries(array('parent' => $gallery));
         foreach ($children as $child) {
             // First check all children to see if they are empty...
             emptyGalleryCheck($child);
index 018716f..fc37809 100755 (executable)
@@ -114,7 +114,10 @@ processDirectory($dir, null, $gallery_id, $gallery_slug, $useCompression);
 function emptyGalleryCheck($gallery)
 {
     if ($gallery->hasSubGalleries()) {
-        $children = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW, null, $gallery, false);
+        $children = $GLOBALS['injector']
+            ->getInstance('Ansel_Storage')
+            ->getScope()
+            ->listGalleries(array('parent' => $gallery));
         foreach ($children as $child) {
             // First check all children to see if they are empty...
             emptyGalleryCheck($child);
index 0a252b8..165e29f 100644 (file)
@@ -18,7 +18,9 @@
  <td>
   <select name="gallery_parent" id="gallery_parent">
    <option value=""><?php echo _("Top Level Gallery") ?></option>
-   <?php echo Ansel::selectGalleries($gallery_parent, Horde_Perms::EDIT, null, null, true, 0, 0, $galleryId) ?>
+   <?php echo Ansel::selectGalleries(array('selected' => $gallery_parent,
+                                           'perm' => Horde_Perms::EDIT,
+                                           'ignore' => $galleryId))?>
   </select>
  </td>
 </tr>
index 927380a..a0c622b 100644 (file)
@@ -1,7 +1,8 @@
 <?php
-
-$num_galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->countGalleries(
-    $GLOBALS['registry']->getAuth(), Horde_Perms::SHOW, array('category' => $group), null, false);
+$num_galleries = $GLOBALS['injector']
+    ->getInstance('Ansel_Storage')
+    ->getScope()
+    ->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW, array('category' => $group), null, false);
 
 if (empty($group)) {
     $category_title = _("Unfiled");
@@ -20,12 +21,17 @@ $link = Horde::link($viewurl, $category_title, 'light');
 
 $preview_gallery = array();
 if ($num_galleries < 5) {
-    $preview_gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(
-                            Horde_Perms::SHOW, array('category' => $group), null, false);
+    $preview_gallery = $GLOBALS['injector']
+        ->getInstance('Ansel_Storage')
+        ->getScope()
+        ->listGalleries(array('filter' => array('category' => $group)));
 } else {
-    $preview_gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(
-                            Horde_Perms::SHOW, array('category' => $group), null,
-                            false, rand(0, $num_galleries - 4), 4);
+    $preview_gallery = $GLOBALS['injector']
+        ->getInstance('Ansel_Storage')
+        ->getScope()
+        ->listGalleries(array('filter' => array('category' => $group),
+                              'from' => rand(0, $num_galleries - 4),
+                              'count' => 4));
 }
 $mini_count = 0;
 ?>
index dbc3b53..9b577c6 100644 (file)
@@ -28,11 +28,16 @@ $link = Horde::link(Ansel::getUrlFor('view', array('groupby' => $groupby,
 $num_galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->countGalleries($GLOBALS['registry']->getAuth(), Horde_Perms::SHOW,
                                                 $group, null, false);
 if ($num_galleries < 5) {
-    $mini_galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(Horde_Perms::SHOW,
-                                                    $group, null, false);
+    $mini_galleries = $GLOBALS['injector']->
+        getInstance('Ansel_Storage')->
+        getScope()->listGalleries(array('filter' => $group));
 } else {
-    $mini_galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->getScope()->listGalleries(
-        Horde_Perms::SHOW, $group, null, false, rand(0, $num_galleries - 4), 4);
+    $mini_galleries = $GLOBALS['injector']
+        ->getInstance('Ansel_Storage')
+        ->getScope()
+        ->listGalleries(array('filter' => $group,
+                              'from' => rand(0, $num_galleries - 4),
+                              'count' => 4));
 }
 $mini_galleries = array_values($mini_galleries);
 ?>
index d219c51..54d6b2f 100644 (file)
@@ -136,7 +136,7 @@ function downloadSelected()
     </td>
     <td align="right">
       <?php echo implode(' | ', $action_links); ?>
-      <select name="new_gallery"><option value="-1"><?php echo _("Selected photos to") ?></option><?php echo Ansel::selectGalleries(null, Horde_Perms::EDIT) ?></select>
+      <select name="new_gallery"><option value="-1"><?php echo _("Selected photos to") ?></option><?php echo Ansel::selectGalleries(array('perms' => Horde_Perms::EDIT))?></select>
       </td></tr></table>
     <?php endif; ?>
     <?php if (!$this->numTiles): ?>
index 14f30f7..49eea91 100644 (file)
@@ -164,7 +164,7 @@ function downloadSelected()
           <?php if ($option_copy): ?>
      |      <?php echo Horde::link('#', _("Copy"), 'widget', '', 'copySelected(); return false;') . _("Copy"); ?></a>
           <?php endif; ?>
-          <select name="new_gallery"><option value="-1"><?php echo _("Selected photos to") ?></option><?php echo Ansel::selectGalleries($this->galleryId, Horde_Perms::EDIT) ?></select>
+          <select name="new_gallery"><option value="-1"><?php echo _("Selected photos to") ?></option><?php echo Ansel::selectGalleries(array('selected' => $this->galleryId, 'perm' => Horde_Perms::EDIT)) ?></select>
           </td></tr></table>
         <?php endif; ?>
      <?php if (!$this->numTiles): ?>
index 5a5ba7e..14e8c9b 100644 (file)
@@ -86,7 +86,7 @@ echo htmlspecialchars($this->getTitle(), ENT_COMPAT, Horde_Nls::getCharset()) .
 <?php if ($option_copy): ?>
  |  <?php echo Horde::link('#', _("Copy"), 'widget', '', 'copySelected(); return false;') . _("Copy"); ?></a>
 <?php endif; ?>
-    <select name="new_gallery"><option value="-1"><?php echo _("Selected photos to") ?></option><?php echo Ansel::selectGalleries(null, Horde_Perms::EDIT) ?></select>
+    <select name="new_gallery"><option value="-1"><?php echo _("Selected photos to") ?></option><?php echo Ansel::selectGalleries(array('perms' => Horde_Perms::EDIT))?></select>
   </td>
  </tr>
 </table>
index a3afc0d..1f2232e 100755 (executable)
@@ -11,7 +11,7 @@
  <p>
   <label style="font-weight:bold" for="gallery"><?php echo _("Existing galleries:") ?></label><br />
   <select id="gallery" name="gallery">
-   <?php echo Ansel::selectGalleries(null, Horde_Perms::EDIT) ?>
+   <?php echo Ansel::selectGalleries(array('perms' => Horde_Perms::EDIT))?>
   </select>
  </p>
  <p>