2006-07-30 00:54:38 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-16 15:12:48 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
|
|
|
|
2006-07-30 00:54:38 +00:00
|
|
|
// Enum = Enumerated
|
2006-08-20 21:47:15 +00:00
|
|
|
/**
|
|
|
|
* Validates a keyword against a list of valid values.
|
|
|
|
*/
|
2006-07-30 00:54:38 +00:00
|
|
|
class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
|
|
|
|
{
|
|
|
|
|
2006-08-20 21:47:15 +00:00
|
|
|
/**
|
|
|
|
* Lookup table of valid values.
|
|
|
|
*/
|
2006-07-30 00:54:38 +00:00
|
|
|
var $valid_values = array();
|
2006-08-20 21:47:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bool indicating whether or not enumeration is case sensitive.
|
|
|
|
* @note In general this is always case insensitive.
|
|
|
|
*/
|
2006-07-30 00:54:38 +00:00
|
|
|
var $case_sensitive = false; // values according to W3C spec
|
|
|
|
|
2006-08-20 21:47:15 +00:00
|
|
|
/**
|
|
|
|
* @param $valid_values List of valid values
|
|
|
|
* @param $case_sensitive Bool indicating whether or not case sensitive
|
|
|
|
*/
|
2006-07-30 00:54:38 +00:00
|
|
|
function HTMLPurifier_AttrDef_Enum(
|
2007-02-14 22:21:07 +00:00
|
|
|
$valid_values = array(), $case_sensitive = false
|
|
|
|
) {
|
2006-07-30 00:54:38 +00:00
|
|
|
$this->valid_values = array_flip($valid_values);
|
|
|
|
$this->case_sensitive = $case_sensitive;
|
|
|
|
}
|
|
|
|
|
2006-08-12 16:04:40 +00:00
|
|
|
function validate($string, $config, &$context) {
|
2006-08-05 00:30:31 +00:00
|
|
|
$string = trim($string);
|
2006-07-30 00:54:38 +00:00
|
|
|
if (!$this->case_sensitive) {
|
|
|
|
$string = ctype_lower($string) ? $string : strtolower($string);
|
|
|
|
}
|
2006-08-04 00:11:54 +00:00
|
|
|
$result = isset($this->valid_values[$string]);
|
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
return $result ? $string : false;
|
2006-07-30 00:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|