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