lightbox2.admin.inc 41 KB
Newer Older
1
<?php
2
// $Id: lightbox2.admin.inc,v 1.1.2.38 2010/09/24 08:41:02 snpower Exp $
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

/**
 * @file
 * Administrative page callbacks for the lightbox2 module.
 */

/**
 * The default lightbox2 settings page.
 */
function lightbox2_settings_page($op = NULL) {
  $output = drupal_get_form('lightbox2_general_settings_form');
  return $output;
}

/**
 * General configuration form for controlling the lightbox behaviour.
 */
function lightbox2_general_settings_form() {

  // 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 29 30 31

  // Define Lightbox2 layout fieldset.
  /* --------------------------------- */
  $form['layout_fieldset'] = array(
    '#type' => 'fieldset',
32
    '#title' => t('Layout settings'),
33 34 35 36 37 38 39 40 41
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // Define Lightbox2 Lite fieldset.
  /* ------------------------------- */
  $use_lite = variable_get('lightbox2_lite', FALSE);
  $form['layout_fieldset']['lightbox2_lite_options'] = array(
    '#type' => 'fieldset',
42
    '#title' => t('Lightbox2 lite'),
43 44 45 46 47 48 49
    '#collapsible' => TRUE,
    '#collapsed' => !$use_lite,
  );

  // Add checkbox for Lightbox2 Lite.
  $form['layout_fieldset']['lightbox2_lite_options']['lightbox2_lite']  = array(
    '#type' => 'checkbox',
50
    '#title' => t('Use lightbox2 lite'),
51 52 53 54 55 56 57 58
    '#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.'),
    '#default_value' => $use_lite,
  );


  // Add checkbox for alternative layout.
  $form['layout_fieldset']['lightbox2_use_alt_layout'] = array(
    '#type' => 'checkbox',
59
    '#title' => t('Use alternative layout'),
60 61 62 63 64 65 66 67 68 69 70 71
    '#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.'),
    '#default_value' => variable_get('lightbox2_use_alt_layout', FALSE),
  );

  // Add checkbox for force navigation display.
  $form['layout_fieldset']['lightbox2_force_show_nav'] = array(
    '#type' => 'checkbox',
    '#title' => t('Force visibility of navigation links'),
    '#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.'),
    '#default_value' => variable_get('lightbox2_force_show_nav', FALSE),
  );

72 73 74 75 76 77 78 79
  // Show caption
  $form['layout_fieldset']['lightbox2_show_caption'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show image caption'),
    '#description' => t('Unset this to always hide the image caption (usually the title).'),
    '#default_value' => variable_get('lightbox2_show_caption', TRUE),
  );

80 81 82
  // Add checkbox for "looping through images'.
  $form['layout_fieldset']['lightbox2_loop_items'] = array(
    '#type' => 'checkbox',
83
    '#title' => t('Continuous galleries'),
84 85 86 87
    '#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.'),
    '#default_value' => variable_get('lightbox2_loop_items', FALSE),
  );

88 89 90 91 92 93 94 95 96
  // Add checkbox for node link target.
  $form['layout_fieldset']['lightbox2_node_link_target'] = array(
    '#type' => 'checkbox',
    '#title' => t('Open image page in new window'),
    '#description' => t('This controls whether the link to the image page underneath the image is opened in a new window or the current window.'),
    '#default_value' => variable_get('lightbox2_node_link_target', FALSE),
    '#return_value' => '_blank',
  );

97 98 99 100 101 102 103
  // Define Lightbox2 text settings.
  /* ------------------------------- */
  $form['lightbox2_text_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Text settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
104 105
  );

106
  // Add text box for link text to node.
107
  $form['lightbox2_text_settings']['lightbox2_node_link_text'] = array(
108 109 110 111 112 113 114
    '#type' => 'textfield',
    '#title' => t('Text for image page link'),
    '#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.'),
    '#default_value' => variable_get('lightbox2_node_link_text', 'View Image Details'),
  );

  // Add text box for link text to node.
115
  $form['lightbox2_text_settings']['lightbox2_download_link_text'] = array(
116 117
    '#type' => 'textfield',
    '#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 120 121
    '#default_value' => variable_get('lightbox2_download_link_text', 'Download Original'),
  );

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 128 129 130
    '#default_value' => variable_get('lightbox2_image_count_str', 'Image !current of !total'),
  );

  // 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 136 137
    '#default_value' => variable_get('lightbox2_page_count_str', 'Page !current of !total'),
  );

138
  // Add text box for video count for grouping.
