3 require_once 'HTMLPurifier/AttrTransform.php';
6 * Pre-transform that changes deprecated hspace and vspace attributes to CSS
8 class HTMLPurifier_AttrTransform_ImgSpace
9 extends HTMLPurifier_AttrTransform
{
13 'hspace' => array('left', 'right'),
14 'vspace' => array('top', 'bottom')
17 function HTMLPurifier_AttrTransform_ImgSpace($attr) {
19 if (!isset($this->css
[$attr])) {
20 trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
24 function transform($attr, $config, &$context) {
26 if (!isset($attr[$this->attr
])) return $attr;
28 $width = $this->confiscateAttr($attr, $this->attr
);
29 // some validation could happen here
31 if (!isset($this->css
[$this->attr
])) return $attr;
34 foreach ($this->css
[$this->attr
] as $suffix) {
35 $property = "margin-$suffix";
36 $style .= "$property:{$width}px;";
39 $this->prependCSS($attr, $style);