Release 1.6.1, merged in 931 to HEAD.
[htmlpurifier.git] / library / HTMLPurifier / AttrTransform / ImgSpace.php
blob53c787e2c92cb858ca1f225d720faebf0ec75f62
1 <?php
3 require_once 'HTMLPurifier/AttrTransform.php';
5 /**
6 * Pre-transform that changes deprecated hspace and vspace attributes to CSS
7 */
8 class HTMLPurifier_AttrTransform_ImgSpace
9 extends HTMLPurifier_AttrTransform {
11 var $attr;
12 var $css = array(
13 'hspace' => array('left', 'right'),
14 'vspace' => array('top', 'bottom')
17 function HTMLPurifier_AttrTransform_ImgSpace($attr) {
18 $this->attr = $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;
33 $style = '';
34 foreach ($this->css[$this->attr] as $suffix) {
35 $property = "margin-$suffix";
36 $style .= "$property:{$width}px;";
39 $this->prependCSS($attr, $style);
41 return $attr;