2007-04-30 19:39:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pre-transform that changes deprecated hspace and vspace attributes to CSS
|
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @type string
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $attr;
|
2013-07-16 11:56:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type array
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param string $attr
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param array $attr
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
* @param HTMLPurifier_Context $context
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform($attr, $config, $context)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2013-07-16 11:56:14 +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;";
|
|
|
|
}
|
2007-05-05 02:25:55 +00:00
|
|
|
$this->prependCSS($attr, $style);
|
2007-04-30 19:39:42 +00:00
|
|
|
return $attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|