Project

General

Profile

Paste
Download (76.3 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / lightbox2 / lightbox2.module @ 6135231a

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
/**
18
 * Implementation of hook_help().
19
 */
20
function lightbox2_help($path, $arg) {
21
  switch ($path) {
22
    case 'admin/modules#description':
23
      $output = t('Enables Lightbox2 for Drupal');
24
      break;
25
    case 'admin/help#lightbox2':
26
      $output = '<h3>' . t('Overview') . '</h3>';
27
      $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>';
28
      $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>';
29
      // Features
30
      $output .= '<h3>' . t('Features') . '</h3>';
31
      $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>';
32
      $output .= '<ul>';
33
      $output .= '<li>' . t('Image Sets: group related images and navigate through them with ease - ideal for your image galleries.') . '</li>';
34
      $output .= '<li>' . t('Slideshow Capability: automatically transition between grouped images, includes play/pause and previous and next buttons.') . '</li>';
35
      $output .= '<li>' . t('HTML Content Support: ability to show websites or other HTML content in a lightbox.') . '</li>';
36
      $output .= '<li>' . t('Video Content Support: ability to show videos in a lightbox.') . '</li>';
37
      $output .= '<li>' . t('Visual Effects: fancy pre-loader and transition when you click on the image.') . '</li>';
38
      $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>';
39
      $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>';
40
      $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. ');
41
      $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'));
42
      $output .= t('It\'s also possible to configure a custom list of image classes which should trigger the lightbox functionality.');
43
      $output .='</li>';
44
      $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>';
45
      $output .= '<li>' . t('Image Page Link: a link to the image node can be provided within the lightbox itself.') . '</li>';
46
      $output .= '<li>' . t('Page Exclusion Capability: exclude certain pages on your site from having the lightbox2 functionality.') . '</li>';
47
      $output .= '<li>' . t('Login Support: ability to modify all user/login links so the login form appears in a lightbox.') . '</li>';
48
      $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>';
49
      $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>';
50
      $output .= '</ul>';
51
      // Usage
52
      $output .= '<h3>' . t('Usage') . '</h3>';
53
      $output .= '<h5 style="text-decoration: underline;">' . t('Adding a Basic Lightbox') . '</h5>';
54
      $output .= '<p>' . t('Add rel=&quot;lightbox&quot; attribute to any link tag to activate the lightbox. For example:') . '</p>';
55
      $output .= '<code>' . t('&lt;a href=&quot;image-1.jpg&quot; rel=&quot;lightbox&quot;&gt;image #1&lt;/a&gt;<br />
56
                              &lt;a href=&quot;image-1.jpg&quot; rel=&quot;lightbox[][my caption]&quot;&gt;image #1&lt;/a&gt;') . '</code>';
57
      $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>';
58
      // Grouping Images
59
      $output .= '<h5 style="text-decoration: underline;">' . t('Grouping Images') . '</h5>';
60
      $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>';
61
      $output .= '<code>' . t('&lt;a href="images/image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br />
62
                              &lt;a href="images/image-2.jpg" rel="lightbox[roadtrip][caption 2]"&gt;image#2&lt;/a&gt;<br />
63
                              &lt;a href="images/image-3.jpg" rel="lightbox[roadtrip][caption 3]"&gt;image#3&lt;/a&gt;') . '</code>';
64
      $output .= '<p>' . t('No limits to the number of image sets per page or how many images are allowed in each set.') . '</p>';
65
      $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>';
66
      $output .= '<p><code>' . t('&lt;a href="images/image-1.jpg" rel="lightbox[roadtrip]"&gt;image #1&lt;/a&gt;<br />
67
                              &lt;a href="images/image-2.jpg" rel="lightbox[roadtrip]" class="lightbox_hide_image"&gt;image #2&lt;/a&gt;<br />
68
                              &lt;a href="images/image-3.jpg" rel="lightbox[roadtrip][caption 3]" class="lightbox_hide_image"&gt;image #3&lt;/a&gt;') . '</code></p>';
69
      // Slideshow
70
      $output .= '<h5 style="text-decoration: underline;">' . t('Slideshow') . '</h5>';
71
      $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>';
72
      $output .= '<p><code>' . t('&lt;a href="images/image-1.jpg" rel="lightshow[roadtrip]"&gt;image #1&lt;/a&gt;<br />
73
                              &lt;a href="images/image-2.jpg" rel="lightshow[roadtrip][caption 2]"&gt;image #2&lt;/a&gt;<br />
74
                              &lt;a href="images/image-3.jpg" rel="lightshow[roadtrip][caption 3]"&gt;image #3&lt;/a&gt;') . '</code></p>';
75
      // Video Content
76
      $output .= '<h5 style="text-decoration: underline;">' . t('Video Content') . '</h5>';
77
      $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>';
78
      $output .= '<p>' . t('Basic example:') . '<br />';
79
      $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>';
80
      $output .= '<p>' . t('Basic example with caption:') . '<br />';
81
      $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>';
82
      $output .= '<p>' . t('Grouped example:') . '<br />';
83
      $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 />
84
                              &lt;a href="http://video.google.com/videoplay?docid=1811233136844420765" rel="lightvideo[group][my caption]"&gt;Grouped example 2&lt;/a&gt;') . '</code></p>';
85
      $output .= '<p>' . t('Controlling lightbox size example:') . '<br />';
86
      $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>';
87
      $output .= '<p>' . t('Supported Video Formats:') . '<br />';
88
      $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>';
89
      // HTML Content
90
      $output .= '<h5 style="text-decoration: underline;">' . t('HTML Content') . '</h5>';
91
      $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>';
92
      $output .= '<p>' . t('Basic example:') . '<br />';
93
      $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[][Search Google]"&gt;Search google&lt;/a&gt;') . '</code></p>';
94
      $output .= '<p>' . t('Grouped example:') . '<br />';
95
      $output .= '<code>' . t('&lt;a href="http://www.google.com" rel="lightframe[search]"&gt;Search google&lt;/a&gt;<br />
96
                              &lt;a href="http://www.yahoo.com" rel="lightframe[search][Search Yahoo]"&gt;Search yahoo&lt;/a&gt;') . '</code></p>';
97
      $output .= '<p>' . t('Controlling iframe property example:') . '<br />';
98
      $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>';
99
      $output .= '<p>' . t('Controlling iframe property when grouped example:') . '<br />';
100
      $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 />
101
                              &lt;a href="http://www.yahoo.com" rel="lightframe[search|width:400px; height:300px;][Search Yahoo]"&gt;Search yahoo&lt;/a&gt;') . '</code></p>';
102
      // Inline Content Support
103
      $output .= '<h5 style="text-decoration: underline;">' . t('Inline Content Support') . '</h5>';
104
      $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>';
105
      $output .= '<p>' . t('Basic example:') . '<br />';
106
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal"&gt;Search&lt;/a&gt;') . '</code></p>';
107
      $output .= '<p>' . t('Basic example with caption:') . '<br />';
108
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[][my caption]"&gt;Search&lt;/a&gt;') . '</code></p>';
109
      $output .= '<p>' . t('Grouped example:') . '<br />';
110
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[search]"&gt;Search&lt;/a&gt;<br />
111
                              &lt;a href="search.php?status=1" rel="lightmodal[search][published]"&gt;Search published content&lt;/a&gt;') . '</code></p>';
112
      $output .= '<p>' . t('Controlling modal property example:') . '<br />';
113
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[|width:400px; height:300px; scrolling: auto;]"&gt;Search&lt;/a&gt;') . '</code></p>';
114
      $output .= '<p>' . t('Controlling modal property when grouped example:') . '<br />';
115
      $output .= '<code>' . t('&lt;a href="search.php" rel="lightmodal[search|width:400px; height:300px; scrolling: auto;]"&gt;Search&lt;/a&gt;<br />
116
                              &lt;a href="search.php?status=1" rel="lightmodal[search|width:400px; height:300px;][Search published]"&gt;Search published content&lt;/a&gt;<br />
117
                              &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>';
118
      // Keyboard Shortcuts
119
      $output .= '<h3>' . t('Keyboard Shortcuts') . '</h3>';
120
      $output .= '<p>' . t('The default keyboard shortcuts are listed below. You can override these on the admin page.') . '</p>';
121
      $output .= '<table>';
122
      $output .= '<tr><td>' . t('Close Lightbox') . '</td><td>x</td></tr>';
123
      $output .= '<tr><td></td><td>o</td></tr>
124
                  <tr><td></td><td>c</td></tr>
125
                  <tr><td></td><td>ESC</td></tr>';
126
      $output .= '<tr><td>' . t('Previous Image') . '</td><td>p</td></tr>';
127
      $output .= '<tr><td></td><td>' . t('Left Arrow') . '</td></tr>';
128
      $output .= '<tr><td>' . t('Next Image') . '</td><td>n</td></tr>';
129
      $output .= '<tr><td></td><td>' . t('Right Arrow') . '</td></tr>';
130
      $output .= '<tr><td>' . t('Toggle Zoom') . '</td><td>' . t('z (not available in slideshow)') . '</td></tr>';
131
      $output .= '<tr><td>' . t('Toggle Play / Pause') . '</td><td>' . t('Spacebar (slideshow only)') . '</td></tr>';
132
      $output .= '</table>';
133
      $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>';
134

    
135
      break;
136
  }
137
  return !empty($output) ? $output : '';
138
}
139

    
140
/**
141
 * Implementation of hook_permission().
142
 */
143
function lightbox2_permission() {
144
  return array(
145
  'administer lightbox2' => array(
146
    'title' => t('Administer Lightbox2'),
147
    'description' => t('Allow the user administer Lightbox2 settings'),
148
  ),
149
  'download original image' => array(
150
    'title' => t('Download Original'),
151
    'description' => t('Create a link that allow the user download the original image'),
152
  ),
153
  );
154
}
155

    
156

    
157
/**
158
 * Implementation of hook_menu().
159
 */
160
function lightbox2_menu() {
161
  $items = array();
162

    
163
  $items['system/lightbox2/filter-xss'] = array(
164
    'title' => 'Filter XSS',
165
    'page callback' => 'lightbox2_filter_xss',
166
    'access callback' => TRUE,
167
    'type' => MENU_CALLBACK,
168
  );
169

    
170
  $items['admin/config/user-interface/lightbox2'] = array(
171
    'title' => 'Lightbox2',
172
    'description' => 'Allows the user to configure the lightbox2 settings',
173
    'file' => 'lightbox2.admin.inc',
174
    'page callback' => 'lightbox2_settings_page',
175
    'access callback' => 'user_access',
176
    'access arguments' => array('administer lightbox2'),
177
  );
178
  $items['admin/config/user-interface/lightbox2/general'] = array(
179
    'title' => 'General',
180
    'description' => 'Allows the user to configure the lightbox2 settings',
181
    'file' => 'lightbox2.admin.inc',
182
    'page callback' => 'drupal_get_form',
183
    'page arguments' => array('lightbox2_general_settings_form'),
184
    'access callback' => 'user_access',
185
    'access arguments' => array('administer lightbox2'),
186
    'type' => MENU_DEFAULT_LOCAL_TASK,
187
    'weight' => 0,
188
  );
189
  $items['admin/config/user-interface/lightbox2/slideshow'] = array(
190
    'title' => 'Slideshow',
191
    'description' => 'Allows the user to configure the lightbox2 slideshow functionality',
192
    'file' => 'lightbox2.admin.inc',
193
    'page callback' => 'drupal_get_form',
194
    'page arguments' => array('lightbox2_slideshow_settings_form'),
195
    'access callback' => 'user_access',
196
    'access arguments' => array('administer lightbox2'),
197
    'type' => MENU_LOCAL_TASK,
198
    'weight' => 1,
199
  );
200
  $items['admin/config/user-interface/lightbox2/html_content'] = array(
201
    'title' => 'HTML Content',
202
    'file' => 'lightbox2.admin.inc',
203
    'page callback' => 'drupal_get_form',
204
    'page arguments' => array('lightbox2_iframe_settings_form'),
205
    'access callback' => 'user_access',
206
    'access arguments' => array('administer lightbox2'),
207
    'description' => 'Allows the user to configure the lightbox2 HTML content functionality.',
208
    'type' => MENU_LOCAL_TASK,
209
    'weight' => 2,
210
  );
211
  $items['admin/config/user-interface/lightbox2/automatic'] = array(
212
    'title' => 'Automatic image handling',
213
    'description' => 'Allows the user to configure the lightbox2 automatic image handling settings',
214
    'file' => 'lightbox2.admin.inc',
215
    'page callback' => 'drupal_get_form',
216
    'page arguments' => array('lightbox2_auto_image_handling_settings_form'),
217
    'access callback' => 'user_access',
218
    'access arguments' => array('administer lightbox2'),
219
    'type' => MENU_LOCAL_TASK,
220
    'weight' => 3,
221
  );
222

    
223
  /**
224
  if (module_exists('emfield') && module_exists('emvideo')) {
225
    $items['video-cck/lightbox2/%node'] = array(
226
      'page callback' => 'lightbox2_emvideo',
227
      'page arguments' => array(2),
228
      'access callback' => 'node_access',
229
      'access arguments' => array('view', 2),
230
      'type' => MENU_CALLBACK,
231
    );
232
  }
233
  */
234
  /**
235
   * There is not a version from acidfree to drupal 7
236
  if (module_exists('acidfree') && module_exists('video')) {
237
    $items['node/%node/lightframevideo'] = array(
238
      'page callback' => 'lightbox2_acidfree_video',
239
      'page arguments' => array(1),
240
      'access callback' => 'lightbox2_acidfree_video_access',
241
      'access arguments' => array(1),
242
      'type' => MENU_CALLBACK,
243
    );
244
  }
245
   */
246
  $items['user/login/lightbox2'] = array(
247
    'title' => 'Login',
248
    'page callback' => 'lightbox2_login',
249
    'access callback' => 'user_is_anonymous',
250
    'type' => MENU_CALLBACK,
251
  );
252
  $items['contact/lightbox2'] = array(
253
    'title' => 'Contact',
254
    'page callback' => 'lightbox2_contact',
255
    'access arguments' => array('access site-wide contact form'),
256
    'type' => MENU_CALLBACK,
257
  );
258

    
259
  return $items;
260
}
261

    
262
/**
263
 * Acidfree video access control.
264
 */
265
/**
266
 * No acidvideo for drupal 7
267
 * function lightbox2_acidfree_video_access($node) {
268
  if (user_access('play video') && node_access('view', $node)) {
269
    return TRUE;
270
  }
271
  return FALSE;
272
}
273
*/
274
/**
275
 * Implementation of hook_init().
276
 */
277
function lightbox2_init() {
278
  if (lightbox2_exclude_these_paths() != 1) {
279
    lightbox2_add_files();
280
  }
281
}
282

    
283

    
284
/**
285
 * Implementation of hook_filter_tips().
286
 */
287
/*
288
 * This is not used any more on drupal 7, keep here only to help with the
289
 * conversion, when there is a drupal 7 port, delete this function
290
function lightbox2_filter_tips($delta, $format, $long = FALSE) {
291
  if ($delta == 0) {
292
    if (!$long) {
293
      return t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
294
    }
295
    else {
296
      $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>';
297
      $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightbox"&gt;image #1&lt;/a&gt;</code>') .'</p>';
298
      $output .= '<p>'. t('<code>&lt;a href="image-1.jpg" rel="lightbox[][my caption]"&gt;image #1&lt;/a&gt;</code>') .'</p>';
299
      $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>';
300
      $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>';
301
      $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>';
302
      $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>';
303
      $output .= '<p>'. t('If you wish to turn the caption into a link, format your caption in the following way:') .'</p>';
304
      $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>';
305
      return $output;
306
    }
307
  }
308
  elseif ($delta == 1) {
309
    return t('Image links from G2 are formatted for use with Lightbox2');
310
  }
311
  elseif ($delta == 2) {
312
    if (!$long) {
313
      return t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.');
314
    }
315
    else {
316
      $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>';
317
      $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>';
318
      $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>';
319
      $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>';
320
      $output .= '<p>'. t('If you wish to turn the caption into a link, format your caption in the following way:') .'</p>';
321
      $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>';
322
      return $output;
323
    }
324
  }
325
  elseif ($delta == 3) {
326
    if (!$long) {
327
      return t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
328
    }
329
    else {
330
      $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>';
331
      $output .= '<p>'. t('Basic example:') .'<br />';
332
      $output .= t('<code>&lt;a href=&quot;http://www.google.com&quot; rel=&quot;lightframe&quot;&gt;Search google&lt;/a&gt;</code>') .'</p>';
333
      $output .= '<p>'. t('Grouped example:') .'<br />';
334
      $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>';
335

    
336
      $output .= '<p>'. t('Controlling iframe property example:') .'<br />';
337
      $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>';
338
      $output .= '<p>'. t('Controlling iframe property when grouped example:') .'<br />';
339
      $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>';
340

    
341
      return $output;
342
    }
343
  }
344
  elseif ($delta == 4) {
345
    if (!$long) {
346
      return t('Links to video content with \'rel="lightvideo"\' 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 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>';
350
      $output .= '<p>'. t('Basic example:') .'<br />';
351
      $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>';
352
      $output .= '<p>'. t('Controlling lightbox size example:') .'<br />';
353
      $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>';
354
      $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>';
355
      return $output;
356
    }
357
  }
358
  elseif ($delta == 5) {
359
    if (!$long) {
360
      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.');
361
    }
362
    else {
363
      $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>';
364
      $output .= '<p>'. t('Basic example:') .'<br />';
365
      $output .= t('<code>&lt;a href=&quot;search.php&quot; rel=&quot;lightmodal&quot;&gt;Search&lt;/a&gt;</code>') .'</p>';
366
      $output .= '<p>'. t('Grouped example:') .'<br />';
367
      $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>';
368

    
369
      $output .= '<p>'. t('Controlling modal property example:') .'<br />';
370
      $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>';
371
      $output .= '<p>'. t('Controlling modal property when grouped example:') .'<br />';
372
      $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>';
373

    
374
      return $output;
375
    }
376
  }
377
}
378

    
379
/**
380
 * Implementation of hook_filter().
381
 */
382
/*
383
 * This is not used any more on drupal 7, keep here only to help with the
384
 * conversion, when there is a drupal 7 port, delete this function
385
function lightbox2_filter($op, $delta = 0, $format = -1, $text = '') {
386
  switch ($op) {
387
    case 'list':
388
      return array(
389
        0 => t('Lightbox filter'),
390
        1 => t('Lightbox G2 filter'),
391
        2 => t('Lightbox slideshow filter'),
392
        3 => t('Lightbox iframe filter'),
393
        4 => t('Lightbox video filter'),
394
        5 => t('Lightbox modal filter'),
395
        6 => t('Disable Lightbox iframe filter'),
396
      );
397

    
398
    case 'description':
399
      if ($delta == 0) {
400
        return t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
401
      }
402
      elseif ($delta == 1) {
403
        return t('Turns g2_filter links into Lightbox2 appropriate links');
404
      }
405
      elseif ($delta == 2) {
406
        return t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.');
407
      }
408
      elseif ($delta == 3) {
409
        return t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
410
      }
411
      elseif ($delta == 4) {
412
        return t('Links to video content with \'rel="lightvideo"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.');
413
      }
414
      elseif ($delta == 5) {
415
        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.');
416
      }
417
      elseif ($delta == 6) {
418
        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.');
419
      }
420

    
421
    case 'process':
422
      if ($delta == 1) {
423
        $text = ' '. $text .' ';
424
        $text = preg_replace('/ShowItem/', 'DownloadItem', $text);
425
        $text = preg_replace('/<img\s+([^>]*?)src="/', '<img \1rel="lightbox" src="', $text);
426
        $text = drupal_substr($text, 1, -1);
427
      }
428
      elseif ($delta == 6) {
429
        $text = preg_replace('/<a([^>]*?)(rel=[\'"]*lightframe[\'"]*)([^>]*?)>/i', '<a\1\3>', $text);
430
      }
431
      return $text;
432

    
433
    default:
434
      return $text;
435
  }
436
}
437
*/
438
/**
439
 * Process callback for Lightbox G2 filter.
440
 */
441
function _lightbox2_process_filter($text, $format) {
442
  $text = ' ' . $text . ' ';
443
  $text = preg_replace('/ShowItem/', 'DownloadItem', $text);
444
  $text = preg_replace('/src="/', 'rel="lightbox" src="', $text);
445
  $text = drupal_substr($text, 1, -1);
446
  return $text;
447
}
448

    
449
/**
450
 * Process callback for Disable Lightbox iframe filter.
451
 */
452
function _lightbox2_process_disable_filter($text, $format) {
453
  $text = preg_replace('/<a([^>]*?)(rel=[\'"]*lightframe[\'"]*)([^>]*?)>/i', '<a\1\3>', $text);
454
  return $text;
455
}
456

    
457
/**
458
 * Implements hook_filter_info().
459
 */
460
function lightbox2_filter_info() {
461
  $filters = array();
462
  $filters['lightbox2_filter'] = array(
463
    'title' => t('Lightbox filter'),
464
    'description' => t('Image links with \'rel="lightbox"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
465
  );
466
  $filters['lightbox2_gd_filter'] = array(
467
    'title' => t('Lightbox GD filter'),
468
    'description' => t('Turns g2_filter links into Lightbox2 appropriate links'),
469
    'process callback' => '_lightbox2_process_filter',
470
  );
471
  $filters['lightbox_slideshow_filter'] = array(
472
    'title' => t('Lightbox slideshow filter'),
473
    'description' => t('Image links with \'rel="lightshow"\' in the &lt;a&gt; tag will appear in a Lightbox slideshow when clicked on.'),
474
  );
475
  $filters['lightbox_iframe_filter'] = array(
476
    'title' => t('Lightbox iframe filter'),
477
    'description' => t('Links to HTML content with \'rel="lightframe"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
478
  );
479
  $filters['lightbox_video_filter'] = array(
480
    'title' => t('Lightbox video filter'),
481
    'description' => t('Links to video content with \'rel="lightvideo"\' in the &lt;a&gt; tag will appear in a Lightbox when clicked on.'),
482
  );
483
  $filters['lightbox_modal_filter'] = array(
484
    'title' => t('Lightbox modal filter'),
485
    '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.'),
486
  );
487
  $filters['lightbox_disable_iframe_filter'] = array(
488
    'title' => t('Disable Lightbox iframe filter'),
489
    '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.'),
490
    'process callback' => '_lightbox2_process_disable_filter',
491
  );
492
  return ($filters);
493
}
494

    
495
/**
496
 * Provide links to the CSS stylesheet and JS file associated with
497
 * this module.
498
 */
499
function lightbox2_add_files() {
500
  global $language, $user;
501
  static $already_added = FALSE;
502
  if ($already_added) {
503
    return; // Don't add the JavaScript and CSS multiple times.
504
  }
505
  $already_added = TRUE;
506

    
507
  // Load required js and css files.
508
  $path = drupal_get_path('module', 'lightbox2');
509

    
510
  // Initialise some variables.
511
  $inline_image_handler = variable_get('lightbox2_inline', 0);
512
  $flickr_image_handler = variable_get('lightbox2_flickr', 0);
513
  $gallery2_block_handler = variable_get('lightbox2_gallery2_blocks', 0);
514
  $image_assist_handler = variable_get('lightbox2_image_assist_custom', 0);
515
  $image_node_handler = variable_get('lightbox2_image_node', 0);
516

    
517
  $custom_class_handler = 0;
518
  switch (variable_get('lightbox2_custom_class_handler', 0)) {
519
    case 1:
520
      $custom_class_handler = 'lightbox_ungrouped';
521
      break;
522
    case 2:
523
      $custom_class_handler = 'lightbox';
524
      break;
525
    case 3:
526
      $custom_class_handler = 'lightshow';
527
      break;
528
    case 4:
529
      $custom_class_handler = 'lightframe_ungrouped';
530
      break;
531
    case 5:
532
      $custom_class_handler = 'lightframe';
533
      break;
534
  }
535

    
536

    
537
  // Set the list of image classes to format urls for.
538
  $image_node_sizes = '';
539
  $trigger_lightbox_classes = '';
540
  $trigger_lightbox_group_classes = '';
541
  $trigger_slideshow_classes = '';
542
  $trigger_lightframe_classes = '';
543
  $trigger_lightframe_group_classes = '';
544

    
545
  // Inline module images.
546
  switch ($inline_image_handler) {
547
    case 1:
548
      $trigger_lightbox_classes .= 'img.inline,';
549
      break;
550
    case 2:
551
      $trigger_lightbox_group_classes .= 'img.inline,';
552
      break;
553
    case 3:
554
      $trigger_slideshow_classes .= 'img.inline,';
555
      break;
556
    case 4:
557
      $trigger_lightframe_classes .= 'img.inline,';
558
      break;
559
    case 5:
560
      $trigger_lightframe_group_classes .= 'img.inline,';
561
      break;
562
  }
563

    
564
  // Flickr images.
565
  switch ($flickr_image_handler) {
566
    case 1:
567
      $trigger_lightbox_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
568
      break;
569
    case 2:
570
      $trigger_lightbox_group_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
571
      break;
572
    case 3:
573
      $trigger_slideshow_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
574
      break;
575
    case 4:
576
      $trigger_lightframe_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
577
      break;
578
    case 5:
579
      $trigger_lightframe_group_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
580
      break;
581
  }
582

    
583
  // Gallery2 block images.
584
  switch ($gallery2_block_handler) {
585
    case 1:
586
      $trigger_lightbox_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
587
      break;
588
    case 2:
589
      $trigger_lightbox_group_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
590
      break;
591
    case 3:
592
      $trigger_slideshow_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
593
      break;
594
    case 4:
595
      $trigger_lightframe_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
596
      break;
597
    case 5:
598
      $trigger_lightframe_group_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
599
      break;
600
  }
601

    
602
  // Image Assist custom size images.
603
  switch ($image_assist_handler) {
604
    case 1:
605
      $trigger_lightbox_classes .= 'img.image-img_assist_custom,';
606
      break;
607
    case 2:
608
      $trigger_lightbox_group_classes .= 'img.image-img_assist_custom,';
609
      break;
610
    case 3:
611
      $trigger_slideshow_classes .= 'img.image-img_assist_custom,';
612
      break;
613
    case 4:
614
      $trigger_lightframe_classes .= 'img.image-img_assist_custom,';
615
      break;
616
    case 5:
617
      $trigger_lightframe_group_classes .= 'img.image-img_assist_custom,';
618
      break;
619
  }
620

    
621
  // Image nodes.
622
  if ($image_node_handler) {
623
    $trigger_sizes = variable_get('lightbox2_trigger_image_size', array('thumbnail'));
624
    usort($trigger_sizes, "sort_by_length");
625
    foreach ($trigger_sizes as $size) {
626
      $triggers = "img.$size, img.image-$size,";
627
      if (empty($size)) {
628
        if (user_access('view original images')) {
629
          $triggers = "img._original, img.image-_original,";
630
        }
631
      }
632
      else {
633
        $image_node_sizes .= "\.$size|";
634
      }
635
      switch ($image_node_handler) {
636
        case 1:
637
          $trigger_lightbox_classes .= $triggers;
638
          break;
639
        case 2:
640
          $trigger_lightbox_group_classes .= $triggers;
641
          break;
642
        case 3:
643
          $trigger_slideshow_classes .= $triggers;
644
          break;
645
        case 4:
646
          $trigger_lightframe_classes .= $triggers;
647
          break;
648
        case 5:
649
          $trigger_lightframe_group_classes .= $triggers;
650
          break;
651
      }
652
    }
653
  }
654

    
655
  // Custom images.
656
  $custom_triggers = variable_get('lightbox2_custom_trigger_classes', '');
657
  $custom_trigger_classes = '';
658
  if ($custom_class_handler && !empty($custom_triggers)) {
659
    $trigger_classes = preg_split("/(\r\n|\n)/", $custom_triggers);
660
    foreach ($trigger_classes as $class) {
661
      if (!empty($class)) {
662
        $custom_trigger_classes .= "img.$class,";
663
      }
664
    }
665
  }
666
  $trigger_lightbox_classes = rtrim($trigger_lightbox_classes, ",");
667
  $trigger_lightbox_group_classes = rtrim($trigger_lightbox_group_classes, ",");
668
  $trigger_slideshow_classes = rtrim($trigger_slideshow_classes, ",");
669
  $trigger_lightframe_classes = rtrim($trigger_lightframe_classes, ",");
670
  $trigger_lightframe_group_classes = rtrim($trigger_lightframe_group_classes, ",");
671
  $custom_trigger_classes = rtrim($custom_trigger_classes, ",");
672
  $image_node_sizes = '(' . rtrim($image_node_sizes, "|") . ')';
673

    
674
  $enable_video = variable_get('lightbox2_enable_video', FALSE);
675
  $enable_login = $user->uid == 0 && variable_get('lightbox2_enable_login', FALSE);
676
  $enable_contact = module_exists('contact') && variable_get('lightbox2_enable_contact', FALSE) && user_access('access site-wide contact form');
677
  $display_image_size = variable_get('lightbox2_display_image_size', 'original');
678
  if ($display_image_size == 'original' && user_access('view original images')) {
679
    $display_image_size = '';
680
  }
681
  $font_color = variable_get('lightbox2_font_color', '000');
682
  $box_color = variable_get('lightbox2_box_color', 'fff');
683

    
684
  $file_path = base_path() . '(\w\w/)' . file_default_scheme() . ':/';
685
  if ( variable_get('file_downloads', 'FILE_DOWNLOADS_PUBLIC') == 'FILE_DOWNLOADS_PRIVATE' ) {
686
    $file_path = base_path() . '(\w\w/)system/files';
687
  }
688

    
689
  // Load the javascript settings.
690
  $js_settings = array(
691
    'rtl' => $language->direction,
692
    'file_path' => $file_path,
693
    'default_image' => base_path() . $path . '/images/brokenimage.jpg',
694
    'border_size' => (int) variable_get('lightbox2_border_size', 10),
695
    'font_color' => !empty($font_color) ? $font_color : '000',
696
    'box_color' => !empty($box_color) ? $box_color : '000',
697
    'top_position' => variable_get('lightbox2_top_position', ''),
698
    'overlay_opacity' => str_replace(',', '.', variable_get('lightbox2_overlay_opacity', 0.8)),
699
    'overlay_color' => variable_get('lightbox2_overlay_color', '000'),
700
    'disable_close_click' => variable_get('lightbox2_disable_close_click', TRUE),
701
    'resize_sequence' => (int)variable_get('lightbox2_resize_sequence', 0),
702
    'resize_speed' => 1000 * str_replace(',', '.', variable_get('lightbox2_resize_speed', 0.4)),
703
    'fade_in_speed' => 1000 * str_replace(',', '.', variable_get('lightbox2_fadein_speed', 0.4)),
704
    'slide_down_speed' => 1000 * str_replace(',', '.', variable_get('lightbox2_slidedown_speed', 0.6)),
705
    'use_alt_layout' => variable_get('lightbox2_use_alt_layout', FALSE),
706
    'disable_resize' => variable_get('lightbox2_disable_resize', FALSE),
707
    'disable_zoom' => variable_get('lightbox2_disable_zoom', FALSE),
708
    'force_show_nav' => variable_get('lightbox2_force_show_nav', FALSE),
709
    'show_caption' => variable_get('lightbox2_show_caption', TRUE),
710
    'loop_items' => variable_get('lightbox2_loop_items', FALSE),
711
    'node_link_text' => check_plain(t(variable_get('lightbox2_node_link_text', 'View Image Details'))),
712
    'node_link_target' => variable_get('lightbox2_node_link_target', FALSE),
713
    'image_count' => check_plain(t(variable_get('lightbox2_image_count_str', 'Image !current of !total'))),
714
    'video_count' => check_plain(t(variable_get('lightbox2_video_count_str', 'Video !current of !total'))),
715
    'page_count' => check_plain(t(variable_get('lightbox2_page_count_str', 'Page !current of !total'))),
716
    'lite_press_x_close' => t('press !x to close', array('!x' => '<a href="#" onclick="hideLightbox(); return FALSE;"><kbd>x</kbd></a>')),
717
    'download_link_text' => '',
718
    'enable_login' => $enable_login,
719
    'enable_contact' => $enable_contact,
720
    // Automatic image handling settings.
721
    'keys_close' => variable_get('lightbox2_keys_close', 'c x 27'),
722
    'keys_previous' => variable_get('lightbox2_keys_previous', 'p 37'),
723
    'keys_next' => variable_get('lightbox2_keys_next', 'n 39'),
724
    'keys_zoom' => variable_get('lightbox2_keys_zoom', 'z'),
725
    'keys_play_pause' => variable_get('lightbox2_keys_play_pause', '32'),
726
    'display_image_size' => $display_image_size,
727
    'image_node_sizes' => $image_node_sizes,
728
    'trigger_lightbox_classes' => $trigger_lightbox_classes,
729
    'trigger_lightbox_group_classes' => $trigger_lightbox_group_classes,
730
    'trigger_slideshow_classes' => $trigger_slideshow_classes,
731
    'trigger_lightframe_classes' => $trigger_lightframe_classes,
732
    'trigger_lightframe_group_classes' => $trigger_lightframe_group_classes,
733
    'custom_class_handler' => $custom_class_handler,
734
    'custom_trigger_classes' => $custom_trigger_classes,
735
    'disable_for_gallery_lists' => variable_get('lightbox2_disable_nested_galleries', TRUE),
736
    'disable_for_acidfree_gallery_lists' => variable_get('lightbox2_disable_nested_acidfree_galleries', TRUE),
737
    'enable_acidfree_videos' => variable_get('lightbox2_enable_acidfree_videos', TRUE),
738
    // Slideshow settings.
739
    'slideshow_interval' => variable_get('lightbox2_slideshow_interval', 5) * 1000,
740
    'slideshow_automatic_start' => variable_get('lightbox2_slideshow_automatic_start', TRUE),
741
    'slideshow_automatic_exit' => variable_get('lightbox2_slideshow_automatic_exit', TRUE),
742
    'show_play_pause' => variable_get('lightbox2_slideshow_show_play_pause', TRUE),
743
    'pause_on_next_click' => variable_get('lightbox2_slideshow_pause_on_next_click', FALSE),
744
    'pause_on_previous_click' => variable_get('lightbox2_slideshow_pause_on_previous_click', TRUE),
745
    'loop_slides' => variable_get('lightbox2_loop_slides', FALSE),
746
    // Iframe settings.
747
    'iframe_width' => (int)variable_get('lightbox2_default_frame_width', 600),
748
    'iframe_height' => (int)variable_get('lightbox2_default_frame_height', 400),
749
    'iframe_border' => (int)variable_get('lightbox2_frame_border', 1),
750
    // Video settings.
751
    'enable_video' => $enable_video,
752
    'useragent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
753
  );
754
  if ($enable_video) {
755
    $js_settings['flvPlayer'] = url(check_plain(trim(variable_get('lightbox2_flv_player_path', 'flvplayer.swf'), '/')));
756
    $js_settings['flvFlashvars'] = check_plain(variable_get('lightbox2_flv_player_flashvars', ''));
757
  }
758

    
759
  // Only supply these if the user has the correct permissions.
760
  if (user_access('download original image') && user_access('view original images')) {
761
    $js_settings['download_link_text'] = check_plain(t(variable_get('lightbox2_download_link_text', 'Download Original')));
762
  }
763

    
764
  drupal_add_js(array('lightbox2' => $js_settings), array( 'type' => 'setting' ) );
765

    
766

    
767
  // Check where we should load the javascript files - header or footer.
768
  $js_location = variable_get('lightbox2_js_location', 'header');
769

    
770
  // Lightbox2 Plus.
771
  if (!variable_get('lightbox2_lite', FALSE)) {
772
    $css = $path . '/css/lightbox.css';
773
    if (variable_get('lightbox2_use_alt_layout', FALSE)) {
774
      $css = $path . '/css/lightbox_alt.css';
775
    }
776
    drupal_add_css($css);
777

    
778
    // Check to see if any automatic image handling options are enabled.
779
    if ($image_node_handler || $flickr_image_handler || $gallery2_block_handler || $inline_image_handler || $image_assist_handler || $custom_triggers != '') {
780
      drupal_add_js($path . '/js/auto_image_handling.js', array( 'scope' => $js_location ) );
781
    }
782
    if (variable_get('lightbox2_enable_video', FALSE)) {
783
      drupal_add_js($path . '/js/lightbox_video.js', array( 'scope' => $js_location ) );
784
    }
785
    if ($enable_login || $enable_contact) {
786
      drupal_add_js($path . '/js/lightbox_modal.js', array( 'scope' => $js_location ) );
787
    }
788
    //drupal_add_js($path .'/js/prototype.js', array( 'scope' => $js_location, 'cache' => false ) );
789
    //drupal_add_js($path .'/js/scriptaculous.js', array( 'scope' => $js_location, 'cache' => false ) );
790
    drupal_add_js($path . '/js/lightbox.js', array( 'scope' => $js_location));
791

    
792
  }
793
  // Lightbox Lite.
794
  else {
795
    $css = $path . '/css/lightbox_lite.css';
796
    drupal_add_css($css);
797
    drupal_add_js($path . '/js/lightbox_lite.js', array( 'scope' => $js_location ) );
798
  }
799
}
800

    
801
/**
802
 * Helper function for image styles.
803
 */
804
function lightbox2_image_styles() {
805
  $image_styles=array('0'=>'original');
806
  $tmp=image_styles();
807
  foreach($tmp as $style) {
808
    $image_styles[$style['name']] = $style['name'];
809
  }
810
  return $image_styles;
811
}
812

    
813
/**
814
 * Helper function for possible fields to display as the caption.
815
 */
816
function lightbox2_image_fields() {
817
  $fields = array(
818
    'hidden' => t('Hidden'),
819
    'title' => t('File title'),
820
    'filename' => t('Filename'),
821
  );
822
  foreach(field_info_instances("file", "image") as $field) {
823
    $fields[$field['field_name']] = $field['label'];
824
  }
825
  return $fields;
826
}
827

    
828
/**
829
 * Helper function for possible lightbox styles.
830
 */
831
function lightbox2_lightbox_types() {
832
    return array(
833
      'lightbox' => t('Single lightbox'),
834
      'lightshow' => t('Lightshow'),
835
    );
836
}
837

    
838
/**
839
 * Implements hook_field_formatter_settings_form().
840
 */
841
function lightbox2_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
842
  $display = $instance['display'][$view_mode];
843
  $settings = $display['settings'];
844

    
845
  $form = array();
846

    
847
  $form['type'] = array(
848
    '#title' => t('Lightbox type'),
849
    '#type' => 'select',
850
    '#options' => lightbox2_lightbox_types(),
851
    '#default_value' => $settings['type'],
852
  );
853
  $form['image_style'] = array(
854
    '#title' => t('Image style'),
855
    '#description' => t('The thumbnail to display as a link for the lightbox.'),
856
    '#type' => 'select',
857
    '#options' => lightbox2_image_styles(),
858
    '#default_value' => $settings['image_style'],
859
  );
860
  $form['lightbox_style'] = array(
861
    '#title' => t('Lightbox style'),
862
    '#description' => t('The image style to show inside the lightbox.'),
863
    '#type' => 'select',
864
    '#options' => lightbox2_image_styles(),
865
    '#default_value' => $settings['lightbox_style'],
866
  );
867

    
868
  $form['caption'] = array(
869
    '#title' => t('Caption field'),
870
    '#description' => t('The field to use as a caption.'),
871
    '#type' => 'select',
872
    '#options' => lightbox2_image_fields(),
873
    '#default_value' => $settings['caption'],
874
  );
875

    
876
  return $form;
877
}
878
/**
879
 * Implements hook_field_formatter_settings_summary().
880
 */
881
function lightbox2_field_formatter_settings_summary($field, $instance, $view_mode) {
882
  $display = $instance['display'][$view_mode];
883
  $settings = $display['settings'];
884

    
885
  $image_styles = lightbox2_image_styles();
886
  $fields = lightbox2_image_fields();
887
  $types = lightbox2_lightbox_types();
888

    
889
  $summary = '';
890

    
891
  if(isset($settings['caption']) && isset($settings['type']) && isset($settings['image_style']) && isset($settings['lightbox_style'])) {
892
    $summary .= '<strong>'.t('Caption field') . '</strong>: ' . $fields[$settings['caption']] . '<br/>';
893
    $summary .= '<strong>'.t('Display') . '</strong>: ' ;
894
    $summary .= $types[$settings['type']];
895
    $summary .= ': ';
896
    $summary .= $image_styles[$settings['image_style']];
897
    $summary .= ' => ';
898
    $summary .= $image_styles[$settings['lightbox_style']];
899
  } else {
900
    $summary = 'Title - Lightbox: original => original';
901
  }
902

    
903

    
904
  return $summary;
905
}
906

    
907
/**
908
 * Implementation of hook_field_formatter_info().
909
 *
910
 * Add certain lightbox and imagecache formatters to CCK image fields if
911
 * the imagefield.module and the imagecache.module exist.  Add additional
912
 * formatters if emfield, emimage and/or emvideo modules exist.
913
 */
914
function lightbox2_field_formatter_info() {
915
  $formatters = array();
916
  if (module_exists('image')) {
917
    $formatters['lightbox2'] = array(
918
      'label' => 'Lightbox2',
919
      'field types' => array('image'),
920
      'settings' => array(
921
          'type' => 'lightbox',
922
          'image_style' => 'original',
923
          'lightbox_style' => 'original',
924
          'caption' => 'hidden',
925
      ),
926
    );
927
  }
928
  return $formatters;
929
  /*
930
  // Handle imagefield and filefield images.
931
  if (module_exists('image')) {
932
  	$rules = array();
933
    if (function_exists('image_styles')) {
934
      $presets = image_styles();
935
      foreach ($presets as $preset_id => $preset_info) {
936
        $rules[$preset_id] = $preset_info['name'];
937
      }
938
    }
939
    $iframe['image__lightframe2__original__node'] = array(
940
      'label' => 'Lightbox2 iframe: original->node page',
941
      'field types' => array('image', 'file'),
942
    );
943
    $iframe['imagefield__lightframe2__link__node'] = array(
944
      'label' => 'Lightbox2 iframe: link->node page',
945
      'field types' => array('image', 'file'),
946
    );
947
    foreach ($rules as $view_rule) {
948
      $lightbox['image__lightbox2__original__'. $view_rule] = array(
949
        'label' => 'Lightbox2: original->'. $view_rule,
950
        'field types' => array('image', 'file'),
951
      );
952
      $lightbox['imagefield__lightbox2_compact__original__'. $view_rule] = array(
953
        'label' => 'Lightbox2: original->'. $view_rule . ' compact',
954
        'field types' => array('image', 'file'),
955
      );
956
      $lightbox['image__lightbox2__'. $view_rule .'__original'] = array(
957
        'label' => 'Lightbox2: '. $view_rule .'->original',
958
        'field types' => array('image', 'file'),
959
      );
960
      $lightbox['imagefield__lightbox2_compact__'. $view_rule .'__original'] = array(
961
        'label' => 'Lightbox2: '. $view_rule .'->original compact',
962
        'field types' => array('image', 'file'),
963
      );
964
      $lightbox['imagefield__lightbox2__link__'. $view_rule] = array(
965
        'label' => 'Lightbox2: link->'. $view_rule,
966
        'field types' => array('image', 'file'),
967
      );
968
      $slideshow['image__lightshow2__original__'. $view_rule] = array(
969
        'label' => 'Lightbox2 slideshow: original->'. $view_rule,
970
        'field types' => array('image', 'file'),
971
      );
972
      $slideshow['imagefield__lightshow2_compact__original__'. $view_rule] = array(
973
        'label' => 'Lightbox2 slideshow: original->'. $view_rule . ' compact',
974
        'field types' => array('image', 'filefield'),
975
      );
976
      $slideshow['image__lightshow2__'. $view_rule .'__original'] = array(
977
        'label' => 'Lightbox2 slideshow: '. $view_rule .'->original',
978
        'field types' => array('image', 'file'),
979
      );
980
      $slideshow['imagefield__lightshow2_compact__'. $view_rule .'__original'] = array(
981
        'label' => 'Lightbox2 slideshow: '. $view_rule .'->original compact',
982
        'field types' => array('image', 'filefield'),
983
      );
984
      $slideshow['imagefield__lightshow2__link__'. $view_rule] = array(
985
        'label' => 'Lightbox2 slideshow: link->'. $view_rule,
986
        'field types' => array('image', 'filefield'),
987
      );
988
      $iframe['image__lightframe2__'. $view_rule .'__node'] = array(
989
        'label' => 'Lightbox2 iframe: '. $view_rule .'->node page',
990
        'field types' => array('image', 'file'),
991
      );
992
	foreach ($rules as $lightbox_rule) {
993
        $lightbox['image__lightbox2__'. $view_rule .'__'. $lightbox_rule] = array(
994
	 'label' => 'Lightbox2: '. $view_rule .'->'. $lightbox_rule,
995
          'field types' => array('image', 'file'),
996
        );
997
        $lightbox['imagefield__lightbox2_compact__'. $view_rule .'__'. $lightbox_rule] = array(
998
          'label' => 'Lightbox2: '. $view_rule .'->'. $lightbox_rule . ' compact',
999
          'field types' => array('image', 'filefield'),
1000
        );
1001
        $slideshow['image__lightshow2__'. $view_rule .'__'. $lightbox_rule] = array(
1002
          'label' => 'Lightbox2 slideshow: '. $view_rule .'->'. $lightbox_rule,
1003
          'field types' => array('image', 'file'),
1004
        );
1005
        $slideshow['imagefield__lightshow2_compact__'. $view_rule .'__'. $lightbox_rule] = array(
1006
          'label' => 'Lightbox2 slideshow: '. $view_rule .'->'. $lightbox_rule . ' compact',
1007
          'field types' => array('image', 'filefield'),
1008
        );
1009
      }
1010
    }
1011
    // Adding them now so they are in some sort of sensible order.
1012
    $formatters = array_merge($lightbox, $slideshow, $iframe);
1013
  }
1014
  if (module_exists('emfield') && module_exists('emimage')) {
1015
    $formatters['emimage_lightbox2'] = array(
1016
      'label' => t('Lightbox2: Image Thumbnail -> Original'),
1017
      'field types' => array('emimage'),
1018
    );
1019
    $formatters['emimage_lightshow2'] = array(
1020
      'label' => t('Lightbox2 slideshow: Image Thumbnail -> Original'),
1021
      'field types' => array('emimage'),
1022
    );
1023
    $formatters['emimage_lightframe2'] = array(
1024
      'label' => t('Lightbox2 iframe: Image Thumbnail -> Content'),
1025
      'field types' => array('emimage'),
1026
    );
1027
  }
1028
  if (variable_get('lightbox2_enable_video', FALSE) && module_exists('emfield') && module_exists('emvideo')) {
1029
    $formatters['emvideo_lightvideo'] = array(
1030
      'label' => t('Lightbox2: Image Thumbnail -> Full Size Video'),
1031
      'field types' => array('emvideo'),
1032
    );
1033
  }
1034
  if (module_exists('file')) {
1035
    $formatters['file_lightframe'] = array(
1036
      'label' => t('Lightbox2 iframe'),
1037
      'field types' => array('file'),
1038
    );
1039
  }
1040
  */
1041
}
1042

    
1043
/**
1044
 * Implements hook_field_formatter_view().
1045
 * 
1046
 * Temporarily a (pretty much) straight copy of image's
1047
 */
1048
function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
1049
  $element = array();
1050
  $settings = $display["settings"];
1051
  $lightbox_type = $settings['type'];
1052
  $image_style = $settings['image_style'];
1053
  $lightbox_style = $settings['lightbox_style'];
1054

    
1055
  if ($image_style == 'original') {
1056
    $image_style = NULL;
1057
  }
1058
  if ($lightbox_style == 'original') {
1059
    $lightbox_style = NULL;
1060
  }
1061

    
1062
  $wrapper = entity_metadata_wrapper($entity_type, $entity);
1063

    
1064
  foreach ($items as $delta => $item) {
1065
    $uri = array(
1066
      'path' => file_create_url($item['uri']),
1067
      'options' => array(),
1068
    );
1069
    $element[$delta] = array(
1070
      '#theme' => 'lightbox2_image',
1071
      '#item' => $item,
1072
      '#lightbox_type' => $lightbox_type,
1073
      '#image_style' => $image_style,
1074
      '#lightbox_style' => $lightbox_style,
1075
      '#path' => $uri,
1076
      '#node_id' => $wrapper->getIdentifier(),
1077
      '#field_name' => $field['field_name'],
1078
      '#caption' => $settings['caption'],
1079
    );
1080
  }
1081
  return ($element);
1082
  /*$element = array();
1083

    
1084
  // Check if the formatter involves a particular image style.
1085
  //$matches = array();
1086
  //if (preg_match('/__([a-z0-9_]+)/', $display['type'], $matches)) {
1087
  //  $image_style = $matches[1];
1088
  //}
1089

    
1090
  $pieces = explode('__', $display);
1091
  $image_style = $pieces[2];
1092
  // Temporary hardcoding link_file and image_style for debugging
1093
  //$image_style = 'thumbnail';
1094
  $link_file = TRUE;
1095

    
1096
  foreach ($items as $delta => $item) {
1097
    if (isset($link_file)) {
1098
      $uri = array(
1099
        'path' => file_create_url($item['uri']),
1100
        'options' => array(),
1101
      );
1102
    }
1103
    $element[$delta] = array(
1104
      '#theme' => 'lightbox2_image',
1105
      '#item' => $item,
1106
      '#image_style' => isset($image_style) ? $image_style : '',
1107
      '#path' => isset($uri) ? $uri : '',
1108
    );
1109
  }
1110

    
1111
  return $element;*/
1112
}
1113

    
1114

    
1115
/**
1116
 * Implementation of hook_theme().
1117
 */
1118
function lightbox2_theme($existing, $type, $theme, $path) {
1119
  $theme = array();
1120
  $theme['lightbox2_image'] = array(
1121
    'variables' => array(
1122
      'item' => NULL,
1123
      'path' => NULL,
1124
      'lightbox_type' => NULL,
1125
      'image_style' => NULL,
1126
      'lightbox_style' => NULL,
1127
      'node_id' => NULL,
1128
      'field_name' => NULL,
1129
      'caption' => NULL,
1130
     ),
1131
    //'variables' => array(),
1132
  );
1133
  //return($theme);
1134

    
1135
  /*
1136
  $theme = array(
1137
    'lightbox2_image' => array(
1138
    'variables' => array(
1139
     'item' => NULL,
1140
     'path' => NULL,
1141
     'image_style' => NULL
1142
     ),
1143
    ),
1144
    // Emfield theme functions.
1145
    'lightbox2_emimage' => array(
1146
      'variables' => array(
1147
        'field' => NULL,
1148
        'item' => NULL,
1149
        'formatter' => NULL,
1150
        'node' => NULL,
1151
        'args' => array()
1152
      ),
1153
    ),
1154
    'lightbox2_formatter_emimage' => array(
1155
      'render element' => 'element',
1156
    ),
1157
    'lightbox2_formatter_emimage_lightbox2' => array(
1158
      'render element' => 'element',
1159
      'function' => 'theme_lightbox2_formatter_emimage',
1160
    ),
1161
    'lightbox2_formatter_emimage_lightshow2' => array(
1162
      'render element' => 'element',
1163
      'function' => 'theme_lightbox2_formatter_emimage',
1164
    ),
1165
    'lightbox2_formatter_emimage_lightframe2' => array(
1166
      'render element' => 'element',
1167
      'function' => 'theme_lightbox2_formatter_emimage',
1168
    ),
1169
    'lightbox2_formatter_emvideo_lightvideo' => array(
1170
      'render element' => 'element',
1171
    ),
1172
    'lightbox2_emvideo' => array(
1173
      'variables' => array(
1174
        'field' => NULL,
1175
        'item' => NULL,
1176
        'formatter' => NULL,
1177
        'node' => NULL
1178
      ),
1179
    ),
1180
    // Filefield theme functions.
1181
    'lightbox2_formatter_filefield_lightframe' => array(
1182
      'render element' => 'element',
1183
    ),
1184
    'lightbox2_file_formatter_lightbox2_iframe' => array(
1185
      'variables' => array(
1186
        'file' => NULL,
1187
        'field' => NULL,
1188
        'file_formatter_settings' => NULL
1189
	  ),
1190
    ),
1191
    // Global imagecache + imagefield theme functions.
1192
    'lightbox2_formatter_imagefield' => array(
1193
       'render element' => 'element',
1194
    ),
1195
    'imagefield_image_imagecache_lightbox2' => array(
1196
      'variables' => array(
1197
        'view_preset' => NULL,
1198
        'field_name' => NULL,
1199
        'item' => NULL,
1200
        'node' => NULL,
1201
        'rel' => 'lightbox',
1202
        'args' => array()
1203
      ),
1204
    ),
1205
  );
1206

    
1207
   // Additional imagecache + imagefield theme functions, by preset.
1208
  if (module_exists("image")) {
1209

    
1210
    $theme['lightbox2_formatter_imagefield__lightframe2__original__node'] = array(
1211
      'render element' => 'element',
1212
      'function' => 'theme_lightbox2_formatter_imagefield',
1213
    );
1214
    $theme['lightbox2_formatter_imagefield__lightframe2__link__node'] = array(
1215
      'arguments' => array('element' => NULL),
1216
      'function' => 'theme_lightbox2_formatter_imagefield',
1217
      'file' => 'lightbox2.formatter.inc',
1218
    );
1219

    
1220
    foreach (image_styles() as $src) {
1221
      $theme['lightbox2_formatter_imagefield__lightbox2__'. $src['name'] .'__original'] = array(
1222
        'render element' => 'element',
1223
        'function' => 'theme_lightbox2_formatter_imagefield',
1224
        'file' => 'lightbox2.formatter.inc',
1225
      );
1226
      $theme['lightbox2_formatter_imagefield__lightbox2_compact__'. $src['name'] .'__original'] = array(
1227
        'arguments' => array('element' => NULL),
1228
        'function' => 'theme_lightbox2_formatter_imagefield',
1229
        'file' => 'lightbox2.formatter.inc',
1230
      );
1231
      $theme['lightbox2_formatter_imagefield__lightshow2__'. $src['name'] .'__original'] = array(
1232
        'render element' => 'element',
1233
        'function' => 'theme_lightbox2_formatter_imagefield',
1234
      );
1235
      $theme['lightbox2_formatter_imagefield__lightshow2_compact__'. $src['name'] .'__original'] = array(
1236
        'arguments' => array('element' => NULL),
1237
        'function' => 'theme_lightbox2_formatter_imagefield',
1238
        'file' => 'lightbox2.formatter.inc',
1239
      );
1240
      $theme['lightbox2_formatter_imagefield__lightbox2__original__'. $src['name']] = array(
1241
        'render element' => 'element',
1242
        'function' => 'theme_lightbox2_formatter_imagefield',
1243
      );
1244
      $theme['lightbox2_formatter_imagefield__lightbox2_compact__original__'. $src['name']] = array(
1245
        'arguments' => array('element' => NULL),
1246
        'function' => 'theme_lightbox2_formatter_imagefield',
1247
        'file' => 'lightbox2.formatter.inc',
1248
      );
1249
    	$theme['lightbox2_formatter_imagefield__lightshow2__original__'. $src['name']] = array(
1250
        'render element' => 'element',
1251
        'function' => 'theme_lightbox2_formatter_imagefield',
1252

    
1253
      );
1254
      $theme['lightbox2_formatter_imagefield__lightshow2_compact__original__'. $src['name']] = array(
1255
        'arguments' => array('element' => NULL),
1256
        'function' => 'theme_lightbox2_formatter_imagefield',
1257
        'file' => 'lightbox2.formatter.inc',
1258
      );
1259
      $theme['lightbox2_formatter_imagefield__lightframe2__'. $src['name'] .'__node'] = array(
1260
        'render element' => 'element',
1261
        'function' => 'theme_lightbox2_formatter_imagefield',
1262
      );
1263
      $theme['lightbox2_formatter_imagefield__lightbox2__link__'. $src['name']] = array(
1264
        'arguments' => array('element' => NULL),
1265
        'function' => 'theme_lightbox2_formatter_imagefield',
1266
        'file' => 'lightbox2.formatter.inc',
1267
      );
1268
      $theme['lightbox2_formatter_imagefield__lightshow2__link__'. $src['name']] = array(
1269
        'arguments' => array('element' => NULL),
1270
        'function' => 'theme_lightbox2_formatter_imagefield',
1271
        'file' => 'lightbox2.formatter.inc',
1272
      );
1273

    
1274
      foreach (image_styles() as $dest) {
1275
        $theme['lightbox2_formatter_imagefield__lightbox2__'. $src['name'] .'__'. $dest['name']] = array(
1276
          'render element' => 'element',
1277
          'function' => 'theme_lightbox2_formatter_imagefield',
1278
        );
1279
        $theme['lightbox2_formatter_imagefield__lightbox2_compact__'. $src['name'] .'__'. $dest['name']] = array(
1280
          'arguments' => array('element' => NULL),
1281
          'function' => 'theme_lightbox2_formatter_imagefield',
1282
          'file' => 'lightbox2.formatter.inc',
1283
        );
1284
        $theme['lightbox2_formatter_imagefield__lightshow2__'. $src['name'] .'__'. $dest['name']] = array(
1285
          'render element' => 'element',
1286
          'function' => 'theme_lightbox2_formatter_imagefield',
1287
        );
1288
        $theme['lightbox2_formatter_imagefield__lightshow2_compact__'. $src['name'] .'__'. $dest['name']] = array(
1289
          'arguments' => array('element' => NULL),
1290
          'function' => 'theme_lightbox2_formatter_imagefield',
1291
          'file' => 'lightbox2.formatter.inc',
1292
        );
1293
      }
1294
    }
1295
  }
1296
  
1297
  // Additional Insert theme functions.
1298
  if (module_exists('insert')) {
1299
    // Theme functions in lightbox2.insert.inc.
1300
    $theme['lightbox2_insert_image'] = array(
1301
      'arguments' => array('item' => NULL, 'widget' => NULL, 'type' => NULL, 'image_preset_name' => NULL, 'link_preset_name' => NULL),
1302
      'template' => 'lightbox2-insert-image',
1303
    );
1304
  }*/
1305
  foreach ($theme as &$array) {
1306
    $array['file'] = 'lightbox2.formatter.inc';
1307
  }
1308
  return $theme;
1309
}
1310

    
1311
/**
1312
 * Configures settings and outputs the video.
1313
 *
1314
 * @param nid
1315
 *   The node id.
1316
 * @param width
1317
 *   The lightbox video width.
1318
 * @param height
1319
 *   The lightbox video height.
1320
 * @param field_name
1321
 *   The name of the cck field the video is contained in.
1322
 * @param provider
1323
 *   The name of the 3rd party video provider.
1324
 * @param id
1325
 *   The video id.
1326
 */
1327
/*
1328
function lightbox2_emvideo($node, $width, $height, $field_name, $provider, $id) {
1329
  $field = content_fields($field_name);
1330
  $field['widget']['video_width'] = $width;
1331
  $field['widget']['video_height'] = $height;
1332
  $field['widget']['video_autoplay'] = 1;
1333
  if (!content_access('view', $field, NULL, $node)) {
1334
    drupal_access_denied();
1335
    return;
1336
  }
1337

    
1338
  $items = $node->$field_name;
1339
  if (is_array($items)) {
1340
    foreach ($items as $item) {
1341
      if ($item['provider'] == $provider && $item['value'] == $id) {
1342
        break;
1343
      }
1344
    }
1345
  }
1346
  print theme('emvideo_video_video', $field, $item, 'video_video', $node);
1347
}*/
1348

    
1349
/**
1350
 * Return TRUE if current path is disabled for lightbox according to
1351
 * lightbox2_page_list and lightbox2_page_init_action.
1352
 */
1353
function lightbox2_exclude_these_paths() {
1354
  $action = variable_get('lightbox2_page_init_action', 'page_disable');
1355
  $page_list = variable_get('lightbox2_page_list', '');
1356

    
1357
  if (!empty($page_list)) {
1358
    // Retrieve Drupal alias for the current path (if exists).
1359
    $alias = drupal_get_path_alias($_GET['q']);
1360

    
1361
    if (drupal_match_path($_GET['q'], $page_list) || drupal_match_path($alias, $page_list)) {
1362
      return ($action == 'page_disable' ? 1 : 0);
1363
    }
1364
  }
1365

    
1366
  return ($action == 'page_disable' ? 0 : 1);
1367
}
1368

    
1369
/**
1370
 * Preprocess function for template by theme('page').
1371
 */
1372
function lightbox2_preprocess_page(&$variables) {
1373
  if (arg(0) != 'node' || arg(2) != 'lightbox2') {
1374
    return;
1375
  }
1376
  //Overwrite template_preprocess_page() region settings.
1377
  global $theme;
1378
  // Retrieve all block regions.
1379
  $regions = system_region_list($theme);
1380
  // Remove all region content assigned via blocks.
1381
  foreach (array_keys($regions) as $region) {
1382
    if ($region != 'content') {
1383
      $variables[$region] = NULL;
1384
    }
1385
  }
1386
  // Set up layout variable to none.
1387
  $variables['layout'] = 'none';
1388
  //additional template files for e.g. page-node-lightbox.tpl.php are allready implemented through template_preprocess_page()
1389
}
1390

    
1391
/**
1392
 * Display the video object.
1393
 *
1394
 * Displays the video object for a specified nid.  It is used for displaying
1395
 * videos in acidfree lists in a lightbox when the thumbnail is clicked on.  It
1396
 * is only triggered for the url 'node/%nid/lightframevideo'.
1397
 *
1398
 * @param $node
1399
 *   The $node object.
1400
 */
1401
/*
1402
function lightbox2_acidfree_video($node) {
1403
print theme('video_player', array( 'node' => $node ) );
1404
}
1405
*/
1406
/**
1407
 * Implementation of filefield's hook_file_formatter_info().
1408
 */
1409
function lightbox2_file_formatter_info() {
1410
  return array(
1411
    'lightbox2_iframe' => array(
1412
      'suitability callback' => 'lightbox2_check_filefield_extension',
1413
      'label' => t('Lightbox2 iframe'),
1414
      'description' => t('Displays all kinds of files in a popup lightbox in an iframe.'),
1415
    ),
1416
    'lightbox2_image' => array(
1417
      'suitability callback' => 'lightbox2_check_filefield_image_extension',
1418
      'label' => t('Lightbox2 image'),
1419
      'description' => t('Displays image files in a popup lightbox.'),
1420
    ),
1421
  );
1422
}
1423

    
1424
/**
1425
 * Suitability callback function for the filefield formatter.
1426
 *
1427
 * @param $file
1428
 *   The file object, containing filepath, mime type, etc.
1429
 * @param $field
1430
 *   CCK field information.
1431
 * @return
1432
 *   True if file extension is supported.
1433
 */
1434
function lightbox2_check_filefield_extension($file, $field) {
1435
  $ext = array_pop(explode('.', $file->filename));
1436
  return lightbox2_supported_file_extension($ext);
1437
}
1438

    
1439
/**
1440
 * Suitability callback function for the image filefield formatter.
1441
 *
1442
 * @param $file
1443
 *   The file object, containing filepath, mime type, etc.
1444
 * @param $field
1445
 *   CCK field information.
1446
 * @return
1447
 *   True if file extension is supported.
1448
 */
1449
function lightbox2_check_filefield_image_extension($file, $field) {
1450
  $ext = array_pop(explode('.', $file->filename));
1451
  return lightbox2_supported_file_extension($ext, 'image');
1452
}
1453

    
1454

    
1455
/**
1456
 * Check whether a given file extension is supported by the lightbox iframe.
1457
 *
1458
 * @param $ext
1459
 *   File extension
1460
 * @param $type
1461
 *   Type of file extensions to check.
1462
 * @return
1463
 *   TRUE if extension is supported.
1464
 */
1465
function lightbox2_supported_file_extension($ext, $type = 'all') {
1466
  $image_extensions = array('png', 'jpg', 'jpeg', 'gif', 'bmp');
1467
  $movie_extensions = array('dv', 'mov', 'moov', 'movie', 'mp4', 'asf', 'wm', 'wmv', 'avi', 'mpg', 'mpeg');
1468
  $web_extensions = array('asp', 'aspx', 'cgi', 'cfm', 'htm', 'html', 'pl', 'php', 'php3', 'php4', 'php5', 'phtml', 'rb', 'rhtml', 'shtml', 'txt', 'vbs');
1469
  $misc_extensions = array('pdf');
1470

    
1471
  $extensions = array();
1472
  switch ($type) {
1473
    case 'image':
1474
      $extensions = $image_extensions;
1475
      break;
1476
    case 'movie':
1477
      $extensions = $movie_extensions;
1478
      break;
1479
    case 'web':
1480
      $extensions = $web_extensions;
1481
      break;
1482
    case 'misc':
1483
      $extensions = $misc_extensions;
1484
      break;
1485
    case 'all':
1486
    default:
1487
      $extensions = array_merge($image_extensions, $movie_extensions, $web_extensions, $misc_extensions);
1488
      break;
1489
  }
1490

    
1491
  if (in_array(drupal_strtolower($ext), $extensions)) {
1492
    return TRUE;
1493
  }
1494

    
1495
  return FALSE;
1496
}
1497

    
1498
/**
1499
 * Helper function to compare the string length of two items.  Used when trying
1500
 * to sort an array by value length.
1501
 *
1502
 * @param $a
1503
 *   String to compare.
1504
 * @param $b
1505
 *   String to compare.
1506
 * @return
1507
 *   0 if they are the same length, -1 if $a is longer than $b, 1 otherwise.
1508
 */
1509
function sort_by_length($a, $b) {
1510
  if ($a == $b) {
1511
    return 0;
1512
  }
1513
  return (drupal_strlen($a) > drupal_strlen($b) ? -1 : 1);
1514
}
1515

    
1516
/**
1517
 * Get the user login form.
1518
 */
1519
function lightbox2_login() {
1520

    
1521
  // do not use lightbox2 for failed validation ie: bad password
1522
  // instead, return the fully rendered Drupal page with errors.
1523
  if (count($_POST)) {
1524
    return drupal_get_form('user_login_block');
1525
  }
1526
  else {
1527
    print drupal_render(drupal_get_form('user_login_block'));
1528
    // If the OpenID module is enabled, the javascript and css may not exist
1529
    // on the page, so add them dynamically.
1530
    if (module_exists('openid')) {
1531
      $path = drupal_get_path('module', 'openid');
1532
      $js_file = base_path() . $path . '/openid.js';
1533
      $css_file = base_path() . $path . '/openid.css';
1534

    
1535
      // Load the javascript dynamically.
1536
      print '<script type="text/javascript">$.getScript("' . $js_file . '", function () {if ($.isFunction(Drupal.behaviors.openid)) { Drupal.behaviors.openid(document); } });</script>';
1537

    
1538
      // Load the css file dynamically.
1539
      print '<script type="text/javascript">
1540
        var fileref=document.createElement("link");
1541
        fileref.setAttribute("rel", "stylesheet");
1542
        fileref.setAttribute("type", "text/css");
1543
        fileref.setAttribute("href", "'. $css_file . '");
1544
        document.getElementsByTagName("head")[0].appendChild(fileref);
1545
        </script>';
1546
    }
1547

    
1548
    // drupal_add_js() with 'inline' didn't seem to work, possibly because this is
1549
    // AJAX loaded content.
1550
    print '<script type="text/javascript">Drupal.attachBehaviors();</script>';
1551
  }
1552
  exit;
1553
}
1554

    
1555
/**
1556
 * Get the contact form.
1557
 */
1558
function lightbox2_contact() {
1559
  if (module_exists('contact') && variable_get('lightbox2_enable_contact', FALSE) && user_access('access site-wide contact form')) {
1560
    $path = drupal_get_path('module', 'contact');
1561
    include_once($path . '/contact.pages.inc');
1562
    print drupal_render(drupal_get_form('contact_site_form'));
1563
    // drupal_add_js() with 'inline' didn't seem to work, possibly because this is
1564
    // AJAX loaded content.
1565
    print '<script type="text/javascript">Drupal.attachBehaviors();</script>';
1566
    exit;
1567
  }
1568
}
1569

    
1570
/**
1571
 * Implementation of hook_form_alter().
1572
 *
1573
 * Update the page action and input size.
1574
 *
1575
 * @param &$form
1576
 *   General reference used in drupal, defining the structure & the fields of
1577
 *   a form.
1578
 * @param $form_state
1579
 *   General variable, used to control the processing of the form.
1580
 * @param $form_id
1581
 *   The default is "user_login_block"; hold the page where the function is being
1582
 *   used.
1583
 * @return
1584
 *   Return the structure of the form.
1585
 */
1586
function lightbox2_form_user_login_block_alter(&$form, $form_state, $form_id = "user_login_block") {
1587
  if ($form_id == 'user_login_block' && arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'lightbox2') {
1588
    $form['#action'] = url('user/login/lightbox2', array('query' => array('destination' => $_GET['destination'])));
1589
  }
1590
}
1591

    
1592
function lightbox2_form_contact_site_form_alter(&$form, $form_state, $form_id = "contact_site_form") {
1593
  if ($form_id == 'contact_site_form' && arg(0) == 'contact' && arg(1) == 'lightbox2') {
1594
    $form['#action'] = url('contact', array('query' => array('destination' => $_GET['destination'])));
1595
  }
1596
}
1597

    
1598
/**
1599
 * Implementation of hook_link_alter().
1600
 *
1601
 * Add a lightbox2 rel attribute to the image link sizes on the image node.
1602
 */
1603
function lightbox2_link_alter(&$links, $node) {
1604
  $image_node_handler = variable_get('lightbox2_image_node', 0);
1605

    
1606
  // Only operate on image nodes and if automatic handling for image nodes is
1607
  // enabled.  Also ensure $links is an array (bug in contemplate module).
1608
  if (!$image_node_handler || ($node->type != 'image' && $image_node_handler) || !is_array($links)) {
1609
    return;
1610
  }
1611
  $trigger_sizes = variable_get('lightbox2_trigger_image_size', array('thumbnail'));
1612

    
1613
  // Change original ('original') to '_original'.
1614
  if (isset($trigger_sizes['original'])) {
1615
    unset($trigger_sizes['original']);
1616
    $trigger_sizes['_original'] = '_original';
1617
  }
1618

    
1619
  $rel = '';
1620
  switch ($image_node_handler) {
1621
    case 1: // Lightbox.
1622
    case 2: // Lightbox grouped.
1623
    case 3: // Slideshow.
1624
      $rel = 'lightbox';
1625
      break;
1626
    case 4: // Lightframe.
1627
    case 5: // Lightframe grouped.
1628
      $rel = 'lightframe';
1629
      break;
1630
  }
1631
  $rel = $rel . '[][' . $node->title . ']';
1632
  foreach ($trigger_sizes as $size) {
1633
    if (isset($links['image_size_' . $size])) {
1634
      $links['image_size_' . $size]['attributes']['rel'] = $rel;
1635
      $links['image_size_' . $size]['href'] = $node->images[$size];
1636
      unset($links['image_size_' . $size]['query']);
1637
    }
1638
  }
1639
}
1640

    
1641
/**
1642
 * Implementation of hook_views_api().
1643
 */
1644
function lightbox2_views_api() {
1645
  return array(
1646
    'api' => '3.0',
1647
  );
1648
}
1649

    
1650
function lightbox2_filter_xss() {
1651
  $allowed_tags = trim(variable_get('lightbox2_filter_xss_allowed_tags', 'p, br, a, em, strong, cite, code, ul, ol, li, dl, dt, dd, '));
1652
  $allowed_tags = (empty($allowed_tags) ? array() : preg_split('/[,\s]+/', $allowed_tags));
1653
  if (!empty($_POST['allowed_tags']) && $_POST['allowed_tags'] != 'undefined') {
1654
    $allowed_tags = explode(',', $_POST['allowed_tags']);
1655
    $output = filter_xss($_POST['string'], $allowed_tags);
1656
  }
1657
  else {
1658
    $output = filter_xss($_POST['string'], $allowed_tags);
1659
  }
1660
  drupal_json_output($output);
1661
}
1662