diff --git a/httprl.install b/httprl.install index 2ab7fc6..01f029b 100644 --- a/httprl.install +++ b/httprl.install @@ -121,7 +121,7 @@ function httprl_requirements($phase) { // hostname. $ip = variable_get('httprl_server_addr', FALSE); if (!empty($ip)) { - if (substr(VERSION, 0, 1) >= 7) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { $x = @unserialize(db_query("SELECT value FROM {variable} WHERE name = :name", array(':name' => 'httprl_server_addr'))->fetchField()); } else { @@ -179,7 +179,7 @@ function httprl_install_http_test($mode, $blocking = FALSE) { // Choose how to issue the HTTP request. if ($mode == 1) { // Execute the request using core. - if (substr(VERSION, 0, 1) >= 7) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { drupal_http_request($url, $options); } else { diff --git a/httprl.module b/httprl.module index 82f03b7..561e83a 100644 --- a/httprl.module +++ b/httprl.module @@ -81,7 +81,7 @@ function httprl_menu() { ); // Admin page. - if (substr(VERSION, 0, 1) >= 7) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { $config_url = 'admin/config/development/httprl'; } else { @@ -121,7 +121,7 @@ function httprl_build_url_self($path = '', $detect_schema = FALSE) { // Pull in the httprl_server_addr variable from the DB. if (!isset($conf['httprl_server_addr']) && empty($variable_loaded)) { - if (substr(VERSION, 0, 1) >= 7) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { $result = db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'httprl_server_addr'))->fetchAssoc(); if (!empty($result)) { $conf['httprl_server_addr'] = unserialize($result['value']); @@ -363,7 +363,7 @@ function httprl_request($url, $options = array()) { // Make sure the socket opened properly. if (!$fp) { // Make sure drupal_convert_to_utf8() is available. - if (substr(VERSION, 0, 1) >= 7) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { require_once DRUPAL_ROOT . '/includes/unicode.inc'; } else { @@ -992,10 +992,29 @@ function httprl_post_processing(&$result) { httprl_decode_data($result); httprl_reconstruct_redirects($result); + // See if a full bootstrap has been done given the Drupal version. + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { + $level = drupal_bootstrap(); + $full_bootstrap = ($level == DRUPAL_BOOTSTRAP_FULL) ? TRUE : FALSE; + } + else { + $full_bootstrap = isset($GLOBALS['multibyte']) ? TRUE : FALSE; + } + + // Allow other modules to alter the result. + if ($full_bootstrap) { + // call hook_httprl_post_processing_alter(). + drupal_alter('httprl_post_processing_alter', $result); + } + // Run callback so other modules can do stuff in the event loop. if (!empty($result->options['callback']) && is_array($result->options['callback'])) { + // Get function name. $function = array_shift($result->options['callback']); - call_user_func_array($function, array_merge(array($result), $result->options['callback'])); + // Merge in values by reference. + $args = array_merge(array(&$result), $result->options['callback']); + // Call function. + call_user_func_array($function, $args); } } diff --git a/httprl.nonblocktest.inc b/httprl.nonblocktest.inc index 8cf9cf8..bcc9508 100644 --- a/httprl.nonblocktest.inc +++ b/httprl.nonblocktest.inc @@ -19,7 +19,7 @@ function httprl_nonblockingtest_page() { || strpos($_GET['id'], 'httprl_') !== 0 || $_GET['key'] != md5(drupal_get_private_key()) ) { - if (substr(VERSION, 0, 1) >= 7) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { drupal_exit(); } else { @@ -35,7 +35,7 @@ function httprl_nonblockingtest_page() { httprl_lock_release($_GET['id']); } echo t('lock @id cleared', array('@id' => $_GET['id'])); - if (substr(VERSION, 0, 1) >= 7) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { drupal_exit(); } else { @@ -55,7 +55,7 @@ function httprl_lock_release($name) { global $locks; unset($locks[$name]); - if (substr(VERSION, 0, 1) >= 7) { + if (defined('VERSION') && substr(VERSION, 0, 1) >= 7) { db_delete('semaphore') ->condition('name', $name) ->execute();