You are here

function theme_colorbox_formatter_imagefield in Colorbox 6

Handler for Colorbox display of imagecache + imagefield CCK fields.

Parameters

$element: The CCK field element.

Return value

HTML output for displaying the image and link.

1 string reference to 'theme_colorbox_formatter_imagefield'
colorbox_theme in ./colorbox.module
Implementation of hook_theme().

File

./colorbox.theme.inc, line 17
Colorbox theme functions.

Code

function theme_colorbox_formatter_imagefield($element) {
  if (!module_exists('imagecache') || !module_exists('imagefield')) {
    return;
  }
  if (!empty($element['#item']['fid'])) {
    $item = $element['#item'];
    if (is_string($item['data'])) {
      $item['data'] = unserialize($item['data']);
    }
    if (!isset($item['filepath'])) {
      $file = field_file_load($item['fid']);
      $item['filepath'] = $file['filepath'];
    }

    // If the title is empty use description, alt or the node title in that order.
    if (empty($item['data']['title'])) {
      if (!empty($item['data']['description'])) {
        $item['data']['title'] = $item['data']['description'];
      }
      elseif (!empty($item['data']['alt'])) {
        $item['data']['title'] = $item['data']['alt'];
      }
      elseif (is_numeric($item['nid']) && ($node = node_load($item['nid']))) {
        $item['data']['title'] = $node->title;
      }
    }

    // Shorten the title for the example styles or when title shortening is active.
    $style = variable_get('colorbox_style', 'default');
    $trim_length = variable_get('colorbox_title_trim_length', 75);
    if ((strpos($style, 'colorbox/example') !== FALSE || variable_get('colorbox_title_trim', 0)) && drupal_strlen($item['data']['title']) > $trim_length) {
      $item['data']['title'] = drupal_substr($item['data']['title'], 0, $trim_length - 5) . '...';
    }

    // Build the gallery id.
    $nid = $item['nid'] ? $item['nid'] : 'nid';
    switch (variable_get('colorbox_imagefield_gallery', 1)) {
      case 0:
        $gallery_id = 'all';
        break;
      case 1:
        $gallery_id = $nid;
        break;
      case 2:
        $gallery_id = $nid . '-' . $element['#field_name'];
        break;
      case 3:
        $gallery_id = $nid . '-' . $item['fid'];
        break;
    }
    list($presetname, $modulename) = explode('__', $element['#formatter'], 2);
    if ($preset = imagecache_preset_by_name($presetname)) {
      return theme('colorbox_imagefield', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title'], $gallery_id, $element['#field_name']);
    }
  }
}