You are here

function _css_injector_evaluate_rule in CSS Injector 7

Same name and namespace in other branches
  1. 6 css_injector.module \_css_injector_evaluate_rule()

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

Parameters

$css_rule: Array describing the rule.

1 call to _css_injector_evaluate_rule()
css_injector_init in ./css_injector.module
Implements hook_init(). Checks to see whether any CSS files should be added to the current page, based on rules configured by the site administrator.

File

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

Code

function _css_injector_evaluate_rule($css_rule = array()) {

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

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

      // When $css_rule['rule_type'] has a value of
      // CSS_INJECTOR_PAGES_NOTLISTED, the rule is matched on
      // all pages except those listed in $css_rule['rule_conditions'].
      // When set to CSS_INJECTOR_PAGES_LISTED, it is displayed only on those
      // pages listed in $css_rule['rule_type'].
      $page_match = !($css_rule['rule_type'] xor $page_match);
    }
    else {
      if (module_exists('php')) {
        $page_match = php_eval($css_rule['rule_conditions']);
      }
      else {
        $page_match = FALSE;
      }
    }
  }
  else {
    $page_match = TRUE;
  }
  return $page_match;
}