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

0001 <?php
0002 
0003 /**
0004  * Class for handling width/height length attribute transformations to CSS
0005  */
0006 class HTMLPurifier_AttrTransform_Length extends HTMLPurifier_AttrTransform
0007 {
0008 
0009     /**
0010      * @type string
0011      */
0012     protected $name;
0013 
0014     /**
0015      * @type string
0016      */
0017     protected $cssName;
0018 
0019     public function __construct($name, $css_name = null)
0020     {
0021         $this->name = $name;
0022         $this->cssName = $css_name ? $css_name : $name;
0023     }
0024 
0025     /**
0026      * @param array $attr
0027      * @param HTMLPurifier_Config $config
0028      * @param HTMLPurifier_Context $context
0029      * @return array
0030      */
0031     public function transform($attr, $config, $context)
0032     {
0033         if (!isset($attr[$this->name])) {
0034             return $attr;
0035         }
0036         $length = $this->confiscateAttr($attr, $this->name);
0037         if (ctype_digit($length)) {
0038             $length .= 'px';
0039         }
0040         $this->prependCSS($attr, $this->cssName . ":$length;");
0041         return $attr;
0042     }
0043 }
0044 
0045 // vim: et sw=4 sts=4