lightbox2.module

  1. cis7 sites/all/modules/ulmus/lightbox2/lightbox2.module
  2. cle7 sites/all/modules/ulmus/lightbox2/lightbox2.module
  3. ecd7 sites/all/modules/ulmus/lightbox2/lightbox2.module
  4. elmsmedia7 sites/all/modules/ulmus/lightbox2/lightbox2.module
  5. harmony7 sites/all/modules/ulmus/lightbox2/lightbox2.module
  6. icor7 sites/all/modules/ulmus/lightbox2/lightbox2.module
  7. meedjum_blog7 sites/all/modules/ulmus/lightbox2/lightbox2.module
  8. mooc7 sites/all/modules/ulmus/lightbox2/lightbox2.module

Enables the use of lightbox2 which places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths.

This module is for Drupal 6.x only.

Module by: Mark Ashmead Mailto: bugzie@gmail.com Co-maintainer: Stella Power (http://drupal.org/user/66894)

Image Node Support: Steve McKenzie

Functions

Namesort descending Description
lightbox2_add_files Provide links to the CSS stylesheet and JS file associated with this module.
lightbox2_check_filefield_extension Suitability callback function for the filefield formatter.
lightbox2_check_filefield_image_extension Suitability callback function for the image filefield formatter.
lightbox2_contact Get the contact form.
lightbox2_exclude_these_paths Return TRUE if current path is disabled for lightbox according to lightbox2_page_list and lightbox2_page_init_action.
lightbox2_field_formatter_info Implementation of hook_field_formatter_info().
lightbox2_field_formatter_view Implements hook_field_formatter_view().
lightbox2_file_formatter_info Implementation of filefield's hook_file_formatter_info().
lightbox2_filter_info Implements hook_filter_info().
lightbox2_filter_xss
lightbox2_form_contact_site_form_alter
lightbox2_form_user_login_block_alter Implementation of hook_form_alter().
lightbox2_help Implementation of hook_help().
lightbox2_init Implementation of hook_init().
lightbox2_link_alter Implementation of hook_link_alter().
lightbox2_login Get the user login form.
lightbox2_menu Implementation of hook_menu().
lightbox2_permission Implementation of hook_permission().
lightbox2_preprocess_page Preprocess function for template by theme('page').
lightbox2_supported_file_extension Check whether a given file extension is supported by the lightbox iframe.
lightbox2_theme Implementation of hook_theme().
lightbox2_views_api Implementation of hook_views_api().
sort_by_length Helper function to compare the string length of two items. Used when trying to sort an array by value length.
_lightbox2_process_disable_filter Process callback for Disable Lightbox iframe filter.
_lightbox2_process_filter Process callback for Lightbox G2 filter.

File

sites/all/modules/ulmus/lightbox2/lightbox2.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Enables the use of lightbox2 which places images above your current page,
  5. * not within. This frees you from the constraints of the layout,
  6. * particularly column widths.
  7. *
  8. * This module is for Drupal 6.x only.
  9. *
  10. * Module by: Mark Ashmead
  11. * Mailto: bugzie@gmail.com
  12. * Co-maintainer: Stella Power (http://drupal.org/user/66894)
  13. *
  14. * Image Node Support: Steve McKenzie
  15. */
  16. /**
  17. * Implementation of hook_help().
  18. */
  19. function lightbox2_help($path, $arg) {
  20. switch ($path) {
  21. case 'admin/modules#description':
  22. $output = t('Enables Lightbox2 for Drupal');
  23. break;
  24. case 'admin/help#lightbox2':
  25. $output = '<h3>' . t('Overview') . '</h3>';
  26. $output .= '<p>' . t('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>';
  27. $output .= '<p>' . t('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>';
  28. // Features
  29. $output .= '<h3>' . t('Features') . '</h3>';
  30. $output .= '<p>' . t('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.') . '</p>';
  31. $output .= '<ul>';
  32. $output .= '<li>' . t('Image Sets: group related images and navigate through them with ease - ideal for your image galleries.') . '</li>';
  33. $output .= '<li>' . t('Slideshow Capability: automatically transition between grouped images, includes play/pause and previous and next buttons.') . '</li>';
  34. $output .= '<li>' . t('HTML Content Support: ability to show websites or other HTML content in a lightbox.') . '</li>';
  35. $output .= '<li>' . t('Video Content Support: ability to show videos in a lightbox.') . '</li>';
  36. $output .= '<li>' . t('Visual Effects: fancy pre-loader and transition when you click on the image.') . '</li>';
  37. $output .= '<li>' . t('Keyboard Shortcuts: useful <a href="http://drupal.org/node/249827">keyboard shortcuts</a> for switching between images, toggling play / pause, etc.') . '</li>';
  38. $output .= '<li>' . t('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>';
  39. $output .= '<li>' . t('Automatic Image Detection: configurable automatic re-formatting of image thumbnails, so there is no need to add \'rel="lightbox"\' to each image link on your site. ');
  40. $output .= t('<a href="!image">Image</a>, <a href="!inline">Inline</a>, <a href="!flickr">Flickr</a>, <a href="!img_assist">Image Assist</a> and <a href="!imagefield">CCK Imagefield</a> modules are all supported. ', array('!image' => 'http://drupal.org/project/image', '!inline' => 'http://drupal.org/project/inline', '!flickr' => 'http://drupal.org/project/flickr', '!img_assist' => 'http://drupal.org/project/img_assist', '!imagefield' => 'http://drupal.org/project/imagefield'));
  41. $output .= t('It\'s also possible to configure a custom list of image classes which should trigger the lightbox functionality.');
  42. $output .='</li>';
  43. $output .= '<li>' . t('<a href="!imagecache">Imagecache</a> Support: adds a Lightbox2 field formatter for <a href="!imagefield">CCK imagefields</a> for your custom <a href="!views">views</a>.', array('!imagecache' => 'http://drupal.org/project/imagecache', '!imagefield' => 'http://drupal.org/project/imagefield', '!views' => 'http://drupal.org/project/views')) . '</li>';
  44. $output .= '<li>' . t('Image Page Link: a link to the image node can be provided within the lightbox itself.') . '</li>';
  45. $output .= '<li>' . t('Page Exclusion Capability: exclude certain pages on your site from having the lightbox2 functionality.') . '</li>';
  46. $output .= '<li>' . t('Login Support: ability to modify all user/login links so the login form appears in a lightbox.') . '</li>';
  47. $output .= '<li>' . t('Skin and Animation Configuration: configure the order and speed of the lightbox animations, along with the lightbox colors, border size and overlay opacity.') . '</li>';
  48. $output .= '<li>' . t('Gallery 2 Support: support for Gallery 2 images via the <a href="!gallery">Gallery</a> module (beta).', array('!gallery' => 'http://drupal.org/project/gallery')) . '</li>';
  49. $output .= '</ul>';
  50. // Usage
  51. $output .= '<h3>' . t('Usage') . '</h3>';
  52. $output .= '<h5 style="text-decoration: underline;">' . t('Adding a Basic Lightbox') . '</h5>';
  53. $output .= '<p>' . t('Add rel=&quot;lightbox&quot; attribute to any link tag to activate the lightbox. For example:') . '</p>';
  54. $output .= '<code>' . t('&lt;a href=&quot;image-1.jpg&quot; rel=&quot;lightbox&quot;&gt;image #1&lt;/a&gt;<br />
  55. &lt;a href=&quot;image-1.jpg&quot; rel=&quot;lightbox[][my caption]&quot;&gt;image #1&lt;/a&gt;') . '</code>';
  56. $output .= '<p>' . t('Optional: To show a caption either use the title attribute or put in the second set of [] of the rel attribute.') . '</p>';
  57. // Grouping Images
  58. $output .= '<h5 style="text-decoration: underline;">' . t('Grouping Images') . '</h5>';
  59. $output .= '<p>' . t('If you have a set of related images that you would like to group, follow step one but additionally include a group name between square brackets in the rel attribute. For example:') . '</p>';
  60. $output .= '<code>' . t('&lt;a href="images/image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br />
  61. &lt;a href="images/image-2.jpg" rel="lightbox[roadtrip][caption 2]"&gt;image#2&lt;/a&gt;<br />
  62. &lt;a href="images/image-3.jpg" rel="lightbox[roadtrip][caption 3]"&gt;image#3&lt;/a&gt;') . '</code>';
  63. $output .= '<p>' . t('No limits to the number of image sets per page or how many images are allowed in each set.') . '</p>';
  64. $output .= '<p>' . t('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>';
  65. $output .= '<p><code>' . t('&lt;a href="images/image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br />
  66. &lt;a href="images/image-2.jpg" rel="lightbox[roadtrip]" class="lightbox_hide_image"&gt;image #2&lt;/a&gt;<br />
  67. &lt;a href="images/image-3.jpg" rel="lightbox[roadtrip][caption 3]" class="lightbox_hide_image"&gt;image #3&lt;/a&gt;') . '</code></p>';
  68. // Slideshow
  69. $output .= '<h5 style="text-decoration: underline;">' . t('Slideshow') . '</h5>';
  70. $output .= '<p>' . t('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>';
  71. $output .= '<p><code>' . t('&lt;a href="images/image-1.jpg" rel="lightshow[roadtrip]"&gt;image #1&lt;/a&gt;<br />
  72. &lt;a href="images/image-2.jpg" rel="lightshow[roadtrip][caption 2]"&gt;image #2&lt;/a&gt;<br />
  73. &lt;a href="images/image-3.jpg" rel="lightshow[roadtrip][caption 3]"&gt;image #3&lt;/a&gt;') . '</code></p>';
  74. // Video Content
  75. $output .= '<h5 style="text-decoration: underline;">' . t('Video Content') . '</h5>';
  76. $output .= '<p>' . t('It\'s possible to show video content in the lightbox. In this case the "rel" attribute should be set to <code>lightvideo</code>. It\'s possible to group videos and to control the size of the lightbox by setting the \'width\' and \'height\' properties. The properties can be configured like <code>lightvideo[group|width:300px; height: 200px;]</code> and <code>lightvideo[|width:300px; height: 200px;][my caption]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon. If no properties are set, then the default width and height of 400px will be used. See below for more detailed examples.') . '</p>';
  77. $output .= '<p>' . t('Basic example:') . '<br />';
  78. $output .= '<code>' . t('&lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo"&gt;Google video example - default size&lt;/a&gt;') . '</code></p>';
  79. $output .= '<p>' . t('Basic example with caption:') . '<br />';
  80. $output .= '<code>' . t('&lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo[][my caption]"&gt;Google video example - default size&lt;/a&gt;') . '</code></p>';
  81. $output .= '<p>' . t('Grouped example:') . '<br />';
  82. $output .= '<code>' . t('&lt;a href="http://video.google.com/videoplay?docid=29023498723974239479" rel="lightvideo[group][my caption]"&gt;Grouped example 1&lt;/a&gt;<br />
  83. &lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo[group][my caption]"&gt;Grouped example 2&lt;/a&gt;') . '</code></p>';
  84. $output .= '<p>' . t('Controlling lightbox size example:') . '<br />';
  85. $output .= '<code>' . t('&lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo[|width:400px; height:300px;][my caption]"&gt;Google video example - custom size&lt;/a&gt;') . '<br /></code></p>';
  86. $output .= '<p>' . t('Supported Video Formats:') . '<br />';
  87. $output .= t('asx, wmv, mov and swf videos should all be supported. A number of video providers are also supported, for example YouTube and Google Video. For full details on how to integrate these with lightbox, please see the online documentation.') . '</p>';
  88. // HTML Content
  89. $output .= '<h5 style="text-decoration: underline;">' . t('HTML Content') . '</h5>';
  90. $output .= '<p>' . t('It\'s possible to show webpage content in the lightbox, using iframes. In this case the "rel" attribute should be set to <code>lightframe</code>. Again it\'s possible to group the items, (e.g. <code>lightframe[search]</code>) but in addition to that, it\'s possible to control some of the iframe properties. It\'s possible to set the \'width\', \'height\' and \'scrolling\' properties of the iframe. The properties are separated from the group name by a <code>|</code>, for example <code>lightframe[search|width:100px;]</code> and <code>lightframe[search|width:120px][my caption]</code>. If no grouping is being used, then the <code>|</code> is still used and the format would be <code>lightframe[|width:100px;]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon. If no iframe properties are set, then the default width and height of 400px will be used. See below for more detailed examples.') . '</p>';
  91. $output .= '<p>' . t('Basic example:') . '<br />';
  92. $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[][Search Google]"&gt;Search google&lt;/a&gt;') . '</code></p>';
  93. $output .= '<p>' . t('Grouped example:') . '<br />';
  94. $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[search]"&gt;Search google&lt;/a&gt;<br />
  95. &lt;a href="http://www.yahoo.com" rel="lightframe[search][Search Yahoo]"&gt;Search yahoo&lt;/a&gt;') . '</code></p>';
  96. $output .= '<p>' . t('Controlling iframe property example:') . '<br />';
  97. $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[|width:400px; height:300px; scrolling: auto;]"&gt;Search google&lt;/a&gt;') . '</code></p>';
  98. $output .= '<p>' . t('Controlling iframe property when grouped example:') . '<br />';
  99. $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[search|width:400px; height:300px; scrolling: auto;]"&gt;Search google&lt;/a&gt;<br />
  100. &lt;a href="http://www.yahoo.com" rel="lightframe[search|width:400px; height:300px;][Search Yahoo]"&gt;Search yahoo&lt;/a&gt;') . '</code></p>';
  101. // Inline Content Support
  102. $output .= '<h5 style="text-decoration: underline;">' . t('Inline Content Support') . '</h5>';
  103. $output .= '<p>' . t('It\'s possible to show HTML snippets in the lightbox, that is on the same domain. In this case the "rel" attribute should be set to <code>lightmodal</code>. Again it\'s possible to group the content, (e.g. <code>lightmodal[search]</code>) but in addition to that, it\'s possible to control some of the inline / modal properties. It\'s possible to set the \'width\', \'height\' and \'scrolling\' properties of the inline content. The properties are separated from the group name by a <code>|</code>, for example <code>lightmodal[search|width:100px;]</code> and <code>lightmodal[search|width:100px;][my caption]</code>. If no grouping is being used, then the <code>|</code> is still used and the format would be <code>lightmodal[|width:100px;]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon. If no properties are set, then the default width and height of 400px will be used. See below for more detailed examples.') . '</p>';
  104. $output .= '<p>' . t('Basic example:') . '<br />';
  105. $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal"&gt;Search&lt;/a&gt;') . '</code></p>';
  106. $output .= '<p>' . t('Basic example with caption:') . '<br />';
  107. $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[][my caption]"&gt;Search&lt;/a&gt;') . '</code></p>';
  108. $output .= '<p>' . t('Grouped example:') . '<br />';
  109. $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[search]"&gt;Search&lt;/a&gt;<br />
  110. &lt;a href="search.php?status=1" rel="lightmodal[search][published]"&gt;Search published content&lt;/a&gt;') . '</code></p>';
  111. $output .= '<p>' . t('Controlling modal property example:') . '<br />';
  112. $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[|width:400px; height:300px; scrolling: auto;]"&gt;Search&lt;/a&gt;') . '</code></p>';
  113. $output .= '<p>' . t('Controlling modal property when grouped example:') . '<br />';
  114. $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[search|width:400px; height:300px; scrolling: auto;]"&gt;Search&lt;/a&gt;<br />
  115. &lt;a href="search.php?status=1" rel="lightmodal[search|width:400px; height:300px;][Search published]"&gt;Search published content&lt;/a&gt;<br />
  116. &lt;a href="search.php?status=0" rel="lightmodal[search|width:400px; height:300px;][Search Unpublished]"&gt;Search unpublished content&lt;/a&gt;') . '</code></p>';
  117. // Keyboard Shortcuts
  118. $output .= '<h3>' . t('Keyboard Shortcuts') . '</h3>';
  119. $output .= '<p>' . t('The default keyboard shortcuts are listed below. You can override these on the admin page.') . '</p>';
  120. $output .= '<table>';
  121. $output .= '<tr><td>' . t('Close Lightbox') . '</td><td>x</td></tr>';
  122. $output .= '<tr><td></td><td>o</td></tr>
  123. <tr><td></td><td>c</td></tr>
  124. <tr><td></td><td>ESC</td></tr>';
  125. $output .= '<tr><td>' . t('Previous Image') . '</td><td>p</td></tr>';
  126. $output .= '<tr><td></td><td>' . t('Left Arrow') . '</td></tr>';
  127. $output .= '<tr><td>' . t('Next Image') . '</td><td>n</td></tr>';
  128. $output .= '<tr><td></td><td>' . t('Right Arrow') . '</td></tr>';
  129. $output .= '<tr><td>' . t('Toggle Zoom') . '</td><td>' . t('z (not available in slideshow)') . '</td></tr>';
  130. $output .= '<tr><td>' . t('Toggle Play / Pause') . '</td><td>' . t('Spacebar (slideshow only)') . '</td></tr>';
  131. $output .= '</table>';
  132. $output .= '<p>' . t('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>';
  133. break;
  134. }
  135. return !empty($output) ? $output : '';
  136. }
  137. /**
  138. * Implementation of hook_permission().
  139. */
  140. function lightbox2_permission() {
  141. return array(
  142. 'administer lightbox2' => array(
  143. 'title' => t('Administer Lightbox2'),
  144. 'description' => t('Allow the user administer Lightbox2 settings'),
  145. ),
  146. 'download original image' => array(
  147. 'title' => t('Download Original'),
  148. 'description' => t('Create a link that allow the user download the original image'),
  149. ),
  150. );
  151. }
  152. /**
  153. * Implementation of hook_menu().
  154. */
  155. function lightbox2_menu() {
  156. $items = array();
  157. $items['system/lightbox2/filter-xss'] = array(
  158. 'title' => 'Filter XSS',
  159. 'page callback' => 'lightbox2_filter_xss',
  160. 'access callback' => TRUE,
  161. 'type' => MENU_CALLBACK,
  162. );
  163. $items['admin/config/user-interface/lightbox2'] = array(
  164. 'title' => 'Lightbox2',
  165. 'description' => 'Allows the user to configure the lightbox2 settings',
  166. 'file' => 'lightbox2.admin.inc',
  167. 'page callback' => 'lightbox2_settings_page',
  168. 'access callback' => 'user_access',
  169. 'access arguments' => array('administer lightbox2'),
  170. );
  171. $items['admin/config/user-interface/lightbox2/general'] = array(
  172. 'title' => 'General',
  173. 'description' => 'Allows the user to configure the lightbox2 settings',
  174. 'file' => 'lightbox2.admin.inc',
  175. 'page callback' => 'drupal_get_form',
  176. 'page arguments' => array('lightbox2_general_settings_form'),
  177. 'access callback' => 'user_access',
  178. 'access arguments' => array('administer lightbox2'),
  179. 'type' => MENU_DEFAULT_LOCAL_TASK,
  180. 'weight' => 0,
  181. );
  182. $items['admin/config/user-interface/lightbox2/slideshow'] = array(
  183. 'title' => 'Slideshow',
  184. 'description' => 'Allows the user to configure the lightbox2 slideshow functionality',
  185. 'file' => 'lightbox2.admin.inc',
  186. 'page callback' => 'drupal_get_form',
  187. 'page arguments' => array('lightbox2_slideshow_settings_form'),
  188. 'access callback' => 'user_access',
  189. 'access arguments' => array('administer lightbox2'),
  190. 'type' => MENU_LOCAL_TASK,
  191. 'weight' => 1,
  192. );
  193. $items['admin/config/user-interface/lightbox2/html_content'] = array(
  194. 'title' => 'HTML Content',
  195. 'file' => 'lightbox2.admin.inc',
  196. 'page callback' => 'drupal_get_form',
  197. 'page arguments' => array('lightbox2_iframe_settings_form'),
  198. 'access callback' => 'user_access',
  199. 'access arguments' => array('administer lightbox2'),
  200. 'description' => 'Allows the user to configure the lightbox2 HTML content functionality.',
  201. 'type' => MENU_LOCAL_TASK,
  202. 'weight' => 2,
  203. );
  204. $items['admin/config/user-interface/lightbox2/automatic'] = array(
  205. 'title' => 'Automatic image handling',
  206. 'description' => 'Allows the user to configure the lightbox2 automatic image handling settings',
  207. 'file' => 'lightbox2.admin.inc',
  208. 'page callback' => 'drupal_get_form',
  209. 'page arguments' => array('lightbox2_auto_image_handling_settings_form'),
  210. 'access callback' => 'user_access',
  211. 'access arguments' => array('administer lightbox2'),
  212. 'type' => MENU_LOCAL_TASK,
  213. 'weight' => 3,
  214. );
  215. /**
  216. if (module_exists('emfield') && module_exists('emvideo')) {
  217. $items['video-cck/lightbox2/%node'] = array(
  218. 'page callback' => 'lightbox2_emvideo',
  219. 'page arguments' => array(2),
  220. 'access callback' => 'node_access',
  221. 'access arguments' => array('view', 2),
  222. 'type' => MENU_CALLBACK,
  223. );
  224. }
  225. */
  226. /**
  227. * There is not a version from acidfree to drupal 7
  228. if (module_exists('acidfree') && module_exists('video')) {
  229. $items['node/%node/lightframevideo'] = array(
  230. 'page callback' => 'lightbox2_acidfree_video',
  231. 'page arguments' => array(1),
  232. 'access callback' => 'lightbox2_acidfree_video_access',
  233. 'access arguments' => array(1),
  234. 'type' => MENU_CALLBACK,
  235. );
  236. }
  237. */
  238. $items['user/login/lightbox2'] = array(
  239. 'title' => 'Login',
  240. 'page callback' => 'lightbox2_login',
  241. 'access callback' => 'user_is_anonymous',
  242. 'type' => MENU_CALLBACK,
  243. );
  244. $items['contact/lightbox2'] = array(
  245. 'title' => 'Contact',
  246. 'page callback' => 'lightbox2_contact',
  247. 'access arguments' => array('access site-wide contact form'),
  248. 'type' => MENU_CALLBACK,
  249. );
  250. return $items;
  251. }
  252. /**
  253. * Acidfree video access control.
  254. */
  255. /**
  256. * No acidvideo for drupal 7
  257. * function lightbox2_acidfree_video_access($node) {
  258. if (user_access('play video') && node_access('view', $node)) {
  259. return TRUE;
  260. }
  261. return FALSE;
  262. }
  263. */
  264. /**
  265. * Implementation of hook_init().
  266. */
  267. function lightbox2_init() {
  268. if (lightbox2_exclude_these_paths() != 1) {
  269. lightbox2_add_files();
  270. }
  271. }
  272. /**
  273. * Implementation of hook_filter_tips().
  274. */
  275. /*
  276. * This is not used any more on drupal 7, keep here only to help with the
  277. * conversion, when there is a drupal 7 port, delete this function
  278. function lightbox2_filter_tips($delta, $format, $long = FALSE) {
  279. if ($delta == 0) {
  280. if (!$long) {
  281. return t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
  282. }
  283. else {
  284. $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>';
  285. $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightbox"&gt;image #1&lt;/a&gt;</code>') .'</p>';
  286. $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightbox[][my caption]"&gt;image #1&lt;/a&gt;</code>') .'</p>';
  287. $output .= '<p>'. t('To show a caption either use the title attribute or put in the second set of square brackets of the rel attribute.') .'</p>';
  288. $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>';
  289. $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br /> &lt;a href="image-2.jpg" rel="lightbox[roadtrip][caption 2]"&gt;image #2&lt;/a&gt;<br /> &lt;a href="image-3.jpg" rel="lightbox[roadtrip][caption 3]"&gt;image #3&lt;/a&gt;<br /> </code>') .'</p>';
  290. $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>';
  291. $output .= '<p>'. t('If you wish to turn the caption into a link, format your caption in the following way:') .'</p>';
  292. $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel=\'lightbox[][&lt;a href="http://www.yourlink.com"&gt;View Image Details&lt;/a&gt;]\' &gt;image #1&lt;/a&gt;</code>') .'</p>';
  293. return $output;
  294. }
  295. }
  296. elseif ($delta == 1) {
  297. return t('Image links from G2 are formatted for use with Lightbox2');
  298. }
  299. elseif ($delta == 2) {
  300. if (!$long) {
  301. return t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.');
  302. }
  303. else {
  304. $output = '<p>'. t('To add a lightbox slideshow to your images, add rel="lightshow[slideshowname][slide caption]" attribute to any link tag to activate the slideshow. For example:') .'</p>';
  305. $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightshow[show1]"&gt;image #1&lt;/a&gt;<br /> &lt;a href="image-2.jpg" rel="lightshow[show1]"&gt;image #2&lt;/a&gt;<br /> &lt;a href="image-3.jpg" rel="lightshow[show1]"&gt;image #3&lt;/a&gt;<br /> </code>') .'</p>';
  306. $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>';
  307. $output .= '<p>'. t('There are no limits to the number of slideshow image sets per page or how many images are allowed in each slideshow.') .'</p>';
  308. $output .= '<p>'. t('If you wish to turn the caption into a link, format your caption in the following way:') .'</p>';
  309. $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel=\'lightshow[show1][&lt;a href="http://www.yourlink.com"&gt;View Image Details&lt;/a&gt;]\'&gt;image #1&lt;/a&gt;</code>') .'</p>';
  310. return $output;
  311. }
  312. }
  313. elseif ($delta == 3) {
  314. if (!$long) {
  315. return t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
  316. }
  317. else {
  318. $output = '<p>'. t('It\'s possible to show webpage content in the lightbox, using iframes. In this case the "rel" attribute should be set to "lightframe". Again it\'s possible to group the content, (e.g. <code>lightframe[search][caption]</code>) but in addition to that, it\'s possible to control some of the iframe properties. It\'s possible to set the "width", "height" and "scrolling" properties of the iframe. The properties are separated from the group name by a <code>|</code>, for example <code>lightframe[search|width:100px;][caption]</code>. If no grouping is being used, then the <code>|</code> is still used and the format would be <code>lightframe[|width:100px;]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon. If no iframe properties are set, then the default width and height of 400px will be used. See below for more detailed examples.') .'</p>';
  319. $output .= '<p>'. t('Basic example:') .'<br />';
  320. $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe&quot;&gt;Search google&lt;/a&gt;</code>') .'</p>';
  321. $output .= '<p>'. t('Grouped example:') .'<br />';
  322. $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe[search][caption]&quot;&gt;Search google&lt;/a&gt;<br />&lt;a href=&quot;http://www.yahoo.com&quot; rel=&quot;lightframe[search]&quot;&gt;Search yahoo&lt;/a&gt;</code>') .'</p>';
  323. $output .= '<p>'. t('Controlling iframe property example:') .'<br />';
  324. $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe[|width:400px; height:300px; scrolling: auto;][caption]&quot;&gt;Search google&lt;/a&gt;</code>') .'</p>';
  325. $output .= '<p>'. t('Controlling iframe property when grouped example:') .'<br />';
  326. $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe[search|width:400px; height:300px; scrolling: auto;]&quot;&gt;Search google&lt;/a&gt;<br />&lt;a href=&quot;http://www.yahoo.com&quot; rel=&quot;lightframe[search|width:400px; height:300px;]&quot;&gt;Search yahoo&lt;/a&gt;</code>') .'</p>';
  327. return $output;
  328. }
  329. }
  330. elseif ($delta == 4) {
  331. if (!$long) {
  332. return t('Links to video content with \'rel="lightvideo"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
  333. }
  334. else {
  335. $output = '<p>'. t('It\'s possible to show video content in the lightbox. In this case the "rel" attribute should be set to <code>lightvideo</code>. It\'s possible to group videos and to control the size of the lightbox by setting the "width" and "height" properties. The properties can be configured like <code>lightvideo[group|width:300px; height: 200px;][caption]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon. If no properties are set, then the default width and height of 400px will be used. See below for more detailed examples.') .'</p>';
  336. $output .= '<p>'. t('Basic example:') .'<br />';
  337. $output .= t('<code>&lt;a href=&quot;http://video.google.com/videoplay?docid=1811233136844420765&quot; rel=&quot;lightvideo&quot;&gt;Google video example - default size&lt;/a&gt;</code>') .'</p>';
  338. $output .= '<p>'. t('Controlling lightbox size example:') .'<br />';
  339. $output .= t('<code>&lt;a href=&quot;http://video.google.com/videoplay?docid=1811233136844420765&quot; rel=&quot;lightvideo[group|width:400px; height:300px;][caption]&quot;&gt;Google video example - custom size&lt;/a&gt;</code>') .'</p>';
  340. $output .= '<p>'. t('Supported video formats include asx, wmv, mov and swf. A number of online video providers are also supported, including YouTube and Google Video. For a full list of the current supported video providers please see the documentation on drupal.org.') .'</p>';
  341. return $output;
  342. }
  343. }
  344. elseif ($delta == 5) {
  345. if (!$long) {
  346. return t('Links to inline or modal content with \'rel="lightmodal"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
  347. }
  348. else {
  349. $output = '<p>'. t('It\'s possible to show HTML snippets in the lightbox, that is on the same domain. In this case the "rel" attribute should be set to "lightmodal". Again it\'s possible to group the content, (e.g. <code>lightmodal[group][caption]</code>) but in addition to that, it\'s possible to control some of the modal properties. It\'s possible to set the "width", "height" and "scrolling" properties of the modal. The properties are separated from the group name by a <code>|</code>, for example <code>lightmodal[group|width:100px;][caption]</code>. If no grouping is being used, then the <code>|</code> is still used and the format would be <code>lightmodal[|width:100px;]</code>. The properties should all be of the format "property: value;" - note the closing semi-colon. If no modal properties are set, then the default width and height of 400px will be used. See below for more detailed examples.') .'</p>';
  350. $output .= '<p>'. t('Basic example:') .'<br />';
  351. $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal&quot;&gt;Search&lt;/a&gt;</code>') .'</p>';
  352. $output .= '<p>'. t('Grouped example:') .'<br />';
  353. $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal[search][caption 1]&quot;&gt;Search&lt;/a&gt;<br />&lt;a href=&quot;search.php?status=1&quot; rel=&quot;lightmodal[search]&quot;&gt;Search published&lt;/a&gt;</code>') .'</p>';
  354. $output .= '<p>'. t('Controlling modal property example:') .'<br />';
  355. $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal[|width:400px; height:300px; scrolling: auto;][caption]&quot;&gt;Search&lt;/a&gt;</code>') .'</p>';
  356. $output .= '<p>'. t('Controlling modal property when grouped example:') .'<br />';
  357. $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal[search|width:400px; height:300px; scrolling: auto;]&quot;&gt;Search&lt;/a&gt;<br />&lt;a href=&quot;search.php?status=1&quot; rel=&quot;lightmodal[search|width:400px; height:300px;]&quot;&gt;Search published&lt;/a&gt;</code>') .'</p>';
  358. return $output;
  359. }
  360. }
  361. }
  362. /**
  363. * Implementation of hook_filter().
  364. */
  365. /*
  366. * This is not used any more on drupal 7, keep here only to help with the
  367. * conversion, when there is a drupal 7 port, delete this function
  368. function lightbox2_filter($op, $delta = 0, $format = -1, $text = '') {
  369. switch ($op) {
  370. case 'list':
  371. return array(
  372. 0 => t('Lightbox filter'),
  373. 1 => t('Lightbox G2 filter'),
  374. 2 => t('Lightbox slideshow filter'),
  375. 3 => t('Lightbox iframe filter'),
  376. 4 => t('Lightbox video filter'),
  377. 5 => t('Lightbox modal filter'),
  378. 6 => t('Disable Lightbox iframe filter'),
  379. );
  380. case 'description':
  381. if ($delta == 0) {
  382. return t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
  383. }
  384. elseif ($delta == 1) {
  385. return t('Turns g2_filter links into Lightbox2 appropriate links');
  386. }
  387. elseif ($delta == 2) {
  388. return t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.');
  389. }
  390. elseif ($delta == 3) {
  391. return t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
  392. }
  393. elseif ($delta == 4) {
  394. return t('Links to video content with \'rel="lightvideo"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
  395. }
  396. elseif ($delta == 5) {
  397. return t('Links to inline or modal content with \'rel="lightmodal"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
  398. }
  399. elseif ($delta == 6) {
  400. return t('It\'s possible to show webpage content in the lightbox, using iframes. In this case the "rel" attribute should be set to "lightframe". However, users can do this without any filters to be enabled. To prevent users from adding iframes to the site in this manner, then please enable this option.');
  401. }
  402. case 'process':
  403. if ($delta == 1) {
  404. $text = ' '. $text .' ';
  405. $text = preg_replace('/ShowItem/', 'DownloadItem', $text);
  406. $text = preg_replace('/<img\s+([^>]*?)src="/', '<img \1rel="lightbox" src="', $text);
  407. $text = drupal_substr($text, 1, -1);
  408. }
  409. elseif ($delta == 6) {
  410. $text = preg_replace('/<a([^>]*?)(rel=[\'"]*lightframe[\'"]*)([^>]*?)>/i', '<a\1\3>', $text);
  411. }
  412. return $text;
  413. default:
  414. return $text;
  415. }
  416. }
  417. */
  418. /**
  419. * Process callback for Lightbox G2 filter.
  420. */
  421. function _lightbox2_process_filter($text, $format) {
  422. $text = ' ' . $text . ' ';
  423. $text = preg_replace('/ShowItem/', 'DownloadItem', $text);
  424. $text = preg_replace('/src="/', 'rel="lightbox" src="', $text);
  425. $text = drupal_substr($text, 1, -1);
  426. return $text;
  427. }
  428. /**
  429. * Process callback for Disable Lightbox iframe filter.
  430. */
  431. function _lightbox2_process_disable_filter($text, $format) {
  432. $text = preg_replace('/<a([^>]*?)(rel=[\'"]*lightframe[\'"]*)([^>]*?)>/i', '<a\1\3>', $text);
  433. return $text;
  434. }
  435. /**
  436. * Implements hook_filter_info().
  437. */
  438. function lightbox2_filter_info() {
  439. $filters = array();
  440. $filters['lightbox2_filter'] = array(
  441. 'title' => t('Lightbox filter'),
  442. 'description' => t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
  443. );
  444. $filters['lightbox2_gd_filter'] = array(
  445. 'title' => t('Lightbox GD filter'),
  446. 'description' => t('Turns g2_filter links into Lightbox2 appropriate links'),
  447. 'process callback' => '_lightbox2_process_filter',
  448. );
  449. $filters['lightbox_slideshow_filter'] = array(
  450. 'title' => t('Lightbox slideshow filter'),
  451. 'description' => t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.'),
  452. );
  453. $filters['lightbox_iframe_filter'] = array(
  454. 'title' => t('Lightbox iframe filter'),
  455. 'description' => t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
  456. );
  457. $filters['lightbox_video_filter'] = array(
  458. 'title' => t('Lightbox video filter'),
  459. 'description' => t('Links to video content with \'rel="lightvideo"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
  460. );
  461. $filters['lightbox_modal_filter'] = array(
  462. 'title' => t('Lightbox modal filter'),
  463. 'description' => t('Links to inline or modal content with \'rel="lightmodal"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
  464. );
  465. $filters['lightbox_disable_iframe_filter'] = array(
  466. 'title' => t('Disable Lightbox iframe filter'),
  467. 'description' => t('It\'s possible to show webpage content in the lightbox, using iframes. In this case the "rel" attribute should be set to "lightframe". However, users can do this without any filters to be enabled. To prevent users from adding iframes to the site in this manner, then please enable this option.'),
  468. 'process callback' => '_lightbox2_process_disable_filter',
  469. );
  470. return ($filters);
  471. }
  472. /**
  473. * Provide links to the CSS stylesheet and JS file associated with
  474. * this module.
  475. */
  476. function lightbox2_add_files() {
  477. global $language, $user;
  478. static $already_added = FALSE;
  479. if ($already_added) {
  480. return; // Don't add the JavaScript and CSS multiple times.
  481. }
  482. $already_added = TRUE;
  483. // Load required js and css files.
  484. $path = drupal_get_path('module', 'lightbox2');
  485. // Initialise some variables.
  486. $inline_image_handler = variable_get('lightbox2_inline', 0);
  487. $flickr_image_handler = variable_get('lightbox2_flickr', 0);
  488. $gallery2_block_handler = variable_get('lightbox2_gallery2_blocks', 0);
  489. $image_assist_handler = variable_get('lightbox2_image_assist_custom', 0);
  490. $image_node_handler = variable_get('lightbox2_image_node', 0);
  491. $custom_class_handler = 0;
  492. switch (variable_get('lightbox2_custom_class_handler', 0)) {
  493. case 1:
  494. $custom_class_handler = 'lightbox_ungrouped';
  495. break;
  496. case 2:
  497. $custom_class_handler = 'lightbox';
  498. break;
  499. case 3:
  500. $custom_class_handler = 'lightshow';
  501. break;
  502. case 4:
  503. $custom_class_handler = 'lightframe_ungrouped';
  504. break;
  505. case 5:
  506. $custom_class_handler = 'lightframe';
  507. break;
  508. }
  509. // Set the list of image classes to format urls for.
  510. $image_node_sizes = '';
  511. $trigger_lightbox_classes = '';
  512. $trigger_lightbox_group_classes = '';
  513. $trigger_slideshow_classes = '';
  514. $trigger_lightframe_classes = '';
  515. $trigger_lightframe_group_classes = '';
  516. // Inline module images.
  517. switch ($inline_image_handler) {
  518. case 1:
  519. $trigger_lightbox_classes .= 'img.inline,';
  520. break;
  521. case 2:
  522. $trigger_lightbox_group_classes .= 'img.inline,';
  523. break;
  524. case 3:
  525. $trigger_slideshow_classes .= 'img.inline,';
  526. break;
  527. case 4:
  528. $trigger_lightframe_classes .= 'img.inline,';
  529. break;
  530. case 5:
  531. $trigger_lightframe_group_classes .= 'img.inline,';
  532. break;
  533. }
  534. // Flickr images.
  535. switch ($flickr_image_handler) {
  536. case 1:
  537. $trigger_lightbox_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
  538. break;
  539. case 2:
  540. $trigger_lightbox_group_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
  541. break;
  542. case 3:
  543. $trigger_slideshow_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
  544. break;
  545. case 4:
  546. $trigger_lightframe_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
  547. break;
  548. case 5:
  549. $trigger_lightframe_group_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
  550. break;
  551. }
  552. // Gallery2 block images.
  553. switch ($gallery2_block_handler) {
  554. case 1:
  555. $trigger_lightbox_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
  556. break;
  557. case 2:
  558. $trigger_lightbox_group_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
  559. break;
  560. case 3:
  561. $trigger_slideshow_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
  562. break;
  563. case 4:
  564. $trigger_lightframe_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
  565. break;
  566. case 5:
  567. $trigger_lightframe_group_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
  568. break;
  569. }
  570. // Image Assist custom size images.
  571. switch ($image_assist_handler) {
  572. case 1:
  573. $trigger_lightbox_classes .= 'img.image-img_assist_custom,';
  574. break;
  575. case 2:
  576. $trigger_lightbox_group_classes .= 'img.image-img_assist_custom,';
  577. break;
  578. case 3:
  579. $trigger_slideshow_classes .= 'img.image-img_assist_custom,';
  580. break;
  581. case 4:
  582. $trigger_lightframe_classes .= 'img.image-img_assist_custom,';
  583. break;
  584. case 5:
  585. $trigger_lightframe_group_classes .= 'img.image-img_assist_custom,';
  586. break;
  587. }
  588. // Image nodes.
  589. if ($image_node_handler) {
  590. $trigger_sizes = variable_get('lightbox2_trigger_image_size', array('thumbnail'));
  591. usort($trigger_sizes, "sort_by_length");
  592. foreach ($trigger_sizes as $size) {
  593. $triggers = "img.$size, img.image-$size,";
  594. if (empty($size)) {
  595. if (user_access('view original images')) {
  596. $triggers = "img._original, img.image-_original,";
  597. }
  598. }
  599. else {
  600. $image_node_sizes .= "\.$size|";
  601. }
  602. switch ($image_node_handler) {
  603. case 1:
  604. $trigger_lightbox_classes .= $triggers;
  605. break;
  606. case 2:
  607. $trigger_lightbox_group_classes .= $triggers;
  608. break;
  609. case 3:
  610. $trigger_slideshow_classes .= $triggers;
  611. break;
  612. case 4:
  613. $trigger_lightframe_classes .= $triggers;
  614. break;
  615. case 5:
  616. $trigger_lightframe_group_classes .= $triggers;
  617. break;
  618. }
  619. }
  620. }
  621. // Custom images.
  622. $custom_triggers = variable_get('lightbox2_custom_trigger_classes', '');
  623. $custom_trigger_classes = '';
  624. if ($custom_class_handler && !empty($custom_triggers)) {
  625. $trigger_classes = preg_split("/(\r\n|\n)/", $custom_triggers);
  626. foreach ($trigger_classes as $class) {
  627. if (!empty($class)) {
  628. $custom_trigger_classes .= "img.$class,";
  629. }
  630. }
  631. }
  632. $trigger_lightbox_classes = rtrim($trigger_lightbox_classes, ",");
  633. $trigger_lightbox_group_classes = rtrim($trigger_lightbox_group_classes, ",");
  634. $trigger_slideshow_classes = rtrim($trigger_slideshow_classes, ",");
  635. $trigger_lightframe_classes = rtrim($trigger_lightframe_classes, ",");
  636. $trigger_lightframe_group_classes = rtrim($trigger_lightframe_group_classes, ",");
  637. $custom_trigger_classes = rtrim($custom_trigger_classes, ",");
  638. $image_node_sizes = '(' . rtrim($image_node_sizes, "|") . ')';
  639. $enable_video = variable_get('lightbox2_enable_video', FALSE);
  640. $enable_login = $user->uid == 0 && variable_get('lightbox2_enable_login', FALSE);
  641. $enable_contact = module_exists('contact') && variable_get('lightbox2_enable_contact', FALSE) && user_access('access site-wide contact form');
  642. $display_image_size = variable_get('lightbox2_display_image_size', 'original');
  643. if ($display_image_size == 'original' && user_access('view original images')) {
  644. $display_image_size = '';
  645. }
  646. $font_color = variable_get('lightbox2_font_color', '000');
  647. $box_color = variable_get('lightbox2_box_color', 'fff');
  648. $file_path = base_path() . '(\w\w/)' . file_default_scheme() . ':/';
  649. if ( variable_get('file_downloads', 'FILE_DOWNLOADS_PUBLIC') == 'FILE_DOWNLOADS_PRIVATE' ) {
  650. $file_path = base_path() . '(\w\w/)system/files';
  651. }
  652. // Load the javascript settings.
  653. $js_settings = array(
  654. 'rtl' => $language->direction,
  655. 'file_path' => $file_path,
  656. 'default_image' => base_path() . $path . '/images/brokenimage.jpg',
  657. 'border_size' => (int) variable_get('lightbox2_border_size', 10),
  658. 'font_color' => !empty($font_color) ? $font_color : '000',
  659. 'box_color' => !empty($box_color) ? $box_color : '000',
  660. 'top_position' => variable_get('lightbox2_top_position', ''),
  661. 'overlay_opacity' => str_replace(',', '.', variable_get('lightbox2_overlay_opacity', 0.8)),
  662. 'overlay_color' => variable_get('lightbox2_overlay_color', '000'),
  663. 'disable_close_click' => variable_get('lightbox2_disable_close_click', TRUE),
  664. 'resize_sequence' => (int)variable_get('lightbox2_resize_sequence', 0),
  665. 'resize_speed' => 1000 * str_replace(',', '.', variable_get('lightbox2_resize_speed', 0.4)),
  666. 'fade_in_speed' => 1000 * str_replace(',', '.', variable_get('lightbox2_fadein_speed', 0.4)),
  667. 'slide_down_speed' => 1000 * str_replace(',', '.', variable_get('lightbox2_slidedown_speed', 0.6)),
  668. 'use_alt_layout' => variable_get('lightbox2_use_alt_layout', FALSE),
  669. 'disable_resize' => variable_get('lightbox2_disable_resize', FALSE),
  670. 'disable_zoom' => variable_get('lightbox2_disable_zoom', FALSE),
  671. 'force_show_nav' => variable_get('lightbox2_force_show_nav', FALSE),
  672. 'show_caption' => variable_get('lightbox2_show_caption', TRUE),
  673. 'loop_items' => variable_get('lightbox2_loop_items', FALSE),
  674. 'node_link_text' => check_plain(variable_get('lightbox2_node_link_text', 'View Image Details')),
  675. 'node_link_target' => variable_get('lightbox2_node_link_target', FALSE),
  676. 'image_count' => check_plain(variable_get('lightbox2_image_count_str', 'Image !current of !total')),
  677. 'video_count' => check_plain(variable_get('lightbox2_video_count_str', 'Video !current of !total')),
  678. 'page_count' => check_plain(variable_get('lightbox2_page_count_str', 'Page !current of !total')),
  679. 'lite_press_x_close' => t('press !x to close', array('!x' => '<a href="#" onclick="hideLightbox(); return FALSE;"><kbd>x</kbd></a>')),
  680. 'download_link_text' => '',
  681. 'enable_login' => $enable_login,
  682. 'enable_contact' => $enable_contact,
  683. // Automatic image handling settings.
  684. 'keys_close' => variable_get('lightbox2_keys_close', 'c x 27'),
  685. 'keys_previous' => variable_get('lightbox2_keys_previous', 'p 37'),
  686. 'keys_next' => variable_get('lightbox2_keys_next', 'n 39'),
  687. 'keys_zoom' => variable_get('lightbox2_keys_zoom', 'z'),
  688. 'keys_play_pause' => variable_get('lightbox2_keys_play_pause', '32'),
  689. 'display_image_size' => $display_image_size,
  690. 'image_node_sizes' => $image_node_sizes,
  691. 'trigger_lightbox_classes' => $trigger_lightbox_classes,
  692. 'trigger_lightbox_group_classes' => $trigger_lightbox_group_classes,
  693. 'trigger_slideshow_classes' => $trigger_slideshow_classes,
  694. 'trigger_lightframe_classes' => $trigger_lightframe_classes,
  695. 'trigger_lightframe_group_classes' => $trigger_lightframe_group_classes,
  696. 'custom_class_handler' => $custom_class_handler,
  697. 'custom_trigger_classes' => $custom_trigger_classes,
  698. 'disable_for_gallery_lists' => variable_get('lightbox2_disable_nested_galleries', TRUE),
  699. 'disable_for_acidfree_gallery_lists' => variable_get('lightbox2_disable_nested_acidfree_galleries', TRUE),
  700. 'enable_acidfree_videos' => variable_get('lightbox2_enable_acidfree_videos', TRUE),
  701. // Slideshow settings.
  702. 'slideshow_interval' => variable_get('lightbox2_slideshow_interval', 5) * 1000,
  703. 'slideshow_automatic_start' => variable_get('lightbox2_slideshow_automatic_start', TRUE),
  704. 'slideshow_automatic_exit' => variable_get('lightbox2_slideshow_automatic_exit', TRUE),
  705. 'show_play_pause' => variable_get('lightbox2_slideshow_show_play_pause', TRUE),
  706. 'pause_on_next_click' => variable_get('lightbox2_slideshow_pause_on_next_click', FALSE),
  707. 'pause_on_previous_click' => variable_get('lightbox2_slideshow_pause_on_previous_click', TRUE),
  708. 'loop_slides' => variable_get('lightbox2_loop_slides', FALSE),
  709. // Iframe settings.
  710. 'iframe_width' => (int)variable_get('lightbox2_default_frame_width', 600),
  711. 'iframe_height' => (int)variable_get('lightbox2_default_frame_height', 400),
  712. 'iframe_border' => (int)variable_get('lightbox2_frame_border', 1),
  713. // Video settings.
  714. 'enable_video' => $enable_video,
  715. );
  716. if ($enable_video) {
  717. $js_settings['flvPlayer'] = url(check_plain(trim(variable_get('lightbox2_flv_player_path', 'flvplayer.swf'), '/')));
  718. $js_settings['flvFlashvars'] = check_plain(variable_get('lightbox2_flv_player_flashvars', ''));
  719. }
  720. // Only supply these if the user has the correct permissions.
  721. if (user_access('download original image') && user_access('view original images')) {
  722. $js_settings['download_link_text'] = check_plain(variable_get('lightbox2_download_link_text', 'Download Original'));
  723. }
  724. drupal_add_js(array('lightbox2' => $js_settings), array( 'type' => 'setting' ) );
  725. // Check where we should load the javascript files - header or footer.
  726. $js_location = variable_get('lightbox2_js_location', 'header');
  727. // Lightbox2 Plus.
  728. if (!variable_get('lightbox2_lite', FALSE)) {
  729. $css = $path . '/css/lightbox.css';
  730. if (variable_get('lightbox2_use_alt_layout', FALSE)) {
  731. $css = $path . '/css/lightbox_alt.css';
  732. }
  733. drupal_add_css($css);
  734. // Check to see if any automatic image handling options are enabled.
  735. if ($image_node_handler || $flickr_image_handler || $gallery2_block_handler || $inline_image_handler || $image_assist_handler || $custom_triggers != '') {
  736. drupal_add_js($path . '/js/auto_image_handling.js', array( 'scope' => $js_location ) );
  737. }
  738. if (variable_get('lightbox2_enable_video', FALSE)) {
  739. drupal_add_js($path . '/js/lightbox_video.js', array( 'scope' => $js_location ) );
  740. }
  741. if ($enable_login || $enable_contact) {
  742. drupal_add_js($path . '/js/lightbox_modal.js', array( 'scope' => $js_location ) );
  743. }
  744. //drupal_add_js($path .'/js/prototype.js', array( 'scope' => $js_location, 'cache' => false ) );
  745. //drupal_add_js($path .'/js/scriptaculous.js', array( 'scope' => $js_location, 'cache' => false ) );
  746. drupal_add_js($path . '/js/lightbox.js', array( 'scope' => $js_location , 'cache' => FALSE) );
  747. }
  748. // Lightbox Lite.
  749. else {
  750. $css = $path . '/css/lightbox_lite.css';
  751. drupal_add_css($css);
  752. drupal_add_js($path . '/js/lightbox_lite.js', array( 'scope' => $js_location ) );
  753. }
  754. }
  755. /**
  756. * Implementation of hook_field_formatter_info().
  757. *
  758. * Add certain lightbox and imagecache formatters to CCK image fields if
  759. * the imagefield.module and the imagecache.module exist. Add additional
  760. * formatters if emfield, emimage and/or emvideo modules exist.
  761. */
  762. function lightbox2_field_formatter_info() {
  763. $formatters = array();
  764. if (module_exists('image')) {
  765. $image = $lightbox = image_styles();
  766. $types = array('lightbox', 'lightshow');
  767. foreach ($types as $type) {
  768. foreach ($image as $image_key => $image_value ) {
  769. $formatters['lightbox2__' . $type . '__' . $image_key . '__original'] = array(
  770. 'label' => 'Lightbox2: ' . $type . ': ' . $image_key . '->original',
  771. 'field types' => array('image'),
  772. );
  773. foreach ($lightbox as $lightbox_key => $lightbox_value ) {
  774. $formatters['lightbox2__' . $type . '__' . $image_key . "__" . $lightbox_key] = array(
  775. 'label' => 'Lightbox2: ' . $type . ': ' . $image_key . '->' . $lightbox_key,
  776. 'field types' => array('image'),
  777. );
  778. }
  779. }
  780. }
  781. }
  782. return $formatters;
  783. /*
  784. // Handle imagefield and filefield images.
  785. if (module_exists('image')) {
  786. $rules = array();
  787. if (function_exists('image_styles')) {
  788. $presets = image_styles();
  789. foreach ($presets as $preset_id => $preset_info) {
  790. $rules[$preset_id] = $preset_info['name'];
  791. }
  792. }
  793. $iframe['image__lightframe2__original__node'] = array(
  794. 'label' => 'Lightbox2 iframe: original->node page',
  795. 'field types' => array('image', 'file'),
  796. );
  797. $iframe['imagefield__lightframe2__link__node'] = array(
  798. 'label' => 'Lightbox2 iframe: link->node page',
  799. 'field types' => array('image', 'file'),
  800. );
  801. foreach ($rules as $view_rule) {
  802. $lightbox['image__lightbox2__original__'. $view_rule] = array(
  803. 'label' => 'Lightbox2: original->'. $view_rule,
  804. 'field types' => array('image', 'file'),
  805. );
  806. $lightbox['imagefield__lightbox2_compact__original__'. $view_rule] = array(
  807. 'label' => 'Lightbox2: original->'. $view_rule . ' compact',
  808. 'field types' => array('image', 'file'),
  809. );
  810. $lightbox['image__lightbox2__'. $view_rule .'__original'] = array(
  811. 'label' => 'Lightbox2: '. $view_rule .'->original',
  812. 'field types' => array('image', 'file'),
  813. );
  814. $lightbox['imagefield__lightbox2_compact__'. $view_rule .'__original'] = array(
  815. 'label' => 'Lightbox2: '. $view_rule .'->original compact',
  816. 'field types' => array('image', 'file'),
  817. );
  818. $lightbox['imagefield__lightbox2__link__'. $view_rule] = array(
  819. 'label' => 'Lightbox2: link->'. $view_rule,
  820. 'field types' => array('image', 'file'),
  821. );
  822. $slideshow['image__lightshow2__original__'. $view_rule] = array(
  823. 'label' => 'Lightbox2 slideshow: original->'. $view_rule,
  824. 'field types' => array('image', 'file'),
  825. );
  826. $slideshow['imagefield__lightshow2_compact__original__'. $view_rule] = array(
  827. 'label' => 'Lightbox2 slideshow: original->'. $view_rule . ' compact',
  828. 'field types' => array('image', 'filefield'),
  829. );
  830. $slideshow['image__lightshow2__'. $view_rule .'__original'] = array(
  831. 'label' => 'Lightbox2 slideshow: '. $view_rule .'->original',
  832. 'field types' => array('image', 'file'),
  833. );
  834. $slideshow['imagefield__lightshow2_compact__'. $view_rule .'__original'] = array(
  835. 'label' => 'Lightbox2 slideshow: '. $view_rule .'->original compact',
  836. 'field types' => array('image', 'filefield'),
  837. );
  838. $slideshow['imagefield__lightshow2__link__'. $view_rule] = array(
  839. 'label' => 'Lightbox2 slideshow: link->'. $view_rule,
  840. 'field types' => array('image', 'filefield'),
  841. );
  842. $iframe['image__lightframe2__'. $view_rule .'__node'] = array(
  843. 'label' => 'Lightbox2 iframe: '. $view_rule .'->node page',
  844. 'field types' => array('image', 'file'),
  845. );
  846. foreach ($rules as $lightbox_rule) {
  847. $lightbox['image__lightbox2__'. $view_rule .'__'. $lightbox_rule] = array(
  848. 'label' => 'Lightbox2: '. $view_rule .'->'. $lightbox_rule,
  849. 'field types' => array('image', 'file'),
  850. );
  851. $lightbox['imagefield__lightbox2_compact__'. $view_rule .'__'. $lightbox_rule] = array(
  852. 'label' => 'Lightbox2: '. $view_rule .'->'. $lightbox_rule . ' compact',
  853. 'field types' => array('image', 'filefield'),
  854. );
  855. $slideshow['image__lightshow2__'. $view_rule .'__'. $lightbox_rule] = array(
  856. 'label' => 'Lightbox2 slideshow: '. $view_rule .'->'. $lightbox_rule,
  857. 'field types' => array('image', 'file'),
  858. );
  859. $slideshow['imagefield__lightshow2_compact__'. $view_rule .'__'. $lightbox_rule] = array(
  860. 'label' => 'Lightbox2 slideshow: '. $view_rule .'->'. $lightbox_rule . ' compact',
  861. 'field types' => array('image', 'filefield'),
  862. );
  863. }
  864. }
  865. // Adding them now so they are in some sort of sensible order.
  866. $formatters = array_merge($lightbox, $slideshow, $iframe);
  867. }
  868. if (module_exists('emfield') && module_exists('emimage')) {
  869. $formatters['emimage_lightbox2'] = array(
  870. 'label' => t('Lightbox2: Image Thumbnail -> Original'),
  871. 'field types' => array('emimage'),
  872. );
  873. $formatters['emimage_lightshow2'] = array(
  874. 'label' => t('Lightbox2 slideshow: Image Thumbnail -> Original'),
  875. 'field types' => array('emimage'),
  876. );
  877. $formatters['emimage_lightframe2'] = array(
  878. 'label' => t('Lightbox2 iframe: Image Thumbnail -> Content'),
  879. 'field types' => array('emimage'),
  880. );
  881. }
  882. if (variable_get('lightbox2_enable_video', FALSE) && module_exists('emfield') && module_exists('emvideo')) {
  883. $formatters['emvideo_lightvideo'] = array(
  884. 'label' => t('Lightbox2: Image Thumbnail -> Full Size Video'),
  885. 'field types' => array('emvideo'),
  886. );
  887. }
  888. if (module_exists('file')) {
  889. $formatters['file_lightframe'] = array(
  890. 'label' => t('Lightbox2 iframe'),
  891. 'field types' => array('file'),
  892. );
  893. }
  894. */
  895. }
  896. /**
  897. * Implements hook_field_formatter_view().
  898. *
  899. * Temporarily a (pretty much) straight copy of image's
  900. */
  901. function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  902. $element = array();
  903. $pieces = explode('__', $display['type']);
  904. $lightbox_type = $pieces[1];
  905. $image_style = $pieces[2];
  906. $lightbox_style = $pieces[3];
  907. if ($image_style == 'original') {
  908. $image_style = NULL;
  909. }
  910. if ($lightbox_style == 'original') {
  911. $lightbox_style = NULL;
  912. }
  913. if ($entity_type == 'node') {
  914. $node_id = $entity->nid;
  915. }
  916. foreach ($items as $delta => $item) {
  917. $uri = array(
  918. 'path' => file_create_url($item['uri']),
  919. 'options' => array(),
  920. );
  921. $element[$delta] = array(
  922. '#theme' => 'lightbox2_image',
  923. '#item' => $item,
  924. '#lightbox_type' => $lightbox_type,
  925. '#image_style' => $image_style,
  926. '#lightbox_style' => $lightbox_style,
  927. '#path' => $uri,
  928. '#node_id' => $node_id,
  929. '#field_name' => $field['field_name'],
  930. );
  931. }
  932. return ($element);
  933. /*$element = array();
  934. // Check if the formatter involves a particular image style.
  935. //$matches = array();
  936. //if (preg_match('/__([a-z0-9_]+)/', $display['type'], $matches)) {
  937. // $image_style = $matches[1];
  938. //}
  939. $pieces = explode('__', $display);
  940. $image_style = $pieces[2];
  941. // Temporary hardcoding link_file and image_style for debugging
  942. //$image_style = 'thumbnail';
  943. $link_file = TRUE;
  944. foreach ($items as $delta => $item) {
  945. if (isset($link_file)) {
  946. $uri = array(
  947. 'path' => file_create_url($item['uri']),
  948. 'options' => array(),
  949. );
  950. }
  951. $element[$delta] = array(
  952. '#theme' => 'lightbox2_image',
  953. '#item' => $item,
  954. '#image_style' => isset($image_style) ? $image_style : '',
  955. '#path' => isset($uri) ? $uri : '',
  956. );
  957. }
  958. return $element;*/
  959. }
  960. /**
  961. * Implementation of hook_theme().
  962. */
  963. function lightbox2_theme($existing, $type, $theme, $path) {
  964. $theme = array();
  965. $theme['lightbox2_image'] = array(
  966. 'variables' => array(
  967. 'item' => NULL,
  968. 'path' => NULL,
  969. 'lightbox_type' => NULL,
  970. 'image_style' => NULL,
  971. 'lightbox_style' => NULL,
  972. 'node_id' => NULL,
  973. 'field_name' => NULL,
  974. ),
  975. //'variables' => array(),
  976. );
  977. //return($theme);
  978. /*
  979. $theme = array(
  980. 'lightbox2_image' => array(
  981. 'variables' => array(
  982. 'item' => NULL,
  983. 'path' => NULL,
  984. 'image_style' => NULL
  985. ),
  986. ),
  987. // Emfield theme functions.
  988. 'lightbox2_emimage' => array(
  989. 'variables' => array(
  990. 'field' => NULL,
  991. 'item' => NULL,
  992. 'formatter' => NULL,
  993. 'node' => NULL,
  994. 'args' => array()
  995. ),
  996. ),
  997. 'lightbox2_formatter_emimage' => array(
  998. 'render element' => 'element',
  999. ),
  1000. 'lightbox2_formatter_emimage_lightbox2' => array(
  1001. 'render element' => 'element',
  1002. 'function' => 'theme_lightbox2_formatter_emimage',
  1003. ),
  1004. 'lightbox2_formatter_emimage_lightshow2' => array(
  1005. 'render element' => 'element',
  1006. 'function' => 'theme_lightbox2_formatter_emimage',
  1007. ),
  1008. 'lightbox2_formatter_emimage_lightframe2' => array(
  1009. 'render element' => 'element',
  1010. 'function' => 'theme_lightbox2_formatter_emimage',
  1011. ),
  1012. 'lightbox2_formatter_emvideo_lightvideo' => array(
  1013. 'render element' => 'element',
  1014. ),
  1015. 'lightbox2_emvideo' => array(
  1016. 'variables' => array(
  1017. 'field' => NULL,
  1018. 'item' => NULL,
  1019. 'formatter' => NULL,
  1020. 'node' => NULL
  1021. ),
  1022. ),
  1023. // Filefield theme functions.
  1024. 'lightbox2_formatter_filefield_lightframe' => array(
  1025. 'render element' => 'element',
  1026. ),
  1027. 'lightbox2_file_formatter_lightbox2_iframe' => array(
  1028. 'variables' => array(
  1029. 'file' => NULL,
  1030. 'field' => NULL,
  1031. 'file_formatter_settings' => NULL
  1032. ),
  1033. ),
  1034. // Global imagecache + imagefield theme functions.
  1035. 'lightbox2_formatter_imagefield' => array(
  1036. 'render element' => 'element',
  1037. ),
  1038. 'imagefield_image_imagecache_lightbox2' => array(
  1039. 'variables' => array(
  1040. 'view_preset' => NULL,
  1041. 'field_name' => NULL,
  1042. 'item' => NULL,
  1043. 'node' => NULL,
  1044. 'rel' => 'lightbox',
  1045. 'args' => array()
  1046. ),
  1047. ),
  1048. );
  1049. // Additional imagecache + imagefield theme functions, by preset.
  1050. if (module_exists("image")) {
  1051. $theme['lightbox2_formatter_imagefield__lightframe2__original__node'] = array(
  1052. 'render element' => 'element',
  1053. 'function' => 'theme_lightbox2_formatter_imagefield',
  1054. );
  1055. $theme['lightbox2_formatter_imagefield__lightframe2__link__node'] = array(
  1056. 'arguments' => array('element' => NULL),
  1057. 'function' => 'theme_lightbox2_formatter_imagefield',
  1058. 'file' => 'lightbox2.formatter.inc',
  1059. );
  1060. foreach (image_styles() as $src) {
  1061. $theme['lightbox2_formatter_imagefield__lightbox2__'. $src['name'] .'__original'] = array(
  1062. 'render element' => 'element',
  1063. 'function' => 'theme_lightbox2_formatter_imagefield',
  1064. 'file' => 'lightbox2.formatter.inc',
  1065. );
  1066. $theme['lightbox2_formatter_imagefield__lightbox2_compact__'. $src['name'] .'__original'] = array(
  1067. 'arguments' => array('element' => NULL),
  1068. 'function' => 'theme_lightbox2_formatter_imagefield',
  1069. 'file' => 'lightbox2.formatter.inc',
  1070. );
  1071. $theme['lightbox2_formatter_imagefield__lightshow2__'. $src['name'] .'__original'] = array(
  1072. 'render element' => 'element',
  1073. 'function' => 'theme_lightbox2_formatter_imagefield',
  1074. );
  1075. $theme['lightbox2_formatter_imagefield__lightshow2_compact__'. $src['name'] .'__original'] = array(
  1076. 'arguments' => array('element' => NULL),
  1077. 'function' => 'theme_lightbox2_formatter_imagefield',
  1078. 'file' => 'lightbox2.formatter.inc',
  1079. );
  1080. $theme['lightbox2_formatter_imagefield__lightbox2__original__'. $src['name']] = array(
  1081. 'render element' => 'element',
  1082. 'function' => 'theme_lightbox2_formatter_imagefield',
  1083. );
  1084. $theme['lightbox2_formatter_imagefield__lightbox2_compact__original__'. $src['name']] = array(
  1085. 'arguments' => array('element' => NULL),
  1086. 'function' => 'theme_lightbox2_formatter_imagefield',
  1087. 'file' => 'lightbox2.formatter.inc',
  1088. );
  1089. $theme['lightbox2_formatter_imagefield__lightshow2__original__'. $src['name']] = array(
  1090. 'render element' => 'element',
  1091. 'function' => 'theme_lightbox2_formatter_imagefield',
  1092. );
  1093. $theme['lightbox2_formatter_imagefield__lightshow2_compact__original__'. $src['name']] = array(
  1094. 'arguments' => array('element' => NULL),
  1095. 'function' => 'theme_lightbox2_formatter_imagefield',
  1096. 'file' => 'lightbox2.formatter.inc',
  1097. );
  1098. $theme['lightbox2_formatter_imagefield__lightframe2__'. $src['name'] .'__node'] = array(
  1099. 'render element' => 'element',
  1100. 'function' => 'theme_lightbox2_formatter_imagefield',
  1101. );
  1102. $theme['lightbox2_formatter_imagefield__lightbox2__link__'. $src['name']] = array(
  1103. 'arguments' => array('element' => NULL),
  1104. 'function' => 'theme_lightbox2_formatter_imagefield',
  1105. 'file' => 'lightbox2.formatter.inc',
  1106. );
  1107. $theme['lightbox2_formatter_imagefield__lightshow2__link__'. $src['name']] = array(
  1108. 'arguments' => array('element' => NULL),
  1109. 'function' => 'theme_lightbox2_formatter_imagefield',
  1110. 'file' => 'lightbox2.formatter.inc',
  1111. );
  1112. foreach (image_styles() as $dest) {
  1113. $theme['lightbox2_formatter_imagefield__lightbox2__'. $src['name'] .'__'. $dest['name']] = array(
  1114. 'render element' => 'element',
  1115. 'function' => 'theme_lightbox2_formatter_imagefield',
  1116. );
  1117. $theme['lightbox2_formatter_imagefield__lightbox2_compact__'. $src['name'] .'__'. $dest['name']] = array(
  1118. 'arguments' => array('element' => NULL),
  1119. 'function' => 'theme_lightbox2_formatter_imagefield',
  1120. 'file' => 'lightbox2.formatter.inc',
  1121. );
  1122. $theme['lightbox2_formatter_imagefield__lightshow2__'. $src['name'] .'__'. $dest['name']] = array(
  1123. 'render element' => 'element',
  1124. 'function' => 'theme_lightbox2_formatter_imagefield',
  1125. );
  1126. $theme['lightbox2_formatter_imagefield__lightshow2_compact__'. $src['name'] .'__'. $dest['name']] = array(
  1127. 'arguments' => array('element' => NULL),
  1128. 'function' => 'theme_lightbox2_formatter_imagefield',
  1129. 'file' => 'lightbox2.formatter.inc',
  1130. );
  1131. }
  1132. }
  1133. }
  1134. // Additional Insert theme functions.
  1135. if (module_exists('insert')) {
  1136. // Theme functions in lightbox2.insert.inc.
  1137. $theme['lightbox2_insert_image'] = array(
  1138. 'arguments' => array('item' => NULL, 'widget' => NULL, 'type' => NULL, 'image_preset_name' => NULL, 'link_preset_name' => NULL),
  1139. 'template' => 'lightbox2-insert-image',
  1140. );
  1141. }*/
  1142. foreach ($theme as &$array) {
  1143. $array['file'] = 'lightbox2.formatter.inc';
  1144. }
  1145. return $theme;
  1146. }
  1147. /**
  1148. * Configures settings and outputs the video.
  1149. *
  1150. * @param nid
  1151. * The node id.
  1152. * @param width
  1153. * The lightbox video width.
  1154. * @param height
  1155. * The lightbox video height.
  1156. * @param field_name
  1157. * The name of the cck field the video is contained in.
  1158. * @param provider
  1159. * The name of the 3rd party video provider.
  1160. * @param id
  1161. * The video id.
  1162. */
  1163. /*
  1164. function lightbox2_emvideo($node, $width, $height, $field_name, $provider, $id) {
  1165. $field = content_fields($field_name);
  1166. $field['widget']['video_width'] = $width;
  1167. $field['widget']['video_height'] = $height;
  1168. $field['widget']['video_autoplay'] = 1;
  1169. if (!content_access('view', $field, NULL, $node)) {
  1170. drupal_access_denied();
  1171. return;
  1172. }
  1173. $items = $node->$field_name;
  1174. if (is_array($items)) {
  1175. foreach ($items as $item) {
  1176. if ($item['provider'] == $provider && $item['value'] == $id) {
  1177. break;
  1178. }
  1179. }
  1180. }
  1181. print theme('emvideo_video_video', $field, $item, 'video_video', $node);
  1182. }*/
  1183. /**
  1184. * Return TRUE if current path is disabled for lightbox according to
  1185. * lightbox2_page_list and lightbox2_page_init_action.
  1186. */
  1187. function lightbox2_exclude_these_paths() {
  1188. $action = variable_get('lightbox2_page_init_action', 'page_disable');
  1189. $page_list = variable_get('lightbox2_page_list', '');
  1190. if (!empty($page_list)) {
  1191. // Retrieve Drupal alias for the current path (if exists).
  1192. $alias = drupal_get_path_alias($_GET['q']);
  1193. if (drupal_match_path($_GET['q'], $page_list) || drupal_match_path($alias, $page_list)) {
  1194. return ($action == 'page_disable' ? 1 : 0);
  1195. }
  1196. }
  1197. return ($action == 'page_disable' ? 0 : 1);
  1198. }
  1199. /**
  1200. * Preprocess function for template by theme('page').
  1201. */
  1202. function lightbox2_preprocess_page(&$variables) {
  1203. if (arg(0) != 'node' || arg(2) != 'lightbox2') {
  1204. return;
  1205. }
  1206. //Overwrite template_preprocess_page() region settings.
  1207. global $theme;
  1208. // Retrieve all block regions.
  1209. $regions = system_region_list($theme);
  1210. // Remove all region content assigned via blocks.
  1211. foreach (array_keys($regions) as $region) {
  1212. if ($region != 'content') {
  1213. $variables[$region] = NULL;
  1214. }
  1215. }
  1216. // Set up layout variable to none.
  1217. $variables['layout'] = 'none';
  1218. //additional template files for e.g. page-node-lightbox.tpl.php are allready implemented through template_preprocess_page()
  1219. }
  1220. /**
  1221. * Display the video object.
  1222. *
  1223. * Displays the video object for a specified nid. It is used for displaying
  1224. * videos in acidfree lists in a lightbox when the thumbnail is clicked on. It
  1225. * is only triggered for the url 'node/%nid/lightframevideo'.
  1226. *
  1227. * @param $node
  1228. * The $node object.
  1229. */
  1230. /*
  1231. function lightbox2_acidfree_video($node) {
  1232. print theme('video_player', array( 'node' => $node ) );
  1233. }
  1234. */
  1235. /**
  1236. * Implementation of filefield's hook_file_formatter_info().
  1237. */
  1238. function lightbox2_file_formatter_info() {
  1239. return array(
  1240. 'lightbox2_iframe' => array(
  1241. 'suitability callback' => 'lightbox2_check_filefield_extension',
  1242. 'title' => t('Lightbox2 iframe'),
  1243. 'description' => t('Displays all kinds of files in a popup lightbox in an iframe.'),
  1244. ),
  1245. 'lightbox2_image' => array(
  1246. 'suitability callback' => 'lightbox2_check_filefield_image_extension',
  1247. 'title' => t('Lightbox2 image'),
  1248. 'description' => t('Displays image files in a popup lightbox.'),
  1249. ),
  1250. );
  1251. }
  1252. /**
  1253. * Suitability callback function for the filefield formatter.
  1254. *
  1255. * @param $file
  1256. * The file object, containing filepath, mime type, etc.
  1257. * @param $field
  1258. * CCK field information.
  1259. * @return
  1260. * True if file extension is supported.
  1261. */
  1262. function lightbox2_check_filefield_extension($file, $field) {
  1263. $ext = array_pop(explode('.', $file->filename));
  1264. return lightbox2_supported_file_extension($ext);
  1265. }
  1266. /**
  1267. * Suitability callback function for the image filefield formatter.
  1268. *
  1269. * @param $file
  1270. * The file object, containing filepath, mime type, etc.
  1271. * @param $field
  1272. * CCK field information.
  1273. * @return
  1274. * True if file extension is supported.
  1275. */
  1276. function lightbox2_check_filefield_image_extension($file, $field) {
  1277. $ext = array_pop(explode('.', $file->filename));
  1278. return lightbox2_supported_file_extension($ext, 'image');
  1279. }
  1280. /**
  1281. * Check whether a given file extension is supported by the lightbox iframe.
  1282. *
  1283. * @param $ext
  1284. * File extension
  1285. * @param $type
  1286. * Type of file extensions to check.
  1287. * @return
  1288. * TRUE if extension is supported.
  1289. */
  1290. function lightbox2_supported_file_extension($ext, $type = 'all') {
  1291. $image_extensions = array('png', 'jpg', 'jpeg', 'gif', 'bmp');
  1292. $movie_extensions = array('dv', 'mov', 'moov', 'movie', 'mp4', 'asf', 'wm', 'wmv', 'avi', 'mpg', 'mpeg');
  1293. $web_extensions = array('asp', 'aspx', 'cgi', 'cfm', 'htm', 'html', 'pl', 'php', 'php3', 'php4', 'php5', 'phtml', 'rb', 'rhtml', 'shtml', 'txt', 'vbs');
  1294. $misc_extensions = array('pdf');
  1295. $extensions = array();
  1296. switch ($type) {
  1297. case 'image':
  1298. $extensions = $image_extensions;
  1299. break;
  1300. case 'movie':
  1301. $extensions = $movie_extensions;
  1302. break;
  1303. case 'web':
  1304. $extensions = $web_extensions;
  1305. break;
  1306. case 'misc':
  1307. $extensions = $misc_extensions;
  1308. break;
  1309. case 'all':
  1310. default:
  1311. $extensions = array_merge($image_extensions, $movie_extensions, $web_extensions, $misc_extensions);
  1312. break;
  1313. }
  1314. if (in_array(drupal_strtolower($ext), $extensions)) {
  1315. return TRUE;
  1316. }
  1317. return FALSE;
  1318. }
  1319. /**
  1320. * Helper function to compare the string length of two items. Used when trying
  1321. * to sort an array by value length.
  1322. *
  1323. * @param $a
  1324. * String to compare.
  1325. * @param $b
  1326. * String to compare.
  1327. * @return
  1328. * 0 if they are the same length, -1 if $a is longer than $b, 1 otherwise.
  1329. */
  1330. function sort_by_length($a, $b) {
  1331. if ($a == $b) {
  1332. return 0;
  1333. }
  1334. return (drupal_strlen($a) > drupal_strlen($b) ? -1 : 1);
  1335. }
  1336. /**
  1337. * Get the user login form.
  1338. */
  1339. function lightbox2_login() {
  1340. // do not use lightbox2 for failed validation ie: bad password
  1341. // instead, return the fully rendered Drupal page with errors.
  1342. if (count($_POST)) {
  1343. return drupal_get_form('user_login_block');
  1344. }
  1345. else {
  1346. print drupal_render(drupal_get_form('user_login_block'));
  1347. // If the OpenID module is enabled, the javascript and css may not exist
  1348. // on the page, so add them dynamically.
  1349. if (module_exists('openid')) {
  1350. $path = drupal_get_path('module', 'openid');
  1351. $js_file = base_path() . $path . '/openid.js';
  1352. $css_file = base_path() . $path . '/openid.css';
  1353. // Load the javascript dynamically.
  1354. print '<script type="text/javascript">$.getScript("' . $js_file . '", function () {if ($.isFunction(Drupal.behaviors.openid)) { Drupal.behaviors.openid(document); } });</script>';
  1355. // Load the css file dynamically.
  1356. print '<script type="text/javascript">
  1357. var fileref=document.createElement("link");
  1358. fileref.setAttribute("rel", "stylesheet");
  1359. fileref.setAttribute("type", "text/css");
  1360. fileref.setAttribute("href", "'. $css_file . '");
  1361. document.getElementsByTagName("head")[0].appendChild(fileref);
  1362. </script>';
  1363. }
  1364. // drupal_add_js() with 'inline' didn't seem to work, possibly because this is
  1365. // AJAX loaded content.
  1366. print '<script type="text/javascript">Drupal.attachBehaviors();</script>';
  1367. }
  1368. exit;
  1369. }
  1370. /**
  1371. * Get the contact form.
  1372. */
  1373. function lightbox2_contact() {
  1374. if (module_exists('contact') && variable_get('lightbox2_enable_contact', FALSE) && user_access('access site-wide contact form')) {
  1375. $path = drupal_get_path('module', 'contact');
  1376. include_once($path . '/contact.pages.inc');
  1377. print drupal_render(drupal_get_form('contact_site_form'));
  1378. // drupal_add_js() with 'inline' didn't seem to work, possibly because this is
  1379. // AJAX loaded content.
  1380. print '<script type="text/javascript">Drupal.attachBehaviors();</script>';
  1381. exit;
  1382. }
  1383. }
  1384. /**
  1385. * Implementation of hook_form_alter().
  1386. *
  1387. * Update the page action and input size.
  1388. *
  1389. * @param &$form
  1390. * General reference used in drupal, defining the structure & the fields of
  1391. * a form.
  1392. * @param $form_state
  1393. * General variable, used to control the processing of the form.
  1394. * @param $form_id
  1395. * The default is "user_login_block"; hold the page where the function is being
  1396. * used.
  1397. * @return
  1398. * Return the structure of the form.
  1399. */
  1400. function lightbox2_form_user_login_block_alter(&$form, $form_state, $form_id = "user_login_block") {
  1401. if ($form_id == 'user_login_block' && arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'lightbox2') {
  1402. $form['#action'] = url('user/login/lightbox2', array('query' => array('destination' => $_GET['destination'])));
  1403. }
  1404. }
  1405. function lightbox2_form_contact_site_form_alter(&$form, $form_state, $form_id = "contact_site_form") {
  1406. if ($form_id == 'contact_site_form' && arg(0) == 'contact' && arg(1) == 'lightbox2') {
  1407. $form['#action'] = url('contact', array('query' => array('destination' => $_GET['destination'])));
  1408. }
  1409. }
  1410. /**
  1411. * Implementation of hook_link_alter().
  1412. *
  1413. * Add a lightbox2 rel attribute to the image link sizes on the image node.
  1414. */
  1415. function lightbox2_link_alter(&$links, $node) {
  1416. $image_node_handler = variable_get('lightbox2_image_node', 0);
  1417. // Only operate on image nodes and if automatic handling for image nodes is
  1418. // enabled. Also ensure $links is an array (bug in contemplate module).
  1419. if (!$image_node_handler || ($node->type != 'image' && $image_node_handler) || !is_array($links)) {
  1420. return;
  1421. }
  1422. $trigger_sizes = variable_get('lightbox2_trigger_image_size', array('thumbnail'));
  1423. // Change original ('original') to '_original'.
  1424. if (isset($trigger_sizes['original'])) {
  1425. unset($trigger_sizes['original']);
  1426. $trigger_sizes['_original'] = '_original';
  1427. }
  1428. $rel = '';
  1429. switch ($image_node_handler) {
  1430. case 1: // Lightbox.
  1431. case 2: // Lightbox grouped.
  1432. case 3: // Slideshow.
  1433. $rel = 'lightbox';
  1434. break;
  1435. case 4: // Lightframe.
  1436. case 5: // Lightframe grouped.
  1437. $rel = 'lightframe';
  1438. break;
  1439. }
  1440. $rel = $rel . '[][' . $node->title . ']';
  1441. foreach ($trigger_sizes as $size) {
  1442. if (isset($links['image_size_' . $size])) {
  1443. $links['image_size_' . $size]['attributes']['rel'] = $rel;
  1444. $links['image_size_' . $size]['href'] = $node->images[$size];
  1445. unset($links['image_size_' . $size]['query']);
  1446. }
  1447. }
  1448. }
  1449. /**
  1450. * Implementation of hook_views_api().
  1451. */
  1452. function lightbox2_views_api() {
  1453. return array(
  1454. 'api' => '3.0',
  1455. );
  1456. }
  1457. function lightbox2_filter_xss() {
  1458. $allowed_tags = trim(variable_get('lightbox2_filter_xss_allowed_tags', 'p, br, a, em, strong, cite, code, ul, ol, li, dl, dt, dd, '));
  1459. $allowed_tags = (empty($allowed_tags) ? array() : preg_split('/[,\s]+/', $allowed_tags));
  1460. if (!empty($_POST['allowed_tags']) && $_POST['allowed_tags'] != 'undefined') {
  1461. $allowed_tags = explode(',', $_POST['allowed_tags']);
  1462. $output = filter_xss($_POST['string'], $allowed_tags);
  1463. }
  1464. else {
  1465. $output = filter_xss($_POST['string'], $allowed_tags);
  1466. }
  1467. drupal_json_output($output);
  1468. }