139
  $form['lightbox2_text_settings']['lightbox2_video_count_str'] = array(
140 141 142 143 144 145
    '#type' => 'textfield',
    '#title' => t('Video count text'),
    '#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.'),
    '#default_value' => variable_get('lightbox2_video_count_str', 'Video !current of !total'),
  );

146 147 148 149 150 151 152 153 154
  // Add text box for video count for grouping.
  $form['lightbox2_text_settings']['lightbox2_filter_xss_allowed_tags'] = array(
    '#type' => 'textfield',
    '#title' => t('Allowed HTML tags'),
    '#description' => t('A list of comma separated HTML tags which are allowed to be used in the caption text area.'),
    '#default_value' => variable_get('lightbox2_filter_xss_allowed_tags', 'p, br, a, em, strong, cite, code, ul, ol, li, dl, dt, dd'),
  );


155 156 157 158
  // Define Lightbox2 zoom fieldset.
  /* -------------------------------- */
  $form['zoom_fieldset'] = array(
    '#type' => 'fieldset',
159
    '#title' => t('Image resize settings'),
160 161 162 163 164 165 166
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Add checkbox for resize image.
  $form['zoom_fieldset']['lightbox2_disable_resize'] = array(
    '#type' => 'checkbox',
167
    '#title' => t('Disable resizing feature'),
168 169 170 171 172 173 174
    '#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.'),
    '#default_value' => variable_get('lightbox2_disable_resize', FALSE),
  );

  // Add checkbox for zoom image.
  $form['zoom_fieldset']['lightbox2_disable_zoom'] = array(
    '#type' => 'checkbox',
175
    '#title' => t('Disable zoom in / out feature'),
176 177 178 179
    '#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.'),
    '#default_value' => variable_get('lightbox2_disable_zoom', FALSE),
  );

