You are here

function flickr_img in Flickr 6

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

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

Parameters

$photo: the photo variable

$size: the desired image size

$attribs: an optional array of HTML attributes to pass to the image

Return value

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

7 calls to flickr_img()
theme_flickrfield_field_formatter in field/flickrfield.module
Basic flickrfield formatter.
theme_flickrfield_formatter_photoset_primaryphoto in field/flickrfield.module
Theme a Flickr photo set as the primary photo of that set.
theme_flickrfield_photoset in field/flickrfield.module
theme_flickr_photo in ./flickr.module
theme_flickr_photoset in ./flickr.module

... See full list

File

./flickr.inc, line 114

Code

function flickr_img($photo, $size = NULL, $attributes = NULL) {
  $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'] = implode(' ', array(
      $attributes['class'],
      'flickr-photoset-img',
    ));
  }
  else {
    $id = $photo['id'];
    $attributes['class'] = implode(' ', array(
      $attributes['class'],
      'flickr-photo-img',
    ));
  }
  if ($size == 's') {
    $attributes['height'] = $attributes['width'] = 75;
    $img_url = flickr_photo_img($photo, $size);
  }
  else {
    $image_sizes = flickr_photo_get_sizes($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'];
        $attributes['height'] = $image_size['height'];
        $attributes['width'] = $image_size['width'];
      }
    }
    else {
      $img_url = flickr_photo_img($photo, $size);
    }
  }
  $info = !is_array($photo['title']) ? flickr_photo_get_info($photo['id']) : '';
  $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') {

    // Make sure we are not passing an array where a string is expected.
    $title = is_array($photo['title']) ? str_replace('"', "'", htmlspecialchars_decode(strip_tags($photo['title']['_content']))) : $photo['title'];
  }
  return theme('image', $img_url, $title, $title, $attributes, FALSE);
}