PHP Class Ansel_Api, horde

Copyright 2004-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Jan Schneider ([email protected])
Author: Chuck Hagenbuch ([email protected])
Author: Michael J. Rubinsky ([email protected])
Inheritance: extends Horde_Registry_Api
Show file Open project: horde/horde

Public Methods

Method Description
browse ( string $path = '', array $properties = [] ) : array Browse through Ansel's gallery tree.
commentCallback ( integer $image_id ) : mixed Callback for Agora comments.
count ( integer $gallery_id = null, array $params = [] ) : integer Returns the number of images in a gallery.
countGalleries ( array $params = [] ) : integer Counts the number of galleries.
createGallery ( array $attributes, array $params = [] ) : integer Add a new gallery to any application scope.
galleryExists ( integer $gallery_id, string $slug = '', string $app = null ) : boolean Checks if the gallery exists
getGalleries ( array $ids, string $app = null, array $slugs = [] ) : array Returns an array of gallery information.
getGalleryKeyImage ( integer $gallery_id, array $params = [] ) : integer Returns the id of the specified gallery's key image.
getGalleryStyles ( ) : hash Get a list of all pre-configured styles.
getImageContent ( integer $image_id, array $params = [] ) : string Returns raw image data in specified encoding/compression format.
getImageUrl ( integer $image_id, array $params = [] ) : string Returns the URL to the specified image.
getRecentImages ( array $params = [] ) : array Return a list of recently added images
hasComments ( ) : boolean Checks if applications allows comments
listGalleries ( array $params = [] ) : array Returns a list of all galleries.
listImages ( integer $gallery_id, array $params = [] ) : array Returns a list of all images in a gallery.
listTagInfo ( array $tags = null, $user = null ) : array Retrieve the list of used tag_names, tag_ids and the total number of resources that are linked to that tag.
postBatchUpload ( array $image_ids ) Notify Ansel that a group of images has just been uploaded. Used for when the postupload hook should be called with a group of recently uploaded images, as opposed to calling it once after each image is saved.
put ( string $path, string $content, string $content_type ) : array Saves an image into the gallery tree.
removeGallery ( integer $gallery_id, array $params = [] ) Removes a gallery and its images.
removeImage ( integer $gallery_id, string $image_id, array $params = [] ) Removes an image from a gallery.
renderView ( array $params = [], string $app = null, string $view = 'Gallery' ) : array Renders a gallery view
saveImage ( integer $gallery_id, array $image, array $params = [] ) : array Stores an image in a gallery and returns gallery and image data.
searchTags ( array $names, integer $max = 10, integer $from, string $resource_type = '', string $user = null, boolean $raw = false, string $app = 'ansel' ) : array SearchTags API: Returns an application-agnostic array (useful for when doing a tag search across multiple applications)
selectGalleries ( array $params = [] ) Returns a 'select' menu from the list of galleries created by listGalleries().

Protected Methods

Method Description
_getImageData ( string $data, string $encoding = 'none', string $compression = 'none', boolean $upload = true ) : string Returns decoded image data

Method Details

_getImageData() protected method

Returns decoded image data
protected _getImageData ( string $data, string $encoding = 'none', string $compression = 'none', boolean $upload = true ) : string
$data string The image data
$encoding string The encoding type for the image data. (none, base64, or binhex)
$compression string The compression type for the image data. (none, gzip, or lzf)
$upload boolean Process direction (true of encode/compress or false if decode/decompress)
return string The decoded/encoded image data

browse() public method

Browse through Ansel's gallery tree.
public browse ( string $path = '', array $properties = [] ) : array
$path string The level of the tree to browse.
$properties array The item properties to return. Defaults to 'name', 'icon', and 'browseable'.
return array The contents of $path

commentCallback() public method

Callback for Agora comments.
public commentCallback ( integer $image_id ) : mixed
$image_id integer Image id to check
return mixed Image filename on success | false on failure

count() public method

Returns the number of images in a gallery.
public count ( integer $gallery_id = null, array $params = [] ) : integer
$gallery_id integer The gallery id.
$params array Array of optional parameters:
   (string)scope  Scope to use, if not the default.
   (string)slug   If set, ignore gallery_id and use this as the slug.
return integer The number of images in the gallery.

countGalleries() public method

Counts the number of galleries.
public countGalleries ( array $params = [] ) : integer
$params array Parameter array containing the following optional:
 (string)app         Application scope to use, if not the default.
 (integer)perm       The level of permissions to require for a gallery
                     to return it.
 (mixed)attributes   Restrict the galleries counted to those matching
                     attributes. An array of attribute/value pairs or
                     a gallery owner username.
 (integer)parent     The parent gallery id to start searching at.
 (boolean)all_levels  Return all levels, or just the direct children of
                     $parent?
return integer Returns the number of matching galleries.

createGallery() public method

