2006-07-30 00:54:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Enum = Enumerated
|
|
|
|
class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
|
|
|
|
{
|
|
|
|
|
|
|
|
var $valid_values = array();
|
|
|
|
var $case_sensitive = false; // values according to W3C spec
|
|
|
|
|
|
|
|
function HTMLPurifier_AttrDef_Enum(
|
2006-07-30 15:29:22 +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-04 00:11:54 +00:00
|
|
|
function validate($raw_string) {
|
|
|
|
$string = trim($raw_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]);
|
|
|
|
|
|
|
|
// if strings equal, return result, otherwise, return
|
|
|
|
// the new string on a good result and false on a bad one
|
|
|
|
return ($string == $raw_string) ? $result : $result ? $string : false;
|
2006-07-30 00:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|