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

0001 <?php
0002 
0003 /**
0004  * Performs miscellaneous cross attribute validation and filtering for
0005  * input elements. This is meant to be a post-transform.
0006  */
0007 class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform
0008 {
0009     /**
0010      * @type HTMLPurifier_AttrDef_HTML_Pixels
0011      */
0012     protected $pixels;
0013 
0014     public function __construct()
0015     {
0016         $this->pixels = new HTMLPurifier_AttrDef_HTML_Pixels();
0017     }
0018 
0019     /**
0020      * @param array $attr
0021      * @param HTMLPurifier_Config $config
0022      * @param HTMLPurifier_Context $context
0023      * @return array
0024      */
0025     public function transform($attr, $config, $context)
0026     {
0027         if (!isset($attr['type'])) {
0028             $t = 'text';
0029         } else {
0030             $t = strtolower($attr['type']);
0031         }
0032         if (isset($attr['checked']) && $t !== 'radio' && $t !== 'checkbox') {
0033             unset($attr['checked']);
0034         }
0035         if (isset($attr['maxlength']) && $t !== 'text' && $t !== 'password') {
0036             unset($attr['maxlength']);
0037         }
0038         if (isset($attr['size']) && $t !== 'text' && $t !== 'password') {
0039             $result = $this->pixels->validate($attr['size'], $config, $context);
0040             if ($result === false) {
0041                 unset($attr['size']);
0042             } else {
0043                 $attr['size'] = $result;
0044             }
0045         }
0046         if (isset($attr['src']) && $t !== 'image') {
0047             unset($attr['src']);
0048         }
0049         if (!isset($attr['value']) && ($t === 'radio' || $t === 'checkbox')) {
0050             $attr['value'] = '';
0051         }
0052         return $attr;
0053     }
0054 }
0055 
0056 // vim: et sw=4 sts=4