]>
Commit | Line | Data |
---|---|---|
d4949327 NL |
1 | <?php\r |
2 | \r | |
3 | /**\r | |
4 | * Pre-transform that changes deprecated hspace and vspace attributes to CSS\r | |
5 | */\r | |
6 | class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform\r | |
7 | {\r | |
8 | /**\r | |
9 | * @type string\r | |
10 | */\r | |
11 | protected $attr;\r | |
12 | \r | |
13 | /**\r | |
14 | * @type array\r | |
15 | */\r | |
16 | protected $css = array(\r | |
17 | 'hspace' => array('left', 'right'),\r | |
18 | 'vspace' => array('top', 'bottom')\r | |
19 | );\r | |
20 | \r | |
21 | /**\r | |
22 | * @param string $attr\r | |
23 | */\r | |
24 | public function __construct($attr)\r | |
25 | {\r | |
26 | $this->attr = $attr;\r | |
27 | if (!isset($this->css[$attr])) {\r | |
28 | trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');\r | |
29 | }\r | |
30 | }\r | |
31 | \r | |
32 | /**\r | |
33 | * @param array $attr\r | |
34 | * @param HTMLPurifier_Config $config\r | |
35 | * @param HTMLPurifier_Context $context\r | |
36 | * @return array\r | |
37 | */\r | |
38 | public function transform($attr, $config, $context)\r | |
39 | {\r | |
40 | if (!isset($attr[$this->attr])) {\r | |
41 | return $attr;\r | |
42 | }\r | |
43 | \r | |
44 | $width = $this->confiscateAttr($attr, $this->attr);\r | |
45 | // some validation could happen here\r | |
46 | \r | |
47 | if (!isset($this->css[$this->attr])) {\r | |
48 | return $attr;\r | |
49 | }\r | |
50 | \r | |
51 | $style = '';\r | |
52 | foreach ($this->css[$this->attr] as $suffix) {\r | |
53 | $property = "margin-$suffix";\r | |
54 | $style .= "$property:{$width}px;";\r | |
55 | }\r | |
56 | $this->prependCSS($attr, $style);\r | |
57 | return $attr;\r | |
58 | }\r | |
59 | }\r | |
60 | \r | |
61 | // vim: et sw=4 sts=4\r |