I think that it is really easy to integrate lightbox V2 with CCK, and the image field, using the formatters provided by cck and image field.
I'll paste here the code (added to the lightbox2.module file) that I'm using, it is modify from the thickbox module:
/**
* Implementation of hook_field_formatter_info().
* Adds certain thickbox+imagecache formatters to CCK image fields if imagefield.module and imagecache.module exist.
*/
function lightbox2_field_formatter_info() {
$formatter = array();
if (module_exists('imagefield') && module_exists('imagecache')) {
$rules = _imagecache_get_presets();
foreach ($rules as $ruleid => $rulename) {
$formatters['lightbox2]['. $rulename] = array(
'label' => 'Lightbox2: '. $rulename,
'field types' => array('image'),
);
}
}
return $formatters;
}
/**
* Implementation of hook_field_formatter().
*/
function lightbox2_field_formatter($field, $item, $formatter) {
if (module_exists('imagefield') && module_exists('imagecache')) {
if (!isset($item['fid'])) {
return '';
}
$file = _imagefield_file_load($item['fid']);
if (strpos($formatter, 'lightbox2][') !== false) {
list($null, $namespace) = explode('][', $formatter, 2);
$rules = _imagecache_get_presets();
if (in_array($namespace, (array) $rules)) {
return theme('imagefield_image_imagecache_lightbox2', $namespace, $field, $file['filepath'], $item['alt'], $item['title']);
}
}
}
}
/**
* Implementation of theme_imagefield_image_imagecache_thickbox().
*/
function theme_imagefield_image_imagecache_lightbox2($namespace, $field, $path, $alt = '', $title = '', $attributes = NULL) {
global $user;
$attributes = drupal_attributes($attributes);
$imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
return
'<a href="'. check_url(file_create_url($path)) .' "rel="lightbox['. check_plain($user-uid).'] ' .'"><img src="'. check_url($imagecache_path) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' /></a>';
}
The modification that i made, was in the function (or method, or message, i'm from the Smalltalk world, so i do not know how the messages are named here) theme_imagefield_image_imagecache_lightbox2, to add the node id to the rel tag:
"rel="lightbox['. check_plain($user-uid).'] '
This is to enable the gallery view.
I'm using in this in my site, www.fileando.com, of course i think that this can be improved, for example, letting the user specify another pattern to add images to a gallery, i mean, it would be nice to avoid the "rel="lightbox['. check_plain($user-uid).'] ' , and make it as the user specify in the module administration.
Thanks for everythink (I can't say anything else),
Claudio.
Comments
Comment #1
stella commentedI've added this to the lightbox2 module in CVS, along with some modifications to show the image title and provide a link to the node in the lightbox. It will be included in the next release.
Thanks for the patch!
Cheers,
Stella
Comment #2
stella commentedShould be available in lightbox2 5.x-1.1.
Cheers,
Stella
Comment #3
cacciaresi commentedNo! please! Thanks Drupal and Drupal communities for being here!!!
One question, did you modify the module so that can be configured the parameter to define the grouping of images?
I mean, is now configurable this?
rel=lightbo[someString]....
someString could be de user_id, the node_id, etc...
Regards,
Claudio.
-** www.fileando.com **-
Comment #4
stella commentedNo, all I did in respect of grouping was to make it controlled by the "Enable Grouping" setting on the lightbox2 settings page, i.e. so you can turn the grouping on and off. I wasn't sure how people would best want to handle different groups - I've no idea what could be viewed as a group, it would depend on their custom view. If this is something people want, it should be raised as a separate issue because it may also affect how the grouping works in the image galleries - though that is handled by javascript and would be more difficult in to implement.
It's also available for drupal 4.7 from CVS, and will be included in the next release of that.
Cheers,
Stella
Comment #5
stella commented