HTMLPurifier 4.4.0
|
00001 <?php 00002 00006 class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform { 00007 00008 protected $attr; 00009 protected $css = array( 00010 'hspace' => array('left', 'right'), 00011 'vspace' => array('top', 'bottom') 00012 ); 00013 00014 public function __construct($attr) { 00015 $this->attr = $attr; 00016 if (!isset($this->css[$attr])) { 00017 trigger_error(htmlspecialchars($attr) . ' is not valid space attribute'); 00018 } 00019 } 00020 00021 public function transform($attr, $config, $context) { 00022 00023 if (!isset($attr[$this->attr])) return $attr; 00024 00025 $width = $this->confiscateAttr($attr, $this->attr); 00026 // some validation could happen here 00027 00028 if (!isset($this->css[$this->attr])) return $attr; 00029 00030 $style = ''; 00031 foreach ($this->css[$this->attr] as $suffix) { 00032 $property = "margin-$suffix"; 00033 $style .= "$property:{$width}px;"; 00034 } 00035 00036 $this->prependCSS($attr, $style); 00037 00038 return $attr; 00039 00040 } 00041 00042 } 00043 00044 // vim: et sw=4 sts=4