function themekey_validator_date_time in ThemeKey 7.3
Same name and namespace in other branches
- 6.4 themekey_validators.inc \themekey_validator_date_time()
- 6.2 themekey_validators.inc \themekey_validator_date_time()
- 6.3 themekey_validators.inc \themekey_validator_date_time()
- 7 themekey_validators.inc \themekey_validator_date_time()
- 7.2 themekey_validators.inc \themekey_validator_date_time()
Validates a Theme Switching Rule. Allowed Operators: "<", "<=", ">", ">=" and "~" Allowed values:
- valid regular expression if operator is "~"
- string formatted like "2009-12-24 23:56:17" for different operators
Parameters
$rule: A Theme Switching Rule as associative array:
- property: ThemeKey property as string (for example, "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.
2 string references to 'themekey_validator_date_time'
- themekey_node_themekey_properties in modules/
themekey.node.inc - Implements hook_themekey_properties().
- themekey_system_themekey_properties in modules/
themekey.system.inc - Implements hook_themekey_properties().
File
- ./
themekey_validators.inc, line 224 - Provides set of validators which can be used to validate ThemeKey Theme Switching Rules.
Code
function themekey_validator_date_time($rule) {
$errors = array();
switch ($rule['operator']) {
case '=':
case '!':
// It seems senseless to switch a theme for one second
$errors['operator'] = t('Possible operators are "*", "!*", "<", "<=", ">", ">=", "~" and "!~"');
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 dates formatted like \"2009-12-24 23:56:17\"");
}
break;
default:
if (!preg_match("/^[0-9]{4}[0-9\\- :]*\$/", $rule['value'])) {
$errors['value'] = t("Value isn't suitable for checks against dates formatted like \"2009-12-24 23:56:17\"");
}
}
return $errors;
}