2007-05-03 04:07:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pre-transform that changes converts a boolean attribute to fixed CSS
|
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
class HTMLPurifier_AttrTransform_BoolToCSS extends HTMLPurifier_AttrTransform
|
|
|
|
{
|
2007-05-03 04:07:47 +00:00
|
|
|
/**
|
2013-07-16 11:56:14 +00:00
|
|
|
* Name of boolean attribute that is trigger.
|
|
|
|
* @type string
|
2007-05-03 04:07:47 +00:00
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $attr;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-03 04:07:47 +00:00
|
|
|
/**
|
2013-07-16 11:56:14 +00:00
|
|
|
* CSS declarations to add to style, needs trailing semicolon.
|
|
|
|
* @type string
|
2007-05-03 04:07:47 +00:00
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $css;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-05-03 04:07:47 +00:00
|
|
|
/**
|
2013-07-16 11:56:14 +00:00
|
|
|
* @param string $attr attribute name to convert from
|
|
|
|
* @param string $css CSS declarations to add to style (needs semicolon)
|
2007-05-03 04:07:47 +00:00
|
|
|
*/
|
2013-07-16 11:56:14 +00:00
|
|
|
public function __construct($attr, $css)
|
|
|
|
{
|
2007-05-03 04:07:47 +00:00
|
|
|
$this->attr = $attr;
|
2013-07-16 11:56:14 +00:00
|
|
|
$this->css = $css;
|
2007-05-03 04:07:47 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
2007-05-03 04:07:47 +00:00
|
|
|
unset($attr[$this->attr]);
|
2007-05-05 02:25:55 +00:00
|
|
|
$this->prependCSS($attr, $this->css);
|
2007-05-03 04:07:47 +00:00
|
|
|
return $attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|