function lightbox2_add_files in Lightbox2 8
Same name and namespace in other branches
- 5.2 lightbox2.module \lightbox2_add_files()
- 5 lightbox2.module \lightbox2_add_files()
- 6 lightbox2.module \lightbox2_add_files()
- 7.2 lightbox2.module \lightbox2_add_files()
- 7 lightbox2.module \lightbox2_add_files()
Provide links to the CSS stylesheet and JS file associated with this module.
2 calls to lightbox2_add_files()
- InitSubscriber::onEvent in src/
EventSubscriber/ InitSubscriber.php - lightbox2_init in ./
lightbox2.module - Implementation of hook_init().
File
- ./
lightbox2.module, line 499 - 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 $language, $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 = \Drupal::config('lightbox2.settings')
->get('lightbox2_inline');
$flickr_image_handler = \Drupal::config('lightbox2.settings')
->get('lightbox2_flickr');
$gallery2_block_handler = \Drupal::config('lightbox2.settings')
->get('lightbox2_gallery2_blocks');
$image_assist_handler = \Drupal::config('lightbox2.settings')
->get('lightbox2_image_assist_custom');
$image_node_handler = \Drupal::config('lightbox2.settings')
->get('lightbox2_image_node');
$custom_class_handler = 0;
switch (\Drupal::config('lightbox2.settings')
->get('lightbox2_custom_class_handler')) {
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) {
// @FIXME
// Could not extract the default value because it is either indeterminate, or
// not scalar. You'll need to provide a default value in
// config/install/lightbox2.settings.yml and config/schema/lightbox2.schema.yml.
$trigger_sizes = \Drupal::config('lightbox2.settings')
->get('lightbox2_trigger_image_size');
usort($trigger_sizes, "sort_by_length");
foreach ($trigger_sizes as $size) {
$triggers = "img.{$size}, img.image-{$size},";
if (empty($size)) {
if (\Drupal::currentUser()
->hasPermission('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 = \Drupal::config('lightbox2.settings')
->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, "|") . ')';
$enable_video = \Drupal::config('lightbox2.settings')
->get('lightbox2_enable_video');
$enable_login = $user->uid == 0 && \Drupal::config('lightbox2.settings')
->get('lightbox2_enable_login');
$enable_contact = \Drupal::moduleHandler()
->moduleExists('contact') && \Drupal::config('lightbox2.settings')
->get('lightbox2_enable_contact') && \Drupal::currentUser()
->hasPermission('access site-wide contact form');
$display_image_size = \Drupal::config('lightbox2.settings')
->get('lightbox2_display_image_size');
if ($display_image_size == 'original' && \Drupal::currentUser()
->hasPermission('view original images')) {
$display_image_size = '';
}
$font_color = \Drupal::config('lightbox2.settings')
->get('lightbox2_font_color');
$box_color = \Drupal::config('lightbox2.settings')
->get('lightbox2_box_color');
$file_path = base_path() . '(\\w\\w/)' . file_default_scheme() . ':/';
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// if ( variable_get('file_downloads', 'FILE_DOWNLOADS_PUBLIC') == 'FILE_DOWNLOADS_PRIVATE' ) {
// $file_path = base_path() . '(\w\w/)system/files';
// }
// Load the javascript settings.
$js_settings = array(
'rtl' => $language->direction,
'file_path' => $file_path,
'default_image' => base_path() . $path . '/images/brokenimage.jpg',
'border_size' => (int) \Drupal::config('lightbox2.settings')
->get('lightbox2_border_size'),
'font_color' => !empty($font_color) ? $font_color : '000',
'box_color' => !empty($box_color) ? $box_color : '000',
'top_position' => \Drupal::config('lightbox2.settings')
->get('lightbox2_top_position'),
'overlay_opacity' => str_replace(',', '.', \Drupal::config('lightbox2.settings')
->get('lightbox2_overlay_opacity')),
'overlay_color' => \Drupal::config('lightbox2.settings')
->get('lightbox2_overlay_color'),
'disable_close_click' => \Drupal::config('lightbox2.settings')
->get('lightbox2_disable_close_click'),
'resize_sequence' => (int) \Drupal::config('lightbox2.settings')
->get('lightbox2_resize_sequence'),
'resize_speed' => 1000 * str_replace(',', '.', \Drupal::config('lightbox2.settings')
->get('lightbox2_resize_speed')),
'fade_in_speed' => 1000 * str_replace(',', '.', \Drupal::config('lightbox2.settings')
->get('lightbox2_fadein_speed')),
'slide_down_speed' => 1000 * str_replace(',', '.', \Drupal::config('lightbox2.settings')
->get('lightbox2_slidedown_speed')),
'use_alt_layout' => \Drupal::config('lightbox2.settings')
->get('lightbox2_use_alt_layout'),
'disable_resize' => \Drupal::config('lightbox2.settings')
->get('lightbox2_disable_resize'),
'disable_zoom' => \Drupal::config('lightbox2.settings')
->get('lightbox2_disable_zoom'),
'force_show_nav' => \Drupal::config('lightbox2.settings')
->get('lightbox2_force_show_nav'),
'show_caption' => \Drupal::config('lightbox2.settings')
->get('lightbox2_show_caption'),
'loop_items' => \Drupal::config('lightbox2.settings')
->get('lightbox2_loop_items'),
'node_link_text' => \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
->get('lightbox2_node_link_text')),
'node_link_target' => \Drupal::config('lightbox2.settings')
->get('lightbox2_node_link_target'),
'image_count' => \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
->get('lightbox2_image_count_str')),
'video_count' => \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
->get('lightbox2_video_count_str')),
'page_count' => \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
->get('lightbox2_page_count_str')),
'lite_press_x_close' => t('press !x to close', array(
'!x' => '<a href="#" onclick="hideLightbox(); return FALSE;"><kbd>x</kbd></a>',
)),
'download_link_text' => '',
'enable_login' => $enable_login,
'enable_contact' => $enable_contact,
// Automatic image handling settings.
'keys_close' => \Drupal::config('lightbox2.settings')
->get('lightbox2_keys_close'),
'keys_previous' => \Drupal::config('lightbox2.settings')
->get('lightbox2_keys_previous'),
'keys_next' => \Drupal::config('lightbox2.settings')
->get('lightbox2_keys_next'),
'keys_zoom' => \Drupal::config('lightbox2.settings')
->get('lightbox2_keys_zoom'),
'keys_play_pause' => \Drupal::config('lightbox2.settings')
->get('lightbox2_keys_play_pause'),
'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' => \Drupal::config('lightbox2.settings')
->get('lightbox2_disable_nested_galleries'),
'disable_for_acidfree_gallery_lists' => \Drupal::config('lightbox2.settings')
->get('lightbox2_disable_nested_acidfree_galleries'),
'enable_acidfree_videos' => \Drupal::config('lightbox2.settings')
->get('lightbox2_enable_acidfree_videos'),
// Slideshow settings.
'slideshow_interval' => \Drupal::config('lightbox2.settings')
->get('lightbox2_slideshow_interval') * 1000,
'slideshow_automatic_start' => \Drupal::config('lightbox2.settings')
->get('lightbox2_slideshow_automatic_start'),
'slideshow_automatic_exit' => \Drupal::config('lightbox2.settings')
->get('lightbox2_slideshow_automatic_exit'),
'show_play_pause' => \Drupal::config('lightbox2.settings')
->get('lightbox2_slideshow_show_play_pause'),
'pause_on_next_click' => \Drupal::config('lightbox2.settings')
->get('lightbox2_slideshow_pause_on_next_click'),
'pause_on_previous_click' => \Drupal::config('lightbox2.settings')
->get('lightbox2_slideshow_pause_on_previous_click'),
'loop_slides' => \Drupal::config('lightbox2.settings')
->get('lightbox2_loop_slides'),
// Iframe settings.
'iframe_width' => (int) \Drupal::config('lightbox2.settings')
->get('lightbox2_default_frame_width'),
'iframe_height' => (int) \Drupal::config('lightbox2.settings')
->get('lightbox2_default_frame_height'),
'iframe_border' => (int) \Drupal::config('lightbox2.settings')
->get('lightbox2_frame_border'),
// Video settings.
'enable_video' => $enable_video,
'useragent' => $_SERVER['HTTP_USER_AGENT'],
);
if ($enable_video) {
// @FIXME
// url() expects a route name or an external URI.
// $js_settings['flvPlayer'] = url(\Drupal\Component\Utility\Html::escape(trim(variable_get('lightbox2_flv_player_path', 'flvplayer.swf'), '/')));
$js_settings['flvFlashvars'] = \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
->get('lightbox2_flv_player_flashvars'));
}
// Only supply these if the user has the correct permissions.
if (\Drupal::currentUser()
->hasPermission('download original image') && \Drupal::currentUser()
->hasPermission('view original images')) {
$js_settings['download_link_text'] = \Drupal\Component\Utility\Html::escape(\Drupal::config('lightbox2.settings')
->get('lightbox2_download_link_text'));
}
// @FIXME
// The Assets API has totally changed. CSS, JavaScript, and libraries are now
// attached directly to render arrays using the #attached property.
//
//
// @see https://www.drupal.org/node/2169605
// @see https://www.drupal.org/node/2408597
// drupal_add_js(array('lightbox2' => $js_settings), array( 'type' => 'setting' ) );
// Check where we should load the javascript files - header or footer.
$js_location = \Drupal::config('lightbox2.settings')
->get('lightbox2_js_location');
// Lightbox2 Plus.
if (!\Drupal::config('lightbox2.settings')
->get('lightbox2_lite')) {
$css = $path . '/css/lightbox.css';
if (\Drupal::config('lightbox2.settings')
->get('lightbox2_use_alt_layout')) {
$css = $path . '/css/lightbox_alt.css';
}
// @FIXME
// The Assets API has totally changed. CSS, JavaScript, and libraries are now
// attached directly to render arrays using the #attached property.
//
//
// @see https://www.drupal.org/node/2169605
// @see https://www.drupal.org/node/2408597
// 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 != '') {
// @FIXME
// The Assets API has totally changed. CSS, JavaScript, and libraries are now
// attached directly to render arrays using the #attached property.
//
//
// @see https://www.drupal.org/node/2169605
// @see https://www.drupal.org/node/2408597
// drupal_add_js($path . '/js/auto_image_handling.js', array( 'scope' => $js_location ) );
}
if (\Drupal::config('lightbox2.settings')
->get('lightbox2_enable_video')) {
// @FIXME
// The Assets API has totally changed. CSS, JavaScript, and libraries are now
// attached directly to render arrays using the #attached property.
//
//
// @see https://www.drupal.org/node/2169605
// @see https://www.drupal.org/node/2408597
// drupal_add_js($path . '/js/lightbox_video.js', array( 'scope' => $js_location ) );
}
if ($enable_login || $enable_contact) {
// @FIXME
// The Assets API has totally changed. CSS, JavaScript, and libraries are now
// attached directly to render arrays using the #attached property.
//
//
// @see https://www.drupal.org/node/2169605
// @see https://www.drupal.org/node/2408597
// drupal_add_js($path . '/js/lightbox_modal.js', array( 'scope' => $js_location ) );
}
//drupal_add_js($path .'/js/prototype.js', array( 'scope' => $js_location, 'cache' => false ) );
//drupal_add_js($path .'/js/scriptaculous.js', array( 'scope' => $js_location, 'cache' => false ) );
// @FIXME
// The Assets API has totally changed. CSS, JavaScript, and libraries are now
// attached directly to render arrays using the #attached property.
//
//
// @see https://www.drupal.org/node/2169605
// @see https://www.drupal.org/node/2408597
// drupal_add_js($path . '/js/lightbox.js', array( 'scope' => $js_location));
}
else {
$css = $path . '/css/lightbox_lite.css';
// @FIXME
// The Assets API has totally changed. CSS, JavaScript, and libraries are now
// attached directly to render arrays using the #attached property.
//
//
// @see https://www.drupal.org/node/2169605
// @see https://www.drupal.org/node/2408597
// drupal_add_css($css);
// @FIXME
// The Assets API has totally changed. CSS, JavaScript, and libraries are now
// attached directly to render arrays using the #attached property.
//
//
// @see https://www.drupal.org/node/2169605
// @see https://www.drupal.org/node/2408597
// drupal_add_js($path . '/js/lightbox_lite.js', array( 'scope' => $js_location ) );
}
}