Forms.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * XHTML 1.1 Forms module, defines all form-related elements found in HTML 4.
  4. */
  5. class HTMLPurifier_HTMLModule_Forms extends HTMLPurifier_HTMLModule
  6. {
  7. public $name = 'Forms';
  8. public $safe = false;
  9. public $content_sets = array(
  10. 'Block' => 'Form',
  11. 'Inline' => 'Formctrl',
  12. );
  13. public function setup($config) {
  14. $form = $this->addElement('form', 'Form',
  15. 'Required: Heading | List | Block | fieldset', 'Common', array(
  16. 'accept' => 'ContentTypes',
  17. 'accept-charset' => 'Charsets',
  18. 'action*' => 'URI',
  19. 'method' => 'Enum#get,post',
  20. // really ContentType, but these two are the only ones used today
  21. 'enctype' => 'Enum#application/x-www-form-urlencoded,multipart/form-data',
  22. ));
  23. $form->excludes = array('form' => true);
  24. $input = $this->addElement('input', 'Formctrl', 'Empty', 'Common', array(
  25. 'accept' => 'ContentTypes',
  26. 'accesskey' => 'Character',
  27. 'alt' => 'Text',
  28. 'checked' => 'Bool#checked',
  29. 'disabled' => 'Bool#disabled',
  30. 'maxlength' => 'Number',
  31. 'name' => 'CDATA',
  32. 'readonly' => 'Bool#readonly',
  33. 'size' => 'Number',
  34. 'src' => 'URI#embedded',
  35. 'tabindex' => 'Number',
  36. 'type' => 'Enum#text,password,checkbox,button,radio,submit,reset,file,hidden,image',
  37. 'value' => 'CDATA',
  38. ));
  39. $input->attr_transform_post[] = new HTMLPurifier_AttrTransform_Input();
  40. $this->addElement('select', 'Formctrl', 'Required: optgroup | option', 'Common', array(
  41. 'disabled' => 'Bool#disabled',
  42. 'multiple' => 'Bool#multiple',
  43. 'name' => 'CDATA',
  44. 'size' => 'Number',
  45. 'tabindex' => 'Number',
  46. ));
  47. $this->addElement('option', false, 'Optional: #PCDATA', 'Common', array(
  48. 'disabled' => 'Bool#disabled',
  49. 'label' => 'Text',
  50. 'selected' => 'Bool#selected',
  51. 'value' => 'CDATA',
  52. ));
  53. // It's illegal for there to be more than one selected, but not
  54. // be multiple. Also, no selected means undefined behavior. This might
  55. // be difficult to implement; perhaps an injector, or a context variable.
  56. $textarea = $this->addElement('textarea', 'Formctrl', 'Optional: #PCDATA', 'Common', array(
  57. 'accesskey' => 'Character',
  58. 'cols*' => 'Number',
  59. 'disabled' => 'Bool#disabled',
  60. 'name' => 'CDATA',
  61. 'readonly' => 'Bool#readonly',
  62. 'rows*' => 'Number',
  63. 'tabindex' => 'Number',
  64. ));
  65. $textarea->attr_transform_pre[] = new HTMLPurifier_AttrTransform_Textarea();
  66. $button = $this->addElement('button', 'Formctrl', 'Optional: #PCDATA | Heading | List | Block | Inline', 'Common', array(
  67. 'accesskey' => 'Character',
  68. 'disabled' => 'Bool#disabled',
  69. 'name' => 'CDATA',
  70. 'tabindex' => 'Number',
  71. 'type' => 'Enum#button,submit,reset',
  72. 'value' => 'CDATA',
  73. ));
  74. // For exclusions, ideally we'd specify content sets, not literal elements
  75. $button->excludes = $this->makeLookup(
  76. 'form', 'fieldset', // Form
  77. 'input', 'select', 'textarea', 'label', 'button', // Formctrl
  78. 'a', // as per HTML 4.01 spec, this is omitted by modularization
  79. 'isindex', 'iframe' // legacy items
  80. );
  81. // Extra exclusion: img usemap="" is not permitted within this element.
  82. // We'll omit this for now, since we don't have any good way of
  83. // indicating it yet.
  84. // This is HIGHLY user-unfriendly; we need a custom child-def for this
  85. $this->addElement('fieldset', 'Form', 'Custom: (#WS?,legend,(Flow|#PCDATA)*)', 'Common');
  86. $label = $this->addElement('label', 'Formctrl', 'Optional: #PCDATA | Inline', 'Common', array(
  87. 'accesskey' => 'Character',
  88. // 'for' => 'IDREF', // IDREF not implemented, cannot allow
  89. ));
  90. $label->excludes = array('label' => true);
  91. $this->addElement('legend', false, 'Optional: #PCDATA | Inline', 'Common', array(
  92. 'accesskey' => 'Character',
  93. ));
  94. $this->addElement('optgroup', false, 'Required: option', 'Common', array(
  95. 'disabled' => 'Bool#disabled',
  96. 'label*' => 'Text',
  97. ));
  98. // Don't forget an injector for <isindex>. This one's a little complex
  99. // because it maps to multiple elements.
  100. }
  101. }
  102. // vim: et sw=4 sts=4