180 181 182
  // Define Lightbox2 modal form fieldset.
  /* -------------------------------------- */
  $form['modal_form_fieldset'] = array(
183
    '#type' => 'fieldset',
184
    '#title' => t('Modal form settings'),
185 186 187 188 189
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Add checkbox for login support.
190
  $form['modal_form_fieldset']['lightbox2_enable_login'] = array(
191
    '#type' => 'checkbox',
192
    '#title' => t('Enable login support'),
193 194 195 196
    '#description' => t('Enabling this option will modify all login links so that the login form appears in a lightbox.'),
    '#default_value' => variable_get('lightbox2_enable_login', FALSE),
  );

197 198 199 200 201 202 203 204
  // Add checkbox for contact form support.
  $form['modal_form_fieldset']['lightbox2_enable_contact'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable contact form support'),
    '#description' => t('Enabling this option will modify all contact links so that the contact form appears in a lightbox.'),
    '#default_value' => variable_get('lightbox2_enable_contact', FALSE),
  );

205 206 207 208
  // Define Lightbox2 video fieldset.
  /* -------------------------------- */
  $form['video_fieldset'] = array(
    '#type' => 'fieldset',
209
    '#title' => t('Video settings'),
210 211 212 213 214 215 216
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Add checkbox for video support.
  $form['video_fieldset']['lightbox2_enable_video'] = array(
    '#type' => 'checkbox',
217
    '#title' => t('Enable video support'),
218 219 220 221
    '#description' => t('By default, video support is disabled in order to reduce the amount of javascript needed.  Checking this box will enable it.'),
    '#default_value' => variable_get('lightbox2_enable_video', FALSE),
  );

222 223 224 225
  // Add textfield for FLV Player path.
  $form['video_fieldset']['lightbox2_flv_player_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to FLV Player'),
226 227
    '#description' => t('The path to the FLV player, relative to Drupal root directory. No leading slashes.'),
    '#default_value' => variable_get('lightbox2_flv_player_path', 'flvplayer.swf'),
228 229
  );

230 231 232 233
  // Add textfield for FLV Player flashvars.
  $form['video_fieldset']['lightbox2_flv_player_flashvars'] = array(
    '#type' => 'textfield',
    '#title' => t('FLV Player flashvars'),
stella's avatar
stella committed
234
    '#description' => t('Flashvars for the FLV Player where supported, e.g. "autoplay=1&playerMode=normal".'),
235 236 237
    '#default_value' => variable_get('lightbox2_flv_player_flashvars', ''),
  );

238 239
  // Define Lightbox2 page specific settings fieldset.
  /* ------------------------------------------------ */
240 241
  $form['lightbox2_page_init'] = array(
    '#type' => 'fieldset',
242
    '#title' => t('Page specific lightbox2 settings'),
243 244 245 246 247 248 249 250 251 252 253 254
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  // Add radio buttons for the actions to take for the listed pages, i.e.
  // disable or enable the lightbox functionality.
  $page_options = array(
    'page_enable' => t('Load only on the listed pages.'),
    'page_disable' => t('Load on every page except the listed pages.'),
  );
  $form['lightbox2_page_init']['lightbox2_page_init_action'] = array(
    '#type' => 'radios',
    '#options' => $page_options,
255
    '#title' => t('Enable lightbox2 on specific pages'),
256 257 258 259 260 261
    '#default_value' => variable_get('lightbox2_page_init_action', 'page_disable'),
  );
  // Add text input for list of pages to take specific action on.
  $form['lightbox2_page_init']['lightbox2_page_list'] = array(
    '#type' => 'textarea',
    '#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 264 265
    '#default_value' => variable_get('lightbox2_page_list', ''),
  );

266
  // Define grouping settings fieldset.
267
  /* ------------------------------------ */
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
  $form['group_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Group display settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  $group_options = array(
    0 => t('No grouping'),
    1 => t('Group by field name'),
    2 => t('Group by node id'),
    3 => t('Group by field name and node id'),
    4 => t('Group all nodes and fields'),
  );

  $form['group_options']['lightbox2_image_group_node_id'] = array(
    '#type' => 'select',
    '#title' => t('Select Imagefield grouping in Views'),
    '#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.'),
    '#options' => $group_options,
    '#default_value' => variable_get('lightbox2_image_group_node_id', 1),
  );
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305


  // Define advanced settings fieldset.
  /* ---------------------------------- */
  $form['advanced_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Allow users to decide where javascript should be loaded - header or footer.
  // Header is recommended so user can click on images before page has finished
  // loading, but footer is needed for sites in IE which use SWFObject.
  $form['advanced_options']['lightbox2_js_location'] = array(
    '#type' => 'select',
306
    '#title' => t('Location of javscript'),
307 308 309 310 311
    '#options' => array('header' => t('Header'), 'footer' => t('Footer')),
    '#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.'),
    '#default_value' => variable_get('lightbox2_js_location', 'header'),
  );

312 313 314 315 316 317 318
  $form['advanced_options']['lightbox2_disable_close_click'] = array(
    '#type' => 'checkbox',
    '#title' => t('Click on overlay or lightbox to close it'),
    '#description' => t('Enable user to close lightbox by clicking on the lightbox itself or the overlay background.'),
    '#default_value' => variable_get('lightbox2_disable_close_click', TRUE),
  );

319 320 321 322
  // Define keyboard shortcuts fieldset.
  /* ---------------------------------- */
  $form['advanced_options']['keyboard_shortcuts'] = array(
    '#type' => 'fieldset',
323 324
    '#title' => t('Keyboard shortcuts'),
    '#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 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_close'] = array(
    '#type' => 'textfield',
    '#title' => t('Close keys'),
    '#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)."),
    '#default_value' => variable_get('lightbox2_keys_close', 'c x 27'),
  );

  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_previous'] = array(
    '#type' => 'textfield',
    '#title' => t('Previous keys'),
    '#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)."),
    '#default_value' => variable_get('lightbox2_keys_previous', 'p 37'),
  );

  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_next'] = array(
    '#type' => 'textfield',
    '#title' => t('Next keys'),
    '#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)."),
    '#default_value' => variable_get('lightbox2_keys_next', 'n 39'),
  );

  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_zoom'] = array(
    '#type' => 'textfield',
    '#title' => t('Zoom keys'),
    '#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'."),
    '#default_value' => variable_get('lightbox2_keys_zoom', 'z'),
  );

  $form['advanced_options']['keyboard_shortcuts']['lightbox2_keys_play_pause'] = array(
    '#type' => 'textfield',
359
    '#title' => t('Pause / play keys'),
360 361 362 363 364 365
    '#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)."),
    '#default_value' => variable_get('lightbox2_keys_play_pause', '32'),
  );



366

