Projet

Général

Profil

Paste
Télécharger (41 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / lightbox2 / lightbox2.admin.inc @ 87dbc3bf

1 85ad3d82 Assos Assos
<?php
2
// $Id: lightbox2.admin.inc,v 1.1.2.38 2010/09/24 08:41:02 snpower Exp $
3
4
/**
5
 * @file
6
 * Administrative page callbacks for the lightbox2 module.
7
 */
8
9
/**
10
 * The default lightbox2 settings page.
11
 */
12
function lightbox2_settings_page($op = NULL) {
13
  $output = drupal_get_form('lightbox2_general_settings_form');
14
  return $output;
15
}
16
17
/**
18
 * General configuration form for controlling the lightbox behaviour.
19
 */
20
function lightbox2_general_settings_form() {
21
22
  // Add the javascript which disables / enables form elements.
23
  drupal_add_js(drupal_get_path('module', 'lightbox2') . '/js/lightbox2.js', 'module');
24
25
  // Enable translation of default strings for potx.
26
  $default_strings = array(t('View Image Details'), t('Image !current of !total'), t('Page !current of !total'), t('Video !current of !total'), t('Download Original'));
27
28
  // Define Lightbox2 layout fieldset.
29
  /* --------------------------------- */
30
  $form['layout_fieldset'] = array(
31
    '#type' => 'fieldset',
32
    '#title' => t('Layout settings'),
33
    '#collapsible' => TRUE,
34
    '#collapsed' => FALSE,
35
  );
36
37
  // Define Lightbox2 Lite fieldset.
38
  /* ------------------------------- */
39
  $use_lite = variable_get('lightbox2_lite', FALSE);
40
  $form['layout_fieldset']['lightbox2_lite_options'] = array(
41
    '#type' => 'fieldset',
42
    '#title' => t('Lightbox2 lite'),
43
    '#collapsible' => TRUE,
44
    '#collapsed' => !$use_lite,
45
  );
46
47
  // Add checkbox for Lightbox2 Lite.
48
  $form['layout_fieldset']['lightbox2_lite_options']['lightbox2_lite']  = array(
49
    '#type' => 'checkbox',
50
    '#title' => t('Use lightbox2 lite'),
51
    '#description' => t('Checking this box will enable Lightbox2 Lite and will disable all of the automatic image URL re-formatting features.  It also disables all grouping features.'),
52
    '#default_value' => $use_lite,
53
  );
54
55
56
  // Add checkbox for alternative layout.
57
  $form['layout_fieldset']['lightbox2_use_alt_layout'] = array(
58
    '#type' => 'checkbox',
59
    '#title' => t('Use alternative layout'),
60
    '#description' => t('Enabling this option alters the layout of the lightbox elements. In the alternative layout the navigational links appear under the image with the caption text, instead of being overlayed on the image itself.  This doesn\'t apply when using Lightbox Lite.'),
61
    '#default_value' => variable_get('lightbox2_use_alt_layout', FALSE),
62
  );
63
64
  // Add checkbox for force navigation display.
65
  $form['layout_fieldset']['lightbox2_force_show_nav'] = array(
66
    '#type' => 'checkbox',
67
    '#title' => t('Force visibility of navigation links'),
68
    '#description' => t('When viewing grouped images, the navigational links to the next and previous images are only displayed when you hover over the image.  Checking this box forces these links to be displayed all the time.'),
69
    '#default_value' => variable_get('lightbox2_force_show_nav', FALSE),
70
  );
71
72
  // Show caption
73
  $form['layout_fieldset']['lightbox2_show_caption'] = array(
74
    '#type' => 'checkbox',
75
    '#title' => t('Show image caption'),
76
    '#description' => t('Unset this to always hide the image caption (usually the title).'),
77
    '#default_value' => variable_get('lightbox2_show_caption', TRUE),
78
  );
79
80
  // Add checkbox for "looping through images'.
81
  $form['layout_fieldset']['lightbox2_loop_items'] = array(
82
    '#type' => 'checkbox',
83
    '#title' => t('Continuous galleries'),
84
    '#description' => t('When viewing grouped images, the Next button on the last image will display the first image, while the Previous button on the first image will display the last image.'),
85
    '#default_value' => variable_get('lightbox2_loop_items', FALSE),
86
  );
87
88
  // Add checkbox for node link target.
89
  $form['layout_fieldset']['lightbox2_node_link_target'] = array(
90
    '#type' => 'checkbox',
91
    '#title' => t('Open image page in new window'),
92
    '#description' => t('This controls whether the link to the image page underneath the image is opened in a new window or the current window.'),
93
    '#default_value' => variable_get('lightbox2_node_link_target', FALSE),
94
    '#return_value' => '_blank',
95
  );
96
97
  // Define Lightbox2 text settings.
98
  /* ------------------------------- */
99
  $form['lightbox2_text_settings'] = array(
100
    '#type' => 'fieldset',
101
    '#title' => t('Text settings'),
102
    '#collapsible' => TRUE,
103
    '#collapsed' => TRUE,
104
  );
105
106
  // Add text box for link text to node.
107
  $form['lightbox2_text_settings']['lightbox2_node_link_text'] = array(
108
    '#type' => 'textfield',
109
    '#title' => t('Text for image page link'),
110
    '#description' => t('This is the text that will appear as the link to the image page underneath the image in the lightbox.  Leave this blank for the link not to appear.'),
111
    '#default_value' => variable_get('lightbox2_node_link_text', 'View Image Details'),
112
  );
113
114
  // Add text box for link text to node.
115
  $form['lightbox2_text_settings']['lightbox2_download_link_text'] = array(
116
    '#type' => 'textfield',
117
    '#title' => t('Text for image original link'),
118
    '#description' => t('This is the text that will appear as the link to the original file underneath the image in the lightbox.  Leave this blank for the link not to appear.  It will only appear for images uploaded via the "image" or "imagefield" modules.  Users will need the "download original image" permission, but also the "view original images" permission if using the "image" module.'),
119
    '#default_value' => variable_get('lightbox2_download_link_text', 'Download Original'),
120
  );
121
122
  // Add text box for image count for grouping.
123
  $form['lightbox2_text_settings']['lightbox2_image_count_str'] = array(
124
    '#type' => 'textfield',
125
    '#title' => t('Image count text'),
126
    '#description' => t('This text is used to display the image count underneath the image in the lightbox when image grouping is enabled.  Use !current as a placeholder for the number of the current image and !total for the total number of images in the group.  For example, "Image !current of !total".  Leave blank for text not to appear.'),
127
    '#default_value' => variable_get('lightbox2_image_count_str', 'Image !current of !total'),
128
  );
129
130
  // Add text box for page count for grouping.
131
  $form['lightbox2_text_settings']['lightbox2_page_count_str'] = array(
132
    '#type' => 'textfield',
133
    '#title' => t('Page count text'),
134
    '#description' => t('This text is used to display the page count underneath HTML content displayed in the lightbox when using groups.  Use !current as a placeholder for the number of the current page and !total for the total number of pages in the group.  For example, "Page !current of !total".  Leave blank for text not to appear.'),
135
    '#default_value' => variable_get('lightbox2_page_count_str', 'Page !current of !total'),
136
  );
137
138
  // Add text box for video count for grouping.
139
  $form['lightbox2_text_settings']['lightbox2_video_count_str'] = array(
140
    '#type' => 'textfield',
141
    '#title' => t('Video count text'),
142
    '#description' => t('This text is used to display the count underneath video content displayed in the lightbox when using groups.  Use !current as a placeholder for the number of the current video and !total for the total number of videos in the group.  For example, "Video !current of !total".  Leave blank for text not to appear.'),
143
    '#default_value' => variable_get('lightbox2_video_count_str', 'Video !current of !total'),
144
  );
145
146
  // Add text box for video count for grouping.
147
  $form['lightbox2_text_settings']['lightbox2_filter_xss_allowed_tags'] = array(
148
    '#type' => 'textfield',
149
    '#title' => t('Allowed HTML tags'),
150
    '#description' => t('A list of comma separated HTML tags which are allowed to be used in the caption text area.'),
151
    '#default_value' => variable_get('lightbox2_filter_xss_allowed_tags', 'p, br, a, em, strong, cite, code, ul, ol, li, dl, dt, dd'),
152
  );
153
154
155
  // Define Lightbox2 zoom fieldset.
156
  /* -------------------------------- */
157
  $form['zoom_fieldset'] = array(
158
    '#type' => 'fieldset',
159
    '#title' => t('Image resize settings'),
160
    '#collapsible' => TRUE,
161
    '#collapsed' => TRUE,
162
  );
163
164
  // Add checkbox for resize image.
165
  $form['zoom_fieldset']['lightbox2_disable_resize'] = array(
166
    '#type' => 'checkbox',
167
    '#title' => t('Disable resizing feature'),
168
    '#description' => t('By default, when the image being displayed in the lightbox is larger than the browser window, it is resized to fit within the window and a zoom button is provided for users who wish to view the image in its original size.  Checking this box will disable this feature and all images will be displayed without any resizing.'),
169
    '#default_value' => variable_get('lightbox2_disable_resize', FALSE),
170
  );
171
172
  // Add checkbox for zoom image.
173
  $form['zoom_fieldset']['lightbox2_disable_zoom'] = array(
174
    '#type' => 'checkbox',
175
    '#title' => t('Disable zoom in / out feature'),
176
    '#description' => t('When the image being displayed in the lightbox is resized to fit in the browser window, a "zoom in" button is shown.  This allows the user to zoom in to see the original full size image.  They will then see a "zoom out" button which will allow them to see the smaller resized version.  Checking this box will prevent these buttons from appearing.'),
177
    '#default_value' => variable_get('lightbox2_disable_zoom', FALSE),
178
  );
179
180
  // Define Lightbox2 modal form fieldset.
181
  /* -------------------------------------- */
182
  $form['modal_form_fieldset'] = array(
183
    '#type' => 'fieldset',
184
    '#title' => t('Modal form settings'),
185
    '#collapsible' => TRUE,
186
    '#collapsed' => TRUE,
187
  );
188
189
  // Add checkbox for login support.
190
  $form['modal_form_fieldset']['lightbox2_enable_login'] = array(
191
    '#type' => 'checkbox',
192
    '#title' => t('Enable login support'),
193
    '#description' => t('Enabling this option will modify all login links so that the login form appears in a lightbox.'),
194
    '#default_value' => variable_get('lightbox2_enable_login', FALSE),
195
  );
196
197
  // Add checkbox for contact form support.
198
  $form['modal_form_fieldset']['lightbox2_enable_contact'] = array(
199
    '#type' => 'checkbox',
200
    '#title' => t('Enable contact form support'),
201
    '#description' => t('Enabling this option will modify all contact links so that the contact form appears in a lightbox.'),
202
    '#default_value' => variable_get('lightbox2_enable_contact', FALSE),
203
  );
204
205
  // Define Lightbox2 video fieldset.
206
  /* -------------------------------- */
207
  $form['video_fieldset'] = array(
208
    '#type' => 'fieldset',
209
    '#title' => t('Video settings'),
210
    '#collapsible' => TRUE,
211
    '#collapsed' => TRUE,
212
  );
213
214
  // Add checkbox for video support.
215
  $form['video_fieldset']['lightbox2_enable_video'] = array(
216
    '#type' => 'checkbox',
217
    '#title' => t('Enable video support'),
218
    '#description' => t('By default, video support is disabled in order to reduce the amount of javascript needed.  Checking this box will enable it.'),
219
    '#default_value' => variable_get('lightbox2_enable_video', FALSE),
220
  );
221
222
  // Add textfield for FLV Player path.
223
  $form['video_fieldset']['lightbox2_flv_player_path'] = array(
224
    '#type' => 'textfield',
225
    '#title' => t('Path to FLV Player'),
226
    '#description' => t('The path to the FLV player, relative to Drupal root directory. No leading slashes.'),
227
    '#default_value' => variable_get('lightbox2_flv_player_path', 'flvplayer.swf'),
228
  );
229
230
  // Add textfield for FLV Player flashvars.
231
  $form['video_fieldset']['lightbox2_flv_player_flashvars'] = array(
232
    '#type' => 'textfield',
233
    '#title' => t('FLV Player flashvars'),
234
    '#description' => t('Flashvars for the FLV Player where supported, e.g. "autoplay=1&playerMode=normal".'),
235
    '#default_value' => variable_get('lightbox2_flv_player_flashvars', ''),
236
  );
237
238
  // Define Lightbox2 page specific settings fieldset.
239
  /* ------------------------------------------------ */
240
  $form['lightbox2_page_init'] = array(
241
    '#type' => 'fieldset',
242
    '#title' => t('Page specific lightbox2 settings'),
243
    '#collapsible' => TRUE,
244
    '#collapsed' => TRUE,
245
  );
246
  // Add radio buttons for the actions to take for the listed pages, i.e.
247
  // disable or enable the lightbox functionality.
248
  $page_options = array(
249
    'page_enable' => t('Load only on the listed pages.'),
250
    'page_disable' => t('Load on every page except the listed pages.'),
251
  );
252
  $form['lightbox2_page_init']['lightbox2_page_init_action'] = array(
253
    '#type' => 'radios',
254
    '#options' => $page_options,
255
    '#title' => t('Enable lightbox2 on specific pages'),
256
    '#default_value' => variable_get('lightbox2_page_init_action', 'page_disable'),
257
  );
258
  // Add text input for list of pages to take specific action on.
259
  $form['lightbox2_page_init']['lightbox2_page_list'] = array(
260
    '#type' => 'textarea',
261
    '#title' => t('Pages'),
262
    '#description' => t('List one page per line as Drupal paths.  The * character is a wildcard.  Example paths are "node/add/page" and "node/add/*".  Use &lt;front&gt; to match the front page.'),
263
    '#default_value' => variable_get('lightbox2_page_list', ''),
264
  );
265
266
  // Define grouping settings fieldset.
267
  /* ------------------------------------ */
268
  $form['group_options'] = array(
269
    '#type' => 'fieldset',
270
    '#title' => t('Group display settings'),
271
    '#collapsible' => TRUE,
272
    '#collapsed' => TRUE,
273
  );
274
275
  $group_options = array(
276
    0 => t('No grouping'),
277
    1 => t('Group by field name'),
278
    2 => t('Group by node id'),
279
    3 => t('Group by field name and node id'),
280
    4 => t('Group all nodes and fields'),
281
  );
282
283
  $form['group_options']['lightbox2_image_group_node_id'] = array(
284
    '#type' => 'select',
285
    '#title' => t('Select Imagefield grouping in Views'),
286
    '#description' => t('By default, imagefields in views are grouped by the field name they appear in the view in.  You can override that grouping here.'),
287
    '#options' => $group_options,
288
    '#default_value' => variable_get('lightbox2_image_group_node_id', 1),
289
  );
290
291
292
  // Define advanced settings fieldset.
293
  /* ---------------------------------- */
294
  $form['advanced_options'] = array(
295
    '#type' => 'fieldset',
296
    '#title' => t('Advanced settings'),
297
    '#collapsible' => TRUE,
298
    '#collapsed' => TRUE,
299
  );
300
301
  // Allow users to decide where javascript should be loaded - header or footer.
302
  // Header is recommended so user can click on images before page has finished
303
  // loading, but footer is needed for sites in IE which use SWFObject.
304
  $form['advanced_options']['lightbox2_js_location'] = array(
305
    '#type' => 'select',
306
    '#title' => t('Location of javscript'),
307
    '#options' => array('header' => t('Header'), 'footer' => t('Footer')),
308
    '#description' => t('By default, the lightbox javascript files are loaded in the HTML header.  However, for sites using SWFObject to load their Flash content, the footer setting is recommended to prevent "Operation Aborted" errors in IE.  If using the footer setting, please note that not all themes correctly implement the footer region and may require a small change.'),
309
    '#default_value' => variable_get('lightbox2_js_location', 'header'),
310
  );
311
312
  $form['advanced_options']['lightbox2_disable_close_click'] = array(
313
    '#type' => 'checkbox',
314
    '#title' => t('Click on overlay or lightbox to close it'),
315
    '#description' => t('Enable user to close lightbox by clicking on the lightbox itself or the overlay background.'),
316
    '#default_value' => variable_get('lightbox2_disable_close_click', TRUE),
317
  );
318
319
  // Define keyboard shortcuts fieldset.
320
  /* ---------------------------------- */
321
  $form['advanced_options']['keyboard_shortcuts'] = array(
322
    '#type' => 'fieldset',
323
    '#title' => t('Keyboard shortcuts'),
324
    '#description' => t('Configure the keyboard shortcuts for controlling the lightbox.  These options do not apply to the Lightbox2 Lite version, which uses the default "Close keys" (c, x and esc) to close the lightbox.'),
325
    '#collapsible' => TRUE,
326
    '#collapsed' => TRUE,
327
  );
328
329
  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_close'] = array(
330
    '#type' => 'textfield',
331
    '#title' => t('Close keys'),
332
    '#description' => t("A list of keys (or key codes) that a user may use to close the lightbox. Values should be separated by a space. Defaults to 'c x 27' (c, x, or esc)."),
333
    '#default_value' => variable_get('lightbox2_keys_close', 'c x 27'),
334
  );
335
336
  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_previous'] = array(
337
    '#type' => 'textfield',
338
    '#title' => t('Previous keys'),
339
    '#description' => t("A list of keys (or key codes) that a user may use to navigate to the previous item in the lightbox. Values should be separated by a space. Defaults to 'p 37' (p or left arrow)."),
340
    '#default_value' => variable_get('lightbox2_keys_previous', 'p 37'),
341
  );
342
343
  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_next'] = array(
344
    '#type' => 'textfield',
345
    '#title' => t('Next keys'),
346
    '#description' => t("A list of keys (or key codes) that a user may use to navigate to the next item in the lightbox. Values should be separated by a space. Defaults to 'n 39' (n or right arrow)."),
347
    '#default_value' => variable_get('lightbox2_keys_next', 'n 39'),
348
  );
349
350
  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_zoom'] = array(
351
    '#type' => 'textfield',
352
    '#title' => t('Zoom keys'),
353
    '#description' => t("A list of keys (or key codes) that a user may use to zoom in / out of images in the lightbox. Values should be separated by a space. Defaults to 'z'."),
354
    '#default_value' => variable_get('lightbox2_keys_zoom', 'z'),
355
  );
356
357
  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_play_pause'] = array(
358
    '#type' => 'textfield',
359
    '#title' => t('Pause / play keys'),
360
    '#description' => t("A list of keys (or key codes) that a user may use to pause / play the lightbox. Values should be separated by a space. Defaults to '32' (spacebar)."),
361
    '#default_value' => variable_get('lightbox2_keys_play_pause', '32'),
362
  );
363
364
365
366
367
  // Define border settings fieldset.
368
  /* ---------------------------------- */
369
  $form['advanced_options']['skin_settings'] = array(
370
    '#type' => 'fieldset',
371
    '#title' => t('Skin settings'),
372
    '#collapsible' => TRUE,
373
    '#collapsed' => TRUE,
374
  );
