3 require_once 'HTMLPurifier/AttrTransform.php';
6 * Generic pre-transform that converts an attribute with a fixed number of
7 * values (enumerated) to CSS.
9 class HTMLPurifier_AttrTransform_EnumToCSS
extends HTMLPurifier_AttrTransform
{
12 * Name of attribute to transform from
17 * Lookup array of attribute values to CSS
19 var $enumToCSS = array();
22 * Case sensitivity of the matching
23 * @warning Currently can only be guaranteed to work with ASCII
26 var $caseSensitive = false;
29 * @param $attr String attribute name to transform from
30 * @param $enumToCSS Lookup array of attribute values to CSS
31 * @param $case_sensitive Boolean case sensitivity indicator, default false
33 function HTMLPurifier_AttrTransform_EnumToCSS($attr, $enum_to_css, $case_sensitive = false) {
35 $this->enumToCSS
= $enum_to_css;
36 $this->caseSensitive
= (bool) $case_sensitive;
39 function transform($attr, $config, &$context) {
41 if (!isset($attr[$this->attr
])) return $attr;
43 $value = trim($attr[$this->attr
]);
44 unset($attr[$this->attr
]);
46 if (!$this->caseSensitive
) $value = strtolower($value);
48 if (!isset($this->enumToCSS
[$value])) {
52 $this->prependCSS($attr, $this->enumToCSS
[$value]);