367 368 369 370 371 372 373 374
  // Define border settings fieldset.
  /* ---------------------------------- */
  $form['advanced_options']['skin_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Skin settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
375

376 377
  $form['advanced_options']['skin_settings']['lightbox2_border_size'] = array(
    '#type' => 'textfield',
378
    '#title' => t('Border size'),
379 380 381 382 383 384 385 386
    '#size' => 6,
    '#maxlength' => 6,
    '#description' => t('Enter the size of the border in pixels to display around the image.'),
    '#default_value' => variable_get('lightbox2_border_size', 10),
  );

  $form['advanced_options']['skin_settings']['lightbox2_box_color'] = array(
    '#type' => 'textfield',
387
    '#title' => t('Lightbox color'),
388 389 390 391 392 393 394 395 396
    '#field_prefix' => '#',
    '#size' => 6,
    '#maxlength' => 6,
    '#description' => t('Enter a hexadecimal color value for the border.  For example <code>fff</code> or <code>ffffff</code> for white).'),
    '#default_value' => variable_get('lightbox2_box_color', 'fff'),
  );

  $form['advanced_options']['skin_settings']['lightbox2_font_color'] = array(
    '#type' => 'textfield',
397
    '#title' => t('Font color'),
398 399 400 401 402 403 404
    '#field_prefix' => '#',
    '#size' => 6,
    '#maxlength' => 6,
    '#description' => t('Enter a hexadecimal color value for the font.  For example <code>000</code> or <code>000000</code> for black).'),
    '#default_value' => variable_get('lightbox2_font_color', '000'),
  );

405 406
  $form['advanced_options']['skin_settings']['lightbox2_top_position'] = array(
    '#type' => 'textfield',
stella's avatar
stella committed
407
    '#title' => t('Distance from top'),
408 409 410 411 412 413
    '#size' => 6,
    '#maxlength' => 6,
    '#description' => t('Enter the position of the top of the lightbox in pixels.  Leave blank for automatic calculation.'),
    '#default_value' => variable_get('lightbox2_top_position', ''),
  );

414 415


416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
  // Define overlay settings fieldset.
  /* ---------------------------------- */
  $form['advanced_options']['overlay_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Overlay settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  // Add checkbox for overlay opacity.
  for ($i = 0; $i < 10; $i++) {
    $opacity_options["0.$i"] = "0.$i";
  }
  $opacity_options["1.0"] = "1.0";
  $form['advanced_options']['overlay_settings']['lightbox2_overlay_opacity'] = array(
    '#type' => 'select',
431
    '#title' => t('Overlay opacity'),
432 433 434 435 436 437 438
    '#options' => $opacity_options,
    '#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.'),
    '#default_value' => variable_get('lightbox2_overlay_opacity', 0.8),
  );

  $form['advanced_options']['overlay_settings']['lightbox2_overlay_color'] = array(
    '#type' => 'textfield',
439
    '#title' => t('Overlay color'),
440 441 442 443 444 445 446
    '#field_prefix' => '#',
    '#size' => 6,
    '#maxlength' => 6,
    '#description' => t('Enter a hexadecimal color value for the overlay.  For example <code>000</code> or <code>000000</code> for black).'),
    '#default_value' => variable_get('lightbox2_overlay_color', '000'),
  );

447

448 449 450 451 452 453 454 455 456 457
  // Define animation settings fieldset.
  /* ----------------------------------- */
  $form['advanced_options']['animation_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Animation settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  // Set animation help text.
  $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 461 462 463 464 465 466
  );
  $resize_sequence_options = array(
    t('Simultaneous'),
    t('Width then height'),
    t('Height then width'),
  );
  $form['advanced_options']['animation_settings']['lightbox2_resize_sequence'] = array(
    '#type' => 'select',
467
    '#title' => t('Resize sequence'),
468 469 470 471 472 473
    '#options' => $resize_sequence_options,
    '#description' => t('The sequence to use for the resizing animation.'),
    '#default_value' => variable_get('lightbox2_resize_sequence', 0),
  );
  $form['advanced_options']['animation_settings']['lightbox2_resize_speed'] = array(
    '#type' => 'textfield',
474
    '#title' => t('Resize duration'),
475 476 477 478 479 480 481
    '#size' => 5,
    '#maxlength' => 5,
    '#description' => t('The duration (in seconds) of the resizing animation.  Enter a value between 0 and 10.'),
    '#default_value' => variable_get('lightbox2_resize_speed', 0.4),
  );
  $form['advanced_options']['animation_settings']['lightbox2_fadein_speed'] = array(
    '#type' => 'textfield',
482
    '#title' => t('Appearance duration'),
483 484
    '#size' => 5,
    '#maxlength' => 5,
stella's avatar
stella committed
485
    '#description' => t('The duration (in seconds) of the lightbox appearance animation.  Enter a positive number less than 10.'),
486 487 488 489 490 491
    '#default_value' => variable_get('lightbox2_fadein_speed', 0.4),
  );


  $form['advanced_options']['animation_settings']['lightbox2_slidedown_speed'] = array(
    '#type' => 'textfield',
492
    '#title' => t('Caption slide down duration'),
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
    '#size' => 5,
    '#maxlength' => 5,
    '#description' => t('The duration (in seconds) of the caption sliding-down animation.  Enter a value between 0 and 10.'),
    '#default_value' => variable_get('lightbox2_slidedown_speed', 0.6),
  );

  return system_settings_form($form);
}

