You are here

function theme_img_assist_inline in Image Assist 5.2

Same name and namespace in other branches
  1. 5.3 img_assist.module \theme_img_assist_inline()
  2. 5 img_assist.module \theme_img_assist_inline()
  3. 6.2 img_assist.module \theme_img_assist_inline()
  4. 6 img_assist.module \theme_img_assist_inline()

Related topics

1 theme call to theme_img_assist_inline()
img_assist_render_image in ./img_assist.module
Return image HTML.

File

./img_assist.module, line 1723
Image Assist module

Code

function theme_img_assist_inline($node, $size, $attributes) {
  $caption = '';
  if ($attributes['title'] && $attributes['desc']) {
    $caption = '<strong>' . $attributes['title'] . ': </strong>' . $attributes['desc'];
  }
  elseif ($attributes['title']) {
    $caption = '<strong>' . $attributes['title'] . '</strong>';
  }
  elseif ($attributes['desc']) {
    $caption = $attributes['desc'];
  }

  // Change the node title because img_assist_display() uses the node title for
  // alt and title.
  $node->title = strip_tags($caption);
  $img_tag = img_assist_display($node, $size);

  // Always define an alignment class, even if it is 'none'.
  $output = '<span class="inline inline-' . $attributes['align'] . '">';
  $link = $attributes['link'];
  $url = '';

  // Backwards compatibility: Also parse link/url in the format link=url,foo.
  if (strpos($link, ',') !== FALSE) {
    list($link, $url) = explode(',', $link, 2);
  }
  elseif (isset($attributes['url'])) {
    $url = $attributes['url'];
  }
  if ($link == 'node') {
    $output .= l($img_tag, 'node/' . $node->nid, array(), NULL, NULL, FALSE, TRUE);
  }
  elseif ($link == 'popup') {
    $popup_size = variable_get('img_assist_popup_label', IMAGE_PREVIEW);
    $info = image_get_info(file_create_path($node->images[$popup_size]));
    $width = $info['width'];
    $height = $info['height'];
    $popup_url = file_create_url($node->images[variable_get('img_assist_popup_label', IMAGE_PREVIEW)]);
    $output .= l($img_tag, $popup_url, array(
      'onclick' => "launch_popup({$node->nid}, {$width}, {$height}); return false;",
      'target' => '_blank',
    ), NULL, NULL, FALSE, TRUE);
  }
  elseif ($link == 'url') {
    $output .= l($img_tag, $url, array(), NULL, NULL, FALSE, TRUE);
  }
  else {
    $output .= $img_tag;
  }
  if ($caption) {
    if ($attributes['align'] != 'center') {
      $info = image_get_info(file_create_path($node->images[$size['key']]));

      // Reduce the caption width slightly so the variable width of the text
      // doesn't ever exceed image width.
      $width = $info['width'] - 2;
      $output .= '<span class="caption" style="width: ' . $width . 'px;">' . $caption . '</span>';
    }
    else {
      $output .= '<span class="caption">' . $caption . '</span>';
    }
  }
  $output .= '</span>';
  return $output;
}