You are here

function themekey_validator_time in ThemeKey 7

Same name and namespace in other branches
  1. 6.4 themekey_validators.inc \themekey_validator_time()
  2. 6.2 themekey_validators.inc \themekey_validator_time()
  3. 6.3 themekey_validators.inc \themekey_validator_time()
  4. 7.3 themekey_validators.inc \themekey_validator_time()
  5. 7.2 themekey_validators.inc \themekey_validator_time()

Validates a Theme Switching Rule. Allowed Operators: any Allowed values:

  • valid regular expression if operator is "~"
  • a valid time like "23:16:56" if operator is "=" or "!"
  • fragment of a time which contains at least the hour as two digits for different operators

Parameters

$rule: A Theme Switching Rule as associative array:

  • property: ThemeKey property as string (e.g., "drupal:path")
  • wildcard: optional string, only used if property is "drupal:path:wildcard"
  • operator: ThemeKey operator as string ("=", "!", "*", "!*", "<", "<=", ">", ">=", "~", "!~")
  • value: ThemeKey property value as string

Return value

An associative array of errors:

  • property: translated error message as string describing a problem with the property
  • wildcard: translated error message as string describing a problem with the wildcard
  • operator: translated error message as string describing a problem with the operator
  • value: translated error message as string describing a problem with the value

If no errors detected the array is empty.

1 string reference to 'themekey_validator_time'
themekey_system_themekey_properties in modules/themekey.system.inc
Implements hook_themekey_properties().

File

./themekey_validators.inc, line 345
Non-displayable characters.

Code

function themekey_validator_time($rule) {
  $errors = array();
  switch ($rule['operator']) {
    case '=':
    case '!':
      if (!preg_match("/^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]\$/", $rule['value'])) {
        $errors['value'] = t('Not a valid date string. Format should look like "23:16:56"');
      }
      break;
    case '~':
    case '!~':
      $errors = themekey_validator_regex($rule);
      break;
    case '*':
    case '!*':
      if (!preg_match("/^[\\d:]+\$/", $rule['value'])) {
        $errors['value'] = t("Value isn't suitable for checks against times formatted like \"23:56:17\"");
      }
      break;
    default:
      if (!preg_match("/^[0-2][0-9][0-9:]*\$/", $rule['value'])) {
        $errors['value'] = t("Value isn't suitable for checks against times formatted like \"23:16:56\"");
      }
  }
  return $errors;
}