/**
 * Validation function for the general configuration form.
 *
 * Ensure that the hex color value submitted is valid and that the speeds are
 * numeric.
 */
function lightbox2_general_settings_form_validate($form, &$form_state) {
509
  if ($form_state['values']['op'] == t('Save configuration')) {
510 511 512 513 514 515 516 517
    $border_size = $form_state['values']['lightbox2_border_size'];
    $box_hex_colour = $form_state['values']['lightbox2_box_color'];
    $font_hex_colour = $form_state['values']['lightbox2_font_color'];
    $top_position = $form_state['values']['lightbox2_top_position'];
    $overlay_hex_colour = $form_state['values']['lightbox2_overlay_color'];
    $resize_speed = $form_state['values']['lightbox2_resize_speed'];
    $fadein_speed = $form_state['values']['lightbox2_fadein_speed'];
    $slide_down_speed = $form_state['values']['lightbox2_slidedown_speed'];
518 519
    $flv_player_path = $form_state['values']['lightbox2_flv_player_path'];

stella's avatar
stella committed
520
    if (!empty($flv_player_path) && $form_state['values']['lightbox2_enable_video']) {
521 522 523 524 525 526 527 528
      if (strpos($flv_player_path, base_path()) === 0) {
        $flv_player_path = drupal_substr($flv_player_path, drupal_strlen(base_path()));
      }
      if (!file_exists($flv_player_path)) {
        form_set_error('lightbox2_flv_player_path', t("FLV player path doesn't exist."));
      }
    }

529 530
    if (!_lightbox2_validate_hex_color($overlay_hex_colour)) {
      form_set_error('lightbox2_overlay_color', t('You must enter a properly formed hex value.'));
531 532
    }

533 534 535 536
    if (!$form_state['values']['lightbox2_lite']) {
      if (!is_numeric($border_size) || $border_size < 0) {
        form_set_error('lightbox2_border_size', t('You must enter a size greater than 0 pixels.'));
      }
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 543 544
      if (!_lightbox2_validate_hex_color($font_hex_colour)) {
        form_set_error('lightbox2_font_color', t('You must enter a properly formed hex value.'));
      }
545

546 547 548
      if (!empty($top_position) && (!is_numeric($top_position) || $top_position < 0)) {
        form_set_error('lightbox2_top_position', t('You must enter a size greater than 0 pixels.  Leave blank for default positioning.'));
      }
549

550 551 552 553
      if (!is_numeric($resize_speed) || $resize_speed <= 0 || $resize_speed >= 10) {
        form_set_error('lightbox2_resize_speed', t('You must enter a duration between 0 and 10 seconds.'));
      }

554
      if (!is_numeric($fadein_speed) || $fadein_speed < 0 || $fadein_speed >= 10) {
555 556
        form_set_error('lightbox2_fadein_speed', t('You must enter a duration between 0 and 10 seconds.'));
      }
557

558 559 560
      if (!is_numeric($slide_down_speed) || $slide_down_speed <= 0 || $slide_down_speed >= 10) {
        form_set_error('lightbox2_slidedown_speed', t('You must enter a duration between 0 and 10 seconds.'));
      }
561
    }
562 563 564
  }
}

565 566 567 568 569 570 571
/**
 * Submit function for the general configuration form.
 */
function lightbox2_general_settings_form_submit($form, &$form_state) {
  cache_clear_all();
}

572 573 574 575 576 577
/**
 * Configuration form for controlling the slideshow behaviour.
 */
