View source
<?php
define('SHADOWBOX_DEFAULT_PATH', 'libraries/shadowbox');
define('SHADOWBOX_ACTIVATION_NOTLISTED', 0);
define('SHADOWBOX_ACTIVATION_LISTED', 1);
define('SHADOWBOX_ACTIVATION_PHP', 2);
function shadowbox_help($path, $arg) {
switch ($path) {
case 'admin/help#shadowbox':
return t('
<p>Shadowbox is a modal media viewer application akin to !lightbox and !thickbox. You can use it to display images, movies, and other web content in a window that is overlaid on top of the page.</p>
<p>The module is integrated with filefield\'s image element so you can select from a number of different options for displaying images uploaded to nodes and shown in views.</p>
<p>For instructions on manually crafting your links please see the !usage.</p>
<p>This module has !options that work on a site-wide basis.</p>', array(
'!lightbox' => l('lightbox2', 'http://drupal.org/project/lightbox2'),
'!thickbox' => l('thickbox', 'http://drupal.org/project/thickbox'),
'!options' => l('options', 'admin/settings/shadowbox'),
'!usage' => l('official usage guide', 'http://www.shadowbox-js.com/usage.html#markup'),
));
case 'admin/settings/shadowbox':
return t('<p>This page provides access to the Shadowbox settings. The settings here work globally so any changes made here will affect Shadowbox for the entire site.</p>');
}
}
function shadowbox_permission() {
return array(
'administer shadowbox' => array(
'title' => t('Administer shadowbox'),
'description' => t('Perform administration tasks for shadowbox.'),
),
);
}
function shadowbox_page_build(&$page) {
$shb_enabled = \Drupal::config('shadowbox.settings')
->get('shadowbox_enabled');
$shb_auto = \Drupal::config('shadowbox.automatic')
->get('shadowbox_auto_enable_all_images');
$shb_enable_globally = \Drupal::config('shadowbox.automatic')
->get('shadowbox_enable_globally');
if ($shb_enabled && ($shb_auto || $shb_enable_globally) && _shadowbox_activation()) {
$page['#attached']['library'][] = 'shadowbox/shadowbox';
}
}
function shadowbox_library_alter(array &$library, $name, $theme = NULL) {
if ($name == 'shadowbox/shadowbox') {
$shadowbox_location = \Drupal::config('shadowbox.settings')
->get('shadowbox_location');
$library['js'][] = array(
'type' => 'setting',
'data' => _shadowbox_get_settings(),
);
$library['js'][] = array(
'type' => 'inline',
'scope' => 'header',
'group' => JS_THEME,
'data' => 'Shadowbox.path = "' . base_path() . $shadowbox_location . '/";',
);
$library['css'][] = array(
'type' => 'inline',
'media' => 'print',
'data' => '
#sb-container { position: relative; }
#sb-overlay { display: none; }
#sb-wrapper { position: relative; top: 0; left: 0; }
#sb-loading { display: none; }
',
);
if ($library['js'][0]['data'] != $shadowbox_location . '/shadowbox.js') {
$library['js'][0]['data'] = $shadowbox_location . '/shadowbox.js';
}
if ($library['css'][0]['data'] != $shadowbox_location . '/shadowbox.css') {
$library['css'][0]['data'] = $shadowbox_location . '/shadowbox.css';
}
}
}
function _shadowbox_get_settings($override = array()) {
$config = \Drupal::config('shadowbox.settings');
$config_automatic = \Drupal::config('shadowbox.automatic');
$settings = array(
'animate' => $config
->get('shadowbox_animate'),
'animateFade' => $config
->get('shadowbox_animate_fade'),
'animSequence' => $config
->get('shadowbox_animation_sequence'),
'auto_enable_all_images' => $config_automatic
->get('shadowbox_auto_enable_all_images'),
'auto_gallery' => $config_automatic
->get('shadowbox_auto_gallery'),
'autoplayMovies' => $config
->get('shadowbox_autoplay_movies'),
'continuous' => $config
->get('shadowbox_continuous_galleries'),
'counterLimit' => $config
->get('shadowbox_counter_limit'),
'counterType' => $config
->get('shadowbox_counter_type'),
'displayCounter' => $config
->get('shadowbox_display_counter'),
'displayNav' => $config
->get('shadowbox_display_nav'),
'enableKeys' => $config
->get('shadowbox_enable_keys'),
'fadeDuration' => $config
->get('shadowbox_fade_duration'),
'handleOversize' => $config
->get('shadowbox_handle_oversize'),
'handleUnsupported' => $config
->get('shadowbox_handle_unsupported'),
'initialHeight' => $config
->get('shadowbox_initial_height'),
'initialWidth' => $config
->get('shadowbox_initial_width'),
'modal' => $config
->get('shadowbox_overlay_listen'),
'overlayColor' => '#' . $config
->get('shadowbox_overlay_color'),
'overlayOpacity' => $config
->get('shadowbox_overlay_opacity'),
'resizeDuration' => $config
->get('shadowbox_resize_duration'),
'showMovieControls' => $config
->get('shadowbox_show_movie_controls'),
'slideshowDelay' => $config
->get('shadowbox_slideshow_delay'),
'viewportPadding' => $config
->get('shadowbox_viewport_padding'),
'useSizzle' => $config
->get('shadowbox_use_sizzle'),
'language' => \Drupal::languageManager()
->getCurrentLanguage()->id,
);
$settings = array_merge($settings, $override);
$settings = array(
'shadowbox' => $settings,
);
return $settings;
}
function _shadowbox_activation() {
$config = \Drupal::config('shadowbox.settings');
$pages = $config
->get('shadowbox_pages');
$activation = $config
->get('shadowbox_activation_type');
if ($pages) {
$lowercase_pages = drupal_strtolower($pages);
if ($activation < SHADOWBOX_ACTIVATION_PHP) {
$current_path = current_path();
$path_alias = \Drupal::service('path.alias_manager.cached')
->getPathByAlias($current_path);
$path = drupal_strtolower($path_alias);
$page_match = drupal_match_path($path, $lowercase_pages);
if ($path != $current_path) {
$page_match = $page_match || drupal_match_path($current_path, $lowercase_pages);
}
$page_match = !($activation xor $page_match);
}
elseif (\Drupal::moduleHandler()
->moduleExists('php')) {
$page_match = php_eval($pages);
}
else {
$page_match = FALSE;
}
}
else {
$page_match = TRUE;
}
return $page_match;
}
function shadowbox_theme() {
return array(
'shadowbox_formatter' => array(
'variables' => array(
'innerHTML' => '',
'url' => '',
'rel' => '',
'title' => '',
'class' => '',
),
),
'shadowbox_thumbnail' => array(
'variables' => array(
'path' => '',
'image_style' => '',
'attributes' => '',
'title' => '',
'alt' => '',
),
),
);
}
function theme_shadowbox_formatter($variables) {
$output = $variables['innerHTML'];
$link_attributes = array(
'rel' => $variables['rel'],
'title' => $variables['title'],
);
$options = array(
'attributes' => $link_attributes,
'html' => TRUE,
);
$output = l($output, $variables['url'], $options);
$output = '<div class="' . $variables['class'] . '"' . ($variables['innerHTML'] == '' ? ' style="display:none;"' : '') . '>' . $output . '</div>';
return $output;
}
function theme_shadowbox_thumbnail($variables) {
$image_style = $variables['image_style'];
if ($image_style) {
$output = array(
'#theme' => 'image_style',
'#style_name' => $image_style,
'#uri' => $variables['path'],
'#alt' => $variables['alt'] ? $variables['alt'] : $variables['title'],
'#title' => $variables['title'],
'#attributes' => array(
'class' => array(
'image-' . $image_style,
),
),
);
}
else {
$output = array(
'#theme' => 'image',
'#uri' => $variables['path'],
'#alt' => $variables['alt'] ? $variables['alt'] : $variables['title'],
'#title' => $variables['title'],
'#attributes' => $variables['attributes'],
);
}
return drupal_render($output);
}