don't error out if the graph doesn't exist but can be created
[php-utility-classes.git] / classes / document.php-class
CommitLineData
cea5b93a 1<?php
880bcb60
RK
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/. */
cea5b93a
RK
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 //
b841a92b 14 // static function initHTML5([$doc])
14014b8f 15 // initialize as an HTML5 document and return references to its basic elements.
b841a92b 16 // If a $doc is handed over (an ExtendedDocument or a derived class), load the content into that document.
14014b8f 17 // returns an associative array with the following elements: 'html', 'head', 'title', 'body'
ae41c41b 18 //
d7403a92
RK
19 // public function loadHTML5($source) {
20 // A version of loadHTML() - see DOMDocument documentation - that is made for loading HTML5 and not emitting warnings/errors for unknown elements.
21 // returns true on success, false otherwise, just like loadHTML5.
22 //
61cc8aa9 23 // public function appendElement($name, [$value])
cea5b93a
RK
24 // appends a DOMDocument::createElement() as a child of this document (see there for params)
25 // returns the new child
26 //
61cc8aa9 27 // public function appendElementXML($name, $xmldata)
cea5b93a
RK
28 // appends a DOMDocument::createElement() with the given name as a child of this document,
29 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
30 // returns the new child
31 //
b3cc0fef 32 // public function appendLink($target, [$value], [$title])
cea5b93a
RK
33 // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
34 // returns the new child
35 //
61cc8aa9 36 // public function appendImage($src, [$alt_text])
53510e9e
RK
37 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
38 // returns the new child
39 //
61cc8aa9 40 // public function appendForm($action, $method, $name, [$id])
b8d16837
RK
41 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
42 // returns the new child
43 //
61cc8aa9 44 // public function appendFormDiv($action, $method, $name, [$id])
ae41c41b
RK
45 // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
46 // returns an HTML <div> that is a child of the new child
47 //
61cc8aa9 48 // public function appendInputHidden($name, $value)
ae41c41b
RK
49 // appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
50 // returns the new child
51 //
61cc8aa9 52 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
ae41c41b
RK
53 // appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
54 // returns the new child
55 //
f925e4a1
RK
56 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
57 // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
58 // returns the new child
59 //
61cc8aa9 60 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
262e0bbb
RK
61 // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
62 // returns the new child
63 //
f925e4a1
RK
64 // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
65 // appends an ExtendedDocument::createElementInputRange() as a child of this document (see there for params)
66 // returns the new child
67 //
68 // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
69 // appends an ExtendedDocument::createElementInputUrl() as a child of this document (see there for params)
70 // returns the new child
71 //
ea32f7e5
RK
72 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
73 // appends an ExtendedDocument::createElementInputEmail() as a child of this document (see there for params)
74 // returns the new child
75 //
f925e4a1
RK
76 // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
77 // appends an ExtendedDocument::createElementInputTel() as a child of this document (see there for params)
78 // returns the new child
79 //
80 // public function appendInputDate($name, [$id], [$min], [$max], [$value])
81 // appends an ExtendedDocument::createElementInputDate() as a child of this document (see there for params)
82 // returns the new child
83 //
84 // public function appendInputTime($name, [$id], [$min], [$max], [$value])
85 // appends an ExtendedDocument::createElementInputTime() as a child of this document (see there for params)
86 // returns the new child
87 //
88 // public function appendInputColor($name, [$id], [$value])
89 // appends an ExtendedDocument::createElementInputColor() as a child of this document (see there for params)
645a7eb6
RK
90 // returns the new child
91 //
61cc8aa9 92 // public function appendInputRadio($name, $id, $value, $checked)
ae41c41b
RK
93 // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
94 // returns the new child
95 //
61cc8aa9 96 // public function appendInputCheckbox($name, $id, $value, $checked)
ae41c41b
RK
97 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
98 // returns the new child
99 //
61cc8aa9 100 // public function appendInputFile($name, $id, $accept)
4bb9d784
RK
101 // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
102 // returns the new child
103 //
61cc8aa9 104 // public function appendInputSubmit($value)
ae41c41b
RK
105 // appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
106 // returns the new child
107 //
61cc8aa9 108 // public function appendButton($value, $onclick = null)
1109f526
RK
109 // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
110 // returns the new child
111 //
61cc8aa9 112 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
bf91764c
RK
113 // appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
114 // returns the new child
115 //
69409ddb 116 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
bf91764c
RK
117 // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
118 // returns the new child
119 //
61cc8aa9 120 // public function appendElementOption($key, $desc, [$selected])
bf91764c
RK
121 // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
122 // returns the new child
123 //
61cc8aa9 124 // public function appendLabel($for_id, $value)
ae41c41b
RK
125 // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
126 // returns the new child
127 //
61cc8aa9 128 // public function appendText($text)
cea5b93a
RK
129 // appends a DOMDocument::createTextNode() as a child of this document (see there for params)
130 // returns the new child
131 //
71771b0c
RK
132 // public function appendLinebreak()
133 // appends a <br> as a child of this document
134 // returns the new child
135 //
6638efd5
RK
136 // public function appendEntity($name)
137 // appends a DOMDocument::createEntityReference() as a child of this document (see there for params)
138 // returns the new child
139 //
61cc8aa9 140 // public function appendComment($comment_data)
cadc5980
RK
141 // appends a DOMDocument::createComment() as a child of this document (see there for params)
142 // returns the new child
143 //
3d4db013
RK
144 // public function appendClonedElement($dom_element, [$deep])
145 // appends a clone of the given DOMElement as a child of this document
146 // the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
147 // returns the new child
148 //
61cc8aa9 149 // public function appendHTMLMarkup($htmldata, [$parentNode])
ae41c41b
RK
150 // appends a representation of the HTML data as children of the given parent node, by default this document
151 // NO return value!
152 //
61cc8aa9 153 // public function appendXMLMarkup($xmldata, [$parentNode])
ae41c41b 154 // appends a representation of the XML data as children of the given parent node, by default this document
cea5b93a
RK
155 // NO return value!
156 //
acaa2daa
RK
157 // public function appendStyleElement($styledata)
158 // appends an ExtendedDocument::createElementStyle() as a child of this document (see there for params)
159 // returns the new child
160 //
61cc8aa9 161 // public function appendJSElement($jsdata)
cea5b93a 162 // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
acaa2daa 163 // returns the new child
cea5b93a 164 //
8afa2e61 165 // public function appendJSFile($jsURL, [$defer], [$async])
ea32f7e5
RK
166 // appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
167 // returns the new child
168 //
b3cc0fef
RK
169 // public function createElementLink($target, [$value], [$title])
170 // returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value as well as (optional) title attribute
cea5b93a 171 //
61cc8aa9 172 // public function createElementImage($src, [$alt_text])
b3cc0fef 173 // returns an ExtendedElement that is an HTML <img> with the given src and alt attributes (set to '' by default)
53510e9e 174 //
61cc8aa9 175 // public function createElementForm($action, $method, $name)
ae41c41b
RK
176 // returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
177 // with the given action, method, and name
178 //
61cc8aa9 179 // public function createElementInputHidden($name, $value)
ae41c41b
RK
180 // returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
181 //
61cc8aa9 182 // public function createElementInputText($name, $maxlength, $size, [$id], [$value])
ae41c41b
RK
183 // returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
184 // and optionally id and value
185 //
f925e4a1
RK
186 // public function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
187 // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
188 // and optionally id and value
189 //
61cc8aa9 190 // public function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
262e0bbb
RK
191 // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
192 // and optionally id and value
193 //
f925e4a1
RK
194 // public function createElementInputRange($name, $id, $min, $max, [$step], [$value])
195 // returns an ExtendedElement that is an HTML <input> of type 'range' with the given name, id, min, max,
196 // and optionally step and value
197 //
198 // public function createElementInputUrl($name, $maxlength, $size, [$id], [$value])
199 // returns an ExtendedElement that is an HTML <input> of type 'url' with the given name, maxlength, size,
200 // and optionally id and value
201 //
ea32f7e5
RK
202 // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value])
203 // returns an ExtendedElement that is an HTML <input> of type 'email' with the given name, maxlength, size,
204 // and optionally id and value
205 //
f925e4a1
RK
206 // public function createElementInputTel($name, $maxlength, $size, [$id], [$value])
207 // returns an ExtendedElement that is an HTML <input> of type 'tel' with the given name, maxlength, size,
208 // and optionally id and value
209 //
210 // public function createElementInputDate($name, [$id], [$min], [$max], [$value])
211 // returns an ExtendedElement that is an HTML <input> of type 'date' with the given name,
212 // and optionally id, min, max, and value
213 //
214 // public function createElementInputTime($name, [$id], [$min], [$max], [$value])
215 // returns an ExtendedElement that is an HTML <input> of type 'time' with the given name,
216 // and optionally id, min, max, and value
217 //
218 // public function createElementInputColor($name, [$id], [$value])
219 // returns an ExtendedElement that is an HTML <input> of type 'color' with the given name,
645a7eb6
RK
220 // and optionally id and value
221 //
61cc8aa9 222 // public function createElementInputRadio($name, $id, $value, $checked)
ae41c41b
RK
223 // returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
224 // checked state
225 //
61cc8aa9 226 // public function createElementInputCheckbox($name, $id, $value, $checked)
ae41c41b
RK
227 // returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
228 // checked state
229 //
61cc8aa9 230 // public function createElementInputFile($name, $id, $accept)
4bb9d784
RK
231 // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
232 //
61cc8aa9 233 // public function createElementInputSubmit($value)
1109f526
RK
234 // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
235 //
61cc8aa9 236 // public function createElementButton($value, $onclick = null)
1109f526 237 // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
ae41c41b 238 //
61cc8aa9 239 // public function createElementTextArea($name, $columns, $rows, [$id], [$value])
bf91764c
RK
240 // returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
241 // and optionally id and value
242 //
69409ddb 243 // public function createElementSelect($name, [$id], [$options], [$default], [$strictmatch])
bf91764c 244 // returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
69409ddb 245 // array of options (key => description) and key of the by-default selected entry (matched including type when strictmatch is true)
bf91764c 246 //
61cc8aa9 247 // public function createElementOption($key, $desc, [$selected])
bf91764c
RK
248 // returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
249 // and optionally bool that tells if the entry is selected
250 //
61cc8aa9 251 // public function createElementLabel($for_id, $value)
ae41c41b 252 // returns an ExtendedElement that is an HTML <label> with the given 'for' and value
cea5b93a 253 //
acaa2daa
RK
254 // public function createElementStyle($styledata)
255 // returns an ExtendedElement that is an HTML <style> of CSS type with the style data inside
256 //
61cc8aa9 257 // public function createElementJS($jsdata)
cea5b93a 258 // returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
c1666e91 259 //
8afa2e61 260 // public function createElementJSFile($jsURL, [$defer], [$async])
ea32f7e5 261 // returns an ExtendedElement that is an HTML <script> of JavaScript type linking to the file given by the URL
8afa2e61 262 // $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.
cea5b93a
RK
263
264 function __construct($version = '1.0', $encoding = 'utf-8') {
265 // make sure the default DOMDocument constructor runs
266 parent::__construct($version, $encoding);
267 $this->registerNodeClass('DOMElement', 'ExtendedElement');
bf91764c 268 $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
cea5b93a
RK
269 }
270
b841a92b
RK
271 static function initHTML5($doc = null) {
272 if (is_null($doc)) { $doc = new ExtendedDocument(); }
d7403a92 273 $doc->loadHTML5('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
14014b8f
RK
274
275 // Created basic HTML document structure.
276 $root = $doc->getElementsByTagName('html')->item(0);
277 $head = $root->appendElement('head');
278 $title = $head->appendElement('title');
279 $body = $root->appendElement('body');
280
281 return array('document' => $doc,
282 'html' => $root,
283 'head' => $head,
284 'title' => $title,
285 'body' => $body);
286 }
287
d7403a92
RK
288 public function loadHTML5($source) {
289 // Do our own handling of DOMDocument error reporting so we can ignore "unknown tags" which are usually fine in HTML5.
290 libxml_use_internal_errors(true);
291 if (!preg_match('/^\s*<?xml /', $source)) {
292 // Add an XML declaration to force DOMDocument into UTF-8 mode.
293 $source = '<?xml version="1.0" encoding="utf-8"?>'."\n".$source;
294 }
295 $result = $this->loadHTML($source);
296 // Handle DOMDocument loading errors, throw away warnings on unknown tags as HTML5 allows all kinds.
297 $errseverity = array(LIBXML_ERR_WARNING => 'Warning', LIBXML_ERR_ERROR => 'Error', LIBXML_ERR_FATAL => 'Fatal');
298 foreach (libxml_get_errors() as $error) {
299 // $error is a libXMLError, see https://www.php.net/manual/en/class.libxmlerror.php
300 // See http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors for error numbers
301 if ($error->code != 801) { // XML_HTML_UNKNOWN_TAG gets no output, should not exist for HTML5.
302 trigger_error($errseverity[$error->level].' loading HTML5: '.$error->message.' (code '.$error->code.'), line: '.$error->line, E_USER_WARNING);
303 }
304 }
305 libxml_clear_errors();
306 libxml_use_internal_errors(false);
307 return $result;
308 }
309
61cc8aa9 310 public function appendElement($name, $value = '') {
a8816f43 311 return $this->appendChild($this->createElement($name, $value));
cea5b93a 312 }
61cc8aa9 313 public function appendElementXML($name, $xmldata) {
cea5b93a 314 $aelem = $this->appendChild($this->createElement($name));
ae41c41b
RK
315 $aelem->appendXMLMarkup($xmldata);
316 //$aelem->appendChild($this->createXMLFragment($xmldata));
cea5b93a
RK
317 return $aelem;
318 }
b3cc0fef
RK
319 public function appendLink($target, $value = '', $title = null) {
320 return $this->appendChild($this->createElementLink($target, $value, $title));
cea5b93a 321 }
61cc8aa9 322 public function appendImage($src, $alt_text = '') {
4aa31782
RK
323 return $this->appendChild($this->createElementImage($src, $alt_text));
324 }
61cc8aa9 325 public function appendForm($action, $method, $name, $id = null) {
b8d16837
RK
326 return $this->appendChild($this->createElementForm($action, $method, $name, $id));
327 }
61cc8aa9 328 public function appendFormDiv($action, $method, $name, $id = null) {
b8d16837 329 $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
ae41c41b
RK
330 return $formelem->appendElement('div');
331 }
61cc8aa9 332 public function appendInputHidden($name, $value) {
ae41c41b
RK
333 return $this->appendChild($this->createElementInputHidden($name, $value));
334 }
61cc8aa9 335 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
ae41c41b
RK
336 return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
337 }
f925e4a1
RK
338 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
339 return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
340 }
61cc8aa9 341 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
262e0bbb
RK
342 return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
343 }
f925e4a1
RK
344 public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
345 return $this->appendChild($this->createElementInputRange($name, $id, $min, $max, $step, $value));
346 }
347 public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
348 return $this->appendChild($this->createElementInputUrl($name, $maxlength, $size, $id, $value));
349 }
ea32f7e5
RK
350 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
351 return $this->appendChild($this->createElementInputEmail($name, $maxlength, $size, $id, $value));
352 }
f925e4a1
RK
353 public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
354 return $this->appendChild($this->createElementInputTel($name, $maxlength, $size, $id, $value));
355 }
356 public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
357 return $this->appendChild($this->createElementInputDate($name, $id, $min, $max, $value));
358 }
359 public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
360 return $this->appendChild($this->createElementInputTime($name, $id, $min, $max, $value));
361 }
362 public function appendInputColor($name, $id = null, $value = null) {
363 return $this->appendChild($this->createElementInputColor($name, $id, $value));
645a7eb6 364 }
61cc8aa9 365 public function appendInputRadio($name, $id, $value, $checked) {
ae41c41b
RK
366 return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
367 }
61cc8aa9 368 public function appendInputCheckbox($name, $id, $value, $checked) {
ae41c41b
RK
369 return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
370 }
61cc8aa9 371 public function appendInputFile($name, $id, $accept) {
4bb9d784
RK
372 return $this->appendChild($this->createElementInputFile($name, $id, $accept));
373 }
61cc8aa9 374 public function appendInputSubmit($value) {
ae41c41b
RK
375 return $this->appendChild($this->createElementInputSubmit($value));
376 }
61cc8aa9 377 public function appendButton($value, $onclick = null) {
1109f526
RK
378 return $this->appendChild($this->createElementButton($value, $onclick));
379 }
61cc8aa9 380 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
bf91764c
RK
381 return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
382 }
69409ddb
RK
383 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
384 return $this->appendChild($this->createElementSelect($name, $id, $options, $default, $strictmatch));
bf91764c 385 }
61cc8aa9 386 public function appendElementOption($key, $desc, $selected = false) {
bf91764c
RK
387 return $this->appendChild($this->createElementOption($key, $desc, $selected));
388 }
61cc8aa9 389 public function appendLabel($for_id, $value) {
ae41c41b
RK
390 return $this->appendChild($this->createElementLabel($for_id, $value));
391 }
61cc8aa9 392 public function appendText($text) {
cea5b93a
RK
393 return $this->appendChild($this->createTextNode($text));
394 }
71771b0c
RK
395 public function appendLinebreak() {
396 return $this->appendChild($this->createElement('br'));
397 }
6638efd5
RK
398 public function appendEntity($name) {
399 return $this->appendChild($this->createEntityReference($name));
400 }
61cc8aa9 401 public function appendComment($comment_data) {
cadc5980
RK
402 return $this->appendChild($this->createComment($comment_data));
403 }
3d4db013
RK
404 public function appendClonedElement($dom_element, $deep = true) {
405 return $this->appendChild($dom_element->cloneNode($deep));
406 }
acaa2daa
RK
407 public function appendStyleElement($styledata) {
408 return $this->appendChild($this->createElementStyle($styledata));
409 }
61cc8aa9 410 public function appendJSElement($jsdata) {
3d4db013 411 return $this->appendChild($this->createElementJS($jsdata));
cea5b93a 412 }
1a4ee0f0
RK
413 public function appendJSFile($jsURL, $defer = false, $async = false) {
414 return $this->appendChild($this->createElementJSFile($jsURL, $defer, $async));
ea32f7e5 415 }
cea5b93a 416
61cc8aa9 417 public function appendHTMLMarkup($htmldata, $parentNode = null) {
ae41c41b 418 if (is_null($parentNode)) { $parentNode =& $this; }
d7403a92 419 // Use loadHTML5() to parse and turn the markup into proper HTML.
a9a5a68a
RK
420 $tmpdoc = new ExtendedDocument;
421 // The XML line is needed to tell the parser that we need UTF-8 parsing.
d7403a92 422 $tmpdoc->loadHTML5('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html><body>'.$htmldata.'</body></html>');
a9a5a68a
RK
423 foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) {
424 $parentNode->appendChild($this->importNode($child, true));
425 }
ae41c41b
RK
426 }
427
61cc8aa9 428 public function appendXMLMarkup($xmldata, $parentNode = null) {
ae41c41b
RK
429 if (is_null($parentNode)) { $parentNode =& $this; }
430 $tmpdoc = new ExtendedDocument;
431 $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
432 $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
433 $tmpxml .= '<root>'.$xmldata.'</root>';
434 $tmpdoc->loadXML($tmpxml);
435 foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
436 $parentNode->appendChild($this->importNode($child, true));
437 }
cea5b93a
RK
438 }
439
61cc8aa9 440 public function createElement($name, $value = '') {
a8816f43
RK
441 // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
442 $aelem = parent::createElement($name);
b3cc0fef 443 if (strlen($value)) { $aelem->appendText($value); }
a8816f43
RK
444 return $aelem;
445 }
446
b3cc0fef 447 public function createElementLink($target, $value = '', $title = null) {
a8816f43 448 $link = $this->createElement('a', $value);
bf91764c 449 $link->setAttribute('href', $target); // XXX: take care of & etc. in links
b3cc0fef 450 if (!is_null($title)) { $link->setAttribute('title', $title); }
cea5b93a
RK
451 return $link;
452 }
453
61cc8aa9 454 public function createElementImage($src, $alt_text = '') {
319cfe8d
RK
455 $img = $this->createElement('img');
456 $img->setAttribute('src', $src);
457 $img->setAttribute('alt', $alt_text);
458 return $img;
4aa31782
RK
459 }
460
61cc8aa9 461 public function createElementForm($action, $method, $name, $id = null) {
ae41c41b
RK
462 $formelem = $this->createElement('form');
463 $formelem->setAttribute('action', $action);
464 $formelem->setAttribute('method', $method);
465 $formelem->setAttribute('name', $name);
b3cc0fef 466 if (!is_null($id)) { $formelem->setAttribute('id', $id); }
ae41c41b
RK
467 return $formelem;
468 }
469
61cc8aa9 470 public function createElementInputHidden($name, $value) {
ae41c41b
RK
471 $hidden = $this->createElement('input');
472 $hidden->setAttribute('type', 'hidden');
473 $hidden->setAttribute('name', $name);
474 $hidden->setAttribute('value', $value);
475 return $hidden;
476 }
477
61cc8aa9 478 public function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
ae41c41b
RK
479 $txfield = $this->createElement('input');
480 $txfield->setAttribute('type', 'text');
481 if (!is_null($id)) { $txfield->setAttribute('id', $id); }
482 $txfield->setAttribute('name', $name);
483 $txfield->setAttribute('maxlength', $maxlength);
484 $txfield->setAttribute('size', $size);
485 if (!is_null($value)) { $txfield->setAttribute('value', $value); }
486 return $txfield;
487 }
488
61cc8aa9 489 public function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
319cfe8d
RK
490 $pwfield = $this->createElement('input');
491 $pwfield->setAttribute('type', 'password');
492 if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
493 $pwfield->setAttribute('name', $name);
494 $pwfield->setAttribute('maxlength', $maxlength);
495 $pwfield->setAttribute('size', $size);
496 if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
497 return $pwfield;
645a7eb6
RK
498 }
499
f925e4a1
RK
500 public function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
501 $numfield = $this->createElement('input');
502 $numfield->setAttribute('type', 'number');
503 if (!is_null($id)) { $numfield->setAttribute('id', $id); }
504 $numfield->setAttribute('name', $name);
505 $numfield->setAttribute('maxlength', $maxlength);
506 $numfield->setAttribute('size', $size);
507 if (!is_null($value)) { $numfield->setAttribute('value', $value); }
508 return $numfield;
509 }
510
511 public function createElementInputRange($name, $id, $min, $max, $step = null, $value = null) {
512 $rgfield = $this->createElement('input');
513 $rgfield->setAttribute('type', 'range');
514 if (!is_null($id)) { $rgfield->setAttribute('id', $id); }
515 $rgfield->setAttribute('name', $name);
516 if (!is_null($min)) { $rgfield->setAttribute('min', $min); }
517 if (!is_null($max)) { $rgfield->setAttribute('max', $max); }
518 if (!is_null($step)) { $rgfield->setAttribute('step', $step); }
519 if (!is_null($value)) { $rgfield->setAttribute('value', $value); }
520 return $rgfield;
521 }
522
523 public function createElementInputUrl($name, $maxlength, $size, $id = null, $value = null) {
524 $urlfield = $this->createElement('input');
525 $urlfield->setAttribute('type', 'url');
526 if (!is_null($id)) { $urlfield->setAttribute('id', $id); }
527 $urlfield->setAttribute('name', $name);
528 $urlfield->setAttribute('maxlength', $maxlength);
529 $urlfield->setAttribute('size', $size);
530 if (!is_null($value)) { $urlfield->setAttribute('value', $value); }
531 return $urlfield;
532 }
533
534 public function createElementInputEmail($name, $maxlength, $size, $id = null, $value = null) {
535 $mailfield = $this->createElement('input');
536 $mailfield->setAttribute('type', 'email');
537 if (!is_null($id)) { $mailfield->setAttribute('id', $id); }
538 $mailfield->setAttribute('name', $name);
539 $mailfield->setAttribute('maxlength', $maxlength);
540 $mailfield->setAttribute('size', $size);
541 if (!is_null($value)) { $mailfield->setAttribute('value', $value); }
542 return $mailfield;
543 }
544
545 public function createElementInputTel($name, $maxlength, $size, $id = null, $value = null) {
546 $telfield = $this->createElement('input');
547 $telfield->setAttribute('type', 'tel');
548 if (!is_null($id)) { $telfield->setAttribute('id', $id); }
549 $telfield->setAttribute('name', $name);
550 $telfield->setAttribute('maxlength', $maxlength);
551 $telfield->setAttribute('size', $size);
552 if (!is_null($value)) { $telfield->setAttribute('value', $value); }
553 return $telfield;
554 }
555
556 public function createElementInputDate($name, $id = null, $min = null, $max = null, $value = null) {
b5897591
RK
557 $dtfield = $this->createElement('input');
558 $dtfield->setAttribute('type', 'date');
559 if (!is_null($id)) { $dtfield->setAttribute('id', $id); }
560 $dtfield->setAttribute('name', $name);
561 if (!is_null($min)) { $dtfield->setAttribute('min', $min); }
562 if (!is_null($max)) { $dtfield->setAttribute('max', $max); }
563 if (!is_null($value)) { $dtfield->setAttribute('value', $value); }
564 return $dtfield;
f925e4a1
RK
565 }
566
567 public function createElementInputTime($name, $id = null, $min = null, $max = null, $value = null) {
b5897591
RK
568 $timefield = $this->createElement('input');
569 $timefield->setAttribute('type', 'time');
570 if (!is_null($id)) { $timefield->setAttribute('id', $id); }
571 $timefield->setAttribute('name', $name);
572 if (!is_null($min)) { $timefield->setAttribute('min', $min); }
573 if (!is_null($max)) { $timefield->setAttribute('max', $max); }
574 if (!is_null($value)) { $timefield->setAttribute('value', $value); }
575 return $timefield;
f925e4a1
RK
576 }
577
578 public function createElementInputColor($name, $id = null, $value = null) {
579 $colfield = $this->createElement('input');
580 $colfield->setAttribute('type', 'color');
581 if (!is_null($id)) { $colfield->setAttribute('id', $id); }
582 $colfield->setAttribute('name', $name);
583 if (!is_null($value)) { $colfield->setAttribute('value', $value); }
584 return $colfield;
585 }
586
61cc8aa9 587 public function createElementInputRadio($name, $id, $value, $checked) {
ae41c41b
RK
588 $radio = $this->createElement('input');
589 $radio->setAttribute('type', 'radio');
590 $radio->setAttribute('name', $name);
4bb9d784 591 if (!is_null($id)) { $radio->setAttribute('id', $id); }
ae41c41b
RK
592 $radio->setAttribute('value', $value);
593 if ($checked) { $radio->setAttribute('checked', ''); }
594 return $radio;
595 }
596
61cc8aa9 597 public function createElementInputCheckbox($name, $id, $value, $checked) {
ae41c41b
RK
598 $cbox = $this->createElement('input');
599 $cbox->setAttribute('type', 'checkbox');
600 $cbox->setAttribute('name', $name);
4bb9d784 601 if (!is_null($id)) { $cbox->setAttribute('id', $id); }
ae41c41b
RK
602 $cbox->setAttribute('value', $value);
603 if ($checked) { $cbox->setAttribute('checked', ''); }
604 return $cbox;
605 }
606
61cc8aa9 607 public function createElementInputFile($name, $id, $accept) {
4bb9d784
RK
608 $fileinput = $this->createElement('input');
609 $fileinput->setAttribute('type', 'file');
610 $fileinput->setAttribute('name', $name);
611 if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
612 $fileinput->setAttribute('accept', $accept);
613 return $fileinput;
614 }
615
61cc8aa9 616 public function createElementInputSubmit($value) {
ae41c41b
RK
617 $submitbtn = $this->createElement('input');
618 $submitbtn->setAttribute('type', 'submit');
619 $submitbtn->setAttribute('value', $value);
620 return $submitbtn;
621 }
622
61cc8aa9 623 public function createElementButton($value, $onclick = null) {
1109f526
RK
624 $btn = $this->createElement('input');
625 $btn->setAttribute('type', 'button');
626 $btn->setAttribute('value', $value);
627 if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
628 return $btn;
629 }
630
61cc8aa9 631 public function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
bf91764c
RK
632 $txtarea = $this->createElement('textarea', $value);
633 $txtarea->setAttribute('name', $name);
634 $txtarea->setAttribute('cols', $columns);
635 $txtarea->setAttribute('rows', $rows);
636 if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
637 return $txtarea;
638 }
639
69409ddb 640 public function createElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
bf91764c
RK
641 $select = $this->createElement('select');
642 $select->setAttribute('name', $name);
643 if (!is_null($id)) { $select->setAttribute('id', $id); }
644 foreach ($options as $key => $desc) {
69409ddb 645 $select->appendElementOption($key, $desc, $strictmatch ? ($key === $default) : ($key == $default));
bf91764c
RK
646 }
647 return $select;
648 }
649
61cc8aa9 650 public function createElementOption($key, $desc, $selected = false) {
bf91764c
RK
651 $option = $this->createElement('option', $desc);
652 $option->setAttribute('value', $key);
653 if ($selected) { $option->setAttribute('selected', ''); }
654 return $option;
655 }
656
61cc8aa9 657 public function createElementLabel($for_id, $value) {
ae41c41b
RK
658 $label = $this->createElement('label', $value);
659 $label->setAttribute('for', $for_id);
660 return $label;
cea5b93a
RK
661 }
662
acaa2daa
RK
663 public function createElementStyle($styledata) {
664 $style_elem = $this->createElement('style');
665 // Note: type can/should be left out for HTML5.
666 $style_elem->setAttribute('type', 'text/css');
667 $style_elem->appendChild($this->createCDATASection($styledata));
668 return $style_elem;
669 }
670
61cc8aa9 671 public function createElementJS($jsdata) {
cea5b93a 672 $jselem = $this->createElement('script');
ea32f7e5 673 // Note: type can/should be left out for HTML5.
cea5b93a
RK
674 $jselem->setAttribute('type', 'text/javascript');
675 $jselem->appendChild($this->createCDATASection($jsdata));
676 return $jselem;
677 }
c1666e91 678
8afa2e61 679 public function createElementJSFile($jsURL, $defer = false, $async = false) {
ea32f7e5
RK
680 $jselem = $this->createElement('script');
681 // Note: type can/should be left out for HTML5.
682 $jselem->setAttribute('type', 'text/javascript');
8afa2e61
RK
683 if ($defer) {
684 $jselem->setAttribute('defer', '');
685 }
686 if ($async) {
687 $jselem->setAttribute('async', '');
688 }
ea32f7e5
RK
689 $jselem->setAttribute('src', $jsURL);
690 return $jselem;
691 }
cea5b93a
RK
692}
693
694class ExtendedElement extends DOMElement {
695 // ExtendedElement PHP class
696 // this extends the general PHP DOM Element class to simplify some usual constructs
697 //
61cc8aa9 698 // public function appendElement($name, [$value])
cea5b93a
RK
699 // appends a DOMDocument::createElement() as a child of this element (see there for params)
700 // returns the new child
701 //
61cc8aa9 702 // public function appendElementXML($name, $xmldata)
cea5b93a
RK
703 // appends a DOMDocument::createElement() with the given name as a child of this element,
704 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
705 // returns the new child
706 //
b3cc0fef 707 // public function appendLink($target, [$value], [$title])
cea5b93a
RK
708 // appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
709 // returns the new child
710 //
61cc8aa9 711 // public function appendImage($src, [$alt_text])
53510e9e
RK
712 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
713 // returns the new child
714 //
61cc8aa9 715 // public function appendForm($action, $method, $name, [$id])
b8d16837
RK
716 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
717 // returns the new child
718 //
61cc8aa9 719 // public function appendFormDiv($action, $method, $name, [$id])
ae41c41b
RK
720 // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
721 // returns an HTML <div> that is a child of the new child
722 //
61cc8aa9 723 // public function appendInputHidden($name, $value)
ae41c41b
RK
724 // appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
725 // returns the new child
726 //
61cc8aa9 727 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
ae41c41b
RK
728 // appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
729 // returns the new child
730 //
f925e4a1
RK
731 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
732 // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
733 // returns the new child
734 //
61cc8aa9 735 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
262e0bbb
RK
736 // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
737 // returns the new child
738 //
f925e4a1
RK
739 // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
740 // appends an ExtendedDocument::createElementInputRange() as a child of this element (see there for params)
741 // returns the new child
742 //
743 // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
744 // appends an ExtendedDocument::createElementInputUrl() as a child of this element (see there for params)
745 // returns the new child
746 //
ea32f7e5
RK
747 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
748 // appends an ExtendedDocument::createElementInputEmail() as a child of this element (see there for params)
749 // returns the new child
750 //
f925e4a1
RK
751 // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
752 // appends an ExtendedDocument::createElementInputTel() as a child of this element (see there for params)
753 // returns the new child
754 //
755 // public function appendInputDate($name, [$id], [$min], [$max], [$value])
756 // appends an ExtendedDocument::createElementInputDate() as a child of this element (see there for params)
757 // returns the new child
758 //
759 // public function appendInputTime($name, [$id], [$min], [$max], [$value])
760 // appends an ExtendedDocument::createElementInputTime() as a child of this element (see there for params)
645a7eb6
RK
761 // returns the new child
762 //
f925e4a1
RK
763 // public function appendInputColor($name, [$id], [$value])
764 // appends an ExtendedDocument::createElementInputColor() as a child of this element (see there for params)
765 //
61cc8aa9 766 // public function appendInputRadio($name, $id, $value, $checked)
ae41c41b
RK
767 // appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
768 // returns the new child
769 //
61cc8aa9 770 // public function appendInputCheckbox($name, $id, $value, $checked)
ae41c41b
RK
771 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
772 // returns the new child
773 //
61cc8aa9 774 // public function appendInputFile($name, $id, $accept)
4bb9d784
RK
775 // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
776 // returns the new child
777 //
61cc8aa9 778 // public function appendInputSubmit($value)
ae41c41b
RK
779 // appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
780 // returns the new child
781 //
61cc8aa9 782 // public function appendButton($value, $onclick = null)
1109f526
RK
783 // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
784 // returns the new child
785 //
61cc8aa9 786 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
bf91764c
RK
787 // appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
788 // returns the new child
789 //
69409ddb 790 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
bf91764c
RK
791 // appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
792 // returns the new child
793 //
61cc8aa9 794 // public function appendElementOption($key, $desc, [$selected])
bf91764c
RK
795 // appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
796 // returns the new child
797 //
61cc8aa9 798 // public function appendLabel($for_id, $value)
ae41c41b
RK
799 // appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
800 // returns the new child
801 //
61cc8aa9 802 // public function appendText($text)
cea5b93a
RK
803 // appends a DOMDocument::createTextNode() as a child of this element (see there for params)
804 // returns the new child
805 //
71771b0c
RK
806 // public function appendLinebreak()
807 // appends a <br> as a child of this element
808 // returns the new child
809 //
6638efd5
RK
810 // public function appendEntity($name)
811 // appends a DOMDocument::createEntityReference() as a child of this element (see there for params)
812 // returns the new child
813 //
61cc8aa9 814 // public function appendComment($comment_data)
cadc5980
RK
815 // appends a DOMDocument::createComment() as a child of this element (see there for params)
816 // returns the new child
817 //
3d4db013
RK
818 // public function appendClonedElement($dom_element, [$deep])
819 // appends a clone of the given DOMElement as a child of this element
820 // the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
821 // returns the new child
822 //
61cc8aa9 823 // public function appendHTMLMarkup($htmldata)
ae41c41b
RK
824 // appends a representation of the HTML data as children of this element
825 // NO return value!
826 //
61cc8aa9 827 // public function appendXMLMarkup($xmldata)
ae41c41b 828 // appends a representation of the XML data as children of this element
cea5b93a
RK
829 // NO return value!
830 //
acaa2daa
RK
831 // public function appendStyleElement($styledata)
832 // appends an ExtendedDocument::createElementStyle() as a child of this element (see there for params)
833 // returns the new child
834 //
61cc8aa9 835 // public function appendJSElement($jsdata)
cea5b93a 836 // appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
3d4db013 837 // returns the new child
c1666e91 838 //
8afa2e61 839 // public function appendJSFile($jsURL, [$defer], [$async])
0bbc241e 840 // appends an ExtendedDocument::createElementJSFile() as a child of this element (see there for params)
ea32f7e5 841 // returns the new child
f887cdcb
RK
842 //
843 // public function setClass($classname)
844 // sets the 'class' attribute of the element to the given classname value
845 //
846 // public function addClass($classname)
847 // adds the given classname value to the space-separated list in the 'class' attribute
848 // returns the value of the 'class' attribute
849 //
850 // public function setID($elem_id)
851 // sets the 'id' attribute of the element to the given elem_id value
cea5b93a 852
61cc8aa9 853 public function appendElement($name, $value = '') {
a8816f43 854 return $this->appendChild($this->ownerDocument->createElement($name, $value));
cea5b93a 855 }
61cc8aa9 856 public function appendElementXML($name, $xmldata) {
cea5b93a 857 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
ae41c41b 858 $aelem->appendXMLMarkup($xmldata);
cea5b93a
RK
859 return $aelem;
860 }
b3cc0fef
RK
861 public function appendLink($target, $value = '', $title = null) {
862 return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title));
cea5b93a 863 }
61cc8aa9 864 public function appendImage($src, $alt_text = '') {
53510e9e
RK
865 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
866 }
61cc8aa9 867 public function appendForm($action, $method, $name, $id = null) {
b8d16837
RK
868 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
869 }
61cc8aa9 870 public function appendFormDiv($action, $method, $name, $id = null) {
b8d16837 871 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
ae41c41b
RK
872 return $formelem->appendElement('div');
873 }
61cc8aa9 874 public function appendInputHidden($name, $value) {
ae41c41b
RK
875 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
876 }
61cc8aa9 877 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
ae41c41b
RK
878 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
879 }
f925e4a1
RK
880 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
881 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
882 }
61cc8aa9 883 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
262e0bbb
RK
884 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
885 }
f925e4a1
RK
886 public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
887 return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value));
888 }
889 public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
890 return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value));
891 }
ea32f7e5
RK
892 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
893 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
894 }
f925e4a1
RK
895 public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
896 return $this->appendChild($this->ownerDocument->createElementInputTel($name, $maxlength, $size, $id, $value));
897 }
898 public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
899 return $this->appendChild($this->ownerDocument->createElementInputDate($name, $id, $min, $max, $value));
900 }
901 public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
902 return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
903 }
904 public function appendInputColor($name, $id = null, $value = null) {
905 return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
645a7eb6 906 }
61cc8aa9 907 public function appendInputRadio($name, $id, $value, $checked) {
ae41c41b
RK
908 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
909 }
61cc8aa9 910 public function appendInputCheckbox($name, $id, $value, $checked) {
ae41c41b
RK
911 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
912 }
61cc8aa9 913 public function appendInputFile($name, $id, $accept) {
4bb9d784
RK
914 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
915 }
61cc8aa9 916 public function appendInputSubmit($value) {
ae41c41b
RK
917 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
918 }
61cc8aa9 919 public function appendButton($value, $onclick = null) {
1109f526
RK
920 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
921 }
61cc8aa9 922 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
bf91764c
RK
923 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
924 }
69409ddb
RK
925 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
926 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
bf91764c 927 }
61cc8aa9 928 public function appendElementOption($key, $desc, $selected = false) {
bf91764c
RK
929 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
930 }
61cc8aa9 931 public function appendLabel($for_id, $value) {
bf91764c
RK
932 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
933 }
61cc8aa9 934 public function appendText($text) {
bf91764c
RK
935 return $this->appendChild($this->ownerDocument->createTextNode($text));
936 }
71771b0c
RK
937 public function appendLinebreak() {
938 return $this->appendChild($this->ownerDocument->createElement('br'));
939 }
6638efd5
RK
940 public function appendEntity($name) {
941 return $this->appendChild($this->ownerDocument->createEntityReference($name));
942 }
61cc8aa9 943 public function appendComment($comment_data) {
cadc5980
RK
944 return $this->appendChild($this->ownerDocument->createComment($comment_data));
945 }
3d4db013
RK
946 public function appendClonedElement($dom_element, $deep = true) {
947 return $this->appendChild($dom_element->cloneNode($deep));
948 }
61cc8aa9 949 public function appendHTMLMarkup($htmldata) {
bf91764c
RK
950 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
951 }
61cc8aa9 952 public function appendXMLMarkup($xmldata) {
bf91764c
RK
953 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
954 }
acaa2daa
RK
955 public function appendStyleElement($styledata) {
956 return $this->appendChild($this->ownerDocument->createElementStyle($styledata));
957 }
61cc8aa9 958 public function appendJSElement($jsdata) {
3d4db013 959 return $this->appendChild($this->ownerDocument->createElementJS($jsdata));
bf91764c 960 }
1a4ee0f0
RK
961 public function appendJSFile($jsURL, $defer = false, $async = false) {
962 return $this->appendChild($this->ownerDocument->createElementJSFile($jsURL, $defer, $async));
ea32f7e5 963 }
f887cdcb
RK
964 public function setClass($classname) {
965 $this->setAttribute('class', $classname);
966 }
967 public function addClass($classname) {
968 $classval = $this->getAttribute('class');
969 if (strlen($classval)) { $classval .= ' '; }
970 $classval .= $classname;
971 $this->setClass($classval);
972 return $classval;
973 }
974 public function setID($elem_id) {
975 $this->setAttribute('id', $elem_id);
976 }
bf91764c
RK
977}
978
979class ExtendedDocumentFragment extends DOMDocumentFragment {
980 // ExtendedDocumentFragment PHP class
981 // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
982 //
61cc8aa9 983 // public function appendElement($name, [$value])
bf91764c
RK
984 // appends a DOMDocument::createElement() as a child of this fragment (see there for params)
985 // returns the new child
986 //
61cc8aa9 987 // public function appendElementXML($name, $xmldata)
bf91764c
RK
988 // appends a DOMDocument::createElement() with the given name as a child of this fragment,
989 // with an ExtendedDocument::createXMLFragment() of the given XML data inside
990 // returns the new child
991 //
b3cc0fef 992 // public function appendLink($target, [$value], [$title])
bf91764c
RK
993 // appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
994 // returns the new child
995 //
61cc8aa9 996 // public function appendImage($src, [$alt_text])
53510e9e
RK
997 // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
998 // returns the new child
999 //
61cc8aa9 1000 // public function appendForm($action, $method, $name, [$id])
b8d16837
RK
1001 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
1002 // returns the new child
1003 //
61cc8aa9 1004 // public function appendFormDiv($action, $method, $name, [$id])
bf91764c
RK
1005 // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
1006 // returns an HTML <div> that is a child of the new child
1007 //
61cc8aa9 1008 // public function appendInputHidden($name, $value)
bf91764c
RK
1009 // appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
1010 // returns the new child
1011 //
61cc8aa9 1012 // public function appendInputText($name, $maxlength, $size, [$id], [$value])
bf91764c
RK
1013 // appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
1014 // returns the new child
1015 //
f925e4a1
RK
1016 // public function appendInputPassword($name, $maxlength, $size, [$id], [$value])
1017 // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
1018 // returns the new child
1019 //
61cc8aa9 1020 // public function appendInputNumber($name, $maxlength, $size, [$id], [$value])
262e0bbb
RK
1021 // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
1022 // returns the new child
1023 //
f925e4a1
RK
1024 // public function appendInputRange($name, $id, $min, $max, [$step], [$value])
1025 // appends an ExtendedDocument::createElementInputRange() as a child of this fragment (see there for params)
1026 // returns the new child
1027 //
1028 // public function appendInputUrl($name, $maxlength, $size, [$id], [$value])
1029 // appends an ExtendedDocument::createElementInputUrl() as a child of this fragment (see there for params)
1030 // returns the new child
1031 //
ea32f7e5
RK
1032 // public function appendInputEmail($name, $maxlength, $size, [$id], [$value])
1033 // appends an ExtendedDocument::createElementInputEmail() as a child of this fragment (see there for params)
1034 // returns the new child
1035 //
f925e4a1
RK
1036 // public function appendInputTel($name, $maxlength, $size, [$id], [$value])
1037 // appends an ExtendedDocument::createElementInputTel() as a child of this fragment (see there for params)
645a7eb6
RK
1038 // returns the new child
1039 //
f925e4a1
RK
1040 // public function appendInputDate($name, [$id], [$min], [$max], [$value])
1041 // appends an ExtendedDocument::createElementInputDate() as a child of this fragment (see there for params)
1042 // returns the new child
1043 //
1044 // public function appendInputTime($name, [$id], [$min], [$max], [$value])
1045 // appends an ExtendedDocument::createElementInputTime() as a child of this fragment (see there for params)
1046 // returns the new child
1047 //
1048 // public function appendInputColor($name, [$id], [$value])
1049 // appends an ExtendedDocument::createElementInputColor() as a child of this fragment (see there for params)
1050 //
61cc8aa9 1051 // public function appendInputRadio($name, $id, $value, $checked)
bf91764c
RK
1052 // appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
1053 // returns the new child
1054 //
61cc8aa9 1055 // public function appendInputCheckbox($name, $id, $value, $checked)
bf91764c
RK
1056 // appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
1057 // returns the new child
1058 //
61cc8aa9 1059 // public function appendInputFile($name, $id, $accept)
4bb9d784
RK
1060 // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
1061 // returns the new child
1062 //
61cc8aa9 1063 // public function appendInputSubmit($value)
bf91764c
RK
1064 // appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
1065 // returns the new child
1066 //
61cc8aa9 1067 // public function appendButton($value, $onclick = null)
1109f526
RK
1068 // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
1069 // returns the new child
1070 //
61cc8aa9 1071 // public function appendTextArea($name, $columns, $rows, [$id], [$value])
bf91764c
RK
1072 // appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
1073 // returns the new child
1074 //
69409ddb 1075 // public function appendElementSelect($name, [$id], [$options], [$default], [$strictmatch])
bf91764c
RK
1076 // appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
1077 // returns the new child
1078 //
61cc8aa9 1079 // public function appendElementOption($key, $desc, [$selected])
bf91764c
RK
1080 // appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
1081 // returns the new child
1082 //
61cc8aa9 1083 // public function appendLabel($for_id, $value)
bf91764c
RK
1084 // appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
1085 // returns the new child
1086 //
61cc8aa9 1087 // public function appendText($text)
bf91764c
RK
1088 // appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
1089 // returns the new child
1090 //
71771b0c
RK
1091 // public function appendLinebreak()
1092 // appends a <br> as a child of this fragment
1093 // returns the new child
1094 //
6638efd5
RK
1095 // public function appendEntity($name)
1096 // appends a DOMDocument::createEntityReference() as a child of this fragment (see there for params)
1097 // returns the new child
1098 //
61cc8aa9 1099 // public function appendComment($comment_data)
cadc5980
RK
1100 // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
1101 // returns the new child
1102 //
3d4db013
RK
1103 // public function appendClonedElement($dom_element, [$deep])
1104 // appends a clone of the given DOMElement as a child of this fragment
1105 // the boolean $deep specifies if the children are cloned as well (defaults to TRUE)
1106 // returns the new child
1107 //
61cc8aa9 1108 // public function appendHTMLMarkup($htmldata)
bf91764c
RK
1109 // appends a representation of the HTML data as children of this fragment
1110 // NO return value!
1111 //
61cc8aa9 1112 // public function appendXMLMarkup($xmldata)
bf91764c
RK
1113 // appends a representation of the XML data as children of this fragment
1114 // NO return value!
1115 //
acaa2daa
RK
1116 // public function appendStyleElement($styledata)
1117 // appends an ExtendedDocument::createElementStyle() as a child of this element (see there for params)
1118 // returns the new child
1119 //
61cc8aa9 1120 // public function appendJSElement($jsdata)
bf91764c 1121 // appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
3d4db013 1122 // returns the new child
c1666e91 1123 //
8afa2e61 1124 // public function appendJSFile($jsURL, [$defer], [$async])
0bbc241e 1125 // appends an ExtendedDocument::createElementJSFile() as a child of this fragment (see there for params)
ea32f7e5 1126 // returns the new child
bf91764c 1127
61cc8aa9 1128 public function appendElement($name, $value = '') {
a8816f43 1129 return $this->appendChild($this->ownerDocument->createElement($name, $value));
bf91764c 1130 }
61cc8aa9 1131 public function appendElementXML($name, $xmldata) {
bf91764c
RK
1132 $aelem = $this->appendChild($this->ownerDocument->createElement($name));
1133 $aelem->appendXMLMarkup($xmldata);
1134 return $aelem;
1135 }
b3cc0fef
RK
1136 public function appendLink($target, $value = '', $title = null) {
1137 return $this->appendChild($this->ownerDocument->createElementLink($target, $value, $title));
bf91764c 1138 }
61cc8aa9 1139 public function appendImage($src, $alt_text = '') {
53510e9e
RK
1140 return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
1141 }
61cc8aa9 1142 public function appendForm($action, $method, $name, $id = null) {
b8d16837
RK
1143 return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
1144 }
61cc8aa9 1145 public function appendFormDiv($action, $method, $name, $id = null) {
b8d16837 1146 $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
bf91764c
RK
1147 return $formelem->appendElement('div');
1148 }
61cc8aa9 1149 public function appendInputHidden($name, $value) {
bf91764c
RK
1150 return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
1151 }
61cc8aa9 1152 public function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
bf91764c 1153 return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
645a7eb6 1154 }
f925e4a1
RK
1155 public function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
1156 return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
1157 }
61cc8aa9 1158 public function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
262e0bbb
RK
1159 return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
1160 }
f925e4a1
RK
1161 public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) {
1162 return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value));
1163 }
1164 public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) {
1165 return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value));
1166 }
ea32f7e5
RK
1167 public function appendInputEmail($name, $maxlength, $size, $id = null, $value = null) {
1168 return $this->appendChild($this->ownerDocument->createElementInputEmail($name, $maxlength, $size, $id, $value));
1169 }
f925e4a1
RK
1170 public function appendInputTel($name, $maxlength, $size, $id = null, $value = null) {
1171 return $this->appendChild($this->ownerDocument->createElementInputTel($name, $maxlength, $size, $id, $value));
1172 }
1173 public function appendInputDate($name, $id = null, $min = null, $max = null, $value = null) {
1174 return $this->appendChild($this->ownerDocument->createElementInputDate($name, $id, $min, $max, $value));
1175 }
1176 public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
1177 return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
1178 }
1179 public function appendInputColor($name, $id = null, $value = null) {
1180 return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
bf91764c 1181 }
61cc8aa9 1182 public function appendInputRadio($name, $id, $value, $checked) {
bf91764c
RK
1183 return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
1184 }
61cc8aa9 1185 public function appendInputCheckbox($name, $id, $value, $checked) {
bf91764c
RK
1186 return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
1187 }
61cc8aa9 1188 public function appendInputFile($name, $id, $accept) {
4bb9d784
RK
1189 return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
1190 }
61cc8aa9 1191 public function appendInputSubmit($value) {
bf91764c
RK
1192 return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
1193 }
61cc8aa9 1194 public function appendButton($value, $onclick = null) {
1109f526
RK
1195 return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
1196 }
61cc8aa9 1197 public function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
bf91764c
RK
1198 return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
1199 }
69409ddb
RK
1200 public function appendElementSelect($name, $id = null, $options = array(), $default = null, $strictmatch = false) {
1201 return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default, $strictmatch));
bf91764c 1202 }
61cc8aa9 1203 public function appendElementOption($key, $desc, $selected = false) {
bf91764c
RK
1204 return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
1205 }
61cc8aa9 1206 public function appendLabel($for_id, $value) {
ae41c41b
RK
1207 return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
1208 }
61cc8aa9 1209 public function appendText($text) {
cea5b93a
RK
1210 return $this->appendChild($this->ownerDocument->createTextNode($text));
1211 }
71771b0c
RK
1212 public function appendLinebreak() {
1213 return $this->appendChild($this->ownerDocument->createElement('br'));
1214 }
6638efd5
RK
1215 public function appendEntity($name) {
1216 return $this->appendChild($this->ownerDocument->createEntityReference($name));
1217 }
61cc8aa9 1218 public function appendComment($comment_data) {
cadc5980
RK
1219 return $this->appendChild($this->ownerDocument->createComment($comment_data));
1220 }
3d4db013
RK
1221 public function appendClonedElement($dom_element, $deep = true) {
1222 return $this->appendChild($dom_element->cloneNode($deep));
1223 }
61cc8aa9 1224 public function appendHTMLMarkup($htmldata) {
ae41c41b
RK
1225 $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
1226 }
61cc8aa9 1227 public function appendXMLMarkup($xmldata) {
ae41c41b 1228 $this->ownerDocument->appendXMLMarkup($xmldata, $this);
cea5b93a 1229 }
acaa2daa
RK
1230 public function appendStyleElement($styledata) {
1231 return $this->appendChild($this->ownerDocument->createElementStyle($styledata));
1232 }
61cc8aa9 1233 public function appendJSElement($jsdata) {
3d4db013 1234 return $this->appendChild($this->ownerDocument->createElementJS($jsdata));
cea5b93a 1235 }
1a4ee0f0
RK
1236 public function appendJSFile($jsURL, $defer = false, $async = false) {
1237 return $this->appendChild($this->ownerDocument->createElementJSFile($jsURL, $defer, $async));
ea32f7e5 1238 }
cea5b93a
RK
1239}
1240?>