function lightbox2_slideshow_settings_form() {

  // Add the javascript which disables / enables form elements.
578
  drupal_add_js(drupal_get_path('module', 'lightbox2') . '/js/lightbox2.js', 'module');
579 580 581 582 583 584 585 586 587 588 589

  // Set up a hidden variable.
  $form['lightbox2_lite'] = array(
    '#type' => 'hidden',
    '#value' => variable_get('lightbox2_lite', FALSE),
  );


  // Add text box for slideshow interval.
  $form['lightbox2_slideshow_interval'] = array(
    '#type' => 'textfield',
590
    '#title' => t('Interval seconds'),
591 592 593 594 595
    '#description' => t('The slideshow interval is the length of time in seconds an image is visible before the slideshow shows the next image.'),
    '#default_value' => variable_get('lightbox2_slideshow_interval', 5),
    '#size' => 20,
  );

596 597 598 599 600 601 602 603
   // Add checkbox for slideshow automatic start.
  $form['lightbox2_slideshow_automatic_start'] = array(
    '#type' => 'checkbox',
    '#title' => t('Automatically start slideshow'),
    '#description' => t('When enabled the slideshow will automatically start.'),
    '#default_value' => variable_get('lightbox2_slideshow_automatic_start', TRUE),
  );

604 605 606
  // Add checkbox for slideshow automatic exit.
  $form['lightbox2_slideshow_automatic_exit'] = array(
    '#type' => 'checkbox',
607
    '#title' => t('Automatically exit slideshow'),
608 609 610 611 612 613 614
    '#description' => t('When enabled the lightbox will automatically close after displaying the last image.'),
    '#default_value' => variable_get('lightbox2_slideshow_automatic_exit', TRUE),
  );

  // Add checkbox for showing hte play / pause button.
  $form['lightbox2_slideshow_show_play_pause'] = array(
    '#type' => 'checkbox',
615
    '#title' => t('Show play / pause button'),
616 617 618 619 620 621 622
    '#description' => t('When enabled, a play / pause button will be shown in the slideshow allowing the user more control over their viewing experience.'),
    '#default_value' => variable_get('lightbox2_slideshow_show_play_pause', TRUE),
  );

  // Add checkbox for "pausing on next click".
  $form['lightbox2_slideshow_pause_on_next_click'] = array(
    '#type' => 'checkbox',
623
    '#title' => t('Pause slideshow on "Next Image" click'),
624 625 626 627 628
    '#description' => t('When enabled the slideshow is automatically paused, and the following image shown, when the "Next" button is clicked.'),
    '#default_value' => variable_get('lightbox2_slideshow_pause_on_next_click', FALSE),
  );

  // 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 633 634 635
    '#description' => t('When enabled the slideshow is automatically paused, and the previous image shown, when the "Previous" button is clicked.'),
    '#default_value' => variable_get('lightbox2_slideshow_pause_on_previous_click', TRUE),
  );

636 637 638
  // Add checkbox for "looping through slides'.
  $form['lightbox2_loop_slides'] = array(
    '#type' => 'checkbox',
639
    '#title' => t('Continuous loop'),
640 641 642 643
    '#description' => t('When enabled the slideshow will automatically start over after displaying the last slide.  This prevents the slideshow from automatically exiting when enabled.'),
    '#default_value' => variable_get('lightbox2_loop_slides', FALSE),
  );

644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
  return system_settings_form($form);
}

/**
 * Validation function for the slideshow configuration form.
 *
 * Ensure that the slideshow interval submitted is numeric.
 */
function lightbox2_slideshow_settings_form_validate($form, &$form_state) {
  if (!is_numeric($form_state['values']['lightbox2_slideshow_interval'])) {
    form_set_error('lightbox2_slideshow_interval', t('The "interval seconds" value must be numeric.'));
  }
}

/**
 * Configuration form for controlling the iframe behaviour.
 */
function lightbox2_iframe_settings_form() {

  // Add the javascript which disables / enables form elements.
664
  drupal_add_js(drupal_get_path('module', 'lightbox2') . '/js/lightbox2.js', 'module');
665 666 667 668 669 670 671 672 673 674 675

  // Set up a hidden variable.
  $form['lightbox2_lite'] = array(
    '#type' => 'hidden',
    '#value' => variable_get('lightbox2_lite', FALSE),
  );


  // Add text box for iframe width.
  $form['lightbox2_default_frame_width'] = array(
    '#type' => 'textfield',
676
    '#title' => t('Default width'),
677 678 679 680 681 682 683 684
    '#description' => t('The default width of the iframe in pixels.'),
    '#default_value' => variable_get('lightbox2_default_frame_width', 600),
    '#size' => 20,
  );

  // Add text box for iframe height.
  $form['lightbox2_default_frame_height'] = array(
    '#type' => 'textfield',
685
    '#title' => t('Default height'),
686 687 688 689 690 691 692 693
    '#description' => t('The default height of the iframe in pixels.'),
    '#default_value' => variable_get('lightbox2_default_frame_height', 400),
    '#size' => 20,
  );

  // Add option for iframe border.
  $form['lightbox2_frame_border'] = array(
    '#type' => 'checkbox',
694
    '#title' => t('Enable border'),
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
    '#description' => t('Enable iframe border.  You can modify the border style in your theme\'s css file using the iframe\'s id "lightboxFrame".'),
    '#default_value' => variable_get('lightbox2_frame_border', 1),
  );

  return system_settings_form($form);
}

