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