Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrTransform / EnumToCSS.php
blob0470413dd48a35af35583b68409fbebad0baf953
1 <?php
3 require_once 'HTMLPurifier/AttrTransform.php';
5 /**
6 * Generic pre-transform that converts an attribute with a fixed number of
7 * values (enumerated) to CSS.
8 */
9 class HTMLPurifier_AttrTransform_EnumToCSS extends HTMLPurifier_AttrTransform {
11 /**
12 * Name of attribute to transform from
14 var $attr;
16 /**
17 * Lookup array of attribute values to CSS
19 var $enumToCSS = array();
21 /**
22 * Case sensitivity of the matching
23 * @warning Currently can only be guaranteed to work with ASCII
24 * values.
26 var $caseSensitive = false;
28 /**
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) {
34 $this->attr = $attr;
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])) {
49 return $attr;
52 $this->prependCSS($attr, $this->enumToCSS[$value]);
54 return $attr;