You are here

function taxonomy_image_display in Taxonomy Image 6

Same name and namespace in other branches
  1. 5 taxonomy_image.module \taxonomy_image_display()

Function to display the image associated with the given term id. An html <img> tag will be returned if an image is found. The link format can be modified with the tags parameter.

Parameters

$tid - the term id.:

$tags - optional HTML attributes to include in the link.:

Return value

An html img link.

See also

taxonomy_image_get_object()

taxonomy_image_get_url()

6 calls to taxonomy_image_display()
taxonomy_image_block in contributed/taxonomy_image_blocks/taxonomy_image_blocks.module
Implementation of hook_block(). This creates and populates the "unanswered questions" block.
taxonomy_image_form_alter in ./taxonomy_image.module
taxonomy_image_link_alter in contributed/taxonomy_image_link_alter/taxonomy_image_link_alter.module
Implement hook_link_alter to picturize the taxonomy term links
taxonomy_image_node_display_nodeapi in contributed/taxonomy_image_node_display/taxonomy_image_node_display.module
Implementation of hook_nodeapi().
taxonomy_image_overview in ./taxonomy_image.admin.inc

... See full list

File

./taxonomy_image.module, line 27
taxonomy_image.module Simple module for providing an association between taxonomy terms and images. Written by Jeremy Andrews <jeremy@kerneltrap.org>, May 2004.

Code

function taxonomy_image_display($tid, $tags = NULL, $profile = NULL, $overrides = array()) {
  global $user;
  if (user_access('access taxonomy images') && empty($user->taxonomy_image_disable_images)) {

    // Get our controlling variables.
    $wrapper = variable_get('taxonomy_image_wrapper', FALSE);
    $imagecache_preset = variable_get('taxonomy_image_imagecache_preset', 'ORIGINAL');
    $recursive = variable_get('taxonomy_image_recursive', 0);
    $resize = variable_get('taxonomy_image_resize', 0);
    $width = variable_get('taxonomy_image_width', '');
    $height = variable_get('taxonomy_image_height', '');

    // Any overrides specified?
    if ($overrides) {
      extract($overrides, EXTR_IF_EXISTS);
    }

    // do lookup, return full display path
    $image = taxonomy_image_get_object($tid, $recursive);

    // Do we have an image?
    if (isset($image->path)) {
      if (module_exists('imagecache') && $image->type_extension != 'swf') {
        $preset = $profile ? $profile : $imagecache_preset;
      }
      else {
        $preset = 'ORIGINAL';
      }

      // Handle our own image resizing?
      if ($preset == 'ORIGINAL') {
        taxonomy_image_resize($image, $resize, $width, $height);
      }
      $current = $image;

      // Build the link title based on admin choice.
      // Note: translation must be done here because the cache needs to be language-neutral.
      if ($current->description && !variable_get('taxonomy_image_link_title', 0)) {
        $current->title = taxonomy_image_tt("taxonomy:term:{$current->tid}:description", $current->description);
      }
      else {
        $current->title = taxonomy_image_tt("taxonomy:term:{$current->tid}:name", $current->name);
      }

      // Have to dump double quotes for attribute.
      $current->title = htmlspecialchars(strip_tags($current->title), ENT_COMPAT);
      $my_attrs = array(
        'width' => $current->width,
        'height' => $current->height,
        'class' => 'taxonomy-image-term-' . $current->tid . ' taxonomy-image-vid-' . $current->vid,
      );

      // $tag was originally an HTML attribute string. It should now be a standard attributes array.
      // If the caller provided the same key, this will force me to use those.
      if (is_array($tags)) {
        $attributes = array_merge($my_attrs, $tags);
      }
      else {

        // Handle the old string format.
        $attributes = array_merge($my_attrs, taxonomy_image_parse_tags($tags));
      }

      // Handle special image types.
      switch ($current->type_extension) {
        case 'swf':
          $attributes['type'] = $current->mime;
          $attributes['data'] = $current->url;
          $attributes['title'] = $current->title;
          $return_url = '<object ' . drupal_attributes($attributes) . '>Your browser does not support Flash objects.</object>';
          break;
        default:
          if ($preset == 'ORIGINAL') {
            $return_url = theme('image', $current->url, $current->name, $current->title, $attributes, FALSE);
          }
          else {

            // Make sure the attributes don't try to override the preset.
            unset($attributes['width'], $attributes['height']);
            $mypath = variable_get('taxonomy_image_path', 'category_pictures') . '/';
            $return_url = theme('imagecache', $preset, $mypath . $current->path, $current->name, $current->title, $attributes);
          }
      }
      if ($wrapper) {
        $return_url = '<div class="taxonomy_image_wrapper">' . $return_url . '</div>';
      }
      return $return_url;
    }
  }
  return '';
}