summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--colorbox.install46
-rw-r--r--colorbox.module64
2 files changed, 81 insertions, 29 deletions
diff --git a/colorbox.install b/colorbox.install
index edb06bc..956de03 100644
--- a/colorbox.install
+++ b/colorbox.install
@@ -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().
diff --git a/colorbox.module b/colorbox.module
index 284b6d3..8a3cd63 100644
--- a/colorbox.module
+++ b/colorbox.module
@@ -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');
/**
@@ -118,6 +119,25 @@ function _colorbox_form_page_access($form_id) {
}
/**
+ * 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.
*
* @return
@@ -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') {
@@ -231,6 +250,40 @@ function _colorbox_doheader() {
}
/**
+ * 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.