Commit | Line | Data |
---|---|---|
cea5b93a | 1 | <?php |
880bcb60 RK |
2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, | |
4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
cea5b93a RK |
5 | |
6 | class ExtendedDocument extends DOMDocument { | |
7 | // ExtendedDocument PHP class | |
8 | // this extends the general PHP DOM Document class to simplify some usual constructs | |
9 | // | |
10 | // function __construct([$version], [$encoding]) | |
11 | // CONSTRUCTOR | |
12 | // construct a new DOM Document that uses our element definitions | |
13 | // | |
b841a92b | 14 | // static function initHTML5([$doc]) |
14014b8f | 15 | // initialize as an HTML5 document and return references to its basic elements. |
b841a92b | 16 | // If a $doc is handed over (an ExtendedDocument or a derived class), load the content into that document. |
14014b8f | 17 | // returns an associative array with the following elements: 'html', 'head', 'title', 'body' |
ae41c41b | 18 | // |
61cc8aa9 | 19 | // public function appendElement($name, [$value]) |
cea5b93a RK |
20 | // appends a DOMDocument::createElement() as a child of this document (see there for params) |
21 | // returns the new child | |
22 | // | |
61cc8aa9 | 23 | // public function appendElementXML($name, $xmldata) |
cea5b93a RK |
24 | // appends a DOMDocument::createElement() with the given name as a child of this document, |
25 | // with an ExtendedDocument::createXMLFragment() of the given XML data inside | |
26 | // returns the new child | |
27 | // | |
b3cc0fef | 28 | // public function appendLink($target, [$value], [$title]) |
cea5b93a RK |
29 | // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params) |
30 | // returns the new child | |
31 | // | |
61cc8aa9 | 32 | // public function appendImage($src, [$alt_text]) |
53510e9e RK |
33 | // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params) |
34 | // returns the new child | |
35 | // | |
61cc8aa9 | 36 | // public function appendForm($action, $method, $name, [$id]) |
b8d16837 RK |
37 | // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params) |
38 | // returns the new child | |
39 | // | |
61cc8aa9 | 40 | // public function appendFormDiv($action, $method, $name, [$id]) |
ae41c41b RK |
41 | // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params) |
42 | // returns an HTML <div> that is a child of the new child | |
43 | // | |
61cc8aa9 | 44 | // public function appendInputHidden($name, $value) |
ae41c41b RK |
45 | // appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params) |
46 | // returns the new child | |
47 | // | |
61cc8aa9 | 48 | // public function appendInputText($name, $maxlength, $size, [$id], [$value]) |
ae41c41b RK |
49 | // appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params) |
50 | // returns the new child | |
51 | // | |
f925e4a1 RK |
52 | // public function appendInputPassword($name, $maxlength, $size, [$id], [$value]) |
53 | // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params) | |
54 | // returns the new child | |
55 | // | |
61cc8aa9 | 56 | // public function appendInputNumber($name, $maxlength, $size, [$id], [$value]) |
262e0bbb RK |
57 | // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params) |
58 | // returns the new child | |
59 | // | |
f925e4a1 RK |
60 | // public function appendInputRange($name, $id, $min, $max, [$step], [$value]) |
61 | // appends an ExtendedDocument::createElementInputRange() as a child of this document (see there for params) | |
62 | // returns the new child | |
63 | // | |
64 | // public function appendInputUrl($name, $maxlength, $size, [$id], [$value]) | |
65 | // appends an ExtendedDocument::createElementInputUrl() as a child of this document (see there for params) | |
66 | // returns the new child | |
67 | // | |
ea32f7e5 RK |
68 | // public function appendInputEmail($name, $maxlength, $size, [$id], [$value]) |
69 | // appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params) | |
70 | // returns the new child | |
71 | // | |
f925e4a1 RK |
72 | // public function appendInputTel($name, $maxlength, $size, [$id], [$value]) |
73 | // appends an ExtendedDocument::createElementInputTel() as a child of this document (see there for params) | |
74 | // returns the new child | |
75 | // | |
76 | // public function appendInputDate($name, [$id], [$min], [$max], [$value]) | |
77 | // appends an ExtendedDocument::createElementInputDate() as a child of this document (see there for params) | |
78 | // returns the new child | |
79 | // | |
80 | // public function appendInputTime($name, [$id], [$min], [$max], [$value]) | |
81 | // appends an ExtendedDocument::createElementInputTime() as a child of this document (see there for params) | |
82 | // returns the new child | |
83 | // | |
84 | // public function appendInputColor($name, [$id], [$value]) | |
85 | // appends an ExtendedDocument::createElementInputColor() as a child of this document (see there for params) | |
645a7eb6 RK |
86 | // returns the new child |
87 | // | |
61cc8aa9 | 88 | // public function appendInputRadio($name, $id, $value, $checked) |
ae41c41b RK |
89 | // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params) |
90 | // returns the new child | |
91 | // | |
61cc8aa9 | 92 | // public function appendInputCheckbox($name, $id, $value, $checked) |
ae41c41b RK |
93 | // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params) |
94 | // returns the new child | |
95 | // | |
61cc8aa9 | 96 | // public function appendInputFile($name, $id, $accept) |
4bb9d784 RK |
97 | // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params) |
98 | // returns the new child | |
99 | // | |
61cc8aa9 | 100 | // public function appendInputSubmit($value) |
ae41c41b RK |
101 | // appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params) |
102 | // returns the new child | |
103 | // | |
61cc8aa9 | 104 | // public function appendButton($value, $onclick = null) |
1109f526 RK |
105 | // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params) |
106 | // returns the new child | |
107 | // | |
61cc8aa9 | 108 | // public function appendTextArea($name, $columns, $rows, [$id], [$value]) |
bf91764c RK |
109 | // appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params) |
110 | // returns the new child | |
111 | // | |
69409ddb | 112 | // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch]) |
bf91764c RK |
113 | // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params) |
114 | // returns the new child | |
115 | // | |
61cc8aa9 | 116 | // public function appendElementOption($key, $desc, [$selected]) |
bf91764c RK |
117 | // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params) |
118 | // returns the new child | |
119 | // | |
61cc8aa9 | 120 | // public function appendLabel($for_id, $value) |
ae41c41b RK |
121 | // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params) |
122 | // returns the new child | |
123 | // | |
61cc8aa9 | 124 | // public function appendText($text) |
cea5b93a RK |
125 | // appends a DOMDocument::createTextNode() as a child of this document (see there for params) |
126 | // returns the new child | |
127 | // | |
71771b0c RK |
128 | // public function appendLinebreak() |
129 | // appends a <br> as a child of this document | |
130 | // returns the new child | |
131 | // | |
6638efd5 RK |
132 | // public function appendEntity($name) |
133 | // appends a DOMDocument::createEntityReference() as a child of this document (see there for params) | |
134 | // returns the new child | |
135 | // | |
61cc8aa9 | 136 | // public function appendComment($comment_data) |
cadc5980 RK |
137 | // appends a DOMDocument::createComment() as a child of this document (see there for params) |
138 | // returns the new child | |
139 | // | |
61cc8aa9 | 140 | // public function appendHTMLMarkup($htmldata, [$parentNode]) |
ae41c41b RK |
141 | // appends a representation of the HTML data as children of the given parent node, by default this document |
142 | // NO return value! | |
143 | // | |
61cc8aa9 | 144 | // public function appendXMLMarkup($xmldata, [$parentNode]) |
ae41c41b | 145 | // appends a representation of the XML data as children of the given parent node, by default this document |
cea5b93a RK |
146 | // NO return value! |
147 | // | |
61cc8aa9 | 148 | // public function appendJSElement($jsdata) |
cea5b93a RK |
149 | // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params) |
150 | // NO return value! | |
151 | // | |
8afa2e61 | 152 | // public function appendJSFile($jsURL, [$defer], [$async]) |
ea32f7e5 RK |
153 | // appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params) |
154 | // returns the new child | |
155 | // | |
b3cc0fef RK |
156 | // public function createElementLink($target, [$value], [$title]) |
157 | // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value as well as (optional) title attribute | |
cea5b93a | 158 | // |
61cc8aa9 | 159 | // public function createElementImage($src, [$alt_text]) |
b3cc0fef | 160 | // returns an ExtendedElement that is an HTML <img> with the given src and alt attributes (set to '' by default) |
53510e9e | 161 | // |
61cc8aa9 | 162 | // public function createElementForm($action, $method, $name) |
ae41c41b RK |
163 | // returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form> |
164 | // with the given action, method, and name | |
165 | // | |
61cc8aa9 | 166 | // public function createElementInputHidden($name, $value) |
ae41c41b RK |
167 | // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value |
168 | // | |
61cc8aa9 | 169 | // public function createElementInputText($name, $maxlength, $size, [$id], [$value]) |
ae41c41b RK |
170 | // returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size, |
171 | // and optionally id and value | |
172 | // | |
f925e4a1 RK |
173 | // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value]) |
174 | // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size, | |
175 | // and optionally id and value | |
176 | // | |
61cc8aa9 | 177 | // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value]) |
262e0bbb RK |
178 | // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size, |
179 | // and optionally id and value | |
180 | // | |
f925e4a1 RK |
181 | // public function createElementInputRange($name, $id, $min, $max, [$step], [$value]) |
182 | // returns an ExtendedElement that is an HTML <input> of type 'range' with the given name, id, min, max, | |
183 | // and optionally step and value | |
184 | // | |
185 | // public function createElementInputUrl($name, $maxlength, $size, [$id], [$value]) | |
186 | // returns an ExtendedElement that is an HTML <input> of type 'url' with the given name, maxlength, size, | |
187 | // and optionally id and value | |
188 | // | |
ea32f7e5 RK |
189 | // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value]) |
190 | // returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size, | |
191 | // and optionally id and value | |
192 | // | |
f925e4a1 RK |
193 | // public function createElementInputTel($name, $maxlength, $size, [$id], [$value]) |
194 | // returns an ExtendedElement that is an HTML <input> of type 'tel' with the given name, maxlength, size, | |
195 | // and optionally id and value | |
196 | // | |
197 | // public function createElementInputDate($name, [$id], [$min], [$max], [$value]) | |
198 | // returns an ExtendedElement that is an HTML <input> of type 'date' with the given name, | |
199 | // and optionally id, min, max, and value | |
200 | // | |
201 | // public function createElementInputTime($name, [$id], [$min], [$max], [$value]) | |
202 | // returns an ExtendedElement that is an HTML <input> of type 'time' with the given name, | |
203 | // and optionally id, min, max, and value | |
204 | // | |
205 | // public function createElementInputColor($name, [$id], [$value]) | |
206 | // returns an ExtendedElement that is an HTML <input> of type 'color' with the given name, | |
645a7eb6 RK |
207 | // and optionally id and value |
208 | // | |
61cc8aa9 | 209 | // public function createElementInputRadio($name, $id, $value, $checked) |
ae41c41b RK |
210 | // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and |
211 | // checked state | |
212 | // | |
61cc8aa9 | 213 | // public function createElementInputCheckbox($name, $id, $value, $checked) |
ae41c41b RK |
214 | // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and |
215 | // checked state | |
216 | // | |
61cc8aa9 | 217 | // public function createElementInputFile($name, $id, $accept) |
4bb9d784 RK |
218 | // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept |
219 | // | |
61cc8aa9 | 220 | // public function createElementInputSubmit($value) |
1109f526 RK |
221 | // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label |
222 | // | |
61cc8aa9 | 223 | // public function createElementButton($value, $onclick = null) |
1109f526 | 224 | // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute |
ae41c41b | 225 | // |
61cc8aa9 | 226 | // public function createElementTextArea($name, $columns, $rows, [$id], [$value]) |
bf91764c RK |
227 | // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows, |
228 | // and optionally id and value | |
229 | // | |
69409ddb | 230 | // public function createElementSelect($name, [$id], [$options], [$default], [$strictmatch]) |
bf91764c | 231 | // returns an ExtendedElement that is an HTML <select> with the given name, and optionally id, |
69409ddb | 232 | // array of options (key => description) and key of the by-default selected entry (matched including type when strictmatch is true) |
bf91764c | 233 | // |
61cc8aa9 | 234 | // public function createElementOption($key, $desc, [$selected]) |
bf91764c RK |
235 | // returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content) |
236 | // and optionally bool that tells if the entry is selected | |
237 | // | |
61cc8aa9 | 238 | // public function createElementLabel($for_id, $value) |
ae41c41b | 239 | // returns an ExtendedElement that is an HTML <label> with the given 'for' and value |
cea5b93a | 240 | // |
61cc8aa9 | 241 | // public function createElementJS($jsdata) |
cea5b93a | 242 | // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside |
c1666e91 | 243 | // |
8afa2e61 | 244 | // public function createElementJSFile($jsURL, [$defer], [$async]) |
ea32f7e5 | 245 | // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL |
8afa2e61 | 246 | // $defer and $async are boolean attributes that set if the script should be executed after parsing but before onload, and if it should be loaded asynchronously. |
cea5b93a RK |
247 | |
248 | function __construct($version = '1.0', $encoding = 'utf-8') { | |
249 | // make sure the default DOMDocument constructor runs | |
250 | parent::__construct($version, $encoding); | |
251 | $this->registerNodeClass('DOMElement', 'ExtendedElement'); | |
bf91764c | 252 | $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment'); |
cea5b93a RK |
253 | } |
254 | ||
b841a92b RK |
255 | static function initHTML5($doc = null) { |
256 | if (is_null($doc)) { $doc = new ExtendedDocument(); } | |
14014b8f RK |
257 | $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly. |
258 | ||
259 | // Created basic HTML document structure. | |
260 | $root = $doc->getElementsByTagName('html')->item(0); | |
261 | $head = $root->appendElement('head'); | |
262 | $title = $head->appendElement('title'); | |
263 | $body = $root->appendElement('body'); | |
264 | ||
265 | return array('document' => $doc, | |
266 | 'html' => $root, | |
267 | 'head' => $head, | |
268 | 'title' => $title, | |
269 | 'body' => $body); | |
270 | } | |
271 | ||
61cc8aa9 | 272 | public function appendElement($name, $value = '') { |
a8816f43 | 273 | return $this->appendChild($this->createElement($name, $value)); |
cea5b93a | 274 | } |
61cc8aa9 | 275 | public function appendElementXML($name, $xmldata) { |
cea5b93a | 276 | $aelem = $this->appendChild($this->createElement($name)); |
ae41c41b RK |
277 | $aelem->appendXMLMarkup($xmldata); |
278 | //$aelem->appendChild($this->createXMLFragment($xmldata)); | |
cea5b93a RK |
279 | return $aelem; |
280 | } | |
b3cc0fef RK |
281 | public function appendLink($target, $value = '', $title = null) { |
282 | return $this->appendChild($this->createElementLink($target, $value, $title)); | |
cea5b93a | 283 | } |
61cc8aa9 | 284 | public function appendImage($src, $alt_text = '') { |
4aa31782 RK |
285 | return $this->appendChild($this->createElementImage($src, $alt_text)); |
286 | } | |
61cc8aa9 | 287 | public function appendForm($action, $method, $name, $id = null) { |
b8d16837 RK |
288 | return $this->appendChild($this->createElementForm($action, $method, $name, $id)); |
289 | } | |
61cc8aa9 | 290 | public function appendFormDiv($action, $method, $name, $id = null) { |
b8d16837 | 291 | $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id)); |
ae41c41b RK |
292 | return $formelem->appendElement('div'); |
293 | } | |
61cc8aa9 | 294 | public function appendInputHidden($name, $value) { |
ae41c41b RK |
295 | return $this->appendChild($this->createElementInputHidden($name, $value)); |
296 | } | |
61cc8aa9 | 297 | public function appendInputText($name, $maxlength, $size, $id = null, $value = null) { |
ae41c41b RK |
298 | return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value)); |
299 | } | |
f925e4a1 RK |
300 | public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) { |
301 | return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value)); | |
302 | } | |
61cc8aa9 | 303 | public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) { |
262e0bbb RK |
304 | return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value)); |
305 | } | |
f925e4a1 RK |
306 | public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) { |
307 | return $this->appendChild($this->createElementInputRange($name, $id, $min, $max, $step, $value)); | |
308 | } | |
309 | public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) { | |
310 | return $this->appendChild($this->createElementInputUrl($name, $maxlength, $size, $id, $value)); | |
311 | } | |
ea32f7e5 RK |
312 | public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) { |
313 | return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value)); | |
314 | } | |
f925e4a1 RK |
315 | public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) { |
316 | return $this->appendChild($this->createElementInputTel($name, $maxlength, $size, $id, $value)); | |
317 | } | |
318 | public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) { | |
319 | return $this->appendChild($this->createElementInputDate($name, $id, $min, $max, $value)); | |
320 | } | |
321 | public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) { | |
322 | return $this->appendChild($this->createElementInputTime($name, $id, $min, $max, $value)); | |
323 | } | |
324 | public function appendInputColor($name, $id = null, $value = null) { | |
325 | return $this->appendChild($this->createElementInputColor($name, $id, $value)); | |
645a7eb6 | 326 | } |
61cc8aa9 | 327 | public function appendInputRadio($name, $id, $value, $checked) { |
ae41c41b RK |
328 | return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked)); |
329 | } | |
61cc8aa9 | 330 | public function appendInputCheckbox($name, $id, $value, $checked) { |
ae41c41b RK |
331 | return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked)); |
332 | } | |
61cc8aa9 | 333 | public function appendInputFile($name, $id, $accept) { |
4bb9d784 RK |
334 | return $this->appendChild($this->createElementInputFile($name, $id, $accept)); |
335 | } | |
61cc8aa9 | 336 | public function appendInputSubmit($value) { |
ae41c41b RK |
337 | return $this->appendChild($this->createElementInputSubmit($value)); |
338 | } | |
61cc8aa9 | 339 | public function appendButton($value, $onclick = null) { |
1109f526 RK |
340 | return $this->appendChild($this->createElementButton($value, $onclick)); |
341 | } | |
61cc8aa9 | 342 | public function appendTextArea($name, $columns, $rows, $id = null, $value = null) { |
bf91764c RK |
343 | return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value)); |
344 | } | |
69409ddb RK |
345 | public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) { |
346 | return $this->appendChild($this->createElementSelect($name, $id, $options, $default, $strictmatch)); | |
bf91764c | 347 | } |
61cc8aa9 | 348 | public function appendElementOption($key, $desc, $selected = false) { |
bf91764c RK |
349 | return $this->appendChild($this->createElementOption($key, $desc, $selected)); |
350 | } | |
61cc8aa9 | 351 | public function appendLabel($for_id, $value) { |
ae41c41b RK |
352 | return $this->appendChild($this->createElementLabel($for_id, $value)); |
353 | } | |
61cc8aa9 | 354 | public function appendText($text) { |
cea5b93a RK |
355 | return $this->appendChild($this->createTextNode($text)); |
356 | } | |
71771b0c RK |
357 | public function appendLinebreak() { |
358 | return $this->appendChild($this->createElement('br')); | |
359 | } | |
6638efd5 RK |
360 | public function appendEntity($name) { |
361 | return $this->appendChild($this->createEntityReference($name)); | |
362 | } | |
61cc8aa9 | 363 | public function appendComment($comment_data) { |
cadc5980 RK |
364 | return $this->appendChild($this->createComment($comment_data)); |
365 | } | |
61cc8aa9 | 366 | public function appendJSElement($jsdata) { |
cea5b93a RK |
367 | $this->appendChild($this->createElementJS($jsdata)); |
368 | } | |
8afa2e61 RK |
369 | public function appendJSFile($jsdata, $defer = false, $async = false) { |
370 | return $this->appendChild($this->createElementJSFile($jsdata, $defer, $async)); | |
ea32f7e5 | 371 | } |
cea5b93a | 372 | |
61cc8aa9 | 373 | public function appendHTMLMarkup($htmldata, $parentNode = null) { |
ae41c41b | 374 | if (is_null($parentNode)) { $parentNode =& $this; } |
a9a5a68a RK |
375 | // Use loadHTML() to parse and turn the markup into proper HTML. |
376 | $tmpdoc = new ExtendedDocument; | |
377 | // The XML line is needed to tell the parser that we need UTF-8 parsing. | |
378 | $tmpdoc->loadHTML('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html><body>'.$htmldata.'</body></html>'); | |
379 | foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) { | |
380 | $parentNode->appendChild($this->importNode($child, true)); | |
381 | } | |
ae41c41b RK |
382 | } |
383 | ||
61cc8aa9 | 384 | public function appendXMLMarkup($xmldata, $parentNode = null) { |
ae41c41b RK |
385 | if (is_null($parentNode)) { $parentNode =& $this; } |
386 | $tmpdoc = new ExtendedDocument; | |
387 | $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n"; | |
388 | $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n"; | |
389 | $tmpxml .= '<root>'.$xmldata.'</root>'; | |
390 | $tmpdoc->loadXML($tmpxml); | |
391 | foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) { | |
392 | $parentNode->appendChild($this->importNode($child, true)); | |
393 | } | |
cea5b93a RK |
394 | } |
395 | ||
61cc8aa9 | 396 | public function createElement($name, $value = '') { |
a8816f43 RK |
397 | // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that. |
398 | $aelem = parent::createElement($name); | |
b3cc0fef | 399 | if (strlen($value)) { $aelem->appendText($value); } |
a8816f43 RK |
400 | return $aelem; |
401 | } | |
402 | ||
b3cc0fef | 403 | public function createElementLink($target, $value = '', $title = null) { |
a8816f43 | 404 | $link = $this->createElement('a', $value); |
bf91764c | 405 | $link->setAttribute('href', $target); // XXX: take care of & etc. in links |
b3cc0fef | 406 | if (!is_null($title)) { $link->setAttribute('title', $title); } |
cea5b93a RK |
407 | return $link; |
408 | } | |
409 | ||
61cc8aa9 | 410 | public function createElementImage($src, $alt_text = '') { |
319cfe8d RK |
411 | $img = $this->createElement('img'); |
412 | $img->setAttribute('src', $src); | |
413 | $img->setAttribute('alt', $alt_text); | |
414 | return $img; | |
4aa31782 RK |
415 | } |
416 | ||
61cc8aa9 | 417 | public function createElementForm($action, $method, $name, $id = null) { |
ae41c41b RK |
418 | $formelem = $this->createElement('form'); |
419 | $formelem->setAttribute('action', $action); | |
420 | $formelem->setAttribute('method', $method); | |
421 | $formelem->setAttribute('name', $name); | |
b3cc0fef | 422 | if (!is_null($id)) { $formelem->setAttribute('id', $id); } |
ae41c41b RK |
423 | return $formelem; |
424 | } | |
425 | ||
61cc8aa9 | 426 | public function createElementInputHidden($name, $value) { |
ae41c41b RK |
427 | $hidden = $this->createElement('input'); |
428 | $hidden->setAttribute('type', 'hidden'); | |
429 | $hidden->setAttribute('name', $name); | |
430 | $hidden->setAttribute('value', $value); | |
431 | return $hidden; | |
432 | } | |
433 | ||
61cc8aa9 | 434 | public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) { |
ae41c41b RK |
435 | $txfield = $this->createElement('input'); |
436 | $txfield->setAttribute('type', 'text'); | |
437 | if (!is_null($id)) { $txfield->setAttribute('id', $id); } | |
438 | $txfield->setAttribute('name', $name); | |
439 | $txfield->setAttribute('maxlength', $maxlength); | |
440 | $txfield->setAttribute('size', $size); | |
441 | if (!is_null($value)) { $txfield->setAttribute('value', $value); } | |
442 | return $txfield; | |
443 | } | |
444 | ||
61cc8aa9 | 445 | public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) { |
319cfe8d RK |
446 | $pwfield = $this->createElement('input'); |
447 | $pwfield->setAttribute('type', 'password'); | |
448 | if (!is_null($id)) { $pwfield->setAttribute('id', $id); } | |
449 | $pwfield->setAttribute('name', $name); | |
450 | $pwfield->setAttribute('maxlength', $maxlength); | |
451 | $pwfield->setAttribute('size', $size); | |
452 | if (!is_null($value)) { $pwfield->setAttribute('value', $value); } | |
453 | return $pwfield; | |
645a7eb6 RK |
454 | } |
455 | ||
f925e4a1 RK |
456 | public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) { |
457 | $numfield = $this->createElement('input'); | |
458 | $numfield->setAttribute('type', 'number'); | |
459 | if (!is_null($id)) { $numfield->setAttribute('id', $id); } | |
460 | $numfield->setAttribute('name', $name); | |
461 | $numfield->setAttribute('maxlength', $maxlength); | |
462 | $numfield->setAttribute('size', $size); | |
463 | if (!is_null($value)) { $numfield->setAttribute('value', $value); } | |
464 | return $numfield; | |
465 | } | |
466 | ||
467 | public function createElementInputRange($name, $id, $min, $max, $step = null, $value = null) { | |
468 | $rgfield = $this->createElement('input'); | |
469 | $rgfield->setAttribute('type', 'range'); | |
470 | if (!is_null($id)) { $rgfield->setAttribute('id', $id); } | |
471 | $rgfield->setAttribute('name', $name); | |
472 | if (!is_null($min)) { $rgfield->setAttribute('min', $min); } | |
473 | if (!is_null($max)) { $rgfield->setAttribute('max', $max); } | |
474 | if (!is_null($step)) { $rgfield->setAttribute('step', $step); } | |
475 | if (!is_null($value)) { $rgfield->setAttribute('value', $value); } | |
476 | return $rgfield; | |
477 | } | |
478 | ||
479 | public function createElementInputUrl($name, $maxlength, $size, $id = null, $value = null) { | |
480 | $urlfield = $this->createElement('input'); | |
481 | $urlfield->setAttribute('type', 'url'); | |
482 | if (!is_null($id)) { $urlfield->setAttribute('id', $id); } | |
483 | $urlfield->setAttribute('name', $name); | |
484 | $urlfield->setAttribute('maxlength', $maxlength); | |
485 | $urlfield->setAttribute('size', $size); | |
486 | if (!is_null($value)) { $urlfield->setAttribute('value', $value); } | |
487 | return $urlfield; | |
488 | } | |
489 | ||
490 | public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) { | |
491 | $mailfield = $this->createElement('input'); | |
492 | $mailfield->setAttribute('type', 'email'); | |
493 | if (!is_null($id)) { $mailfield->setAttribute('id', $id); } | |
494 | $mailfield->setAttribute('name', $name); | |
495 | $mailfield->setAttribute('maxlength', $maxlength); | |
496 | $mailfield->setAttribute('size', $size); | |
497 | if (!is_null($value)) { $mailfield->setAttribute('value', $value); } | |
498 | return $mailfield; | |
499 | } | |
500 | ||
501 | public function createElementInputTel($name, $maxlength, $size, $id = null, $value = null) { | |
502 | $telfield = $this->createElement('input'); | |
503 | $telfield->setAttribute('type', 'tel'); | |
504 | if (!is_null($id)) { $telfield->setAttribute('id', $id); } | |
505 | $telfield->setAttribute('name', $name); | |
506 | $telfield->setAttribute('maxlength', $maxlength); | |
507 | $telfield->setAttribute('size', $size); | |
508 | if (!is_null($value)) { $telfield->setAttribute('value', $value); } | |
509 | return $telfield; | |
510 | } | |
511 | ||
512 | public function createElementInputDate($name, $id = null, $min = null, $max = null, $value = null) { | |
513 | $telfield = $this->createElement('input'); | |
514 | $telfield->setAttribute('type', 'date'); | |
515 | if (!is_null($id)) { $telfield->setAttribute('id', $id); } | |
516 | if (!is_null($min)) { $rgfield->setAttribute('min', $min); } | |
517 | if (!is_null($max)) { $rgfield->setAttribute('max', $max); } | |
518 | if (!is_null($value)) { $telfield->setAttribute('value', $value); } | |
519 | return $telfield; | |
520 | } | |
521 | ||
522 | public function createElementInputTime($name, $id = null, $min = null, $max = null, $value = null) { | |
523 | $telfield = $this->createElement('input'); | |
524 | $telfield->setAttribute('type', 'time'); | |
525 | if (!is_null($id)) { $telfield->setAttribute('id', $id); } | |
526 | if (!is_null($min)) { $rgfield->setAttribute('min', $min); } | |
527 | if (!is_null($max)) { $rgfield->setAttribute('max', $max); } | |
528 | if (!is_null($value)) { $telfield->setAttribute('value', $value); } | |
529 | return $telfield; | |
530 | } | |
531 | ||
532 | public function createElementInputColor($name, $id = null, $value = null) { | |
533 | $colfield = $this->createElement('input'); | |
534 | $colfield->setAttribute('type', 'color'); | |
535 | if (!is_null($id)) { $colfield->setAttribute('id', $id); } | |
536 | $colfield->setAttribute('name', $name); | |
537 | if (!is_null($value)) { $colfield->setAttribute('value', $value); } | |
538 | return $colfield; | |
539 | } | |
540 | ||
61cc8aa9 | 541 | public function createElementInputRadio($name, $id, $value, $checked) { |
ae41c41b RK |
542 | $radio = $this->createElement('input'); |
543 | $radio->setAttribute('type', 'radio'); | |
544 | $radio->setAttribute('name', $name); | |
4bb9d784 | 545 | if (!is_null($id)) { $radio->setAttribute('id', $id); } |
ae41c41b RK |
546 | $radio->setAttribute('value', $value); |
547 | if ($checked) { $radio->setAttribute('checked', ''); } | |
548 | return $radio; | |
549 | } | |
550 | ||
61cc8aa9 | 551 | public function createElementInputCheckbox($name, $id, $value, $checked) { |
ae41c41b RK |
552 | $cbox = $this->createElement('input'); |
553 | $cbox->setAttribute('type', 'checkbox'); | |
554 | $cbox->setAttribute('name', $name); | |
4bb9d784 | 555 | if (!is_null($id)) { $cbox->setAttribute('id', $id); } |
ae41c41b RK |
556 | $cbox->setAttribute('value', $value); |
557 | if ($checked) { $cbox->setAttribute('checked', ''); } | |
558 | return $cbox; | |
559 | } | |
560 | ||
61cc8aa9 | 561 | public function createElementInputFile($name, $id, $accept) { |
4bb9d784 RK |
562 | $fileinput = $this->createElement('input'); |
563 | $fileinput->setAttribute('type', 'file'); | |
564 | $fileinput->setAttribute('name', $name); | |
565 | if (!is_null($id)) { $fileinput->setAttribute('id', $id); } | |
566 | $fileinput->setAttribute('accept', $accept); | |
567 | return $fileinput; | |
568 | } | |
569 | ||
61cc8aa9 | 570 | public function createElementInputSubmit($value) { |
ae41c41b RK |
571 | $submitbtn = $this->createElement('input'); |
572 | $submitbtn->setAttribute('type', 'submit'); | |
573 | $submitbtn->setAttribute('value', $value); | |
574 | return $submitbtn; | |
575 | } | |
576 | ||
61cc8aa9 | 577 | public function createElementButton($value, $onclick = null) { |
1109f526 RK |
578 | $btn = $this->createElement('input'); |
579 | $btn->setAttribute('type', 'button'); | |
580 | $btn->setAttribute('value', $value); | |
581 | if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); } | |
582 | return $btn; | |
583 | } | |
584 | ||
61cc8aa9 | 585 | public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) { |
bf91764c RK |
586 | $txtarea = $this->createElement('textarea', $value); |
587 | $txtarea->setAttribute('name', $name); | |
588 | $txtarea->setAttribute('cols', $columns); | |
589 | $txtarea->setAttribute('rows', $rows); | |
590 | if (!is_null($id)) { $txtarea->setAttribute('id', $id); } | |
591 | return $txtarea; | |
592 | } | |
593 | ||
69409ddb | 594 | public function createElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) { |
bf91764c RK |
595 | $select = $this->createElement('select'); |
596 | $select->setAttribute('name', $name); | |
597 | if (!is_null($id)) { $select->setAttribute('id', $id); } | |
598 | foreach ($options as $key => $desc) { | |
69409ddb | 599 | $select->appendElementOption($key, $desc, $strictmatch ? ($key === $default) : ($key == $default)); |
bf91764c RK |
600 | } |
601 | return $select; | |
602 | } | |
603 | ||
61cc8aa9 | 604 | public function createElementOption($key, $desc, $selected = false) { |
bf91764c RK |
605 | $option = $this->createElement('option', $desc); |
606 | $option->setAttribute('value', $key); | |
607 | if ($selected) { $option->setAttribute('selected', ''); } | |
608 | return $option; | |
609 | } | |
610 | ||
61cc8aa9 | 611 | public function createElementLabel($for_id, $value) { |
ae41c41b RK |
612 | $label = $this->createElement('label', $value); |
613 | $label->setAttribute('for', $for_id); | |
614 | return $label; | |
cea5b93a RK |
615 | } |
616 | ||
61cc8aa9 | 617 | public function createElementJS($jsdata) { |
cea5b93a | 618 | $jselem = $this->createElement('script'); |
ea32f7e5 | 619 | // Note: type can/should be left out for HTML5. |
cea5b93a RK |
620 | $jselem->setAttribute('type', 'text/javascript'); |
621 | $jselem->appendChild($this->createCDATASection($jsdata)); | |
622 | return $jselem; | |
623 | } | |
c1666e91 | 624 | |
8afa2e61 | 625 | public function createElementJSFile($jsURL, $defer = false, $async = false) { |
ea32f7e5 RK |
626 | $jselem = $this->createElement('script'); |
627 | // Note: type can/should be left out for HTML5. | |
628 | $jselem->setAttribute('type', 'text/javascript'); | |
8afa2e61 RK |
629 | if ($defer) { |
630 | $jselem->setAttribute('defer', ''); | |
631 | } | |
632 | if ($async) { | |
633 | $jselem->setAttribute('async', ''); | |
634 | } | |
ea32f7e5 RK |
635 | $jselem->setAttribute('src', $jsURL); |
636 | return $jselem; | |
637 | } | |
cea5b93a RK |
638 | } |
639 | ||
640 | class ExtendedElement extends DOMElement { | |
641 | // ExtendedElement PHP class | |
642 | // this extends the general PHP DOM Element class to simplify some usual constructs | |
643 | // | |
61cc8aa9 | 644 | // public function appendElement($name, [$value]) |
cea5b93a RK |
645 | // appends a DOMDocument::createElement() as a child of this element (see there for params) |
646 | // returns the new child | |
647 | // | |
61cc8aa9 | 648 | // public function appendElementXML($name, $xmldata) |
cea5b93a RK |
649 | // appends a DOMDocument::createElement() with the given name as a child of this element, |
650 | // with an ExtendedDocument::createXMLFragment() of the given XML data inside | |
651 | // returns the new child | |
652 | // | |
b3cc0fef | 653 | // public function appendLink($target, [$value], [$title]) |
cea5b93a RK |
654 | // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params) |
655 | // returns the new child | |
656 | // | |
61cc8aa9 | 657 | // public function appendImage($src, [$alt_text]) |
53510e9e RK |
658 | // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params) |
659 | // returns the new child | |
660 | // | |
61cc8aa9 | 661 | // public function appendForm($action, $method, $name, [$id]) |
b8d16837 RK |
662 | // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params) |
663 | // returns the new child | |
664 | // | |
61cc8aa9 | 665 | // public function appendFormDiv($action, $method, $name, [$id]) |
ae41c41b RK |
666 | // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params) |
667 | // returns an HTML <div> that is a child of the new child | |
668 | // | |
61cc8aa9 | 669 | // public function appendInputHidden($name, $value) |
ae41c41b RK |
670 | // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params) |
671 | // returns the new child | |
672 | // | |
61cc8aa9 | 673 | // public function appendInputText($name, $maxlength, $size, [$id], [$value]) |
ae41c41b RK |
674 | // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params) |
675 | // returns the new child | |
676 | // | |
f925e4a1 RK |
677 | // public function appendInputPassword($name, $maxlength, $size, [$id], [$value]) |
678 | // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params) | |
679 | // returns the new child | |
680 | // | |
61cc8aa9 | 681 | // public function appendInputNumber($name, $maxlength, $size, [$id], [$value]) |
262e0bbb RK |
682 | // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params) |
683 | // returns the new child | |
684 | // | |
f925e4a1 RK |
685 | // public function appendInputRange($name, $id, $min, $max, [$step], [$value]) |
686 | // appends an ExtendedDocument::createElementInputRange() as a child of this element (see there for params) | |
687 | // returns the new child | |
688 | // | |
689 | // public function appendInputUrl($name, $maxlength, $size, [$id], [$value]) | |
690 | // appends an ExtendedDocument::createElementInputUrl() as a child of this element (see there for params) | |
691 | // returns the new child | |
692 | // | |
ea32f7e5 RK |
693 | // public function appendInputEmail($name, $maxlength, $size, [$id], [$value]) |
694 | // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params) | |
695 | // returns the new child | |
696 | // | |
f925e4a1 RK |
697 | // public function appendInputTel($name, $maxlength, $size, [$id], [$value]) |
698 | // appends an ExtendedDocument::createElementInputTel() as a child of this element (see there for params) | |
699 | // returns the new child | |
700 | // | |
701 | // public function appendInputDate($name, [$id], [$min], [$max], [$value]) | |
702 | // appends an ExtendedDocument::createElementInputDate() as a child of this element (see there for params) | |
703 | // returns the new child | |
704 | // | |
705 | // public function appendInputTime($name, [$id], [$min], [$max], [$value]) | |
706 | // appends an ExtendedDocument::createElementInputTime() as a child of this element (see there for params) | |
645a7eb6 RK |
707 | // returns the new child |
708 | // | |
f925e4a1 RK |
709 | // public function appendInputColor($name, [$id], [$value]) |
710 | // appends an ExtendedDocument::createElementInputColor() as a child of this element (see there for params) | |
711 | // | |
61cc8aa9 | 712 | // public function appendInputRadio($name, $id, $value, $checked) |
ae41c41b RK |
713 | // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params) |
714 | // returns the new child | |
715 | // | |
61cc8aa9 | 716 | // public function appendInputCheckbox($name, $id, $value, $checked) |
ae41c41b RK |
717 | // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params) |
718 | // returns the new child | |
719 | // | |
61cc8aa9 | 720 | // public function appendInputFile($name, $id, $accept) |
4bb9d784 RK |
721 | // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params) |
722 | // returns the new child | |
723 | // | |
61cc8aa9 | 724 | // public function appendInputSubmit($value) |
ae41c41b RK |
725 | // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params) |
726 | // returns the new child | |
727 | // | |
61cc8aa9 | 728 | // public function appendButton($value, $onclick = null) |
1109f526 RK |
729 | // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params) |
730 | // returns the new child | |
731 | // | |
61cc8aa9 | 732 | // public function appendTextArea($name, $columns, $rows, [$id], [$value]) |
bf91764c RK |
733 | // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params) |
734 | // returns the new child | |
735 | // | |
69409ddb | 736 | // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch]) |
bf91764c RK |
737 | // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params) |
738 | // returns the new child | |
739 | // | |
61cc8aa9 | 740 | // public function appendElementOption($key, $desc, [$selected]) |
bf91764c RK |
741 | // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params) |
742 | // returns the new child | |
743 | // | |
61cc8aa9 | 744 | // public function appendLabel($for_id, $value) |
ae41c41b RK |
745 | // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params) |
746 | // returns the new child | |
747 | // | |
61cc8aa9 | 748 | // public function appendText($text) |
cea5b93a RK |
749 | // appends a DOMDocument::createTextNode() as a child of this element (see there for params) |
750 | // returns the new child | |
751 | // | |
71771b0c RK |
752 | // public function appendLinebreak() |
753 | // appends a <br> as a child of this element | |
754 | // returns the new child | |
755 | // | |
6638efd5 RK |
756 | // public function appendEntity($name) |
757 | // appends a DOMDocument::createEntityReference() as a child of this element (see there for params) | |
758 | // returns the new child | |
759 | // | |
61cc8aa9 | 760 | // public function appendComment($comment_data) |
cadc5980 RK |
761 | // appends a DOMDocument::createComment() as a child of this element (see there for params) |
762 | // returns the new child | |
763 | // | |
61cc8aa9 | 764 | // public function appendHTMLMarkup($htmldata) |
ae41c41b RK |
765 | // appends a representation of the HTML data as children of this element |
766 | // NO return value! | |
767 | // | |
61cc8aa9 | 768 | // public function appendXMLMarkup($xmldata) |
ae41c41b | 769 | // appends a representation of the XML data as children of this element |
cea5b93a RK |
770 | // NO return value! |
771 | // | |
61cc8aa9 | 772 | // public function appendJSElement($jsdata) |
cea5b93a RK |
773 | // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params) |
774 | // NO return value! | |
c1666e91 | 775 | // |
8afa2e61 | 776 | // public function appendJSFile($jsURL, [$defer], [$async]) |
0bbc241e | 777 | // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params) |
ea32f7e5 | 778 | // returns the new child |
f887cdcb RK |
779 | // |
780 | // public function setClass($classname) | |
781 | // sets the 'class' attribute of the element to the given classname value | |
782 | // | |
783 | // public function addClass($classname) | |
784 | // adds the given classname value to the space-separated list in the 'class' attribute | |
785 | // returns the value of the 'class' attribute | |
786 | // | |
787 | // public function setID($elem_id) | |
788 | // sets the 'id' attribute of the element to the given elem_id value | |
cea5b93a | 789 | |
61cc8aa9 | 790 | public function appendElement($name, $value = '') { |
a8816f43 | 791 | return $this->appendChild($this->ownerDocument->createElement($name, $value)); |
cea5b93a | 792 | } |
61cc8aa9 | 793 | public function appendElementXML($name, $xmldata) { |
cea5b93a | 794 | $aelem = $this->appendChild($this->ownerDocument->createElement($name)); |
ae41c41b | 795 | $aelem->appendXMLMarkup($xmldata); |
cea5b93a RK |
796 | return $aelem; |
797 | } | |
b3cc0fef RK |
798 | public function appendLink($target, $value = '', $title = null) { |
799 | return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title)); | |
cea5b93a | 800 | } |
61cc8aa9 | 801 | public function appendImage($src, $alt_text = '') { |
53510e9e RK |
802 | return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text)); |
803 | } | |
61cc8aa9 | 804 | public function appendForm($action, $method, $name, $id = null) { |
b8d16837 RK |
805 | return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id)); |
806 | } | |
61cc8aa9 | 807 | public function appendFormDiv($action, $method, $name, $id = null) { |
b8d16837 | 808 | $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id)); |
ae41c41b RK |
809 | return $formelem->appendElement('div'); |
810 | } | |
61cc8aa9 | 811 | public function appendInputHidden($name, $value) { |
ae41c41b RK |
812 | return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value)); |
813 | } | |
61cc8aa9 | 814 | public function appendInputText($name, $maxlength, $size, $id = null, $value = null) { |
ae41c41b RK |
815 | return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value)); |
816 | } | |
f925e4a1 RK |
817 | public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) { |
818 | return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value)); | |
819 | } | |
61cc8aa9 | 820 | public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) { |
262e0bbb RK |
821 | return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value)); |
822 | } | |
f925e4a1 RK |
823 | public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) { |
824 | return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value)); | |
825 | } | |
826 | public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) { | |
827 | return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value)); | |
828 | } | |
ea32f7e5 RK |
829 | public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) { |
830 | return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value)); | |
831 | } | |
f925e4a1 RK |
832 | public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) { |
833 | return $this->appendChild($this->ownerDocument->createElementInputTel($name, $maxlength, $size, $id, $value)); | |
834 | } | |
835 | public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) { | |
836 | return $this->appendChild($this->ownerDocument->createElementInputDate($name, $id, $min, $max, $value)); | |
837 | } | |
838 | public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) { | |
839 | return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value)); | |
840 | } | |
841 | public function appendInputColor($name, $id = null, $value = null) { | |
842 | return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value)); | |
645a7eb6 | 843 | } |
61cc8aa9 | 844 | public function appendInputRadio($name, $id, $value, $checked) { |
ae41c41b RK |
845 | return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked)); |
846 | } | |
61cc8aa9 | 847 | public function appendInputCheckbox($name, $id, $value, $checked) { |
ae41c41b RK |
848 | return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked)); |
849 | } | |
61cc8aa9 | 850 | public function appendInputFile($name, $id, $accept) { |
4bb9d784 RK |
851 | return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept)); |
852 | } | |
61cc8aa9 | 853 | public function appendInputSubmit($value) { |
ae41c41b RK |
854 | return $this->appendChild($this->ownerDocument->createElementInputSubmit($value)); |
855 | } | |
61cc8aa9 | 856 | public function appendButton($value, $onclick = null) { |
1109f526 RK |
857 | return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick)); |
858 | } | |
61cc8aa9 | 859 | public function appendTextArea($name, $columns, $rows, $id = null, $value = null) { |
bf91764c RK |
860 | return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value)); |
861 | } | |
69409ddb RK |
862 | public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) { |
863 | return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch)); | |
bf91764c | 864 | } |
61cc8aa9 | 865 | public function appendElementOption($key, $desc, $selected = false) { |
bf91764c RK |
866 | return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected)); |
867 | } | |
61cc8aa9 | 868 | public function appendLabel($for_id, $value) { |
bf91764c RK |
869 | return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value)); |
870 | } | |
61cc8aa9 | 871 | public function appendText($text) { |
bf91764c RK |
872 | return $this->appendChild($this->ownerDocument->createTextNode($text)); |
873 | } | |
71771b0c RK |
874 | public function appendLinebreak() { |
875 | return $this->appendChild($this->ownerDocument->createElement('br')); | |
876 | } | |
6638efd5 RK |
877 | public function appendEntity($name) { |
878 | return $this->appendChild($this->ownerDocument->createEntityReference($name)); | |
879 | } | |
61cc8aa9 | 880 | public function appendComment($comment_data) { |
cadc5980 RK |
881 | return $this->appendChild($this->ownerDocument->createComment($comment_data)); |
882 | } | |
61cc8aa9 | 883 | public function appendHTMLMarkup($htmldata) { |
bf91764c RK |
884 | $this->ownerDocument->appendHTMLMarkup($htmldata, $this); |
885 | } | |
61cc8aa9 | 886 | public function appendXMLMarkup($xmldata) { |
bf91764c RK |
887 | $this->ownerDocument->appendXMLMarkup($xmldata, $this); |
888 | } | |
61cc8aa9 | 889 | public function appendJSElement($jsdata) { |
bf91764c RK |
890 | $this->appendChild($this->ownerDocument->createElementJS($jsdata)); |
891 | } | |
8afa2e61 RK |
892 | public function appendJSFile($jsdata, $defer = false, $async = false) { |
893 | return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async)); | |
ea32f7e5 | 894 | } |
f887cdcb RK |
895 | public function setClass($classname) { |
896 | $this->setAttribute('class', $classname); | |
897 | } | |
898 | public function addClass($classname) { | |
899 | $classval = $this->getAttribute('class'); | |
900 | if (strlen($classval)) { $classval .= ' '; } | |
901 | $classval .= $classname; | |
902 | $this->setClass($classval); | |
903 | return $classval; | |
904 | } | |
905 | public function setID($elem_id) { | |
906 | $this->setAttribute('id', $elem_id); | |
907 | } | |
bf91764c RK |
908 | } |
909 | ||
910 | class ExtendedDocumentFragment extends DOMDocumentFragment { | |
911 | // ExtendedDocumentFragment PHP class | |
912 | // this extends the general PHP DOM Document Fragment class to simplify some usual constructs | |
913 | // | |
61cc8aa9 | 914 | // public function appendElement($name, [$value]) |
bf91764c RK |
915 | // appends a DOMDocument::createElement() as a child of this fragment (see there for params) |
916 | // returns the new child | |
917 | // | |
61cc8aa9 | 918 | // public function appendElementXML($name, $xmldata) |
bf91764c RK |
919 | // appends a DOMDocument::createElement() with the given name as a child of this fragment, |
920 | // with an ExtendedDocument::createXMLFragment() of the given XML data inside | |
921 | // returns the new child | |
922 | // | |
b3cc0fef | 923 | // public function appendLink($target, [$value], [$title]) |
bf91764c RK |
924 | // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params) |
925 | // returns the new child | |
926 | // | |
61cc8aa9 | 927 | // public function appendImage($src, [$alt_text]) |
53510e9e RK |
928 | // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params) |
929 | // returns the new child | |
930 | // | |
61cc8aa9 | 931 | // public function appendForm($action, $method, $name, [$id]) |
b8d16837 RK |
932 | // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params) |
933 | // returns the new child | |
934 | // | |
61cc8aa9 | 935 | // public function appendFormDiv($action, $method, $name, [$id]) |
bf91764c RK |
936 | // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params) |
937 | // returns an HTML <div> that is a child of the new child | |
938 | // | |
61cc8aa9 | 939 | // public function appendInputHidden($name, $value) |
bf91764c RK |
940 | // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params) |
941 | // returns the new child | |
942 | // | |
61cc8aa9 | 943 | // public function appendInputText($name, $maxlength, $size, [$id], [$value]) |
bf91764c RK |
944 | // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params) |
945 | // returns the new child | |
946 | // | |
f925e4a1 RK |
947 | // public function appendInputPassword($name, $maxlength, $size, [$id], [$value]) |
948 | // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params) | |
949 | // returns the new child | |
950 | // | |
61cc8aa9 | 951 | // public function appendInputNumber($name, $maxlength, $size, [$id], [$value]) |
262e0bbb RK |
952 | // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params) |
953 | // returns the new child | |
954 | // | |
f925e4a1 RK |
955 | // public function appendInputRange($name, $id, $min, $max, [$step], [$value]) |
956 | // appends an ExtendedDocument::createElementInputRange() as a child of this fragment (see there for params) | |
957 | // returns the new child | |
958 | // | |
959 | // public function appendInputUrl($name, $maxlength, $size, [$id], [$value]) | |
960 | // appends an ExtendedDocument::createElementInputUrl() as a child of this fragment (see there for params) | |
961 | // returns the new child | |
962 | // | |
ea32f7e5 RK |
963 | // public function appendInputEmail($name, $maxlength, $size, [$id], [$value]) |
964 | // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params) | |
965 | // returns the new child | |
966 | // | |
f925e4a1 RK |
967 | // public function appendInputTel($name, $maxlength, $size, [$id], [$value]) |
968 | // appends an ExtendedDocument::createElementInputTel() as a child of this fragment (see there for params) | |
645a7eb6 RK |
969 | // returns the new child |
970 | // | |
f925e4a1 RK |
971 | // public function appendInputDate($name, [$id], [$min], [$max], [$value]) |
972 | // appends an ExtendedDocument::createElementInputDate() as a child of this fragment (see there for params) | |
973 | // returns the new child | |
974 | // | |
975 | // public function appendInputTime($name, [$id], [$min], [$max], [$value]) | |
976 | // appends an ExtendedDocument::createElementInputTime() as a child of this fragment (see there for params) | |
977 | // returns the new child | |
978 | // | |
979 | // public function appendInputColor($name, [$id], [$value]) | |
980 | // appends an ExtendedDocument::createElementInputColor() as a child of this fragment (see there for params) | |
981 | // | |
61cc8aa9 | 982 | // public function appendInputRadio($name, $id, $value, $checked) |
bf91764c RK |
983 | // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params) |
984 | // returns the new child | |
985 | // | |
61cc8aa9 | 986 | // public function appendInputCheckbox($name, $id, $value, $checked) |
bf91764c RK |
987 | // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params) |
988 | // returns the new child | |
989 | // | |
61cc8aa9 | 990 | // public function appendInputFile($name, $id, $accept) |
4bb9d784 RK |
991 | // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params) |
992 | // returns the new child | |
993 | // | |
61cc8aa9 | 994 | // public function appendInputSubmit($value) |
bf91764c RK |
995 | // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params) |
996 | // returns the new child | |
997 | // | |
61cc8aa9 | 998 | // public function appendButton($value, $onclick = null) |
1109f526 RK |
999 | // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params) |
1000 | // returns the new child | |
1001 | // | |
61cc8aa9 | 1002 | // public function appendTextArea($name, $columns, $rows, [$id], [$value]) |
bf91764c RK |
1003 | // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params) |
1004 | // returns the new child | |
1005 | // | |
69409ddb | 1006 | // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch]) |
bf91764c RK |
1007 | // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params) |
1008 | // returns the new child | |
1009 | // | |
61cc8aa9 | 1010 | // public function appendElementOption($key, $desc, [$selected]) |
bf91764c RK |
1011 | // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params) |
1012 | // returns the new child | |
1013 | // | |
61cc8aa9 | 1014 | // public function appendLabel($for_id, $value) |
bf91764c RK |
1015 | // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params) |
1016 | // returns the new child | |
1017 | // | |
61cc8aa9 | 1018 | // public function appendText($text) |
bf91764c RK |
1019 | // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params) |
1020 | // returns the new child | |
1021 | // | |
71771b0c RK |
1022 | // public function appendLinebreak() |
1023 | // appends a <br> as a child of this fragment | |
1024 | // returns the new child | |
1025 | // | |
6638efd5 RK |
1026 | // public function appendEntity($name) |
1027 | // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params) | |
1028 | // returns the new child | |
1029 | // | |
61cc8aa9 | 1030 | // public function appendComment($comment_data) |
cadc5980 RK |
1031 | // appends a DOMDocument::createComment() as a child of this fragment (see there for params) |
1032 | // returns the new child | |
1033 | // | |
61cc8aa9 | 1034 | // public function appendHTMLMarkup($htmldata) |
bf91764c RK |
1035 | // appends a representation of the HTML data as children of this fragment |
1036 | // NO return value! | |
1037 | // | |
61cc8aa9 | 1038 | // public function appendXMLMarkup($xmldata) |
bf91764c RK |
1039 | // appends a representation of the XML data as children of this fragment |
1040 | // NO return value! | |
1041 | // | |
61cc8aa9 | 1042 | // public function appendJSElement($jsdata) |
bf91764c RK |
1043 | // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params) |
1044 | // NO return value! | |
c1666e91 | 1045 | // |
8afa2e61 | 1046 | // public function appendJSFile($jsURL, [$defer], [$async]) |
0bbc241e | 1047 | // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params) |
ea32f7e5 | 1048 | // returns the new child |
bf91764c | 1049 | |
61cc8aa9 | 1050 | public function appendElement($name, $value = '') { |
a8816f43 | 1051 | return $this->appendChild($this->ownerDocument->createElement($name, $value)); |
bf91764c | 1052 | } |
61cc8aa9 | 1053 | public function appendElementXML($name, $xmldata) { |
bf91764c RK |
1054 | $aelem = $this->appendChild($this->ownerDocument->createElement($name)); |
1055 | $aelem->appendXMLMarkup($xmldata); | |
1056 | return $aelem; | |
1057 | } | |
b3cc0fef RK |
1058 | public function appendLink($target, $value = '', $title = null) { |
1059 | return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title)); | |
bf91764c | 1060 | } |
61cc8aa9 | 1061 | public function appendImage($src, $alt_text = '') { |
53510e9e RK |
1062 | return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text)); |
1063 | } | |
61cc8aa9 | 1064 | public function appendForm($action, $method, $name, $id = null) { |
b8d16837 RK |
1065 | return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id)); |
1066 | } | |
61cc8aa9 | 1067 | public function appendFormDiv($action, $method, $name, $id = null) { |
b8d16837 | 1068 | $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id)); |
bf91764c RK |
1069 | return $formelem->appendElement('div'); |
1070 | } | |
61cc8aa9 | 1071 | public function appendInputHidden($name, $value) { |
bf91764c RK |
1072 | return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value)); |
1073 | } | |
61cc8aa9 | 1074 | public function appendInputText($name, $maxlength, $size, $id = null, $value = null) { |
bf91764c | 1075 | return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value)); |
645a7eb6 | 1076 | } |
f925e4a1 RK |
1077 | public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) { |
1078 | return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value)); | |
1079 | } | |
61cc8aa9 | 1080 | public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) { |
262e0bbb RK |
1081 | return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value)); |
1082 | } | |
f925e4a1 RK |
1083 | public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) { |
1084 | return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value)); | |
1085 | } | |
1086 | public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) { | |
1087 | return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value)); | |
1088 | } | |
ea32f7e5 RK |
1089 | public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) { |
1090 | return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value)); | |
1091 | } | |
f925e4a1 RK |
1092 | public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) { |
1093 | return $this->appendChild($this->ownerDocument->createElementInputTel($name, $maxlength, $size, $id, $value)); | |
1094 | } | |
1095 | public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) { | |
1096 | return $this->appendChild($this->ownerDocument->createElementInputDate($name, $id, $min, $max, $value)); | |
1097 | } | |
1098 | public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) { | |
1099 | return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value)); | |
1100 | } | |
1101 | public function appendInputColor($name, $id = null, $value = null) { | |
1102 | return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value)); | |
bf91764c | 1103 | } |
61cc8aa9 | 1104 | public function appendInputRadio($name, $id, $value, $checked) { |
bf91764c RK |
1105 | return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked)); |
1106 | } | |
61cc8aa9 | 1107 | public function appendInputCheckbox($name, $id, $value, $checked) { |
bf91764c RK |
1108 | return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked)); |
1109 | } | |
61cc8aa9 | 1110 | public function appendInputFile($name, $id, $accept) { |
4bb9d784 RK |
1111 | return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept)); |
1112 | } | |
61cc8aa9 | 1113 | public function appendInputSubmit($value) { |
bf91764c RK |
1114 | return $this->appendChild($this->ownerDocument->createElementInputSubmit($value)); |
1115 | } | |
61cc8aa9 | 1116 | public function appendButton($value, $onclick = null) { |
1109f526 RK |
1117 | return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick)); |
1118 | } | |
61cc8aa9 | 1119 | public function appendTextArea($name, $columns, $rows, $id = null, $value = null) { |
bf91764c RK |
1120 | return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value)); |
1121 | } | |
69409ddb RK |
1122 | public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) { |
1123 | return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch)); | |
bf91764c | 1124 | } |
61cc8aa9 | 1125 | public function appendElementOption($key, $desc, $selected = false) { |
bf91764c RK |
1126 | return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected)); |
1127 | } | |
61cc8aa9 | 1128 | public function appendLabel($for_id, $value) { |
ae41c41b RK |
1129 | return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value)); |
1130 | } | |
61cc8aa9 | 1131 | public function appendText($text) { |
cea5b93a RK |
1132 | return $this->appendChild($this->ownerDocument->createTextNode($text)); |
1133 | } | |
71771b0c RK |
1134 | public function appendLinebreak() { |
1135 | return $this->appendChild($this->ownerDocument->createElement('br')); | |
1136 | } | |
6638efd5 RK |
1137 | public function appendEntity($name) { |
1138 | return $this->appendChild($this->ownerDocument->createEntityReference($name)); | |
1139 | } | |
61cc8aa9 | 1140 | public function appendComment($comment_data) { |
cadc5980 RK |
1141 | return $this->appendChild($this->ownerDocument->createComment($comment_data)); |
1142 | } | |
61cc8aa9 | 1143 | public function appendHTMLMarkup($htmldata) { |
ae41c41b RK |
1144 | $this->ownerDocument->appendHTMLMarkup($htmldata, $this); |
1145 | } | |
61cc8aa9 | 1146 | public function appendXMLMarkup($xmldata) { |
ae41c41b | 1147 | $this->ownerDocument->appendXMLMarkup($xmldata, $this); |
cea5b93a | 1148 | } |
61cc8aa9 | 1149 | public function appendJSElement($jsdata) { |
cea5b93a RK |
1150 | $this->appendChild($this->ownerDocument->createElementJS($jsdata)); |
1151 | } | |
8afa2e61 RK |
1152 | public function appendJSFile($jsdata, $defer = false, $async = false) { |
1153 | return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async)); | |
ea32f7e5 | 1154 | } |
cea5b93a RK |
1155 | } |
1156 | ?> |