You are here

function media_flickr_photo_load in Media: Flickr 6

Implements hook_load().

Load the XML data for a flickr photo.

2 calls to media_flickr_photo_load()
media_flickr_photoset_load in ./media_flickr.module
Implements hook_load().
media_flickr_record_photo in ./media_flickr.module
Record any associated metadata with a specific photo.

File

./media_flickr.module, line 85
Embedded Video Field provider file for Flickr.com photosets.

Code

function media_flickr_photo_load($photoid) {
  static $xml;

  // Reset our static array.
  if (is_null($xml)) {
    $xml = array();
  }

  // If we try to load this with an already loaded photo,
  // then attempt to grab the ID from that.
  if (is_array($photoid)) {
    $photoid = $photoid['photo']['id'];
  }

  // If we haven't retrieved the XML from flickr, then do so now.
  if (is_null($xml[$photoid])) {
    if ($cache = cache_get('media_flickr:photoid:' . $photoid)) {
      $xml[$photoset] = $cache->data;
    }
    else {

      // Grab the cached photoset XML from flickr.
      $xml[$photoid] = media_flickr_sets_request('flickr.photos.getInfo', array(
        'photo_id' => $photoid,
      ));
      if ($xml[$photoid]['stat'] != 'ok') {
        $xml[$photoid] = FALSE;
      }
      cache_set('media_flickr:photoid:' . $photoid, $xml[$photoid], 'cache', time() + variable_get('media_flickr_cache_time', 3600));
    }
  }

  // Return the static XML for the photoset, or FALSE if not available.
  return $xml[$photoid];
}