PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/vjCommentPlugin/lib/tools/htmlpurifier/library/HTMLPurifier/HTMLModule/Forms.php

https://bitbucket.org/Kudlaty/360kdw
PHP | 118 lines | 85 code | 17 blank | 16 comment | 0 complexity | 73153b86492552a9fbb88340c770963f MD5 | raw file
Possible License(s): LGPL-2.1
  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#embeds',
  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. );
  80. // Extra exclusion: img usemap="" is not permitted within this element.
  81. // We'll omit this for now, since we don't have any good way of
  82. // indicating it yet.
  83. // This is HIGHLY user-unfriendly; we need a custom child-def for this
  84. $this->addElement('fieldset', 'Form', 'Custom: (#WS?,legend,(Flow|#PCDATA)*)', 'Common');
  85. $label = $this->addElement('label', 'Formctrl', 'Optional: #PCDATA | Inline', 'Common', array(
  86. 'accesskey' => 'Character',
  87. // 'for' => 'IDREF', // IDREF not implemented, cannot allow
  88. ));
  89. $label->excludes = array('label' => true);
  90. $this->addElement('legend', false, 'Optional: #PCDATA | Inline', 'Common', array(
  91. 'accesskey' => 'Character',
  92. ));
  93. $this->addElement('optgroup', false, 'Required: option', 'Common', array(
  94. 'disabled' => 'Bool#disabled',
  95. 'label*' => 'Text',
  96. ));
  97. // Don't forget an injector for <isindex>. This one's a little complex
  98. // because it maps to multiple elements.
  99. }
  100. }
  101. // vim: et sw=4 sts=4