]>
Commit | Line | Data |
---|---|---|
f45a286b AD |
1 | <?php |
2 | ||
3 | /** | |
4 | * Processes an entire attribute array for corrections needing multiple values. | |
5 | * | |
6 | * Occasionally, a certain attribute will need to be removed and popped onto | |
7 | * another value. Instead of creating a complex return syntax for | |
8 | * HTMLPurifier_AttrDef, we just pass the whole attribute array to a | |
9 | * specialized object and have that do the special work. That is the | |
10 | * family of HTMLPurifier_AttrTransform. | |
11 | * | |
12 | * An attribute transformation can be assigned to run before or after | |
13 | * HTMLPurifier_AttrDef validation. See HTMLPurifier_HTMLDefinition for | |
14 | * more details. | |
15 | */ | |
16 | ||
17 | abstract class HTMLPurifier_AttrTransform | |
18 | { | |
19 | ||
20 | /** | |
21 | * Abstract: makes changes to the attributes dependent on multiple values. | |
22 | * | |
23 | * @param $attr Assoc array of attributes, usually from | |
24 | * HTMLPurifier_Token_Tag::$attr | |
25 | * @param $config Mandatory HTMLPurifier_Config object. | |
26 | * @param $context Mandatory HTMLPurifier_Context object | |
27 | * @returns Processed attribute array. | |
28 | */ | |
29 | abstract public function transform($attr, $config, $context); | |
30 | ||
31 | /** | |
32 | * Prepends CSS properties to the style attribute, creating the | |
33 | * attribute if it doesn't exist. | |
34 | * @param $attr Attribute array to process (passed by reference) | |
35 | * @param $css CSS to prepend | |
36 | */ | |
37 | public function prependCSS(&$attr, $css) { | |
38 | $attr['style'] = isset($attr['style']) ? $attr['style'] : ''; | |
39 | $attr['style'] = $css . $attr['style']; | |
40 | } | |
41 | ||
42 | /** | |
43 | * Retrieves and removes an attribute | |
44 | * @param $attr Attribute array to process (passed by reference) | |
45 | * @param $key Key of attribute to confiscate | |
46 | */ | |
47 | public function confiscateAttr(&$attr, $key) { | |
48 | if (!isset($attr[$key])) return null; | |
49 | $value = $attr[$key]; | |
50 | unset($attr[$key]); | |
51 | return $value; | |
52 | } | |
53 | ||
54 | } | |
55 | ||
56 | // vim: et sw=4 sts=4 |