2007-03-29 23:48:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for handling width/height length attribute transformations to CSS
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_AttrTransform_Length extends HTMLPurifier_AttrTransform
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @type string
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $name;
|
2013-07-16 11:56:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type string
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $cssName;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function __construct($name, $css_name = null)
|
|
|
|
{
|
2007-03-29 23:48:54 +00:00
|
|
|
$this->name = $name;
|
|
|
|
$this->cssName = $css_name ? $css_name : $name;
|
|
|
|
}
|
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->name])) {
|
|
|
|
return $attr;
|
|
|
|
}
|
2007-05-05 02:25:55 +00:00
|
|
|
$length = $this->confiscateAttr($attr, $this->name);
|
2013-07-16 11:56:14 +00:00
|
|
|
if (ctype_digit($length)) {
|
|
|
|
$length .= 'px';
|
|
|
|
}
|
2007-05-05 02:25:55 +00:00
|
|
|
$this->prependCSS($attr, $this->cssName . ":$length;");
|
2007-03-29 23:48:54 +00:00
|
|
|
return $attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|