X-Git-Url: https://git-public.kairo.at/?a=blobdiff_plain;ds=sidebyside;f=include%2Fcbsm%2Futil%2Fdocument.php-class;h=b708d1cb3a32c779575016b40beb70d0f2587c18;hb=14014b8f766b1c6af7c67eb2b902144510d25e69;hp=1563e9fa13d1c08996f87057da9992e7570f175b;hpb=b8d168371c98b48193b8c61f8521618038feac1e;p=php-utility-classes.git
diff --git a/include/cbsm/util/document.php-class b/include/cbsm/util/document.php-class
index 1563e9f..b708d1c 100755
--- a/include/cbsm/util/document.php-class
+++ b/include/cbsm/util/document.php-class
@@ -27,11 +27,9 @@ class ExtendedDocument extends DOMDocument {
// 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)
@@ -66,6 +64,10 @@ class ExtendedDocument extends DOMDocument {
// 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
@@ -78,6 +80,10 @@ class ExtendedDocument extends DOMDocument {
// 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
@@ -143,6 +149,10 @@ class ExtendedDocument extends DOMDocument {
// returns an ExtendedElement that is an HTML 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 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 of type 'password' with the given name, maxlength, size,
// and optionally id and value
@@ -155,6 +165,9 @@ class ExtendedDocument extends DOMDocument {
// returns an ExtendedElement that is an HTML of type 'checkbox' with the given name, id, value and
// checked state
//
+ // function createElementInputFile($name, $id, $accept)
+ // returns an ExtendedElement that is an HTML of type 'file' with the given name, id and accept
+ //
// function createElementInputSubmit($value)
// returns an ExtendedElement that is an HTML of type 'submit' with the given value as label
//
@@ -190,11 +203,25 @@ class ExtendedDocument extends DOMDocument {
$this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
}
+ static function initHTML5() {
+ $doc = new ExtendedDocument();
+ $doc->loadHTML(''); // 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 = '') {
- // Adding the $value in createElement does NOT escape it, so use appendText to support that.
- $aelem = $this->appendChild($this->createElement($name));
- $aelem->appendText($value);
- return $aelem;
+ return $this->appendChild($this->createElement($name, $value));
}
function appendElementXML($name, $xmldata) {
$aelem = $this->appendChild($this->createElement($name));
@@ -221,6 +248,9 @@ class ExtendedDocument extends DOMDocument {
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));
}
@@ -230,6 +260,9 @@ class ExtendedDocument extends DOMDocument {
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));
}
@@ -279,9 +312,15 @@ class ExtendedDocument extends DOMDocument {
}
}
+ 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');
- $link->appendText($value);
+ $link = $this->createElement('a', $value);
$link->setAttribute('href', $target); // XXX: take care of & etc. in links
return $link;
}
@@ -321,6 +360,17 @@ class ExtendedDocument extends DOMDocument {
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');
@@ -336,7 +386,7 @@ class ExtendedDocument extends DOMDocument {
$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;
@@ -346,12 +396,21 @@ class ExtendedDocument extends DOMDocument {
$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');
@@ -454,6 +513,10 @@ class ExtendedElement extends DOMElement {
// 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
@@ -466,6 +529,10 @@ class ExtendedElement extends DOMElement {
// 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
@@ -515,10 +582,7 @@ class ExtendedElement extends DOMElement {
// returns the new child
function appendElement($name, $value = '') {
- // Adding the $value in createElement does NOT escape it, so use appendText to support that.
- $aelem = $this->appendChild($this->ownerDocument->createElement($name));
- $aelem->appendText($value);
- return $aelem;
+ return $this->appendChild($this->ownerDocument->createElement($name, $value));
}
function appendElementXML($name, $xmldata) {
$aelem = $this->appendChild($this->ownerDocument->createElement($name));
@@ -544,6 +608,9 @@ class ExtendedElement extends DOMElement {
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));
}
@@ -553,6 +620,9 @@ class ExtendedElement extends DOMElement {
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));
}
@@ -628,6 +698,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
// 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
@@ -640,6 +714,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
// 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
@@ -689,10 +767,7 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
// returns the new child
function appendElement($name, $value = '') {
- // Adding the $value in createElement does NOT escape it, so use appendText to support that.
- $aelem = $this->appendChild($this->ownerDocument->createElement($name));
- $aelem->appendText($value);
- return $aelem;
+ return $this->appendChild($this->ownerDocument->createElement($name, $value));
}
function appendElementXML($name, $xmldata) {
$aelem = $this->appendChild($this->ownerDocument->createElement($name));
@@ -718,6 +793,9 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
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));
}
@@ -727,6 +805,9 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
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));
}