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