add code for datetime-local input elements
[php-utility-classes.git] / classes / document.php-class
... / ...
CommitLineData
1<?php
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/. */
5
6class 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 //
14 // static function initHTML5([$doc])
15 // initialize as an HTML5 document and return references to its basic elements.
16 // If a $doc is handed over (an ExtendedDocument or a derived class), load the content into that document.
17 // returns an associative array with the following elements: 'html', 'head', 'title', 'body'
18 //
19 // public function loadHTML5($source) {
20 // A version of loadHTML() - see DOMDocument documentation - that is made for loading HTML5 and not emitting warnings/errors for unknown elements.
21 // returns true on success, false otherwise, just like loadHTML5.
22 //
23 // public function appendElement($name, [$value])
24 // appends a DOMDocument::createElement() as a child of this document (see there for params)
25 // returns the new child
26 //
27 // public function appendElementXML($name, $xmldata)
28 // appends a DOMDocument::createElement() with the given name as a child of this document,
29 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
30 // returns the new child
31 //
32 // public function appendLink($target, [$value], [$title])
33 // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
34 // returns the new child
35 //
36 // public function appendImage($src, [$alt_text])
37 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
38 // returns the new child
39 //
40 // public function appendForm($action, $method, $name, [$id])
41 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
42 // returns the new child
43 //
44 // public function appendFormDiv($action, $method, $name, [$id])
45 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
46 // returns an HTML <div> that is a child of the new child
47 //
48 // public function appendInputHidden($name, $value)
49 // appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
50 // returns the new child
51 //
52 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
53 // appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
54 // returns the new child
55 //
56 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
57 // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
58 // returns the new child
59 //
60 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
61 // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
62 // returns the new child
63 //
64 // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
65 // appends an ExtendedDocument::createElementInputRange() as a child of this document (see there for params)
66 // returns the new child
67 //
68 // public function appendInputSearch($name, $maxlength, $size, [$id], [$value])
69 // appends an ExtendedDocument::createElementInputSearch() as a child of this document (see there for params)
70 // returns the new child
71 //
72 // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
73 // appends an ExtendedDocument::createElementInputUrl() as a child of this document (see there for params)
74 // returns the new child
75 //
76 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
77 // appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params)
78 // returns the new child
79 //
80 // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
81 // appends an ExtendedDocument::createElementInputTel() as a child of this document (see there for params)
82 // returns the new child
83 //
84 // public function appendInputDate($name, [$id], [$min], [$max], [$value])
85 // appends an ExtendedDocument::createElementInputDate() as a child of this document (see there for params)
86 // returns the new child
87 //
88 // public function appendInputTime($name, [$id], [$min], [$max], [$value])
89 // appends an ExtendedDocument::createElementInputTime() as a child of this document (see there for params)
90 // returns the new child
91 //
92 // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
93 // appends an ExtendedDocument::createElementInputDateTime() as a child of this document (see there for params)
94 // returns the new child
95 //
96 // public function appendInputColor($name, [$id], [$value])
97 // appends an ExtendedDocument::createElementInputColor() as a child of this document (see there for params)
98 // returns the new child
99 //
100 // public function appendInputRadio($name, $id, $value, $checked)
101 // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
102 // returns the new child
103 //
104 // public function appendInputCheckbox($name, $id, $value, $checked)
105 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
106 // returns the new child
107 //
108 // public function appendInputFile($name, $id, $accept)
109 // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
110 // returns the new child
111 //
112 // public function appendInputSubmit($value)
113 // appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
114 // returns the new child
115 //
116 // public function appendButton($value, $onclick = null)
117 // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
118 // returns the new child
119 //
120 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
121 // appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
122 // returns the new child
123 //
124 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
125 // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
126 // returns the new child
127 //
128 // public function appendElementOption($key, $desc, [$selected])
129 // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
130 // returns the new child
131 //
132 // public function appendLabel($for_id, $value)
133 // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
134 // returns the new child
135 //
136 // public function appendElementDatalist([$id], [$options])
137 // appends an ExtendedDocument::createElementDatalist() as a child of this document (see there for params)
138 // returns the new child
139 //
140 // public function appendText($text)
141 // appends a DOMDocument::createTextNode() as a child of this document (see there for params)
142 // returns the new child
143 //
144 // public function appendLinebreak()
145 // appends a <br> as a child of this document
146 // returns the new child
147 //
148 // public function appendEntity($name)
149 // appends a DOMDocument::createEntityReference() as a child of this document (see there for params)
150 // returns the new child
151 //
152 // public function appendComment($comment_data)
153 // appends a DOMDocument::createComment() as a child of this document (see there for params)
154 // returns the new child
155 //
156 // public function appendClonedElement($dom_element, [$deep])
157 // appends a clone of the given DOMElement as a child of this document
158 // the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
159 // returns the new child
160 //
161 // public function appendHTMLMarkup($htmldata, [$parentNode])
162 // appends a representation of the HTML data as children of the given parent node, by default this document
163 // NO return value!
164 //
165 // public function appendXMLMarkup($xmldata, [$parentNode])
166 // appends a representation of the XML data as children of the given parent node, by default this document
167 // NO return value!
168 //
169 // public function appendStyleElement($styledata)
170 // appends an ExtendedDocument::createElementStyle() as a child of this document (see there for params)
171 // returns the new child
172 //
173 // public function appendJSElement($jsdata)
174 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
175 // returns the new child
176 //
177 // public function appendJSFile($jsURL, [$defer], [$async])
178 // appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
179 // returns the new child
180 //
181 // public function createElementLink($target, [$value], [$title])
182 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value as well as (optional) title attribute
183 //
184 // public function createElementImage($src, [$alt_text])
185 // returns an ExtendedElement that is an HTML <img> with the given src and alt attributes (set to '' by default)
186 //
187 // public function createElementForm($action, $method, $name)
188 // returns an ExtendedElement that is an HTML <form> with the given action, method, and name
189 //
190 // public function createElementInputHidden($name, $value)
191 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
192 //
193 // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
194 // returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
195 // and optionally id and value
196 //
197 // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
198 // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
199 // and optionally id and value
200 //
201 // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
202 // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
203 // and optionally id and value
204 //
205 // public function createElementInputRange($name, $id, $min, $max, [$step], [$value])
206 // returns an ExtendedElement that is an HTML <input> of type 'range' with the given name, id, min, max,
207 // and optionally step and value
208 //
209 // public function createElementInputUrl($name, $maxlength, $size, [$id], [$value])
210 // returns an ExtendedElement that is an HTML <input> of type 'url' with the given name, maxlength, size,
211 // and optionally id and value
212 //
213 // public function createElementInputSearch($name, $maxlength, $size, [$id], [$value])
214 // returns an ExtendedElement that is an HTML <input> of type 'search' with the given name, maxlength, size,
215 // and optionally id and value
216 //
217 // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
218 // returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
219 // and optionally id and value
220 //
221 // public function createElementInputTel($name, $maxlength, $size, [$id], [$value])
222 // returns an ExtendedElement that is an HTML <input> of type 'tel' with the given name, maxlength, size,
223 // and optionally id and value
224 //
225 // public function createElementInputDate($name, [$id], [$min], [$max], [$value])
226 // returns an ExtendedElement that is an HTML <input> of type 'date' with the given name,
227 // and optionally id, min, max, and value
228 //
229 // public function createElementInputTime($name, [$id], [$min], [$max], [$value])
230 // returns an ExtendedElement that is an HTML <input> of type 'time' with the given name,
231 // and optionally id, min, max, and value
232 //
233 // public function createElementInputDateTime($name, [$id], [$min], [$max], [$value])
234 // returns an ExtendedElement that is an HTML <input> of type 'datetime-local' with the given name,
235 // and optionally id, min, max, and value
236 //
237 // public function createElementInputColor($name, [$id], [$value])
238 // returns an ExtendedElement that is an HTML <input> of type 'color' with the given name,
239 // and optionally id and value
240 //
241 // public function createElementInputRadio($name, $id, $value, $checked)
242 // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
243 // checked state
244 //
245 // public function createElementInputCheckbox($name, $id, $value, $checked)
246 // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
247 // checked state
248 //
249 // public function createElementInputFile($name, $id, $accept)
250 // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
251 //
252 // public function createElementInputSubmit($value)
253 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
254 //
255 // public function createElementButton($value, $onclick = null)
256 // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
257 //
258 // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
259 // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
260 // and optionally id and value
261 //
262 // public function createElementSelect($name, [$id], [$options], [$default], [$strictmatch])
263 // returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
264 // array of options (key => description) and key of the by-default selected entry (matched including type when strictmatch is true)
265 //
266 // public function createElementOption($key, $desc, [$selected])
267 // returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
268 // and optionally bool that tells if the entry is selected
269 //
270 // public function createElementLabel($for_id, $value)
271 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
272 //
273 // public function createElementDatalist([$id], [$options])
274 // returns an ExtendedElement that is an HTML <datalist> with optionally the given id and array of options (key => description)
275 //
276 // public function createElementStyle($styledata)
277 // returns an ExtendedElement that is an HTML <style> of CSS type with the style data inside
278 //
279 // public function createElementJS($jsdata)
280 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
281 //
282 // public function createElementJSFile($jsURL, [$defer], [$async])
283 // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
284 // $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.
285
286 function __construct($version = '1.0', $encoding = 'utf-8') {
287 // make sure the default DOMDocument constructor runs
288 parent::__construct($version, $encoding);
289 $this->registerNodeClass('DOMElement', 'ExtendedElement');
290 $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
291 }
292
293 static function initHTML5($doc = null) {
294 if (is_null($doc)) { $doc = new ExtendedDocument(); }
295 $doc->loadHTML5('<?xml version="1.0" encoding="utf-8"?>'."\n".'<!DOCTYPE html>'."\n".'<html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
296
297 // Created basic HTML document structure.
298 $root = $doc->getElementsByTagName('html')->item(0);
299 $head = $root->appendElement('head');
300 $title = $head->appendElement('title');
301 $body = $root->appendElement('body');
302
303 return array('document' => $doc,
304 'html' => $root,
305 'head' => $head,
306 'title' => $title,
307 'body' => $body);
308 }
309
310 public function loadHTML5($source) {
311 // Do our own handling of DOMDocument error reporting so we can ignore "unknown tags" which are usually fine in HTML5.
312 libxml_use_internal_errors(true);
313 if (!preg_match('/^\s*<\?xml /', $source)) {
314 // Add an XML declaration to force DOMDocument into UTF-8 mode.
315 $source = '<?xml version="1.0" encoding="utf-8"?>'."\n".$source;
316 }
317 $result = $this->loadHTML($source);
318 // Set encoding directly a,d remove any processing node that isn't the first node
319 $this->encoding = 'utf-8';
320 foreach ($this->childNodes as $i => $child) {
321 if ($i && $child->nodeType == XML_PI_NODE) {
322 $this->removeChild($child);
323 }
324 }
325 // Handle DOMDocument loading errors, throw away warnings on unknown tags as HTML5 allows all kinds.
326 $errseverity = array(LIBXML_ERR_WARNING => 'Warning', LIBXML_ERR_ERROR => 'Error', LIBXML_ERR_FATAL => 'Fatal');
327 foreach (libxml_get_errors() as $error) {
328 // $error is a libXMLError, see https://www.php.net/manual/en/class.libxmlerror.php
329 // See http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors for error numbers
330 if ($error->code != 801) { // XML_HTML_UNKNOWN_TAG gets no output, should not exist for HTML5.
331 trigger_error($errseverity[$error->level].' loading HTML5: '.$error->message.' (code '.$error->code.'), line: '.$error->line, E_USER_WARNING);
332 }
333 }
334 libxml_clear_errors();
335 libxml_use_internal_errors(false);
336 return $result;
337 }
338
339 public function appendElement($name, $value = '') {
340 return $this->appendChild($this->createElement($name, $value));
341 }
342 public function appendElementXML($name, $xmldata) {
343 $aelem = $this->appendChild($this->createElement($name));
344 $aelem->appendXMLMarkup($xmldata);
345 //$aelem->appendChild($this->createXMLFragment($xmldata));
346 return $aelem;
347 }
348 public function appendLink($target, $value = '', $title = null) {
349 return $this->appendChild($this->createElementLink($target, $value, $title));
350 }
351 public function appendImage($src, $alt_text = '') {
352 return $this->appendChild($this->createElementImage($src, $alt_text));
353 }
354 public function appendForm($action, $method, $name, $id = null) {
355 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
356 }
357 public function appendFormDiv($action, $method, $name, $id = null) {
358 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
359 return $formelem->appendElement('div');
360 }
361 public function appendInputHidden($name, $value) {
362 return $this->appendChild($this->createElementInputHidden($name, $value));
363 }
364 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
365 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
366 }
367 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
368 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
369 }
370 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
371 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
372 }
373 public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
374 return $this->appendChild($this->createElementInputRange($name, $id, $min, $max, $step, $value));
375 }
376 public function appendInputSearch($name, $maxlength, $size, $id = null, $value = null) {
377 return $this->appendChild($this->createElementInputSearch($name, $maxlength, $size, $id, $value));
378 }
379 public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
380 return $this->appendChild($this->createElementInputUrl($name, $maxlength, $size, $id, $value));
381 }
382 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
383 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
384 }
385 public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
386 return $this->appendChild($this->createElementInputTel($name, $maxlength, $size, $id, $value));
387 }
388 public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
389 return $this->appendChild($this->createElementInputDate($name, $id, $min, $max, $value));
390 }
391 public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
392 return $this->appendChild($this->createElementInputTime($name, $id, $min, $max, $value));
393 }
394 public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
395 return $this->appendChild($this->createElementInputDateTime($name, $id, $min, $max, $value));
396 }
397 public function appendInputColor($name, $id = null, $value = null) {
398 return $this->appendChild($this->createElementInputColor($name, $id, $value));
399 }
400 public function appendInputRadio($name, $id, $value, $checked) {
401 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
402 }
403 public function appendInputCheckbox($name, $id, $value, $checked) {
404 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
405 }
406 public function appendInputFile($name, $id, $accept) {
407 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
408 }
409 public function appendInputSubmit($value) {
410 return $this->appendChild($this->createElementInputSubmit($value));
411 }
412 public function appendButton($value, $onclick = null) {
413 return $this->appendChild($this->createElementButton($value, $onclick));
414 }
415 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
416 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
417 }
418 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
419 return $this->appendChild($this->createElementSelect($name, $id, $options, $default, $strictmatch));
420 }
421 public function appendElementOption($key, $desc, $selected = false) {
422 return $this->appendChild($this->createElementOption($key, $desc, $selected));
423 }
424 public function appendLabel($for_id, $value) {
425 return $this->appendChild($this->createElementLabel($for_id, $value));
426 }
427 public function appendElementDatalist($id = null, $options = array()) {
428 return $this->appendChild($this->createElementDatalist($id, $options));
429 }
430 public function appendText($text) {
431 return $this->appendChild($this->createTextNode($text));
432 }
433 public function appendLinebreak() {
434 return $this->appendChild($this->createElement('br'));
435 }
436 public function appendEntity($name) {
437 return $this->appendChild($this->createEntityReference($name));
438 }
439 public function appendComment($comment_data) {
440 return $this->appendChild($this->createComment($comment_data));
441 }
442 public function appendClonedElement($dom_element, $deep = true) {
443 return $this->appendChild($dom_element->cloneNode($deep));
444 }
445 public function appendStyleElement($styledata) {
446 return $this->appendChild($this->createElementStyle($styledata));
447 }
448 public function appendJSElement($jsdata) {
449 return $this->appendChild($this->createElementJS($jsdata));
450 }
451 public function appendJSFile($jsURL, $defer = false, $async = false) {
452 return $this->appendChild($this->createElementJSFile($jsURL, $defer, $async));
453 }
454
455 public function appendHTMLMarkup($htmldata, $parentNode = null) {
456 if (is_null($parentNode)) { $parentNode =& $this; }
457 // Use loadHTML5() to parse and turn the markup into proper HTML.
458 $tmpdoc = new ExtendedDocument;
459 // The XML line is needed to tell the parser that we need UTF-8 parsing.
460 $tmpdoc->loadHTML5('<?xml version="1.0" encoding="utf-8"?>'."\n".'<!DOCTYPE html>'."\n".'<html><body>'.$htmldata.'</body></html>');
461 foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) {
462 $parentNode->appendChild($this->importNode($child, true));
463 }
464 }
465
466 public function appendXMLMarkup($xmldata, $parentNode = null) {
467 if (is_null($parentNode)) { $parentNode =& $this; }
468 $tmpdoc = new ExtendedDocument;
469 $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
470 $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
471 $tmpxml .= '<root>'.$xmldata.'</root>';
472 $tmpdoc->loadXML($tmpxml);
473 foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
474 $parentNode->appendChild($this->importNode($child, true));
475 }
476 }
477
478 public function createElement($name, $value = '') {
479 // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
480 $aelem = parent::createElement($name);
481 if (strlen($value ?? '')) { $aelem->appendText($value); }
482 return $aelem;
483 }
484
485 public function createElementLink($target, $value = '', $title = null) {
486 $link = $this->createElement('a', $value);
487 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
488 if (!is_null($title)) { $link->setAttribute('title', $title); }
489 return $link;
490 }
491
492 public function createElementImage($src, $alt_text = '') {
493 $img = $this->createElement('img');
494 $img->setAttribute('src', $src);
495 $img->setAttribute('alt', $alt_text);
496 return $img;
497 }
498
499 public function createElementForm($action, $method, $name, $id = null) {
500 $formelem = $this->createElement('form');
501 $formelem->setAttribute('action', $action);
502 $formelem->setAttribute('method', $method);
503 $formelem->setAttribute('name', $name);
504 if (!is_null($id)) { $formelem->setAttribute('id', $id); }
505 return $formelem;
506 }
507
508 public function createElementInputHidden($name, $value) {
509 $hidden = $this->createElement('input');
510 $hidden->setAttribute('type', 'hidden');
511 $hidden->setAttribute('name', $name);
512 $hidden->setAttribute('value', $value);
513 return $hidden;
514 }
515
516 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
517 $txfield = $this->createElement('input');
518 $txfield->setAttribute('type', 'text');
519 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
520 $txfield->setAttribute('name', $name);
521 $txfield->setAttribute('maxlength', $maxlength);
522 $txfield->setAttribute('size', $size);
523 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
524 return $txfield;
525 }
526
527 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
528 $pwfield = $this->createElement('input');
529 $pwfield->setAttribute('type', 'password');
530 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
531 $pwfield->setAttribute('name', $name);
532 $pwfield->setAttribute('maxlength', $maxlength);
533 $pwfield->setAttribute('size', $size);
534 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
535 return $pwfield;
536 }
537
538 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
539 $numfield = $this->createElement('input');
540 $numfield->setAttribute('type', 'number');
541 if (!is_null($id)) { $numfield->setAttribute('id', $id); }
542 $numfield->setAttribute('name', $name);
543 $numfield->setAttribute('maxlength', $maxlength);
544 $numfield->setAttribute('size', $size);
545 if (!is_null($value)) { $numfield->setAttribute('value', $value); }
546 return $numfield;
547 }
548
549 public function createElementInputRange($name, $id, $min, $max, $step = null, $value = null) {
550 $rgfield = $this->createElement('input');
551 $rgfield->setAttribute('type', 'range');
552 if (!is_null($id)) { $rgfield->setAttribute('id', $id); }
553 $rgfield->setAttribute('name', $name);
554 if (!is_null($min)) { $rgfield->setAttribute('min', $min); }
555 if (!is_null($max)) { $rgfield->setAttribute('max', $max); }
556 if (!is_null($step)) { $rgfield->setAttribute('step', $step); }
557 if (!is_null($value)) { $rgfield->setAttribute('value', $value); }
558 return $rgfield;
559 }
560
561 public function createElementInputSearch($name, $maxlength, $size, $id = null, $value = null) {
562 $urlfield = $this->createElement('input');
563 $urlfield->setAttribute('type', 'search');
564 if (!is_null($id)) { $urlfield->setAttribute('id', $id); }
565 $urlfield->setAttribute('name', $name);
566 $urlfield->setAttribute('maxlength', $maxlength);
567 $urlfield->setAttribute('size', $size);
568 if (!is_null($value)) { $urlfield->setAttribute('value', $value); }
569 return $urlfield;
570 }
571
572 public function createElementInputUrl($name, $maxlength, $size, $id = null, $value = null) {
573 $urlfield = $this->createElement('input');
574 $urlfield->setAttribute('type', 'url');
575 if (!is_null($id)) { $urlfield->setAttribute('id', $id); }
576 $urlfield->setAttribute('name', $name);
577 $urlfield->setAttribute('maxlength', $maxlength);
578 $urlfield->setAttribute('size', $size);
579 if (!is_null($value)) { $urlfield->setAttribute('value', $value); }
580 return $urlfield;
581 }
582
583 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
584 $mailfield = $this->createElement('input');
585 $mailfield->setAttribute('type', 'email');
586 if (!is_null($id)) { $mailfield->setAttribute('id', $id); }
587 $mailfield->setAttribute('name', $name);
588 $mailfield->setAttribute('maxlength', $maxlength);
589 $mailfield->setAttribute('size', $size);
590 if (!is_null($value)) { $mailfield->setAttribute('value', $value); }
591 return $mailfield;
592 }
593
594 public function createElementInputTel($name, $maxlength, $size, $id = null, $value = null) {
595 $telfield = $this->createElement('input');
596 $telfield->setAttribute('type', 'tel');
597 if (!is_null($id)) { $telfield->setAttribute('id', $id); }
598 $telfield->setAttribute('name', $name);
599 $telfield->setAttribute('maxlength', $maxlength);
600 $telfield->setAttribute('size', $size);
601 if (!is_null($value)) { $telfield->setAttribute('value', $value); }
602 return $telfield;
603 }
604
605 public function createElementInputDate($name, $id = null, $min = null, $max = null, $value = null) {
606 $dtfield = $this->createElement('input');
607 $dtfield->setAttribute('type', 'date');
608 if (!is_null($id)) { $dtfield->setAttribute('id', $id); }
609 $dtfield->setAttribute('name', $name);
610 if (!is_null($min)) { $dtfield->setAttribute('min', $min); }
611 if (!is_null($max)) { $dtfield->setAttribute('max', $max); }
612 if (!is_null($value)) { $dtfield->setAttribute('value', $value); }
613 return $dtfield;
614 }
615
616 public function createElementInputTime($name, $id = null, $min = null, $max = null, $value = null) {
617 $timefield = $this->createElement('input');
618 $timefield->setAttribute('type', 'time');
619 if (!is_null($id)) { $timefield->setAttribute('id', $id); }
620 $timefield->setAttribute('name', $name);
621 if (!is_null($min)) { $timefield->setAttribute('min', $min); }
622 if (!is_null($max)) { $timefield->setAttribute('max', $max); }
623 if (!is_null($value)) { $timefield->setAttribute('value', $value); }
624 return $timefield;
625 }
626
627 public function createElementInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
628 $dtfield = $this->createElement('input');
629 $dtfield->setAttribute('type', 'datetime-local');
630 if (!is_null($id)) { $dtfield->setAttribute('id', $id); }
631 $dtfield->setAttribute('name', $name);
632 if (!is_null($min)) { $dtfield->setAttribute('min', $min); }
633 if (!is_null($max)) { $dtfield->setAttribute('max', $max); }
634 if (!is_null($value)) { $dtfield->setAttribute('value', str_replace(' ', 'T', $value, 1)); }
635 return $dtfield;
636 }
637
638 public function createElementInputColor($name, $id = null, $value = null) {
639 $colfield = $this->createElement('input');
640 $colfield->setAttribute('type', 'color');
641 if (!is_null($id)) { $colfield->setAttribute('id', $id); }
642 $colfield->setAttribute('name', $name);
643 if (!is_null($value)) { $colfield->setAttribute('value', $value); }
644 return $colfield;
645 }
646
647 public function createElementInputRadio($name, $id, $value, $checked) {
648 $radio = $this->createElement('input');
649 $radio->setAttribute('type', 'radio');
650 $radio->setAttribute('name', $name);
651 if (!is_null($id)) { $radio->setAttribute('id', $id); }
652 $radio->setAttribute('value', $value);
653 if ($checked) { $radio->setAttribute('checked', ''); }
654 return $radio;
655 }
656
657 public function createElementInputCheckbox($name, $id, $value, $checked) {
658 $cbox = $this->createElement('input');
659 $cbox->setAttribute('type', 'checkbox');
660 $cbox->setAttribute('name', $name);
661 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
662 $cbox->setAttribute('value', $value);
663 if ($checked) { $cbox->setAttribute('checked', ''); }
664 return $cbox;
665 }
666
667 public function createElementInputFile($name, $id, $accept) {
668 $fileinput = $this->createElement('input');
669 $fileinput->setAttribute('type', 'file');
670 $fileinput->setAttribute('name', $name);
671 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
672 $fileinput->setAttribute('accept', $accept);
673 return $fileinput;
674 }
675
676 public function createElementInputSubmit($value) {
677 $submitbtn = $this->createElement('input');
678 $submitbtn->setAttribute('type', 'submit');
679 $submitbtn->setAttribute('value', $value);
680 return $submitbtn;
681 }
682
683 public function createElementButton($value, $onclick = null) {
684 $btn = $this->createElement('input');
685 $btn->setAttribute('type', 'button');
686 $btn->setAttribute('value', $value);
687 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
688 return $btn;
689 }
690
691 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
692 $txtarea = $this->createElement('textarea', $value);
693 $txtarea->setAttribute('name', $name);
694 $txtarea->setAttribute('cols', $columns);
695 $txtarea->setAttribute('rows', $rows);
696 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
697 return $txtarea;
698 }
699
700 public function createElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
701 $select = $this->createElement('select');
702 $select->setAttribute('name', $name);
703 if (!is_null($id)) { $select->setAttribute('id', $id); }
704 foreach ($options as $key => $desc) {
705 $select->appendElementOption($key, $desc, $strictmatch ? ($key === $default) : ($key == $default));
706 }
707 return $select;
708 }
709
710 public function createElementOption($key, $desc, $selected = false) {
711 $option = $this->createElement('option', $desc);
712 if (is_numeric($key) || is_string($key)) {
713 $option->setAttribute('value', $key);
714 }
715 if ($selected) {
716 $option->setAttribute('selected', '');
717 }
718 return $option;
719 }
720
721 public function createElementLabel($for_id, $value) {
722 $label = $this->createElement('label', $value);
723 $label->setAttribute('for', $for_id);
724 return $label;
725 }
726
727 public function createElementDatalist($id = null, $options = array()) {
728 $select = $this->createElement('datalist');
729 if (!is_null($id)) { $select->setAttribute('id', $id); }
730 foreach ($options as $key => $desc) {
731 $select->appendElementOption($key, $desc);
732 }
733 return $select;
734 }
735
736 public function createElementStyle($styledata) {
737 $style_elem = $this->createElement('style');
738 // Note: type can/should be left out for HTML5.
739 $style_elem->setAttribute('type', 'text/css');
740 $style_elem->appendChild($this->createCDATASection($styledata));
741 return $style_elem;
742 }
743
744 public function createElementJS($jsdata) {
745 $jselem = $this->createElement('script');
746 // Note: type can/should be left out for HTML5.
747 $jselem->setAttribute('type', 'text/javascript');
748 $jselem->appendChild($this->createCDATASection($jsdata));
749 return $jselem;
750 }
751
752 public function createElementJSFile($jsURL, $defer = false, $async = false) {
753 $jselem = $this->createElement('script');
754 // Note: type can/should be left out for HTML5.
755 $jselem->setAttribute('type', 'text/javascript');
756 if ($defer) {
757 $jselem->setAttribute('defer', '');
758 }
759 if ($async) {
760 $jselem->setAttribute('async', '');
761 }
762 $jselem->setAttribute('src', $jsURL);
763 return $jselem;
764 }
765}
766
767class ExtendedElement extends DOMElement {
768 // ExtendedElement PHP class
769 // this extends the general PHP DOM Element class to simplify some usual constructs
770 //
771 // public function appendElement($name, [$value])
772 // appends a DOMDocument::createElement() as a child of this element (see there for params)
773 // returns the new child
774 //
775 // public function appendElementXML($name, $xmldata)
776 // appends a DOMDocument::createElement() with the given name as a child of this element,
777 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
778 // returns the new child
779 //
780 // public function appendLink($target, [$value], [$title])
781 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
782 // returns the new child
783 //
784 // public function appendImage($src, [$alt_text])
785 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
786 // returns the new child
787 //
788 // public function appendForm($action, $method, $name, [$id])
789 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
790 // returns the new child
791 //
792 // public function appendFormDiv($action, $method, $name, [$id])
793 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
794 // returns an HTML <div> that is a child of the new child
795 //
796 // public function appendInputHidden($name, $value)
797 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
798 // returns the new child
799 //
800 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
801 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
802 // returns the new child
803 //
804 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
805 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
806 // returns the new child
807 //
808 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
809 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
810 // returns the new child
811 //
812 // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
813 // appends an ExtendedDocument::createElementInputRange() as a child of this element (see there for params)
814 // returns the new child
815 //
816 // public function appendInputSearch($name, $maxlength, $size, [$id], [$value])
817 // appends an ExtendedDocument::createElementInputSearch() as a child of this element (see there for params)
818 // returns the new child
819 //
820 // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
821 // appends an ExtendedDocument::createElementInputUrl() as a child of this element (see there for params)
822 // returns the new child
823 //
824 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
825 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
826 // returns the new child
827 //
828 // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
829 // appends an ExtendedDocument::createElementInputTel() as a child of this element (see there for params)
830 // returns the new child
831 //
832 // public function appendInputDate($name, [$id], [$min], [$max], [$value])
833 // appends an ExtendedDocument::createElementInputDate() as a child of this element (see there for params)
834 // returns the new child
835 //
836 // public function appendInputTime($name, [$id], [$min], [$max], [$value])
837 // appends an ExtendedDocument::createElementInputTime() as a child of this element (see there for params)
838 // returns the new child
839 //
840 // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
841 // appends an ExtendedDocument::createElementInputDateTime() as a child of this element (see there for params)
842 // returns the new child
843 //
844 // public function appendInputColor($name, [$id], [$value])
845 // appends an ExtendedDocument::createElementInputColor() as a child of this element (see there for params)
846 //
847 // public function appendInputRadio($name, $id, $value, $checked)
848 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
849 // returns the new child
850 //
851 // public function appendInputCheckbox($name, $id, $value, $checked)
852 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
853 // returns the new child
854 //
855 // public function appendInputFile($name, $id, $accept)
856 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
857 // returns the new child
858 //
859 // public function appendInputSubmit($value)
860 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
861 // returns the new child
862 //
863 // public function appendButton($value, $onclick = null)
864 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
865 // returns the new child
866 //
867 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
868 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
869 // returns the new child
870 //
871 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
872 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
873 // returns the new child
874 //
875 // public function appendElementOption($key, $desc, [$selected])
876 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
877 // returns the new child
878 //
879 // public function appendLabel($for_id, $value)
880 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
881 // returns the new child
882 //
883 // public function appendElementDatalist([$id], [$options])
884 // appends an ExtendedDocument::createElementDatalist() as a child of this element (see there for params)
885 // returns the new child
886 //
887 // public function appendText($text)
888 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
889 // returns the new child
890 //
891 // public function appendLinebreak()
892 // appends a <br> as a child of this element
893 // returns the new child
894 //
895 // public function appendEntity($name)
896 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
897 // returns the new child
898 //
899 // public function appendComment($comment_data)
900 // appends a DOMDocument::createComment() as a child of this element (see there for params)
901 // returns the new child
902 //
903 // public function appendClonedElement($dom_element, [$deep])
904 // appends a clone of the given DOMElement as a child of this element
905 // the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
906 // returns the new child
907 //
908 // public function appendHTMLMarkup($htmldata)
909 // appends a representation of the HTML data as children of this element
910 // NO return value!
911 //
912 // public function appendXMLMarkup($xmldata)
913 // appends a representation of the XML data as children of this element
914 // NO return value!
915 //
916 // public function appendStyleElement($styledata)
917 // appends an ExtendedDocument::createElementStyle() as a child of this element (see there for params)
918 // returns the new child
919 //
920 // public function appendJSElement($jsdata)
921 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
922 // returns the new child
923 //
924 // public function appendJSFile($jsURL, [$defer], [$async])
925 // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
926 // returns the new child
927 //
928 // public function setClass($classname)
929 // sets the 'class' attribute of the element to the given classname value
930 //
931 // public function addClass($classname)
932 // adds the given classname value to the space-separated list in the 'class' attribute
933 // returns the value of the 'class' attribute
934 //
935 // public function setID($elem_id)
936 // sets the 'id' attribute of the element to the given elem_id value
937
938 public function appendElement($name, $value = '') {
939 return $this->appendChild($this->ownerDocument->createElement($name, $value));
940 }
941 public function appendElementXML($name, $xmldata) {
942 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
943 $aelem->appendXMLMarkup($xmldata);
944 return $aelem;
945 }
946 public function appendLink($target, $value = '', $title = null) {
947 return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title));
948 }
949 public function appendImage($src, $alt_text = '') {
950 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
951 }
952 public function appendForm($action, $method, $name, $id = null) {
953 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
954 }
955 public function appendFormDiv($action, $method, $name, $id = null) {
956 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
957 return $formelem->appendElement('div');
958 }
959 public function appendInputHidden($name, $value) {
960 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
961 }
962 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
963 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
964 }
965 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
966 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
967 }
968 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
969 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
970 }
971 public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
972 return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value));
973 }
974 public function appendInputSearch($name, $maxlength, $size, $id = null, $value = null) {
975 return $this->appendChild($this->ownerDocument->createElementInputSearch($name, $maxlength, $size, $id, $value));
976 }
977 public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
978 return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value));
979 }
980 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
981 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
982 }
983 public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
984 return $this->appendChild($this->ownerDocument->createElementInputTel($name, $maxlength, $size, $id, $value));
985 }
986 public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
987 return $this->appendChild($this->ownerDocument->createElementInputDate($name, $id, $min, $max, $value));
988 }
989 public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
990 return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
991 }
992 public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
993 return $this->appendChild($this->ownerDocument->createElementInputDateTime($name, $id, $min, $max, $value));
994 }
995 public function appendInputColor($name, $id = null, $value = null) {
996 return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
997 }
998 public function appendInputRadio($name, $id, $value, $checked) {
999 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
1000 }
1001 public function appendInputCheckbox($name, $id, $value, $checked) {
1002 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
1003 }
1004 public function appendInputFile($name, $id, $accept) {
1005 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
1006 }
1007 public function appendInputSubmit($value) {
1008 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
1009 }
1010 public function appendButton($value, $onclick = null) {
1011 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
1012 }
1013 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
1014 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
1015 }
1016 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
1017 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
1018 }
1019 public function appendElementOption($key, $desc, $selected = false) {
1020 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
1021 }
1022 public function appendLabel($for_id, $value) {
1023 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
1024 }
1025 public function appendElementDatalist($id = null, $options = array()) {
1026 return $this->appendChild($this->ownerDocument->createElementDatalist($id, $options));
1027 }
1028 public function appendText($text) {
1029 return $this->appendChild($this->ownerDocument->createTextNode($text ?? ''));
1030 }
1031 public function appendLinebreak() {
1032 return $this->appendChild($this->ownerDocument->createElement('br'));
1033 }
1034 public function appendEntity($name) {
1035 return $this->appendChild($this->ownerDocument->createEntityReference($name));
1036 }
1037 public function appendComment($comment_data) {
1038 return $this->appendChild($this->ownerDocument->createComment($comment_data));
1039 }
1040 public function appendClonedElement($dom_element, $deep = true) {
1041 return $this->appendChild($dom_element->cloneNode($deep));
1042 }
1043 public function appendHTMLMarkup($htmldata) {
1044 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
1045 }
1046 public function appendXMLMarkup($xmldata) {
1047 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
1048 }
1049 public function appendStyleElement($styledata) {
1050 return $this->appendChild($this->ownerDocument->createElementStyle($styledata));
1051 }
1052 public function appendJSElement($jsdata) {
1053 return $this->appendChild($this->ownerDocument->createElementJS($jsdata));
1054 }
1055 public function appendJSFile($jsURL, $defer = false, $async = false) {
1056 return $this->appendChild($this->ownerDocument->createElementJSFile($jsURL, $defer, $async));
1057 }
1058 public function setClass($classname) {
1059 $this->setAttribute('class', $classname);
1060 }
1061 public function addClass($classname) {
1062 $classval = $this->getAttribute('class');
1063 if (strlen($classval)) { $classval .= ' '; }
1064 $classval .= $classname;
1065 $this->setClass($classval);
1066 return $classval;
1067 }
1068 public function setID($elem_id) {
1069 $this->setAttribute('id', $elem_id);
1070 }
1071}
1072
1073class ExtendedDocumentFragment extends DOMDocumentFragment {
1074 // ExtendedDocumentFragment PHP class
1075 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
1076 //
1077 // public function appendElement($name, [$value])
1078 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
1079 // returns the new child
1080 //
1081 // public function appendElementXML($name, $xmldata)
1082 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
1083 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
1084 // returns the new child
1085 //
1086 // public function appendLink($target, [$value], [$title])
1087 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
1088 // returns the new child
1089 //
1090 // public function appendImage($src, [$alt_text])
1091 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
1092 // returns the new child
1093 //
1094 // public function appendForm($action, $method, $name, [$id])
1095 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
1096 // returns the new child
1097 //
1098 // public function appendFormDiv($action, $method, $name, [$id])
1099 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
1100 // returns an HTML <div> that is a child of the new child
1101 //
1102 // public function appendInputHidden($name, $value)
1103 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
1104 // returns the new child
1105 //
1106 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
1107 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
1108 // returns the new child
1109 //
1110 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
1111 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
1112 // returns the new child
1113 //
1114 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
1115 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
1116 // returns the new child
1117 //
1118 // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
1119 // appends an ExtendedDocument::createElementInputRange() as a child of this fragment (see there for params)
1120 // returns the new child
1121 //
1122 // public function appendInputSearch($name, $maxlength, $size, [$id], [$value])
1123 // appends an ExtendedDocument::createElementInputSearch() as a child of this fragment (see there for params)
1124 // returns the new child
1125 //
1126 // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
1127 // appends an ExtendedDocument::createElementInputUrl() as a child of this fragment (see there for params)
1128 // returns the new child
1129 //
1130 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
1131 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
1132 // returns the new child
1133 //
1134 // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
1135 // appends an ExtendedDocument::createElementInputTel() as a child of this fragment (see there for params)
1136 // returns the new child
1137 //
1138 // public function appendInputDate($name, [$id], [$min], [$max], [$value])
1139 // appends an ExtendedDocument::createElementInputDate() as a child of this fragment (see there for params)
1140 // returns the new child
1141 //
1142 // public function appendInputTime($name, [$id], [$min], [$max], [$value])
1143 // appends an ExtendedDocument::createElementInputTime() as a child of this fragment (see there for params)
1144 // returns the new child
1145 //
1146 // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
1147 // appends an ExtendedDocument::createElementInputDateTime() as a child of this fragment (see there for params)
1148 // returns the new child
1149 //
1150 // public function appendInputColor($name, [$id], [$value])
1151 // appends an ExtendedDocument::createElementInputColor() as a child of this fragment (see there for params)
1152 //
1153 // public function appendInputRadio($name, $id, $value, $checked)
1154 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
1155 // returns the new child
1156 //
1157 // public function appendInputCheckbox($name, $id, $value, $checked)
1158 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
1159 // returns the new child
1160 //
1161 // public function appendInputFile($name, $id, $accept)
1162 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
1163 // returns the new child
1164 //
1165 // public function appendInputSubmit($value)
1166 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
1167 // returns the new child
1168 //
1169 // public function appendButton($value, $onclick = null)
1170 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
1171 // returns the new child
1172 //
1173 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
1174 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
1175 // returns the new child
1176 //
1177 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
1178 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
1179 // returns the new child
1180 //
1181 // public function appendElementOption($key, $desc, [$selected])
1182 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
1183 // returns the new child
1184 //
1185 // public function appendLabel($for_id, $value)
1186 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
1187 // returns the new child
1188 //
1189 // public function appendElementDatalist([$id], [$options])
1190 // appends an ExtendedDocument::createElementDatalist() as a child of this fragment (see there for params)
1191 // returns the new child
1192 //
1193 // public function appendText($text)
1194 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
1195 // returns the new child
1196 //
1197 // public function appendLinebreak()
1198 // appends a <br> as a child of this fragment
1199 // returns the new child
1200 //
1201 // public function appendEntity($name)
1202 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
1203 // returns the new child
1204 //
1205 // public function appendComment($comment_data)
1206 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
1207 // returns the new child
1208 //
1209 // public function appendClonedElement($dom_element, [$deep])
1210 // appends a clone of the given DOMElement as a child of this fragment
1211 // the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
1212 // returns the new child
1213 //
1214 // public function appendHTMLMarkup($htmldata)
1215 // appends a representation of the HTML data as children of this fragment
1216 // NO return value!
1217 //
1218 // public function appendXMLMarkup($xmldata)
1219 // appends a representation of the XML data as children of this fragment
1220 // NO return value!
1221 //
1222 // public function appendStyleElement($styledata)
1223 // appends an ExtendedDocument::createElementStyle() as a child of this element (see there for params)
1224 // returns the new child
1225 //
1226 // public function appendJSElement($jsdata)
1227 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
1228 // returns the new child
1229 //
1230 // public function appendJSFile($jsURL, [$defer], [$async])
1231 // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
1232 // returns the new child
1233
1234 public function appendElement($name, $value = '') {
1235 return $this->appendChild($this->ownerDocument->createElement($name, $value));
1236 }
1237 public function appendElementXML($name, $xmldata) {
1238 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
1239 $aelem->appendXMLMarkup($xmldata);
1240 return $aelem;
1241 }
1242 public function appendLink($target, $value = '', $title = null) {
1243 return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title));
1244 }
1245 public function appendImage($src, $alt_text = '') {
1246 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
1247 }
1248 public function appendForm($action, $method, $name, $id = null) {
1249 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
1250 }
1251 public function appendFormDiv($action, $method, $name, $id = null) {
1252 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
1253 return $formelem->appendElement('div');
1254 }
1255 public function appendInputHidden($name, $value) {
1256 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
1257 }
1258 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
1259 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
1260 }
1261 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
1262 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
1263 }
1264 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
1265 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
1266 }
1267 public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
1268 return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value));
1269 }
1270 public function appendInputSearch($name, $maxlength, $size, $id = null, $value = null) {
1271 return $this->appendChild($this->ownerDocument->createElementInputSearch($name, $maxlength, $size, $id, $value));
1272 }
1273 public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
1274 return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value));
1275 }
1276 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
1277 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
1278 }
1279 public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
1280 return $this->appendChild($this->ownerDocument->createElementInputTel($name, $maxlength, $size, $id, $value));
1281 }
1282 public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
1283 return $this->appendChild($this->ownerDocument->createElementInputDate($name, $id, $min, $max, $value));
1284 }
1285 public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
1286 return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
1287 }
1288 public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
1289 return $this->appendChild($this->ownerDocument->createElementInputDateTime($name, $id, $min, $max, $value));
1290 }
1291 public function appendInputColor($name, $id = null, $value = null) {
1292 return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
1293 }
1294 public function appendInputRadio($name, $id, $value, $checked) {
1295 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
1296 }
1297 public function appendInputCheckbox($name, $id, $value, $checked) {
1298 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
1299 }
1300 public function appendInputFile($name, $id, $accept) {
1301 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
1302 }
1303 public function appendInputSubmit($value) {
1304 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
1305 }
1306 public function appendButton($value, $onclick = null) {
1307 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
1308 }
1309 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
1310 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
1311 }
1312 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
1313 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
1314 }
1315 public function appendElementOption($key, $desc, $selected = false) {
1316 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
1317 }
1318 public function appendLabel($for_id, $value) {
1319 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
1320 }
1321 public function appendElementDatalist($id = null, $options = array()) {
1322 return $this->appendChild($this->ownerDocument->createElementDatalist($id, $options));
1323 }
1324 public function appendText($text) {
1325 return $this->appendChild($this->ownerDocument->createTextNode($text));
1326 }
1327 public function appendLinebreak() {
1328 return $this->appendChild($this->ownerDocument->createElement('br'));
1329 }
1330 public function appendEntity($name) {
1331 return $this->appendChild($this->ownerDocument->createEntityReference($name));
1332 }
1333 public function appendComment($comment_data) {
1334 return $this->appendChild($this->ownerDocument->createComment($comment_data));
1335 }
1336 public function appendClonedElement($dom_element, $deep = true) {
1337 return $this->appendChild($dom_element->cloneNode($deep));
1338 }
1339 public function appendHTMLMarkup($htmldata) {
1340 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
1341 }
1342 public function appendXMLMarkup($xmldata) {
1343 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
1344 }
1345 public function appendStyleElement($styledata) {
1346 return $this->appendChild($this->ownerDocument->createElementStyle($styledata));
1347 }
1348 public function appendJSElement($jsdata) {
1349 return $this->appendChild($this->ownerDocument->createElementJS($jsdata));
1350 }
1351 public function appendJSFile($jsURL, $defer = false, $async = false) {
1352 return $this->appendChild($this->ownerDocument->createElementJSFile($jsURL, $defer, $async));
1353 }
1354}
1355?>