J-Flickr
J-Flickr is a WordPress plugin that acts as a thin client over the Flickr API. It currently provides shortcode (e.g. [ flickr key="value" ]) syntax and flexible output using XSL. The latest version is 1.0.
» Download from japanographia.com
» Download from WordPress (coming soon!)
Details
J-Flickr is designed to be as unintrusive as possible in giving you access to the Flickr API service. This means that you are not limited to the methods you can call or hamstrung by the output of the plugin. If you want to search for photos with an Attribution License uploaded last year then you can, just as you can get a list of your public contacts or talk to the Flickr Pandas. Essentially you construct the shortcode as if making an API call and then either use one of the existing general templates or make your own! The templates are in XSL and operate directly on the XML sent back from Flickr so you’re never wanting for data that plugins may not expose.
Examples
Get a list of photos updated in April 2009
[ flickr method="photos.recentlyUpdated" min_date="2009-04-01" extras="license,geo,tags" ]
Get the photos from a specific group pool
[ flickr method="groups.pools.getPhotos" group_id="57342295@N00" per_page="25" page="4" ]
Get the comments for a specific photo with a custom template
[ flickr method="photos.comments.getList" photo_id="3459139116" max_comment_date="2009-04-01" jflickr_template="commentTemplate" ]
Requirements
J-Flickr is designed to be as compatible as possible, however it does require XSLT functionality which is not included as standard in PHP 4 installations which is what WordPress currently baselines. If you are on one of those fancy progressive servers with PHP 5, chances are high that you’ll have everything you need. If your server uses PHP 4, J-Flickr will let you know if it can’t proceed, or if you don’t want to go through the plugin installation hassle, check your php_info output (your host should provide this) for “XSLT”; if it’s there you should be all set.
Technical details
J-Flickr is, at its core, only a couple of functions. One gathers all the parameters from the shortcode while the other does the request and makes sure the API key is appended and other minor sanity checks. It is left to the user to tweak their parameters and the plugin will only output something unintended if there was an unintended error. J-Flickr implements caching of results as well so that this doesn’t hammer the Flickr API; by default the cache is set at 24 hours per request and the plugin tries to be smart about identical requests (e.g. [ flickr param1="1" param2="2" ] and [ flickr param2="2" param1="1" ] are equivalent even though their paramter orders are different. J-Flickr uses Cache_Lite by Fabien Marty for the caching which will only require the PEAR library if something goes wrong which is very infrequently.
The XSLT part of the plugin is the real icing and came about after I was considering building a templating system for the plugin and realised there was already a robust one available. I slightly extended XSLT by allowing for macros which are expanded by the plugin; at the moment there is only the {{username}} macro which is replaced by exactly what you would expect. The XSLT templates are broken down into three sections: general, method and user.
- General templates are fallbacks for the most commonly used methods, the most used one being the “photos” template which formats a list of photos into whatever you choose.
- Method templates are specific for a method and have file names reflecting this.
- User templates are not automatically selected by can be selected using the shortcode parameter “jflickr_template” e.g. [ flickr method="photos.search" jflickr_template="mytemplate" ].
This gives you a lot of flexibility to output how you choose.
History
J-Flickr started as a quick and dirty project for my blog for my Japan trip; I wanted to be able to upload photos to Flickr and pull the uploads for a specific timeframe to my blog posts. The plugin started as all of mine do: fast, rigid and hard to configure; my API key was hard coded and other parts were in PHP5 code with external libraries (Zend_Cache was used before Cache_Lite) and all sorts of other unreleasable parts. Having gotten good use out of while I was in Japan, I cleaned it up on my return making it more compatible and integrating it into WordPress “proper”. This was version 1.0.
Future
There are plans for developing the plugin so it stops being so specialises and becomes a more general and fully featured Flickr plugin for WordPress. I had originally intended to include a web-based template editor with version 1.0 but decided that it muddied the purity of what I was trying to achieve. J-Flickr is still very much a developer led plugin and it seemed an odd usage of time for fluffy UI elements, especially for a 1.0 release.
In no particular order:
- Admin template manager
- Proper, remote API key validation
- WP Media integration
- Tighter error checking of prerequisites (writable cache directory etc.)
- Better error reporting than silence or crunchy PHP output
- Authentication support (see Gotchas)
These should all be included in a 2.0 release although the development of that will likely depend on interest (if any) of this version.
Possible gotchas
There are a few things you need to bear in mind while using the J-Flickr plugin:
- At the moment you can’t use any methods which require authentication, this shouldn’t be too much of a problem for most people. Version 2.0 may have some support for authenticated methods though I haven’t explored its feasibility yet.
- Some methods don’t make sense to use anyway as they don’t produce any output so authentication is low priority.
- Only the most commonly used templates are included in the plugin distro, if there is specific demand for a certain template I’ll include it in the next version.
- Every invocation of the shortcode is a remote call to the API, you are responsible for managing your connections and queries to the Flickr API. I would recommend a generous cache time and judicious placement of the shortcode (e.g. behind “read more”s); be nice to Flickr.
Problems and bugs
If you run into any problems or bugs with the plugin please e-mail me using “john dot noel at chaostangent dot com”. Any and all comments and criticisms are welcome. If you do anything spiffy with J-Flickr or a particularly useful template, please let me know.