You are here

function media_flickr_photoset_load in Media: Flickr 6

Implements hook_load().

Load the XML data for a Flickr photoset.

1 call to media_flickr_photoset_load()
media_flickr_record_photoset in ./media_flickr.module
Record the photoset and all its photos.

File

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

Code

function media_flickr_photoset_load($photoset) {
  static $xml;

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

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

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

      // If we aren't storing the photoset in any field, then don't allow this page load.
      if (!db_result(db_query("SELECT instances FROM {media_flickr_photoset_count} WHERE photoset = '%s'", $photoset))) {
        $xml[$photoset] = FALSE;
      }
      else {

        // Grab the cached photoset XML from flickr.
        $xml[$photoset] = media_flickr_sets_request('flickr.photosets.getPhotos', array(
          'photoset_id' => $photoset,
        ));
        if ($xml[$photoset]['stat'] != 'ok') {
          $xml[$photoset] = FALSE;
        }
        else {

          // Associate each photo in its array by Flickr's photo ID.
          $photos = array();
          foreach ($xml[$photoset]['photoset']['photo'] as $photo) {
            $photos[$photo['id']] = media_flickr_photo_load($photo['id']);
          }
          $xml[$photoset]['photoset']['photo'] = $photos;
        }
      }
      cache_set('media_flickr:photoset:' . $photoset, $xml[$photoset], 'cache', time() + variable_get('media_flickr_cache_time', 3600));
    }
  }

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