move the files needed for the new php-utility-classes repo into new directories
[php-utility-classes.git] / classes / document.php-class
... / ...
CommitLineData
1<?php
2/* ***** BEGIN LICENSE BLOCK *****
3 *
4 * The contents of this file are subject to Austrian copyright reegulations
5 * ("Urheberrecht"); you may not use this file except in compliance with
6 * those laws.
7 * This contents and any derived work, if it gets distributed in any way,
8 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
9 * either express or implied.
10 *
11 * The Original Code is KaiRo's extended DOM document classes.
12 *
13 * The Initial Developer of the Original Code is
14 * KaiRo - Robert Kaiser.
15 * Portions created by the Initial Developer are Copyright (C) 2010
16 * the Initial Developer. All Rights Reserved.
17 *
18 * Contributor(s): Robert Kaiser <kairo@kairo.at>
19 *
20 * ***** END LICENSE BLOCK ***** */
21
22class ExtendedDocument extends DOMDocument {
23 // ExtendedDocument PHP class
24 // this extends the general PHP DOM Document class to simplify some usual constructs
25 //
26 // function __construct([$version], [$encoding])
27 // CONSTRUCTOR
28 // construct a new DOM Document that uses our element definitions
29 //
30 // static function initHTML5()
31 // initialize as an HTML5 document and return references to its basic elements.
32 // returns an associative array with the following elements: 'html', 'head', 'title', 'body'
33 //
34 // public function appendElement($name, [$value])
35 // appends a DOMDocument::createElement() as a child of this document (see there for params)
36 // returns the new child
37 //
38 // public function appendElementXML($name, $xmldata)
39 // appends a DOMDocument::createElement() with the given name as a child of this document,
40 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
41 // returns the new child
42 //
43 // public function appendLink($target, [$value])
44 // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
45 // returns the new child
46 //
47 // public function appendImage($src, [$alt_text])
48 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
49 // returns the new child
50 //
51 // public function appendForm($action, $method, $name, [$id])
52 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
53 // returns the new child
54 //
55 // public function appendFormDiv($action, $method, $name, [$id])
56 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
57 // returns an HTML <div> that is a child of the new child
58 //
59 // public function appendInputHidden($name, $value)
60 // appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
61 // returns the new child
62 //
63 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
64 // appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
65 // returns the new child
66 //
67 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
68 // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
69 // returns the new child
70 //
71 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
72 // appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params)
73 // returns the new child
74 //
75 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
76 // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
77 // returns the new child
78 //
79 // public function appendInputRadio($name, $id, $value, $checked)
80 // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
81 // returns the new child
82 //
83 // public function appendInputCheckbox($name, $id, $value, $checked)
84 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
85 // returns the new child
86 //
87 // public function appendInputFile($name, $id, $accept)
88 // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
89 // returns the new child
90 //
91 // public function appendInputSubmit($value)
92 // appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
93 // returns the new child
94 //
95 // public function appendButton($value, $onclick = null)
96 // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
97 // returns the new child
98 //
99 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
100 // appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
101 // returns the new child
102 //
103 // public function appendElementSelect($name, [$id], [$options], [$default])
104 // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
105 // returns the new child
106 //
107 // public function appendElementOption($key, $desc, [$selected])
108 // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
109 // returns the new child
110 //
111 // public function appendLabel($for_id, $value)
112 // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
113 // returns the new child
114 //
115 // public function appendText($text)
116 // appends a DOMDocument::createTextNode() as a child of this document (see there for params)
117 // returns the new child
118 //
119 // public function appendEntity($name)
120 // appends a DOMDocument::createEntityReference() as a child of this document (see there for params)
121 // returns the new child
122 //
123 // public function appendComment($comment_data)
124 // appends a DOMDocument::createComment() as a child of this document (see there for params)
125 // returns the new child
126 //
127 // public function appendHTMLMarkup($htmldata, [$parentNode])
128 // appends a representation of the HTML data as children of the given parent node, by default this document
129 // NO return value!
130 //
131 // public function appendXMLMarkup($xmldata, [$parentNode])
132 // appends a representation of the XML data as children of the given parent node, by default this document
133 // NO return value!
134 //
135 // public function appendJSElement($jsdata)
136 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
137 // NO return value!
138 //
139 // public function appendJSFile($jsURL)
140 // appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
141 // returns the new child
142 //
143 // public function appendCOMElement($module, $attributes)
144 // appends an ExtendedDocument::createCOMElement() as a child of this document (see there for params)
145 // returns the new child
146 //
147 // public function createElementLink($target, [$value])
148 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
149 //
150 // public function createElementImage($src, [$alt_text])
151 // returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
152 //
153 // public function createElementForm($action, $method, $name)
154 // returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
155 // with the given action, method, and name
156 //
157 // public function createElementInputHidden($name, $value)
158 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
159 //
160 // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
161 // returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
162 // and optionally id and value
163 //
164 // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
165 // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
166 // and optionally id and value
167 //
168 // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
169 // returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
170 // and optionally id and value
171 //
172 // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
173 // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
174 // and optionally id and value
175 //
176 // public function createElementInputRadio($name, $id, $value, $checked)
177 // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
178 // checked state
179 //
180 // public function createElementInputCheckbox($name, $id, $value, $checked)
181 // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
182 // checked state
183 //
184 // public function createElementInputFile($name, $id, $accept)
185 // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
186 //
187 // public function createElementInputSubmit($value)
188 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
189 //
190 // public function createElementButton($value, $onclick = null)
191 // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
192 //
193 // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
194 // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
195 // and optionally id and value
196 //
197 // public function createElementSelect($name, [$id], [$options], [$default])
198 // returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
199 // array of options (key => description) and key of the by-default selected entry
200 //
201 // public function createElementOption($key, $desc, [$selected])
202 // returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
203 // and optionally bool that tells if the entry is selected
204 //
205 // public function createElementLabel($for_id, $value)
206 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
207 //
208 // public function createElementJS($jsdata)
209 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
210 //
211 // public function createElementJSFile($jsURL)
212 // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
213 //
214 // public function createCOMElement($module, $attributes)
215 // returns an ExtendedElement that is in COM_NS namespace, with the given module as name and the
216 // given name=>value array as attributes
217
218 function __construct($version = '1.0', $encoding = 'utf-8') {
219 // make sure the default DOMDocument constructor runs
220 parent::__construct($version, $encoding);
221 $this->registerNodeClass('DOMElement', 'ExtendedElement');
222 $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
223 }
224
225 static function initHTML5() {
226 $doc = new ExtendedDocument();
227 $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
228
229 // Created basic HTML document structure.
230 $root = $doc->getElementsByTagName('html')->item(0);
231 $head = $root->appendElement('head');
232 $title = $head->appendElement('title');
233 $body = $root->appendElement('body');
234
235 return array('document' => $doc,
236 'html' => $root,
237 'head' => $head,
238 'title' => $title,
239 'body' => $body);
240 }
241
242 public function appendElement($name, $value = '') {
243 return $this->appendChild($this->createElement($name, $value));
244 }
245 public function appendElementXML($name, $xmldata) {
246 $aelem = $this->appendChild($this->createElement($name));
247 $aelem->appendXMLMarkup($xmldata);
248 //$aelem->appendChild($this->createXMLFragment($xmldata));
249 return $aelem;
250 }
251 public function appendLink($target, $value = '') {
252 return $this->appendChild($this->createElementLink($target, $value));
253 }
254 public function appendImage($src, $alt_text = '') {
255 return $this->appendChild($this->createElementImage($src, $alt_text));
256 }
257 public function appendForm($action, $method, $name, $id = null) {
258 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
259 }
260 public function appendFormDiv($action, $method, $name, $id = null) {
261 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
262 return $formelem->appendElement('div');
263 }
264 public function appendInputHidden($name, $value) {
265 return $this->appendChild($this->createElementInputHidden($name, $value));
266 }
267 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
268 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
269 }
270 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
271 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
272 }
273 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
274 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
275 }
276 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
277 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
278 }
279 public function appendInputRadio($name, $id, $value, $checked) {
280 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
281 }
282 public function appendInputCheckbox($name, $id, $value, $checked) {
283 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
284 }
285 public function appendInputFile($name, $id, $accept) {
286 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
287 }
288 public function appendInputSubmit($value) {
289 return $this->appendChild($this->createElementInputSubmit($value));
290 }
291 public function appendButton($value, $onclick = null) {
292 return $this->appendChild($this->createElementButton($value, $onclick));
293 }
294 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
295 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
296 }
297 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
298 return $this->appendChild($this->createElementSelect($name, $id, $options, $default));
299 }
300 public function appendElementOption($key, $desc, $selected = false) {
301 return $this->appendChild($this->createElementOption($key, $desc, $selected));
302 }
303 public function appendLabel($for_id, $value) {
304 return $this->appendChild($this->createElementLabel($for_id, $value));
305 }
306 public function appendText($text) {
307 return $this->appendChild($this->createTextNode($text));
308 }
309 public function appendEntity($name) {
310 return $this->appendChild($this->createEntityReference($name));
311 }
312 public function appendComment($comment_data) {
313 return $this->appendChild($this->createComment($comment_data));
314 }
315 public function appendJSElement($jsdata) {
316 $this->appendChild($this->createElementJS($jsdata));
317 }
318 public function appendJSFile($jsdata) {
319 return $this->appendChild($this->createElementJSFile($jsdata));
320 }
321 public function appendCOMElement($module, $attributes) {
322 return $this->appendChild($this->createCOMElement($module, $attributes));
323 }
324
325 public function appendHTMLMarkup($htmldata, $parentNode = null) {
326 if (is_null($parentNode)) { $parentNode =& $this; }
327 // XXX: just a workaround for now!
328 $parentNode->appendChild($this->createCDATASection($htmldata));
329 }
330
331 public function appendXMLMarkup($xmldata, $parentNode = null) {
332 if (is_null($parentNode)) { $parentNode =& $this; }
333 $tmpdoc = new ExtendedDocument;
334 $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
335 $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
336 $tmpxml .= '<root>'.$xmldata.'</root>';
337 $tmpdoc->loadXML($tmpxml);
338 foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
339 $parentNode->appendChild($this->importNode($child, true));
340 }
341 }
342
343 public function createElement($name, $value = '') {
344 // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
345 $aelem = parent::createElement($name);
346 $aelem->appendText($value);
347 return $aelem;
348 }
349
350 public function createElementLink($target, $value = '') {
351 $link = $this->createElement('a', $value);
352 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
353 return $link;
354 }
355
356 public function createElementImage($src, $alt_text = '') {
357 $img = $this->createElement('img');
358 $img->setAttribute('src', $src);
359 $img->setAttribute('alt', $alt_text);
360 return $img;
361 }
362
363 public function createElementForm($action, $method, $name, $id = null) {
364 $formelem = $this->createElement('form');
365 $formelem->setAttribute('action', $action);
366 $formelem->setAttribute('method', $method);
367 $formelem->setAttribute('name', $name);
368 $formelem->setAttribute('id', $id);
369 return $formelem;
370 }
371
372 public function createElementInputHidden($name, $value) {
373 $hidden = $this->createElement('input');
374 $hidden->setAttribute('type', 'hidden');
375 $hidden->setAttribute('name', $name);
376 $hidden->setAttribute('value', $value);
377 return $hidden;
378 }
379
380 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
381 $txfield = $this->createElement('input');
382 $txfield->setAttribute('type', 'text');
383 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
384 $txfield->setAttribute('name', $name);
385 $txfield->setAttribute('maxlength', $maxlength);
386 $txfield->setAttribute('size', $size);
387 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
388 return $txfield;
389 }
390
391 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
392 $txfield = $this->createElement('input');
393 $txfield->setAttribute('type', 'number');
394 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
395 $txfield->setAttribute('name', $name);
396 $txfield->setAttribute('maxlength', $maxlength);
397 $txfield->setAttribute('size', $size);
398 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
399 return $txfield;
400 }
401
402 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
403 $txfield = $this->createElement('input');
404 $txfield->setAttribute('type', 'email');
405 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
406 $txfield->setAttribute('name', $name);
407 $txfield->setAttribute('maxlength', $maxlength);
408 $txfield->setAttribute('size', $size);
409 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
410 return $txfield;
411 }
412
413 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
414 $pwfield = $this->createElement('input');
415 $pwfield->setAttribute('type', 'password');
416 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
417 $pwfield->setAttribute('name', $name);
418 $pwfield->setAttribute('maxlength', $maxlength);
419 $pwfield->setAttribute('size', $size);
420 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
421 return $pwfield;
422 }
423
424 public function createElementInputRadio($name, $id, $value, $checked) {
425 $radio = $this->createElement('input');
426 $radio->setAttribute('type', 'radio');
427 $radio->setAttribute('name', $name);
428 if (!is_null($id)) { $radio->setAttribute('id', $id); }
429 $radio->setAttribute('value', $value);
430 if ($checked) { $radio->setAttribute('checked', ''); }
431 return $radio;
432 }
433
434 public function createElementInputCheckbox($name, $id, $value, $checked) {
435 $cbox = $this->createElement('input');
436 $cbox->setAttribute('type', 'checkbox');
437 $cbox->setAttribute('name', $name);
438 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
439 $cbox->setAttribute('value', $value);
440 if ($checked) { $cbox->setAttribute('checked', ''); }
441 return $cbox;
442 }
443
444 public function createElementInputFile($name, $id, $accept) {
445 $fileinput = $this->createElement('input');
446 $fileinput->setAttribute('type', 'file');
447 $fileinput->setAttribute('name', $name);
448 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
449 $fileinput->setAttribute('accept', $accept);
450 return $fileinput;
451 }
452
453 public function createElementInputSubmit($value) {
454 $submitbtn = $this->createElement('input');
455 $submitbtn->setAttribute('type', 'submit');
456 $submitbtn->setAttribute('value', $value);
457 return $submitbtn;
458 }
459
460 public function createElementButton($value, $onclick = null) {
461 $btn = $this->createElement('input');
462 $btn->setAttribute('type', 'button');
463 $btn->setAttribute('value', $value);
464 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
465 return $btn;
466 }
467
468 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
469 $txtarea = $this->createElement('textarea', $value);
470 $txtarea->setAttribute('name', $name);
471 $txtarea->setAttribute('cols', $columns);
472 $txtarea->setAttribute('rows', $rows);
473 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
474 return $txtarea;
475 }
476
477 public function createElementSelect($name, $id = null, $options = array(), $default = null) {
478 $select = $this->createElement('select');
479 $select->setAttribute('name', $name);
480 if (!is_null($id)) { $select->setAttribute('id', $id); }
481 foreach ($options as $key => $desc) {
482 $select->appendElementOption($key, $desc, ($key == $default));
483 }
484 return $select;
485 }
486
487 public function createElementOption($key, $desc, $selected = false) {
488 $option = $this->createElement('option', $desc);
489 $option->setAttribute('value', $key);
490 if ($selected) { $option->setAttribute('selected', ''); }
491 return $option;
492 }
493
494 public function createElementLabel($for_id, $value) {
495 $label = $this->createElement('label', $value);
496 $label->setAttribute('for', $for_id);
497 return $label;
498 }
499
500 public function createElementJS($jsdata) {
501 $jselem = $this->createElement('script');
502 // Note: type can/should be left out for HTML5.
503 $jselem->setAttribute('type', 'text/javascript');
504 $jselem->appendChild($this->createCDATASection($jsdata));
505 return $jselem;
506 }
507
508 public function createElementJSFile($jsURL) {
509 $jselem = $this->createElement('script');
510 // Note: type can/should be left out for HTML5.
511 $jselem->setAttribute('type', 'text/javascript');
512 $jselem->setAttribute('src', $jsURL);
513 return $jselem;
514 }
515
516 public function createCOMElement($module, $attributes) {
517 $com_elem = $this->createElementNS(COM_NS, $module);
518 if (is_array($attributes) && count($attributes)) {
519 foreach ($attributes as $name=>$value) {
520 $com_elem->setAttribute($name, $value);
521 }
522 }
523 return $com_elem;
524 }
525}
526
527class ExtendedElement extends DOMElement {
528 // ExtendedElement PHP class
529 // this extends the general PHP DOM Element class to simplify some usual constructs
530 //
531 // public function appendElement($name, [$value])
532 // appends a DOMDocument::createElement() as a child of this element (see there for params)
533 // returns the new child
534 //
535 // public function appendElementXML($name, $xmldata)
536 // appends a DOMDocument::createElement() with the given name as a child of this element,
537 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
538 // returns the new child
539 //
540 // public function appendLink($target, [$value])
541 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
542 // returns the new child
543 //
544 // public function appendImage($src, [$alt_text])
545 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
546 // returns the new child
547 //
548 // public function appendForm($action, $method, $name, [$id])
549 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
550 // returns the new child
551 //
552 // public function appendFormDiv($action, $method, $name, [$id])
553 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
554 // returns an HTML <div> that is a child of the new child
555 //
556 // public function appendInputHidden($name, $value)
557 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
558 // returns the new child
559 //
560 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
561 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
562 // returns the new child
563 //
564 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
565 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
566 // returns the new child
567 //
568 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
569 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
570 // returns the new child
571 //
572 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
573 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
574 // returns the new child
575 //
576 // public function appendInputRadio($name, $id, $value, $checked)
577 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
578 // returns the new child
579 //
580 // public function appendInputCheckbox($name, $id, $value, $checked)
581 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
582 // returns the new child
583 //
584 // public function appendInputFile($name, $id, $accept)
585 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
586 // returns the new child
587 //
588 // public function appendInputSubmit($value)
589 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
590 // returns the new child
591 //
592 // public function appendButton($value, $onclick = null)
593 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
594 // returns the new child
595 //
596 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
597 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
598 // returns the new child
599 //
600 // public function appendElementSelect($name, [$id], [$options], [$default])
601 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
602 // returns the new child
603 //
604 // public function appendElementOption($key, $desc, [$selected])
605 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
606 // returns the new child
607 //
608 // public function appendLabel($for_id, $value)
609 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
610 // returns the new child
611 //
612 // public function appendText($text)
613 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
614 // returns the new child
615 //
616 // public function appendEntity($name)
617 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
618 // returns the new child
619 //
620 // public function appendComment($comment_data)
621 // appends a DOMDocument::createComment() as a child of this element (see there for params)
622 // returns the new child
623 //
624 // public function appendHTMLMarkup($htmldata)
625 // appends a representation of the HTML data as children of this element
626 // NO return value!
627 //
628 // public function appendXMLMarkup($xmldata)
629 // appends a representation of the XML data as children of this element
630 // NO return value!
631 //
632 // public function appendJSElement($jsdata)
633 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
634 // NO return value!
635 //
636 // public function appendCOMElement($module, $attributes)
637 // appends an ExtendedDocument::createCOMElement() as a child of this element (see there for params)
638 // returns the new child
639 //
640 // public function appendCOMElement($module, $attributes)
641 // appends an ExtendedDocument::createCOMElement() as a child of this element (see there for params)
642 // returns the new child
643
644 public function appendElement($name, $value = '') {
645 return $this->appendChild($this->ownerDocument->createElement($name, $value));
646 }
647 public function appendElementXML($name, $xmldata) {
648 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
649 $aelem->appendXMLMarkup($xmldata);
650 return $aelem;
651 }
652 public function appendLink($target, $value = '') {
653 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
654 }
655 public function appendImage($src, $alt_text = '') {
656 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
657 }
658 public function appendForm($action, $method, $name, $id = null) {
659 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
660 }
661 public function appendFormDiv($action, $method, $name, $id = null) {
662 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
663 return $formelem->appendElement('div');
664 }
665 public function appendInputHidden($name, $value) {
666 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
667 }
668 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
669 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
670 }
671 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
672 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
673 }
674 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
675 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
676 }
677 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
678 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
679 }
680 public function appendInputRadio($name, $id, $value, $checked) {
681 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
682 }
683 public function appendInputCheckbox($name, $id, $value, $checked) {
684 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
685 }
686 public function appendInputFile($name, $id, $accept) {
687 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
688 }
689 public function appendInputSubmit($value) {
690 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
691 }
692 public function appendButton($value, $onclick = null) {
693 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
694 }
695 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
696 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
697 }
698 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
699 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
700 }
701 public function appendElementOption($key, $desc, $selected = false) {
702 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
703 }
704 public function appendLabel($for_id, $value) {
705 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
706 }
707 public function appendText($text) {
708 return $this->appendChild($this->ownerDocument->createTextNode($text));
709 }
710 public function appendEntity($name) {
711 return $this->appendChild($this->ownerDocument->createEntityReference($name));
712 }
713 public function appendComment($comment_data) {
714 return $this->appendChild($this->ownerDocument->createComment($comment_data));
715 }
716 public function appendHTMLMarkup($htmldata) {
717 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
718 }
719 public function appendXMLMarkup($xmldata) {
720 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
721 }
722 public function appendJSElement($jsdata) {
723 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
724 }
725 public function appendJSFile($jsdata) {
726 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
727 }
728 public function appendCOMElement($module, $attributes) {
729 return $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
730 }
731}
732
733class ExtendedDocumentFragment extends DOMDocumentFragment {
734 // ExtendedDocumentFragment PHP class
735 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
736 //
737 // public function appendElement($name, [$value])
738 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
739 // returns the new child
740 //
741 // public function appendElementXML($name, $xmldata)
742 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
743 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
744 // returns the new child
745 //
746 // public function appendLink($target, [$value])
747 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
748 // returns the new child
749 //
750 // public function appendImage($src, [$alt_text])
751 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
752 // returns the new child
753 //
754 // public function appendForm($action, $method, $name, [$id])
755 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
756 // returns the new child
757 //
758 // public function appendFormDiv($action, $method, $name, [$id])
759 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
760 // returns an HTML <div> that is a child of the new child
761 //
762 // public function appendInputHidden($name, $value)
763 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
764 // returns the new child
765 //
766 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
767 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
768 // returns the new child
769 //
770 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
771 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
772 // returns the new child
773 //
774 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
775 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
776 // returns the new child
777 //
778 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
779 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
780 // returns the new child
781 //
782 // public function appendInputRadio($name, $id, $value, $checked)
783 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
784 // returns the new child
785 //
786 // public function appendInputCheckbox($name, $id, $value, $checked)
787 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
788 // returns the new child
789 //
790 // public function appendInputFile($name, $id, $accept)
791 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
792 // returns the new child
793 //
794 // public function appendInputSubmit($value)
795 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
796 // returns the new child
797 //
798 // public function appendButton($value, $onclick = null)
799 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
800 // returns the new child
801 //
802 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
803 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
804 // returns the new child
805 //
806 // public function appendElementSelect($name, [$id], [$options], [$default])
807 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
808 // returns the new child
809 //
810 // public function appendElementOption($key, $desc, [$selected])
811 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
812 // returns the new child
813 //
814 // public function appendLabel($for_id, $value)
815 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
816 // returns the new child
817 //
818 // public function appendText($text)
819 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
820 // returns the new child
821 //
822 // public function appendEntity($name)
823 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
824 // returns the new child
825 //
826 // public function appendComment($comment_data)
827 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
828 // returns the new child
829 //
830 // public function appendHTMLMarkup($htmldata)
831 // appends a representation of the HTML data as children of this fragment
832 // NO return value!
833 //
834 // public function appendXMLMarkup($xmldata)
835 // appends a representation of the XML data as children of this fragment
836 // NO return value!
837 //
838 // public function appendJSElement($jsdata)
839 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
840 // NO return value!
841 //
842 // public function appendCOMElement($module, $attributes)
843 // appends an ExtendedDocument::createCOMElement() as a child of this fragment (see there for params)
844 // returns the new child
845 //
846 // public function appendCOMElement($module, $attributes)
847 // appends an ExtendedDocument::createCOMElement() as a child of this fragment (see there for params)
848 // returns the new child
849
850 public function appendElement($name, $value = '') {
851 return $this->appendChild($this->ownerDocument->createElement($name, $value));
852 }
853 public function appendElementXML($name, $xmldata) {
854 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
855 $aelem->appendXMLMarkup($xmldata);
856 return $aelem;
857 }
858 public function appendLink($target, $value = '') {
859 return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
860 }
861 public function appendImage($src, $alt_text = '') {
862 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
863 }
864 public function appendForm($action, $method, $name, $id = null) {
865 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
866 }
867 public function appendFormDiv($action, $method, $name, $id = null) {
868 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
869 return $formelem->appendElement('div');
870 }
871 public function appendInputHidden($name, $value) {
872 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
873 }
874 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
875 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
876 }
877 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
878 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
879 }
880 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
881 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
882 }
883 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
884 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
885 }
886 public function appendInputRadio($name, $id, $value, $checked) {
887 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
888 }
889 public function appendInputCheckbox($name, $id, $value, $checked) {
890 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
891 }
892 public function appendInputFile($name, $id, $accept) {
893 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
894 }
895 public function appendInputSubmit($value) {
896 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
897 }
898 public function appendButton($value, $onclick = null) {
899 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
900 }
901 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
902 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
903 }
904 public function appendElementSelect($name, $id = null, $options = array(), $default = null) {
905 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
906 }
907 public function appendElementOption($key, $desc, $selected = false) {
908 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
909 }
910 public function appendLabel($for_id, $value) {
911 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
912 }
913 public function appendText($text) {
914 return $this->appendChild($this->ownerDocument->createTextNode($text));
915 }
916 public function appendEntity($name) {
917 return $this->appendChild($this->ownerDocument->createEntityReference($name));
918 }
919 public function appendComment($comment_data) {
920 return $this->appendChild($this->ownerDocument->createComment($comment_data));
921 }
922 public function appendHTMLMarkup($htmldata) {
923 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
924 }
925 public function appendXMLMarkup($xmldata) {
926 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
927 }
928 public function appendJSElement($jsdata) {
929 $this->appendChild($this->ownerDocument->createElementJS($jsdata));
930 }
931 public function appendJSFile($jsdata) {
932 return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata));
933 }
934 public function appendCOMElement($module, $attributes) {
935 return $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
936 }
937}
938?>