Add a new gallery to any application scope.
public createGallery ( array $attributes, array $params = [] ) : integer
$attributes array The gallery attributes
$params array Additional (optional) parameters:
   (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

galleryExists() public method

Checks if the gallery exists
public galleryExists ( integer $gallery_id, string $slug = '', string $app = null ) : boolean
$gallery_id integer The gallery id
$slug string The gallery slug
$app string Application scope to use, if not the default.
return boolean

getGalleries() public method

Returns an array of gallery information.
public getGalleries ( array $ids, string $app = null, array $slugs = [] ) : array
$ids array An array of gallery ids.
$app string Application scope to use, if not the default.
$slugs array An array of gallery slugs (ignore $ids).
return array An array of gallery data arrays

getGalleryKeyImage() public method

Returns the id of the specified gallery's key image.
public getGalleryKeyImage ( integer $gallery_id, array $params = [] ) : integer
$gallery_id integer The gallery id.
$params array Additional parameters:
 (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
return integer The key image id.

getGalleryStyles() public method

Get a list of all pre-configured styles.
public getGalleryStyles ( ) : hash
return hash of style definitions.

getImageContent() public method

Returns raw image data in specified encoding/compression format.
public getImageContent ( integer $image_id, array $params = [] ) : string
$image_id integer The id of the image.
$params array Optional parameters:
 (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)
return string The raw image data.

getImageUrl() public method

Returns the URL to the specified image.
public getImageUrl ( integer $image_id, array $params = [] ) : string
$image_id integer The id of the image.
$params array Additional optional parameters:
  (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.
return string The image path.

getRecentImages() public method

Return a list of recently added images
See also: Ansel_Api::getImages
public getRecentImages ( array $params = [] ) : array
$params array Parameter (optionally) containing:
  (string)app       Application used if null then use default.
  (array)galleries  An array of gallery ids to check.  If left empty,
                    will search all galleries with the given
                    permissions for the current user.
  (string)view      The type of image view to return.
  (boolean)full     Return a full URL if this is true.
  (integer)limit    The maximum number of images to return.
  (string)style     Force the use of this gallery style
  (array)slugs      An array of gallery slugs
return array A hash of image information arrays, keyed by image_id:

hasComments() public method

Checks if applications allows comments
public hasComments ( ) : boolean
return boolean

listGalleries() public method

Returns a list of all galleries.
public listGalleries ( array $params = [] ) : array
$params array Optional parameters:
 (string)scope       The application scope, if not default.
 (integer)perm       The permissions filter to use [Horde_Perms::SHOW]
 (mixed)attributes   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)all_levels 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]
 (array)tags        An array of tags to limit results by.
return array An array of gallery information.

listImages() public method

The return has the URL because in a lot of cases you'll want the url also. Using api call getImageURL results in a lot of overhead when e.g. generating a select list.
public listImages ( integer $gallery_id, array $params = [] ) : array
$gallery_id integer Gallery id to get images from.
$params array Additional parameters:
 (string)app          Application scope to use [ansel].
 (string)view         View size to generate URLs for [thumb].
 (boolean)full        Return a full URL [false].
 (integer)from        Start image.
 (integer)limit       Max count of images to return.
 (string)style        Use this gallery style.
 (string)slug         Gallery slug (ignore gallery_id).
return array Hash of image data (see below) keyed by image_id.
 name
 caption
 type
 uploaded
 original_date
 url

listTagInfo() public method

Retrieve the list of used tag_names, tag_ids and the total number of resources that are linked to that tag.
public listTagInfo ( array $tags = null, $user = null ) : array
$tags array An optional array of tag_ids. If omitted, all tags will be included.
return array An array containing tag_name, and total

postBatchUpload() public method

Notify Ansel that a group of images has just been uploaded. Used for when the postupload hook should be called with a group of recently uploaded images, as opposed to calling it once after each image is saved.
public postBatchUpload ( array $image_ids )
$image_ids array An array of image ids.

put() public method

Saves an image into the gallery tree.
public put ( string $path, string $content, string $content_type ) : array
$path string The path where to PUT the file.
$content string The file content.
$content_type string The file's content type.
return array The event UIDs.

removeGallery() public method

Removes a gallery and its images.
public removeGallery ( integer $gallery_id, array $params = [] )
$gallery_id integer The id of gallery.
$params array Any additional, optional, parameters:
  (string)scope  the scope to use, if not the default

removeImage() public method

Removes an image from a gallery.
public removeImage ( integer $gallery_id, string $image_id, array $params = [] )
$gallery_id integer The id of gallery.
$image_id string The id of image to remove.
$params array Additional parameters:
  (string)scope  The scope to use, if not the default.

renderView() public method

Renders a gallery view
public renderView ( array $params = [], string $app = null, string $view = 'Gallery' ) : array
$params array Any parameters that the view might need. @see Ansel_View_* classes for descriptions of available parameters to use here.
$app string Application scope to use, if not the default.
$view string The generic type of view we want. (Gallery, Image, List, Embedded)
return array An array containing 'html' and 'crumbs' keys.

saveImage() public method

Stores an image in a gallery and returns gallery and image data.
public saveImage ( integer $gallery_id, array $image, array $params = [] ) : array
$gallery_id integer The gallery id to add the image to.
$image array 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' and optionally 'tags'
$params array An array of additional parameters:
  (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).
return array An array of image/gallery data

searchTags() public method

The 'raw' results array can be returned instead by setting $raw = true.
public searchTags ( array $names, integer $max = 10, integer $from, string $resource_type = '', string $user = null, boolean $raw = false, string $app = 'ansel' ) : array
$names array An array of tag_names to search for.
$max integer The maximum number of resources to return.
$from integer The number of the resource to start with.
$resource_type string The resource type [gallery, image, '']
$user string Restrict results to resources owned by $user.
$raw boolean Return the raw data?
$app string Application scope to use, if not the default.
return array An array of results:
 'title'    - The title for this resource.
 'desc'     - A terse description of this resource.
 'view_url' - The URL to view this resource.
 'app'      - The Horde application this resource belongs to.

selectGalleries() public method

Returns a 'select' menu from the list of galleries created by listGalleries().
public selectGalleries ( array $params = [] )
$params array Optional parameters:
 (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.