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], [$title])
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], [$strictmatch])
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 appendLinebreak()
105 // appends a <br> as a child of this document
106 // returns the new child
108 // public function appendEntity($name)
109 // appends a DOMDocument::createEntityReference() as a child of this document (see there for params)
110 // returns the new child
112 // public function appendComment($comment_data)
113 // appends a DOMDocument::createComment() as a child of this document (see there for params)
114 // returns the new child
116 // public function appendHTMLMarkup($htmldata, [$parentNode])
117 // appends a representation of the HTML data as children of the given parent node, by default this document
120 // public function appendXMLMarkup($xmldata, [$parentNode])
121 // appends a representation of the XML data as children of the given parent node, by default this document
124 // public function appendJSElement($jsdata)
125 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
128 // public function appendJSFile($jsURL, [$defer], [$async])
129 // appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
130 // returns the new child
132 // public function createElementLink($target, [$value], [$title])
133 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value as well as (optional) title attribute
135 // public function createElementImage($src, [$alt_text])
136 // returns an ExtendedElement that is an HTML <img> with the given src and alt attributes (set to '' by default)
138 // public function createElementForm($action, $method, $name)
139 // returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
140 // with the given action, method, and name
142 // public function createElementInputHidden($name, $value)
143 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
145 // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
146 // returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
147 // and optionally id and value
149 // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
150 // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
151 // and optionally id and value
153 // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
154 // returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
155 // and optionally id and value
157 // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
158 // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
159 // and optionally id and value
161 // public function createElementInputRadio($name, $id, $value, $checked)
162 // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
165 // public function createElementInputCheckbox($name, $id, $value, $checked)
166 // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
169 // public function createElementInputFile($name, $id, $accept)
170 // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
172 // public function createElementInputSubmit($value)
173 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
175 // public function createElementButton($value, $onclick = null)
176 // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
178 // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
179 // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
180 // and optionally id and value
182 // public function createElementSelect($name, [$id], [$options], [$default], [$strictmatch])
183 // returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
184 // array of options (key => description) and key of the by-default selected entry (matched including type when strictmatch is true)
186 // public function createElementOption($key, $desc, [$selected])
187 // returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
188 // and optionally bool that tells if the entry is selected
190 // public function createElementLabel($for_id, $value)
191 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
193 // public function createElementJS($jsdata)
194 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
196 // public function createElementJSFile($jsURL, [$defer], [$async])
197 // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
198 // $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.
200 function __construct($version = '1.0', $encoding = 'utf-8') {
201 // make sure the default DOMDocument constructor runs
202 parent::__construct($version, $encoding);
203 $this->registerNodeClass('DOMElement', 'ExtendedElement');
204 $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
207 static function initHTML5($doc = null) {
208 if (is_null($doc)) { $doc = new ExtendedDocument(); }
209 $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
211 // Created basic HTML document structure.
212 $root = $doc->getElementsByTagName('html')->item(0);
213 $head = $root->appendElement('head');
214 $title = $head->appendElement('title');
215 $body = $root->appendElement('body');
217 return array('document' => $doc,
224 public function appendElement($name, $value = '') {
225 return $this->appendChild($this->createElement($name, $value));
227 public function appendElementXML($name, $xmldata) {
228 $aelem = $this->appendChild($this->createElement($name));
229 $aelem->appendXMLMarkup($xmldata);
230 //$aelem->appendChild($this->createXMLFragment($xmldata));
233 public function appendLink($target, $value = '', $title = null) {
234 return $this->appendChild($this->createElementLink($target, $value, $title));
236 public function appendImage($src, $alt_text = '') {
237 return $this->appendChild($this->createElementImage($src, $alt_text));
239 public function appendForm($action, $method, $name, $id = null) {
240 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
242 public function appendFormDiv($action, $method, $name, $id = null) {
243 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
244 return $formelem->appendElement('div');
246 public function appendInputHidden($name, $value) {
247 return $this->appendChild($this->createElementInputHidden($name, $value));
249 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
250 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
252 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
253 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
255 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
256 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
258 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
259 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
261 public function appendInputRadio($name, $id, $value, $checked) {
262 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
264 public function appendInputCheckbox($name, $id, $value, $checked) {
265 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
267 public function appendInputFile($name, $id, $accept) {
268 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
270 public function appendInputSubmit($value) {
271 return $this->appendChild($this->createElementInputSubmit($value));
273 public function appendButton($value, $onclick = null) {
274 return $this->appendChild($this->createElementButton($value, $onclick));
276 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
277 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
279 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
280 return $this->appendChild($this->createElementSelect($name, $id, $options, $default, $strictmatch));
282 public function appendElementOption($key, $desc, $selected = false) {
283 return $this->appendChild($this->createElementOption($key, $desc, $selected));
285 public function appendLabel($for_id, $value) {
286 return $this->appendChild($this->createElementLabel($for_id, $value));
288 public function appendText($text) {
289 return $this->appendChild($this->createTextNode($text));
291 public function appendLinebreak() {
292 return $this->appendChild($this->createElement('br'));
294 public function appendEntity($name) {
295 return $this->appendChild($this->createEntityReference($name));
297 public function appendComment($comment_data) {
298 return $this->appendChild($this->createComment($comment_data));
300 public function appendJSElement($jsdata) {
301 $this->appendChild($this->createElementJS($jsdata));
303 public function appendJSFile($jsdata, $defer = false, $async = false) {
304 return $this->appendChild($this->createElementJSFile($jsdata, $defer, $async));
307 public function appendHTMLMarkup($htmldata, $parentNode = null) {
308 if (is_null($parentNode)) { $parentNode =& $this; }
309 // Use loadHTML() to parse and turn the markup into proper HTML.
310 $tmpdoc = new ExtendedDocument;
311 // The XML line is needed to tell the parser that we need UTF-8 parsing.
312 $tmpdoc->loadHTML('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html><body>'.$htmldata.'</body></html>');
313 foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) {
314 $parentNode->appendChild($this->importNode($child, true));
318 public function appendXMLMarkup($xmldata, $parentNode = null) {
319 if (is_null($parentNode)) { $parentNode =& $this; }
320 $tmpdoc = new ExtendedDocument;
321 $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
322 $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
323 $tmpxml .= '<root>'.$xmldata.'</root>';
324 $tmpdoc->loadXML($tmpxml);
325 foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
326 $parentNode->appendChild($this->importNode($child, true));
330 public function createElement($name, $value = '') {
331 // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
332 $aelem = parent::createElement($name);
333 if (strlen($value)) { $aelem->appendText($value); }
337 public function createElementLink($target, $value = '', $title = null) {
338 $link = $this->createElement('a', $value);
339 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
340 if (!is_null($title)) { $link->setAttribute('title', $title); }
344 public function createElementImage($src, $alt_text = '') {
345 $img = $this->createElement('img');
346 $img->setAttribute('src', $src);
347 $img->setAttribute('alt', $alt_text);
351 public function createElementForm($action, $method, $name, $id = null) {
352 $formelem = $this->createElement('form');
353 $formelem->setAttribute('action', $action);
354 $formelem->setAttribute('method', $method);
355 $formelem->setAttribute('name', $name);
356 if (!is_null($id)) { $formelem->setAttribute('id', $id); }
360 public function createElementInputHidden($name, $value) {
361 $hidden = $this->createElement('input');
362 $hidden->setAttribute('type', 'hidden');
363 $hidden->setAttribute('name', $name);
364 $hidden->setAttribute('value', $value);
368 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
369 $txfield = $this->createElement('input');
370 $txfield->setAttribute('type', 'text');
371 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
372 $txfield->setAttribute('name', $name);
373 $txfield->setAttribute('maxlength', $maxlength);
374 $txfield->setAttribute('size', $size);
375 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
379 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
380 $txfield = $this->createElement('input');
381 $txfield->setAttribute('type', 'number');
382 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
383 $txfield->setAttribute('name', $name);
384 $txfield->setAttribute('maxlength', $maxlength);
385 $txfield->setAttribute('size', $size);
386 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
390 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
391 $txfield = $this->createElement('input');
392 $txfield->setAttribute('type', 'email');
393 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
394 $txfield->setAttribute('name', $name);
395 $txfield->setAttribute('maxlength', $maxlength);
396 $txfield->setAttribute('size', $size);
397 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
401 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
402 $pwfield = $this->createElement('input');
403 $pwfield->setAttribute('type', 'password');
404 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
405 $pwfield->setAttribute('name', $name);
406 $pwfield->setAttribute('maxlength', $maxlength);
407 $pwfield->setAttribute('size', $size);
408 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
412 public function createElementInputRadio($name, $id, $value, $checked) {
413 $radio = $this->createElement('input');
414 $radio->setAttribute('type', 'radio');
415 $radio->setAttribute('name', $name);
416 if (!is_null($id)) { $radio->setAttribute('id', $id); }
417 $radio->setAttribute('value', $value);
418 if ($checked) { $radio->setAttribute('checked', ''); }
422 public function createElementInputCheckbox($name, $id, $value, $checked) {
423 $cbox = $this->createElement('input');
424 $cbox->setAttribute('type', 'checkbox');
425 $cbox->setAttribute('name', $name);
426 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
427 $cbox->setAttribute('value', $value);
428 if ($checked) { $cbox->setAttribute('checked', ''); }
432 public function createElementInputFile($name, $id, $accept) {
433 $fileinput = $this->createElement('input');
434 $fileinput->setAttribute('type', 'file');
435 $fileinput->setAttribute('name', $name);
436 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
437 $fileinput->setAttribute('accept', $accept);
441 public function createElementInputSubmit($value) {
442 $submitbtn = $this->createElement('input');
443 $submitbtn->setAttribute('type', 'submit');
444 $submitbtn->setAttribute('value', $value);
448 public function createElementButton($value, $onclick = null) {
449 $btn = $this->createElement('input');
450 $btn->setAttribute('type', 'button');
451 $btn->setAttribute('value', $value);
452 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
456 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
457 $txtarea = $this->createElement('textarea', $value);
458 $txtarea->setAttribute('name', $name);
459 $txtarea->setAttribute('cols', $columns);
460 $txtarea->setAttribute('rows', $rows);
461 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
465 public function createElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
466 $select = $this->createElement('select');
467 $select->setAttribute('name', $name);
468 if (!is_null($id)) { $select->setAttribute('id', $id); }
469 foreach ($options as $key => $desc) {
470 $select->appendElementOption($key, $desc, $strictmatch ? ($key === $default) : ($key == $default));
475 public function createElementOption($key, $desc, $selected = false) {
476 $option = $this->createElement('option', $desc);
477 $option->setAttribute('value', $key);
478 if ($selected) { $option->setAttribute('selected', ''); }
482 public function createElementLabel($for_id, $value) {
483 $label = $this->createElement('label', $value);
484 $label->setAttribute('for', $for_id);
488 public function createElementJS($jsdata) {
489 $jselem = $this->createElement('script');
490 // Note: type can/should be left out for HTML5.
491 $jselem->setAttribute('type', 'text/javascript');
492 $jselem->appendChild($this->createCDATASection($jsdata));
496 public function createElementJSFile($jsURL, $defer = false, $async = false) {
497 $jselem = $this->createElement('script');
498 // Note: type can/should be left out for HTML5.
499 $jselem->setAttribute('type', 'text/javascript');
501 $jselem->setAttribute('defer', '');
504 $jselem->setAttribute('async', '');
506 $jselem->setAttribute('src', $jsURL);
511 class ExtendedElement extends DOMElement {
512 // ExtendedElement PHP class
513 // this extends the general PHP DOM Element class to simplify some usual constructs
515 // public function appendElement($name, [$value])
516 // appends a DOMDocument::createElement() as a child of this element (see there for params)
517 // returns the new child
519 // public function appendElementXML($name, $xmldata)
520 // appends a DOMDocument::createElement() with the given name as a child of this element,
521 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
522 // returns the new child
524 // public function appendLink($target, [$value], [$title])
525 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
526 // returns the new child
528 // public function appendImage($src, [$alt_text])
529 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
530 // returns the new child
532 // public function appendForm($action, $method, $name, [$id])
533 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
534 // returns the new child
536 // public function appendFormDiv($action, $method, $name, [$id])
537 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
538 // returns an HTML <div> that is a child of the new child
540 // public function appendInputHidden($name, $value)
541 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
542 // returns the new child
544 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
545 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
546 // returns the new child
548 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
549 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
550 // returns the new child
552 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
553 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
554 // returns the new child
556 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
557 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
558 // returns the new child
560 // public function appendInputRadio($name, $id, $value, $checked)
561 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
562 // returns the new child
564 // public function appendInputCheckbox($name, $id, $value, $checked)
565 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
566 // returns the new child
568 // public function appendInputFile($name, $id, $accept)
569 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
570 // returns the new child
572 // public function appendInputSubmit($value)
573 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
574 // returns the new child
576 // public function appendButton($value, $onclick = null)
577 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
578 // returns the new child
580 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
581 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
582 // returns the new child
584 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
585 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
586 // returns the new child
588 // public function appendElementOption($key, $desc, [$selected])
589 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
590 // returns the new child
592 // public function appendLabel($for_id, $value)
593 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
594 // returns the new child
596 // public function appendText($text)
597 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
598 // returns the new child
600 // public function appendLinebreak()
601 // appends a <br> as a child of this element
602 // returns the new child
604 // public function appendEntity($name)
605 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
606 // returns the new child
608 // public function appendComment($comment_data)
609 // appends a DOMDocument::createComment() as a child of this element (see there for params)
610 // returns the new child
612 // public function appendHTMLMarkup($htmldata)
613 // appends a representation of the HTML data as children of this element
616 // public function appendXMLMarkup($xmldata)
617 // appends a representation of the XML data as children of this element
620 // public function appendJSElement($jsdata)
621 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
624 // public function appendJSFile($jsURL, [$defer], [$async])
625 // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
626 // returns the new child
628 // public function setClass($classname)
629 // sets the 'class' attribute of the element to the given classname value
631 // public function addClass($classname)
632 // adds the given classname value to the space-separated list in the 'class' attribute
633 // returns the value of the 'class' attribute
635 // public function setID($elem_id)
636 // sets the 'id' attribute of the element to the given elem_id value
638 public function appendElement($name, $value = '') {
639 return $this->appendChild($this->ownerDocument->createElement($name, $value));
641 public function appendElementXML($name, $xmldata) {
642 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
643 $aelem->appendXMLMarkup($xmldata);
646 public function appendLink($target, $value = '', $title = null) {
647 return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title));
649 public function appendImage($src, $alt_text = '') {
650 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
652 public function appendForm($action, $method, $name, $id = null) {
653 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
655 public function appendFormDiv($action, $method, $name, $id = null) {
656 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
657 return $formelem->appendElement('div');
659 public function appendInputHidden($name, $value) {
660 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
662 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
663 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
665 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
666 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
668 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
669 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
671 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
672 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
674 public function appendInputRadio($name, $id, $value, $checked) {
675 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
677 public function appendInputCheckbox($name, $id, $value, $checked) {
678 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
680 public function appendInputFile($name, $id, $accept) {
681 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
683 public function appendInputSubmit($value) {
684 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
686 public function appendButton($value, $onclick = null) {
687 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
689 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
690 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
692 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
693 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
695 public function appendElementOption($key, $desc, $selected = false) {
696 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
698 public function appendLabel($for_id, $value) {
699 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
701 public function appendText($text) {
702 return $this->appendChild($this->ownerDocument->createTextNode($text));
704 public function appendLinebreak() {
705 return $this->appendChild($this->ownerDocument->createElement('br'));
707 public function appendEntity($name) {
708 return $this->appendChild($this->ownerDocument->createEntityReference($name));
710 public function appendComment($comment_data) {
711 return $this->appendChild($this->ownerDocument->createComment($comment_data));
713 public function appendHTMLMarkup($htmldata) {
714 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
716 public function appendXMLMarkup($xmldata) {
717 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
719 public function appendJSElement($jsdata) {
720 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
722 public function appendJSFile($jsdata, $defer = false, $async = false) {
723 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));
725 public function setClass($classname) {
726 $this->setAttribute('class', $classname);
728 public function addClass($classname) {
729 $classval = $this->getAttribute('class');
730 if (strlen($classval)) { $classval .= ' '; }
731 $classval .= $classname;
732 $this->setClass($classval);
735 public function setID($elem_id) {
736 $this->setAttribute('id', $elem_id);
740 class ExtendedDocumentFragment extends DOMDocumentFragment {
741 // ExtendedDocumentFragment PHP class
742 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
744 // public function appendElement($name, [$value])
745 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
746 // returns the new child
748 // public function appendElementXML($name, $xmldata)
749 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
750 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
751 // returns the new child
753 // public function appendLink($target, [$value], [$title])
754 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
755 // returns the new child
757 // public function appendImage($src, [$alt_text])
758 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
759 // returns the new child
761 // public function appendForm($action, $method, $name, [$id])
762 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
763 // returns the new child
765 // public function appendFormDiv($action, $method, $name, [$id])
766 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
767 // returns an HTML <div> that is a child of the new child
769 // public function appendInputHidden($name, $value)
770 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
771 // returns the new child
773 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
774 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
775 // returns the new child
777 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
778 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
779 // returns the new child
781 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
782 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
783 // returns the new child
785 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
786 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
787 // returns the new child
789 // public function appendInputRadio($name, $id, $value, $checked)
790 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
791 // returns the new child
793 // public function appendInputCheckbox($name, $id, $value, $checked)
794 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
795 // returns the new child
797 // public function appendInputFile($name, $id, $accept)
798 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
799 // returns the new child
801 // public function appendInputSubmit($value)
802 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
803 // returns the new child
805 // public function appendButton($value, $onclick = null)
806 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
807 // returns the new child
809 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
810 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
811 // returns the new child
813 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
814 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
815 // returns the new child
817 // public function appendElementOption($key, $desc, [$selected])
818 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
819 // returns the new child
821 // public function appendLabel($for_id, $value)
822 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
823 // returns the new child
825 // public function appendText($text)
826 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
827 // returns the new child
829 // public function appendLinebreak()
830 // appends a <br> as a child of this fragment
831 // returns the new child
833 // public function appendEntity($name)
834 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
835 // returns the new child
837 // public function appendComment($comment_data)
838 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
839 // returns the new child
841 // public function appendHTMLMarkup($htmldata)
842 // appends a representation of the HTML data as children of this fragment
845 // public function appendXMLMarkup($xmldata)
846 // appends a representation of the XML data as children of this fragment
849 // public function appendJSElement($jsdata)
850 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
853 // public function appendJSFile($jsURL, [$defer], [$async])
854 // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
855 // returns the new child
857 public function appendElement($name, $value = '') {
858 return $this->appendChild($this->ownerDocument->createElement($name, $value));
860 public function appendElementXML($name, $xmldata) {
861 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
862 $aelem->appendXMLMarkup($xmldata);
865 public function appendLink($target, $value = '', $title = null) {
866 return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title));
868 public function appendImage($src, $alt_text = '') {
869 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
871 public function appendForm($action, $method, $name, $id = null) {
872 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
874 public function appendFormDiv($action, $method, $name, $id = null) {
875 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
876 return $formelem->appendElement('div');
878 public function appendInputHidden($name, $value) {
879 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
881 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
882 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
884 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
885 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
887 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
888 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
890 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
891 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
893 public function appendInputRadio($name, $id, $value, $checked) {
894 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
896 public function appendInputCheckbox($name, $id, $value, $checked) {
897 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
899 public function appendInputFile($name, $id, $accept) {
900 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
902 public function appendInputSubmit($value) {
903 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
905 public function appendButton($value, $onclick = null) {
906 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
908 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
909 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
911 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
912 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
914 public function appendElementOption($key, $desc, $selected = false) {
915 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
917 public function appendLabel($for_id, $value) {
918 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
920 public function appendText($text) {
921 return $this->appendChild($this->ownerDocument->createTextNode($text));
923 public function appendLinebreak() {
924 return $this->appendChild($this->ownerDocument->createElement('br'));
926 public function appendEntity($name) {
927 return $this->appendChild($this->ownerDocument->createEntityReference($name));
929 public function appendComment($comment_data) {
930 return $this->appendChild($this->ownerDocument->createComment($comment_data));
932 public function appendHTMLMarkup($htmldata) {
933 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
935 public function appendXMLMarkup($xmldata) {
936 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
938 public function appendJSElement($jsdata) {
939 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
941 public function appendJSFile($jsdata, $defer = false, $async = false) {
942 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));