00001 <?php
00002
00003
00010 class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
00011 {
00012
00017 public $valid_values = array();
00018
00023 protected $case_sensitive = false;
00024
00029 public function __construct(
00030 $valid_values = array(), $case_sensitive = false
00031 ) {
00032 $this->valid_values = array_flip($valid_values);
00033 $this->case_sensitive = $case_sensitive;
00034 }
00035
00036 public function validate($string, $config, $context) {
00037 $string = trim($string);
00038 if (!$this->case_sensitive) {
00039
00040 $string = ctype_lower($string) ? $string : strtolower($string);
00041 }
00042 $result = isset($this->valid_values[$string]);
00043
00044 return $result ? $string : false;
00045 }
00046
00052 public function make($string) {
00053 if (strlen($string) > 2 && $string[0] == 's' && $string[1] == ':') {
00054 $string = substr($string, 2);
00055 $sensitive = true;
00056 } else {
00057 $sensitive = false;
00058 }
00059 $values = explode(',', $string);
00060 return new HTMLPurifier_AttrDef_Enum($values, $sensitive);
00061 }
00062
00063 }
00064