File indexing completed on 2025-01-26 05:29:07
0001 <?php 0002 0003 /** 0004 * XHTML 1.1 Forms module, defines all form-related elements found in HTML 4. 0005 */ 0006 class HTMLPurifier_HTMLModule_Forms extends HTMLPurifier_HTMLModule 0007 { 0008 /** 0009 * @type string 0010 */ 0011 public $name = 'Forms'; 0012 0013 /** 0014 * @type bool 0015 */ 0016 public $safe = false; 0017 0018 /** 0019 * @type array 0020 */ 0021 public $content_sets = array( 0022 'Block' => 'Form', 0023 'Inline' => 'Formctrl', 0024 ); 0025 0026 /** 0027 * @param HTMLPurifier_Config $config 0028 */ 0029 public function setup($config) 0030 { 0031 $form = $this->addElement( 0032 'form', 0033 'Form', 0034 'Required: Heading | List | Block | fieldset', 0035 'Common', 0036 array( 0037 'accept' => 'ContentTypes', 0038 'accept-charset' => 'Charsets', 0039 'action*' => 'URI', 0040 'method' => 'Enum#get,post', 0041 // really ContentType, but these two are the only ones used today 0042 'enctype' => 'Enum#application/x-www-form-urlencoded,multipart/form-data', 0043 ) 0044 ); 0045 $form->excludes = array('form' => true); 0046 0047 $input = $this->addElement( 0048 'input', 0049 'Formctrl', 0050 'Empty', 0051 'Common', 0052 array( 0053 'accept' => 'ContentTypes', 0054 'accesskey' => 'Character', 0055 'alt' => 'Text', 0056 'checked' => 'Bool#checked', 0057 'disabled' => 'Bool#disabled', 0058 'maxlength' => 'Number', 0059 'name' => 'CDATA', 0060 'readonly' => 'Bool#readonly', 0061 'size' => 'Number', 0062 'src' => 'URI#embedded', 0063 'tabindex' => 'Number', 0064 'type' => 'Enum#text,password,checkbox,button,radio,submit,reset,file,hidden,image', 0065 'value' => 'CDATA', 0066 ) 0067 ); 0068 $input->attr_transform_post[] = new HTMLPurifier_AttrTransform_Input(); 0069 0070 $this->addElement( 0071 'select', 0072 'Formctrl', 0073 'Required: optgroup | option', 0074 'Common', 0075 array( 0076 'disabled' => 'Bool#disabled', 0077 'multiple' => 'Bool#multiple', 0078 'name' => 'CDATA', 0079 'size' => 'Number', 0080 'tabindex' => 'Number', 0081 ) 0082 ); 0083 0084 $this->addElement( 0085 'option', 0086 false, 0087 'Optional: #PCDATA', 0088 'Common', 0089 array( 0090 'disabled' => 'Bool#disabled', 0091 'label' => 'Text', 0092 'selected' => 'Bool#selected', 0093 'value' => 'CDATA', 0094 ) 0095 ); 0096 // It's illegal for there to be more than one selected, but not 0097 // be multiple. Also, no selected means undefined behavior. This might 0098 // be difficult to implement; perhaps an injector, or a context variable. 0099 0100 $textarea = $this->addElement( 0101 'textarea', 0102 'Formctrl', 0103 'Optional: #PCDATA', 0104 'Common', 0105 array( 0106 'accesskey' => 'Character', 0107 'cols*' => 'Number', 0108 'disabled' => 'Bool#disabled', 0109 'name' => 'CDATA', 0110 'readonly' => 'Bool#readonly', 0111 'rows*' => 'Number', 0112 'tabindex' => 'Number', 0113 ) 0114 ); 0115 $textarea->attr_transform_pre[] = new HTMLPurifier_AttrTransform_Textarea(); 0116 0117 $button = $this->addElement( 0118 'button', 0119 'Formctrl', 0120 'Optional: #PCDATA | Heading | List | Block | Inline', 0121 'Common', 0122 array( 0123 'accesskey' => 'Character', 0124 'disabled' => 'Bool#disabled', 0125 'name' => 'CDATA', 0126 'tabindex' => 'Number', 0127 'type' => 'Enum#button,submit,reset', 0128 'value' => 'CDATA', 0129 ) 0130 ); 0131 0132 // For exclusions, ideally we'd specify content sets, not literal elements 0133 $button->excludes = $this->makeLookup( 0134 'form', 0135 'fieldset', // Form 0136 'input', 0137 'select', 0138 'textarea', 0139 'label', 0140 'button', // Formctrl 0141 'a', // as per HTML 4.01 spec, this is omitted by modularization 0142 'isindex', 0143 'iframe' // legacy items 0144 ); 0145 0146 // Extra exclusion: img usemap="" is not permitted within this element. 0147 // We'll omit this for now, since we don't have any good way of 0148 // indicating it yet. 0149 0150 // This is HIGHLY user-unfriendly; we need a custom child-def for this 0151 $this->addElement('fieldset', 'Form', 'Custom: (#WS?,legend,(Flow|#PCDATA)*)', 'Common'); 0152 0153 $label = $this->addElement( 0154 'label', 0155 'Formctrl', 0156 'Optional: #PCDATA | Inline', 0157 'Common', 0158 array( 0159 'accesskey' => 'Character', 0160 // 'for' => 'IDREF', // IDREF not implemented, cannot allow 0161 ) 0162 ); 0163 $label->excludes = array('label' => true); 0164 0165 $this->addElement( 0166 'legend', 0167 false, 0168 'Optional: #PCDATA | Inline', 0169 'Common', 0170 array( 0171 'accesskey' => 'Character', 0172 ) 0173 ); 0174 0175 $this->addElement( 0176 'optgroup', 0177 false, 0178 'Required: option', 0179 'Common', 0180 array( 0181 'disabled' => 'Bool#disabled', 0182 'label*' => 'Text', 0183 ) 0184 ); 0185 // Don't forget an injector for <isindex>. This one's a little complex 0186 // because it maps to multiple elements. 0187 } 0188 } 0189 0190 // vim: et sw=4 sts=4