375
376
  $form['advanced_options']['skin_settings']['lightbox2_border_size'] = array(
377
    '#type' => 'textfield',
378
    '#title' => t('Border size'),
379
    '#size' => 6,
380
    '#maxlength' => 6,
381
    '#description' => t('Enter the size of the border in pixels to display around the image.'),
382
    '#default_value' => variable_get('lightbox2_border_size', 10),
383
  );
384
385
  $form['advanced_options']['skin_settings']['lightbox2_box_color'] = array(
386
    '#type' => 'textfield',
387
    '#title' => t('Lightbox color'),
388
    '#field_prefix' => '#',
389
    '#size' => 6,
390
    '#maxlength' => 6,
391
    '#description' => t('Enter a hexadecimal color value for the border.  For example <code>fff</code> or <code>ffffff</code> for white).'),
392
    '#default_value' => variable_get('lightbox2_box_color', 'fff'),
393
  );
394
395
  $form['advanced_options']['skin_settings']['lightbox2_font_color'] = array(
396
    '#type' => 'textfield',
397
    '#title' => t('Font color'),
398
    '#field_prefix' => '#',
399
    '#size' => 6,
400
    '#maxlength' => 6,
401
    '#description' => t('Enter a hexadecimal color value for the font.  For example <code>000</code> or <code>000000</code> for black).'),
402
    '#default_value' => variable_get('lightbox2_font_color', '000'),
403
  );
