You are here

function theme_emvideo_video_thumbnail in Embedded Media Field 6.2

Same name and namespace in other branches
  1. 6.3 contrib/emvideo/emvideo.theme.inc \theme_emvideo_video_thumbnail()
  2. 6 contrib/emvideo/emvideo.theme.inc \theme_emvideo_video_thumbnail()

This will return a provided thumbnail image for a video.

Parameters

$field: This is the field providing settings for the video thumbnail.

$item: This is the data returned by the field. It requires at the least to be an array with 'value' and 'provider'. $item['value'] will be the video code, and $item['provider'] will be the provider, such as youtube.

$formatter: This is the formatter for the view. This will nearly always be video_thumbnail.

$node: This is the node object containing the field.

$no_link: Optional. If FALSE, then we provide a link to the node. (In retrospect, this should have been $link, defaulting to TRUE. TODO: fix? problem though is that this goes deeper up the tree.)

$options: Optional array. This is to pass optional overrides. currently: $options['width'] and $options['height'], if provided, will override any field settings for the thumbnail w/h. $options['link_url'], if provided, will cause the thumbnail link to go to another URL other than node/nid. $no_link must be FALSE. $options['title'], if provided, will set the title of the link and image. $options['link_title'], if provided, will set the title of the link when no image is provided. otherwise, it defaults to 'See video'. $options['image_title'], if provided, will set the title attribute of the href link, defaulting to $options['link_title']. $options['image_alt'], if provided, will set the alt attribute of the href link, defaulting to $options['link_title']. $options['thumbnail_url'], if provided, will completely override the thumbnail image entirely. $options['attributes'], if provided, sets the attributes for the displayed image. $options['return_url'], if provided, simply returns the URL to the thumbnail. $options['raw'], if TRUE, will return the raw URL, assuming $options['return_url'] is also true.

Return value

The thumbnail output.

9 theme calls to theme_emvideo_video_thumbnail()
theme_emthumb_imagecache_formatter_imagelink in contrib/emthumb/emthumb.theme.inc
Returns the imagecache image linked to the original image.
theme_emthumb_imagecache_formatter_path in contrib/emthumb/emthumb.theme.inc
Returns the path to the imagecache image.
theme_emthumb_imagecache_formatter_url in contrib/emthumb/emthumb.theme.inc
Returns the URL to the imagecache image.
theme_emvideo_modal_generic in contrib/emvideo/emvideo.theme.inc
theme_emvideo_video_thumbnail_no_link in contrib/emvideo/emvideo.theme.inc

... See full list

File

contrib/emvideo/emvideo.theme.inc, line 89
This defines the various theme functions for Embedded Video Field (emvideo).

Code

function theme_emvideo_video_thumbnail($field, $item, $formatter, $node, $no_link = FALSE, $options = array()) {

  // Thickbox requires some output, so make sure we have at least a blank string.
  $output = '';
  $options['node'] = $node;
  $width = isset($options['width']) ? $options['width'] : ($field['widget']['thumbnail_width'] ? $field['widget']['thumbnail_width'] : variable_get('emvideo_default_video_width', EMVIDEO_DEFAULT_THUMBNAIL_WIDTH));
  $height = isset($options['height']) ? $options['height'] : ($field['widget']['thumbnail_height'] ? $field['widget']['thumbnail_height'] : variable_get('emvideo_default_video_height', EMVIDEO_DEFAULT_THUMBNAIL_HEIGHT));

  // Get a thumbnail URL. This can be an override through $options['thumbnail_url'],
  // defined by the provider (the usual case), or a default image.
  if (isset($options['thumbnail_url']) || $item['value'] && $item['provider']) {

    // If we've set $options['thumbnail_url'], then we'll just use that.
    $thumbnail_url = isset($options['thumbnail_url']) ? $options['thumbnail_url'] : '';

    // Otherwise, if we have emthumb installed, then give it a chance to override our thumbnail.
    if (empty($thumbnail_url) && function_exists('emthumb_thumbnail_path')) {
      $thumbnail_url = emthumb_thumbnail_path($item);
    }

    // If we don't have a custom thumbnail, then see if the provider gives us a thumbnail.
    if (empty($thumbnail_url)) {
      $thumbnail_url = emfield_include_invoke('emvideo', $item['provider'], 'thumbnail', $field, $item, $formatter, $node, $width, $height, $options);
    }
  }

  // If we still don't have a thumbnail, then apply a default thumbnail, if it exists.
  if (empty($thumbnail_url)) {
    $default_thumbnail_url = $field['widget']['thumbnail_default_path'] ? $field['widget']['thumbnail_default_path'] : variable_get('emvideo_default_thumbnail_path', NULL);
    if ($default_thumbnail_url) {
      $thumbnail_url = $default_thumbnail_url;
    }
  }

  // Define the thumbnail link's path.
  $link_url = isset($options['link_url']) ? $options['link_url'] : 'node/' . $node->nid;

  // Define the title/alt to display for the link hover.
  $link_title = isset($options['link_title']) ? $options['link_title'] : (isset($options['title']) ? $options['title'] : (isset($field['widget']['thumbnail_link_title']) ? $field['widget']['thumbnail_link_title'] : (isset($item['title']) ? $item['title'] : variable_get('emvideo_default_thumbnail_link_title', t('See video')))));
  if (module_exists('token')) {

    // Allow the editor to use [title] tokens.
    $link_title = token_replace($link_title, 'global', $node);
  }
  $image_title = isset($options['image_title']) ? $options['image_title'] : (isset($item['title']) ? $item['title'] : $link_title);
  $image_alt = isset($options['image_alt']) ? $options['image_alt'] : (isset($item['description']) ? $item['description'] : $link_title);
  if (isset($thumbnail_url)) {
    if (!empty($options['absolute'])) {
      $thumbnail_url = url($thumbnail_url, array(
        'absolute' => $options['absolute'],
      ));
    }
    if (isset($options['return_url'])) {
      return isset($options['raw']) && $options['raw'] ? $thumbnail_url : url($thumbnail_url);
    }
    $width = isset($options['width']) ? $options['width'] : NULL;
    $width = isset($width) ? $width : ($field['widget']['thumbnail_width'] ? $field['widget']['thumbnail_width'] : variable_get('emvideo_default_thumbnail_width', EMVIDEO_DEFAULT_THUMBNAIL_WIDTH));
    $height = isset($options['height']) ? $options['height'] : NULL;
    $height = isset($height) ? $height : ($field['widget']['thumbnail_height'] ? $field['widget']['thumbnail_height'] : variable_get('emvideo_default_thumbnail_height', EMVIDEO_DEFAULT_THUMBNAIL_HEIGHT));
    $attributes = isset($options['attributes']) ? $options['attributes'] : array();
    $attributes['width'] = isset($attributes['width']) ? $attributes['width'] : $width;
    $attributes['height'] = isset($attributes['height']) ? $attributes['height'] : $height;
    $image = theme('image', $thumbnail_url, $image_alt, $image_title, $attributes, FALSE);
    if ($no_link) {

      // Thickbox requires the thumbnail returned without the link.
      $output = $image;
    }
    else {
      $output = l($image, $link_url, array(
        'html' => TRUE,
      ));
    }
  }
  else {
    if ($options['return_url']) {
      return $options['raw'] ? $thumbnail_url : url($link_url);
    }

    // If all else fails, then just print a 'see video' type link.
    if (!$no_link) {
      $output = l($link_title, $link_url);
    }
  }
  return $output;
}