You are here

function theme_lightbox2_image_ncck in Lightbox2 5.2

Generate the HTML output to open embedded cck images in a lightbox.

Parameters

$field: The field the action is being performed on.

$item: An array, keyed by column, of the data stored for this item in this field.

$formatter: The formatter to use for the field.

$node: The node object.

$options: Array of options available. Not used in this theme function but required by the invoked emfield function.

File

./lightbox2.module, line 2046
Enables the use of lightbox2 which places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths.

Code

function theme_lightbox2_image_ncck($field, $item, $formatter, $node, $options = array()) {
  if ($item['value'] && $item['provider']) {
    $rel = 'lightbox';
    if ($field['lightbox_type'] == 'lightshow2') {
      $rel = 'lightshow';
    }
    elseif ($field['lightbox_type'] == 'lightframe2') {
      $rel = 'lightframe';
    }
    if ($rel == 'lightframe' && arg(0) == 'node' && arg(1) == $node->nid) {
      $rel = 'lightbox';
    }
    $orig_rel = $rel;
    $code = $item['value'];
    $width = $field['widget']['thumbnail_width'] == '' ? variable_get('image_ncck_default_full_width', IMAGE_NCCK_DEFAULT_FULL_WIDTH) : $field['widget']['thumbnail_width'];
    $height = $field['widget']['thumbnail_height'] == '' ? variable_get('image_ncck_default_full_height', IMAGE_NCCK_DEFAULT_FULL_HEIGHT) : $field['widget']['thumbnail_height'];
    $link = $field['widget']['thumbnail_link'] ? $field['widget']['thumbnail_link'] : variable_get('image_ncck_default_thumbnail_link', IMAGE_NCCK_DEFAULT_THUMBNAIL_LINK);
    if ($link == IMAGE_NCCK_LINK_CONTENT) {
      $link = 'node/' . $node->nid;
    }
    elseif ($link == IMAGE_NCCK_LINK_PROVIDER) {
      $link = module_invoke('emfield', 'include_invoke', 'image_ncck', $item['provider'], 'embedded_link', $code, $item['data']);
    }
    else {
      $link = NULL;
    }
    $attributes = array();
    if ($width) {
      $attributes['width'] = $width;
    }
    if ($height) {
      $attributes['height'] = $height;
    }
    $target = variable_get('lightbox2_node_link_target', FALSE);
    if (!empty($target)) {
      $attributes['target'] = $target;
    }

    // Set up caption.
    $node_link_text = variable_get('lightbox2_node_link_text', 'View Image Details');
    if (!empty($node_link_text) && !empty($link)) {
      $node_link = '<br /><br />' . l($node_link_text, $link, $attributes);
    }
    $title = module_invoke('emfield', 'include_invoke', 'image_ncck', $item['provider'], 'image_title', $code, $item['data']);
    $caption = $title . $node_link;

    // Set up url and image.
    $url = module_invoke('emfield', 'include_invoke', 'image_ncck', $item['provider'], 'image_url', $code, $width, $height, $formatter, $field, $item, $node);
    $image = theme('image', $url, $title, $title, $attributes, FALSE);

    // Set up rel attribute.
    $image_grouping = variable_get('lightbox2_image_ncck_group_node_id', 1);
    if ($image_grouping == 1) {
      $rel = $rel . '[' . $field['field_name'] . '][' . $caption . ']';
    }
    elseif ($image_grouping == 2 && !empty($node->nid)) {
      $rel = $rel . '[' . $node->nid . '][' . $caption . ']';
    }
    elseif ($image_grouping == 3 && !empty($node->nid)) {
      $rel = $rel . '[' . $field['field_name'] . $node->nid . '][' . $caption . ']';
    }
    else {
      $rel = $rel . '[][' . $caption . ']';
    }
    if ($orig_rel != 'lightframe') {
      $link_attributes = array(
        'rel' => $rel,
      );
      $full_width = $field['widget']['full_width'] == '' ? variable_get('image_ncck_default_full_width', IMAGE_NCCK_DEFAULT_FULL_WIDTH) : $field['widget']['full_width'];
      $full_height = $field['widget']['full_height'] == '' ? variable_get('image_ncck_default_full_height', IMAGE_NCCK_DEFAULT_FULL_HEIGHT) : $field['widget']['full_height'];
      $full_image_url = module_invoke('emfield', 'include_invoke', 'image_ncck', $item['provider'], 'image_url', $code, $full_width, $full_height, $formatter, $field, $item, $node);
      $output = l($image, $full_image_url, $link_attributes, NULL, NULL, FALSE, TRUE);
    }
    else {
      $frame_width = variable_get('lightbox2_default_frame_width', 600);
      $frame_height = variable_get('lightbox2_default_frame_height', 400);
      $frame_size = 'width:' . $frame_width . 'px; height:' . $frame_height . 'px;';
      $rel = preg_replace('/\\]\\[/', "|{$frame_size}][", $rel);
      $link_attributes = array(
        'rel' => $rel,
      );
      $output = l($image, $link . '/lightbox2', $link_attributes, NULL, NULL, FALSE, TRUE);
    }
  }
  return $output;
}