/**
 * Validation function for the iframe configuration form.
 *
 * Ensure that the iframe width and height submitted are numeric.
 */
function lightbox2_iframe_settings_form_validate($form, &$form_state) {
  if (!is_numeric($form_state['values']['lightbox2_default_frame_width'])) {
    form_set_error('lightbox2_slideshow_interval', t('The "default width" value must be numeric.'));
  }
  if (!is_numeric($form_state['values']['lightbox2_default_frame_height'])) {
    form_set_error('lightbox2_slideshow_interval', t('The "default height" value must be numeric.'));
  }
}


/**
 * Configuration form the automatic image handling functionality.
 */
function lightbox2_auto_image_handling_settings_form() {

  // Add the javascript which disables / enables form elements.
723
  drupal_add_js(drupal_get_path('module', 'lightbox2') . '/js/lightbox2.js', 'module');
724 725 726 727 728 729 730 731 732 733 734 735

  // Set up a hidden variable.
  $form['lightbox2_lite'] = array(
    '#type' => 'hidden',
    '#value' => variable_get('lightbox2_lite', FALSE),
  );

  $automatic_options = array(
    0 => t('Disabled'),
    1 => t('Lightbox'),
    2 => t('Lightbox grouped'),
    3 => t('Slideshow'),
736 737
    4 => t('HTML content'),
    5 => t('HTML content grouped'),
738 739 740 741 742 743 744
  );

  // Set image node options help text.
  $form['image_node_options'] = array(
    '#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.'),
  );

