Projet

Général

Profil

Paste
Télécharger (73,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / lightbox2 / lightbox2.module @ 87dbc3bf

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(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(variable_get('lightbox2_image_count_str', 'Image !current of !total')),
714
    'video_count' => check_plain(variable_get('lightbox2_video_count_str', 'Video !current of !total')),
715
    'page_count' => check_plain(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
  );
753
  if ($enable_video) {
754
    $js_settings['flvPlayer'] = url(check_plain(trim(variable_get('lightbox2_flv_player_path', 'flvplayer.swf'), '/')));
755
    $js_settings['flvFlashvars'] = check_plain(variable_get('lightbox2_flv_player_flashvars', ''));
756
  }
757

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

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

    
765

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

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

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

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

    
800
/**
801
 * Implementation of hook_field_formatter_info().
802
 *
803
 * Add certain lightbox and imagecache formatters to CCK image fields if
804
 * the imagefield.module and the imagecache.module exist.  Add additional
805
 * formatters if emfield, emimage and/or emvideo modules exist.
806
 */
807
function lightbox2_field_formatter_info() {
808
  $formatters = array();
809
  if (module_exists('image')) {
810
    $image = $lightbox = image_styles();
811
    $types = array('lightbox', 'lightshow');
812
    foreach ($types as $type) {
813
      foreach ($image as $image_key => $image_value ) {
814
        $formatters['lightbox2__' . $type . '__' . $image_key . '__original'] = array(
815
          'label' => 'Lightbox2: ' . $type . ': ' . $image_key . '->original',
816
          'field types' => array('image'),
817
        );
818
        foreach ($lightbox as $lightbox_key => $lightbox_value ) {
819
          $formatters['lightbox2__' . $type . '__' . $image_key . "__" . $lightbox_key] = array(
820
            'label' => 'Lightbox2: ' . $type . ': ' . $image_key . '->' . $lightbox_key,
821
            'field types' => array('image'),
822
          );
823
        }
824
      }
825
    }
826
  }
827
  return $formatters;
828
  /*
829
  // Handle imagefield and filefield images.
830
  if (module_exists('image')) {
831
  	$rules = array();
832
    if (function_exists('image_styles')) {
833
      $presets = image_styles();
834
      foreach ($presets as $preset_id => $preset_info) {
835
        $rules[$preset_id] = $preset_info['name'];
836
      }
837
    }
838
    $iframe['image__lightframe2__original__node'] = array(
839
      'label' => 'Lightbox2 iframe: original->node page',
840
      'field types' => array('image', 'file'),
841
    );
842
    $iframe['imagefield__lightframe2__link__node'] = array(
843
      'label' => 'Lightbox2 iframe: link->node page',
844
      'field types' => array('image', 'file'),
845
    );
846
    foreach ($rules as $view_rule) {
847
      $lightbox['image__lightbox2__original__'. $view_rule] = array(
848
        'label' => 'Lightbox2: original->'. $view_rule,
849
        'field types' => array('image', 'file'),
850
      );
851
      $lightbox['imagefield__lightbox2_compact__original__'. $view_rule] = array(
852
        'label' => 'Lightbox2: original->'. $view_rule . ' compact',
853
        'field types' => array('image', 'file'),
854
      );
855
      $lightbox['image__lightbox2__'. $view_rule .'__original'] = array(
856
        'label' => 'Lightbox2: '. $view_rule .'->original',
857
        'field types' => array('image', 'file'),
858
      );
859
      $lightbox['imagefield__lightbox2_compact__'. $view_rule .'__original'] = array(
860
        'label' => 'Lightbox2: '. $view_rule .'->original compact',
861
        'field types' => array('image', 'file'),
862
      );
863
      $lightbox['imagefield__lightbox2__link__'. $view_rule] = array(
864
        'label' => 'Lightbox2: link->'. $view_rule,
865
        'field types' => array('image', 'file'),
866
      );
867
      $slideshow['image__lightshow2__original__'. $view_rule] = array(
868
        'label' => 'Lightbox2 slideshow: original->'. $view_rule,
869
        'field types' => array('image', 'file'),
870
      );
871
      $slideshow['imagefield__lightshow2_compact__original__'. $view_rule] = array(
872
        'label' => 'Lightbox2 slideshow: original->'. $view_rule . ' compact',
873
        'field types' => array('image', 'filefield'),
874
      );
875
      $slideshow['image__lightshow2__'. $view_rule .'__original'] = array(
876
        'label' => 'Lightbox2 slideshow: '. $view_rule .'->original',
877
        'field types' => array('image', 'file'),
878
      );
879
      $slideshow['imagefield__lightshow2_compact__'. $view_rule .'__original'] = array(
880
        'label' => 'Lightbox2 slideshow: '. $view_rule .'->original compact',
881
        'field types' => array('image', 'filefield'),
882
      );
883
      $slideshow['imagefield__lightshow2__link__'. $view_rule] = array(
884
        'label' => 'Lightbox2 slideshow: link->'. $view_rule,
885
        'field types' => array('image', 'filefield'),
886
      );
887
      $iframe['image__lightframe2__'. $view_rule .'__node'] = array(
888
        'label' => 'Lightbox2 iframe: '. $view_rule .'->node page',
889
        'field types' => array('image', 'file'),
890
      );
891
	foreach ($rules as $lightbox_rule) {
892
        $lightbox['image__lightbox2__'. $view_rule .'__'. $lightbox_rule] = array(
893
	 'label' => 'Lightbox2: '. $view_rule .'->'. $lightbox_rule,
894
          'field types' => array('image', 'file'),
895
        );
896
        $lightbox['imagefield__lightbox2_compact__'. $view_rule .'__'. $lightbox_rule] = array(
897
          'label' => 'Lightbox2: '. $view_rule .'->'. $lightbox_rule . ' compact',
898
          'field types' => array('image', 'filefield'),
899
        );
900
        $slideshow['image__lightshow2__'. $view_rule .'__'. $lightbox_rule] = array(
901
          'label' => 'Lightbox2 slideshow: '. $view_rule .'->'. $lightbox_rule,
902
          'field types' => array('image', 'file'),
903
        );
904
        $slideshow['imagefield__lightshow2_compact__'. $view_rule .'__'. $lightbox_rule] = array(
905
          'label' => 'Lightbox2 slideshow: '. $view_rule .'->'. $lightbox_rule . ' compact',
906
          'field types' => array('image', 'filefield'),
907
        );
908
      }
909
    }
910
    // Adding them now so they are in some sort of sensible order.
911
    $formatters = array_merge($lightbox, $slideshow, $iframe);
912
  }
913
  if (module_exists('emfield') && module_exists('emimage')) {
914
    $formatters['emimage_lightbox2'] = array(
915
      'label' => t('Lightbox2: Image Thumbnail -> Original'),
916
      'field types' => array('emimage'),
917
    );
918
    $formatters['emimage_lightshow2'] = array(
919
      'label' => t('Lightbox2 slideshow: Image Thumbnail -> Original'),
920
      'field types' => array('emimage'),
921
    );
922
    $formatters['emimage_lightframe2'] = array(
923
      'label' => t('Lightbox2 iframe: Image Thumbnail -> Content'),
924
      'field types' => array('emimage'),
925
    );
926
  }
927
  if (variable_get('lightbox2_enable_video', FALSE) && module_exists('emfield') && module_exists('emvideo')) {
928
    $formatters['emvideo_lightvideo'] = array(
929
      'label' => t('Lightbox2: Image Thumbnail -> Full Size Video'),
930
      'field types' => array('emvideo'),
931
    );
932
  }
933
  if (module_exists('file')) {
934
    $formatters['file_lightframe'] = array(
935
      'label' => t('Lightbox2 iframe'),
936
      'field types' => array('file'),
937
    );
938
  }
939
  */
940
}
941

    
942
/**
943
 * Implements hook_field_formatter_view().
944
 * 
945
 * Temporarily a (pretty much) straight copy of image's
946
 */
947
function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
948
  $element = array();
949
  $pieces = explode('__', $display['type']);
950
  $lightbox_type = $pieces[1];
951
  $image_style = $pieces[2];
952
  $lightbox_style = $pieces[3];
953

    
954
  if ($image_style == 'original') {
955
    $image_style = NULL;
956
  }
957
  if ($lightbox_style == 'original') {
958
    $lightbox_style = NULL;
959
  }
960

    
961
  if ($entity_type == 'node') {
962
    $node_id = $entity->nid;
963
  }
964

    
965
  foreach ($items as $delta => $item) {
966
    $uri = array(
967
      'path' => file_create_url($item['uri']),
968
      'options' => array(),
969
    );
970
    $element[$delta] = array(
971
      '#theme' => 'lightbox2_image',
972
      '#item' => $item,
973
      '#lightbox_type' => $lightbox_type,
974
      '#image_style' => $image_style,
975
      '#lightbox_style' => $lightbox_style,
976
      '#path' => $uri,
977
      '#node_id' => $node_id,
978
      '#field_name' => $field['field_name'],
979
    );
980
  }
981
  return ($element);
982
  /*$element = array();
983

    
984
  // Check if the formatter involves a particular image style.
985
  //$matches = array();
986
  //if (preg_match('/__([a-z0-9_]+)/', $display['type'], $matches)) {
987
  //  $image_style = $matches[1];
988
  //}
989

    
990
  $pieces = explode('__', $display);
991
  $image_style = $pieces[2];
992
  // Temporary hardcoding link_file and image_style for debugging
993
  //$image_style = 'thumbnail';
994
  $link_file = TRUE;
995

    
996
  foreach ($items as $delta => $item) {
997
    if (isset($link_file)) {
998
      $uri = array(
999
        'path' => file_create_url($item['uri']),
1000
        'options' => array(),
1001
      );
1002
    }
1003
    $element[$delta] = array(
1004
      '#theme' => 'lightbox2_image',
1005
      '#item' => $item,
1006
      '#image_style' => isset($image_style) ? $image_style : '',
1007
      '#path' => isset($uri) ? $uri : '',
1008
    );
1009
  }
1010

    
1011
  return $element;*/
1012
}
1013

    
1014

    
1015
/**
1016
 * Implementation of hook_theme().
1017
 */
1018
function lightbox2_theme($existing, $type, $theme, $path) {
1019
  $theme = array();
1020
  $theme['lightbox2_image'] = array(
1021
    'variables' => array(
1022
      'item' => NULL,
1023
      'path' => NULL,
1024
      'lightbox_type' => NULL,
1025
      'image_style' => NULL,
1026
      'lightbox_style' => NULL,
1027
      'node_id' => NULL,
1028
      'field_name' => NULL,
1029
     ),
1030
    //'variables' => array(),
1031
  );
1032
  //return($theme);
1033

    
1034
  /*
1035
  $theme = array(
1036
    'lightbox2_image' => array(
1037
    'variables' => array(
1038
     'item' => NULL,
1039
     'path' => NULL,
1040
     'image_style' => NULL
1041
     ),
1042
    ),
1043
    // Emfield theme functions.
1044
    'lightbox2_emimage' => array(
1045
      'variables' => array(
1046
        'field' => NULL,
1047
        'item' => NULL,
1048
        'formatter' => NULL,
1049
        'node' => NULL,
1050
        'args' => array()
1051
      ),
1052
    ),
1053
    'lightbox2_formatter_emimage' => array(
1054
      'render element' => 'element',
1055
    ),
1056
    'lightbox2_formatter_emimage_lightbox2' => array(
1057
      'render element' => 'element',
1058
      'function' => 'theme_lightbox2_formatter_emimage',
1059
    ),
1060
    'lightbox2_formatter_emimage_lightshow2' => array(
1061
      'render element' => 'element',
1062
      'function' => 'theme_lightbox2_formatter_emimage',
1063
    ),
1064
    'lightbox2_formatter_emimage_lightframe2' => array(
1065
      'render element' => 'element',
1066
      'function' => 'theme_lightbox2_formatter_emimage',
1067
    ),
1068
    'lightbox2_formatter_emvideo_lightvideo' => array(
1069
      'render element' => 'element',
1070
    ),
1071
    'lightbox2_emvideo' => array(
1072
      'variables' => array(
1073
        'field' => NULL,
1074
        'item' => NULL,
1075
        'formatter' => NULL,
1076
        'node' => NULL
1077
      ),
1078
    ),
1079
    // Filefield theme functions.
1080
    'lightbox2_formatter_filefield_lightframe' => array(
1081
      'render element' => 'element',
1082
    ),
1083
    'lightbox2_file_formatter_lightbox2_iframe' => array(
1084
      'variables' => array(
1085
        'file' => NULL,
1086
        'field' => NULL,
1087
        'file_formatter_settings' => NULL
1088
	  ),
1089
    ),
1090
    // Global imagecache + imagefield theme functions.
1091
    'lightbox2_formatter_imagefield' => array(
1092
       'render element' => 'element',
1093
    ),
1094
    'imagefield_image_imagecache_lightbox2' => array(
1095
      'variables' => array(
1096
        'view_preset' => NULL,
1097
        'field_name' => NULL,
1098
        'item' => NULL,
1099
        'node' => NULL,
1100
        'rel' => 'lightbox',
1101
        'args' => array()
1102
      ),
1103
    ),
1104
  );
1105

    
1106
   // Additional imagecache + imagefield theme functions, by preset.
1107
  if (module_exists("image")) {
1108

    
1109
    $theme['lightbox2_formatter_imagefield__lightframe2__original__node'] = array(
1110
      'render element' => 'element',
1111
      'function' => 'theme_lightbox2_formatter_imagefield',
1112
    );
1113
    $theme['lightbox2_formatter_imagefield__lightframe2__link__node'] = array(
1114
      'arguments' => array('element' => NULL),
1115
      'function' => 'theme_lightbox2_formatter_imagefield',
1116
      'file' => 'lightbox2.formatter.inc',
1117
    );
1118

    
1119
    foreach (image_styles() as $src) {
1120
      $theme['lightbox2_formatter_imagefield__lightbox2__'. $src['name'] .'__original'] = array(
1121
        'render element' => 'element',
1122
        'function' => 'theme_lightbox2_formatter_imagefield',
1123
        'file' => 'lightbox2.formatter.inc',
1124
      );
1125
      $theme['lightbox2_formatter_imagefield__lightbox2_compact__'. $src['name'] .'__original'] = array(
1126
        'arguments' => array('element' => NULL),
1127
        'function' => 'theme_lightbox2_formatter_imagefield',
1128
        'file' => 'lightbox2.formatter.inc',
1129
      );
1130
      $theme['lightbox2_formatter_imagefield__lightshow2__'. $src['name'] .'__original'] = array(
1131
        'render element' => 'element',
1132
        'function' => 'theme_lightbox2_formatter_imagefield',
1133
      );
1134
      $theme['lightbox2_formatter_imagefield__lightshow2_compact__'. $src['name'] .'__original'] = array(
1135
        'arguments' => array('element' => NULL),
1136
        'function' => 'theme_lightbox2_formatter_imagefield',
1137
        'file' => 'lightbox2.formatter.inc',
1138
      );
1139
      $theme['lightbox2_formatter_imagefield__lightbox2__original__'. $src['name']] = array(
1140
        'render element' => 'element',
1141
        'function' => 'theme_lightbox2_formatter_imagefield',
1142
      );
1143
      $theme['lightbox2_formatter_imagefield__lightbox2_compact__original__'. $src['name']] = array(
1144
        'arguments' => array('element' => NULL),
1145
        'function' => 'theme_lightbox2_formatter_imagefield',
1146
        'file' => 'lightbox2.formatter.inc',
1147
      );
1148
    	$theme['lightbox2_formatter_imagefield__lightshow2__original__'. $src['name']] = array(
1149
        'render element' => 'element',
1150
        'function' => 'theme_lightbox2_formatter_imagefield',
1151

    
1152
      );
1153
      $theme['lightbox2_formatter_imagefield__lightshow2_compact__original__'. $src['name']] = array(
1154
        'arguments' => array('element' => NULL),
1155
        'function' => 'theme_lightbox2_formatter_imagefield',
1156
        'file' => 'lightbox2.formatter.inc',
1157
      );
1158
      $theme['lightbox2_formatter_imagefield__lightframe2__'. $src['name'] .'__node'] = array(
1159
        'render element' => 'element',
1160
        'function' => 'theme_lightbox2_formatter_imagefield',
1161
      );
1162
      $theme['lightbox2_formatter_imagefield__lightbox2__link__'. $src['name']] = array(
1163
        'arguments' => array('element' => NULL),
1164
        'function' => 'theme_lightbox2_formatter_imagefield',
1165
        'file' => 'lightbox2.formatter.inc',
1166
      );
1167
      $theme['lightbox2_formatter_imagefield__lightshow2__link__'. $src['name']] = array(
1168
        'arguments' => array('element' => NULL),
1169
        'function' => 'theme_lightbox2_formatter_imagefield',
1170
        'file' => 'lightbox2.formatter.inc',
1171
      );
1172

    
1173
      foreach (image_styles() as $dest) {
1174
        $theme['lightbox2_formatter_imagefield__lightbox2__'. $src['name'] .'__'. $dest['name']] = array(
1175
          'render element' => 'element',
1176
          'function' => 'theme_lightbox2_formatter_imagefield',
1177
        );
1178
        $theme['lightbox2_formatter_imagefield__lightbox2_compact__'. $src['name'] .'__'. $dest['name']] = array(
1179
          'arguments' => array('element' => NULL),
1180
          'function' => 'theme_lightbox2_formatter_imagefield',
1181
          'file' => 'lightbox2.formatter.inc',
1182
        );
1183
        $theme['lightbox2_formatter_imagefield__lightshow2__'. $src['name'] .'__'. $dest['name']] = array(
1184
          'render element' => 'element',
1185
          'function' => 'theme_lightbox2_formatter_imagefield',
1186
        );
1187
        $theme['lightbox2_formatter_imagefield__lightshow2_compact__'. $src['name'] .'__'. $dest['name']] = array(
1188
          'arguments' => array('element' => NULL),
1189
          'function' => 'theme_lightbox2_formatter_imagefield',
1190
          'file' => 'lightbox2.formatter.inc',
1191
        );
1192
      }
1193
    }
1194
  }
1195
  
1196
  // Additional Insert theme functions.
1197
  if (module_exists('insert')) {
1198
    // Theme functions in lightbox2.insert.inc.
1199
    $theme['lightbox2_insert_image'] = array(
1200
      'arguments' => array('item' => NULL, 'widget' => NULL, 'type' => NULL, 'image_preset_name' => NULL, 'link_preset_name' => NULL),
1201
      'template' => 'lightbox2-insert-image',
1202
    );
1203
  }*/
1204
  foreach ($theme as &$array) {
1205
    $array['file'] = 'lightbox2.formatter.inc';
1206
  }
1207
  return $theme;
1208
}
1209

    
1210
/**
1211
 * Configures settings and outputs the video.
1212
 *
1213
 * @param nid
1214
 *   The node id.
1215
 * @param width
1216
 *   The lightbox video width.
1217
 * @param height
1218
 *   The lightbox video height.
1219
 * @param field_name
1220
 *   The name of the cck field the video is contained in.
1221
 * @param provider
1222
 *   The name of the 3rd party video provider.
1223
 * @param id
1224
 *   The video id.
1225
 */
1226
/*
1227
function lightbox2_emvideo($node, $width, $height, $field_name, $provider, $id) {
1228
  $field = content_fields($field_name);
1229
  $field['widget']['video_width'] = $width;
1230
  $field['widget']['video_height'] = $height;
1231
  $field['widget']['video_autoplay'] = 1;
1232
  if (!content_access('view', $field, NULL, $node)) {
1233
    drupal_access_denied();
1234
    return;
1235
  }
1236

    
1237
  $items = $node->$field_name;
1238
  if (is_array($items)) {
1239
    foreach ($items as $item) {
1240
      if ($item['provider'] == $provider && $item['value'] == $id) {
1241
        break;
1242
      }
1243
    }
1244
  }
1245
  print theme('emvideo_video_video', $field, $item, 'video_video', $node);
1246
}*/
1247

    
1248
/**
1249
 * Return TRUE if current path is disabled for lightbox according to
1250
 * lightbox2_page_list and lightbox2_page_init_action.
1251
 */
1252
function lightbox2_exclude_these_paths() {
1253
  $action = variable_get('lightbox2_page_init_action', 'page_disable');
1254
  $page_list = variable_get('lightbox2_page_list', '');
1255

    
1256
  if (!empty($page_list)) {
1257
    // Retrieve Drupal alias for the current path (if exists).
1258
    $alias = drupal_get_path_alias($_GET['q']);
1259

    
1260
    if (drupal_match_path($_GET['q'], $page_list) || drupal_match_path($alias, $page_list)) {
1261
      return ($action == 'page_disable' ? 1 : 0);
1262
    }
1263
  }
1264

    
1265
  return ($action == 'page_disable' ? 0 : 1);
1266
}
1267

    
1268
/**
1269
 * Preprocess function for template by theme('page').
1270
 */
1271
function lightbox2_preprocess_page(&$variables) {
1272
  if (arg(0) != 'node' || arg(2) != 'lightbox2') {
1273
    return;
1274
  }
1275
  //Overwrite template_preprocess_page() region settings.
1276
  global $theme;
1277
  // Retrieve all block regions.
1278
  $regions = system_region_list($theme);
1279
  // Remove all region content assigned via blocks.
1280
  foreach (array_keys($regions) as $region) {
1281
    if ($region != 'content') {
1282
      $variables[$region] = NULL;
1283
    }
1284
  }
1285
  // Set up layout variable to none.
1286
  $variables['layout'] = 'none';
1287
  //additional template files for e.g. page-node-lightbox.tpl.php are allready implemented through template_preprocess_page()
1288
}
1289

    
1290
/**
1291
 * Display the video object.
1292
 *
1293
 * Displays the video object for a specified nid.  It is used for displaying
1294
 * videos in acidfree lists in a lightbox when the thumbnail is clicked on.  It
1295
 * is only triggered for the url 'node/%nid/lightframevideo'.
1296
 *
1297
 * @param $node
1298
 *   The $node object.
1299
 */
1300
/*
1301
function lightbox2_acidfree_video($node) {
1302
print theme('video_player', array( 'node' => $node ) );
1303
}
1304
*/
1305
/**
1306
 * Implementation of filefield's hook_file_formatter_info().
1307
 */
1308
function lightbox2_file_formatter_info() {
1309
  return array(
1310
    'lightbox2_iframe' => array(
1311
      'suitability callback' => 'lightbox2_check_filefield_extension',
1312
      'title' => t('Lightbox2 iframe'),
1313
      'description' => t('Displays all kinds of files in a popup lightbox in an iframe.'),
1314
    ),
1315
    'lightbox2_image' => array(
1316
      'suitability callback' => 'lightbox2_check_filefield_image_extension',
1317
      'title' => t('Lightbox2 image'),
1318
      'description' => t('Displays image files in a popup lightbox.'),
1319
    ),
1320
  );
1321
}
1322

    
1323
/**
1324
 * Suitability callback function for the filefield formatter.
1325
 *
1326
 * @param $file
1327
 *   The file object, containing filepath, mime type, etc.
1328
 * @param $field
1329
 *   CCK field information.
1330
 * @return
1331
 *   True if file extension is supported.
1332
 */
1333
function lightbox2_check_filefield_extension($file, $field) {
1334
  $ext = array_pop(explode('.', $file->filename));
1335
  return lightbox2_supported_file_extension($ext);
1336
}
1337

    
1338
/**
1339
 * Suitability callback function for the image filefield formatter.
1340
 *
1341
 * @param $file
1342
 *   The file object, containing filepath, mime type, etc.
1343
 * @param $field
1344
 *   CCK field information.
1345
 * @return
1346
 *   True if file extension is supported.
1347
 */
1348
function lightbox2_check_filefield_image_extension($file, $field) {
1349
  $ext = array_pop(explode('.', $file->filename));
1350
  return lightbox2_supported_file_extension($ext, 'image');
1351
}
1352

    
1353

    
1354
/**
1355
 * Check whether a given file extension is supported by the lightbox iframe.
1356
 *
1357
 * @param $ext
1358
 *   File extension
1359
 * @param $type
1360
 *   Type of file extensions to check.
1361
 * @return
1362
 *   TRUE if extension is supported.
1363
 */
1364
function lightbox2_supported_file_extension($ext, $type = 'all') {
1365
  $image_extensions = array('png', 'jpg', 'jpeg', 'gif', 'bmp');
1366
  $movie_extensions = array('dv', 'mov', 'moov', 'movie', 'mp4', 'asf', 'wm', 'wmv', 'avi', 'mpg', 'mpeg');
1367
  $web_extensions = array('asp', 'aspx', 'cgi', 'cfm', 'htm', 'html', 'pl', 'php', 'php3', 'php4', 'php5', 'phtml', 'rb', 'rhtml', 'shtml', 'txt', 'vbs');
1368
  $misc_extensions = array('pdf');
1369

    
1370
  $extensions = array();
1371
  switch ($type) {
1372
    case 'image':
1373
      $extensions = $image_extensions;
1374
      break;
1375
    case 'movie':
1376
      $extensions = $movie_extensions;
1377
      break;
1378
    case 'web':
1379
      $extensions = $web_extensions;
1380
      break;
1381
    case 'misc':
1382
      $extensions = $misc_extensions;
1383
      break;
1384
    case 'all':
1385
    default:
1386
      $extensions = array_merge($image_extensions, $movie_extensions, $web_extensions, $misc_extensions);
1387
      break;
1388
  }
1389

    
1390
  if (in_array(drupal_strtolower($ext), $extensions)) {
1391
    return TRUE;
1392
  }
1393

    
1394
  return FALSE;
1395
}
1396

    
1397
/**
1398
 * Helper function to compare the string length of two items.  Used when trying
1399
 * to sort an array by value length.
1400
 *
1401
 * @param $a
1402
 *   String to compare.
1403
 * @param $b
1404
 *   String to compare.
1405
 * @return
1406
 *   0 if they are the same length, -1 if $a is longer than $b, 1 otherwise.
1407
 */
1408
function sort_by_length($a, $b) {
1409
  if ($a == $b) {
1410
    return 0;
1411
  }
1412
  return (drupal_strlen($a) > drupal_strlen($b) ? -1 : 1);
1413
}
1414

    
1415
/**
1416
 * Get the user login form.
1417
 */
1418
function lightbox2_login() {
1419

    
1420
  // do not use lightbox2 for failed validation ie: bad password
1421
  // instead, return the fully rendered Drupal page with errors.
1422
  if (count($_POST)) {
1423
    return drupal_get_form('user_login_block');
1424
  }
1425
  else {
1426
    print drupal_render(drupal_get_form('user_login_block'));
1427
    // If the OpenID module is enabled, the javascript and css may not exist
1428
    // on the page, so add them dynamically.
1429
    if (module_exists('openid')) {
1430
      $path = drupal_get_path('module', 'openid');
1431
      $js_file = base_path() . $path . '/openid.js';
1432
      $css_file = base_path() . $path . '/openid.css';
1433

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

    
1437
      // Load the css file dynamically.
1438
      print '<script type="text/javascript">
1439
        var fileref=document.createElement("link");
1440
        fileref.setAttribute("rel", "stylesheet");
1441
        fileref.setAttribute("type", "text/css");
1442
        fileref.setAttribute("href", "'. $css_file . '");
1443
        document.getElementsByTagName("head")[0].appendChild(fileref);
1444
        </script>';
1445
    }
1446

    
1447
    // drupal_add_js() with 'inline' didn't seem to work, possibly because this is
1448
    // AJAX loaded content.
1449
    print '<script type="text/javascript">Drupal.attachBehaviors();</script>';
1450
  }
1451
  exit;
1452
}
1453

    
1454
/**
1455
 * Get the contact form.
1456
 */
1457
function lightbox2_contact() {
1458
  if (module_exists('contact') && variable_get('lightbox2_enable_contact', FALSE) && user_access('access site-wide contact form')) {
1459
    $path = drupal_get_path('module', 'contact');
1460
    include_once($path . '/contact.pages.inc');
1461
    print drupal_render(drupal_get_form('contact_site_form'));
1462
    // drupal_add_js() with 'inline' didn't seem to work, possibly because this is
1463
    // AJAX loaded content.
1464
    print '<script type="text/javascript">Drupal.attachBehaviors();</script>';
1465
    exit;
1466
  }
1467
}
1468

    
1469
/**
1470
 * Implementation of hook_form_alter().
1471
 *
1472
 * Update the page action and input size.
1473
 *
1474
 * @param &$form
1475
 *   General reference used in drupal, defining the structure & the fields of
1476
 *   a form.
1477
 * @param $form_state
1478
 *   General variable, used to control the processing of the form.
1479
 * @param $form_id
1480
 *   The default is "user_login_block"; hold the page where the function is being
1481
 *   used.
1482
 * @return
1483
 *   Return the structure of the form.
1484
 */
1485
function lightbox2_form_user_login_block_alter(&$form, $form_state, $form_id = "user_login_block") {
1486
  if ($form_id == 'user_login_block' && arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'lightbox2') {
1487
    $form['#action'] = url('user/login/lightbox2', array('query' => array('destination' => $_GET['destination'])));
1488
  }
1489
}
1490

    
1491
function lightbox2_form_contact_site_form_alter(&$form, $form_state, $form_id = "contact_site_form") {
1492
  if ($form_id == 'contact_site_form' && arg(0) == 'contact' && arg(1) == 'lightbox2') {
1493
    $form['#action'] = url('contact', array('query' => array('destination' => $_GET['destination'])));
1494
  }
1495
}
1496

    
1497
/**
1498
 * Implementation of hook_link_alter().
1499
 *
1500
 * Add a lightbox2 rel attribute to the image link sizes on the image node.
1501
 */
1502
function lightbox2_link_alter(&$links, $node) {
1503
  $image_node_handler = variable_get('lightbox2_image_node', 0);
1504

    
1505
  // Only operate on image nodes and if automatic handling for image nodes is
1506
  // enabled.  Also ensure $links is an array (bug in contemplate module).
1507
  if (!$image_node_handler || ($node->type != 'image' && $image_node_handler) || !is_array($links)) {
1508
    return;
1509
  }
1510
  $trigger_sizes = variable_get('lightbox2_trigger_image_size', array('thumbnail'));
1511

    
1512
  // Change original ('original') to '_original'.
1513
  if (isset($trigger_sizes['original'])) {
1514
    unset($trigger_sizes['original']);
1515
    $trigger_sizes['_original'] = '_original';
1516
  }
1517

    
1518
  $rel = '';
1519
  switch ($image_node_handler) {
1520
    case 1: // Lightbox.
1521
    case 2: // Lightbox grouped.
1522
    case 3: // Slideshow.
1523
      $rel = 'lightbox';
1524
      break;
1525
    case 4: // Lightframe.
1526
    case 5: // Lightframe grouped.
1527
      $rel = 'lightframe';
1528
      break;
1529
  }
1530
  $rel = $rel . '[][' . $node->title . ']';
1531
  foreach ($trigger_sizes as $size) {
1532
    if (isset($links['image_size_' . $size])) {
1533
      $links['image_size_' . $size]['attributes']['rel'] = $rel;
1534
      $links['image_size_' . $size]['href'] = $node->images[$size];
1535
      unset($links['image_size_' . $size]['query']);
1536
    }
1537
  }
1538
}
1539

    
1540
/**
1541
 * Implementation of hook_views_api().
1542
 */
1543
function lightbox2_views_api() {
1544
  return array(
1545
    'api' => '3.0',
1546
  );
1547
}
1548

    
1549
function lightbox2_filter_xss() {
1550
  $allowed_tags = trim(variable_get('lightbox2_filter_xss_allowed_tags', 'p, br, a, em, strong, cite, code, ul, ol, li, dl, dt, dd, '));
1551
  $allowed_tags = (empty($allowed_tags) ? array() : preg_split('/[,\s]+/', $allowed_tags));
1552
  if (!empty($_POST['allowed_tags']) && $_POST['allowed_tags'] != 'undefined') {
1553
    $allowed_tags = explode(',', $_POST['allowed_tags']);
1554
    $output = filter_xss($_POST['string'], $allowed_tags);
1555
  }
1556
  else {
1557
    $output = filter_xss($_POST['string'], $allowed_tags);
1558
  }
1559
  drupal_json_output($output);
1560
}
1561