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()
15 // initialize as an HTML5 document and return references to its basic elements.
16 // returns an associative array with the following elements: 'html', 'head', 'title', 'body'
18 // public function appendElement($name, [$value])
19 // appends a DOMDocument::createElement() as a child of this document (see there for params)
20 // returns the new child
22 // public function appendElementXML($name, $xmldata)
23 // appends a DOMDocument::createElement() with the given name as a child of this document,
24 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
25 // returns the new child
27 // public function appendLink($target, [$value])
28 // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
29 // returns the new child
31 // public function appendImage($src, [$alt_text])
32 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
33 // returns the new child
35 // public function appendForm($action, $method, $name, [$id])
36 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
37 // returns the new child
39 // public function appendFormDiv($action, $method, $name, [$id])
40 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
41 // returns an HTML <div> that is a child of the new child
43 // public function appendInputHidden($name, $value)
44 // appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
45 // returns the new child
47 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
48 // appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
49 // returns the new child
51 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
52 // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
53 // returns the new child
55 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
56 // appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params)
57 // returns the new child
59 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
60 // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
61 // returns the new child
63 // public function appendInputRadio($name, $id, $value, $checked)
64 // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
65 // returns the new child
67 // public function appendInputCheckbox($name, $id, $value, $checked)
68 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
69 // returns the new child
71 // public function appendInputFile($name, $id, $accept)
72 // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
73 // returns the new child
75 // public function appendInputSubmit($value)
76 // appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
77 // returns the new child
79 // public function appendButton($value, $onclick = null)
80 // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
81 // returns the new child
83 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
84 // appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
85 // returns the new child
87 // public function appendElementSelect($name, [$id], [$options], [$default])
88 // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
89 // returns the new child
91 // public function appendElementOption($key, $desc, [$selected])
92 // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
93 // returns the new child
95 // public function appendLabel($for_id, $value)
96 // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
97 // returns the new child
99 // public function appendText($text)
100 // appends a DOMDocument::createTextNode() as a child of this document (see there for params)
101 // returns the new child
103 // public function appendEntity($name)
104 // appends a DOMDocument::createEntityReference() as a child of this document (see there for params)
105 // returns the new child
107 // public function appendComment($comment_data)
108 // appends a DOMDocument::createComment() as a child of this document (see there for params)
109 // returns the new child
111 // public function appendHTMLMarkup($htmldata, [$parentNode])
112 // appends a representation of the HTML data as children of the given parent node, by default this document
115 // public function appendXMLMarkup($xmldata, [$parentNode])
116 // appends a representation of the XML data as children of the given parent node, by default this document
119 // public function appendJSElement($jsdata)
120 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
123 // public function appendJSFile($jsURL)
124 // appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
125 // returns the new child
127 // public function createElementLink($target, [$value])
128 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
130 // public function createElementImage($src, [$alt_text])
131 // returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
133 // public function createElementForm($action, $method, $name)
134 // returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
135 // with the given action, method, and name
137 // public function createElementInputHidden($name, $value)
138 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
140 // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
141 // returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
142 // and optionally id and value
144 // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
145 // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
146 // and optionally id and value
148 // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
149 // returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
150 // and optionally id and value
152 // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
153 // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
154 // and optionally id and value
156 // public function createElementInputRadio($name, $id, $value, $checked)
157 // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
160 // public function createElementInputCheckbox($name, $id, $value, $checked)
161 // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
164 // public function createElementInputFile($name, $id, $accept)
165 // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
167 // public function createElementInputSubmit($value)
168 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
170 // public function createElementButton($value, $onclick = null)
171 // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
173 // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
174 // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
175 // and optionally id and value
177 // public function createElementSelect($name, [$id], [$options], [$default])
178 // returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
179 // array of options (key => description) and key of the by-default selected entry
181 // public function createElementOption($key, $desc, [$selected])
182 // returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
183 // and optionally bool that tells if the entry is selected
185 // public function createElementLabel($for_id, $value)
186 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
188 // public function createElementJS($jsdata)
189 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
191 // public function createElementJSFile($jsURL)
192 // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
194 function __construct($version = '1.0', $encoding = 'utf-8') {
195 // make sure the default DOMDocument constructor runs
196 parent::__construct($version, $encoding);
197 $this->registerNodeClass('DOMElement', 'ExtendedElement');
198 $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
201 static function initHTML5() {
202 $doc = new ExtendedDocument();
203 $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
205 // Created basic HTML document structure.
206 $root = $doc->getElementsByTagName('html')->item(0);
207 $head = $root->appendElement('head');
208 $title = $head->appendElement('title');
209 $body = $root->appendElement('body');
211 return array('document' => $doc,
218 public function appendElement($name, $value = '') {
219 return $this->appendChild($this->createElement($name, $value));
221 public function appendElementXML($name, $xmldata) {
222 $aelem = $this->appendChild($this->createElement($name));
223 $aelem->appendXMLMarkup($xmldata);
224 //$aelem->appendChild($this->createXMLFragment($xmldata));
227 public function appendLink($target, $value = '') {
228 return $this->appendChild($this->createElementLink($target, $value));
230 public function appendImage($src, $alt_text = '') {
231 return $this->appendChild($this->createElementImage($src, $alt_text));
233 public function appendForm($action, $method, $name, $id = null) {
234 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
236 public function appendFormDiv($action, $method, $name, $id = null) {
237 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
238 return $formelem->appendElement('div');
240 public function appendInputHidden($name, $value) {
241 return $this->appendChild($this->createElementInputHidden($name, $value));
243 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
244 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
246 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
247 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
249 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
250 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
252 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
253 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
255 public function appendInputRadio($name, $id, $value, $checked) {
256 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
258 public function appendInputCheckbox($name, $id, $value, $checked) {
259 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
261 public function appendInputFile($name, $id, $accept) {
262 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
264 public function appendInputSubmit($value) {
265 return $this->appendChild($this->createElementInputSubmit($value));
267 public function appendButton($value, $onclick = null) {
268 return $this->appendChild($this->createElementButton($value, $onclick));
270 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
271 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
273 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
274 return $this->appendChild($this->createElementSelect($name, $id, $options, $default));
276 public function appendElementOption($key, $desc, $selected = false) {
277 return $this->appendChild($this->createElementOption($key, $desc, $selected));
279 public function appendLabel($for_id, $value) {
280 return $this->appendChild($this->createElementLabel($for_id, $value));
282 public function appendText($text) {
283 return $this->appendChild($this->createTextNode($text));
285 public function appendEntity($name) {
286 return $this->appendChild($this->createEntityReference($name));
288 public function appendComment($comment_data) {
289 return $this->appendChild($this->createComment($comment_data));
291 public function appendJSElement($jsdata) {
292 $this->appendChild($this->createElementJS($jsdata));
294 public function appendJSFile($jsdata) {
295 return $this->appendChild($this->createElementJSFile($jsdata));
298 public function appendHTMLMarkup($htmldata, $parentNode = null) {
299 if (is_null($parentNode)) { $parentNode =& $this; }
300 // XXX: just a workaround for now!
301 $parentNode->appendChild($this->createCDATASection($htmldata));
304 public function appendXMLMarkup($xmldata, $parentNode = null) {
305 if (is_null($parentNode)) { $parentNode =& $this; }
306 $tmpdoc = new ExtendedDocument;
307 $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
308 $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
309 $tmpxml .= '<root>'.$xmldata.'</root>';
310 $tmpdoc->loadXML($tmpxml);
311 foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
312 $parentNode->appendChild($this->importNode($child, true));
316 public function createElement($name, $value = '') {
317 // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
318 $aelem = parent::createElement($name);
319 $aelem->appendText($value);
323 public function createElementLink($target, $value = '') {
324 $link = $this->createElement('a', $value);
325 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
329 public function createElementImage($src, $alt_text = '') {
330 $img = $this->createElement('img');
331 $img->setAttribute('src', $src);
332 $img->setAttribute('alt', $alt_text);
336 public function createElementForm($action, $method, $name, $id = null) {
337 $formelem = $this->createElement('form');
338 $formelem->setAttribute('action', $action);
339 $formelem->setAttribute('method', $method);
340 $formelem->setAttribute('name', $name);
341 $formelem->setAttribute('id', $id);
345 public function createElementInputHidden($name, $value) {
346 $hidden = $this->createElement('input');
347 $hidden->setAttribute('type', 'hidden');
348 $hidden->setAttribute('name', $name);
349 $hidden->setAttribute('value', $value);
353 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
354 $txfield = $this->createElement('input');
355 $txfield->setAttribute('type', 'text');
356 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
357 $txfield->setAttribute('name', $name);
358 $txfield->setAttribute('maxlength', $maxlength);
359 $txfield->setAttribute('size', $size);
360 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
364 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
365 $txfield = $this->createElement('input');
366 $txfield->setAttribute('type', 'number');
367 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
368 $txfield->setAttribute('name', $name);
369 $txfield->setAttribute('maxlength', $maxlength);
370 $txfield->setAttribute('size', $size);
371 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
375 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
376 $txfield = $this->createElement('input');
377 $txfield->setAttribute('type', 'email');
378 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
379 $txfield->setAttribute('name', $name);
380 $txfield->setAttribute('maxlength', $maxlength);
381 $txfield->setAttribute('size', $size);
382 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
386 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
387 $pwfield = $this->createElement('input');
388 $pwfield->setAttribute('type', 'password');
389 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
390 $pwfield->setAttribute('name', $name);
391 $pwfield->setAttribute('maxlength', $maxlength);
392 $pwfield->setAttribute('size', $size);
393 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
397 public function createElementInputRadio($name, $id, $value, $checked) {
398 $radio = $this->createElement('input');
399 $radio->setAttribute('type', 'radio');
400 $radio->setAttribute('name', $name);
401 if (!is_null($id)) { $radio->setAttribute('id', $id); }
402 $radio->setAttribute('value', $value);
403 if ($checked) { $radio->setAttribute('checked', ''); }
407 public function createElementInputCheckbox($name, $id, $value, $checked) {
408 $cbox = $this->createElement('input');
409 $cbox->setAttribute('type', 'checkbox');
410 $cbox->setAttribute('name', $name);
411 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
412 $cbox->setAttribute('value', $value);
413 if ($checked) { $cbox->setAttribute('checked', ''); }
417 public function createElementInputFile($name, $id, $accept) {
418 $fileinput = $this->createElement('input');
419 $fileinput->setAttribute('type', 'file');
420 $fileinput->setAttribute('name', $name);
421 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
422 $fileinput->setAttribute('accept', $accept);
426 public function createElementInputSubmit($value) {
427 $submitbtn = $this->createElement('input');
428 $submitbtn->setAttribute('type', 'submit');
429 $submitbtn->setAttribute('value', $value);
433 public function createElementButton($value, $onclick = null) {
434 $btn = $this->createElement('input');
435 $btn->setAttribute('type', 'button');
436 $btn->setAttribute('value', $value);
437 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
441 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
442 $txtarea = $this->createElement('textarea', $value);
443 $txtarea->setAttribute('name', $name);
444 $txtarea->setAttribute('cols', $columns);
445 $txtarea->setAttribute('rows', $rows);
446 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
450 public function createElementSelect($name, $id = null, $options = array(), $default = null) {
451 $select = $this->createElement('select');
452 $select->setAttribute('name', $name);
453 if (!is_null($id)) { $select->setAttribute('id', $id); }
454 foreach ($options as $key => $desc) {
455 $select->appendElementOption($key, $desc, ($key == $default));
460 public function createElementOption($key, $desc, $selected = false) {
461 $option = $this->createElement('option', $desc);
462 $option->setAttribute('value', $key);
463 if ($selected) { $option->setAttribute('selected', ''); }
467 public function createElementLabel($for_id, $value) {
468 $label = $this->createElement('label', $value);
469 $label->setAttribute('for', $for_id);
473 public function createElementJS($jsdata) {
474 $jselem = $this->createElement('script');
475 // Note: type can/should be left out for HTML5.
476 $jselem->setAttribute('type', 'text/javascript');
477 $jselem->appendChild($this->createCDATASection($jsdata));
481 public function createElementJSFile($jsURL) {
482 $jselem = $this->createElement('script');
483 // Note: type can/should be left out for HTML5.
484 $jselem->setAttribute('type', 'text/javascript');
485 $jselem->setAttribute('src', $jsURL);
490 class ExtendedElement extends DOMElement {
491 // ExtendedElement PHP class
492 // this extends the general PHP DOM Element class to simplify some usual constructs
494 // public function appendElement($name, [$value])
495 // appends a DOMDocument::createElement() as a child of this element (see there for params)
496 // returns the new child
498 // public function appendElementXML($name, $xmldata)
499 // appends a DOMDocument::createElement() with the given name as a child of this element,
500 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
501 // returns the new child
503 // public function appendLink($target, [$value])
504 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
505 // returns the new child
507 // public function appendImage($src, [$alt_text])
508 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
509 // returns the new child
511 // public function appendForm($action, $method, $name, [$id])
512 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
513 // returns the new child
515 // public function appendFormDiv($action, $method, $name, [$id])
516 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
517 // returns an HTML <div> that is a child of the new child
519 // public function appendInputHidden($name, $value)
520 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
521 // returns the new child
523 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
524 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
525 // returns the new child
527 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
528 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
529 // returns the new child
531 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
532 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
533 // returns the new child
535 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
536 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
537 // returns the new child
539 // public function appendInputRadio($name, $id, $value, $checked)
540 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
541 // returns the new child
543 // public function appendInputCheckbox($name, $id, $value, $checked)
544 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
545 // returns the new child
547 // public function appendInputFile($name, $id, $accept)
548 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
549 // returns the new child
551 // public function appendInputSubmit($value)
552 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
553 // returns the new child
555 // public function appendButton($value, $onclick = null)
556 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
557 // returns the new child
559 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
560 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
561 // returns the new child
563 // public function appendElementSelect($name, [$id], [$options], [$default])
564 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
565 // returns the new child
567 // public function appendElementOption($key, $desc, [$selected])
568 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
569 // returns the new child
571 // public function appendLabel($for_id, $value)
572 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
573 // returns the new child
575 // public function appendText($text)
576 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
577 // returns the new child
579 // public function appendEntity($name)
580 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
581 // returns the new child
583 // public function appendComment($comment_data)
584 // appends a DOMDocument::createComment() as a child of this element (see there for params)
585 // returns the new child
587 // public function appendHTMLMarkup($htmldata)
588 // appends a representation of the HTML data as children of this element
591 // public function appendXMLMarkup($xmldata)
592 // appends a representation of the XML data as children of this element
595 // public function appendJSElement($jsdata)
596 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
599 // public function appendJSFile($jsURL)
600 // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
601 // returns the new child
603 public function appendElement($name, $value = '') {
604 return $this->appendChild($this->ownerDocument->createElement($name, $value));
606 public function appendElementXML($name, $xmldata) {
607 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
608 $aelem->appendXMLMarkup($xmldata);
611 public function appendLink($target, $value = '') {
612 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
614 public function appendImage($src, $alt_text = '') {
615 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
617 public function appendForm($action, $method, $name, $id = null) {
618 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
620 public function appendFormDiv($action, $method, $name, $id = null) {
621 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
622 return $formelem->appendElement('div');
624 public function appendInputHidden($name, $value) {
625 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
627 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
628 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
630 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
631 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
633 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
634 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
636 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
637 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
639 public function appendInputRadio($name, $id, $value, $checked) {
640 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
642 public function appendInputCheckbox($name, $id, $value, $checked) {
643 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
645 public function appendInputFile($name, $id, $accept) {
646 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
648 public function appendInputSubmit($value) {
649 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
651 public function appendButton($value, $onclick = null) {
652 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
654 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
655 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
657 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
658 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
660 public function appendElementOption($key, $desc, $selected = false) {
661 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
663 public function appendLabel($for_id, $value) {
664 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
666 public function appendText($text) {
667 return $this->appendChild($this->ownerDocument->createTextNode($text));
669 public function appendEntity($name) {
670 return $this->appendChild($this->ownerDocument->createEntityReference($name));
672 public function appendComment($comment_data) {
673 return $this->appendChild($this->ownerDocument->createComment($comment_data));
675 public function appendHTMLMarkup($htmldata) {
676 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
678 public function appendXMLMarkup($xmldata) {
679 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
681 public function appendJSElement($jsdata) {
682 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
684 public function appendJSFile($jsdata) {
685 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
689 class ExtendedDocumentFragment extends DOMDocumentFragment {
690 // ExtendedDocumentFragment PHP class
691 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
693 // public function appendElement($name, [$value])
694 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
695 // returns the new child
697 // public function appendElementXML($name, $xmldata)
698 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
699 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
700 // returns the new child
702 // public function appendLink($target, [$value])
703 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
704 // returns the new child
706 // public function appendImage($src, [$alt_text])
707 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
708 // returns the new child
710 // public function appendForm($action, $method, $name, [$id])
711 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
712 // returns the new child
714 // public function appendFormDiv($action, $method, $name, [$id])
715 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
716 // returns an HTML <div> that is a child of the new child
718 // public function appendInputHidden($name, $value)
719 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
720 // returns the new child
722 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
723 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
724 // returns the new child
726 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
727 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
728 // returns the new child
730 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
731 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
732 // returns the new child
734 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
735 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
736 // returns the new child
738 // public function appendInputRadio($name, $id, $value, $checked)
739 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
740 // returns the new child
742 // public function appendInputCheckbox($name, $id, $value, $checked)
743 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
744 // returns the new child
746 // public function appendInputFile($name, $id, $accept)
747 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
748 // returns the new child
750 // public function appendInputSubmit($value)
751 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
752 // returns the new child
754 // public function appendButton($value, $onclick = null)
755 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
756 // returns the new child
758 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
759 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
760 // returns the new child
762 // public function appendElementSelect($name, [$id], [$options], [$default])
763 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
764 // returns the new child
766 // public function appendElementOption($key, $desc, [$selected])
767 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
768 // returns the new child
770 // public function appendLabel($for_id, $value)
771 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
772 // returns the new child
774 // public function appendText($text)
775 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
776 // returns the new child
778 // public function appendEntity($name)
779 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
780 // returns the new child
782 // public function appendComment($comment_data)
783 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
784 // returns the new child
786 // public function appendHTMLMarkup($htmldata)
787 // appends a representation of the HTML data as children of this fragment
790 // public function appendXMLMarkup($xmldata)
791 // appends a representation of the XML data as children of this fragment
794 // public function appendJSElement($jsdata)
795 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
798 // public function appendJSFile($jsURL)
799 // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
800 // returns the new child
802 public function appendElement($name, $value = '') {
803 return $this->appendChild($this->ownerDocument->createElement($name, $value));
805 public function appendElementXML($name, $xmldata) {
806 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
807 $aelem->appendXMLMarkup($xmldata);
810 public function appendLink($target, $value = '') {
811 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
813 public function appendImage($src, $alt_text = '') {
814 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
816 public function appendForm($action, $method, $name, $id = null) {
817 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
819 public function appendFormDiv($action, $method, $name, $id = null) {
820 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
821 return $formelem->appendElement('div');
823 public function appendInputHidden($name, $value) {
824 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
826 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
827 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
829 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
830 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
832 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
833 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
835 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
836 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
838 public function appendInputRadio($name, $id, $value, $checked) {
839 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
841 public function appendInputCheckbox($name, $id, $value, $checked) {
842 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
844 public function appendInputFile($name, $id, $accept) {
845 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
847 public function appendInputSubmit($value) {
848 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
850 public function appendButton($value, $onclick = null) {
851 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
853 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
854 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
856 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
857 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
859 public function appendElementOption($key, $desc, $selected = false) {
860 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
862 public function appendLabel($for_id, $value) {
863 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
865 public function appendText($text) {
866 return $this->appendChild($this->ownerDocument->createTextNode($text));
868 public function appendEntity($name) {
869 return $this->appendChild($this->ownerDocument->createEntityReference($name));
871 public function appendComment($comment_data) {
872 return $this->appendChild($this->ownerDocument->createComment($comment_data));
874 public function appendHTMLMarkup($htmldata) {
875 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
877 public function appendXMLMarkup($xmldata) {
878 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
880 public function appendJSElement($jsdata) {
881 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
883 public function appendJSFile($jsdata) {
884 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));