404
405
  $form['advanced_options']['skin_settings']['lightbox2_top_position'] = array(
406
    '#type' => 'textfield',
407
    '#title' => t('Distance from top'),
408
    '#size' => 6,
409
    '#maxlength' => 6,
410
    '#description' => t('Enter the position of the top of the lightbox in pixels.  Leave blank for automatic calculation.'),
411
    '#default_value' => variable_get('lightbox2_top_position', ''),
412
  );
413
414
415
416
  // Define overlay settings fieldset.
417
  /* ---------------------------------- */
418
  $form['advanced_options']['overlay_settings'] = array(
419
    '#type' => 'fieldset',
420
    '#title' => t('Overlay settings'),
421
    '#collapsible' => TRUE,
422
    '#collapsed' => TRUE,
423
  );
424
  // Add checkbox for overlay opacity.
425
  for ($i = 0; $i < 10; $i++) {
426
    $opacity_options["0.$i"] = "0.$i";
427
  }
428
  $opacity_options["1.0"] = "1.0";
429
  $form['advanced_options']['overlay_settings']['lightbox2_overlay_opacity'] = array(
430
    '#type' => 'select',
431
    '#title' => t('Overlay opacity'),
432
    '#options' => $opacity_options,
433
    '#description' => t('The overlay opacity setting determines how visible the background page is behind the lightbox.  The opacity value can range from 0.0 to 1.0 where 0.0 is 100% transparent and 1.0 is 100% opaque.'),
434
    '#default_value' => variable_get('lightbox2_overlay_opacity', 0.8),
435
  );
436
437
  $form['advanced_options']['overlay_settings']['lightbox2_overlay_color'] = array(
438
    '#type' => 'textfield',
439
    '#title' => t('Overlay color'),
440
    '#field_prefix' => '#',
441
    '#size' => 6,
442
    '#maxlength' => 6,
443
    '#description' => t('Enter a hexadecimal color value for the overlay.  For example <code>000</code> or <code>000000</code> for black).'),
444
    '#default_value' => variable_get('lightbox2_overlay_color', '000'),
445
  );
446
447
448
  // Define animation settings fieldset.
449
  /* ----------------------------------- */
450
  $form['advanced_options']['animation_settings'] = array(
451
    '#type' => 'fieldset',
452
    '#title' => t('Animation settings'),
453
    '#collapsible' => TRUE,
454
    '#collapsed' => TRUE,
455
  );
