function theme_imagefield_image_imagecache_lightbox2 in Lightbox2 6
Same name and namespace in other branches
- 5.2 lightbox2.module \theme_imagefield_image_imagecache_lightbox2()
- 5 lightbox2.module \theme_imagefield_image_imagecache_lightbox2()
Generate the HTML output for imagefield + imagecache images so they can be opened in a lightbox by clicking on the image on the node page or in a view.
This actually also handles filefields + imagecache images too.
Parameters
$view_preset: The imagecache preset to be displayed on the node or in the view.
$field_name: The field name the action is being performed on.
$item: An array, keyed by column, of the data stored for this item in this field.
$node: The node object.
$rel: The type of lightbox to open: lightbox, lightshow or lightframe.
$args: Args may override internal processes: caption, rel_grouping.
Return value
The themed imagefield + imagecache image and link.
1 theme call to theme_imagefield_image_imagecache_lightbox2()
- lightbox2_imagefield_image_imagecache in ./
lightbox2.formatter.inc - Function to set up the data needed for theme_imagefield_image_imagecache_lightbox2().
File
- ./
lightbox2.formatter.inc, line 143 - Lightbox2 formatter hooks and callbacks.
Code
function theme_imagefield_image_imagecache_lightbox2($view_preset, $field_name, $item, $node, $rel = 'lightbox', $args = array()) {
if (!isset($args['lightbox_preset'])) {
$args['lightbox_preset'] = 'original';
}
// Can't show current node page in a lightframe on the node page.
// Switch instead to show it in a lightbox.
$on_image_node = arg(0) == 'node' && arg(1) == $node->nid;
if ($rel == 'lightframe' && $on_image_node) {
$rel = 'lightbox';
}
$orig_rel = $rel;
// Unserialize into original - if sourced by views.
$item_data = $item['data'];
if (is_string($item['data'])) {
$item_data = unserialize($item['data']);
}
// Set up the title.
$image_title = $item_data['description'];
$image_title = !empty($image_title) ? $image_title : $item_data['title'];
$image_title = !empty($image_title) ? $image_title : $item_data['alt'];
if (empty($image_title) || variable_get('lightbox2_imagefield_use_node_title', FALSE)) {
$node = node_load($node->nid);
$image_title = $node->title;
}
$image_tag_title = '';
if (!empty($item_data['title'])) {
$image_tag_title = $item_data['title'];
}
// Enforce image alt.
$image_tag_alt = '';
if (!empty($item_data['alt'])) {
$image_tag_alt = $item_data['alt'];
}
elseif (!empty($image_title)) {
$image_tag_alt = $image_title;
}
// Set up the caption.
$node_links = array();
if (!empty($item['nid'])) {
$attributes = array();
$attributes['id'] = 'lightbox2-node-link-text';
$target = variable_get('lightbox2_node_link_target', FALSE);
if (!empty($target)) {
$attributes['target'] = $target;
}
$node_link_text = variable_get('lightbox2_node_link_text', 'View Image Details');
if (!$on_image_node && !empty($node_link_text)) {
$node_links[] = l($node_link_text, 'node/' . $item['nid'], array(
'attributes' => $attributes,
));
}
$download_link_text = check_plain(variable_get('lightbox2_download_link_text', 'Download Original'));
if (!empty($download_link_text) && user_access('download original image')) {
$node_links[] = l($download_link_text, file_create_url($item['filepath']), array(
'attributes' => array(
'target' => '_blank',
'id' => 'lightbox2-download-link-text',
),
));
}
}
$caption = $image_title;
if (count($node_links)) {
$caption .= '<br /><br />' . implode(" - ", $node_links);
}
if (isset($args['caption'])) {
$caption = $args['caption'];
// Override caption.
}
if ($orig_rel == 'lightframe') {
$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);
}
// Set up the rel attribute.
$full_rel = '';
$imagefield_grouping = variable_get('lightbox2_imagefield_group_node_id', 1);
if (isset($args['rel_grouping'])) {
$full_rel = $rel . '[' . $args['rel_grouping'] . '][' . $caption . ']';
}
elseif ($imagefield_grouping == 1) {
$full_rel = $rel . '[' . $field_name . '][' . $caption . ']';
}
elseif ($imagefield_grouping == 2 && !empty($item['nid'])) {
$full_rel = $rel . '[' . $item['nid'] . '][' . $caption . ']';
}
elseif ($imagefield_grouping == 3 && !empty($item['nid'])) {
$full_rel = $rel . '[' . $field_name . '_' . $item['nid'] . '][' . $caption . ']';
}
elseif ($imagefield_grouping == 4) {
$full_rel = $rel . '[allnodes][' . $caption . ']';
}
else {
$full_rel = $rel . '[][' . $caption . ']';
}
$class = '';
if ($view_preset != 'original') {
$class = 'imagecache imagecache-' . $field_name . ' imagecache-' . $view_preset . ' imagecache-' . $field_name . '-' . $view_preset;
}
$link_attributes = array(
'rel' => $full_rel,
'class' => 'imagefield imagefield-lightbox2 imagefield-lightbox2-' . $view_preset . ' imagefield-' . $field_name . ' ' . $class,
);
$attributes = array();
if (isset($args['compact']) && $item['#delta']) {
$image = '';
}
elseif ($view_preset == 'original') {
$image = theme('lightbox2_image', $item['filepath'], $image_tag_alt, $image_tag_title, $attributes);
}
elseif ($view_preset == 'link') {
// Not actually an image, just a text link.
$image = variable_get('lightbox2_view_image_text', 'View image');
}
else {
$image = theme('imagecache', $view_preset, $item['filepath'], $image_tag_alt, $image_tag_title, $attributes);
}
if ($args['lightbox_preset'] == 'node') {
$output = l($image, 'node/' . $node->nid . '/lightbox2', array(
'attributes' => $link_attributes,
'html' => TRUE,
));
}
elseif ($args['lightbox_preset'] == 'original') {
$output = l($image, file_create_url($item['filepath']), array(
'attributes' => $link_attributes,
'html' => TRUE,
));
}
else {
$output = l($image, imagecache_create_url($args['lightbox_preset'], $item['filepath']), array(
'attributes' => $link_attributes,
'html' => TRUE,
));
}
return $output;
}