';
return $image;
}
/**
* Handler for Lightbox2 display of imagecache + imagefield CCK fields.
*
* @param $element
* The CCK field element.
* @return
* HTML output for displaying the image and link.
*/
function theme_lightbox2_formatter_imagefield($element) {
if (!module_exists("imagecache") || !module_exists("imagefield")) {
return;
}
$field_name = $element['#field_name'];
$item = $element['#item'];
$formatter = $element['#formatter'];
$node = node_load($element['#item']['nid']);
if (strpos($formatter, '__lightbox2__') !== FALSE || strpos($formatter, '__lightshow2__') !== FALSE || strpos($formatter, '__lightframe2__') !== FALSE) {
list($tmp, $lightbox_type, $view_preset, $lightbox_preset) = explode('__', $formatter, 4);
return lightbox2_imagefield_image_imagecache($field_name, $item, $formatter, $node, $view_preset, $lightbox_preset);
}
}
/**
* Function to set up the data needed for
* theme_imagefield_image_imagecache_lightbox2().
*
* @param $field_name
* The field name the action is being performed on.
* @param $item
* An array, keyed by column, of the data stored for this item in this field.
* @param $formatter
* The formatter to use for the field.
* @param $node
* The node object.
* @param $view_preset
* The imagecache preset to be displayed on the node or in the view.
* @param $lightbox_preset
* The imagecache preset to be displayed in the lightbox.
* @return
* The themed imagefield + imagecache image and link.
*/
function lightbox2_imagefield_image_imagecache($field_name, $item, $formatter, $node, $view_preset, $lightbox_preset) {
// Load file data if missing
if (!isset($item['filepath']) && !empty($item['fid'])) {
$file = field_file_load($item['fid']);
$item = array_merge($item, (array)$file);
}
elseif (!isset($item['filepath'])) {
// No file in field, return.
return '';
}
$args = array();
$args['lightbox_preset'] = $lightbox_preset;
// Check view_preset for existence.
$rules = array();
if (function_exists('imagecache_presets')) {
$presets = imagecache_presets();
foreach ($presets as $preset_id => $preset_info) {
$rules[$preset_id] = $preset_info['presetname'];
}
}
else {
$rules = _imagecache_get_presets();
}
if ($view_preset == 'original' || in_array($view_preset, (array) $rules)) {
$rel = 'lightbox';
if (strpos($formatter, '__lightshow2__') !== FALSE) {
$rel = 'lightshow';
}
elseif (strpos($formatter, '__lightframe2__') !== FALSE) {
$rel = 'lightframe';
}
return theme('imagefield_image_imagecache_lightbox2', $view_preset, $field_name, $item, $node, $rel, $args);
}
}
/**
* 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.
*
* @param $view_preset
* The imagecache preset to be displayed on the node or in the view.
* @param $field_name
* The field name the action is being performed on.
* @param $item
* An array, keyed by column, of the data stored for this item in this field.
* @param $node
* The node object.
* @param $rel
* The type of lightbox to open: lightbox, lightshow or lightframe.
* @param $args
* Args may override internal processes: caption, rel_grouping.
* @return
* The themed imagefield + imagecache image and link.
*/
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.
if ($rel == 'lightframe' && arg(0) == 'node' && arg(1) == $node->nid) {
$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']);
$image_tag_title = '';
if (!empty($item_data['title'])) {
$image_tag_title = $item_data['title'];
}
if (variable_get('lightbox2_imagefield_use_node_title', FALSE)) {
$node = node_load($node->nid);
$image_title = $node->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'] = '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 (!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') && user_access('view imagefield uploads')) {
$node_links[] = l($download_link_text, $item['filepath'], array('attributes' => array('target' => '_blank', 'id' => 'download_link_text')));
}
}
$caption = $image_title;
if (count($node_links)) {
$caption .= '
'. 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 ($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 (isset($args['rel_grouping'])) {
$full_rel = $rel .'['. $args['rel_grouping'] .']['. $caption .']';
}
else {
$full_rel = $rel .'[]['. $caption .']';
}
$link_attributes = array(
'rel' => $full_rel,
);
$attributes = array();
if ($view_preset == 'original') {
$image = theme('lightbox2_image', $item['filepath'], $image_tag_alt, $image_tag_title, $attributes);
}
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;
}
/**
* Theme function for the lightbox iframe filefield formatter.
*
* @param $element
* The CCK field element.
* @return
* The themed link to the file, with lightframe support.
*/
function theme_lightbox2_formatter_filefield_lightframe($element) {
$file = $element['#item'];
$field = content_fields($element['#field_name']);
if (!filefield_view_access($field['field_name']) || empty($file['list'])) {
return '';
}
if (empty($file['fid']) || !is_file($file['filepath'])) {
return '';
}
$file = (object)$file;
if (!lightbox2_check_filefield_extension($file, $field)) {
return '';
}
drupal_add_css(drupal_get_path('module', 'filefield') .'/filefield.css');
return '