You are here

function theme_emaudio_audio_thumbnail in Embedded Media Field 6

Same name and namespace in other branches
  1. 6.3 contrib/emaudio/emaudio.theme.inc \theme_emaudio_audio_thumbnail()
  2. 6.2 contrib/emaudio/emaudio.theme.inc \theme_emaudio_audio_thumbnail()

File

contrib/emaudio/emaudio.theme.inc, line 24
This defines the various theme functions for Embedded Audio Field (emaudio).

Code

function theme_emaudio_audio_thumbnail($field, $item, $formatter, $node, $no_link = FALSE, $options = array()) {
  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', 'emaudio', $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('emaudio_default_thumbnail_path', NULL);
      if ($default_thumbnail_url) {
        $thumbnail_url = base_path() . $default_thumbnail_url;
      }
    }
  }
  else {

    // Seems to be an unknown audio. 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('emaudio_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 audio');
  $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('emaudio_default_thumbnail_width', EMAUDIO_DEFAULT_THUMBNAIL_WIDTH));
    $height = isset($options['height']) ? $options['height'] : NULL;
    $height = isset($height) ? $height : ($field['widget']['thumbnail_height'] ? $field['widget']['thumbnail_height'] : variable_get('emaudio_default_thumbnail_height', emaudio_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(
        'html' => true,
      ));
    }
  }
  else {

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

      //thickbox won't work without a thumbnail
    }
    else {
      $output = l($link_title, $link_url);
    }
  }
  return $output;
}