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/. */
6 class ExtendedDocument extends DOMDocument {
7 // ExtendedDocument PHP class
8 // this extends the general PHP DOM Document class to simplify some usual constructs
10 // function __construct([$version], [$encoding])
12 // construct a new DOM Document that uses our element definitions
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'
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
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
28 // public function appendLink($target, [$value])
29 // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
30 // returns the new child
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
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
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
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
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
52 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
53 // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
54 // returns the new child
56 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
57 // appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params)
58 // returns the new child
60 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
61 // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
62 // returns the new child
64 // public function appendInputRadio($name, $id, $value, $checked)
65 // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
66 // returns the new child
68 // public function appendInputCheckbox($name, $id, $value, $checked)
69 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
70 // returns the new child
72 // public function appendInputFile($name, $id, $accept)
73 // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
74 // returns the new child
76 // public function appendInputSubmit($value)
77 // appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
78 // returns the new child
80 // public function appendButton($value, $onclick = null)
81 // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
82 // returns the new child
84 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
85 // appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
86 // returns the new child
88 // public function appendElementSelect($name, [$id], [$options], [$default])
89 // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
90 // returns the new child
92 // public function appendElementOption($key, $desc, [$selected])
93 // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
94 // returns the new child
96 // public function appendLabel($for_id, $value)
97 // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
98 // returns the new child
100 // public function appendText($text)
101 // appends a DOMDocument::createTextNode() as a child of this document (see there for params)
102 // returns the new child
104 // public function appendEntity($name)
105 // appends a DOMDocument::createEntityReference() as a child of this document (see there for params)
106 // returns the new child
108 // public function appendComment($comment_data)
109 // appends a DOMDocument::createComment() as a child of this document (see there for params)
110 // returns the new child
112 // public function appendHTMLMarkup($htmldata, [$parentNode])
113 // appends a representation of the HTML data as children of the given parent node, by default this document
116 // public function appendXMLMarkup($xmldata, [$parentNode])
117 // appends a representation of the XML data as children of the given parent node, by default this document
120 // public function appendJSElement($jsdata)
121 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
124 // public function appendJSFile($jsURL)
125 // appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
126 // returns the new child
128 // public function createElementLink($target, [$value])
129 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
131 // public function createElementImage($src, [$alt_text])
132 // returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
134 // public function createElementForm($action, $method, $name)
135 // returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
136 // with the given action, method, and name
138 // public function createElementInputHidden($name, $value)
139 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
141 // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
142 // returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
143 // and optionally id and value
145 // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
146 // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
147 // and optionally id and value
149 // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
150 // returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
151 // and optionally id and value
153 // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
154 // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
155 // and optionally id and value
157 // public function createElementInputRadio($name, $id, $value, $checked)
158 // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
161 // public function createElementInputCheckbox($name, $id, $value, $checked)
162 // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
165 // public function createElementInputFile($name, $id, $accept)
166 // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
168 // public function createElementInputSubmit($value)
169 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
171 // public function createElementButton($value, $onclick = null)
172 // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
174 // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
175 // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
176 // and optionally id and value
178 // public function createElementSelect($name, [$id], [$options], [$default])
179 // returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
180 // array of options (key => description) and key of the by-default selected entry
182 // public function createElementOption($key, $desc, [$selected])
183 // returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
184 // and optionally bool that tells if the entry is selected
186 // public function createElementLabel($for_id, $value)
187 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
189 // public function createElementJS($jsdata)
190 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
192 // public function createElementJSFile($jsURL)
193 // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
195 function __construct($version = '1.0', $encoding = 'utf-8') {
196 // make sure the default DOMDocument constructor runs
197 parent::__construct($version, $encoding);
198 $this->registerNodeClass('DOMElement', 'ExtendedElement');
199 $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
202 static function initHTML5($doc = null) {
203 if (is_null($doc)) { $doc = new ExtendedDocument(); }
204 $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
206 // Created basic HTML document structure.
207 $root = $doc->getElementsByTagName('html')->item(0);
208 $head = $root->appendElement('head');
209 $title = $head->appendElement('title');
210 $body = $root->appendElement('body');
212 return array('document' => $doc,
219 public function appendElement($name, $value = '') {
220 return $this->appendChild($this->createElement($name, $value));
222 public function appendElementXML($name, $xmldata) {
223 $aelem = $this->appendChild($this->createElement($name));
224 $aelem->appendXMLMarkup($xmldata);
225 //$aelem->appendChild($this->createXMLFragment($xmldata));
228 public function appendLink($target, $value = '') {
229 return $this->appendChild($this->createElementLink($target, $value));
231 public function appendImage($src, $alt_text = '') {
232 return $this->appendChild($this->createElementImage($src, $alt_text));
234 public function appendForm($action, $method, $name, $id = null) {
235 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
237 public function appendFormDiv($action, $method, $name, $id = null) {
238 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
239 return $formelem->appendElement('div');
241 public function appendInputHidden($name, $value) {
242 return $this->appendChild($this->createElementInputHidden($name, $value));
244 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
245 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
247 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
248 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
250 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
251 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
253 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
254 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
256 public function appendInputRadio($name, $id, $value, $checked) {
257 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
259 public function appendInputCheckbox($name, $id, $value, $checked) {
260 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
262 public function appendInputFile($name, $id, $accept) {
263 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
265 public function appendInputSubmit($value) {
266 return $this->appendChild($this->createElementInputSubmit($value));
268 public function appendButton($value, $onclick = null) {
269 return $this->appendChild($this->createElementButton($value, $onclick));
271 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
272 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
274 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
275 return $this->appendChild($this->createElementSelect($name, $id, $options, $default));
277 public function appendElementOption($key, $desc, $selected = false) {
278 return $this->appendChild($this->createElementOption($key, $desc, $selected));
280 public function appendLabel($for_id, $value) {
281 return $this->appendChild($this->createElementLabel($for_id, $value));
283 public function appendText($text) {
284 return $this->appendChild($this->createTextNode($text));
286 public function appendEntity($name) {
287 return $this->appendChild($this->createEntityReference($name));
289 public function appendComment($comment_data) {
290 return $this->appendChild($this->createComment($comment_data));
292 public function appendJSElement($jsdata) {
293 $this->appendChild($this->createElementJS($jsdata));
295 public function appendJSFile($jsdata) {
296 return $this->appendChild($this->createElementJSFile($jsdata));
299 public function appendHTMLMarkup($htmldata, $parentNode = null) {
300 if (is_null($parentNode)) { $parentNode =& $this; }
301 // XXX: just a workaround for now!
302 $parentNode->appendChild($this->createCDATASection($htmldata));
305 public function appendXMLMarkup($xmldata, $parentNode = null) {
306 if (is_null($parentNode)) { $parentNode =& $this; }
307 $tmpdoc = new ExtendedDocument;
308 $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
309 $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
310 $tmpxml .= '<root>'.$xmldata.'</root>';
311 $tmpdoc->loadXML($tmpxml);
312 foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
313 $parentNode->appendChild($this->importNode($child, true));
317 public function createElement($name, $value = '') {
318 // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
319 $aelem = parent::createElement($name);
320 $aelem->appendText($value);
324 public function createElementLink($target, $value = '') {
325 $link = $this->createElement('a', $value);
326 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
330 public function createElementImage($src, $alt_text = '') {
331 $img = $this->createElement('img');
332 $img->setAttribute('src', $src);
333 $img->setAttribute('alt', $alt_text);
337 public function createElementForm($action, $method, $name, $id = null) {
338 $formelem = $this->createElement('form');
339 $formelem->setAttribute('action', $action);
340 $formelem->setAttribute('method', $method);
341 $formelem->setAttribute('name', $name);
342 $formelem->setAttribute('id', $id);
346 public function createElementInputHidden($name, $value) {
347 $hidden = $this->createElement('input');
348 $hidden->setAttribute('type', 'hidden');
349 $hidden->setAttribute('name', $name);
350 $hidden->setAttribute('value', $value);
354 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
355 $txfield = $this->createElement('input');
356 $txfield->setAttribute('type', 'text');
357 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
358 $txfield->setAttribute('name', $name);
359 $txfield->setAttribute('maxlength', $maxlength);
360 $txfield->setAttribute('size', $size);
361 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
365 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
366 $txfield = $this->createElement('input');
367 $txfield->setAttribute('type', 'number');
368 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
369 $txfield->setAttribute('name', $name);
370 $txfield->setAttribute('maxlength', $maxlength);
371 $txfield->setAttribute('size', $size);
372 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
376 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
377 $txfield = $this->createElement('input');
378 $txfield->setAttribute('type', 'email');
379 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
380 $txfield->setAttribute('name', $name);
381 $txfield->setAttribute('maxlength', $maxlength);
382 $txfield->setAttribute('size', $size);
383 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
387 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
388 $pwfield = $this->createElement('input');
389 $pwfield->setAttribute('type', 'password');
390 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
391 $pwfield->setAttribute('name', $name);
392 $pwfield->setAttribute('maxlength', $maxlength);
393 $pwfield->setAttribute('size', $size);
394 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
398 public function createElementInputRadio($name, $id, $value, $checked) {
399 $radio = $this->createElement('input');
400 $radio->setAttribute('type', 'radio');
401 $radio->setAttribute('name', $name);
402 if (!is_null($id)) { $radio->setAttribute('id', $id); }
403 $radio->setAttribute('value', $value);
404 if ($checked) { $radio->setAttribute('checked', ''); }
408 public function createElementInputCheckbox($name, $id, $value, $checked) {
409 $cbox = $this->createElement('input');
410 $cbox->setAttribute('type', 'checkbox');
411 $cbox->setAttribute('name', $name);
412 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
413 $cbox->setAttribute('value', $value);
414 if ($checked) { $cbox->setAttribute('checked', ''); }
418 public function createElementInputFile($name, $id, $accept) {
419 $fileinput = $this->createElement('input');
420 $fileinput->setAttribute('type', 'file');
421 $fileinput->setAttribute('name', $name);
422 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
423 $fileinput->setAttribute('accept', $accept);
427 public function createElementInputSubmit($value) {
428 $submitbtn = $this->createElement('input');
429 $submitbtn->setAttribute('type', 'submit');
430 $submitbtn->setAttribute('value', $value);
434 public function createElementButton($value, $onclick = null) {
435 $btn = $this->createElement('input');
436 $btn->setAttribute('type', 'button');
437 $btn->setAttribute('value', $value);
438 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
442 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
443 $txtarea = $this->createElement('textarea', $value);
444 $txtarea->setAttribute('name', $name);
445 $txtarea->setAttribute('cols', $columns);
446 $txtarea->setAttribute('rows', $rows);
447 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
451 public function createElementSelect($name, $id = null, $options = array(), $default = null) {
452 $select = $this->createElement('select');
453 $select->setAttribute('name', $name);
454 if (!is_null($id)) { $select->setAttribute('id', $id); }
455 foreach ($options as $key => $desc) {
456 $select->appendElementOption($key, $desc, ($key == $default));
461 public function createElementOption($key, $desc, $selected = false) {
462 $option = $this->createElement('option', $desc);
463 $option->setAttribute('value', $key);
464 if ($selected) { $option->setAttribute('selected', ''); }
468 public function createElementLabel($for_id, $value) {
469 $label = $this->createElement('label', $value);
470 $label->setAttribute('for', $for_id);
474 public function createElementJS($jsdata) {
475 $jselem = $this->createElement('script');
476 // Note: type can/should be left out for HTML5.
477 $jselem->setAttribute('type', 'text/javascript');
478 $jselem->appendChild($this->createCDATASection($jsdata));
482 public function createElementJSFile($jsURL) {
483 $jselem = $this->createElement('script');
484 // Note: type can/should be left out for HTML5.
485 $jselem->setAttribute('type', 'text/javascript');
486 $jselem->setAttribute('src', $jsURL);
491 class ExtendedElement extends DOMElement {
492 // ExtendedElement PHP class
493 // this extends the general PHP DOM Element class to simplify some usual constructs
495 // public function appendElement($name, [$value])
496 // appends a DOMDocument::createElement() as a child of this element (see there for params)
497 // returns the new child
499 // public function appendElementXML($name, $xmldata)
500 // appends a DOMDocument::createElement() with the given name as a child of this element,
501 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
502 // returns the new child
504 // public function appendLink($target, [$value])
505 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
506 // returns the new child
508 // public function appendImage($src, [$alt_text])
509 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
510 // returns the new child
512 // public function appendForm($action, $method, $name, [$id])
513 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
514 // returns the new child
516 // public function appendFormDiv($action, $method, $name, [$id])
517 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
518 // returns an HTML <div> that is a child of the new child
520 // public function appendInputHidden($name, $value)
521 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
522 // returns the new child
524 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
525 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
526 // returns the new child
528 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
529 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
530 // returns the new child
532 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
533 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
534 // returns the new child
536 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
537 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
538 // returns the new child
540 // public function appendInputRadio($name, $id, $value, $checked)
541 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
542 // returns the new child
544 // public function appendInputCheckbox($name, $id, $value, $checked)
545 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
546 // returns the new child
548 // public function appendInputFile($name, $id, $accept)
549 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
550 // returns the new child
552 // public function appendInputSubmit($value)
553 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
554 // returns the new child
556 // public function appendButton($value, $onclick = null)
557 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
558 // returns the new child
560 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
561 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
562 // returns the new child
564 // public function appendElementSelect($name, [$id], [$options], [$default])
565 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
566 // returns the new child
568 // public function appendElementOption($key, $desc, [$selected])
569 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
570 // returns the new child
572 // public function appendLabel($for_id, $value)
573 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
574 // returns the new child
576 // public function appendText($text)
577 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
578 // returns the new child
580 // public function appendEntity($name)
581 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
582 // returns the new child
584 // public function appendComment($comment_data)
585 // appends a DOMDocument::createComment() as a child of this element (see there for params)
586 // returns the new child
588 // public function appendHTMLMarkup($htmldata)
589 // appends a representation of the HTML data as children of this element
592 // public function appendXMLMarkup($xmldata)
593 // appends a representation of the XML data as children of this element
596 // public function appendJSElement($jsdata)
597 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
600 // public function appendJSFile($jsURL)
601 // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
602 // returns the new child
604 public function appendElement($name, $value = '') {
605 return $this->appendChild($this->ownerDocument->createElement($name, $value));
607 public function appendElementXML($name, $xmldata) {
608 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
609 $aelem->appendXMLMarkup($xmldata);
612 public function appendLink($target, $value = '') {
613 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
615 public function appendImage($src, $alt_text = '') {
616 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
618 public function appendForm($action, $method, $name, $id = null) {
619 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
621 public function appendFormDiv($action, $method, $name, $id = null) {
622 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
623 return $formelem->appendElement('div');
625 public function appendInputHidden($name, $value) {
626 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
628 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
629 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
631 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
632 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
634 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
635 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
637 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
638 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
640 public function appendInputRadio($name, $id, $value, $checked) {
641 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
643 public function appendInputCheckbox($name, $id, $value, $checked) {
644 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
646 public function appendInputFile($name, $id, $accept) {
647 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
649 public function appendInputSubmit($value) {
650 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
652 public function appendButton($value, $onclick = null) {
653 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
655 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
656 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
658 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
659 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
661 public function appendElementOption($key, $desc, $selected = false) {
662 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
664 public function appendLabel($for_id, $value) {
665 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
667 public function appendText($text) {
668 return $this->appendChild($this->ownerDocument->createTextNode($text));
670 public function appendEntity($name) {
671 return $this->appendChild($this->ownerDocument->createEntityReference($name));
673 public function appendComment($comment_data) {
674 return $this->appendChild($this->ownerDocument->createComment($comment_data));
676 public function appendHTMLMarkup($htmldata) {
677 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
679 public function appendXMLMarkup($xmldata) {
680 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
682 public function appendJSElement($jsdata) {
683 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
685 public function appendJSFile($jsdata) {
686 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
690 class ExtendedDocumentFragment extends DOMDocumentFragment {
691 // ExtendedDocumentFragment PHP class
692 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
694 // public function appendElement($name, [$value])
695 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
696 // returns the new child
698 // public function appendElementXML($name, $xmldata)
699 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
700 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
701 // returns the new child
703 // public function appendLink($target, [$value])
704 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
705 // returns the new child
707 // public function appendImage($src, [$alt_text])
708 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
709 // returns the new child
711 // public function appendForm($action, $method, $name, [$id])
712 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
713 // returns the new child
715 // public function appendFormDiv($action, $method, $name, [$id])
716 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
717 // returns an HTML <div> that is a child of the new child
719 // public function appendInputHidden($name, $value)
720 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
721 // returns the new child
723 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
724 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
725 // returns the new child
727 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
728 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
729 // returns the new child
731 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
732 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
733 // returns the new child
735 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
736 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
737 // returns the new child
739 // public function appendInputRadio($name, $id, $value, $checked)
740 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
741 // returns the new child
743 // public function appendInputCheckbox($name, $id, $value, $checked)
744 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
745 // returns the new child
747 // public function appendInputFile($name, $id, $accept)
748 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
749 // returns the new child
751 // public function appendInputSubmit($value)
752 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
753 // returns the new child
755 // public function appendButton($value, $onclick = null)
756 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
757 // returns the new child
759 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
760 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
761 // returns the new child
763 // public function appendElementSelect($name, [$id], [$options], [$default])
764 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
765 // returns the new child
767 // public function appendElementOption($key, $desc, [$selected])
768 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
769 // returns the new child
771 // public function appendLabel($for_id, $value)
772 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
773 // returns the new child
775 // public function appendText($text)
776 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
777 // returns the new child
779 // public function appendEntity($name)
780 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
781 // returns the new child
783 // public function appendComment($comment_data)
784 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
785 // returns the new child
787 // public function appendHTMLMarkup($htmldata)
788 // appends a representation of the HTML data as children of this fragment
791 // public function appendXMLMarkup($xmldata)
792 // appends a representation of the XML data as children of this fragment
795 // public function appendJSElement($jsdata)
796 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
799 // public function appendJSFile($jsURL)
800 // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
801 // returns the new child
803 public function appendElement($name, $value = '') {
804 return $this->appendChild($this->ownerDocument->createElement($name, $value));
806 public function appendElementXML($name, $xmldata) {
807 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
808 $aelem->appendXMLMarkup($xmldata);
811 public function appendLink($target, $value = '') {
812 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
814 public function appendImage($src, $alt_text = '') {
815 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
817 public function appendForm($action, $method, $name, $id = null) {
818 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
820 public function appendFormDiv($action, $method, $name, $id = null) {
821 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
822 return $formelem->appendElement('div');
824 public function appendInputHidden($name, $value) {
825 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
827 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
828 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
830 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
831 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
833 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
834 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
836 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
837 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
839 public function appendInputRadio($name, $id, $value, $checked) {
840 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
842 public function appendInputCheckbox($name, $id, $value, $checked) {
843 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
845 public function appendInputFile($name, $id, $accept) {
846 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
848 public function appendInputSubmit($value) {
849 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
851 public function appendButton($value, $onclick = null) {
852 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
854 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
855 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
857 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
858 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
860 public function appendElementOption($key, $desc, $selected = false) {
861 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
863 public function appendLabel($for_id, $value) {
864 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
866 public function appendText($text) {
867 return $this->appendChild($this->ownerDocument->createTextNode($text));
869 public function appendEntity($name) {
870 return $this->appendChild($this->ownerDocument->createEntityReference($name));
872 public function appendComment($comment_data) {
873 return $this->appendChild($this->ownerDocument->createComment($comment_data));
875 public function appendHTMLMarkup($htmldata) {
876 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
878 public function appendXMLMarkup($xmldata) {
879 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
881 public function appendJSElement($jsdata) {
882 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
884 public function appendJSFile($jsdata) {
885 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));