A new Flickr service for php

Soflomo has built its CMS upon the Zend Framework and because I use Flickr for my on-line gallery, I’ve done some research into the Zend_Service_Flickr component of ZF. I’d be nice if I could have used it to manage my photos (and sets and collection) to display to all visitors. Unfortunately its structure is very simple, it’s more a wrapper around the REST client: you have to make the api calls yourself and get a very common ‘result set’ from the service back.

I thought it could be done such better with a more O/R like service. You’ll have Flickr_Collection, Flickr_Set, Flickr_User and Flickr_Photo objects, all very clear and with distinguished roles. You can ask a set for its photos, a collection for its sets and so on.

Because I’m very open source minded and Soflomo is happy to use the open source ZF product, some of our code will also be published under the new BSD license (just like ZF). The open Soflomo library is called Sozfo and hosted at Google Code. There are more things in the library, but one of them is the Sozfo_Service_Flickr package. You should check out the source and try it yourself, it’s actually easy to get some results.

For example, these are some snippets I used to get my gallery online at this website:

$flickr = new Sofzo_Service_Flickr();
$flickr->setKey($apiKey)
       ->setSecret($apiSecret)
       ->setToken($authToken);

$user = $flickr->factory('user');
//$email, $profilepage or $photopage will work as well
$user = $user->find($username);

$set = $flickr->factory('set');
$sets = $set->getList($user);

echo 'Sets for user ' . $user->getUsername();
foreach ($sets as $set) {
  echo '<h2>' . $set->getTitle() . '</h2>';
  echo '<img src="' . $set->getPrimary()->location('thumbnail') . '">';
}

I hope you like the opportunities. Because Flickr recently updated their api with collections support, the Sozfo_Service_Flickr has support for collections! My gallery if updated directly from every change I make at Flickr (with some local cache of course), so no local configuration anymore. Huraay!