Zend Framework have a good API to play with Flickr Service. You will find it in the service API of Zend Framework.

First of all, we take the tag we want to search on the Flickr database.

1
$flirktag = "php, mysql"

After, we dont want to call each time the Flickr database so we will settup a cache of 10 minutes.

1
2
3
4
5
6
$frontendOptions = array(
    'lifetime' => 600,                   // cache lifetime of 10 minute
    'automatic_serialization' => false  // this is the default anyways
);
$backendOptions = array('cache_dir' => MYAPP_PATH_DATA);
$cache = Zend_Cache::factory('Output', 'File', $frontendOptions, $backendOptions);

We check first if it already have cache for the query we want. If no cache we execute the query like this :

8
9
10
11
12
13
14
15
16
17
18
if(!$flickrPlugin = $cache->load("flickr".md5($flirktag))) {
    $flickrPlugin = "";
    $flickr = new Zend_Service_Flickr('###YOUR#ID###');
    $options = array(
        'per_page' => 5,
        'page'     => 1,
        'tag_mode' => 'all',
        'extras'   => 'license, date_upload, date_taken, owner_name, icon_server'
        );
    $tags = explode(", ", $flirktag);
    $flickr_results = $flickr->tagSearch($tags, $options);

After, if we have some result, we can show data like this :

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    if (count($result) > 0){
        $flickrPlugin .= '<div class="flickr section"><ul class="gallery">';
        foreach ($flickr_results as $flickr_result) {
            if ($flickr_result->title == ""){
                $title = $result->flickr;
            }else{
                $substring = strtolower(substr($flickr_result->title, -4));
                if ($substring == ".jpg" or $substring == ".gif" or $substring == ".png"){
                    $title = $result->flickr;
                }else{
                    $title = $flickr_result->title;
                }
            }
            $flickrPlugin .= '<li><a rel="lightbox-tour" href="'.$flickr_result->Medium->uri.'" title="'.$flickr_result->title.'"><img class="thumb" src="'.$flickr_result->Square->uri.'" /></a></li>';
        }
    $flickrPlugin .= '</ul></div>';
}

Finally, we save the cache for future request than print the result.

38
39
    $cache->save($flickrPlugin, "flickr".md5($flirktag));
    print ($flickrPlugin);

This is a very simple exemple of what we can do with the Zend_Service_Flickr component.

Tags: , , , , , ,

Partager
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • RSS
  • Live
  • Technorati
  • Twitter
  • Blogosphere News
  • Yahoo! Bookmarks
  • LinkedIn

Related posts:

  1. Autocomplete field with Zend Framework and Dojo
  2. Add language route to your Zend Framework project.
  3. Phenix_Wiki, a parser componant for Zend Framework

Tags: , , , , , ,

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">