2007-04-30 19:39:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pre-transform that changes deprecated hspace and vspace attributes to CSS
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $attr;
|
|
|
|
protected $css = array(
|
2007-04-30 19:39:42 +00:00
|
|
|
'hspace' => array('left', 'right'),
|
|
|
|
'vspace' => array('top', 'bottom')
|
|
|
|
);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-11-29 04:29:51 +00:00
|
|
|
public function __construct($attr) {
|
2007-04-30 19:39:42 +00:00
|
|
|
$this->attr = $attr;
|
|
|
|
if (!isset($this->css[$attr])) {
|
|
|
|
trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
|
|
|
|
}
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-01-05 00:10:43 +00:00
|
|
|
public function transform($attr, $config, $context) {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-04-30 19:39:42 +00:00
|
|
|
if (!isset($attr[$this->attr])) return $attr;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-05 02:25:55 +00:00
|
|
|
$width = $this->confiscateAttr($attr, $this->attr);
|
2007-04-30 19:39:42 +00:00
|
|
|
// some validation could happen here
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-04-30 19:39:42 +00:00
|
|
|
if (!isset($this->css[$this->attr])) return $attr;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-04-30 19:39:42 +00:00
|
|
|
$style = '';
|
|
|
|
foreach ($this->css[$this->attr] as $suffix) {
|
|
|
|
$property = "margin-$suffix";
|
|
|
|
$style .= "$property:{$width}px;";
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-05 02:25:55 +00:00
|
|
|
$this->prependCSS($attr, $style);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-04-30 19:39:42 +00:00
|
|
|
return $attr;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-04-30 19:39:42 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-04-30 19:39:42 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|