4 * Generic pre-transform that converts an attribute with a fixed number of
5 * values (enumerated) to CSS.
7 class HTMLPurifier_AttrTransform_EnumToCSS
extends HTMLPurifier_AttrTransform
{
10 * Name of attribute to transform from
15 * Lookup array of attribute values to CSS
17 protected $enumToCSS = array();
20 * Case sensitivity of the matching
21 * @warning Currently can only be guaranteed to work with ASCII
24 protected $caseSensitive = false;
27 * @param $attr String attribute name to transform from
28 * @param $enumToCSS Lookup array of attribute values to CSS
29 * @param $case_sensitive Boolean case sensitivity indicator, default false
31 public function __construct($attr, $enum_to_css, $case_sensitive = false) {
33 $this->enumToCSS
= $enum_to_css;
34 $this->caseSensitive
= (bool) $case_sensitive;
37 public function transform($attr, $config, $context) {
39 if (!isset($attr[$this->attr
])) return $attr;
41 $value = trim($attr[$this->attr
]);
42 unset($attr[$this->attr
]);
44 if (!$this->caseSensitive
) $value = strtolower($value);
46 if (!isset($this->enumToCSS
[$value])) {
50 $this->prependCSS($attr, $this->enumToCSS
[$value]);