summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--context.install14
-rw-r--r--plugins/context_reaction_block.inc45
2 files changed, 16 insertions, 43 deletions
diff --git a/context.install b/context.install
index b1af4b1..da9765e 100644
--- a/context.install
+++ b/context.install
@@ -1,5 +1,19 @@
<?php
+
+/**
+ * Implementation of hook_requirements().
+ */
+function context_requirements($phase) {
+ $requirements = array();
+ $t = get_t();
+ // Test PHP version
+ if (!function_exists('json_decode')) {
+ $requirements['php_context']['description'] = $t('Your PHP installation is too old. Context requires at least PHP %version or installation of the json library (%path)', array('%version' => '5.1.0', '%path' => 'http://pecl.php.net/package/json'));
+ $requirements['php_context']['severity'] = REQUIREMENT_ERROR;
+ }
+}
+
/**
* Implementation of hook_install().
*/
diff --git a/plugins/context_reaction_block.inc b/plugins/context_reaction_block.inc
index 6293210..e99e182 100644
--- a/plugins/context_reaction_block.inc
+++ b/plugins/context_reaction_block.inc
@@ -501,50 +501,9 @@ class context_reaction_block extends context_reaction {
if (function_exists('json_decode')) {
return json_decode($json, $assoc);
}
- return context_reaction_block::_json_decode($json);
- }
-
- /**
- * From http://www.php.net/manual/en/function.json-decode.php#91216
- * with modifications for consistency with output of json_decode().
- *
- * Original author: walidator.info 2009.
- */
- static function _json_decode($json) {
- $comment = false;
- $out = '$x = ';
- for ($i=0; $i < strlen($json); $i++) {
- if (!$comment) {
- switch ($json[$i]) {
- case '{':
- $out .= ' (object) array(';
- break;
- case '}':
- $out .= ')';
- break;
- case '[':
- $out .= ' array(';
- break;
- case ']':
- $out .= ')';
- break;
- case ':';
- $out .= '=>';
- break;
- default:
- $out .= $json[$i];
- break;
- }
- }
- else {
- $out .= $json[$i];
- }
- if ($json[$i] == '"') {
- $comment = !$comment;
- }
+ else {
+ watchdog('context', 'Please upgrade your PHP version to one that supports json_decode.');
}
- eval($out . ';');
- return $x;
}
/**