2 /* ***** BEGIN LICENSE BLOCK *****
4 * The contents of this file are subject to Austrian copyright reegulations
5 * ("Urheberrecht"); you may not use this file except in compliance with
7 * This contents and any derived work, if it gets distributed in any way,
8 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
9 * either express or implied.
11 * The Original Code is KaiRo's extended DOM document classes.
13 * The Initial Developer of the Original Code is
14 * KaiRo - Robert Kaiser.
15 * Portions created by the Initial Developer are Copyright (C) 2010
16 * the Initial Developer. All Rights Reserved.
18 * Contributor(s): Robert Kaiser <kairo@kairo.at>
20 * ***** END LICENSE BLOCK ***** */
22 class ExtendedDocument extends DOMDocument {
23 // ExtendedDocument PHP class
24 // this extends the general PHP DOM Document class to simplify some usual constructs
26 // function __construct([$version], [$encoding])
28 // construct a new DOM Document that uses our element definitions
30 // static function initHTML5()
31 // initialize as an HTML5 document and return references to its basic elements.
32 // returns an associative array with the following elements: 'html', 'head', 'title', 'body'
34 // public function appendElement($name, [$value])
35 // appends a DOMDocument::createElement() as a child of this document (see there for params)
36 // returns the new child
38 // public function appendElementXML($name, $xmldata)
39 // appends a DOMDocument::createElement() with the given name as a child of this document,
40 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
41 // returns the new child
43 // public function appendLink($target, [$value])
44 // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
45 // returns the new child
47 // public function appendImage($src, [$alt_text])
48 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
49 // returns the new child
51 // public function appendForm($action, $method, $name, [$id])
52 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
53 // returns the new child
55 // public function appendFormDiv($action, $method, $name, [$id])
56 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
57 // returns an HTML <div> that is a child of the new child
59 // public function appendInputHidden($name, $value)
60 // appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
61 // returns the new child
63 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
64 // appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
65 // returns the new child
67 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
68 // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
69 // returns the new child
71 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
72 // appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params)
73 // returns the new child
75 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
76 // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
77 // returns the new child
79 // public function appendInputRadio($name, $id, $value, $checked)
80 // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
81 // returns the new child
83 // public function appendInputCheckbox($name, $id, $value, $checked)
84 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
85 // returns the new child
87 // public function appendInputFile($name, $id, $accept)
88 // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
89 // returns the new child
91 // public function appendInputSubmit($value)
92 // appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
93 // returns the new child
95 // public function appendButton($value, $onclick = null)
96 // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
97 // returns the new child
99 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
100 // appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
101 // returns the new child
103 // public function appendElementSelect($name, [$id], [$options], [$default])
104 // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
105 // returns the new child
107 // public function appendElementOption($key, $desc, [$selected])
108 // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
109 // returns the new child
111 // public function appendLabel($for_id, $value)
112 // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
113 // returns the new child
115 // public function appendText($text)
116 // appends a DOMDocument::createTextNode() as a child of this document (see there for params)
117 // returns the new child
119 // public function appendEntity($name)
120 // appends a DOMDocument::createEntityReference() as a child of this document (see there for params)
121 // returns the new child
123 // public function appendComment($comment_data)
124 // appends a DOMDocument::createComment() as a child of this document (see there for params)
125 // returns the new child
127 // public function appendHTMLMarkup($htmldata, [$parentNode])
128 // appends a representation of the HTML data as children of the given parent node, by default this document
131 // public function appendXMLMarkup($xmldata, [$parentNode])
132 // appends a representation of the XML data as children of the given parent node, by default this document
135 // public function appendJSElement($jsdata)
136 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
139 // public function appendJSFile($jsURL)
140 // appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
141 // returns the new child
143 // public function createElementLink($target, [$value])
144 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
146 // public function createElementImage($src, [$alt_text])
147 // returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
149 // public function createElementForm($action, $method, $name)
150 // returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
151 // with the given action, method, and name
153 // public function createElementInputHidden($name, $value)
154 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
156 // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
157 // returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
158 // and optionally id and value
160 // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
161 // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
162 // and optionally id and value
164 // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
165 // returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
166 // and optionally id and value
168 // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
169 // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
170 // and optionally id and value
172 // public function createElementInputRadio($name, $id, $value, $checked)
173 // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
176 // public function createElementInputCheckbox($name, $id, $value, $checked)
177 // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
180 // public function createElementInputFile($name, $id, $accept)
181 // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
183 // public function createElementInputSubmit($value)
184 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
186 // public function createElementButton($value, $onclick = null)
187 // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
189 // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
190 // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
191 // and optionally id and value
193 // public function createElementSelect($name, [$id], [$options], [$default])
194 // returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
195 // array of options (key => description) and key of the by-default selected entry
197 // public function createElementOption($key, $desc, [$selected])
198 // returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
199 // and optionally bool that tells if the entry is selected
201 // public function createElementLabel($for_id, $value)
202 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
204 // public function createElementJS($jsdata)
205 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
207 // public function createElementJSFile($jsURL)
208 // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
210 function __construct($version = '1.0', $encoding = 'utf-8') {
211 // make sure the default DOMDocument constructor runs
212 parent::__construct($version, $encoding);
213 $this->registerNodeClass('DOMElement', 'ExtendedElement');
214 $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
217 static function initHTML5() {
218 $doc = new ExtendedDocument();
219 $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
221 // Created basic HTML document structure.
222 $root = $doc->getElementsByTagName('html')->item(0);
223 $head = $root->appendElement('head');
224 $title = $head->appendElement('title');
225 $body = $root->appendElement('body');
227 return array('document' => $doc,
234 public function appendElement($name, $value = '') {
235 return $this->appendChild($this->createElement($name, $value));
237 public function appendElementXML($name, $xmldata) {
238 $aelem = $this->appendChild($this->createElement($name));
239 $aelem->appendXMLMarkup($xmldata);
240 //$aelem->appendChild($this->createXMLFragment($xmldata));
243 public function appendLink($target, $value = '') {
244 return $this->appendChild($this->createElementLink($target, $value));
246 public function appendImage($src, $alt_text = '') {
247 return $this->appendChild($this->createElementImage($src, $alt_text));
249 public function appendForm($action, $method, $name, $id = null) {
250 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
252 public function appendFormDiv($action, $method, $name, $id = null) {
253 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
254 return $formelem->appendElement('div');
256 public function appendInputHidden($name, $value) {
257 return $this->appendChild($this->createElementInputHidden($name, $value));
259 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
260 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
262 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
263 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
265 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
266 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
268 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
269 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
271 public function appendInputRadio($name, $id, $value, $checked) {
272 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
274 public function appendInputCheckbox($name, $id, $value, $checked) {
275 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
277 public function appendInputFile($name, $id, $accept) {
278 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
280 public function appendInputSubmit($value) {
281 return $this->appendChild($this->createElementInputSubmit($value));
283 public function appendButton($value, $onclick = null) {
284 return $this->appendChild($this->createElementButton($value, $onclick));
286 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
287 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
289 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
290 return $this->appendChild($this->createElementSelect($name, $id, $options, $default));
292 public function appendElementOption($key, $desc, $selected = false) {
293 return $this->appendChild($this->createElementOption($key, $desc, $selected));
295 public function appendLabel($for_id, $value) {
296 return $this->appendChild($this->createElementLabel($for_id, $value));
298 public function appendText($text) {
299 return $this->appendChild($this->createTextNode($text));
301 public function appendEntity($name) {
302 return $this->appendChild($this->createEntityReference($name));
304 public function appendComment($comment_data) {
305 return $this->appendChild($this->createComment($comment_data));
307 public function appendJSElement($jsdata) {
308 $this->appendChild($this->createElementJS($jsdata));
310 public function appendJSFile($jsdata) {
311 return $this->appendChild($this->createElementJSFile($jsdata));
314 public function appendHTMLMarkup($htmldata, $parentNode = null) {
315 if (is_null($parentNode)) { $parentNode =& $this; }
316 // XXX: just a workaround for now!
317 $parentNode->appendChild($this->createCDATASection($htmldata));
320 public function appendXMLMarkup($xmldata, $parentNode = null) {
321 if (is_null($parentNode)) { $parentNode =& $this; }
322 $tmpdoc = new ExtendedDocument;
323 $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
324 $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
325 $tmpxml .= '<root>'.$xmldata.'</root>';
326 $tmpdoc->loadXML($tmpxml);
327 foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
328 $parentNode->appendChild($this->importNode($child, true));
332 public function createElement($name, $value = '') {
333 // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
334 $aelem = parent::createElement($name);
335 $aelem->appendText($value);
339 public function createElementLink($target, $value = '') {
340 $link = $this->createElement('a', $value);
341 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
345 public function createElementImage($src, $alt_text = '') {
346 $img = $this->createElement('img');
347 $img->setAttribute('src', $src);
348 $img->setAttribute('alt', $alt_text);
352 public function createElementForm($action, $method, $name, $id = null) {
353 $formelem = $this->createElement('form');
354 $formelem->setAttribute('action', $action);
355 $formelem->setAttribute('method', $method);
356 $formelem->setAttribute('name', $name);
357 $formelem->setAttribute('id', $id);
361 public function createElementInputHidden($name, $value) {
362 $hidden = $this->createElement('input');
363 $hidden->setAttribute('type', 'hidden');
364 $hidden->setAttribute('name', $name);
365 $hidden->setAttribute('value', $value);
369 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
370 $txfield = $this->createElement('input');
371 $txfield->setAttribute('type', 'text');
372 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
373 $txfield->setAttribute('name', $name);
374 $txfield->setAttribute('maxlength', $maxlength);
375 $txfield->setAttribute('size', $size);
376 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
380 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
381 $txfield = $this->createElement('input');
382 $txfield->setAttribute('type', 'number');
383 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
384 $txfield->setAttribute('name', $name);
385 $txfield->setAttribute('maxlength', $maxlength);
386 $txfield->setAttribute('size', $size);
387 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
391 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
392 $txfield = $this->createElement('input');
393 $txfield->setAttribute('type', 'email');
394 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
395 $txfield->setAttribute('name', $name);
396 $txfield->setAttribute('maxlength', $maxlength);
397 $txfield->setAttribute('size', $size);
398 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
402 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
403 $pwfield = $this->createElement('input');
404 $pwfield->setAttribute('type', 'password');
405 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
406 $pwfield->setAttribute('name', $name);
407 $pwfield->setAttribute('maxlength', $maxlength);
408 $pwfield->setAttribute('size', $size);
409 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
413 public function createElementInputRadio($name, $id, $value, $checked) {
414 $radio = $this->createElement('input');
415 $radio->setAttribute('type', 'radio');
416 $radio->setAttribute('name', $name);
417 if (!is_null($id)) { $radio->setAttribute('id', $id); }
418 $radio->setAttribute('value', $value);
419 if ($checked) { $radio->setAttribute('checked', ''); }
423 public function createElementInputCheckbox($name, $id, $value, $checked) {
424 $cbox = $this->createElement('input');
425 $cbox->setAttribute('type', 'checkbox');
426 $cbox->setAttribute('name', $name);
427 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
428 $cbox->setAttribute('value', $value);
429 if ($checked) { $cbox->setAttribute('checked', ''); }
433 public function createElementInputFile($name, $id, $accept) {
434 $fileinput = $this->createElement('input');
435 $fileinput->setAttribute('type', 'file');
436 $fileinput->setAttribute('name', $name);
437 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
438 $fileinput->setAttribute('accept', $accept);
442 public function createElementInputSubmit($value) {
443 $submitbtn = $this->createElement('input');
444 $submitbtn->setAttribute('type', 'submit');
445 $submitbtn->setAttribute('value', $value);
449 public function createElementButton($value, $onclick = null) {
450 $btn = $this->createElement('input');
451 $btn->setAttribute('type', 'button');
452 $btn->setAttribute('value', $value);
453 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
457 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
458 $txtarea = $this->createElement('textarea', $value);
459 $txtarea->setAttribute('name', $name);
460 $txtarea->setAttribute('cols', $columns);
461 $txtarea->setAttribute('rows', $rows);
462 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
466 public function createElementSelect($name, $id = null, $options = array(), $default = null) {
467 $select = $this->createElement('select');
468 $select->setAttribute('name', $name);
469 if (!is_null($id)) { $select->setAttribute('id', $id); }
470 foreach ($options as $key => $desc) {
471 $select->appendElementOption($key, $desc, ($key == $default));
476 public function createElementOption($key, $desc, $selected = false) {
477 $option = $this->createElement('option', $desc);
478 $option->setAttribute('value', $key);
479 if ($selected) { $option->setAttribute('selected', ''); }
483 public function createElementLabel($for_id, $value) {
484 $label = $this->createElement('label', $value);
485 $label->setAttribute('for', $for_id);
489 public function createElementJS($jsdata) {
490 $jselem = $this->createElement('script');
491 // Note: type can/should be left out for HTML5.
492 $jselem->setAttribute('type', 'text/javascript');
493 $jselem->appendChild($this->createCDATASection($jsdata));
497 public function createElementJSFile($jsURL) {
498 $jselem = $this->createElement('script');
499 // Note: type can/should be left out for HTML5.
500 $jselem->setAttribute('type', 'text/javascript');
501 $jselem->setAttribute('src', $jsURL);
506 class ExtendedElement extends DOMElement {
507 // ExtendedElement PHP class
508 // this extends the general PHP DOM Element class to simplify some usual constructs
510 // public function appendElement($name, [$value])
511 // appends a DOMDocument::createElement() as a child of this element (see there for params)
512 // returns the new child
514 // public function appendElementXML($name, $xmldata)
515 // appends a DOMDocument::createElement() with the given name as a child of this element,
516 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
517 // returns the new child
519 // public function appendLink($target, [$value])
520 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
521 // returns the new child
523 // public function appendImage($src, [$alt_text])
524 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
525 // returns the new child
527 // public function appendForm($action, $method, $name, [$id])
528 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
529 // returns the new child
531 // public function appendFormDiv($action, $method, $name, [$id])
532 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
533 // returns an HTML <div> that is a child of the new child
535 // public function appendInputHidden($name, $value)
536 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
537 // returns the new child
539 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
540 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
541 // returns the new child
543 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
544 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
545 // returns the new child
547 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
548 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
549 // returns the new child
551 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
552 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
553 // returns the new child
555 // public function appendInputRadio($name, $id, $value, $checked)
556 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
557 // returns the new child
559 // public function appendInputCheckbox($name, $id, $value, $checked)
560 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
561 // returns the new child
563 // public function appendInputFile($name, $id, $accept)
564 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
565 // returns the new child
567 // public function appendInputSubmit($value)
568 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
569 // returns the new child
571 // public function appendButton($value, $onclick = null)
572 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
573 // returns the new child
575 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
576 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
577 // returns the new child
579 // public function appendElementSelect($name, [$id], [$options], [$default])
580 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
581 // returns the new child
583 // public function appendElementOption($key, $desc, [$selected])
584 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
585 // returns the new child
587 // public function appendLabel($for_id, $value)
588 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
589 // returns the new child
591 // public function appendText($text)
592 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
593 // returns the new child
595 // public function appendEntity($name)
596 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
597 // returns the new child
599 // public function appendComment($comment_data)
600 // appends a DOMDocument::createComment() as a child of this element (see there for params)
601 // returns the new child
603 // public function appendHTMLMarkup($htmldata)
604 // appends a representation of the HTML data as children of this element
607 // public function appendXMLMarkup($xmldata)
608 // appends a representation of the XML data as children of this element
611 // public function appendJSElement($jsdata)
612 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
615 // public function appendJSFile($jsURL)
616 // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
617 // returns the new child
619 public function appendElement($name, $value = '') {
620 return $this->appendChild($this->ownerDocument->createElement($name, $value));
622 public function appendElementXML($name, $xmldata) {
623 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
624 $aelem->appendXMLMarkup($xmldata);
627 public function appendLink($target, $value = '') {
628 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
630 public function appendImage($src, $alt_text = '') {
631 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
633 public function appendForm($action, $method, $name, $id = null) {
634 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
636 public function appendFormDiv($action, $method, $name, $id = null) {
637 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
638 return $formelem->appendElement('div');
640 public function appendInputHidden($name, $value) {
641 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
643 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
644 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
646 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
647 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
649 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
650 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
652 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
653 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
655 public function appendInputRadio($name, $id, $value, $checked) {
656 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
658 public function appendInputCheckbox($name, $id, $value, $checked) {
659 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
661 public function appendInputFile($name, $id, $accept) {
662 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
664 public function appendInputSubmit($value) {
665 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
667 public function appendButton($value, $onclick = null) {
668 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
670 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
671 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
673 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
674 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
676 public function appendElementOption($key, $desc, $selected = false) {
677 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
679 public function appendLabel($for_id, $value) {
680 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
682 public function appendText($text) {
683 return $this->appendChild($this->ownerDocument->createTextNode($text));
685 public function appendEntity($name) {
686 return $this->appendChild($this->ownerDocument->createEntityReference($name));
688 public function appendComment($comment_data) {
689 return $this->appendChild($this->ownerDocument->createComment($comment_data));
691 public function appendHTMLMarkup($htmldata) {
692 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
694 public function appendXMLMarkup($xmldata) {
695 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
697 public function appendJSElement($jsdata) {
698 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
700 public function appendJSFile($jsdata) {
701 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
705 class ExtendedDocumentFragment extends DOMDocumentFragment {
706 // ExtendedDocumentFragment PHP class
707 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
709 // public function appendElement($name, [$value])
710 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
711 // returns the new child
713 // public function appendElementXML($name, $xmldata)
714 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
715 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
716 // returns the new child
718 // public function appendLink($target, [$value])
719 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
720 // returns the new child
722 // public function appendImage($src, [$alt_text])
723 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
724 // returns the new child
726 // public function appendForm($action, $method, $name, [$id])
727 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
728 // returns the new child
730 // public function appendFormDiv($action, $method, $name, [$id])
731 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
732 // returns an HTML <div> that is a child of the new child
734 // public function appendInputHidden($name, $value)
735 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
736 // returns the new child
738 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
739 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
740 // returns the new child
742 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
743 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
744 // returns the new child
746 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
747 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
748 // returns the new child
750 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
751 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
752 // returns the new child
754 // public function appendInputRadio($name, $id, $value, $checked)
755 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
756 // returns the new child
758 // public function appendInputCheckbox($name, $id, $value, $checked)
759 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
760 // returns the new child
762 // public function appendInputFile($name, $id, $accept)
763 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
764 // returns the new child
766 // public function appendInputSubmit($value)
767 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
768 // returns the new child
770 // public function appendButton($value, $onclick = null)
771 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
772 // returns the new child
774 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
775 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
776 // returns the new child
778 // public function appendElementSelect($name, [$id], [$options], [$default])
779 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
780 // returns the new child
782 // public function appendElementOption($key, $desc, [$selected])
783 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
784 // returns the new child
786 // public function appendLabel($for_id, $value)
787 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
788 // returns the new child
790 // public function appendText($text)
791 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
792 // returns the new child
794 // public function appendEntity($name)
795 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
796 // returns the new child
798 // public function appendComment($comment_data)
799 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
800 // returns the new child
802 // public function appendHTMLMarkup($htmldata)
803 // appends a representation of the HTML data as children of this fragment
806 // public function appendXMLMarkup($xmldata)
807 // appends a representation of the XML data as children of this fragment
810 // public function appendJSElement($jsdata)
811 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
814 // public function appendJSFile($jsURL)
815 // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
816 // returns the new child
818 public function appendElement($name, $value = '') {
819 return $this->appendChild($this->ownerDocument->createElement($name, $value));
821 public function appendElementXML($name, $xmldata) {
822 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
823 $aelem->appendXMLMarkup($xmldata);
826 public function appendLink($target, $value = '') {
827 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
829 public function appendImage($src, $alt_text = '') {
830 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
832 public function appendForm($action, $method, $name, $id = null) {
833 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
835 public function appendFormDiv($action, $method, $name, $id = null) {
836 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
837 return $formelem->appendElement('div');
839 public function appendInputHidden($name, $value) {
840 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
842 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
843 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
845 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
846 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
848 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
849 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
851 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
852 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
854 public function appendInputRadio($name, $id, $value, $checked) {
855 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
857 public function appendInputCheckbox($name, $id, $value, $checked) {
858 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
860 public function appendInputFile($name, $id, $accept) {
861 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
863 public function appendInputSubmit($value) {
864 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
866 public function appendButton($value, $onclick = null) {
867 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
869 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
870 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
872 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
873 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
875 public function appendElementOption($key, $desc, $selected = false) {
876 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
878 public function appendLabel($for_id, $value) {
879 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
881 public function appendText($text) {
882 return $this->appendChild($this->ownerDocument->createTextNode($text));
884 public function appendEntity($name) {
885 return $this->appendChild($this->ownerDocument->createEntityReference($name));
887 public function appendComment($comment_data) {
888 return $this->appendChild($this->ownerDocument->createComment($comment_data));
890 public function appendHTMLMarkup($htmldata) {
891 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
893 public function appendXMLMarkup($xmldata) {
894 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
896 public function appendJSElement($jsdata) {
897 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
899 public function appendJSFile($jsdata) {
900 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));