Make extractBody not terminate prematurely on first </body>.
[htmlpurifier.git] / library / HTMLPurifier / AttrTransform / ImgSpace.php
blobfd84c10c3618fb4642282ae307cf731e9e042490
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 protected $attr;
9 protected $css = array(
10 'hspace' => array('left', 'right'),
11 'vspace' => array('top', 'bottom')
14 public function __construct($attr) {
15 $this->attr = $attr;
16 if (!isset($this->css[$attr])) {
17 trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
21 public function transform($attr, $config, $context) {
23 if (!isset($attr[$this->attr])) return $attr;
25 $width = $this->confiscateAttr($attr, $this->attr);
26 // some validation could happen here
28 if (!isset($this->css[$this->attr])) return $attr;
30 $style = '';
31 foreach ($this->css[$this->attr] as $suffix) {
32 $property = "margin-$suffix";
33 $style .= "$property:{$width}px;";
36 $this->prependCSS($attr, $style);
38 return $attr;
44 // vim: et sw=4 sts=4