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