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.
16 * Lookup array of attribute values to CSS.
19 protected $enumToCSS = array();
22 * Case sensitivity of the matching.
24 * @warning Currently can only be guaranteed to work with ASCII
27 protected $caseSensitive = false;
30 * @param string $attr Attribute name to transform from
31 * @param array $enum_to_css Lookup array of attribute values to CSS
32 * @param bool $case_sensitive Case sensitivity indicator, default false
34 public function __construct($attr, $enum_to_css, $case_sensitive = false)
37 $this->enumToCSS
= $enum_to_css;
38 $this->caseSensitive
= (bool)$case_sensitive;
43 * @param HTMLPurifier_Config $config
44 * @param HTMLPurifier_Context $context
47 public function transform($attr, $config, $context)
49 if (!isset($attr[$this->attr
])) {
53 $value = trim($attr[$this->attr
]);
54 unset($attr[$this->attr
]);
56 if (!$this->caseSensitive
) {
57 $value = strtolower($value);
60 if (!isset($this->enumToCSS
[$value])) {
63 $this->prependCSS($attr, $this->enumToCSS
[$value]);