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, [$defer], [$async])
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, [$defer], [$async])
193 // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
194 // $defer and $async are boolean attributes that set if the script should be executed after parsing but before onload, and if it should be loaded asynchronously.
196 function __construct($version = '1.0', $encoding = 'utf-8') {
197 // make sure the default DOMDocument constructor runs
198 parent::__construct($version, $encoding);
199 $this->registerNodeClass('DOMElement', 'ExtendedElement');
200 $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
203 static function initHTML5($doc = null) {
204 if (is_null($doc)) { $doc = new ExtendedDocument(); }
205 $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
207 // Created basic HTML document structure.
208 $root = $doc->getElementsByTagName('html')->item(0);
209 $head = $root->appendElement('head');
210 $title = $head->appendElement('title');
211 $body = $root->appendElement('body');
213 return array('document' => $doc,
220 public function appendElement($name, $value = '') {
221 return $this->appendChild($this->createElement($name, $value));
223 public function appendElementXML($name, $xmldata) {
224 $aelem = $this->appendChild($this->createElement($name));
225 $aelem->appendXMLMarkup($xmldata);
226 //$aelem->appendChild($this->createXMLFragment($xmldata));
229 public function appendLink($target, $value = '') {
230 return $this->appendChild($this->createElementLink($target, $value));
232 public function appendImage($src, $alt_text = '') {
233 return $this->appendChild($this->createElementImage($src, $alt_text));
235 public function appendForm($action, $method, $name, $id = null) {
236 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
238 public function appendFormDiv($action, $method, $name, $id = null) {
239 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
240 return $formelem->appendElement('div');
242 public function appendInputHidden($name, $value) {
243 return $this->appendChild($this->createElementInputHidden($name, $value));
245 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
246 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
248 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
249 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
251 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
252 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
254 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
255 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
257 public function appendInputRadio($name, $id, $value, $checked) {
258 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
260 public function appendInputCheckbox($name, $id, $value, $checked) {
261 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
263 public function appendInputFile($name, $id, $accept) {
264 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
266 public function appendInputSubmit($value) {
267 return $this->appendChild($this->createElementInputSubmit($value));
269 public function appendButton($value, $onclick = null) {
270 return $this->appendChild($this->createElementButton($value, $onclick));
272 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
273 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
275 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
276 return $this->appendChild($this->createElementSelect($name, $id, $options, $default));
278 public function appendElementOption($key, $desc, $selected = false) {
279 return $this->appendChild($this->createElementOption($key, $desc, $selected));
281 public function appendLabel($for_id, $value) {
282 return $this->appendChild($this->createElementLabel($for_id, $value));
284 public function appendText($text) {
285 return $this->appendChild($this->createTextNode($text));
287 public function appendEntity($name) {
288 return $this->appendChild($this->createEntityReference($name));
290 public function appendComment($comment_data) {
291 return $this->appendChild($this->createComment($comment_data));
293 public function appendJSElement($jsdata) {
294 $this->appendChild($this->createElementJS($jsdata));
296 public function appendJSFile($jsdata, $defer = false, $async = false) {
297 return $this->appendChild($this->createElementJSFile($jsdata, $defer, $async));
300 public function appendHTMLMarkup($htmldata, $parentNode = null) {
301 if (is_null($parentNode)) { $parentNode =& $this; }
302 // XXX: just a workaround for now!
303 $parentNode->appendChild($this->createCDATASection($htmldata));
306 public function appendXMLMarkup($xmldata, $parentNode = null) {
307 if (is_null($parentNode)) { $parentNode =& $this; }
308 $tmpdoc = new ExtendedDocument;
309 $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
310 $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
311 $tmpxml .= '<root>'.$xmldata.'</root>';
312 $tmpdoc->loadXML($tmpxml);
313 foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
314 $parentNode->appendChild($this->importNode($child, true));
318 public function createElement($name, $value = '') {
319 // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
320 $aelem = parent::createElement($name);
321 $aelem->appendText($value);
325 public function createElementLink($target, $value = '') {
326 $link = $this->createElement('a', $value);
327 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
331 public function createElementImage($src, $alt_text = '') {
332 $img = $this->createElement('img');
333 $img->setAttribute('src', $src);
334 $img->setAttribute('alt', $alt_text);
338 public function createElementForm($action, $method, $name, $id = null) {
339 $formelem = $this->createElement('form');
340 $formelem->setAttribute('action', $action);
341 $formelem->setAttribute('method', $method);
342 $formelem->setAttribute('name', $name);
343 $formelem->setAttribute('id', $id);
347 public function createElementInputHidden($name, $value) {
348 $hidden = $this->createElement('input');
349 $hidden->setAttribute('type', 'hidden');
350 $hidden->setAttribute('name', $name);
351 $hidden->setAttribute('value', $value);
355 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
356 $txfield = $this->createElement('input');
357 $txfield->setAttribute('type', 'text');
358 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
359 $txfield->setAttribute('name', $name);
360 $txfield->setAttribute('maxlength', $maxlength);
361 $txfield->setAttribute('size', $size);
362 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
366 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
367 $txfield = $this->createElement('input');
368 $txfield->setAttribute('type', 'number');
369 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
370 $txfield->setAttribute('name', $name);
371 $txfield->setAttribute('maxlength', $maxlength);
372 $txfield->setAttribute('size', $size);
373 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
377 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
378 $txfield = $this->createElement('input');
379 $txfield->setAttribute('type', 'email');
380 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
381 $txfield->setAttribute('name', $name);
382 $txfield->setAttribute('maxlength', $maxlength);
383 $txfield->setAttribute('size', $size);
384 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
388 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
389 $pwfield = $this->createElement('input');
390 $pwfield->setAttribute('type', 'password');
391 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
392 $pwfield->setAttribute('name', $name);
393 $pwfield->setAttribute('maxlength', $maxlength);
394 $pwfield->setAttribute('size', $size);
395 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
399 public function createElementInputRadio($name, $id, $value, $checked) {
400 $radio = $this->createElement('input');
401 $radio->setAttribute('type', 'radio');
402 $radio->setAttribute('name', $name);
403 if (!is_null($id)) { $radio->setAttribute('id', $id); }
404 $radio->setAttribute('value', $value);
405 if ($checked) { $radio->setAttribute('checked', ''); }
409 public function createElementInputCheckbox($name, $id, $value, $checked) {
410 $cbox = $this->createElement('input');
411 $cbox->setAttribute('type', 'checkbox');
412 $cbox->setAttribute('name', $name);
413 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
414 $cbox->setAttribute('value', $value);
415 if ($checked) { $cbox->setAttribute('checked', ''); }
419 public function createElementInputFile($name, $id, $accept) {
420 $fileinput = $this->createElement('input');
421 $fileinput->setAttribute('type', 'file');
422 $fileinput->setAttribute('name', $name);
423 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
424 $fileinput->setAttribute('accept', $accept);
428 public function createElementInputSubmit($value) {
429 $submitbtn = $this->createElement('input');
430 $submitbtn->setAttribute('type', 'submit');
431 $submitbtn->setAttribute('value', $value);
435 public function createElementButton($value, $onclick = null) {
436 $btn = $this->createElement('input');
437 $btn->setAttribute('type', 'button');
438 $btn->setAttribute('value', $value);
439 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
443 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
444 $txtarea = $this->createElement('textarea', $value);
445 $txtarea->setAttribute('name', $name);
446 $txtarea->setAttribute('cols', $columns);
447 $txtarea->setAttribute('rows', $rows);
448 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
452 public function createElementSelect($name, $id = null, $options = array(), $default = null) {
453 $select = $this->createElement('select');
454 $select->setAttribute('name', $name);
455 if (!is_null($id)) { $select->setAttribute('id', $id); }
456 foreach ($options as $key => $desc) {
457 $select->appendElementOption($key, $desc, ($key == $default));
462 public function createElementOption($key, $desc, $selected = false) {
463 $option = $this->createElement('option', $desc);
464 $option->setAttribute('value', $key);
465 if ($selected) { $option->setAttribute('selected', ''); }
469 public function createElementLabel($for_id, $value) {
470 $label = $this->createElement('label', $value);
471 $label->setAttribute('for', $for_id);
475 public function createElementJS($jsdata) {
476 $jselem = $this->createElement('script');
477 // Note: type can/should be left out for HTML5.
478 $jselem->setAttribute('type', 'text/javascript');
479 $jselem->appendChild($this->createCDATASection($jsdata));
483 public function createElementJSFile($jsURL, $defer = false, $async = false) {
484 $jselem = $this->createElement('script');
485 // Note: type can/should be left out for HTML5.
486 $jselem->setAttribute('type', 'text/javascript');
488 $jselem->setAttribute('defer', '');
491 $jselem->setAttribute('async', '');
493 $jselem->setAttribute('src', $jsURL);
498 class ExtendedElement extends DOMElement {
499 // ExtendedElement PHP class
500 // this extends the general PHP DOM Element class to simplify some usual constructs
502 // public function appendElement($name, [$value])
503 // appends a DOMDocument::createElement() as a child of this element (see there for params)
504 // returns the new child
506 // public function appendElementXML($name, $xmldata)
507 // appends a DOMDocument::createElement() with the given name as a child of this element,
508 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
509 // returns the new child
511 // public function appendLink($target, [$value])
512 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
513 // returns the new child
515 // public function appendImage($src, [$alt_text])
516 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
517 // returns the new child
519 // public function appendForm($action, $method, $name, [$id])
520 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
521 // returns the new child
523 // public function appendFormDiv($action, $method, $name, [$id])
524 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
525 // returns an HTML <div> that is a child of the new child
527 // public function appendInputHidden($name, $value)
528 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
529 // returns the new child
531 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
532 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
533 // returns the new child
535 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
536 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
537 // returns the new child
539 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
540 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
541 // returns the new child
543 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
544 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
545 // returns the new child
547 // public function appendInputRadio($name, $id, $value, $checked)
548 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
549 // returns the new child
551 // public function appendInputCheckbox($name, $id, $value, $checked)
552 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
553 // returns the new child
555 // public function appendInputFile($name, $id, $accept)
556 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
557 // returns the new child
559 // public function appendInputSubmit($value)
560 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
561 // returns the new child
563 // public function appendButton($value, $onclick = null)
564 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
565 // returns the new child
567 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
568 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
569 // returns the new child
571 // public function appendElementSelect($name, [$id], [$options], [$default])
572 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
573 // returns the new child
575 // public function appendElementOption($key, $desc, [$selected])
576 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
577 // returns the new child
579 // public function appendLabel($for_id, $value)
580 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
581 // returns the new child
583 // public function appendText($text)
584 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
585 // returns the new child
587 // public function appendEntity($name)
588 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
589 // returns the new child
591 // public function appendComment($comment_data)
592 // appends a DOMDocument::createComment() as a child of this element (see there for params)
593 // returns the new child
595 // public function appendHTMLMarkup($htmldata)
596 // appends a representation of the HTML data as children of this element
599 // public function appendXMLMarkup($xmldata)
600 // appends a representation of the XML data as children of this element
603 // public function appendJSElement($jsdata)
604 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
607 // public function appendJSFile($jsURL, [$defer], [$async])
608 // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
609 // returns the new child
611 public function appendElement($name, $value = '') {
612 return $this->appendChild($this->ownerDocument->createElement($name, $value));
614 public function appendElementXML($name, $xmldata) {
615 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
616 $aelem->appendXMLMarkup($xmldata);
619 public function appendLink($target, $value = '') {
620 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
622 public function appendImage($src, $alt_text = '') {
623 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
625 public function appendForm($action, $method, $name, $id = null) {
626 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
628 public function appendFormDiv($action, $method, $name, $id = null) {
629 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
630 return $formelem->appendElement('div');
632 public function appendInputHidden($name, $value) {
633 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
635 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
636 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
638 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
639 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
641 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
642 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
644 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
645 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
647 public function appendInputRadio($name, $id, $value, $checked) {
648 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
650 public function appendInputCheckbox($name, $id, $value, $checked) {
651 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
653 public function appendInputFile($name, $id, $accept) {
654 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
656 public function appendInputSubmit($value) {
657 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
659 public function appendButton($value, $onclick = null) {
660 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
662 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
663 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
665 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
666 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
668 public function appendElementOption($key, $desc, $selected = false) {
669 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
671 public function appendLabel($for_id, $value) {
672 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
674 public function appendText($text) {
675 return $this->appendChild($this->ownerDocument->createTextNode($text));
677 public function appendEntity($name) {
678 return $this->appendChild($this->ownerDocument->createEntityReference($name));
680 public function appendComment($comment_data) {
681 return $this->appendChild($this->ownerDocument->createComment($comment_data));
683 public function appendHTMLMarkup($htmldata) {
684 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
686 public function appendXMLMarkup($xmldata) {
687 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
689 public function appendJSElement($jsdata) {
690 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
692 public function appendJSFile($jsdata, $defer = false, $async = false) {
693 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));
697 class ExtendedDocumentFragment extends DOMDocumentFragment {
698 // ExtendedDocumentFragment PHP class
699 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
701 // public function appendElement($name, [$value])
702 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
703 // returns the new child
705 // public function appendElementXML($name, $xmldata)
706 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
707 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
708 // returns the new child
710 // public function appendLink($target, [$value])
711 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
712 // returns the new child
714 // public function appendImage($src, [$alt_text])
715 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
716 // returns the new child
718 // public function appendForm($action, $method, $name, [$id])
719 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
720 // returns the new child
722 // public function appendFormDiv($action, $method, $name, [$id])
723 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
724 // returns an HTML <div> that is a child of the new child
726 // public function appendInputHidden($name, $value)
727 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
728 // returns the new child
730 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
731 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
732 // returns the new child
734 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
735 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
736 // returns the new child
738 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
739 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
740 // returns the new child
742 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
743 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
744 // returns the new child
746 // public function appendInputRadio($name, $id, $value, $checked)
747 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
748 // returns the new child
750 // public function appendInputCheckbox($name, $id, $value, $checked)
751 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
752 // returns the new child
754 // public function appendInputFile($name, $id, $accept)
755 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
756 // returns the new child
758 // public function appendInputSubmit($value)
759 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
760 // returns the new child
762 // public function appendButton($value, $onclick = null)
763 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
764 // returns the new child
766 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
767 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
768 // returns the new child
770 // public function appendElementSelect($name, [$id], [$options], [$default])
771 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
772 // returns the new child
774 // public function appendElementOption($key, $desc, [$selected])
775 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
776 // returns the new child
778 // public function appendLabel($for_id, $value)
779 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
780 // returns the new child
782 // public function appendText($text)
783 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
784 // returns the new child
786 // public function appendEntity($name)
787 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
788 // returns the new child
790 // public function appendComment($comment_data)
791 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
792 // returns the new child
794 // public function appendHTMLMarkup($htmldata)
795 // appends a representation of the HTML data as children of this fragment
798 // public function appendXMLMarkup($xmldata)
799 // appends a representation of the XML data as children of this fragment
802 // public function appendJSElement($jsdata)
803 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
806 // public function appendJSFile($jsURL, [$defer], [$async])
807 // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
808 // returns the new child
810 public function appendElement($name, $value = '') {
811 return $this->appendChild($this->ownerDocument->createElement($name, $value));
813 public function appendElementXML($name, $xmldata) {
814 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
815 $aelem->appendXMLMarkup($xmldata);
818 public function appendLink($target, $value = '') {
819 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
821 public function appendImage($src, $alt_text = '') {
822 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
824 public function appendForm($action, $method, $name, $id = null) {
825 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
827 public function appendFormDiv($action, $method, $name, $id = null) {
828 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
829 return $formelem->appendElement('div');
831 public function appendInputHidden($name, $value) {
832 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
834 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
835 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
837 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
838 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
840 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
841 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
843 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
844 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
846 public function appendInputRadio($name, $id, $value, $checked) {
847 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
849 public function appendInputCheckbox($name, $id, $value, $checked) {
850 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
852 public function appendInputFile($name, $id, $accept) {
853 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
855 public function appendInputSubmit($value) {
856 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
858 public function appendButton($value, $onclick = null) {
859 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
861 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
862 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
864 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
865 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
867 public function appendElementOption($key, $desc, $selected = false) {
868 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
870 public function appendLabel($for_id, $value) {
871 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
873 public function appendText($text) {
874 return $this->appendChild($this->ownerDocument->createTextNode($text));
876 public function appendEntity($name) {
877 return $this->appendChild($this->ownerDocument->createEntityReference($name));
879 public function appendComment($comment_data) {
880 return $this->appendChild($this->ownerDocument->createComment($comment_data));
882 public function appendHTMLMarkup($htmldata) {
883 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
885 public function appendXMLMarkup($xmldata) {
886 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
888 public function appendJSElement($jsdata) {
889 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
891 public function appendJSFile($jsdata, $defer = false, $async = false) {
892 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));