Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrDef / Enum.php
blob91a075f87aa7b52965f84e3082a8f27a654957fe
1 <?php
3 require_once 'HTMLPurifier/AttrDef.php';
5 // Enum = Enumerated
6 /**
7 * Validates a keyword against a list of valid values.
8 * @warning The case-insensitive compare of this function uses PHP's
9 * built-in strtolower and ctype_lower functions, which may
10 * cause problems with international comparisons
12 class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
15 /**
16 * Lookup table of valid values.
18 var $valid_values = array();
20 /**
21 * Bool indicating whether or not enumeration is case sensitive.
22 * @note In general this is always case insensitive.
24 var $case_sensitive = false; // values according to W3C spec
26 /**
27 * @param $valid_values List of valid values
28 * @param $case_sensitive Bool indicating whether or not case sensitive
30 function HTMLPurifier_AttrDef_Enum(
31 $valid_values = array(), $case_sensitive = false
32 ) {
33 $this->valid_values = array_flip($valid_values);
34 $this->case_sensitive = $case_sensitive;
37 function validate($string, $config, &$context) {
38 $string = trim($string);
39 if (!$this->case_sensitive) {
40 // we may want to do full case-insensitive libraries
41 $string = ctype_lower($string) ? $string : strtolower($string);
43 $result = isset($this->valid_values[$string]);
45 return $result ? $string : false;