Index: jlightbox.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/jlightbox/jlightbox.module,v
retrieving revision 1.11
diff -u -p -r1.11 jlightbox.module
--- jlightbox.module	6 May 2009 23:57:17 -0000	1.11
+++ jlightbox.module	27 May 2009 15:07:17 -0000
@@ -13,7 +13,7 @@
  */
 
 /**
- * Implementation of hook_menu()
+ * Implementation of hook_menu().
  */
 function jlightbox_init() {
   jlightbox_add();
@@ -24,7 +24,7 @@ function jlightbox_init() {
  */
 function jlightbox_add() {
   $path = drupal_get_path('module', 'jlightbox');
-  
+
   // Theme-specific stylesheet override support.
   // #178364: path_to_theme() invokes init_theme(), thus it must not be invoked
   // in block settings to allow initializing of the selected theme. Likewise,
@@ -36,17 +36,17 @@ function jlightbox_add() {
     }
     drupal_add_css($css, 'module', 'screen');
   }
-  
+
   // Image / Image Assist support.
   if (module_exists('image') && module_exists('img_assist')) {
     drupal_add_js($path .'/js/jlightbox_image.js');
   }
-  
+
   // Inline support.
   if (module_exists('inline')) {
     drupal_add_js($path .'/js/jlightbox_inline.js');
   }
-  
+
   // jLightbox needs to be loaded last.
   drupal_add_js($path .'/js/jlightbox.js');
 }
@@ -84,21 +84,24 @@ function jlightbox_field_formatter_info(
       'field types' => array('image', 'filefield'),
     );
   }
-  
+
   return $formatters;
 }
 
 /**
  * Implementation of hook_field_formatter().
+ *
+ * This hook is now deprecated and must be called from a theme function.
  */
 function jlightbox_field_formatter($field, $item, $formatter, $node) {
+
   if (!module_exists('imagefield') || !module_exists('imagecache')) {
     return '';
   }
   if (!isset($item['fid'])) {
     return '';
   }
-  $file = _imagefield_file_load($item['fid']);
+  $file = field_file_load($item['fid']);
   $item = array_merge($item, $file);
   if (strpos($formatter, 'jlightbox][') !== FALSE) {
     list($module, $namespace, $type) = explode('][', $formatter);
@@ -122,13 +125,46 @@ function jlightbox_field_formatter($fiel
 
 /**
  * Implementation of hook_theme().
+ *
+ * Adds a theme function for each imagecache preset if both imagefield.module
+ * and imagecache.module exist.
  */
 function jlightbox_theme() {
-  return array(
+  $theme = array(
     'imagefield_jlightbox' => array(
       'arguments' => array('namespace' => '', 'formatter' => NULL, 'field' => array(), 'item' => array(), 'type' => '', 'attributes' => array()),
     ),
   );
+  if (module_exists('imagefield') && module_exists('imagecache')) {
+    $presets = imagecache_presets();
+    foreach ($presets as $preset_id => $preset_info) {
+      $theme['jlightbox_formatter_'.'jlightbox]['. $preset_info['presetname'] .'][single'] = array(
+        'arguments' => array('element' => NULL),
+        'function' => 'theme_jlightbox_formatter',
+      );
+      $theme['jlightbox_formatter_'.'jlightbox]['. $preset_info['presetname'] .'][gallery'] = array(
+        'arguments' => array('element' => NULL),
+        'function' => 'theme_jlightbox_formatter',
+      );
+    }
+  }
+
+  return $theme;
+}
+
+function theme_jlightbox_formatter($element) {
+  if (isset($element['#item']['nid']) && $node = node_load($element['#item']['nid'])) {
+    $data = array();
+    if ($element['#item']['data'] && is_array($element['#item']['data'])) {
+      $data = $element['#item']['data'];
+    }
+    foreach ($data as $key => $value) {
+      if (!isset($element['#item'][$key])) {
+        $element['#item'][$key] = $value;
+      }
+    }
+    return jlightbox_field_formatter($element['#field_name'], $element['#item'], $element['#formatter'], $node);
+  }
 }
 
 /**
@@ -137,10 +173,10 @@ function jlightbox_theme() {
 function theme_imagefield_jlightbox($namespace, $formatter, $field, $item, $type, $attributes = array()) {
   $attributes['class'] = 'image '. $namespace;
   $gallery = '';
-  
+
   $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $item['filepath']);
   $image = theme('imagecache', $namespace, $item['filepath'], $item['alt'], $item['title'], $attributes);
-  
+
   if ($type == 'gallery') {
     $gallery = '['. form_clean_id($field['field_name']) .']';
   }
@@ -148,10 +184,8 @@ function theme_imagefield_jlightbox($nam
     'rel' => 'lightbox'. $gallery,
     'title' => ($item['alt'] != $item['filename']) ? $item['alt'] : $item['title'],
   );
-  
-  $output = l($image, file_create_url($item['filepath']), array('attributes' => $link_attributes, 'absolute' => FALSE, 'html' => TRUE));
-  
-  return $output;
-}
 
+  $output = l($image, file_create_url($item['filepath']), array('attributes' => $link_attributes, 'absolute' => FALSE, 'html' => TRUE));
 
+  return $output;
+}
\ No newline at end of file
