Input.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Performs miscellaneous cross attribute validation and filtering for
  4. * input elements. This is meant to be a post-transform.
  5. */
  6. class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform {
  7. protected $pixels;
  8. public function __construct() {
  9. $this->pixels = new HTMLPurifier_AttrDef_HTML_Pixels();
  10. }
  11. public function transform($attr, $config, $context) {
  12. if (!isset($attr['type'])) $t = 'text';
  13. else $t = strtolower($attr['type']);
  14. if (isset($attr['checked']) && $t !== 'radio' && $t !== 'checkbox') {
  15. unset($attr['checked']);
  16. }
  17. if (isset($attr['maxlength']) && $t !== 'text' && $t !== 'password') {
  18. unset($attr['maxlength']);
  19. }
  20. if (isset($attr['size']) && $t !== 'text' && $t !== 'password') {
  21. $result = $this->pixels->validate($attr['size'], $config, $context);
  22. if ($result === false) unset($attr['size']);
  23. else $attr['size'] = $result;
  24. }
  25. if (isset($attr['src']) && $t !== 'image') {
  26. unset($attr['src']);
  27. }
  28. if (!isset($attr['value']) && ($t === 'radio' || $t === 'checkbox')) {
  29. $attr['value'] = '';
  30. }
  31. return $attr;
  32. }
  33. }
  34. // vim: et sw=4 sts=4