You are here

function lightbox2_add_files in Lightbox2 5.2

Same name and namespace in other branches
  1. 8 lightbox2.module \lightbox2_add_files()
  2. 5 lightbox2.module \lightbox2_add_files()
  3. 6 lightbox2.module \lightbox2_add_files()
  4. 7.2 lightbox2.module \lightbox2_add_files()
  5. 7 lightbox2.module \lightbox2_add_files()

Provide links to the CSS stylesheet and JS file associated with this module.

1 call to lightbox2_add_files()
lightbox2_menu in ./lightbox2.module
Implementation of hook_menu().

File

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

Code

function lightbox2_add_files() {
  global $user;
  static $already_added = FALSE;
  if ($already_added) {
    return;

    // Don't add the javascript and CSS multiple times.
  }
  $already_added = TRUE;

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

  // Initialise some variables.
  $inline_image_handler = variable_get('lightbox2_inline', 0);
  $flickr_image_handler = variable_get('lightbox2_flickr', 0);
  $gallery2_block_handler = variable_get('lightbox2_gallery2_blocks', 0);
  $image_assist_handler = variable_get('lightbox2_image_assist_custom', 0);
  $image_node_handler = variable_get('lightbox2_image_node', 0);
  $custom_class_handler = 0;
  switch (variable_get('lightbox2_custom_class_handler', 0)) {
    case 1:
      $custom_class_handler = 'lightbox_ungrouped';
      break;
    case 2:
      $custom_class_handler = 'lightbox';
      break;
    case 3:
      $custom_class_handler = 'lightshow';
      break;
    case 4:
      $custom_class_handler = 'lightframe_ungrouped';
      break;
    case 5:
      $custom_class_handler = 'lightframe';
      break;
  }

  // Set the list of image classes to format urls for.
  $image_node_sizes = '';
  $trigger_lightbox_classes = '';
  $trigger_lightbox_group_classes = '';
  $trigger_slideshow_classes = '';
  $trigger_lightframe_classes = '';
  $trigger_lightframe_group_classes = '';

  // Inline module images.
  switch ($inline_image_handler) {
    case 1:
      $trigger_lightbox_classes .= 'img.inline,';
      break;
    case 2:
      $trigger_lightbox_group_classes .= 'img.inline,';
      break;
    case 3:
      $trigger_slideshow_classes .= 'img.inline,';
      break;
    case 4:
      $trigger_lightframe_classes .= 'img.inline,';
      break;
    case 5:
      $trigger_lightframe_group_classes .= 'img.inline,';
      break;
  }

  // Flickr images.
  switch ($flickr_image_handler) {
    case 1:
      $trigger_lightbox_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
    case 2:
      $trigger_lightbox_group_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
    case 3:
      $trigger_slideshow_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
    case 4:
      $trigger_lightframe_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
    case 5:
      $trigger_lightframe_group_classes .= 'img.flickr-photo-img,img.flickr-photoset-img,';
      break;
  }

  // Gallery2 block images.
  switch ($gallery2_block_handler) {
    case 1:
      $trigger_lightbox_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
    case 2:
      $trigger_lightbox_group_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
    case 3:
      $trigger_slideshow_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
    case 4:
      $trigger_lightframe_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
    case 5:
      $trigger_lightframe_group_classes .= 'img.ImageFrame_image,img.ImageFrame_none,';
      break;
  }

  // Image Assist custom size images.
  switch ($image_assist_handler) {
    case 1:
      $trigger_lightbox_classes .= 'img.image-img_assist_custom,';
      break;
    case 2:
      $trigger_lightbox_group_classes .= 'img.image-img_assist_custom,';
      break;
    case 3:
      $trigger_slideshow_classes .= 'img.image-img_assist_custom,';
      break;
    case 4:
      $trigger_lightframe_classes .= 'img.image-img_assist_custom,';
      break;
    case 5:
      $trigger_lightframe_group_classes .= 'img.image-img_assist_custom,';
      break;
  }

  // Image nodes.
  if ($image_node_handler) {
    $trigger_sizes = variable_get('lightbox2_trigger_image_size', array(
      'thumbnail',
    ));
    usort($trigger_sizes, "sort_by_length");
    foreach ($trigger_sizes as $size) {
      $triggers = "img.{$size}, img.image-{$size},";
      if (empty($size)) {
        if (user_access('view original images')) {
          $triggers = "img._original, img.image-_original,";
        }
      }
      else {
        $image_node_sizes .= "\\.{$size}|";
      }
      switch ($image_node_handler) {
        case 1:
          $trigger_lightbox_classes .= $triggers;
          break;
        case 2:
          $trigger_lightbox_group_classes .= $triggers;
          break;
        case 3:
          $trigger_slideshow_classes .= $triggers;
          break;
        case 4:
          $trigger_lightframe_classes .= $triggers;
          break;
        case 5:
          $trigger_lightframe_group_classes .= $triggers;
          break;
      }
    }
  }

  // Custom images.
  $custom_triggers = variable_get('lightbox2_custom_trigger_classes', '');
  $custom_trigger_classes = '';
  if ($custom_class_handler && !empty($custom_triggers)) {
    $trigger_classes = preg_split("/(\r\n|\n)/", $custom_triggers);
    foreach ($trigger_classes as $class) {
      if (!empty($class)) {
        $custom_trigger_classes .= "img.{$class},";
      }
    }
  }
  $trigger_lightbox_classes = rtrim($trigger_lightbox_classes, ",");
  $trigger_lightbox_group_classes = rtrim($trigger_lightbox_group_classes, ",");
  $trigger_slideshow_classes = rtrim($trigger_slideshow_classes, ",");
  $trigger_lightframe_classes = rtrim($trigger_lightframe_classes, ",");
  $trigger_lightframe_group_classes = rtrim($trigger_lightframe_group_classes, ",");
  $custom_trigger_classes = rtrim($custom_trigger_classes, ",");
  $image_node_sizes = '(' . rtrim($image_node_sizes, "|") . ')';

  // Find out if we're using a RTL language.
  $rtl = FALSE;
  if (module_exists('i18n') && module_invoke('i18n', 'language_rtl')) {
    $rtl = TRUE;
  }
  $enable_video = variable_get('lightbox2_enable_video', FALSE);
  $enable_login = $user->uid == 0 && variable_get('lightbox2_enable_login', FALSE);
  $enable_contact = module_exists('contact') && variable_get('lightbox2_enable_contact', FALSE) && user_access('access site-wide contact form');
  $display_image_size = variable_get('lightbox2_display_image_size', 'original');
  if ($display_image_size == 'original' && user_access('view original images')) {
    $display_image_size = '';
  }

  // Load the javascript settings.
  $js_settings = array(
    'rtl' => $rtl,
    'file_path' => base_path() . '(\\w\\w/)' . file_directory_path(),
    'base_path' => base_path(),
    'default_image' => base_path() . $path . '/images/brokenimage.jpg',
    'border_size' => (int) variable_get('lightbox2_border_size', 10),
    'font_color' => variable_get('lightbox2_font_color', '000'),
    'box_color' => variable_get('lightbox2_box_color', 'fff'),
    'top_position' => variable_get('lightbox2_top_position', ''),
    'overlay_opacity' => (double) variable_get('lightbox2_overlay_opacity', 0.8),
    'overlay_color' => variable_get('lightbox2_overlay_color', '000'),
    'disable_close_click' => variable_get('lightbox2_disable_close_click', TRUE),
    'resize_sequence' => (int) variable_get('lightbox2_resize_sequence', 0),
    'resize_speed' => 1000 * (double) variable_get('lightbox2_resize_speed', 0.4),
    'fade_in_speed' => 1000 * (double) variable_get('lightbox2_fadein_speed', 0.4),
    'slide_down_speed' => 1000 * (double) variable_get('lightbox2_slidedown_speed', 0.6),
    'use_alt_layout' => variable_get('lightbox2_use_alt_layout', FALSE),
    'disable_resize' => variable_get('lightbox2_disable_resize', FALSE),
    'disable_zoom' => variable_get('lightbox2_disable_zoom', FALSE),
    'force_show_nav' => variable_get('lightbox2_force_show_nav', FALSE),
    'loop_items' => variable_get('lightbox2_loop_items', FALSE),
    'node_link_text' => check_plain(variable_get('lightbox2_node_link_text', 'View Image Details')),
    'node_link_target' => variable_get('lightbox2_node_link_target', FALSE),
    'image_count' => check_plain(variable_get('lightbox2_image_count_str', 'Image !current of !total')),
    'page_count' => check_plain(variable_get('lightbox2_page_count_str', 'Page !current of !total')),
    'video_count' => check_plain(variable_get('lightbox2_video_count_str', 'Video !current of !total')),
    'lite_press_x_close' => t('press !x to close', array(
      '!x' => '<a href="#" onclick="hideLightbox(); return FALSE;"><kbd>x</kbd></a>',
    )),
    'enable_login' => $enable_login,
    'enable_contact' => $enable_contact,
    // Automatic image handling settings.
    'keys_close' => variable_get('lightbox2_keys_close', 'c x 27'),
    'keys_previous' => variable_get('lightbox2_keys_previous', 'p 37'),
    'keys_next' => variable_get('lightbox2_keys_next', 'n 39'),
    'keys_zoom' => variable_get('lightbox2_keys_zoom', 'z'),
    'keys_play_pause' => variable_get('lightbox2_keys_play_pause', '32'),
    'display_image_size' => $display_image_size,
    'image_node_sizes' => $image_node_sizes,
    'trigger_lightbox_classes' => $trigger_lightbox_classes,
    'trigger_lightbox_group_classes' => $trigger_lightbox_group_classes,
    'trigger_slideshow_classes' => $trigger_slideshow_classes,
    'trigger_lightframe_classes' => $trigger_lightframe_classes,
    'trigger_lightframe_group_classes' => $trigger_lightframe_group_classes,
    'custom_class_handler' => $custom_class_handler,
    'custom_trigger_classes' => $custom_trigger_classes,
    'disable_for_gallery_lists' => variable_get('lightbox2_disable_nested_galleries', TRUE),
    'disable_for_acidfree_gallery_lists' => variable_get('lightbox2_disable_nested_acidfree_galleries', TRUE),
    'enable_acidfree_videos' => variable_get('lightbox2_enable_acidfree_videos', FALSE),
    // Slideshow settings.
    'slideshow_interval' => variable_get('lightbox2_slideshow_interval', 5) * 1000,
    'slideshow_automatic_start' => variable_get('lightbox2_slideshow_automatic_start', TRUE),
    'slideshow_automatic_exit' => variable_get('lightbox2_slideshow_automatic_exit', TRUE),
    'show_play_pause' => variable_get('lightbox2_slideshow_show_play_pause', TRUE),
    'pause_on_next_click' => variable_get('lightbox2_slideshow_pause_on_next_click', FALSE),
    'pause_on_previous_click' => variable_get('lightbox2_slideshow_pause_on_previous_click', TRUE),
    'loop_slides' => variable_get('lightbox2_loop_slides', FALSE),
    // Iframe settings.
    'iframe_width' => (int) variable_get('lightbox2_default_frame_width', 600),
    'iframe_height' => (int) variable_get('lightbox2_default_frame_height', 400),
    'iframe_border' => (int) variable_get('lightbox2_frame_border', 1),
    // Video settings.
    'enable_video' => variable_get('lightbox2_enable_video', FALSE),
  );
  if ($enable_video) {
    $js_settings['flvPlayer'] = url(check_plain(trim(variable_get('lightbox2_flv_player_path', 'flvplayer.swf'), '/')));
    $js_settings['flvFlashvars'] = check_plain(variable_get('lightbox2_flv_player_flashvars', ''));
  }
  drupal_add_js(array(
    'lightbox2' => $js_settings,
  ), 'setting');

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

  // Lightbox2 Plus.
  if (!variable_get('lightbox2_lite', FALSE)) {
    $css = $path . '/css/lightbox.css';
    if (module_exists('i18n') && module_invoke('i18n', 'language_rtl')) {
      $css = $path . '/css/lightbox-rtl.css';
    }
    if (variable_get('lightbox2_use_alt_layout', FALSE)) {

      // No need for rtl version, everything is centred.
      $css = $path . '/css/lightbox_alt.css';
    }
    drupal_add_css($css);

    // Check to see if any automatic image handling options are enabled.
    if ($image_node_handler || $flickr_image_handler || $gallery2_block_handler || $inline_image_handler || $image_assist_handler || $custom_triggers != '') {
      drupal_add_js($path . '/js/auto_image_handling.js', 'module', $js_location);
    }
    if (variable_get('lightbox2_enable_video', FALSE)) {
      drupal_add_js($path . '/js/lightbox_video.js', 'module', $js_location);
    }
    if ($enable_login || $enable_contact) {
      drupal_add_js($path . '/js/lightbox_modal.js', 'module', $js_location);
    }
    drupal_add_js($path . '/js/lightbox.js', 'module', $js_location);
  }
  else {
    $css = $path . '/css/lightbox_lite.css';
    if (module_exists('i18n') && module_invoke('i18n', 'language_rtl')) {
      $css = $path . '/css/lightbox_lite-rtl.css';
    }
    drupal_add_css($css);
    drupal_add_js($path . '/js/lightbox_lite.js', 'module', $js_location);
  }
}