You are here

function taxonomy_image_display in Taxonomy Image 5

Same name and namespace in other branches
  1. 6 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()

9 calls to taxonomy_image_display()
taxonomy_image_block in contributed/taxonomy_image_blocks/taxonomy_image_blocks.module
Implementation of hook_block().
taxonomy_image_form_alter in ./taxonomy_image.module
taxonomy_image_handler_arg_taximg in ./taxonomy_image.module
taxonomy_image_handler_field_allterms in ./taxonomy_image.module
Display all the terms for a given vocabulary
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

... See full list

File

./taxonomy_image.module, line 25
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.
      if ($current->description && !variable_get('taxonomy_image_link_title', 0)) {
        $current->title = strip_tags($current->description);
      }
      else {
        $current->title = strip_tags($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,
      );

      // $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']);
            $return_url = theme('imagecache', $preset, $current->path, $current->name, $current->title, $attributes);
          }
      }
      if ($wrapper) {
        $return_url = '<div class="taxonomy_image_wrapper">' . $return_url . '</div>';
      }
      return $return_url;
    }
  }
  return '';
}