theme_imagefield_image

5 imagefield.module theme_imagefield_image($file, $alt = '', $title = '', $attributes = null, $getsize = true)
6 imagefield.module theme_imagefield_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE)

@defgroup "Theme Callbacks"

See also

imagefield_theme().

5 theme calls to theme_imagefield_image()

File

contributions/imagefield/imagefield.module, line 316
ImageField core hooks and menu callbacks.

Code

function theme_imagefield_image($file, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
  $file = (array) $file;

  if ($getsize) {
    // Use cached width and height if available.
    if (!empty($file['data']['width']) && !empty($file['data']['height'])) {
      $attributes['width']  = $file['data']['width'];
      $attributes['height'] = $file['data']['height'];
    }
    // Otherwise pull the width and height from the file.
    elseif (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath'])) {
      $attributes['width'] = $width;
      $attributes['height'] = $height;
    }
  }

  if (!empty($title)) {
    $attributes['title'] = $title;
  }

  // Alt text should be added even if it is an empty string.
  $attributes['alt'] = $alt;

  // Add a timestamp to the URL to ensure it is immediately updated after editing.
  $query_string = '';
  if (isset($file['timestamp'])) {
    $query_character = (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE && variable_get('clean_url', '0') == '0') ? '&' : '?';
    $query_string = $query_character . $file['timestamp'];
  }

  // Encode the path so that unusual characters are printed correctly.
  $path = field_file_urlencode_path($file['filepath']);

  // Construct the URL.
  $url = file_create_url($path) . $query_string;
  $attributes['src'] = $url;
  $attributes = drupal_attributes($attributes);
  return '<img ' . $attributes . ' />';
}