3
require_once 'HTMLPurifier/AttrTransform.php';
6
* Pre-transform that changes deprecated hspace and vspace attributes to CSS
8
class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform {
11
protected $css = array(
12
'hspace' => array('left', 'right'),
13
'vspace' => array('top', 'bottom')
16
public function __construct($attr) {
18
if (!isset($this->css[$attr])) {
19
trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
23
public function transform($attr, $config, $context) {
25
if (!isset($attr[$this->attr])) return $attr;
27
$width = $this->confiscateAttr($attr, $this->attr);
28
// some validation could happen here
30
if (!isset($this->css[$this->attr])) return $attr;
33
foreach ($this->css[$this->attr] as $suffix) {
34
$property = "margin-$suffix";
35
$style .= "$property:{$width}px;";
38
$this->prependCSS($attr, $style);