deanmoses / zenphoto-json-rest-api

Rest API for Zenphoto
GNU General Public License v2.0
9 stars 1 forks source link
rest-api zenphoto-plugin zenphotocms-plugin

zenphoto-json-rest-api

A Zenphoto plugin that provides a JSON REST API to retrieve albums and run searches.

It's useful for building mobile apps and javascript-heavy web apps on top of Zenphoto.

The API is read-only; it cannot create or modify albums or images.

PHP 5.4+ required.

Installation

  1. Place json_rest_api.php and the folder json_rest_api in the /plugins folder of your Zenphoto installation
  2. Activate the plugin from your Zenphoto administration panel, under the Plugins -> Development tab

Usage

Use your normal gallery URLs but add a query string parameter named "json" to get a JSON representation.

Albums:

Images:

Search:

The gallery itself:

Pagination

By default, results are paginated in the normal Zenphoto pattern. Get subsequent pages of results like this:

Use "pagination=off" to return the full unpaginated set of results:

pagination has no effect on images.

Depth of album retrieval

Use the depth parameter to control the amount of information retrieved about descendant albums.

Albums:

The gallery itself:

If depth is omitted, it defaults to 1, meaning it returns thumbnail information about immediate child albums.

There is no maximum depth. You can go as deep as you want.

Use depth carefully! It can be very expensive to get a giant set of nested albums. I can't call this on my own root gallery of about 1000 albums and 25000 images because it times out.

depth has no effect on images and searches.

Statistics

If you have enabled the image_album_statistics plugin (it's included with Zenphoto), you can retrieve various statistics about your overall gallery or specific albums.

The gallery itself:

Albums:

Supports the following stats:

Supports the following parameters:

Examples:

Join parameters with commas:

http://mysite.com/?json&popular_albums=count:3,sort:asc,threshold:2

If you just want to get statistics and not get anything else, the most efficient way is to ask for the gallery with depth=0:

http://mysite.com/?json&depth=0&popular_albums

Statistics can only be collected on gallery and album requests; they cannot be collected on image and search requests.

Localization

If your Zenphoto is in multilingual mode, you can access language-specific content:

This principle works with all the URLs above.

Cross-domain AJAX

For security reasons it does not support AJAX requests from random domains. However, it does allow cross-domain AJAX from subdomains. For example, you can have zenphoto on mysite.com and your web app on app.mysite.com.