You are here

function theme_video_cck_video_thumbnail in Embedded Media Field 5

This will return a provided thumbnail image for a video.

Parameters

$field: This is the field providing settings for the video thumbnail. @param $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. @param $formatter This is the formatter for the view. This will nearly always be video_thumbnail. @param $node This is the node object containing the field. @param $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.) @param $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['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.

1 theme call to theme_video_cck_video_thumbnail()
theme_video_cck_thickbox in contrib/video_cck/video_cck.module

File

contrib/video_cck/video_cck.module, line 366

Code

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

  // Sometime in the past, we added the $no_link argument before $options.
  // However, emfield.module attempts to call this w/o $no_link at line 341.
  if (is_array($no_link) && empty($options)) {
    $options = $no_link;
  }
  if (is_array($no_link)) {
    $no_link = FALSE;
  }
  $options['node'] = $node;
  if ($item['value'] && $item['provider']) {

    // if we've set $options['thumbnail_url'], then we'll just use that.
    // otherwise, if we have emthumb installed, then give it a chance to override our thumbnail
    $thumbnail_url = $options['thumbnail_url'] ? $options['thumbnail_url'] : module_invoke('emthumb', 'thumbnail_url', $item);

    // if we don't have a custom thumbnail, then see if the provider gives us a thumbnail
    $thumbnail_url = $thumbnail_url ? $thumbnail_url : module_invoke('emfield', 'include_invoke', 'video_cck', $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 (!$thumbnail_url) {
      $default_thumbnail_url = $field['widget']['thumbnail_default_path'] ? $field['widget']['thumbnail_default_path'] : variable_get('video_cck_default_thumbnail_path', NULL);
      if ($default_thumbnail_url) {
        $thumbnail_url = base_path() . $default_thumbnail_url;
      }
    }
  }
  else {

    // seems to be an unknown video
    // apply a default thumbnail, if it exists
    if (!$thumbnail_url) {
      $default_thumbnail_url = $field['widget']['thumbnail_default_path'] ? $field['widget']['thumbnail_default_path'] : variable_get('video_cck_default_thumbnail_path', NULL);
      if ($default_thumbnail_url) {
        $thumbnail_url = base_path() . $default_thumbnail_url;
      }
    }
  }
  $link_url = isset($options['link_url']) ? $options['link_url'] : 'node/' . $node->nid;
  $link_title = isset($options['link_title']) ? $options['link_title'] : t('See video');
  $image_title = isset($options['image_title']) ? $options['image_title'] : $link_title;
  $image_alt = isset($options['image_alt']) ? $options['image_alt'] : $link_title;
  if ($thumbnail_url) {
    $width = isset($options['width']) ? $options['width'] : NULL;
    $width = isset($width) ? $width : ($field['widget']['thumbnail_width'] ? $field['widget']['thumbnail_width'] : variable_get('video_cck_default_thumbnail_width', VIDEO_CCK_DEFAULT_THUMBNAIL_WIDTH));
    $height = isset($options['height']) ? $options['height'] : NULL;
    $height = isset($height) ? $height : ($field['widget']['thumbnail_height'] ? $field['widget']['thumbnail_height'] : variable_get('video_cck_default_thumbnail_height', VIDEO_CCK_DEFAULT_THUMBNAIL_HEIGHT));
    if ($no_link) {

      //thickbox requires the thumbnail returned without the link
      $output = '<img src="' . $thumbnail_url . '" width="' . $width . '" height="' . $height . '" alt="' . $image_alt . '" title="' . $image_title . '" />';
    }
    else {
      $output = l('<img src="' . $thumbnail_url . '" width="' . $width . '" height="' . $height . '" alt="' . $image_alt . '" title="' . $image_title . '" />', $link_url, array(), NULL, NULL, false, true);
    }
  }
  else {

    // if all else fails, then just print a 'see video' link.
    if ($no_link) {
      $output = '';

      //thickbox won't work without a thumbnail
    }
    else {
      if ($item['value'] && $item['provider']) {
        $output = l($link_title, $link_url);
      }
      else {
        $output = '';
      }
    }
  }
  return $output;
}