File indexing completed on 2024-05-12 06:02:04

0001 <?php
0002 
0003 /**
0004  * Pre-transform that changes converts a boolean attribute to fixed CSS
0005  */
0006 class HTMLPurifier_AttrTransform_BoolToCSS extends HTMLPurifier_AttrTransform
0007 {
0008     /**
0009      * Name of boolean attribute that is trigger.
0010      * @type string
0011      */
0012     protected $attr;
0013 
0014     /**
0015      * CSS declarations to add to style, needs trailing semicolon.
0016      * @type string
0017      */
0018     protected $css;
0019 
0020     /**
0021      * @param string $attr attribute name to convert from
0022      * @param string $css CSS declarations to add to style (needs semicolon)
0023      */
0024     public function __construct($attr, $css)
0025     {
0026         $this->attr = $attr;
0027         $this->css = $css;
0028     }
0029 
0030     /**
0031      * @param array $attr
0032      * @param HTMLPurifier_Config $config
0033      * @param HTMLPurifier_Context $context
0034      * @return array
0035      */
0036     public function transform($attr, $config, $context)
0037     {
0038         if (!isset($attr[$this->attr])) {
0039             return $attr;
0040         }
0041         unset($attr[$this->attr]);
0042         $this->prependCSS($attr, $this->css);
0043         return $attr;
0044     }
0045 }
0046 
0047 // vim: et sw=4 sts=4