PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / library / HTMLPurifier / AttrTransform / ImgSpace.php
blob350b3358fcb673f96ac59353d6b2582615954310
1 <?php
3 /**
4 * Pre-transform that changes deprecated hspace and vspace attributes to CSS
5 */
6 class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform
8 /**
9 * @type string
11 protected $attr;
13 /**
14 * @type array
16 protected $css = array(
17 'hspace' => array('left', 'right'),
18 'vspace' => array('top', 'bottom')
21 /**
22 * @param string $attr
24 public function __construct($attr)
26 $this->attr = $attr;
27 if (!isset($this->css[$attr])) {
28 trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
32 /**
33 * @param array $attr
34 * @param HTMLPurifier_Config $config
35 * @param HTMLPurifier_Context $context
36 * @return array
38 public function transform($attr, $config, $context)
40 if (!isset($attr[$this->attr])) {
41 return $attr;
44 $width = $this->confiscateAttr($attr, $this->attr);
45 // some validation could happen here
47 if (!isset($this->css[$this->attr])) {
48 return $attr;
51 $style = '';
52 foreach ($this->css[$this->attr] as $suffix) {
53 $property = "margin-$suffix";
54 $style .= "$property:{$width}px;";
56 $this->prependCSS($attr, $style);
57 return $attr;
61 // vim: et sw=4 sts=4