You are here

function flickr_img in Flickr 7

Same name and namespace in other branches
  1. 5 flickr.inc \flickr_img()
  2. 6 flickr.inc \flickr_img()

This function will try to create an html image tag referencing the Flickr photo with the desired size if that size is available for this photo.

Parameters

string $photo: The photo variable.

string $size: The desired image size.

string $attributes: An optional array of HTML attributes to pass to the image.

Return value

array a html image tag referencing the image of the desired size if it is available.

5 calls to flickr_img()
theme_flickrfield_formatter_photoset_primaryphoto in field/flickrfield.module
Theme a Flickr photo set as the primary photo of that set.
theme_flickr_photo in ./flickr.module
Theme Flickr photo.
theme_flickr_photoset in ./flickr.module
Theme Flickr photoset.
theme_flickr_photo_box in ./flickr.module
Theme Flickr photo box on a profile page.
theme_flickr_sets_photoset_box in sets/flickr_sets.module
Theme a user's photos in a given set.

File

./flickr.inc, line 264
The Flickr API functions.

Code

function flickr_img($photo, $size = NULL, $attributes = NULL) {

  // Debug info.
  if (variable_get('flickr_debug', 0) == 2 && function_exists('dpm')) {
    dpm("Value of 'photo' passed to 'function flickr_img()' in 'flickr.inc':");
    dpm($photo);
  }
  $sizes = flickr_photo_sizes();
  if (!isset($size)) {
    $size = '-';
  }
  if (!isset($sizes[$size])) {
    return;
  }
  if (!isset($attributes) || !is_array($attributes)) {
    $attributes = array();
  }
  if (empty($attributes['class'])) {
    $attributes['class'] = NULL;
  }

  // Photoset's use primary instead of id to specify the image.
  if (isset($photo['primary'])) {
    $id = $photo['primary'];
    $attributes['class'] = explode(' ', trim($attributes['class'] . ' flickr-photoset-img'));
  }
  else {
    $id = $photo['id'];
    $attributes['class'] = explode(' ', trim($attributes['class'] . ' flickr-photo-img'));
  }
  $image_sizes = flickr_photos_getsizes($id);
  if ($image_sizes) {
    foreach ($image_sizes as $image_size) {
      if ($image_size['label'] == $sizes[$size]['label']) {
        break;
      }
    }
    if (isset($image_size)) {
      $img_url = $image_size['source'];

      // Fallback if no valid image is returned (might happen on some videos).
      if (!stripos($img_url, 'jpg')) {
        $img_url = flickr_photo_img($photo, $size);
      }
    }
  }
  else {
    $img_url = flickr_photo_img($photo, $size);
  }
  $info = !is_array($photo['title']) ? flickr_photos_getinfo($photo['id']) : '';
  if (isset($info['dates']) || isset($photo['dates'])) {
    $date_taken = is_array($info) && isset($info['dates']['taken']) ? $info['dates']['taken'] : $photo['dates']['taken'];
    $format_title = variable_get('flickr_date_format_image_title', 'medium');
    switch ($format_title) {
      case 'interval':
        $taken_short = format_interval(time() - strtotime($date_taken), 1) . ' ' . t('ago');
        break;
      case 'none':
        $taken_short = '';
        break;
      default:
        $taken_short = format_date(strtotime($date_taken), $format_title, '', NULL);
    }
  }
  $taken_short = empty($taken_short) ? '' : $taken_short . ' - ';
  $title = is_array($photo['title']) ? str_replace('"', "'", htmlspecialchars_decode(strip_tags($photo['description']['_content']))) : str_replace('"', "'", htmlspecialchars_decode(strip_tags($info['description']['_content'])));
  if (empty($title)) {
    $title = is_array($photo['title']) ? str_replace('"', "'", htmlspecialchars_decode(strip_tags($photo['title']['_content']))) : $photo['title'];
  }
  $title = $taken_short . $title;
  $overlay = variable_get('flickr_info_overlay', array(
    'title' => 'title',
    'metadata' => 'metadata',
    'description' => 'description',
    'license' => 0,
  ));
  $title = gettype($overlay['description']) == 'integer' ? $photo['title'] : $title;
  if (module_exists('jcaption') && (variable_get('flickr_class') != NULL || variable_get('flickr_rel') != NULL)) {
    $title = '';
  }
  return theme('image', array(
    'path' => $img_url,
    'alt' => $title,
    'title' => $title,
    'attributes' => $attributes,
    'getsize' => FALSE,
  ));
}