You are here

function _media_flickr_photo_url_from_size in Media: Flickr 6

Same name and namespace in other branches
  1. 7.2 includes/media_flickr.utilities.inc \_media_flickr_photo_url_from_size()
  2. 7 includes/media_flickr.utilities.inc \_media_flickr_photo_url_from_size()
1 call to _media_flickr_photo_url_from_size()
media_flickr_photo_url_from_size in ./media_flickr.module

File

./media_flickr.utilities.inc, line 27
Utility functions for Media: Flickr.

Code

function _media_flickr_photo_url_from_size($photo_code, $size = 5) {
  if ($photo_code) {

    // If we're storing our files locally, then grab the filepath now.
    if ($store = variable_get('media_flickr_store_local', FALSE)) {
      $filepath = db_result(db_query("SELECT f.filepath FROM {files} f INNER JOIN {media_flickr_sizes} m ON m.fid = f.fid AND m.code = '%s' AND m.size = %d", $photo_code, $size));
    }

    // If we don't have a filepath, it's either because we're not storing
    // them locally, or it hasn't been saved locally yet.
    if (!$filepath && $store) {

      // Let's attempt to store our file locally.
      $filepath = media_flickr_store_local($photo_code, $size);
    }

    // We're not storing locally, or have otherwise failed,
    // so now we'll just grab the remote URL.
    if (!$filepath) {
      $filepath = media_flickr_photo_remote_url($photo_code, $size);
    }

    // URLize that path...
    $filepath = url($filepath, array(
      'absolute' => TRUE,
    ));
    return $filepath;
  }
}