View source
<?php
define('COLORBOX_PATH', 'sites/all/libraries/colorbox');
define('COLORBOX_MIN_PLUGIN_VERSION', '1.3.18');
define('COLORBOX_MIN_JQUERY_VERSION', '1.3.1');
define('COLORBOX_MAX_JQUERY_VERSION', '1.4+');
function colorbox_theme() {
$theme = array(
'colorbox_imagefield' => array(
'arguments' => array(
'namespace' => NULL,
'path' => NULL,
'alt' => NULL,
'title' => NULL,
'gid' => NULL,
'field_name' => NULL,
'attributes' => NULL,
),
'file' => 'colorbox.theme.inc',
),
'colorbox_insert_image' => array(
'arguments' => array(
'item' => NULL,
'widget' => NULL,
),
'template' => 'colorbox-insert-image',
'file' => 'colorbox.theme.inc',
),
);
if (module_exists('imagecache')) {
foreach (imagecache_presets() as $preset) {
$theme['colorbox_formatter_' . $preset['presetname'] . '__colorbox'] = array(
'function' => 'theme_colorbox_formatter_imagefield',
'arguments' => array(
'element' => NULL,
),
'file' => 'colorbox.theme.inc',
);
}
}
return $theme;
}
function colorbox_init() {
if (defined('MAINTENANCE_MODE') && (MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update')) {
return;
}
_colorbox_doheader();
}
function colorbox_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'colorbox') . '/views',
);
}
function colorbox_menu() {
$items = array();
$items['admin/settings/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',
),
);
$items['user/login/colorbox'] = array(
'title' => 'Login',
'page callback' => 'colorbox_login',
'access callback' => 'user_is_anonymous',
'type' => MENU_CALLBACK,
'file' => 'colorbox.pages.inc',
);
$items['colorbox/form'] = array(
'title' => 'Form',
'page callback' => 'colorbox_form_page',
'page arguments' => array(
2,
),
'access callback' => '_colorbox_form_page_access',
'access arguments' => array(
2,
),
'type' => MENU_CALLBACK,
'file' => 'colorbox.pages.inc',
);
return $items;
}
function _colorbox_form_page_access($form_id) {
$access = FALSE;
switch ($form_id) {
case 'contact_mail_page':
$access = user_access('access site-wide contact form');
break;
case 'user_register':
$access = user_register_access();
break;
case 'user_pass':
case 'user_login':
case 'user_login_block':
$access = user_is_anonymous();
break;
}
if (!$access) {
foreach (module_implements('colorbox_form_access') as $module) {
if ($access = module_invoke($module, 'colorbox_form_access', $form_id)) {
return $access;
}
}
}
return $access;
}
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*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit");
$page_match = drupal_match_path($path, $colorbox_pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $colorbox_pages);
}
return !$page_match;
}
function _colorbox_doheader() {
static $already_added = FALSE;
if ($already_added) {
return;
}
if (!_colorbox_active()) {
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.9'),
'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' => variable_get('colorbox_text_current', '{current} of {total}'),
'previous' => variable_get('colorbox_text_previous', '« Prev'),
'next' => variable_get('colorbox_text_next', 'Next »'),
'close' => variable_get('colorbox_text_close', 'Close'),
'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
'maxWidth' => variable_get('colorbox_maxwidth', '100%'),
'maxHeight' => variable_get('colorbox_maxheight', '100%'),
);
}
else {
$js_settings = array(
'transition' => 'elastic',
'speed' => 350,
'opacity' => '0.85',
'slideshow' => FALSE,
'slideshowAuto' => FALSE,
'slideshowSpeed' => 2500,
'slideshowStart' => '',
'slideshowStop' => '',
'current' => t('{current} of {total}'),
'previous' => t('« Prev'),
'next' => t('Next »'),
'close' => t('Close'),
'overlayClose' => TRUE,
'maxWidth' => '100%',
'maxHeight' => '100%',
);
}
$path = drupal_get_path('module', 'colorbox');
$style = variable_get('colorbox_style', 'default');
$data =& $js_settings;
$data['__drupal_alter_by_ref'] = array(
&$style,
);
drupal_alter('colorbox_settings', $data);
drupal_add_js(array(
'colorbox' => $js_settings,
), 'setting');
if (module_exists('image') && variable_get('colorbox_auto_image_nodes', 0)) {
$image_derivative = variable_get('colorbox_image_derivative', 'preview');
if (!($image_derivative == IMAGE_ORIGINAL && !user_access('view original images'))) {
drupal_add_js(array(
'colorbox' => array(
'image_derivative' => $image_derivative,
),
), 'setting');
drupal_add_js($path . '/js/colorbox_image_module.js');
}
}
if (module_exists('img_assist') && variable_get('colorbox_auto_img_assist_custom', 0)) {
$img_assist_derivative = variable_get('colorbox_img_assist_derivative', 'preview');
if (!($img_assist_derivative == IMAGE_ORIGINAL && !user_access('view original images'))) {
drupal_add_js(array(
'colorbox' => array(
'img_assist_derivative' => $img_assist_derivative,
),
), 'setting');
drupal_add_js($path . '/js/colorbox_img_assist_module.js');
}
}
drupal_add_js(colorbox_get_js());
drupal_add_js($path . '/js/colorbox.js');
switch ($style) {
case 'none':
break;
case 'default':
drupal_add_css($path . '/styles/default/colorbox_default_style.css');
drupal_add_js($path . '/styles/default/colorbox_default_style.js');
break;
case 'stockholmsyndrome':
drupal_add_css($path . '/styles/stockholmsyndrome/colorbox_stockholmsyndrome.css');
drupal_add_js($path . '/styles/stockholmsyndrome/colorbox_stockholmsyndrome.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');
}
if ($GLOBALS['user']->uid == 0 && variable_get('colorbox_login', 0)) {
drupal_add_js($path . '/js/colorbox_login.js');
}
$already_added = TRUE;
}
function colorbox_get_version($colorbox_js = NULL) {
$version = 0;
$pattern = '#ColorBox v([0-9\\.a-z]+)#';
if (is_null($colorbox_js)) {
$colorbox_js = colorbox_get_js();
}
if (file_exists($colorbox_js)) {
$colorbox_plugin = file_get_contents($colorbox_js, NULL, NULL, 0, 32);
if (preg_match($pattern, $colorbox_plugin, $matches)) {
$version = $matches[1];
}
}
return $version;
}
function colorbox_get_js() {
$library_path = colorbox_get_path();
if (file_exists($library_path . '/colorbox/jquery.colorbox.js') && file_exists($library_path . '/colorbox/jquery.colorbox-min.js')) {
$colorbox_js_map = array(
'none' => 'jquery.colorbox.js',
'min' => 'jquery.colorbox-min.js',
);
$colorbox_js = $colorbox_js_map[variable_get('colorbox_compression_type', 'min')];
return $library_path . '/colorbox/' . $colorbox_js;
}
}
function colorbox_get_path() {
static $library_path = NULL;
if ($library_path == NULL) {
$path = variable_get('colorbox_path', COLORBOX_PATH);
if (is_dir($path . '/colorbox')) {
$library_path = $path;
}
elseif ($library_path == NULL && module_exists('libraries')) {
if ($path = libraries_get_path('colorbox')) {
$library_path = $path;
variable_set('colorbox_path', $library_path);
}
}
elseif ($library_path == NULL) {
$library_path = COLORBOX_PATH;
}
}
return $library_path;
}
function colorbox_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_login':
if (arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'colorbox') {
$form['name']['#size'] = 25;
$form['pass']['#size'] = 25;
if (variable_get('colorbox_login_links', 0)) {
$items = array();
if (variable_get('colorbox_login_links', 0) == 1) {
if (variable_get('user_register', 1)) {
$items[] = l(t('Create new account'), 'user/register', array(
'attributes' => array(
'title' => t('Create a new user account.'),
),
));
}
$items[] = l(t('Request new password'), 'user/password', array(
'attributes' => array(
'title' => t('Request new password via e-mail.'),
),
));
}
if (variable_get('colorbox_login_links', 0) == 2) {
if (variable_get('user_register', 1)) {
$items[] = l(t('Create new account'), 'colorbox/form/user_register', array(
'query' => 'width=300&height=auto',
'attributes' => array(
'title' => t('Create a new user account.'),
'class' => 'colorbox-load',
),
));
}
$items[] = l(t('Request new password'), 'colorbox/form/user_pass', array(
'query' => 'width=300&height=150',
'attributes' => array(
'title' => t('Request new password via e-mail.'),
'class' => 'colorbox-load',
),
));
}
$form['links'] = array(
'#value' => theme('item_list', $items),
);
}
}
break;
case 'user_register':
if (arg(0) == 'colorbox' && arg(1) == 'form') {
$form['name']['#size'] = 30;
$form['mail']['#size'] = 30;
}
break;
case 'user_pass':
if (arg(0) == 'colorbox' && arg(1) == 'form') {
$form['name']['#size'] = 30;
}
break;
}
}
function colorbox_link_alter(&$links, $node) {
if ($node->type == 'image' && is_array($node->images) && variable_get('colorbox_auto_image_nodes', 0)) {
foreach ($node->images as $size => $path) {
$links['image_size_' . $size]['attributes']['class'] = "image image-{$size} colorbox";
$links['image_size_' . $size]['href'] = $path;
unset($links['image_size_' . $size]['query']);
}
}
}
function colorbox_field_formatter_info() {
$formatters = array();
if (module_exists('imagefield') && module_exists('imagecache')) {
foreach (imagecache_presets() as $preset) {
$formatters[$preset['presetname'] . '__colorbox'] = array(
'label' => t('Colorbox: @preset image', array(
'@preset' => $preset['presetname'],
)),
'field types' => array(
'image',
'filefield',
),
);
}
}
return $formatters;
}
function colorbox_insert_styles() {
$insert_styles = array();
$insert_styles = colorbox_field_formatter_info();
return $insert_styles;
}
function colorbox_insert_content($item, $style, $widget) {
list($item['presetname'], $item['modulename']) = explode('__', $style['name'], 2);
return theme('colorbox_insert_image', $item, $widget);
}