You are here

function themekey_match_condition in ThemeKey 6.2

Same name and namespace in other branches
  1. 6.4 themekey_base.inc \themekey_match_condition()
  2. 6.3 themekey_base.inc \themekey_match_condition()
  3. 7.3 themekey_base.inc \themekey_match_condition()
  4. 7 themekey_base.inc \themekey_match_condition()
  5. 7.2 themekey_base.inc \themekey_match_condition()

Detects if a ThemeKey rule matches to the current page request.

Parameters

$condition: ThemeKey rule as associative array:

  • property
  • operator
  • value

$parameters: reference to an array containing all ThemeKey properties an their values

Return value

boolean

1 call to themekey_match_condition()
themekey_match_rule_childs in ./themekey_base.inc
Helper function of

File

./themekey_base.inc, line 314
The functions in this file are the back end of ThemeKey.

Code

function themekey_match_condition($condition, &$parameters) {
  global $custom_theme;
  if (is_array($condition) && count($condition)) {

    // Default operator is 'equal'
    if (empty($condition['operator'])) {
      $condition['operator'] = '=';
    }
    if ('drupal:path' == $condition['property']) {
      return themekey_match_path($condition, $parameters);
    }
    $value = themekey_property_value($parameters, $condition['property']);
    if ('static' === $value && $custom_theme) {
      if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
        themekey_set_debug_message('A static rule set custom theme %custom_theme', array(
          '%custom_theme' => $custom_theme,
        ));
      }
      return TRUE;
    }
    if (!is_array($value)) {
      $value = array(
        $value,
      );
    }
    if (!empty($value)) {
      foreach ($value as $single_value) {
        if (!is_null($single_value)) {

          // Supported operators for condition check:
          // smaller ('<'), greater ('>'), equal ('='), not equal ('!'), regex match ('~')
          if ($condition['operator'] == '<' && $single_value >= $condition['value']) {
            return FALSE;
          }
          elseif ($condition['operator'] == '>' && $single_value <= $condition['value']) {
            return FALSE;
          }
          elseif ($condition['operator'] == '<=' && $single_value > $condition['value']) {
            return FALSE;
          }
          elseif ($condition['operator'] == '>=' && $single_value < $condition['value']) {
            return FALSE;
          }
          elseif ($condition['operator'] == '=' && $single_value == $condition['value']) {
            return TRUE;
          }
          elseif ($condition['operator'] == '!' && $single_value == $condition['value']) {
            return FALSE;
          }
          elseif ($condition['operator'] == '~' && preg_match($condition['value'], $single_value)) {
            return TRUE;
          }
        }
        else {

          // value is NULL
          return FALSE;
        }
      }
      if ($condition['operator'] == '=' || $condition['operator'] == '~') {

        // no value matched
        return FALSE;
      }
      else {

        // condition matched for all values
        return TRUE;
      }
    }
    else {

      // value array is empty => value is NULL
      return FALSE;
    }
  }
  else {
    trigger_error(t('Function themekey_match_condition() called with illegal parameters'), E_USER_ERROR);
  }
}