// CONSTRUCTOR
// construct a new DOM Document that uses our element definitions
//
- // private $xmheader
- // the default XML header
- //
- // private $xhtmldtype
- // the XHTML doctype to use by default
+ // static function initHTML5()
+ // initialize as an HTML5 document and return references to its basic elements.
+ // returns an associative array with the following elements: 'html', 'head', 'title', 'body'
//
// function appendElement($name, [$value])
// appends a DOMDocument::createElement() as a child of this document (see there for params)
// appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
// returns the new child
//
- // function appendFormDiv($action, $method, $name)
+ // function appendImage($src, [$alt_text])
+ // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
+ // returns the new child
+ //
+ // function appendForm($action, $method, $name, [$id])
+ // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
+ // returns the new child
+ //
+ // function appendFormDiv($action, $method, $name, [$id])
// appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
// returns an HTML <div> that is a child of the new child
//
// appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
// returns the new child
//
+ // function appendInputNumber($name, $maxlength, $size, [$id], [$value])
+ // appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
+ // returns the new child
+ //
+ // function appendInputPassword($name, $maxlength, $size, [$id], [$value])
+ // appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
+ // returns the new child
+ //
// function appendInputRadio($name, $id, $value, $checked)
// appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
// returns the new child
// appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
// returns the new child
//
+ // function appendInputFile($name, $id, $accept)
+ // appends an ExtendedDocument::createElementInputFile() as a child of this document (see there for params)
+ // returns the new child
+ //
// function appendInputSubmit($value)
// appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
// returns the new child
//
+ // function appendButton($value, $onclick = null)
+ // appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
+ // returns the new child
+ //
// function appendTextArea($name, $columns, $rows, [$id], [$value])
// appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
// returns the new child
// appends a DOMDocument::createTextNode() as a child of this document (see there for params)
// returns the new child
//
+ // function appendComment($comment_data)
+ // appends a DOMDocument::createComment() as a child of this document (see there for params)
+ // returns the new child
+ //
// function appendHTMLMarkup($htmldata, [$parentNode])
// appends a representation of the HTML data as children of the given parent node, by default this document
// NO return value!
// function createElementLink($target, [$value])
// returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
//
+ // function createElementImage($src, [$alt_text])
+ // returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
+ //
// function createElementForm($action, $method, $name)
// returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
// with the given action, method, and name
// returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
// and optionally id and value
//
+ // function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
+ // returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
+ // and optionally id and value
+ //
+ // function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
+ // returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
+ // and optionally id and value
+ //
// function createElementInputRadio($name, $id, $value, $checked)
// returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
// checked state
// returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
// checked state
//
+ // function createElementInputFile($name, $id, $accept)
+ // returns an ExtendedElement that is an HTML <input> of type 'file' with the given name, id and accept
+ //
// function createElementInputSubmit($value)
- // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given name and value
+ // returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
+ //
+ // function createElementButton($value, $onclick = null)
+ // returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
//
// function createElementTextArea($name, $columns, $rows, [$id], [$value])
// returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
$this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
}
+ static function initHTML5() {
+ $doc = new ExtendedDocument();
+ $doc->loadHTML('<!DOCTYPE html><html></html>'); // this seems to be the only way to get the DOCTYPE set properly.
+
+ // Created basic HTML document structure.
+ $root = $doc->getElementsByTagName('html')->item(0);
+ $head = $root->appendElement('head');
+ $title = $head->appendElement('title');
+ $body = $root->appendElement('body');
+
+ return array('document' => $doc,
+ 'html' => $root,
+ 'head' => $head,
+ 'title' => $title,
+ 'body' => $body);
+ }
+
function appendElement($name, $value = '') {
return $this->appendChild($this->createElement($name, $value));
}
function appendImage($src, $alt_text = '') {
return $this->appendChild($this->createElementImage($src, $alt_text));
}
- function appendFormDiv($action, $method, $name) {
- $formelem = $this->appendChild($this->createElementForm($action, $method, $name));
+ function appendForm($action, $method, $name, $id = null) {
+ return $this->appendChild($this->createElementForm($action, $method, $name, $id));
+ }
+ function appendFormDiv($action, $method, $name, $id = null) {
+ $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
return $formelem->appendElement('div');
}
function appendInputHidden($name, $value) {
function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
}
+ function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
+ return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
+ }
+ function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
+ return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
+ }
function appendInputRadio($name, $id, $value, $checked) {
return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
}
function appendInputCheckbox($name, $id, $value, $checked) {
return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
}
+ function appendInputFile($name, $id, $accept) {
+ return $this->appendChild($this->createElementInputFile($name, $id, $accept));
+ }
function appendInputSubmit($value) {
return $this->appendChild($this->createElementInputSubmit($value));
}
+ function appendButton($value, $onclick = null) {
+ return $this->appendChild($this->createElementButton($value, $onclick));
+ }
function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
}
function appendText($text) {
return $this->appendChild($this->createTextNode($text));
}
+ function appendComment($comment_data) {
+ return $this->appendChild($this->createComment($comment_data));
+ }
function appendJSElement($jsdata) {
$this->appendChild($this->createElementJS($jsdata));
}
}
}
+ function createElement($name, $value = '') {
+ // Adding the $value in DOMDocument's createElement does NOT escape it, so override it and use appendText to support that.
+ $aelem = parent::createElement($name);
+ $aelem->appendText($value);
+ return $aelem;
+ }
+
function createElementLink($target, $value = '') {
$link = $this->createElement('a', $value);
$link->setAttribute('href', $target); // XXX: take care of & etc. in links
}
function createElementImage($src, $alt_text = '') {
- $link = $this->createElement('img');
- $link->setAttribute('src', $src);
- $link->setAttribute('alt', $alt_text);
- return $link;
+ $img = $this->createElement('img');
+ $img->setAttribute('src', $src);
+ $img->setAttribute('alt', $alt_text);
+ return $img;
}
- function createElementForm($action, $method, $name) {
+ function createElementForm($action, $method, $name, $id = null) {
$formelem = $this->createElement('form');
$formelem->setAttribute('action', $action);
$formelem->setAttribute('method', $method);
$formelem->setAttribute('name', $name);
+ $formelem->setAttribute('id', $id);
return $formelem;
}
return $txfield;
}
+ function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
+ $txfield = $this->createElement('input');
+ $txfield->setAttribute('type', 'number');
+ if (!is_null($id)) { $txfield->setAttribute('id', $id); }
+ $txfield->setAttribute('name', $name);
+ $txfield->setAttribute('maxlength', $maxlength);
+ $txfield->setAttribute('size', $size);
+ if (!is_null($value)) { $txfield->setAttribute('value', $value); }
+ return $txfield;
+ }
+
+ function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
+ $pwfield = $this->createElement('input');
+ $pwfield->setAttribute('type', 'password');
+ if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
+ $pwfield->setAttribute('name', $name);
+ $pwfield->setAttribute('maxlength', $maxlength);
+ $pwfield->setAttribute('size', $size);
+ if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
+ return $pwfield;
+ }
+
function createElementInputRadio($name, $id, $value, $checked) {
$radio = $this->createElement('input');
$radio->setAttribute('type', 'radio');
$radio->setAttribute('name', $name);
- $radio->setAttribute('id', $id);
+ if (!is_null($id)) { $radio->setAttribute('id', $id); }
$radio->setAttribute('value', $value);
if ($checked) { $radio->setAttribute('checked', ''); }
return $radio;
$cbox = $this->createElement('input');
$cbox->setAttribute('type', 'checkbox');
$cbox->setAttribute('name', $name);
- $cbox->setAttribute('id', $id);
+ if (!is_null($id)) { $cbox->setAttribute('id', $id); }
$cbox->setAttribute('value', $value);
if ($checked) { $cbox->setAttribute('checked', ''); }
return $cbox;
}
+ function createElementInputFile($name, $id, $accept) {
+ $fileinput = $this->createElement('input');
+ $fileinput->setAttribute('type', 'file');
+ $fileinput->setAttribute('name', $name);
+ if (!is_null($id)) { $fileinput->setAttribute('id', $id); }
+ $fileinput->setAttribute('accept', $accept);
+ return $fileinput;
+ }
+
function createElementInputSubmit($value) {
$submitbtn = $this->createElement('input');
$submitbtn->setAttribute('type', 'submit');
return $submitbtn;
}
+ function createElementButton($value, $onclick = null) {
+ $btn = $this->createElement('input');
+ $btn->setAttribute('type', 'button');
+ $btn->setAttribute('value', $value);
+ if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
+ return $btn;
+ }
+
function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
$txtarea = $this->createElement('textarea', $value);
$txtarea->setAttribute('name', $name);
// appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
// returns the new child
//
- // function appendFormDiv($action, $method, $name)
+ // function appendImage($src, [$alt_text])
+ // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
+ // returns the new child
+ //
+ // function appendForm($action, $method, $name, [$id])
+ // appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
+ // returns the new child
+ //
+ // function appendFormDiv($action, $method, $name, [$id])
// appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
// returns an HTML <div> that is a child of the new child
//
// appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
// returns the new child
//
+ // function appendInputNumber($name, $maxlength, $size, [$id], [$value])
+ // appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
+ // returns the new child
+ //
+ // function appendInputPassword($name, $maxlength, $size, [$id], [$value])
+ // appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
+ // returns the new child
+ //
// function appendInputRadio($name, $id, $value, $checked)
// appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
// returns the new child
// appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
// returns the new child
//
+ // function appendInputFile($name, $id, $accept)
+ // appends an ExtendedDocument::createElementInputFile() as a child of this element (see there for params)
+ // returns the new child
+ //
// function appendInputSubmit($value)
// appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
// returns the new child
//
+ // function appendButton($value, $onclick = null)
+ // appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
+ // returns the new child
+ //
// function appendTextArea($name, $columns, $rows, [$id], [$value])
// appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
// returns the new child
// appends a DOMDocument::createTextNode() as a child of this element (see there for params)
// returns the new child
//
+ // function appendComment($comment_data)
+ // appends a DOMDocument::createComment() as a child of this element (see there for params)
+ // returns the new child
+ //
// function appendHTMLMarkup($htmldata)
// appends a representation of the HTML data as children of this element
// NO return value!
function appendLink($target, $value = '') {
return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
}
- function appendFormDiv($action, $method, $name) {
- $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name));
+ function appendImage($src, $alt_text = '') {
+ return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
+ }
+ function appendForm($action, $method, $name, $id = null) {
+ return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
+ }
+ function appendFormDiv($action, $method, $name, $id = null) {
+ $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
return $formelem->appendElement('div');
}
function appendInputHidden($name, $value) {
function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
}
+ function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
+ return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
+ }
+ function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
+ return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
+ }
function appendInputRadio($name, $id, $value, $checked) {
return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
}
function appendInputCheckbox($name, $id, $value, $checked) {
return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
}
+ function appendInputFile($name, $id, $accept) {
+ return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
+ }
function appendInputSubmit($value) {
return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
}
+ function appendButton($value, $onclick = null) {
+ return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
+ }
function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
}
function appendText($text) {
return $this->appendChild($this->ownerDocument->createTextNode($text));
}
+ function appendComment($comment_data) {
+ return $this->appendChild($this->ownerDocument->createComment($comment_data));
+ }
function appendHTMLMarkup($htmldata) {
$this->ownerDocument->appendHTMLMarkup($htmldata, $this);
}
// appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
// returns the new child
//
- // function appendFormDiv($action, $method, $name)
+ // function appendImage($src, [$alt_text])
+ // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
+ // returns the new child
+ //
+ // function appendForm($action, $method, $name, [$id])
+ // appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
+ // returns the new child
+ //
+ // function appendFormDiv($action, $method, $name, [$id])
// appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
// returns an HTML <div> that is a child of the new child
//
// appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
// returns the new child
//
+ // function appendInputNumber($name, $maxlength, $size, [$id], [$value])
+ // appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
+ // returns the new child
+ //
+ // function appendInputPassword($name, $maxlength, $size, [$id], [$value])
+ // appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
+ // returns the new child
+ //
// function appendInputRadio($name, $id, $value, $checked)
// appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
// returns the new child
// appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
// returns the new child
//
+ // function appendInputFile($name, $id, $accept)
+ // appends an ExtendedDocument::createElementInputFile() as a child of this fragment (see there for params)
+ // returns the new child
+ //
// function appendInputSubmit($value)
// appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
// returns the new child
//
+ // function appendButton($value, $onclick = null)
+ // appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
+ // returns the new child
+ //
// function appendTextArea($name, $columns, $rows, [$id], [$value])
// appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
// returns the new child
// appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
// returns the new child
//
+ // function appendComment($comment_data)
+ // appends a DOMDocument::createComment() as a child of this fragment (see there for params)
+ // returns the new child
+ //
// function appendHTMLMarkup($htmldata)
// appends a representation of the HTML data as children of this fragment
// NO return value!
function appendLink($target, $value = '') {
return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
}
- function appendFormDiv($action, $method, $name) {
- $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name));
+ function appendImage($src, $alt_text = '') {
+ return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
+ }
+ function appendForm($action, $method, $name, $id = null) {
+ return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
+ }
+ function appendFormDiv($action, $method, $name, $id = null) {
+ $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
return $formelem->appendElement('div');
}
function appendInputHidden($name, $value) {
function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
}
+ function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
+ return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
+ }
+ function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
+ return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
+ }
function appendInputRadio($name, $id, $value, $checked) {
return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
}
function appendInputCheckbox($name, $id, $value, $checked) {
return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
}
+ function appendInputFile($name, $id, $accept) {
+ return $this->appendChild($this->ownerDocument->createElementInputFile($name, $id, $accept));
+ }
function appendInputSubmit($value) {
return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
}
+ function appendButton($value, $onclick = null) {
+ return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
+ }
function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
}
function appendText($text) {
return $this->appendChild($this->ownerDocument->createTextNode($text));
}
+ function appendComment($comment_data) {
+ return $this->appendChild($this->ownerDocument->createComment($comment_data));
+ }
function appendHTMLMarkup($htmldata) {
$this->ownerDocument->appendHTMLMarkup($htmldata, $this);
}