? jlightbox.new.patch ? jlightbox.patch ? jlightbox_views.patch Index: jlightbox.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/jlightbox/jlightbox.module,v retrieving revision 1.12 diff -u -p -r1.12 jlightbox.module --- jlightbox.module 2 Aug 2009 01:49:14 -0000 1.12 +++ jlightbox.module 26 Aug 2009 10:53:41 -0000 @@ -13,7 +13,7 @@ */ /** - * Implementation of hook_menu() + * Implementation of hook_menu(). */ function jlightbox_init() { jlightbox_add(); @@ -37,17 +37,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.uncompressed.js'); } @@ -85,74 +85,96 @@ function jlightbox_field_formatter_info( 'field types' => array('image', 'filefield'), ); } - + return $formatters; } /** - * Implementation of hook_field_formatter(). + * Implementation of hook_theme(). + * + * Adds a theme function for each imagecache preset if both imagefield.module + * and imagecache.module exist. */ -function jlightbox_field_formatter($field, $item, $formatter, $node) { +function jlightbox_theme() { + $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 (!module_exists('imagefield') || !module_exists('imagecache')) { return ''; } + $field = content_fields($element['#field_name']); + $item = $element['#item']; + $formatter = $element['#formatter']; if (!isset($item['fid'])) { return ''; } - $file = _imagefield_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')) { + + if (isset($item['nid']) && $node = node_load($item['nid'])) { + $data = array(); + if ($item['data'] && is_array($item['data'])) { + $data = $item['data']; + } + foreach ($data as $key => $value) { + if (!isset($item[$key])) { + $item[$key] = $value; + } + } + $file = field_file_load($item['fid']); + $item = array_merge($item, $file); + if (strpos($formatter, 'jlightbox][') !== FALSE) { + list($module, $namespace, $type) = explode('][', $formatter); + $rules = array(); $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)) { - return theme('imagefield_jlightbox', $namespace, $formatter, $field, $item, $type); - } + if (in_array($namespace, (array)$rules)) { + return theme('imagefield_jlightbox', $namespace, $formatter, $field, $item, $type); + } + } + return jlightbox_field_formatter($field, $item, $formatter, $node); } } /** - * Implementation of hook_theme(). - */ -function jlightbox_theme() { - return array( - 'imagefield_jlightbox' => array( - 'arguments' => array('namespace' => '', 'formatter' => NULL, 'field' => array(), 'item' => array(), 'type' => '', 'attributes' => array()), - ), - ); -} - -/** * Implementation of theme_imagefield_jlightbox(). */ 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']) .']'; + $gallery = '['. str_replace('_', '-', $field['field_name']) .']'; } $link_attributes = array( '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