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.
- Place
json_rest_api.phpand the folderjson_rest_apiin the/pluginsfolder of your Zenphoto installation - Activate the plugin from your Zenphoto administration panel, under the Plugins -> Development tab
Use your normal gallery URLs but add a query string parameter named "json" to get a JSON representation.
Albums:
http://mysite.com/myAlbum/?jsonget JSON about myAlbum and its immediate child albums
Images:
http://mysite.com/myAlbum/myImage.jpg?jsonget JSON about myImage.jpg
Search:
http://mysite.com/page/search/train/?jsonget JSON about the first page of search results about 'train'
The gallery itself:
http://mysite.com/?jsonget JSON about the gallery itself and the top-level albums
By default, results are paginated in the normal Zenphoto pattern. Get subsequent pages of results like this:
http://mysite.com/myAlbum/page/2/?jsonget JSON about myAlbum and the second page of its immediate child albumshttp://mysite.com/page/search/train/page/2/?jsonget JSON about the second page of search results about 'train'
Use "pagination=off" to return the full unpaginated set of results:
http://mysite.com/myAlbum/?json&pagination=offget myAlbum and all its descendants, unpaginatedhttp://mysite.com/page/search/train/?json&pagination=offget search results about 'train', unpaginatedhttp://mysite.com/?json&pagination=offget info about the gallery itself and the top-level albums, unpaginated
pagination has no effect on images.
Use the depth parameter to control the amount of information retrieved about descendant albums.
Albums:
http://mysite.com/myAlbum/?json&depth=0get thumbnail info about myAlbum (no images, no subalbums)http://mysite.com/myAlbum/?json&depth=1get myAlbum and thumbnail info about its immediate subalbumshttp://mysite.com/myAlbum/?json&depth=2get myAlbum, its immediate subalbums, and thumbnail info about the subalbums' immediate subalbumshttp://mysite.com/myAlbum/?json&depth=-1get full information about myAlbum and ALL its descendants
The gallery itself:
http://mysite.com/?json&depth=0get basic info about the gallery, but no albumshttp://mysite.com/?json&depth=1get thumbnail info about the top-level albumshttp://mysite.com/?json&depth=2get top level albums and thumbnail info about their childrenhttp://mysite.com/?json&depth=-1get EVERY ALBUM IN THE SYSTEM
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.
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:
http://mysite.com/?json&latest_albumsget the latest album in your galleryhttp://mysite.com/?json&latest_albums&latest_imagesget the latest album and the latest image
Albums:
http://mysite.com/myAlbum/?json&latest_albumsget myAlbum's latest subalbum
Supports the following stats:
- Albums
- popular_albums, latest_albums, latest_date_albums, latest_mtime_albums, latest_publishdate_albums, mostrated_albums, toprated_albums, latestupdated_albums, random_albums
- Images
- popular_images, latest_images, latest_date_images, latest_mtime_images, latest_publishdate_images, mostrated_images, toprated_images, random_images
Supports the following parameters:
countThe number of albums or images to return. Defaults to 1.thresholdThe minimum number of ratings (for rating options) or hits (for popular option) an album must have to be included in the list. Defaults to 0.sortTakes eitherascordesc. Whether to return items in ascending or descending order (e.g., most to least hits or least to most) Defaults to descending.deepThis only applies when getting albums, not the overall gallery. Whentruethe stats will be measured across all descendant albums. Otherwise it will only measure the stats on the specific named album: image stats will only include images in the album and album stats will only include immedate child albums. Defaults to false.
Examples:
http://mysite.com/?json&latest_albums=count:3get the 3 latest albumshttp://mysite.com/?json&popular_albums=threshold:2get the most popular subalbum, must have at least 2 viewshttp://mysite.com/?json&latest_albums=sort:ascget the oldest album in the galleryhttp://mysite.com/myAlbum/?json&latest_albums=deep:trueget the newest album at any depth under myAlbum
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.
If your Zenphoto is in multilingual mode, you can access language-specific content:
- Enable the official
seo_localeplugin to allow switching the language via URL http://mysite.com/<locale>/myAlbum/?jsonnow gets JSON about myAlbum in that locale, if any language-specific content exists. Otherwise it gets content for the default language.- Example:
http://mysite.com/de_DE/myAlbum/?jsonwould get the German content
This principle works with all the URLs above.
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.