456
  // Set animation help text.
457
  $form['advanced_options']['animation_settings']['animation_options_help'] = array(
458
    '#value' => '<p>' . t("These options aren't available when using Lightbox2 Lite.") . '</p>',
459
  );
460
  $resize_sequence_options = array(
461
    t('Simultaneous'),
462
    t('Width then height'),
463
    t('Height then width'),
464
  );
465
  $form['advanced_options']['animation_settings']['lightbox2_resize_sequence'] = array(
466
    '#type' => 'select',
467
    '#title' => t('Resize sequence'),
468
    '#options' => $resize_sequence_options,
469
    '#description' => t('The sequence to use for the resizing animation.'),
470
    '#default_value' => variable_get('lightbox2_resize_sequence', 0),
471
  );
472
  $form['advanced_options']['animation_settings']['lightbox2_resize_speed'] = array(
473
    '#type' => 'textfield',
474
    '#title' => t('Resize duration'),
475
    '#size' => 5,
476
    '#maxlength' => 5,
477
    '#description' => t('The duration (in seconds) of the resizing animation.  Enter a value between 0 and 10.'),
478
    '#default_value' => variable_get('lightbox2_resize_speed', 0.4),
479
  );
480
  $form['advanced_options']['animation_settings']['lightbox2_fadein_speed'] = array(
481
    '#type' => 'textfield',
482
    '#title' => t('Appearance duration'),
483
    '#size' => 5,
484
    '#maxlength' => 5,
485
    '#description' => t('The duration (in seconds) of the lightbox appearance animation.  Enter a positive number less than 10.'),
486
    '#default_value' => variable_get('lightbox2_fadein_speed', 0.4),
487
  );
488
489
490
  $form['advanced_options']['animation_settings']['lightbox2_slidedown_speed'] = array(
491
    '#type' => 'textfield',
492
    '#title' => t('Caption slide down duration'),
493
    '#size' => 5,
494
    '#maxlength' => 5,
495
    '#description' => t('The duration (in seconds) of the caption sliding-down animation.  Enter a value between 0 and 10.'),
496
    '#default_value' => variable_get('lightbox2_slidedown_speed', 0.6),
497
  );
498
499
  return system_settings_form($form);
500
}
501
502
/**
503
 * Validation function for the general configuration form.
504
 *
505
 * Ensure that the hex color value submitted is valid and that the speeds are
506
 * numeric.
507
 */
508
function lightbox2_general_settings_form_validate($form, &$form_state) {
509
  if ($form_state['values']['op'] == t('Save configuration')) {
510
    $border_size = $form_state['values']['lightbox2_border_size'];
511
    $box_hex_colour = $form_state['values']['lightbox2_box_color'];
512
    $font_hex_colour = $form_state['values']['lightbox2_font_color'];
513
    $top_position = $form_state['values']['lightbox2_top_position'];
514
    $overlay_hex_colour = $form_state['values']['lightbox2_overlay_color'];
515
    $resize_speed = $form_state['values']['lightbox2_resize_speed'];
516
    $fadein_speed = $form_state['values']['lightbox2_fadein_speed'];
517
    $slide_down_speed = $form_state['values']['lightbox2_slidedown_speed'];
518
    $flv_player_path = $form_state['values']['lightbox2_flv_player_path'];
519
520
    if (!empty($flv_player_path) && $form_state['values']['lightbox2_enable_video']) {
521
      if (strpos($flv_player_path, base_path()) === 0) {
522
        $flv_player_path = drupal_substr($flv_player_path, drupal_strlen(base_path()));
523
      }
524
      if (!file_exists($flv_player_path)) {
525
        form_set_error('lightbox2_flv_player_path', t("FLV player path doesn't exist."));
526
      }
527
    }
528
529
    if (!_lightbox2_validate_hex_color($overlay_hex_colour)) {
530
      form_set_error('lightbox2_overlay_color', t('You must enter a properly formed hex value.'));
531
    }
532
533
    if (!$form_state['values']['lightbox2_lite']) {
534
      if (!is_numeric($border_size) || $border_size < 0) {
535
        form_set_error('lightbox2_border_size', t('You must enter a size greater than 0 pixels.'));
536
      }
537
538
      if (!_lightbox2_validate_hex_color($box_hex_colour)) {
539
        form_set_error('lightbox2_box_color', t('You must enter a properly formed hex value.'));
540
      }
541
542
      if (!_lightbox2_validate_hex_color($font_hex_colour)) {
543
        form_set_error('lightbox2_font_color', t('You must enter a properly formed hex value.'));
544
      }
545
546
      if (!empty($top_position) && (!is_numeric($top_position) || $top_position < 0)) {
547
        form_set_error('lightbox2_top_position', t('You must enter a size greater than 0 pixels.  Leave blank for default positioning.'));
548
      }
549
550
      if (!is_numeric($resize_speed) || $resize_speed <= 0 || $resize_speed >= 10) {
551
        form_set_error('lightbox2_resize_speed', t('You must enter a duration between 0 and 10 seconds.'));
552
      }
553
554
      if (!is_numeric($fadein_speed) || $fadein_speed < 0 || $fadein_speed >= 10) {
555
        form_set_error('lightbox2_fadein_speed', t('You must enter a duration between 0 and 10 seconds.'));
556
      }
557
558
      if (!is_numeric($slide_down_speed) || $slide_down_speed <= 0 || $slide_down_speed >= 10) {
559
        form_set_error('lightbox2_slidedown_speed', t('You must enter a duration between 0 and 10 seconds.'));
560
      }
561
    }
562
  }
563
}
564
565
/**
566
 * Submit function for the general configuration form.
567
 */
