Commit 9545c18b authored by frjo's avatar frjo
Browse files

Improving the requirement checks. Now reports the Colorbox plugin version on...

Improving the requirement checks. Now reports the Colorbox plugin version on the status page. Added colorbox_get_version() and colorbox_get_path() functions modeled on jQuery Update.
parent a775aaa0
......@@ -4,31 +4,37 @@
/**
* @file
* Install, update and uninstall functions for the colorbox module.
*
*/
/**
* @file
* Installation functions for colorbox.
*/
/**
* Implementation of hook_requirements().
*/
// function colorbox_update_requirements($phase) {
// $requirements = array();
// $t = get_t();
//
// if ($phase == 'runtime') {
// $requirements['colorbox'] = array(
// 'title' => $t('Colorbox'),
// 'severity' => REQUIREMENT_OK,
// 'value' => ,
// );
// }
//
// return $requirements;
// }
function colorbox_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$t = get_t();
$status = _colorbox_status();
if (!$status['colorbox_plugin']) {
$requirements['colorbox_plugin'] = array(
'title' => $t('Colorbox plugin'),
'value' => $t('At least @a', array('@a' => COLORBOX_MIN_PLUGIN_VERSION)),
'severity' => REQUIREMENT_ERROR,
'description' => $t('You need to download the !colorbox and extract the entire contents of the archive into the %path folder of your server.', array('!colorbox' => l(t('Colorbox plugin'), 'http://colorpowered.com/colorbox/'), '%path' => 'sites/all/libraries')),
);
}
else {
$requirements['colorbox_plugin'] = array(
'title' => $t('Colorbox plugin'),
'severity' => REQUIREMENT_OK,
'value' => colorbox_get_version(),
);
}
}
return $requirements;
}
/**
* Implementation of hook_uninstall().
......
......@@ -10,6 +10,7 @@
* The default path to the Colorbox directory.
*/
define('COLORBOX_PATH', 'sites/all/libraries/colorbox');
define('COLORBOX_MIN_PLUGIN_VERSION', '1.3.6');
/**
......@@ -117,6 +118,25 @@ function _colorbox_form_page_access($form_id) {
return $access;
}
/**
* Check Colorbox dependencies, Colorbox plugin.
*
* @return
* array with TRUE/FALSE for each dependency.
*
* @see colorbox_requirements()
*/
function _colorbox_status() {
$status = array();
$status['colorbox_plugin'] = FALSE;
if (version_compare(colorbox_get_version(), COLORBOX_MIN_PLUGIN_VERSION, '>=')) {
$status['colorbox_plugin'] = TRUE;
}
return $status;
}
/**
* Check if Colorbox should be active for the current URL.
*
......@@ -211,8 +231,7 @@ function _colorbox_doheader() {
}
}
$colorbox_file = array('none' => 'jquery.colorbox.js', 'min' => 'jquery.colorbox-min.js');
drupal_add_js(variable_get('colorbox_path', COLORBOX_PATH) . '/colorbox/' . $colorbox_file[variable_get('colorbox_compression_type', 'min')]);
drupal_add_js(colorbox_get_path());
drupal_add_js($path . '/js/colorbox.js');
if ($style == 'default') {
......@@ -230,6 +249,40 @@ function _colorbox_doheader() {
$already_added = TRUE;
}
/**
* Return the version of Colorbox plugin that is installed.
*
* This can be used by other modules' hook_requirements() to ensure that the
* proper version of Colorbox plugin is installed.
*
* @see version_compare
*/
function colorbox_get_version($colorbox_path = NULL) {
$version = 0;
$pattern = '#ColorBox v([0-9\.a-z]+)#';
// No file is passed in so use the default location.
if (is_null($colorbox_path)) {
$colorbox_path = colorbox_get_path();
}
// Return the version of Colorbox plugin.
$colorbox_plugin = file_get_contents($colorbox_path, NULL, NULL, 0, 32);
if (preg_match($pattern, $colorbox_plugin, $matches)) {
$version = $matches[1];
}
return $version;
}
/**
* Return the path to the Colorbox plugin.
*/
function colorbox_get_path() {
$colorbox_file = array('none' => 'jquery.colorbox.js', 'min' => 'jquery.colorbox-min.js');
return variable_get('colorbox_path', COLORBOX_PATH) .'/colorbox/'. $colorbox_file[variable_get('colorbox_compression_type', 'min')];
}
/**
* Implementation of hook_form_alter().
* Reformat the login form.
......@@ -280,13 +333,6 @@ function colorbox_field_formatter_info() {
* Implements hook_field_formatter_view().
*/
function colorbox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
// dpm($entity_type);
// dpm($entity);
// dpm($field);
// dpm($instance);
// dpm($langcode);
// dpm($items);
// dpm($display);
$element = array();
// Check if the formatter involves a particular image style.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment