You are here

function query_parameters_to_url_is_called_from_global_redirect_init in Query Parameters To URL 7

Checks whether the function is called from inside globalredirect_init().

Necessary to work with global redirect module, until the patch below is merged into the project.

See also

https://www.drupal.org/node/2060123

1 call to query_parameters_to_url_is_called_from_global_redirect_init()
query_parameters_to_url_url_outbound_alter in ./query_parameters_to_url.module
Implements hook_url_outbound_alter().

File

./query_parameters_to_url.module, line 191
Query Arguments To URL module.

Code

function query_parameters_to_url_is_called_from_global_redirect_init() {
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['global_redirect_enabled'] =& drupal_static(__FUNCTION__, module_exists('globalredirect'));
    $drupal_static_fast['called'] =& drupal_static(__FUNCTION__ . '_called');
  }
  $global_redirect_enabled =& $drupal_static_fast['global_redirect_enabled'];
  static $times_called_from_inside_global_redirect = 0;

  // We don't return TRUE for any subsequent calls after the second time
  // we encounter that the function was called from inside
  // globalredirect_init(), nor when the module is disabled.
  // globalredirect_init will call this function once and then redirect,
  // or twice and then redirect / not redirect. That's why we need to check
  // it twice.
  if (!$global_redirect_enabled || $times_called_from_inside_global_redirect >= 2) {
    return FALSE;
  }
  $called =& $drupal_static_fast['called'];
  if (!isset($called) || empty($called)) {
    $called = FALSE;

    // Save memory in the debug_backtrace() function when possible.
    $options = version_compare(PHP_VERSION, '5.3.6', '>=') ? DEBUG_BACKTRACE_IGNORE_ARGS : NULL;
    $call_stack = debug_backtrace($options);

    // Check whether the function is called from inside globalredirect_init().
    foreach ($call_stack as $function) {
      $called = $function['function'] == 'globalredirect_init';
      if ($called) {
        $times_called_from_inside_global_redirect++;
        break;
      }
    }
  }
  else {
    $times_called_from_inside_global_redirect++;
  }
  return $called;
}