topical media & game development

talk show tell print

mashup-flickr-06-Step-7-lib-FlickrGallery.php / php



  <?php
  
  class FlickrGallery
  {
    var flickr;
    var nsid = '50317659@N00';
  
    function FlickrGallery()
    {
      global flickrApiKey;
      global flickrApiSecret;
  
      this->flickr = new phpFlickr(flickrApiKey, flickrApiSecret, false);
    }
  
    function findRecentPhotos(n = 20)
    {
      args = array(
      'user_id' => this->nsid,
      'sort' => 'date-posted-desc',
      'page' => 1, 
      'per_page' => n
       );
  
      p = this->flickr->photos_search(args);
      if (this->flickr->getErrorCode())
      {
        echo ("Error fetching photos: " . this->flickr->getErrorMsg());
      }
  
      return p['photo'];
    }
    
    function getPhotoInfo(id)
    {
      p = this->flickr->photos_getInfo(id);
      if (this->flickr->getErrorCode())
      {
        echo ("Error getting photo info: " . this->flickr->getErrorMsg());
      }
  
      return p;
    }
  
    function showSmartSetThumbnail(linkPage, title = "Set", n = 20, tags = "", 
      tagMode = "all", sort = "date-posted-desc")
    {
      s = "";
      url = linkPage . '?title=' . urlencode(title) . '&tags=' . urlencode(tags) 
        . "&n=n&tagMode=tagMode&sort=sort";
      // Get image to display
      photos = this->getSmartSet(1, tags, tagMode, sort);
  
      if (is_array(photos) && count(photos) > 0)
      {
        photo = photos[0];
        img = 'http://static.flickr.com/' . photo['server'] . '/' . photo['id'] 
          . '_' . photo['secret'] . '_s.jpg';
        s .= "<a href=\"url\"><img src=\"img\" /></a>";
        s .= "<p class=\"smart-set-caption\">" . title . "</p>";
      }
      return s;
    }
  
    function getSmartSet(n = 20, tags = "", tagMode = "all", 
      sort = "date-posted-desc")
    {
      ret = array();
  
      args = array(
        'user_id' => this->nsid,
        'sort' => sort,
        'page' => 1,
        'per_page' => n,
        'extras' => 'owner_name'
      );
  
      if (!empty(tags))
      {
        args['tags'] = tags;
        args['tag_mode'] = tagMode;
      }
  
      p = this->flickr->photos_search(args);
      if (this->flickr->getErrorCode())
      {
        echo ("Error fetching photos: " . this->flickr->getErrorMsg());
      }
  
      if (is_array(p['photo']) && count(p['photo']) > 0)
      {
        ret = p['photo'];
      }
  
      return ret;
    }
  }
  
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.