7 * Enables the use of lightbox2 which places images above your current page,
8 * not within. This frees you from the constraints of the layout, particularly
11 * This module is for Drupal 5.x only.
13 * Module by: Mark Ashmead
14 * Mailto: bugzie@gmail.com
15 * Co-maintainer: Stella Power (http://drupal.org/user/66894)
17 * Image Node Support: Steve McKenzie
22 * Implementation of hook_help().
24 function lightbox2_help($section) {
26 case
'admin/modules#description':
27 return t('Enables Lightbox2 for Drupal');
29 case
'admin/help#lightbox2':
30 return t('<h3>Overview</h3>
31 <p align="justify">Lightbox2 JS is a simple, unobtrusive script used to overlay images on the current page. It\'s a snap to setup and works on all modern browsers. The module comes with a Lightbox2 Lite option which does not use the jQuery libraries; it is therefore less likely to conflict with anything else.</p>
32 <p align="justify">Places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths. Keeps users on the same page. Clicking to view an image and then having to click the back button to return to your site is bad for continuity (and no fun!).</p>
34 The version 2 module has several benefits over the plain Lightbox module. Note, not all of these features are available when the "Lightbox2 Lite" option is enabled.
36 <li>Image Sets: group related images and navigate through them with ease - ideal for your image galleries.</li>
37 <li>Slideshow Capability: automatically transition between grouped images, includes play/pause and previous and next buttons.</li>
38 <li>HTML Content Support: ability to show websites or other HTML content in a lightbox.</li>
39 <li>Visual Effects: fancy pre-loader and transition when you click on the image.</li>
40 <li>Keyboard Shortcuts: useful <a href="http://drupal.org/node/249827">keyboard shortcuts</a> for switching between images, toggling play / pause, etc.</li>
41 <li>Zoom Capability: larger images are reduced in size so they fit snugly inside the browser window. A zoom button can then be clicked on to see it in its original size.</li>
42 <li>Automatic Image Detection: configurable automatic re-formatting of
43 image thumbnails, so there is no need to add \'rel="lightbox"\' to each
44 image link on your site. <a
45 href="http://drupal.org/project/image">Image</a>, <a
46 href="http://drupal.org/project/inline">Inline</a>, <a
47 href="http://drupal.org/project/flickr">Flickr</a>, <a
48 href="http://drupal.org/project/img_assist">Image Assist</a> and <a
49 href="http://drupal.org/project/imagefield">CCK Imagefield</a> modules are all
50 supported. It\'s also possible to configure a custom list of image classes
51 which should trigger the lightbox functionality.</li>
52 <li><a href="http://drupal.org/project/imagecache">Imagecache</a> Support: adds a Lightbox2 field formatter for <a href="http://drupal.org/project/imagefield">CCK imagefields</a> for your custom <a href="http://drupal.org/project/views">views</a>.</li>
53 <li>Image Page Link: a link to the image node can be provided within the lightbox itself.</li>
54 <li>Page Exclusion Capability: exclude certain pages on your site from having the lightbox2 functionality.</li>
55 <li>Gallery 2 Support: support for Gallery 2 images via the <a href="http://drupal.org/project/gallery">Gallery</a> module (beta).</li>
57 <p align="justify"><h3>Usage</h3></p>
58 <h5 style="text-decoration: underline;">Adding a Basic Lightbox</h5>
59 <p>Add rel="lightbox" attribute to any link tag to activate the lightbox. For example: </p>
60 <p><a href="image-1.jpg" rel="lightbox" title="my caption">image #1</a></p>
61 <p>Optional: Use the title attribute if you want to show a caption.</p>
62 <h5 style="text-decoration: underline;">Grouping Images</h5>
63 <p>If you have a set of related images that you would like to group, follow
64 step one but additionally include a group name between square brackets in the
65 rel attribute. For example:</p><p><a href="images/image-1.jpg"
66 rel="lightbox[roadtrip]">image #1</a><br />
67 <a href="images/image-2.jpg" rel="lightbox[roadtrip]">image
69 <a href="images/image-3.jpg" rel="lightbox[roadtrip]">image
70 #3</a><br /></p>
71 <p>No limits to the number of image sets per page or how many images are allowed
74 <p>If you have a set of images that you would like to group together in a lightbox, but only wish for one of these images to be visible on your page, you can assign the "lightbox_hide_image" class to hide the additional images. For example:</p>
76 <p><a href="images/image-1.jpg" rel="lightbox[roadtrip]">image #1</a><br />
77 <a href="images/image-2.jpg" rel="lightbox[roadtrip]" class="lightbox_hide_image">image #2</a><br />
78 <a href="images/image-3.jpg" rel="lightbox[roadtrip]" class="lightbox_hide_image">image #3</a></p>
80 <h5 style="text-decoration: underline;">Slideshow</h5>
81 <p>This is very similar to the grouping functionality described above. The only difference is that "rel" attribute should be set to "lightshow" instead of "lightbox". Using the same example as above, we could launch the images in a slideshow by doing:</p>
83 <p><a href="images/image-1.jpg" rel="lightshow[roadtrip]">image #1</a><br />
84 <a href="images/image-2.jpg" rel="lightshow[roadtrip]">image #2</a><br />
85 <a href="images/image-3.jpg" rel="lightshow[roadtrip]">image #3</a></p>
87 <h3>Keyboard Shortcuts</h3>
89 <tr><td>Close Lightbox</td><td>x</td></tr>
90 <tr><td></td><td>o</td></tr>
91 <tr><td></td><td>c</td></tr>
92 <tr><td></td><td>ESC</td></tr>
94 <tr><td>Previous Image</td><td>p</td></tr>
95 <tr><td></td><td>Left Arrow</td></tr>
97 <tr><td>Next Image</td><td>n</td></tr>
98 <tr><td></td><td>Right Arrow</td></tr>
100 <tr><td>Toggle Zoom</td><td>z (not available in slideshow)</td></tr>
102 <tr><td>Toggle Play / Pause</td><td>Spacebar (slideshow only)</td></tr>
105 <p>Not all of the keyboard shortcuts work in the Opera browser, for example "z" for toggling the zoom and "spacebar" for toggling play / pause in slideshows. This can be overcome by updating your shortcut settings in the Opera preferences editor.</p>
113 * Implementation of hook_perm().
115 function lightbox2_perm() {
116 return array('administer lightbox2');
120 * Implementation of hook_menu().
122 function lightbox2_menu($may_cache) {
126 $items[] = array('path' => 'admin/settings/lightbox2',
127 'title' => t('Lightbox2'),
128 'callback' => 'lightbox2_settings_page',
129 'access' => user_access('administer lightbox2'),
130 'description' => t('Allows the user to configure the lightbox2 settings'),
132 $items[] = array('path' => 'admin/settings/lightbox2/general',
133 'title' => t('General'),
134 'callback' => 'drupal_get_form',
135 'callback arguments' => array('lightbox2_general_settings_form'),
136 'access' => user_access('administer lightbox2'),
137 'description' => t('Allows the user to configure the lightbox2 settings'),
138 'type' => MENU_DEFAULT_LOCAL_TASK
,
141 $items[] = array('path' => 'admin/settings/lightbox2/slideshow',
142 'title' => t('Slideshow'),
143 'callback' => 'drupal_get_form',
144 'callback arguments' => array('lightbox2_slideshow_settings_form'),
145 'access' => user_access('administer lightbox2'),
146 'description' => t('Allows the user to configure the lightbox2 slideshow functionality.'),
147 'type' => MENU_LOCAL_TASK
,
150 $items[] = array('path' => 'admin/settings/lightbox2/automatic',
151 'title' => t('Automatic image handling'),
152 'callback' => 'drupal_get_form',
153 'callback arguments' => array('lightbox2_auto_image_handling_settings_form'),
154 'access' => user_access('administer lightbox2'),
155 'description' => t('Allows the user to configure the lightbox2 automatic image handling settings'),
156 'type' => MENU_LOCAL_TASK
,
161 if (lightbox2_exclude_these_paths() != 1) {
162 lightbox2_add_files();
171 * The default lightbox2 settings page.
173 function lightbox2_settings_page($op = NULL
) {
174 $output .
= drupal_get_form('lightbox2_general_settings_form');
179 * General configuration form for controlling the lightbox behaviour.
181 function lightbox2_general_settings_form() {
183 // Add the javascript which disables / enables form elements.
184 drupal_add_js(drupal_get_path('module', 'lightbox2') .
'/js/lightbox2.js', 'module');
186 // Enable translation of default strings for potx.
187 $default_strings = array(t('View Image Details'), t('Image !current of !total'));
189 // Define Lightbox2 Lite fieldset.
190 /* ------------------------------- */
191 $use_lite = variable_get('lightbox2_lite', FALSE
);
192 $form['lightbox2_lite_options'] = array(
193 '#type' => 'fieldset',
194 '#title' => t('Lightbox2 Lite'),
195 '#collapsible' => TRUE
,
196 '#collapsed' => !$use_lite,
199 // Add checkbox for Lightbox2 Lite.
200 $form['lightbox2_lite_options']['lightbox2_lite'] = array(
201 '#type' => 'checkbox',
202 '#title' => t('Use Lightbox2 Lite'),
203 '#description' => t('Checking this box will enable Lightbox2 Lite and will disable all of the automatic image URL re-formatting features. It also disables all grouping features.'),
204 '#default_value' => $use_lite,
208 // Add checkbox for alternative layout.
209 $form['lightbox2_use_alt_layout'] = array(
210 '#type' => 'checkbox',
211 '#title' => t('Use Alternative Layout'),
212 '#description' => t('Enabling this option alters the layout of the lightbox elements. This doesn\'t apply when using Lightbox Lite.'),
213 '#default_value' => variable_get('lightbox2_use_alt_layout', FALSE
),
216 // Add checkbox for force navigation display.
217 $form['lightbox2_force_show_nav'] = array(
218 '#type' => 'checkbox',
219 '#title' => t('Force visibility of navigation links'),
220 '#description' => t('When viewing grouped images using the default layout, the navigational links to the next and previous images are only displayed when you hover over the image. Checking this box forces these links to be displayed all the time.'),
221 '#default_value' => variable_get('lightbox2_force_show_nav', FALSE
),
224 // Add text box for image count for grouping.
225 $form['lightbox2_image_count_str'] = array(
226 '#type' => 'textfield',
227 '#title' => t('Image Count Text'),
228 '#description' => t('This text is used to display the image count underneath the image in the lightbox when image grouping is enabled. Use !current as a placeholder for the number of the current image and !total for the total number of images in the group. For example, "Image !current of !total".'),
229 '#default_value' => variable_get('lightbox2_image_count_str', 'Image !current of !total'),
232 // Add checkbox for zoom image.
233 $form['lightbox2_disable_zoom'] = array(
234 '#type' => 'checkbox',
235 '#title' => t('Disable Zoom Feature'),
236 '#description' => t('By default, when the image being displayed in the lightbox is larger than the browser window, it is resized to fit within the window and a zoom button is provided for users who wish to view the image in its original size. Checking this box will disable this feature and all images will be displayed without any resizing.'),
237 '#default_value' => variable_get('lightbox2_disable_zoom', FALSE
),
240 // Add textarea for urls without lightbox.
241 $form['lightbox2_disable_these_urls'] = array(
242 '#type' => 'textarea',
243 '#title' => t('Disable LightBox for these urls'),
244 '#description' => t('List the urls where the lightbox should be disabled, e.g. "node/add/page". Use <front> to match the front page. Put each url on a separate line. You can use the % character as a wildcard.'),
245 '#default_value' => variable_get('lightbox2_disable_these_urls', ''),
249 // Define imagefield settings fieldset.
250 /* ---------------------------------- */
251 if (module_exists('imagefield') && module_exists('imagecache')) {
252 $form['lightbox2_imagefield_options'] = array(
253 '#type' => 'fieldset',
254 '#title' => t('Imagefield settings'),
255 '#collapsible' => TRUE
,
256 '#collapsed' => TRUE
,
259 $imagefield_options = array(
260 0 => t('No Grouping'),
261 1 => t('Group by Field Name'),
262 2 => t('Group by Node Id'),
263 3 => t('Group by Field Name and Node Id'),
265 // Add checkbox for imagefield grouping.
266 $form['lightbox2_imagefield_options']['lightbox2_imagefield_group_node_id'] = array(
268 '#title' => t('Select Imagefield Grouping in Views'),
269 '#description' => t('By default, imagefields in views are grouped by the field name they appear in the view in. You can override that grouping here.'),
270 '#options' => $imagefield_options,
271 '#default_value' => variable_get('lightbox2_imagefield_group_node_id', 1),
276 // Define advanced settings fieldset.
277 /* ---------------------------------- */
278 $form['lightbox2_advanced_options'] = array(
279 '#type' => 'fieldset',
280 '#title' => t('Advanced settings'),
281 '#collapsible' => TRUE
,
282 '#collapsed' => TRUE
,
285 // Add checkbox for overlay opacity.
286 for ($i = 0; $i < 10; $i++) {
287 $opacity_options["0.$i"] = "0.$i";
289 $opacity_options["1.0"] = "1.0";
290 $form['lightbox2_advanced_options']['lightbox2_overlay_opacity'] = array(
292 '#title' => t('Overlay Opacity'),
293 '#options' => $opacity_options,
294 '#description' => t('The overlay opacity setting determines how visible or transparent the background page is behind the lightbox. The opacity value can range from 0.0 to 1.0 where 0.0 is 100% transparent and 1.0 is 100% opaque.'),
295 '#default_value' => variable_get('lightbox2_overlay_opacity', '0.6'),
298 // Allow users to decide where javascript should be loaded - header or footer.
299 // Header is recommended so user can click on images before page has finished
300 // loading, but footer is needed for sites in IE which use SWFObject.
301 $form['lightbox2_advanced_options']['lightbox2_js_location'] = array(
303 '#title' => t('Location of Javscript'),
304 '#options' => array('header' => t('Header'), 'footer' => t('Footer')),
305 '#description' => t('By default, the lightbox javascript files are loaded in the HTML header. However, for sites using SWFObject to load their Flash content, the footer setting is recommended to prevent "Operation Aborted" errors in IE. If using the footer setting, please note that not all themes correctly implement the footer region and may require a small change.'),
306 '#default_value' => variable_get('lightbox2_js_location', 'header'),
310 return system_settings_form($form);
314 * Configuration form for controlling the slideshow behaviour.
316 function lightbox2_slideshow_settings_form() {
318 // Add the javascript which disables / enables form elements.
319 drupal_add_js(drupal_get_path('module', 'lightbox2') .
'/js/lightbox2.js', 'module');
321 // Set up a hidden variable.
322 $form['lightbox2_lite'] = array(
324 '#value' => variable_get('lightbox2_lite', FALSE
),
328 // Add text box for slideshow interval.
329 $form['lightbox2_slideshow_interval'] = array(
330 '#type' => 'textfield',
331 '#title' => t('Interval Seconds'),
332 '#description' => t('The slideshow interval is the length of time in seconds an image is visible before the slideshow shows the next image.'),
333 '#default_value' => variable_get('lightbox2_slideshow_interval', 5),
337 // Add checkbox for slideshow automatic exit.
338 $form['lightbox2_slideshow_automatic_exit'] = array(
339 '#type' => 'checkbox',
340 '#title' => t('Automatically Exit Slideshow'),
341 '#description' => t('Enabling this option will cause the lightbox to automatically close after displaying the last image.'),
342 '#default_value' => variable_get('lightbox2_slideshow_automatic_exit', TRUE
),
345 // Add checkbox for showing hte play / pause button.
346 $form['lightbox2_slideshow_show_play_pause'] = array(
347 '#type' => 'checkbox',
348 '#title' => t('Show Play / Pause Button'),
349 '#description' => t('If enabled, a play / pause button will be shown in the slideshow allowing the user more control over their viewing experience.'),
350 '#default_value' => variable_get('lightbox2_slideshow_show_play_pause', TRUE
),
353 // Add checkbox for "pausing on next click".
354 $form['lightbox2_slideshow_pause_on_next_click'] = array(
355 '#type' => 'checkbox',
356 '#title' => t('Pause Slideshow on "Next Image" Click'),
357 '#description' => t('When enabled the slideshow is automatically paused, and the following image shown, when the "Next" button is clicked.'),
358 '#default_value' => variable_get('lightbox2_slideshow_pause_on_next_click', FALSE
),
361 // Add checkbox for "pausing on prev click".
362 $form['lightbox2_slideshow_pause_on_prev_click'] = array(
363 '#type' => 'checkbox',
364 '#title' => t('Pause Slideshow on "Previous Image" Click'),
365 '#description' => t('When enabled the slideshow is automatically paused, and the previous image shown, when the "Previous" button is clicked.'),
366 '#default_value' => variable_get('lightbox2_slideshow_pause_on_previous_click', TRUE
),
369 return system_settings_form($form);
373 * Validation function for the slideshow configuration form.
375 * Ensure that the slideshow interval submitted is numeric.
377 function lightbox2_slideshow_settings_form_validate($form_id, $form_values) {
378 if (!is_numeric($form_values['lightbox2_slideshow_interval'])) {
379 form_set_error('lightbox2_slideshow_interval', t('The "interval seconds" value must be numeric.'));
384 * Configuration form the automatic image handling functionality.
386 function lightbox2_auto_image_handling_settings_form() {
388 // Add the javascript which disables / enables form elements.
389 drupal_add_js(drupal_get_path('module', 'lightbox2') .
'/js/lightbox2.js', 'module');
391 // Set up a hidden variable.
392 $form['lightbox2_lite'] = array(
394 '#value' => variable_get('lightbox2_lite', FALSE
),
397 $automatic_options = array(
400 2 => t('Lightbox grouped'),
404 // Set image node options help text.
405 $form['image_node_options'] = array(
406 '#value' => t('These options allow automatic URL re-formatting of images. This removes the need for you to add \'rel="lightbox"\' to each image link throughout your site. You can select which image sizes will trigger the lightbox and configure a list of image CSS classes which should also have their URLs automatically re-formatted. This feature is not available when using Lightbox2 Lite.'),
409 // Define image nodes settings fieldset.
410 /* ------------------------------------- */
411 $form['lightbox2_image_node_options'] = array(
412 '#type' => 'fieldset',
413 '#title' => t('Image node settings'),
414 '#collapsible' => TRUE
,
415 '#collapsed' => FALSE
,
418 // Add checkbox for image nodes.
419 $form['lightbox2_image_node_options']['lightbox2_image_node'] = array(
421 '#title' => t('Automatic handler for Image Nodes'),
422 '#options' => $automatic_options,
423 '#description' => t('Choose how URLs for image nodes will be automatically handled.'),
424 '#default_value' => variable_get('lightbox2_image_node', 2),
427 // Add drop-down for list of available image sizes.
428 if (module_exists('image')) {
429 $sizes = _image_get_sizes();
430 foreach ($sizes as
$size_key => $size) {
431 if ($size_key == 'original' || $size_key == '_original') {
434 $size_options[$size_key] = $size['label'];
436 $form['lightbox2_image_node_options']['lightbox2_display_image_size'] = array(
438 '#title' => t('Lightbox image display size'),
439 '#options' => $size_options,
440 '#default_value' => variable_get('lightbox2_display_image_size', ''),
441 '#description' => t('Select which image size will be loaded in the lightbox. This only applies to images uploaded with the Image module.'),
444 $form['lightbox2_image_node_options']['lightbox2_trigger_image_size'] = array(
447 '#title' => t('Image trigger size'),
448 '#options' => $size_options,
449 '#default_value' => variable_get('lightbox2_trigger_image_size', array('thumbnail' => t('Thumbnail'))),
450 '#description' => t('Select which image size, when clicked on, will automatically trigger the lightbox. This only applies to images uploaded with the Image module.'),
455 // Add checkbox for disabling lightbox for gallery lists.
456 $form['lightbox2_image_node_options']['lightbox2_disable_nested_galleries'] = array(
457 '#type' => 'checkbox',
458 '#title' => t('Disable Lightbox for Gallery Lists'),
459 '#description' => t('Checking this box will disable the lightbox for images in gallery lists. This means it is possible to open a gallery by clicking on the teaser image, but the lightbox will still appear when viewing images within the gallery. This only applies to image galleries created with the "image gallery" module.'),
460 '#default_value' => variable_get('lightbox2_disable_nested_galleries', TRUE
),
463 // Add checkbox for flickr image support.
464 $form['lightbox2_flickr'] = array(
466 '#title' => t('Automatic handler for Flickr images'),
467 '#options' => $automatic_options,
468 '#description' => t('Choose how URLs for Flickr images will be automatically handled.'),
469 '#default_value' => variable_get('lightbox2_flickr', 2),
472 // Add checkbox for gallery2 block image support.
473 $form['lightbox2_gallery2_blocks'] = array(
475 '#title' => t('Automatic handler for Gallery2 block images'),
476 '#options' => $automatic_options,
477 '#description' => t('Choose how URLs for images, contained within Gallery2 image blocks, will be automatically handled.'),
478 '#default_value' => variable_get('lightbox2_gallery2_blocks', 2),
482 // Add checkbox for inline image support.
483 $form['lightbox2_inline'] = array(
485 '#title' => t('Automatic handler for Inline images'),
486 '#options' => $automatic_options,
487 '#description' => t('Choose how URLs for Inline images will be automatically handled.'),
488 '#default_value' => variable_get('lightbox2_inline', 2),
491 // Add checkbox for image assist custom size images.
492 $form['lightbox2_image_assist_custom'] = array(
494 '#title' => t('Automatic handler for Image Assist custom size images'),
495 '#options' => $automatic_options,
496 '#description' => t('Choose how URLs for custom size images, displayed by the Image Assist module, will be automatically handled.'),
497 '#default_value' => variable_get('lightbox2_image_assist_custom', 2),
500 // Add text box for custom trigger classes.
501 $form['lightbox2_custom_trigger_classes'] = array(
502 '#type' => 'textarea',
503 '#title' => t('Custom image trigger classes'),
504 '#description' => t('List the image classes which should trigger the lightbox when clicked on. Put each class on a separate line.'),
505 '#default_value' => variable_get('lightbox2_custom_trigger_classes', ''),
508 // Add text box for link text to node.
509 $form['lightbox2_node_link_text'] = array(
510 '#type' => 'textfield',
511 '#title' => t('Text for Image Page Link'),
512 '#description' => t('This is the text that will appear as the link to the image page underneath the image in the lightbox.'),
513 '#default_value' => variable_get('lightbox2_node_link_text', 'View Image Details'),
516 // Add checkbox for node link target.
517 $form['lightbox2_node_link_target'] = array(
518 '#type' => 'checkbox',
519 '#title' => t('Open Image Page in New Window'),
520 '#description' => t('This controls whether the link to the image page underneath the image is opened in a new window or the current window.'),
521 '#default_value' => variable_get('lightbox2_node_link_target', FALSE
),
522 '#return_value' => '_blank',
525 // Add checkbox for disabling lightbox for acidfree gallery lists.
526 if (module_exists("acidfree")) {
527 $form['lightbox2_disable_nested_acidfree_galleries'] = array(
528 '#type' => 'checkbox',
529 '#title' => t('Disable Lightbox for Acidfree Gallery Lists'),
530 '#description' => t('Checking this box will disable the lightbox for images in gallery lists. This means it is possible to open a gallery by clicking on the teaser image, but the lightbox will still appear when viewing images within the gallery. This only applies to image galleries created with the "acidfree" module.'),
531 '#default_value' => variable_get('lightbox2_disable_nested_acidfree_galleries', TRUE
),
535 return system_settings_form($form);
539 * Implementation of hook_filter_tips().
541 function lightbox2_filter_tips($delta, $format, $long = FALSE
) {
544 return t('Image links with \'rel="lightbox"\' in the <a> tag will appear in a Lightbox when clicked on.');
547 $output = '<p>'.
t('To add a lightbox to your images, add rel="lightbox" attribute to any link tag to activate the lightbox. For example:') .
'</p>';
548 $output .
= '<p>'.
t('<code><a href="image-1.jpg" rel="lightbox" title="my caption">image #1</a></code>') .
'</p>';
549 $output .
= '<p>'.
t('The title attribute in the link tag is optional. The addition of this attribute enables the display of a caption with the image displayed in the lightbox.') .
'</p>';
550 $output .
= '<p>'.
t('If you have a set of related images that you would like to group, then you will need to include a group name between square brackets in the rel attribute. For example:') .
'</p>';
551 $output .
= '<p>'.
t('<code><a href="image-1.jpg" rel="lightbox[roadtrip]">image #1</a><br /> <a href="image-2.jpg" rel="lightbox[roadtrip]">image #2</a><br /> <a href="image-3.jpg" rel="lightbox[roadtrip]">image #3</a><br /> </code>') .
'</p>';
552 $output .
= '<p>'.
t('There are no limits to the number of image sets per page or how many images are allowed in each set.') .
'</p>';
553 $output .
= '<p>'.
t('If you wish to turn the caption into a link, format your caption in the following way:') .
'</p>';
554 $output .
= '<p>'.
t('<code><a href="image-1.jpg" rel="lightbox" title=\'<a href="http://www.yourlink.com">View Image Details</a>\'>image #1</a></code>') .
'</p>';
558 else if ($delta == 1) {
559 return t('Image links from G2 are formatted for use with Lightbox2');
564 * Implementation of hook_filter().
566 function lightbox2_filter($op, $delta = 0, $format = -1, $text = '') {
569 return array(0 => t('Lightbox filter'), 1 => t('Lightbox G2 filter'));
573 return t('Turns g2_filter links into Lightbox2 appropriate links');
576 return t('Image links with \'rel="lightbox"\' in the <a> tag will appear in a Lightbox when clicked on.');
581 $text = ' '.
$text .
' ';
582 $text = preg_replace('/ShowItem/', 'DownloadItem', $text);
583 $text = preg_replace('/target=""/', 'rel="lightbox"', $text);
584 $text = substr($text, 1, -1);
594 * Provide links to the CSS stylesheet and JS file associated with
597 function lightbox2_add_files() {
598 static
$already_added = FALSE
;
599 if ($already_added) {
600 return; // Don't add the javascript and CSS multiple times.
602 $already_added = TRUE
;
604 // Load required js and css files.
605 $path = drupal_get_path('module', 'lightbox2');
607 // Initialise some variables.
608 $inline_image_handler = variable_get('lightbox2_inline', 2);
609 $flickr_image_handler = variable_get('lightbox2_flickr', 2);
610 $gallery2_block_handler = variable_get('lightbox2_gallery2_blocks', 2);
611 $image_assist_handler = variable_get('lightbox2_image_assist_custom', 2);
612 $image_node_handler = variable_get('lightbox2_image_node', 2);
614 // Set the list of image classes to format urls for.
615 $image_node_sizes = '';
616 $trigger_lightbox_classes = '';
617 $trigger_lightbox_group_classes = '';
618 $trigger_slideshow_classes = '';
620 // Inline module images.
621 switch ($inline_image_handler) {
623 $trigger_lightbox_classes .
= "img.inline,";
626 $trigger_lightbox_group_classes .
= "img.inline,";
629 $trigger_slideshow_classes .
= "img.inline,";
634 switch ($flickr_image_handler) {
636 $trigger_lightbox_classes .
= "img.flickr-photo-img,img.flickr-photoset-img,";
639 $trigger_lightbox_group_classes .
= "img.flickr-photo-img,img.flickr-photoset-img,";
642 $trigger_slideshow_classes .
= "img.flickr-photo-img,img.flickr-photoset-img,";
646 // Gallery2 block images.
647 switch ($gallery2_block_handler) {
649 $trigger_lightbox_classes .
= "img.ImageFrame_image,";
652 $trigger_lightbox_group_classes .
= "img.ImageFrame_image,";
655 $trigger_slideshow_classes .
= "img.ImageFrame_image,";
659 // Image Assist custom size images.
660 switch ($image_assist_handler) {
662 $trigger_lightbox_classes .
= "img.image-img_assist_custom,";
665 $trigger_lightbox_group_classes .
= "img.image-img_assist_custom,";
668 $trigger_slideshow_classes .
= "img.image-img_assist_custom,";
673 if ($image_node_handler) {
674 $trigger_sizes = variable_get('lightbox2_trigger_image_size', array('thumbnail' => t('Thumbnail')));
675 foreach ($trigger_sizes as
$size => $size_name) {
676 $triggers = "img.$size, img.image-$size,";
678 $triggers = "img._original, img.image-_original,";
681 $image_node_sizes .
= "\.$size|";
683 switch ($image_node_handler) {
685 $trigger_lightbox_classes .
= $triggers;
688 $trigger_lightbox_group_classes .
= $triggers;
691 $trigger_slideshow_classes .
= $triggers;
698 $custom_triggers = variable_get('lightbox2_custom_trigger_classes', '');
699 if (!empty($custom_triggers)) {
700 $trigger_classes = preg_split("/(\r\n|\n)/", $custom_triggers);
701 foreach ($trigger_classes as
$class) {
702 if (!empty($class)) {
703 $trigger_lightbox_classes .
= "img.$class,";
707 $trigger_lightbox_classes = rtrim($trigger_lightbox_classes, ",");
708 $trigger_lightbox_group_classes = rtrim($trigger_lightbox_group_classes, ",");
709 $trigger_slideshow_classes = rtrim($trigger_slideshow_classes, ",");
710 $image_node_sizes = '('.
rtrim($image_node_sizes, "|") .
')';
712 // Find out if we're using a RTL language.
714 if (module_exists('i18n') && module_invoke('i18n', 'language_rtl')) {
718 // Load the javascript settings.
719 $js_settings = array(
721 'file_path' => base_path() .
'(\w\w/)'.
file_directory_path(),
722 'base_path' => base_path(),
723 'default_image' => base_path() .
$path .
'/images/brokenimage.jpg',
724 'overlay_opacity' => variable_get('lightbox2_overlay_opacity', '0.6'),
725 'use_alt_layout' => variable_get('lightbox2_use_alt_layout', FALSE
),
726 'disable_zoom' => variable_get('lightbox2_disable_zoom', FALSE
),
727 'force_show_nav' => variable_get('lightbox2_force_show_nav', FALSE
),
728 'node_link_text' => check_plain(t(variable_get('lightbox2_node_link_text', 'View Image Details'))),
729 'node_link_target' => variable_get('lightbox2_node_link_target', FALSE
),
730 'image_count' => check_plain(t(variable_get('lightbox2_image_count_str', 'Image !current of !total'))),
731 'lite_press_x_close' => t('press !x to close', array('!x' => '<a href="#" onclick="hideLightbox(); return FALSE;"><kbd>x</kbd></a>')),
732 // Automatic image handling settings.
733 'display_image_size' => variable_get('lightbox2_display_image_size', ''),
734 'image_node_sizes' => $image_node_sizes,
735 'trigger_lightbox_classes' => $trigger_lightbox_classes,
736 'trigger_lightbox_group_classes' => $trigger_lightbox_group_classes,
737 'trigger_slideshow_classes' => $trigger_slideshow_classes,
738 'disable_for_gallery_lists' => variable_get('lightbox2_disable_nested_galleries', TRUE
),
739 'disable_for_acidfree_gallery_lists' => variable_get('lightbox2_disable_nested_acidfree_galleries', TRUE
),
740 // Slideshow settings.
741 'slideshow_interval' => variable_get('lightbox2_slideshow_interval', 5) * 1000,
742 'slideshow_automatic_exit' => variable_get('lightbox2_slideshow_automatic_exit', TRUE
),
743 'show_play_pause' => variable_get('lightbox2_slideshow_show_play_pause', TRUE
),
744 'pause_on_next_click' => variable_get('lightbox2_slideshow_pause_on_next_click', FALSE
),
745 'pause_on_previous_click' => variable_get('lightbox2_slideshow_pause_on_previous_click', TRUE
),
747 drupal_add_js(array('lightbox2' => $js_settings), 'setting');
749 // Check where we should load the javascript files - header or footer.
750 $js_location = variable_get('lightbox2_js_location', 'header');
753 if (!variable_get('lightbox2_lite', FALSE
)) {
754 $css = $path .
'/css/lightbox.css';
755 if (module_exists('i18n') && module_invoke('i18n', 'language_rtl')) {
756 $css = $path .
'/css/lightbox-rtl.css';
758 if (variable_get('lightbox2_use_alt_layout', FALSE
)) {
759 // No need for rtl version, everything is centred.
760 $css = $path .
'/css/lightbox_alt.css';
762 drupal_add_css($css);
764 // Check to see if any automatic image handling options are enabled.
765 if ($image_node_handler || $flickr_image_handler || $gallery2_block_handler || $inline_image_handler || $image_assist_handler || $custom_triggers != '') {
766 drupal_add_js($path .
'/js/auto_image_handling.js', 'module', $js_location);
768 drupal_add_js($path .
'/js/lightbox.js', 'module', $js_location);
773 $css = $path .
'/css/lightbox_lite.css';
774 if (module_exists('i18n') && module_invoke('i18n', 'language_rtl')) {
775 $css = $path .
'/css/lightbox_lite-rtl.css';
777 drupal_add_css($css);
778 drupal_add_js($path .
'/js/lightbox_lite.js', 'module', $js_location);
783 * Implementation of hook_field_formatter_info().
785 * Add certain lightbox+imagecache formatters to CCK image fields if the
786 * imagefield.module and the imagecache.module exist.
788 function lightbox2_field_formatter_info() {
789 $formatter = array();
790 if (module_exists('imagefield') && module_exists('imagecache')) {
792 if (function_exists('imagecache_presets')) {
793 $presets = imagecache_presets();
794 foreach ($presets as
$preset_id => $preset_info) {
795 $rules[$preset_id] = $preset_info['presetname'];
799 $rules = _imagecache_get_presets();
801 foreach ($rules as
$ruleid => $view_rule) {
802 $formatters['lightbox2][original]['.
$view_rule] = array(
803 'label' => 'Lightbox2: original->'.
$view_rule,
804 'field types' => array('image'),
806 $formatters['lightbox2]['.
$view_rule .
'][original'] = array(
807 'label' => 'Lightbox2: '.
$view_rule .
'->original',
808 'field types' => array('image'),
810 $formatters['lightshow2][original]['.
$view_rule] = array(
811 'label' => 'Lightbox2 slideshow: original->'.
$view_rule,
812 'field types' => array('image'),
814 $formatters['lightshow2]['.
$view_rule .
'][original'] = array(
815 'label' => 'Lightbox2 slideshow: '.
$view_rule .
'->original',
816 'field types' => array('image'),
818 foreach ($rules as
$rid => $lightbox_rule) {
819 $formatters['lightbox2]['.
$view_rule .
']['.
$lightbox_rule] = array(
820 'label' => 'Lightbox2: '.
$view_rule .
'->'.
$lightbox_rule,
821 'field types' => array('image'),
823 $formatters['lightshow2]['.
$view_rule .
']['.
$lightbox_rule] = array(
824 'label' => 'Lightbox2 slideshow: '.
$view_rule .
'->'.
$lightbox_rule,
825 'field types' => array('image'),
835 * Implementation of hook_field_formatter().
837 function lightbox2_field_formatter($field, $item, $formatter) {
838 if (module_exists('imagefield') && module_exists('imagecache')) {
839 if (isset($item['filepath'])) {
840 $filepath = &$item['filepath'];
842 else if (!empty($item['fid'])) {
843 $file = _imagefield_file_load($item['fid']);
844 $filepath = &$file['filepath'];
849 if (lightbox2_exclude_these_paths() != 1) {
850 lightbox2_add_files();
853 $item = array_merge($item, (array)$file);
854 $item['filepath'] = $filepath;
855 if (strpos($formatter, 'lightbox2][') !== FALSE
|| strpos($formatter, 'lightshow2][') !== FALSE
) {
856 list($null, $view_preset, $lightbox_preset) = explode('][', $formatter, 3);
857 $item['lightbox_preset'] = $lightbox_preset;
860 if (function_exists('imagecache_presets')) {
861 $presets = imagecache_presets();
862 foreach ($presets as
$preset_id => $preset_info) {
863 $rules[$preset_id] = $preset_info['presetname'];
867 $rules = _imagecache_get_presets();
869 if ($view_preset == 'original' || in_array($view_preset, (array) $rules)) {
871 if (strpos($formatter, 'lightshow2][') !== FALSE
) {
874 return theme('imagefield_image_imagecache_lightbox2', $view_preset, $field, $item, NULL
, $slideshow);
881 * Implementation of theme_imagefield_image_imagecache_lightbox2().
883 function theme_imagefield_image_imagecache_lightbox2($view_preset, $field, $item, $attributes = NULL
, $slideshow = FALSE
) {
889 $imagefield_grouping = variable_get('lightbox2_imagefield_group_node_id', 1);
890 if ($imagefield_grouping == 1) {
891 $rel = $rel .
'['.
$field['field_name'] .
']';
893 else if ($imagefield_grouping == 2 && !empty($item['nid'])) {
894 $rel = $rel .
'['.
$item['nid'] .
']';
896 else if ($imagefield_grouping == 3 && !empty($item['nid'])) {
897 $rel = $rel .
'['.
$field['field_name'] .
$item['nid'] .
']';
901 if (!empty($item['nid'])) {
902 $attributes = array();
903 $target = variable_get('lightbox2_node_link_target', FALSE
);
904 if (!empty($target)) {
905 $attributes = array('target' => $target);
907 $node_link = '<br /><br />'.
l(t(variable_get('lightbox2_node_link_text', 'View Image Details')), 'node/'.
$item['nid'], $attributes);
910 $link_attributes = array(
912 'title' => $item['title'] .
$node_link);
914 if ($view_preset == 'original') {
915 $image = theme('lightbox2_image', $item['filepath'], $item['alt'], $item['title'], $attributes);
918 $image = theme('imagecache', $view_preset, $item['filepath'], $item['alt'], $item['title'], $attributes);
920 if ($item['lightbox_preset'] == 'original') {
921 $output = l($image, file_create_url($item['filepath']), $link_attributes, NULL
, NULL
, FALSE
, TRUE
);
924 $output = l($image, lightbox2_imagecache_create_url($item['lightbox_preset'], $item['filepath']), $link_attributes, NULL
, NULL
, FALSE
, TRUE
);
931 * Return TRUE if current path is disabled for lightbox according to
932 * lightbox2_disable_these_urls.
934 function lightbox2_exclude_these_paths() {
935 // Use lightbox if this url is not excluded.
936 $disabled_urls = variable_get('lightbox2_disable_these_urls', '');
938 if (!empty($disabled_urls)) {
939 $urls = explode("\n", $disabled_urls);
941 foreach ($urls as
$url) {
943 if ($url == "<front>") {
946 $url = preg_replace('/%/', '.*?', preg_quote($url, '/'));
947 $pattern = '/^'.
$url .
'$/';
948 if (preg_match($pattern, $_REQUEST['q'])) {
958 * Theme function for displaying the lightbox2 trigger image in an imagefield.
960 function theme_lightbox2_image($path, $alt = '', $title = '', $attributes = NULL
) {
961 $attributes = drupal_attributes($attributes);
962 $image = '<img src="'.
file_create_url($path) .
'" alt="'.
check_plain($alt) .
'" title="'.
check_plain($title) .
'" '.
$attributes .
' />';
967 * Implementation of the imagecache_create_url() function for integration with
968 * imagecache module versions prior to imagecache 2.
970 function lightbox2_imagecache_create_url($preset, $filepath) {
971 if (function_exists('imagecache_create_url')) {
972 return imagecache_create_url($preset, $filepath);
975 $path = _imagecache_strip_file_directory($filepath);
976 return file_create_url(file_directory_path() .
'/imagecache/'.
$preset .
'/'.
$path);