View source
<?php
define('SHADOWBOX_DEFAULT_PATH', 'sites/all/libraries/shadowbox');
define('SHADOWBOX_ACTIVATION_NOTLISTED', 0);
define('SHADOWBOX_ACTIVATION_LISTED', 1);
define('SHADOWBOX_ACTIVATION_PHP', 2);
function shadowbox_library() {
$shadowbox_location = variable_get('shadowbox_location', SHADOWBOX_DEFAULT_PATH);
$libraries['shadowbox'] = array(
'title' => 'Shadowbox',
'website' => 'http://www.shadowbox-js.com/',
'version' => '3.0.3',
'js' => array(
$shadowbox_location . '/shadowbox.js' => array(),
array(
'type' => 'setting',
'data' => _shadowbox_get_settings(),
),
array(
'type' => 'inline',
'scope' => 'header',
'group' => JS_THEME,
'data' => '
Shadowbox.path = "' . base_path() . $shadowbox_location . '/";
',
),
drupal_get_path('module', 'shadowbox') . '/shadowbox_auto.js' => array(),
),
'css' => array(
variable_get('shadowbox_location', SHADOWBOX_DEFAULT_PATH) . '/shadowbox.css' => array(
'type' => 'file',
'media' => 'screen',
),
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; }
',
),
),
);
return $libraries;
}
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_menu() {
$items = array();
$items['admin/config/media/shadowbox'] = array(
'title' => 'Shadowbox',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'shadowbox_global_settings',
),
'access arguments' => array(
'administer shadowbox',
),
'description' => 'Configure the settings for Shadowbox.',
'file' => 'shadowbox.admin.inc',
);
$items['admin/config/media/shadowbox/global'] = array(
'title' => 'Global',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'shadowbox_global_settings',
),
'access arguments' => array(
'administer shadowbox',
),
'description' => 'Configure the settings for Shadowbox.',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
'file' => 'shadowbox.admin.inc',
);
$items['admin/config/media/shadowbox/automatic'] = array(
'title' => 'Auto handling',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'shadowbox_automatic_settings',
),
'access arguments' => array(
'administer shadowbox',
),
'description' => 'Configure the Shadowbox automatic image handling settings.',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
'file' => 'shadowbox.admin.inc',
);
return $items;
}
function shadowbox_init() {
_shadowbox_construct_header();
}
function shadowbox_theme() {
return array(
'shadowbox_formatter' => array(
'variables' => array(
'itemid' => NULL,
'item' => NULL,
'image_style' => "thumbnail",
'image_link' => "",
'gallery' => "",
'compact' => 0,
'title' => "",
),
),
);
}
function _shadowbox_construct_header() {
$shadowbox_enabled = variable_get('shadowbox_enabled', TRUE);
$shadowbox_auto = variable_get('shadowbox_auto_enable_all_images', 0);
$shadowbox_enable_globally = variable_get('shadowbox_enable_globally', TRUE);
if ($shadowbox_enabled && ($shadowbox_auto || $shadowbox_enable_globally) && _shadowbox_activation()) {
drupal_add_library('shadowbox', 'shadowbox');
}
}
function _shadowbox_add_css($file) {
drupal_add_css(drupal_get_path('module', 'shadowbox') . '/' . $file);
}
function _shadowbox_add_js($file) {
drupal_add_js(drupal_get_path('module', 'shadowbox') . '/' . $file);
}
function _shadowbox_library_add_js($file) {
drupal_add_js(variable_get('shadowbox_location', SHADOWBOX_DEFAULT_PATH) . '/' . $file);
}
function _shadowbox_library_add_css($file) {
drupal_add_css(variable_get('shadowbox_location', SHADOWBOX_DEFAULT_PATH) . '/' . $file);
}
function _shadowbox_get_settings($override = array()) {
global $language;
$settings = array(
'animate' => variable_get('shadowbox_animate', TRUE),
'animateFade' => variable_get('shadowbox_animate_fade', TRUE),
'animSequence' => variable_get('shadowbox_animation_sequence', 'wh'),
'auto_enable_all_images' => variable_get('shadowbox_auto_enable_all_images', 0),
'auto_gallery' => variable_get('shadowbox_auto_gallery', 0),
'autoplayMovies' => variable_get('shadowbox_autoplay_movies', 1) === 1 ? TRUE : FALSE,
'continuous' => variable_get('shadowbox_continuous_galleries', FALSE),
'counterLimit' => variable_get('shadowbox_counter_limit', 10),
'counterType' => variable_get('shadowbox_counter_type', 'default'),
'displayCounter' => variable_get('shadowbox_display_counter', TRUE),
'displayNav' => variable_get('shadowbox_display_nav', TRUE),
'enableKeys' => variable_get('shadowbox_enable_keys', TRUE),
'fadeDuration' => variable_get('shadowbox_fade_duration', 0.35),
'handleOversize' => variable_get('shadowbox_handle_oversize', 'resize'),
'handleUnsupported' => variable_get('shadowbox_handle_unsupported', 'link'),
'initialHeight' => variable_get('shadowbox_initial_height', 160),
'initialWidth' => variable_get('shadowbox_initial_width', 320),
'language' => $language->language,
'modal' => !variable_get('shadowbox_overlay_listen', TRUE),
'overlayColor' => '#' . variable_get('shadowbox_overlay_color', '000'),
'overlayOpacity' => variable_get('shadowbox_overlay_opacity', 0.8),
'resizeDuration' => variable_get('shadowbox_resize_duration', 0.55),
'showMovieControls' => variable_get('shadowbox_show_movie_controls', TRUE),
'slideshowDelay' => variable_get('shadowbox_slideshow_delay', 0),
'viewportPadding' => variable_get('shadowbox_viewport_padding', 20),
'useSizzle' => variable_get('shadowbox_use_sizzle', FALSE),
);
$settings = array_merge($settings, $override);
$settings = array(
'shadowbox' => $settings,
);
return $settings;
}
function _shadowbox_activation() {
$pages = variable_get('shadowbox_pages', "admin*\nimg_assist*\nnode/add/*\nnode/*/edit");
$activation = variable_get('shadowbox_activation_type', SHADOWBOX_ACTIVATION_NOTLISTED);
if ($pages) {
$lowercase_pages = drupal_strtolower($pages);
if ($activation < SHADOWBOX_ACTIVATION_PHP) {
$path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
$page_match = drupal_match_path($path, $lowercase_pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $lowercase_pages);
}
$page_match = !($activation xor $page_match);
}
elseif (module_exists('php')) {
$page_match = php_eval($pages);
}
else {
$page_match = FALSE;
}
}
else {
$page_match = TRUE;
}
return $page_match;
}
function shadowbox_field_formatter_info() {
$formatters = array(
'shadowbox' => array(
'label' => t('Shadowbox'),
'field types' => array(
'image',
),
'settings' => array(
'image_style' => '',
'image_link' => '',
'gallery' => '',
'compact' => '',
'title' => '',
),
),
);
return $formatters;
}
function shadowbox_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$image_styles = image_style_options(FALSE);
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
);
$element['image_link'] = array(
'#title' => t('Link image to'),
'#type' => 'select',
'#default_value' => $settings['image_link'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
);
$gallery_options = array(
'page' => 'gallery page',
'field' => 'gallery field',
'nid' => 'gallery entity',
);
$element['gallery'] = array(
'#title' => t('gallery'),
'#type' => 'select',
'#default_value' => $settings['gallery'],
'#empty_option' => t('None (individual)'),
'#options' => $gallery_options,
);
$element['compact'] = array(
'#title' => t('compact'),
'#type' => 'checkbox',
'#default_value' => $settings['compact'],
);
$title_options = array(
'title' => 'image title',
'alt' => 'image alt',
'node' => 'node title',
);
$element['title'] = array(
'#title' => t('title'),
'#type' => 'select',
'#default_value' => $settings['title'],
'#empty_option' => t('None'),
'#options' => $title_options,
);
return $element;
}
function shadowbox_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = array();
$image_styles = image_style_options(FALSE);
unset($image_styles['']);
if (isset($image_styles[$settings['image_style']])) {
$summary[] = t('Image style: @style', array(
'@style' => $image_styles[$settings['image_style']],
));
}
else {
$summary[] = t('Original image');
}
if (isset($image_styles[$settings['image_link']])) {
$summary[] = t('Linked to: @style', array(
'@style' => $image_styles[$settings['image_link']],
));
}
else {
$summary[] = t('Linked to: Original image');
}
$gallery_options = array(
'page' => 'gallery page',
'field' => 'gallery field',
'nid' => 'gallery entity',
);
if (isset($gallery_options[$settings['gallery']])) {
$summary[] = t('as @gallery', array(
'@gallery' => (isset($settings['compact']) && $settings['compact'] ? 'compact ' : '') . $gallery_options[$settings['gallery']],
));
}
$title_options = array(
'title' => 'image title',
'alt' => 'image alt',
'node' => 'node title',
);
if (isset($title_options[$settings['title']])) {
$summary[] = t('with @title as title', array(
'@title' => $title_options[$settings['title']],
));
}
return implode('<br />', $summary);
}
function shadowbox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$shadowbox_enabled_path = _shadowbox_activation() && variable_get('shadowbox_enabled', TRUE);
switch ($display['settings']['gallery']) {
case 'page':
$gallery_id = 'gallery';
break;
case 'field':
$gallery_id = $field['field_name'];
break;
case 'nid':
$info = entity_get_info($entity_type);
$id = $info['entity keys']['id'];
$gallery_id = "{$entity_type}-{$entity->{$id}}";
break;
default:
$gallery_id = "";
break;
}
foreach ($items as $delta => $item) {
switch ($display['settings']['title']) {
case 'alt':
$title = $item['alt'];
break;
case 'title':
$title = $item['title'];
break;
case 'node':
$title = $entity->title;
break;
default:
$title = '';
break;
}
$element[$delta] = array(
'#theme' => 'shadowbox_formatter',
'#itemid' => $delta,
'#item' => $item,
'#image_style' => $display['settings']['image_style'],
'#image_link' => $display['settings']['image_link'],
'#gallery' => $gallery_id,
'#compact' => $display['settings']['compact'],
'#title' => $title,
);
if ($shadowbox_enabled_path) {
$element[$delta]['#attached']['library'][] = array(
'shadowbox',
'shadowbox',
);
}
}
return $element;
}
function theme_shadowbox_formatter($variables) {
$item = $variables['item'];
$image = array(
'path' => $item['uri'],
'alt' => $item['alt'],
);
if (drupal_strlen($item['title']) > 0) {
$image['title'] = $item['title'];
}
$image_style = $variables['image_style'];
if ($variables['itemid'] == 0 || isset($variables['compact']) && !$variables['compact']) {
if ($image_style) {
$image['style_name'] = $image_style;
$image['attributes'] = array(
'class' => 'image-' . $image_style,
);
$output = theme('image_style', $image);
}
else {
$output = theme('image', $image);
}
}
else {
$output = "";
}
$linked_style = $variables['image_link'];
if ($linked_style) {
$path = image_style_url($linked_style, $item['uri']);
}
else {
$path = $item['uri'];
}
$gallery_id = $variables['gallery'];
$rel = $gallery_id != '' ? "shadowbox[{$gallery_id}]" : 'shadowbox';
$link_attributes = array(
'rel' => $rel,
'title' => $variables['title'],
);
$options = array(
'attributes' => $link_attributes,
'html' => TRUE,
);
$output = l($output, file_create_url($path), $options);
$wrapper_classes = $gallery_id != '' ? "sb-image sb-gallery sb-gallery-{$gallery_id}" : 'sb-image sb-individual';
return '<div class="' . $wrapper_classes . '"' . ($variables['itemid'] == 0 || isset($variables['compact']) && !$variables['compact'] ? '' : 'style="display:none;') . '>' . $output . '</div>';
}