View source
<?php
define('COLORBOX_MIN_PLUGIN_VERSION', '1.6.1');
function colorbox_theme() {
return array(
'colorbox_imagefield' => array(
'variables' => array(
'image' => array(),
'path' => NULL,
'title' => NULL,
'gid' => NULL,
),
'file' => 'colorbox.theme.inc',
),
'colorbox_insert_image' => array(
'variables' => array(
'item' => NULL,
'widget' => NULL,
),
'template' => 'colorbox-insert-image',
'pattern' => 'colorbox_insert_image__[a-z0-9_]+',
'file' => 'colorbox.theme.inc',
),
'colorbox_image_formatter' => array(
'variables' => array(
'item' => NULL,
'entity_type' => NULL,
'entity' => NULL,
'node' => NULL,
'field' => array(),
'display_settings' => array(),
'delta' => NULL,
),
'file' => 'colorbox.theme.inc',
),
);
}
function colorbox_init() {
if (!drupal_installation_attempted() && _colorbox_active()) {
_colorbox_doheader();
}
}
function colorbox_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'colorbox') . '/views',
);
}
function colorbox_libraries_info() {
$libraries['colorbox'] = array(
'name' => 'Colorbox plugin',
'vendor url' => 'http://www.jacklmoore.com/colorbox',
'download url' => 'https://github.com/jackmoore/colorbox/archive/1.x.zip',
'version arguments' => array(
'file' => 'jquery.colorbox-min.js',
'pattern' => '@(?i:Colorbox)\\sv?([0-9\\.a-z]+)@',
'lines' => 5,
),
'files' => array(
'js' => array(
'jquery.colorbox-min.js',
),
),
'variants' => array(
'minified' => array(
'files' => array(
'js' => array(
'jquery.colorbox-min.js',
),
),
),
'source' => array(
'files' => array(
'js' => array(
'jquery.colorbox.js',
),
),
),
),
);
return $libraries;
}
function colorbox_menu() {
$items = array();
$items['admin/config/media/colorbox'] = array(
'title' => 'Colorbox',
'description' => 'Adjust Colorbox settings.',
'file' => 'colorbox.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'colorbox_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
);
return $items;
}
function _colorbox_active() {
if (isset($_GET['colorbox']) && $_GET['colorbox'] == 'no') {
return FALSE;
}
$path = drupal_get_path_alias($_GET['q']);
$colorbox_pages = variable_get('colorbox_pages', "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*");
$page_match = drupal_match_path($path, $colorbox_pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $colorbox_pages);
}
$page_match = variable_get('colorbox_visibility', 0) == 0 ? !$page_match : $page_match;
drupal_alter('colorbox_active', $page_match);
return $page_match;
}
function _colorbox_doheader() {
static $already_added = FALSE;
if ($already_added) {
return;
}
if (variable_get('colorbox_custom_settings_activate', 0)) {
$js_settings = array(
'transition' => variable_get('colorbox_transition_type', 'elastic'),
'speed' => variable_get('colorbox_transition_speed', 350),
'opacity' => variable_get('colorbox_opacity', '0.85'),
'slideshow' => variable_get('colorbox_slideshow', 0) ? TRUE : FALSE,
'slideshowAuto' => variable_get('colorbox_slideshowauto', 1) ? TRUE : FALSE,
'slideshowSpeed' => variable_get('colorbox_slideshowspeed', 2500),
'slideshowStart' => variable_get('colorbox_text_start', 'start slideshow'),
'slideshowStop' => variable_get('colorbox_text_stop', 'stop slideshow'),
'current' => strip_tags(variable_get('colorbox_text_current', '{current} of {total}')),
'previous' => strip_tags(variable_get('colorbox_text_previous', '« Prev')),
'next' => strip_tags(variable_get('colorbox_text_next', 'Next »')),
'close' => strip_tags(variable_get('colorbox_text_close', 'Close')),
'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
'returnFocus' => variable_get('colorbox_returnfocus', 1) ? TRUE : FALSE,
'maxWidth' => variable_get('colorbox_maxwidth', '98%'),
'maxHeight' => variable_get('colorbox_maxheight', '98%'),
'initialWidth' => variable_get('colorbox_initialwidth', '300'),
'initialHeight' => variable_get('colorbox_initialheight', '250'),
'fixed' => variable_get('colorbox_fixed', 1) ? TRUE : FALSE,
'scrolling' => variable_get('colorbox_scrolling', 1) ? TRUE : FALSE,
'mobiledetect' => variable_get('colorbox_mobile_detect', 1) ? TRUE : FALSE,
'mobiledevicewidth' => variable_get('colorbox_mobile_device_width', '480px'),
);
}
else {
$js_settings = array(
'opacity' => '0.85',
'current' => t('{current} of {total}'),
'previous' => t('« Prev'),
'next' => t('Next »'),
'close' => t('Close'),
'maxWidth' => '98%',
'maxHeight' => '98%',
'fixed' => TRUE,
'mobiledetect' => variable_get('colorbox_mobile_detect', 1) ? TRUE : FALSE,
'mobiledevicewidth' => variable_get('colorbox_mobile_device_width', '480px'),
);
}
$js_settings['specificPagesDefaultValue'] = "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*";
$path = drupal_get_path('module', 'colorbox');
$style = variable_get('colorbox_style', 'default');
$data =& $js_settings;
drupal_alter('colorbox_settings', $data, $style);
drupal_add_js(array(
'colorbox' => $js_settings,
), array(
'type' => 'setting',
'scope' => JS_DEFAULT,
));
$variant = variable_get('colorbox_compression_type', 'minified');
if (module_exists('libraries')) {
libraries_load('colorbox', $variant);
}
drupal_add_js($path . '/js/colorbox.js');
switch ($style) {
case 'none':
break;
case 'default':
case 'plain':
case 'stockholmsyndrome':
drupal_add_css($path . '/styles/' . $style . '/colorbox_style.css');
drupal_add_js($path . '/styles/' . $style . '/colorbox_style.js');
break;
default:
drupal_add_css($style . '/colorbox.css');
}
if (variable_get('colorbox_load', 0)) {
drupal_add_js($path . '/js/colorbox_load.js');
}
if (variable_get('colorbox_inline', 0)) {
drupal_add_js($path . '/js/colorbox_inline.js');
}
$already_added = TRUE;
}
function colorbox_field_formatter_info() {
return array(
'colorbox' => array(
'label' => t('Colorbox'),
'field types' => array(
'image',
),
'settings' => array(
'colorbox_node_style' => '',
'colorbox_node_style_first' => '',
'colorbox_image_style' => '',
'colorbox_gallery' => 'post',
'colorbox_gallery_custom' => '',
'colorbox_caption' => 'auto',
'colorbox_caption_custom' => '',
'colorbox_multivalue_index' => NULL,
),
),
);
}
function colorbox_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);
$image_styles_hide = $image_styles;
$image_styles_hide['hide'] = t('Hide (do not display image)');
$element['colorbox_node_style'] = array(
'#title' => t('Content image style'),
'#type' => 'select',
'#default_value' => $settings['colorbox_node_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles_hide,
'#description' => t('Image style to use in the content.'),
);
$element['colorbox_node_style_first'] = array(
'#title' => t('Content image style for first image'),
'#type' => 'select',
'#default_value' => $settings['colorbox_node_style_first'],
'#empty_option' => t('No special style.'),
'#options' => $image_styles,
'#description' => t('Image style to use in the content for the first image.'),
);
$element['colorbox_image_style'] = array(
'#title' => t('Colorbox image style'),
'#type' => 'select',
'#default_value' => $settings['colorbox_image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#description' => t('Image style to use in the Colorbox.'),
);
$gallery = array(
'post' => t('Per post gallery'),
'page' => t('Per page gallery'),
'field_post' => t('Per field in post gallery'),
'field_page' => t('Per field in page gallery'),
'custom' => t('Custom'),
'none' => t('No gallery'),
);
$element['colorbox_gallery'] = array(
'#title' => t('Gallery (image grouping)'),
'#type' => 'select',
'#default_value' => $settings['colorbox_gallery'],
'#options' => $gallery,
'#description' => t('How Colorbox should group the image galleries.'),
);
$element['colorbox_gallery_custom'] = array(
'#title' => t('Custom gallery'),
'#type' => 'textfield',
'#maxlength' => 32,
'#default_value' => $settings['colorbox_gallery_custom'],
'#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, hyphen and underscores.'),
'#element_validate' => array(
'colorbox_gallery_custom_validate',
),
'#required' => FALSE,
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array(
'value' => 'custom',
),
),
),
);
$caption = array(
'auto' => t('Automatic'),
'title' => t('Title text'),
'alt' => t('Alt text'),
'node_title' => t('Content title'),
'custom' => t('Custom (with tokens)'),
'none' => t('None'),
);
$element['colorbox_caption'] = array(
'#title' => t('Caption'),
'#type' => 'select',
'#default_value' => $settings['colorbox_caption'],
'#options' => $caption,
'#description' => t('Automatic will use the first non-empty value of the title, the alt text and the content title.'),
);
$element['colorbox_caption_custom'] = array(
'#title' => t('Custom caption'),
'#type' => 'textfield',
'#default_value' => $settings['colorbox_caption_custom'],
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array(
'value' => 'custom',
),
),
),
);
if (module_exists('token') && ($recursion_limit = min(variable_get('token_tree_recursion_limit', 3), variable_get('colorbox_token_recursion_limit', 3)))) {
if (!empty($field)) {
$token_types = array_merge(array_keys($field['bundles']), array(
'file',
));
}
else {
$token_types = array(
$instance['entity_type'],
'file',
);
}
$element['colorbox_token'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#theme' => 'token_tree',
'#token_types' => $token_types,
'#recursion_limit' => $recursion_limit,
'#dialog' => TRUE,
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array(
'value' => 'custom',
),
),
),
);
}
else {
$element['colorbox_token'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#description' => '<strong class="error">' . t('For token support the <a href="@token_url">token module</a> must be installed.', array(
'@token_url' => 'http://drupal.org/project/token',
)) . '</strong>',
'#states' => array(
'visible' => array(
':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array(
'value' => 'custom',
),
),
),
);
}
return $element;
}
function colorbox_gallery_custom_validate($element, &$form_state) {
if (!empty($element['#value']) && !preg_match('!^[a-z0-9_-]+$!', $element['#value'])) {
form_error($element, t('%name must only contain lowercase letters, numbers, hyphen and underscores.', array(
'%name' => $element['#title'],
)));
}
}
function colorbox_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['colorbox_node_style']])) {
$summary[] = t('Content image style: @style', array(
'@style' => $image_styles[$settings['colorbox_node_style']],
));
}
elseif ($settings['colorbox_node_style'] == 'hide') {
$summary[] = t('Content image style: Hide');
}
else {
$summary[] = t('Content image style: Original image');
}
if (isset($image_styles[$settings['colorbox_node_style_first']])) {
$summary[] = t('Content image style of first image: @style', array(
'@style' => $image_styles[$settings['colorbox_node_style_first']],
));
}
if (isset($image_styles[$settings['colorbox_image_style']])) {
$summary[] = t('Colorbox image style: @style', array(
'@style' => $image_styles[$settings['colorbox_image_style']],
));
}
else {
$summary[] = t('Colorbox image style: Original image');
}
$gallery = array(
'post' => t('Per post gallery'),
'page' => t('Per page gallery'),
'field_post' => t('Per field in post gallery'),
'field_page' => t('Per field in page gallery'),
'custom' => t('Custom'),
'none' => t('No gallery'),
);
if (isset($settings['colorbox_gallery'])) {
$summary[] = t('Colorbox gallery type: @type', array(
'@type' => $gallery[$settings['colorbox_gallery']],
)) . ($settings['colorbox_gallery'] == 'custom' ? ' (' . $settings['colorbox_gallery_custom'] . ')' : '');
}
$caption = array(
'auto' => t('Automatic'),
'title' => t('Title text'),
'alt' => t('Alt text'),
'node_title' => t('Content title'),
'custom' => t('Custom (with tokens)'),
'none' => t('None'),
);
if (isset($settings['colorbox_caption'])) {
$summary[] = t('Colorbox caption: @type', array(
'@type' => $caption[$settings['colorbox_caption']],
));
}
return implode('<br />', $summary);
}
function colorbox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$index = $display['settings']['colorbox_multivalue_index'];
foreach ($items as $delta => $item) {
if ($index === NULL || $index === $delta) {
$element[$delta] = array(
'#theme' => 'colorbox_image_formatter',
'#item' => $item,
'#entity_type' => $entity_type,
'#entity' => $entity,
'#node' => $entity,
'#field' => $field,
'#display_settings' => $display['settings'],
'#delta' => $delta,
);
}
}
return $element;
}
function colorbox_insert_styles() {
$insert_styles = array();
foreach (image_styles() as $key => $style) {
$label = isset($style['label']) ? $style['label'] : $style['name'];
$insert_styles['colorbox__' . $key] = array(
'label' => t('Colorbox @style', array(
'@style' => $label,
)),
);
}
return $insert_styles;
}
function colorbox_help($path, $arg) {
switch ($path) {
case 'admin/help#colorbox':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('<a target="_blank" href="@colorbox_project_link">Colorbox</a> is a light-weight customizable lightbox plugin for jQuery. This module allows for integration of Colorbox into Drupal.', array(
'@colorbox_project_link' => 'https://www.drupal.org/project/colorbox',
)) . '</p>';
$output .= '<p>' . t('Images, iframed or inline content etc. can be displayed in a overlay above the current page.') . '</p>';
$output .= '<h3>' . t('Usage') . '</h3>';
$output .= '<p>' . t('Go to "Configuration" » "Media" » "Colorbox" to find all the configuration options.') . '</p>';
$output .= '<h3>' . t('Features') . '</h3>';
$output .= '<b>' . t('The Colorbox:') . '</b>';
$output .= '<ul>';
$output .= '<li>' . t('Excellent integration with Image field and Image styles') . '</li>';
$output .= '<li>' . t('Choose between a default style and 5 example styles that are included.') . '</li>';
$output .= '<li>' . t('Style the Colorbox with a custom colorbox.css file in your theme.') . '</li>';
$output .= '<li>' . t('Drush command to download and install the Colorbox plugin in sites/all/libraries') . '</li>';
$output .= '</ul>';
$output .= '<b>' . t('The Colorbox plugin:') . '</b>';
$output .= '<ul>';
$output .= '<li>' . t('Supports photos, grouping, slideshow, ajax, inline, and iframed content.') . '</li>';
$output .= '<li>' . t('Appearance is controlled through CSS so it can be restyled.') . '</li>';
$output .= '<li>' . t('Preloads upcoming images in a photo group.') . '</li>';
$output .= '<li>' . t('Completely unobtrusive, options are set in the JS and require no') . '</li>';
$output .= '<li>' . t('changes to existing HTML.') . '</li>';
$output .= '<li>' . t('Compatible with: jQuery 1.3.2+ in Firefox, Safari, Chrome, Opera,') . '</li>';
$output .= '<li>' . t('Internet Explorer 7+.') . '</li>';
$output .= '<li>' . t('Released under the MIT License.') . '</p>';
$output .= '</ul>';
$output .= '<h3>' . t('Colorbox screencasts') . '</h3>';
$output .= '<b>' . t('Part 1 to 3 is for an older 7.x-1.x version of the Colorbox:') . '</b>';
$output .= '<ul>';
$output .= '<li>' . t('Part 1: <a href="@colorbox_screencasts_part1" target="blank">Installation and image field integration on Vimeo</a>', array(
'@colorbox_screencasts_part1' => 'https://vimeo.com/19122850',
)) . '</li>';
$output .= '<li>' . t('Part 2: <a href="@colorbox_screencasts_part2" target="blank">Inline images with the Insert module on Vimeo</a>', array(
'@colorbox_screencasts_part2' => 'https://vimeo.com/19386122',
)) . '</li>';
$output .= '<li>' . t('Part 3: <a href="@colorbox_screencasts_part3" target="blank">Building a image gallery and a image slideshow.</a>', array(
'@colorbox_screencasts_part3' => 'https://vimeo.com/26411524',
)) . '</li>';
$output .= '</ul>';
$output .= '<b>' . t('Contributed screencasts:') . '</b>';
$output .= '<ul>';
$output .= '<li>' . t('<a href="@colorbox_contributed_screencasts_part1" target="blank">Drupal 7 Colorbox project</a> by Code Karate', array(
'@colorbox_contributed_screencasts_part1' => 'http://codekarate.com/daily-dose-of-drupal/drupal-7-colorbox-module',
)) . '</li>';
$output .= '<li>' . t('<a href="@colorbox_contributed_screencasts_part2" target="blank">Creating and Theming a Node Photo Gallery with Drupal 7 and Colorbox</a> by High Rock Media.', array(
'@colorbox_contributed_screencasts_part2' => 'http://dannyenglander.com/blog/screencast-creating-and-theming-node-photo-gallery-drupal-7-and-colorbox',
)) . '</li>';
$output .= '<li>' . t('<a href="@colorbox_contributed_screencasts_part3" target="blank">How to Build a Lightbox Portfolio in Drupal 7</a> by CMS Quickstart', array(
'@colorbox_contributed_screencasts_part3' => 'http://www.cmsquickstart.com/blog/tutorial-how-build-lightbox-portfolio-drupal-7',
)) . '</li>';
$output .= '</ul>';
$output .= '<h3>' . t('Load Content in a Colorbox') . '</h3>';
$output .= '<p>' . t('Check the "Enable Colorbox load" option in Colorbox settings.') . '</p>';
$output .= '<p>' . t('This enables custom links that can open content in a Colorbox.') . '</p>';
$output .= '<p>' . t('Add the class "colorbox-load" to the link and build the url like this "[path]?width=500&height=500&iframe=true" or "[path]?width=500&height=500" if you don\'t want an iframe.') . '</p>';
$output .= '<p>' . t('Other projects may activate this for easy Colorbox integration.') . '</p>';
$output .= '<h3>' . t('Load Images from custom links in a Colorbox') . '</h3>';
$output .= '<p>' . t('Add the class "colorbox" to the link and point its href attribute to the image you want to display in the Colorbox.') . '</p>';
return $output;
}
}
function colorbox_insert_content($item, $style, $widget) {
list($item['module_name'], $item['style_name']) = explode('__', $style['name'], 2);
return theme(array(
'colorbox_insert_image__' . str_replace('-', '_', $item['style_name']),
'colorbox_insert_image',
), array(
'item' => $item,
'widget' => $widget,
));
}
function colorbox_gallery_exists() {
return FALSE;
}