add a workaround for when imap module is missing
[php-utility-classes.git] / classes / document.php-class
... / ...
CommitLineData
1<?php
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/. */
5
6class ExtendedDocument extends DOMDocument {
7 // ExtendedDocument PHP class
8 // this extends the general PHP DOM Document class to simplify some usual constructs
9 //
10 // function __construct([$version], [$encoding])
11 // CONSTRUCTOR
12 // construct a new DOM Document that uses our element definitions
13 //
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'
18 //
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
22 //
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
27 //
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
31 //
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
35 //
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
39 //
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
43 //
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
47 //
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
51 //
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
55 //
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
59 //
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
63 //
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
67 //
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
71 //
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
75 //
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
79 //
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
83 //
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
87 //
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
91 //
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
95 //
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
99 //
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
103 //
104 // public function appendLinebreak()
105 // appends a <br> as a child of this document
106 // returns the new child
107 //
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
111 //
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
115 //
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
118 // NO return value!
119 //
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
122 // NO return value!
123 //
124 // public function appendJSElement($jsdata)
125 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
126 // NO return value!
127 //
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
131 //
132 // public function createElementLink($target, [$value])
133 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
134 //
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)
137 //
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
141 //
142 // public function createElementInputHidden($name, $value)
143 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
144 //
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
148 //
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
152 //
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
156 //
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
160 //
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
163 // checked state
164 //
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
167 // checked state
168 //
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
171 //
172 // public function createElementInputSubmit($value)
173 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
174 //
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
177 //
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
181 //
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)
185 //
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
189 //
190 // public function createElementLabel($for_id, $value)
191 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
192 //
193 // public function createElementJS($jsdata)
194 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
195 //
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.
199
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');
205 }
206
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.
210
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');
216
217 return array('document' => $doc,
218 'html' => $root,
219 'head' => $head,
220 'title' => $title,
221 'body' => $body);
222 }
223
224 public function appendElement($name, $value = '') {
225 return $this->appendChild($this->createElement($name, $value));
226 }
227 public function appendElementXML($name, $xmldata) {
228 $aelem = $this->appendChild($this->createElement($name));
229 $aelem->appendXMLMarkup($xmldata);
230 //$aelem->appendChild($this->createXMLFragment($xmldata));
231 return $aelem;
232 }
233 public function appendLink($target, $value = '') {
234 return $this->appendChild($this->createElementLink($target, $value));
235 }
236 public function appendImage($src, $alt_text = '') {
237 return $this->appendChild($this->createElementImage($src, $alt_text));
238 }
239 public function appendForm($action, $method, $name, $id = null) {
240 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
241 }
242 public function appendFormDiv($action, $method, $name, $id = null) {
243 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
244 return $formelem->appendElement('div');
245 }
246 public function appendInputHidden($name, $value) {
247 return $this->appendChild($this->createElementInputHidden($name, $value));
248 }
249 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
250 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
251 }
252 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
253 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
254 }
255 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
256 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
257 }
258 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
259 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
260 }
261 public function appendInputRadio($name, $id, $value, $checked) {
262 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
263 }
264 public function appendInputCheckbox($name, $id, $value, $checked) {
265 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
266 }
267 public function appendInputFile($name, $id, $accept) {
268 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
269 }
270 public function appendInputSubmit($value) {
271 return $this->appendChild($this->createElementInputSubmit($value));
272 }
273 public function appendButton($value, $onclick = null) {
274 return $this->appendChild($this->createElementButton($value, $onclick));
275 }
276 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
277 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
278 }
279 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
280 return $this->appendChild($this->createElementSelect($name, $id, $options, $default, $strictmatch));
281 }
282 public function appendElementOption($key, $desc, $selected = false) {
283 return $this->appendChild($this->createElementOption($key, $desc, $selected));
284 }
285 public function appendLabel($for_id, $value) {
286 return $this->appendChild($this->createElementLabel($for_id, $value));
287 }
288 public function appendText($text) {
289 return $this->appendChild($this->createTextNode($text));
290 }
291 public function appendLinebreak() {
292 return $this->appendChild($this->createElement('br'));
293 }
294 public function appendEntity($name) {
295 return $this->appendChild($this->createEntityReference($name));
296 }
297 public function appendComment($comment_data) {
298 return $this->appendChild($this->createComment($comment_data));
299 }
300 public function appendJSElement($jsdata) {
301 $this->appendChild($this->createElementJS($jsdata));
302 }
303 public function appendJSFile($jsdata, $defer = false, $async = false) {
304 return $this->appendChild($this->createElementJSFile($jsdata, $defer, $async));
305 }
306
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));
315 }
316 }
317
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));
327 }
328 }
329
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 $aelem->appendText($value);
334 return $aelem;
335 }
336
337 public function createElementLink($target, $value = '') {
338 $link = $this->createElement('a', $value);
339 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
340 return $link;
341 }
342
343 public function createElementImage($src, $alt_text = '') {
344 $img = $this->createElement('img');
345 $img->setAttribute('src', $src);
346 $img->setAttribute('alt', $alt_text);
347 return $img;
348 }
349
350 public function createElementForm($action, $method, $name, $id = null) {
351 $formelem = $this->createElement('form');
352 $formelem->setAttribute('action', $action);
353 $formelem->setAttribute('method', $method);
354 $formelem->setAttribute('name', $name);
355 $formelem->setAttribute('id', $id);
356 return $formelem;
357 }
358
359 public function createElementInputHidden($name, $value) {
360 $hidden = $this->createElement('input');
361 $hidden->setAttribute('type', 'hidden');
362 $hidden->setAttribute('name', $name);
363 $hidden->setAttribute('value', $value);
364 return $hidden;
365 }
366
367 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
368 $txfield = $this->createElement('input');
369 $txfield->setAttribute('type', 'text');
370 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
371 $txfield->setAttribute('name', $name);
372 $txfield->setAttribute('maxlength', $maxlength);
373 $txfield->setAttribute('size', $size);
374 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
375 return $txfield;
376 }
377
378 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
379 $txfield = $this->createElement('input');
380 $txfield->setAttribute('type', 'number');
381 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
382 $txfield->setAttribute('name', $name);
383 $txfield->setAttribute('maxlength', $maxlength);
384 $txfield->setAttribute('size', $size);
385 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
386 return $txfield;
387 }
388
389 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
390 $txfield = $this->createElement('input');
391 $txfield->setAttribute('type', 'email');
392 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
393 $txfield->setAttribute('name', $name);
394 $txfield->setAttribute('maxlength', $maxlength);
395 $txfield->setAttribute('size', $size);
396 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
397 return $txfield;
398 }
399
400 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
401 $pwfield = $this->createElement('input');
402 $pwfield->setAttribute('type', 'password');
403 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
404 $pwfield->setAttribute('name', $name);
405 $pwfield->setAttribute('maxlength', $maxlength);
406 $pwfield->setAttribute('size', $size);
407 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
408 return $pwfield;
409 }
410
411 public function createElementInputRadio($name, $id, $value, $checked) {
412 $radio = $this->createElement('input');
413 $radio->setAttribute('type', 'radio');
414 $radio->setAttribute('name', $name);
415 if (!is_null($id)) { $radio->setAttribute('id', $id); }
416 $radio->setAttribute('value', $value);
417 if ($checked) { $radio->setAttribute('checked', ''); }
418 return $radio;
419 }
420
421 public function createElementInputCheckbox($name, $id, $value, $checked) {
422 $cbox = $this->createElement('input');
423 $cbox->setAttribute('type', 'checkbox');
424 $cbox->setAttribute('name', $name);
425 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
426 $cbox->setAttribute('value', $value);
427 if ($checked) { $cbox->setAttribute('checked', ''); }
428 return $cbox;
429 }
430
431 public function createElementInputFile($name, $id, $accept) {
432 $fileinput = $this->createElement('input');
433 $fileinput->setAttribute('type', 'file');
434 $fileinput->setAttribute('name', $name);
435 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
436 $fileinput->setAttribute('accept', $accept);
437 return $fileinput;
438 }
439
440 public function createElementInputSubmit($value) {
441 $submitbtn = $this->createElement('input');
442 $submitbtn->setAttribute('type', 'submit');
443 $submitbtn->setAttribute('value', $value);
444 return $submitbtn;
445 }
446
447 public function createElementButton($value, $onclick = null) {
448 $btn = $this->createElement('input');
449 $btn->setAttribute('type', 'button');
450 $btn->setAttribute('value', $value);
451 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
452 return $btn;
453 }
454
455 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
456 $txtarea = $this->createElement('textarea', $value);
457 $txtarea->setAttribute('name', $name);
458 $txtarea->setAttribute('cols', $columns);
459 $txtarea->setAttribute('rows', $rows);
460 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
461 return $txtarea;
462 }
463
464 public function createElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
465 $select = $this->createElement('select');
466 $select->setAttribute('name', $name);
467 if (!is_null($id)) { $select->setAttribute('id', $id); }
468 foreach ($options as $key => $desc) {
469 $select->appendElementOption($key, $desc, $strictmatch ? ($key === $default) : ($key == $default));
470 }
471 return $select;
472 }
473
474 public function createElementOption($key, $desc, $selected = false) {
475 $option = $this->createElement('option', $desc);
476 $option->setAttribute('value', $key);
477 if ($selected) { $option->setAttribute('selected', ''); }
478 return $option;
479 }
480
481 public function createElementLabel($for_id, $value) {
482 $label = $this->createElement('label', $value);
483 $label->setAttribute('for', $for_id);
484 return $label;
485 }
486
487 public function createElementJS($jsdata) {
488 $jselem = $this->createElement('script');
489 // Note: type can/should be left out for HTML5.
490 $jselem->setAttribute('type', 'text/javascript');
491 $jselem->appendChild($this->createCDATASection($jsdata));
492 return $jselem;
493 }
494
495 public function createElementJSFile($jsURL, $defer = false, $async = false) {
496 $jselem = $this->createElement('script');
497 // Note: type can/should be left out for HTML5.
498 $jselem->setAttribute('type', 'text/javascript');
499 if ($defer) {
500 $jselem->setAttribute('defer', '');
501 }
502 if ($async) {
503 $jselem->setAttribute('async', '');
504 }
505 $jselem->setAttribute('src', $jsURL);
506 return $jselem;
507 }
508}
509
510class ExtendedElement extends DOMElement {
511 // ExtendedElement PHP class
512 // this extends the general PHP DOM Element class to simplify some usual constructs
513 //
514 // public function appendElement($name, [$value])
515 // appends a DOMDocument::createElement() as a child of this element (see there for params)
516 // returns the new child
517 //
518 // public function appendElementXML($name, $xmldata)
519 // appends a DOMDocument::createElement() with the given name as a child of this element,
520 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
521 // returns the new child
522 //
523 // public function appendLink($target, [$value])
524 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
525 // returns the new child
526 //
527 // public function appendImage($src, [$alt_text])
528 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
529 // returns the new child
530 //
531 // public function appendForm($action, $method, $name, [$id])
532 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
533 // returns the new child
534 //
535 // public function appendFormDiv($action, $method, $name, [$id])
536 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
537 // returns an HTML <div> that is a child of the new child
538 //
539 // public function appendInputHidden($name, $value)
540 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
541 // returns the new child
542 //
543 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
544 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
545 // returns the new child
546 //
547 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
548 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
549 // returns the new child
550 //
551 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
552 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
553 // returns the new child
554 //
555 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
556 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
557 // returns the new child
558 //
559 // public function appendInputRadio($name, $id, $value, $checked)
560 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
561 // returns the new child
562 //
563 // public function appendInputCheckbox($name, $id, $value, $checked)
564 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
565 // returns the new child
566 //
567 // public function appendInputFile($name, $id, $accept)
568 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
569 // returns the new child
570 //
571 // public function appendInputSubmit($value)
572 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
573 // returns the new child
574 //
575 // public function appendButton($value, $onclick = null)
576 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
577 // returns the new child
578 //
579 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
580 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
581 // returns the new child
582 //
583 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
584 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
585 // returns the new child
586 //
587 // public function appendElementOption($key, $desc, [$selected])
588 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
589 // returns the new child
590 //
591 // public function appendLabel($for_id, $value)
592 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
593 // returns the new child
594 //
595 // public function appendText($text)
596 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
597 // returns the new child
598 //
599 // public function appendLinebreak()
600 // appends a <br> as a child of this element
601 // returns the new child
602 //
603 // public function appendEntity($name)
604 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
605 // returns the new child
606 //
607 // public function appendComment($comment_data)
608 // appends a DOMDocument::createComment() as a child of this element (see there for params)
609 // returns the new child
610 //
611 // public function appendHTMLMarkup($htmldata)
612 // appends a representation of the HTML data as children of this element
613 // NO return value!
614 //
615 // public function appendXMLMarkup($xmldata)
616 // appends a representation of the XML data as children of this element
617 // NO return value!
618 //
619 // public function appendJSElement($jsdata)
620 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
621 // NO return value!
622 //
623 // public function appendJSFile($jsURL, [$defer], [$async])
624 // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
625 // returns the new child
626 //
627 // public function setClass($classname)
628 // sets the 'class' attribute of the element to the given classname value
629 //
630 // public function addClass($classname)
631 // adds the given classname value to the space-separated list in the 'class' attribute
632 // returns the value of the 'class' attribute
633 //
634 // public function setID($elem_id)
635 // sets the 'id' attribute of the element to the given elem_id value
636
637 public function appendElement($name, $value = '') {
638 return $this->appendChild($this->ownerDocument->createElement($name, $value));
639 }
640 public function appendElementXML($name, $xmldata) {
641 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
642 $aelem->appendXMLMarkup($xmldata);
643 return $aelem;
644 }
645 public function appendLink($target, $value = '') {
646 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
647 }
648 public function appendImage($src, $alt_text = '') {
649 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
650 }
651 public function appendForm($action, $method, $name, $id = null) {
652 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
653 }
654 public function appendFormDiv($action, $method, $name, $id = null) {
655 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
656 return $formelem->appendElement('div');
657 }
658 public function appendInputHidden($name, $value) {
659 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
660 }
661 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
662 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
663 }
664 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
665 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
666 }
667 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
668 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
669 }
670 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
671 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
672 }
673 public function appendInputRadio($name, $id, $value, $checked) {
674 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
675 }
676 public function appendInputCheckbox($name, $id, $value, $checked) {
677 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
678 }
679 public function appendInputFile($name, $id, $accept) {
680 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
681 }
682 public function appendInputSubmit($value) {
683 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
684 }
685 public function appendButton($value, $onclick = null) {
686 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
687 }
688 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
689 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
690 }
691 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
692 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
693 }
694 public function appendElementOption($key, $desc, $selected = false) {
695 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
696 }
697 public function appendLabel($for_id, $value) {
698 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
699 }
700 public function appendText($text) {
701 return $this->appendChild($this->ownerDocument->createTextNode($text));
702 }
703 public function appendLinebreak() {
704 return $this->appendChild($this->ownerDocument->createElement('br'));
705 }
706 public function appendEntity($name) {
707 return $this->appendChild($this->ownerDocument->createEntityReference($name));
708 }
709 public function appendComment($comment_data) {
710 return $this->appendChild($this->ownerDocument->createComment($comment_data));
711 }
712 public function appendHTMLMarkup($htmldata) {
713 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
714 }
715 public function appendXMLMarkup($xmldata) {
716 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
717 }
718 public function appendJSElement($jsdata) {
719 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
720 }
721 public function appendJSFile($jsdata, $defer = false, $async = false) {
722 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));
723 }
724 public function setClass($classname) {
725 $this->setAttribute('class', $classname);
726 }
727 public function addClass($classname) {
728 $classval = $this->getAttribute('class');
729 if (strlen($classval)) { $classval .= ' '; }
730 $classval .= $classname;
731 $this->setClass($classval);
732 return $classval;
733 }
734 public function setID($elem_id) {
735 $this->setAttribute('id', $elem_id);
736 }
737}
738
739class ExtendedDocumentFragment extends DOMDocumentFragment {
740 // ExtendedDocumentFragment PHP class
741 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
742 //
743 // public function appendElement($name, [$value])
744 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
745 // returns the new child
746 //
747 // public function appendElementXML($name, $xmldata)
748 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
749 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
750 // returns the new child
751 //
752 // public function appendLink($target, [$value])
753 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
754 // returns the new child
755 //
756 // public function appendImage($src, [$alt_text])
757 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
758 // returns the new child
759 //
760 // public function appendForm($action, $method, $name, [$id])
761 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
762 // returns the new child
763 //
764 // public function appendFormDiv($action, $method, $name, [$id])
765 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
766 // returns an HTML <div> that is a child of the new child
767 //
768 // public function appendInputHidden($name, $value)
769 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
770 // returns the new child
771 //
772 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
773 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
774 // returns the new child
775 //
776 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
777 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
778 // returns the new child
779 //
780 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
781 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
782 // returns the new child
783 //
784 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
785 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
786 // returns the new child
787 //
788 // public function appendInputRadio($name, $id, $value, $checked)
789 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
790 // returns the new child
791 //
792 // public function appendInputCheckbox($name, $id, $value, $checked)
793 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
794 // returns the new child
795 //
796 // public function appendInputFile($name, $id, $accept)
797 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
798 // returns the new child
799 //
800 // public function appendInputSubmit($value)
801 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
802 // returns the new child
803 //
804 // public function appendButton($value, $onclick = null)
805 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
806 // returns the new child
807 //
808 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
809 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
810 // returns the new child
811 //
812 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
813 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
814 // returns the new child
815 //
816 // public function appendElementOption($key, $desc, [$selected])
817 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
818 // returns the new child
819 //
820 // public function appendLabel($for_id, $value)
821 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
822 // returns the new child
823 //
824 // public function appendText($text)
825 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
826 // returns the new child
827 //
828 // public function appendLinebreak()
829 // appends a <br> as a child of this fragment
830 // returns the new child
831 //
832 // public function appendEntity($name)
833 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
834 // returns the new child
835 //
836 // public function appendComment($comment_data)
837 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
838 // returns the new child
839 //
840 // public function appendHTMLMarkup($htmldata)
841 // appends a representation of the HTML data as children of this fragment
842 // NO return value!
843 //
844 // public function appendXMLMarkup($xmldata)
845 // appends a representation of the XML data as children of this fragment
846 // NO return value!
847 //
848 // public function appendJSElement($jsdata)
849 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
850 // NO return value!
851 //
852 // public function appendJSFile($jsURL, [$defer], [$async])
853 // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
854 // returns the new child
855
856 public function appendElement($name, $value = '') {
857 return $this->appendChild($this->ownerDocument->createElement($name, $value));
858 }
859 public function appendElementXML($name, $xmldata) {
860 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
861 $aelem->appendXMLMarkup($xmldata);
862 return $aelem;
863 }
864 public function appendLink($target, $value = '') {
865 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
866 }
867 public function appendImage($src, $alt_text = '') {
868 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
869 }
870 public function appendForm($action, $method, $name, $id = null) {
871 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
872 }
873 public function appendFormDiv($action, $method, $name, $id = null) {
874 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
875 return $formelem->appendElement('div');
876 }
877 public function appendInputHidden($name, $value) {
878 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
879 }
880 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
881 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
882 }
883 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
884 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
885 }
886 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
887 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
888 }
889 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
890 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
891 }
892 public function appendInputRadio($name, $id, $value, $checked) {
893 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
894 }
895 public function appendInputCheckbox($name, $id, $value, $checked) {
896 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
897 }
898 public function appendInputFile($name, $id, $accept) {
899 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
900 }
901 public function appendInputSubmit($value) {
902 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
903 }
904 public function appendButton($value, $onclick = null) {
905 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
906 }
907 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
908 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
909 }
910 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
911 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
912 }
913 public function appendElementOption($key, $desc, $selected = false) {
914 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
915 }
916 public function appendLabel($for_id, $value) {
917 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
918 }
919 public function appendText($text) {
920 return $this->appendChild($this->ownerDocument->createTextNode($text));
921 }
922 public function appendLinebreak() {
923 return $this->appendChild($this->ownerDocument->createElement('br'));
924 }
925 public function appendEntity($name) {
926 return $this->appendChild($this->ownerDocument->createEntityReference($name));
927 }
928 public function appendComment($comment_data) {
929 return $this->appendChild($this->ownerDocument->createComment($comment_data));
930 }
931 public function appendHTMLMarkup($htmldata) {
932 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
933 }
934 public function appendXMLMarkup($xmldata) {
935 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
936 }
937 public function appendJSElement($jsdata) {
938 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
939 }
940 public function appendJSFile($jsdata, $defer = false, $async = false) {
941 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));
942 }
943}
944?>