You are here

function _js_injector_evaluate_rule in JS injector 6

Same name and namespace in other branches
  1. 6.2 js_injector.module \_js_injector_evaluate_rule()
  2. 7 js_injector.module \_js_injector_evaluate_rule()

Helper function to determine whether a rule's conditions are met.

1 call to _js_injector_evaluate_rule()
js_injector_init in ./js_injector.module
Implementation of hook_init(). Checks to see whether any js files should be added to the current page, based on rules configured by the site administrator.

File

./js_injector.module, line 141
Allows administrators to inject js into the page output based on configurable rules. Useful for adding simple js tweaks without modifying a site's official theme.

Code

function _js_injector_evaluate_rule($js_rule = array()) {

  // Match path if necessary.
  if (!empty($js_rule['rule_conditions'])) {
    if ($js_rule['rule_type'] < 2) {
      $path = drupal_get_path_alias($_GET['q']);

      // Compare with the internal and path alias (if any).
      $page_match = drupal_match_path($path, $js_rule['rule_conditions']);
      if ($path != $_GET['q']) {
        $page_match = $page_match || drupal_match_path($_GET['q'], $js_rule['rule_conditions']);
      }

      // When $js_rule['rule_type'] has a value of 0, the rule is matched on
      // all pages except those listed in $js_rule['rule_conditions'].
      // When set to 1, it is displayed only on those pages listed in
      // $js_rule['rule_type'].
      $page_match = !($js_rule['rule_type'] xor $page_match);
    }
    else {
      $page_match = drupal_eval($js_rule['rule_conditions']);
    }
  }
  else {
    $page_match = TRUE;
  }
  return $page_match;
}