568
function lightbox2_general_settings_form_submit($form, &$form_state) {
569
  cache_clear_all();
570
}
571
572
/**
573
 * Configuration form for controlling the slideshow behaviour.
574
 */
575
function lightbox2_slideshow_settings_form() {
576
577
  // Add the javascript which disables / enables form elements.
578
  drupal_add_js(drupal_get_path('module', 'lightbox2') . '/js/lightbox2.js', 'module');
579
580
  // Set up a hidden variable.
581
  $form['lightbox2_lite'] = array(
582
    '#type' => 'hidden',
583
    '#value' => variable_get('lightbox2_lite', FALSE),
584
  );
585
586
587
  // Add text box for slideshow interval.
588
  $form['lightbox2_slideshow_interval'] = array(
589
    '#type' => 'textfield',
590
    '#title' => t('Interval seconds'),
591
    '#description' => t('The slideshow interval is the length of time in seconds an image is visible before the slideshow shows the next image.'),
592
    '#default_value' => variable_get('lightbox2_slideshow_interval', 5),
593
    '#size' => 20,
594
  );
595
596
   // Add checkbox for slideshow automatic start.
597
  $form['lightbox2_slideshow_automatic_start'] = array(
598
    '#type' => 'checkbox',
599
    '#title' => t('Automatically start slideshow'),
600
    '#description' => t('When enabled the slideshow will automatically start.'),
601
    '#default_value' => variable_get('lightbox2_slideshow_automatic_start', TRUE),
602
  );
603
604
  // Add checkbox for slideshow automatic exit.
605
  $form['lightbox2_slideshow_automatic_exit'] = array(
606
    '#type' => 'checkbox',
607
    '#title' => t('Automatically exit slideshow'),
608
    '#description' => t('When enabled the lightbox will automatically close after displaying the last image.'),
609
    '#default_value' => variable_get('lightbox2_slideshow_automatic_exit', TRUE),
610
  );
611
612
  // Add checkbox for showing hte play / pause button.
613
  $form['lightbox2_slideshow_show_play_pause'] = array(
614
    '#type' => 'checkbox',
615
    '#title' => t('Show play / pause button'),
616
    '#description' => t('When enabled, a play / pause button will be shown in the slideshow allowing the user more control over their viewing experience.'),
617
    '#default_value' => variable_get('lightbox2_slideshow_show_play_pause', TRUE),
618
  );
619
620
  // Add checkbox for "pausing on next click".
621
  $form['lightbox2_slideshow_pause_on_next_click'] = array(
622
    '#type' => 'checkbox',
623
    '#title' => t('Pause slideshow on "Next Image" click'),
624
    '#description' => t('When enabled the slideshow is automatically paused, and the following image shown, when the "Next" button is clicked.'),
625
    '#default_value' => variable_get('lightbox2_slideshow_pause_on_next_click', FALSE),
626
  );
627
628
  // Add checkbox for "pausing on prev click".
629
  $form['lightbox2_slideshow_pause_on_previous_click'] = array(
630
    '#type' => 'checkbox',
631
    '#title' => t('Pause slideshow on "Previous Image" click'),
632
    '#description' => t('When enabled the slideshow is automatically paused, and the previous image shown, when the "Previous" button is clicked.'),
633
    '#default_value' => variable_get('lightbox2_slideshow_pause_on_previous_click', TRUE),
634
  );
635
636
  // Add checkbox for "looping through slides'.
637
  $form['lightbox2_loop_slides'] = array(
638
    '#type' => 'checkbox',
639
    '#title' => t('Continuous loop'),
640
    '#description' => t('When enabled the slideshow will automatically start over after displaying the last slide.  This prevents the slideshow from automatically exiting when enabled.'),
641
    '#default_value' => variable_get('lightbox2_loop_slides', FALSE),
642
  );
643
644
  return system_settings_form($form);
645
}
646
647
/**
648
 * Validation function for the slideshow configuration form.
649
 *
650
 * Ensure that the slideshow interval submitted is numeric.
651
 */
652
function lightbox2_slideshow_settings_form_validate($form, &$form_state) {
653
  if (!is_numeric($form_state['values']['lightbox2_slideshow_interval'])) {
654
    form_set_error('lightbox2_slideshow_interval', t('The "interval seconds" value must be numeric.'));
655
  }
656
}
657
658
/**
659
 * Configuration form for controlling the iframe behaviour.
660
 */
661
function lightbox2_iframe_settings_form() {
662
663
  // Add the javascript which disables / enables form elements.
664
  drupal_add_js(drupal_get_path('module', 'lightbox2') . '/js/lightbox2.js', 'module');
665
666
  // Set up a hidden variable.
667
  $form['lightbox2_lite'] = array(
668
    '#type' => 'hidden',
669
    '#value' => variable_get('lightbox2_lite', FALSE),
670
  );
671
672
673
  // Add text box for iframe width.
674
  $form['lightbox2_default_frame_width'] = array(
675
    '#type' => 'textfield',
676
    '#title' => t('Default width'),
677
    '#description' => t('The default width of the iframe in pixels.'),
678
    '#default_value' => variable_get('lightbox2_default_frame_width', 600),
679
    '#size' => 20,
680
  );
681
682
  // Add text box for iframe height.
683
  $form['lightbox2_default_frame_height'] = array(
684
    '#type' => 'textfield',
685
    '#title' => t('Default height'),
686
    '#description' => t('The default height of the iframe in pixels.'),
687
    '#default_value' => variable_get('lightbox2_default_frame_height', 400),
688
    '#size' => 20,
689
  );
690
691
  // Add option for iframe border.
692
  $form['lightbox2_frame_border'] = array(
693
    '#type' => 'checkbox',
694
    '#title' => t('Enable border'),
695
    '#description' => t('Enable iframe border.  You can modify the border style in your theme\'s css file using the iframe\'s id "lightboxFrame".'),
696
    '#default_value' => variable_get('lightbox2_frame_border', 1),
697
  );
698
699
  return system_settings_form($form);
700
}
701
702
/**
703
 * Validation function for the iframe configuration form.
704
 *
705
 * Ensure that the iframe width and height submitted are numeric.
706
 */