745 746 747 748
  // Define handler settings fieldset.
  /* --------------------------------- */
  $form['handler_options'] = array(
    '#type' => 'fieldset',
749
    '#title' => t('Automatic handlers'),
750 751 752 753
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

754 755
  // Define image nodes settings fieldset.
  /* ------------------------------------- */
756
  $form['handler_options']['image_node_options'] = array(
757 758 759
    '#type' => 'fieldset',
    '#title' => t('Image node settings'),
    '#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 768 769 770 771
    '#options' => $automatic_options,
    '#description' => t('Choose how URLs for image nodes will be automatically handled.'),
    '#default_value' => variable_get('lightbox2_image_node', 0),
  );

772
  /*
773 774
  // Add drop-down for list of available image sizes.
  if (module_exists('image')) {
775
    $sizes = image_get_sizes();
776 777
    foreach ($sizes as $size_key => $size) {
      if ($size_key == 'original' or $size_key == '_original')  {
778
        $size_key = 'original';
779 780 781
      }
      $size_options[$size_key] = $size['label'];
    }
782
    $form['handler_options']['image_node_options']['lightbox2_display_image_size'] = array(
783 784 785
      '#type' => 'select',
      '#title' => t('Lightbox image display size'),
      '#options' => $size_options,
786
      '#default_value' => variable_get('lightbox2_display_image_size', 'original'),
787 788 789
      '#description' => t('Select which image size will be loaded in the lightbox.  This only applies to images uploaded with the Image module.'),
    );

790
    $form['handler_options']['image_node_options']['lightbox2_trigger_image_size'] = array(
791 792 793 794 795 796 797 798 799
      '#type' => 'select',
      '#multiple' => TRUE,
      '#title' => t('Image trigger size'),
      '#options' => $size_options,
      '#default_value' => variable_get('lightbox2_trigger_image_size', array('thumbnail')),
      '#description' => t('Select which image size, when clicked on, will automatically trigger the lightbox.  This only applies to images uploaded with the Image module.'),
    );

  }
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 807 808 809
    '#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.'),
    '#default_value' => variable_get('lightbox2_disable_nested_galleries', TRUE),
  );

810 811 812 813
  // Define flickr fieldset.
  /* ----------------------- */
  $form['handler_options']['flickr_options'] = array(
    '#type' => 'fieldset',
814
    '#title' => t('Flickr images'),
815 816 817
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
818
  // Add checkbox for flickr image support.
819
  $form['handler_options']['flickr_options']['lightbox2_flickr'] = array(
820 821 822 823 824 825 826
    '#type' => 'select',
    '#title' => t('Automatic handler for Flickr images'),
    '#options' => $automatic_options,
    '#description' => t('Choose how URLs for Flickr images will be automatically handled.'),
    '#default_value' => variable_get('lightbox2_flickr', 0),
  );

827 828 829 830
  // Define gallery2 fieldset.
  /* ------------------------- */
  $form['handler_options']['gallery2_options'] = array(
    '#type' => 'fieldset',
831
    '#title' => t('Gallery2 images'),
832 833 834
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
835
  // Add checkbox for gallery2 block image support.
836
  $form['handler_options']['gallery2_options']['lightbox2_gallery2_blocks'] = array(
837 838 839 840 841 842 843
    '#type' => 'select',
    '#title' => t('Automatic handler for Gallery2 block images'),
    '#options' => $automatic_options,
    '#description' => t('Choose how URLs for images, contained within Gallery2 image blocks, will be automatically handled.'),
    '#default_value' => variable_get('lightbox2_gallery2_blocks', 0),
  );

844 845 846 847
  // Define inline fieldset.
  /* ----------------------- */
  $form['handler_options']['inline_options'] = array(
    '#type' => 'fieldset',
stella's avatar
stella committed
848
    '#title' => t('Inline module images'),
849 850 851
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
852
  // Add checkbox for inline image support.
853
  $form['handler_options']['inline_options']['lightbox2_inline'] = array(
854
    '#type' => 'select',
stella's avatar
stella committed
855
    '#title' => t('Automatic handler for Inline module images'),
856
    '#options' => $automatic_options,
stella's avatar
stella committed
857
    '#description' => t('Choose how URLs for Inline module images will be automatically handled.'),
858 859 860
    '#default_value' => variable_get('lightbox2_inline', 0),
  );

861 862 863 864
  // Define image assist fieldset.
  /* ----------------------------- */
  $form['handler_options']['img_assist_options'] = array(
    '#type' => 'fieldset',
865
    '#title' => t('Image Assist images'),
866 867 868
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
869
  // Add checkbox for image assist custom size images.
870
  $form['handler_options']['img_assist_options']['lightbox2_image_assist_custom'] = array(
871 872 873 874 875 876 877
    '#type' => 'select',
    '#title' => t('Automatic handler for Image Assist custom size images'),
    '#options' => $automatic_options,
    '#description' => t('Choose how URLs for custom size images, displayed by the Image Assist module, will be automatically handled.'),
    '#default_value' => variable_get('lightbox2_image_assist_custom', 0),
  );

878 879 880 881
  // Define custom fieldset.
  /* ----------------------- */
  $form['handler_options']['custom_options'] = array(
    '#type' => 'fieldset',
882
    '#title' => t('Custom class images'),
883 884 885 886 887 888 889 890 891 892 893
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  // Add checkbox for custom class image support.
  $form['handler_options']['custom_options']['lightbox2_custom_class_handler'] = array(
    '#type' => 'select',
    '#title' => t('Automatic handler for custom class images'),
    '#options' => $automatic_options,
    '#description' => t('Choose how URLs for custom class images will be automatically handled.'),
    '#default_value' => variable_get('lightbox2_custom_class_handler', 0),
  );
894
  // Add text box for custom trigger classes.
895
  $form['handler_options']['custom_options']['lightbox2_custom_trigger_classes'] = array(
896 897 898 899 900 901 902 903
    '#type' => 'textarea',
    '#title' => t('Custom image trigger classes'),
    '#description' => t('List the image classes which should trigger the lightbox when clicked on.  Put each class on a separate line.'),
    '#default_value' => variable_get('lightbox2_custom_trigger_classes', ''),
  );

  // Add checkbox for disabling lightbox for acidfree gallery lists.
  if (module_exists("acidfree")) {
904 905 906 907 908 909 910 911 912
    // Define acidfree settings fieldset.
    /* ---------------------------------- */
    $form['handler_options']['lightbox2_acidfree_options'] = array(
      '#type' => 'fieldset',
      '#title' => t('Acidfree settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $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 916 917 918 919
      '#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.'),
      '#default_value' => variable_get('lightbox2_disable_nested_acidfree_galleries', TRUE),
    );
    // Add checkbox for enabling lightbox for acidfree videos.
    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 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
        '#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.'),
        '#default_value' => variable_get('lightbox2_enable_acidfree_videos', FALSE),
      );
    }
  }

  return system_settings_form($form);
}

/**
 * Validate a hex color value.
 *
 * @param $hex
 *   The hex color string to validate.
 * @return
 *   TRUE if $hex is a valid hex color value.
 */
function _lightbox2_validate_hex_color($hex) {
  return preg_match('!^[a-f0-9]{3}([a-f0-9]{3})?$!i', $hex);
}