Index: jlightbox.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/jlightbox/jlightbox.module,v retrieving revision 1.9 diff -u -p -r1.9 jlightbox.module --- jlightbox.module 15 Oct 2008 08:14:30 -0000 1.9 +++ jlightbox.module 26 Feb 2009 16:57:54 -0000 @@ -51,17 +51,36 @@ function jlightbox_add() { } /** - * Implementation of hook_field_formatter_info(). - * - * Adds a field formatter for CCK image field if both imagefield.module and - * imagecache.module exist. + * Implementation of hook_theme(). */ -function jlightbox_field_formatter_info() { - $formatters = array(); - if (!module_exists('imagefield') || !module_exists('imagecache')) { - return $formatters; +function jlightbox_theme() { + $presets = _jlightbox_get_presets(); + foreach ($presets as $name) { + $theme['jlightbox_formatter_jlightbox]['. $name .'][gallery'] = array( + 'arguments' => array('element' => NULL), + 'function' => 'theme_jlightbox_formatter', + ); + $theme['jlightbox_formatter_jlightbox]['. $name .'][single'] = array( + 'arguments' => array('element' => NULL), + 'function' => 'theme_jlightbox_formatter', + ); } + $theme['imagefield_jlightbox'] = array( + 'arguments' => array('namespace' => '', 'formatter' => NULL, 'field' => array(), 'item' => array(), 'type' => '', 'attributes' => array()), + ); + + return $theme; +} + +/** + * Retrieve ImageCache preset names. + */ +function _jlightbox_get_presets() { $rules = array(); + if (!module_exists('imagecache')) { + return $rules; + } + // ImageCache v2 API. if (function_exists('imagecache_presets')) { $presets = imagecache_presets(); @@ -73,13 +92,28 @@ function jlightbox_field_formatter_info( else { $rules = _imagecache_get_presets(); } - foreach ($rules as $ruleid => $rulename) { - $formatters['jlightbox]['. $rulename .'][gallery'] = array( - 'label' => 'jLightbox: '. $rulename .' gallery', + return $rules; +} + +/** + * Implementation of hook_field_formatter_info(). + * + * Adds a field formatter for CCK image field if both imagefield.module and + * imagecache.module exist. + */ +function jlightbox_field_formatter_info() { + $formatters = array(); + if (!module_exists('imagefield') || !module_exists('imagecache')) { + return $formatters; + } + $presets = _jlightbox_get_presets(); + foreach ($presets as $name) { + $formatters['jlightbox]['. $name .'][gallery'] = array( + 'label' => 'jLightbox: '. $name .' gallery', 'field types' => array('image'), ); - $formatters['jlightbox]['. $rulename .'][single'] = array( - 'label' => 'jLightbox: '. $rulename, + $formatters['jlightbox]['. $name .'][single'] = array( + 'label' => 'jLightbox: '. $name, 'field types' => array('image'), ); } @@ -97,37 +131,24 @@ function jlightbox_field_formatter($fiel 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); - $rules = array(); - // ImageCache v2 API. - if (function_exists('imagecache_presets')) { - $presets = imagecache_presets(); - foreach ($presets as $preset_id => $preset_info) { - $rules[$preset_id] = $preset_info['presetname']; - } - } - // ImageCache v1 API (deprecated). - else { - $rules = _imagecache_get_presets(); - } - if (in_array($namespace, (array)$rules)) { + $presets = _jlightbox_get_presets(); + if (in_array($namespace, (array)$presets)) { return theme('imagefield_jlightbox', $namespace, $formatter, $field, $item, $type); } } } /** - * Implementation of hook_theme(). + * Implementation of theme_jlightbox_formatter(). */ -function jlightbox_theme() { - return array( - 'imagefield_jlightbox' => array( - 'arguments' => array('namespace' => '', 'formatter' => NULL, 'field' => array(), 'item' => array(), 'type' => '', 'attributes' => array()), - ), - ); +function theme_jlightbox_formatter($element) { + if (isset($element['#item']['nid']) && $node = node_load($element['#item']['nid'])) { + return jlightbox_field_formatter($element['#field_name'], $element['#item'], $element['#formatter'], $node); + } } /**