707
function lightbox2_iframe_settings_form_validate($form, &$form_state) {
708
  if (!is_numeric($form_state['values']['lightbox2_default_frame_width'])) {
709
    form_set_error('lightbox2_slideshow_interval', t('The "default width" value must be numeric.'));
710
  }
711
  if (!is_numeric($form_state['values']['lightbox2_default_frame_height'])) {
712
    form_set_error('lightbox2_slideshow_interval', t('The "default height" value must be numeric.'));
713
  }
714
}
715
716
717
/**
718
 * Configuration form the automatic image handling functionality.
719
 */
720
function lightbox2_auto_image_handling_settings_form() {
721
722
  // Add the javascript which disables / enables form elements.
723
  drupal_add_js(drupal_get_path('module', 'lightbox2') . '/js/lightbox2.js', 'module');
724
725
  // Set up a hidden variable.
726
  $form['lightbox2_lite'] = array(
727
    '#type' => 'hidden',
728
    '#value' => variable_get('lightbox2_lite', FALSE),
729
  );
730
731
  $automatic_options = array(
732
    0 => t('Disabled'),
733
    1 => t('Lightbox'),
734
    2 => t('Lightbox grouped'),
735
    3 => t('Slideshow'),
736
    4 => t('HTML content'),
737
    5 => t('HTML content grouped'),
738
  );
739
740
  // Set image node options help text.
741
  $form['image_node_options'] = array(
742
    '#value' => t('These options allow automatic URL re-formatting of images.  This removes the need for you to add \'rel="lightbox"\' to each image link throughout your site.  You can select which image sizes will trigger the lightbox and configure a list of image CSS classes which should also have their URLs automatically re-formatted.  This feature is not available when using Lightbox2 Lite.'),
743
  );
744
745
  // Define handler settings fieldset.
746
  /* --------------------------------- */
747
  $form['handler_options'] = array(
748
    '#type' => 'fieldset',
749
    '#title' => t('Automatic handlers'),
750
    '#collapsible' => TRUE,
751
    '#collapsed' => FALSE,
752
  );
753
754
  // Define image nodes settings fieldset.
755
  /* ------------------------------------- */
756
  $form['handler_options']['image_node_options'] = array(
757
    '#type' => 'fieldset',
758
    '#title' => t('Image node settings'),
759
    '#collapsible' => TRUE,
760
    '#collapsed' => TRUE,
761
  );
762
763
  // Add checkbox for image nodes.
764
  $form['handler_options']['image_node_options']['lightbox2_image_node']  = array(
765
    '#type' => 'select',
766
    '#title' => t('Automatic handler for image nodes'),
767
    '#options' => $automatic_options,
768
    '#description' => t('Choose how URLs for image nodes will be automatically handled.'),
769
    '#default_value' => variable_get('lightbox2_image_node', 0),
770
  );
771
772
  /*
773
  // Add drop-down for list of available image sizes.
774
  if (module_exists('image')) {
775
    $sizes = image_get_sizes();
776
    foreach ($sizes as $size_key => $size) {
777
      if ($size_key == 'original' or $size_key == '_original')  {
778
        $size_key = 'original';
779
      }
780
      $size_options[$size_key] = $size['label'];
781
    }
782
    $form['handler_options']['image_node_options']['lightbox2_display_image_size'] = array(
783
      '#type' => 'select',
784
      '#title' => t('Lightbox image display size'),
785
      '#options' => $size_options,
786
      '#default_value' => variable_get('lightbox2_display_image_size', 'original'),
787
      '#description' => t('Select which image size will be loaded in the lightbox.  This only applies to images uploaded with the Image module.'),
788
    );
789
790
    $form['handler_options']['image_node_options']['lightbox2_trigger_image_size'] = array(
791
      '#type' => 'select',
792
      '#multiple' => TRUE,
793
      '#title' => t('Image trigger size'),
794
      '#options' => $size_options,
795
      '#default_value' => variable_get('lightbox2_trigger_image_size', array('thumbnail')),
796
      '#description' => t('Select which image size, when clicked on, will automatically trigger the lightbox.  This only applies to images uploaded with the Image module.'),
797
    );
798
799
  }
800
  */
801
802
  // Add checkbox for disabling lightbox for gallery lists.
803
  $form['handler_options']['image_node_options']['lightbox2_disable_nested_galleries']  = array(
804
    '#type' => 'checkbox',
805
    '#title' => t('Disable lightbox for gallery lists'),
806
    '#description' => t('Checking this box will disable the lightbox for images in gallery lists.  This means it is possible to open a gallery by clicking on the teaser image, but the lightbox will still appear when viewing images within the gallery.  This only applies to image galleries created with the "image gallery" module.'),
807
    '#default_value' => variable_get('lightbox2_disable_nested_galleries', TRUE),
808
  );
809
810
  // Define flickr fieldset.
811
  /* ----------------------- */
812
  $form['handler_options']['flickr_options'] = array(
813
    '#type' => 'fieldset',
814
    '#title' => t('Flickr images'),
815
    '#collapsible' => TRUE,
816
    '#collapsed' => TRUE,
817
  );
818
  // Add checkbox for flickr image support.
819
  $form['handler_options']['flickr_options']['lightbox2_flickr'] = array(
820
    '#type' => 'select',
821
    '#title' => t('Automatic handler for Flickr images'),
822
    '#options' => $automatic_options,
823
    '#description' => t('Choose how URLs for Flickr images will be automatically handled.'),
824
    '#default_value' => variable_get('lightbox2_flickr', 0),
825
  );
826
827
  // Define gallery2 fieldset.
828
  /* ------------------------- */
829
  $form['handler_options']['gallery2_options'] = array(
830
    '#type' => 'fieldset',
831
    '#title' => t('Gallery2 images'),
832
    '#collapsible' => TRUE,
833
    '#collapsed' => TRUE,
834
  );
835
  // Add checkbox for gallery2 block image support.
836
  $form['handler_options']['gallery2_options']['lightbox2_gallery2_blocks'] = array(
837
    '#type' => 'select',
838
    '#title' => t('Automatic handler for Gallery2 block images'),
839
    '#options' => $automatic_options,
840
    '#description' => t('Choose how URLs for images, contained within Gallery2 image blocks, will be automatically handled.'),
841
    '#default_value' => variable_get('lightbox2_gallery2_blocks', 0),
842
  );
843
844
  // Define inline fieldset.
845
  /* ----------------------- */
846
  $form['handler_options']['inline_options'] = array(
847
    '#type' => 'fieldset',
848
    '#title' => t('Inline module images'),
849
    '#collapsible' => TRUE,
850
    '#collapsed' => TRUE,
851
  );
852
  // Add checkbox for inline image support.
853
  $form['handler_options']['inline_options']['lightbox2_inline'] = array(
854
    '#type' => 'select',
855
    '#title' => t('Automatic handler for Inline module images'),
856
    '#options' => $automatic_options,
857
    '#description' => t('Choose how URLs for Inline module images will be automatically handled.'),
858
    '#default_value' => variable_get('lightbox2_inline', 0),
859
  );
860
861
  // Define image assist fieldset.
862
  /* ----------------------------- */
863
  $form['handler_options']['img_assist_options'] = array(
864
    '#type' => 'fieldset',
865
    '#title' => t('Image Assist images'),
866
    '#collapsible' => TRUE,
867
    '#collapsed' => TRUE,
868
  );
869
  // Add checkbox for image assist custom size images.
870
  $form['handler_options']['img_assist_options']['lightbox2_image_assist_custom'] = array(
871
    '#type' => 'select',
872
    '#title' => t('Automatic handler for Image Assist custom size images'),
873
    '#options' => $automatic_options,
874
    '#description' => t('Choose how URLs for custom size images, displayed by the Image Assist module, will be automatically handled.'),
875
    '#default_value' => variable_get('lightbox2_image_assist_custom', 0),
876
  );
877
878
  // Define custom fieldset.
879
  /* ----------------------- */
880
  $form['handler_options']['custom_options'] = array(
881
    '#type' => 'fieldset',
882
    '#title' => t('Custom class images'),
883
    '#collapsible' => TRUE,
884
    '#collapsed' => TRUE,
885
  );
886
  // Add checkbox for custom class image support.
887
  $form['handler_options']['custom_options']['lightbox2_custom_class_handler'] = array(
888
    '#type' => 'select',
889
    '#title' => t('Automatic handler for custom class images'),
890
    '#options' => $automatic_options,
891
    '#description' => t('Choose how URLs for custom class images will be automatically handled.'),
892
    '#default_value' => variable_get('lightbox2_custom_class_handler', 0),
893
  );
894
  // Add text box for custom trigger classes.
895
  $form['handler_options']['custom_options']['lightbox2_custom_trigger_classes'] = array(
896
    '#type' => 'textarea',
897
    '#title' => t('Custom image trigger classes'),
898
    '#description' => t('List the image classes which should trigger the lightbox when clicked on.  Put each class on a separate line.'),
899
    '#default_value' => variable_get('lightbox2_custom_trigger_classes', ''),
900
  );
901
902
  // Add checkbox for disabling lightbox for acidfree gallery lists.
903
  if (module_exists("acidfree")) {
904
    // Define acidfree settings fieldset.
905
    /* ---------------------------------- */
906
    $form['handler_options']['lightbox2_acidfree_options'] = array(
907
      '#type' => 'fieldset',
908
      '#title' => t('Acidfree settings'),
909
      '#collapsible' => TRUE,
910
      '#collapsed' => TRUE,
911
    );
912
    $form['handler_options']['lightbox2_acidfree_options']['lightbox2_disable_nested_acidfree_galleries'] = array(
913
      '#type' => 'checkbox',
914
      '#title' => t('Disable lightbox for Acidfree gallery lists'),
915
      '#description' => t('Checking this box will disable the lightbox for images in gallery lists.  This means it is possible to open a gallery by clicking on the teaser image, but the lightbox will still appear when viewing images within the gallery.  This only applies to image galleries created with the "acidfree" module.'),
916
      '#default_value' => variable_get('lightbox2_disable_nested_acidfree_galleries', TRUE),
917
    );
918
    // Add checkbox for enabling lightbox for acidfree videos.
919
    if (module_exists("video")) {
920
      $form['handler_options']['lightbox2_acidfree_options']['lightbox2_enable_acidfree_videos'] = array(
921
        '#type' => 'checkbox',
922
        '#title' => t('Enable lightbox for Acidfree videos'),
923
        '#description' => t('Checking this box will enable the display of acidfree videos in a lightbox.  This only applies to videos created by the "video" module and which appear in an acidfree gallery.'),
924
        '#default_value' => variable_get('lightbox2_enable_acidfree_videos', FALSE),
925
      );
926
    }
927
  }
928
929
  return system_settings_form($form);
930
}
931
932
/**
933
 * Validate a hex color value.
934
 *
935
 * @param $hex
936
 *   The hex color string to validate.
937
 * @return
938
 *   TRUE if $hex is a valid hex color value.
939
 */
940
function _lightbox2_validate_hex_color($hex) {
941
  return preg_match('!^[a-f0-9]{3}([a-f0-9]{3})?$!i', $hex);
942
}