您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
1.6KB

  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. {
  8. /**
  9. * @type HTMLPurifier_AttrDef_HTML_Pixels
  10. */
  11. protected $pixels;
  12. public function __construct()
  13. {
  14. $this->pixels = new HTMLPurifier_AttrDef_HTML_Pixels();
  15. }
  16. /**
  17. * @param array $attr
  18. * @param HTMLPurifier_Config $config
  19. * @param HTMLPurifier_Context $context
  20. * @return array
  21. */
  22. public function transform($attr, $config, $context)
  23. {
  24. if (!isset($attr['type'])) {
  25. $t = 'text';
  26. } else {
  27. $t = strtolower($attr['type']);
  28. }
  29. if (isset($attr['checked']) && $t !== 'radio' && $t !== 'checkbox') {
  30. unset($attr['checked']);
  31. }
  32. if (isset($attr['maxlength']) && $t !== 'text' && $t !== 'password') {
  33. unset($attr['maxlength']);
  34. }
  35. if (isset($attr['size']) && $t !== 'text' && $t !== 'password') {
  36. $result = $this->pixels->validate($attr['size'], $config, $context);
  37. if ($result === false) {
  38. unset($attr['size']);
  39. } else {
  40. $attr['size'] = $result;
  41. }
  42. }
  43. if (isset($attr['src']) && $t !== 'image') {
  44. unset($attr['src']);
  45. }
  46. if (!isset($attr['value']) && ($t === 'radio' || $t === 'checkbox')) {
  47. $attr['value'] = '';
  48. }
  49. return $attr;
  50. }
  51. }
  52. // vim: et sw=4 sts=4