From 7edd708f85562943539ec927775c1b083f079b2d Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Mon, 27 Jun 2016 18:48:48 +0200 Subject: [PATCH 01/16] only cache the last_update value for 10 seconds, so that we can reasonably use this function to wait for updates but still don't flodd the commandline with requests --- include/classes/rrdstat.php-class | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/classes/rrdstat.php-class b/include/classes/rrdstat.php-class index aa7079d..ce334e0 100644 --- a/include/classes/rrdstat.php-class +++ b/include/classes/rrdstat.php-class @@ -476,11 +476,13 @@ class rrdstat { public function last_update() { // fetch time of last update in this RRD file - static $last_update; + static $last_update, $last_saved; + if (isset($last_update) && isset($last_saved) && ($last_saved <= (time() - 10))) { unset($last_update); } if (!isset($last_update) && in_array($this->status, array('ok','readonly'))) { $last_cmd = $this->rrdtool_bin.' last '.$this->rrd_file; $return = trim(`$last_cmd 2>&1`); $last_update = is_numeric($return)?$return:null; + $last_saved = time(); } return isset($last_update)?$last_update:null; } -- 2.43.0 From ad01f23ccef99cf2fa5712ed55d7fb94447c9004 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Thu, 15 Sep 2016 20:50:17 +0200 Subject: [PATCH 02/16] ignore some warnings --- include/classes/rrdstat.php-class | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/classes/rrdstat.php-class b/include/classes/rrdstat.php-class index ce334e0..1443ec6 100644 --- a/include/classes/rrdstat.php-class +++ b/include/classes/rrdstat.php-class @@ -974,7 +974,7 @@ class rrdstat { else { $sURL_add = '&sub=%s'; } $default_num_cols = $GLOBALS['ua']->isMobile()?1:2; - $num_cols = is_numeric($pconf['num_rows'])?$pconf['num_rows']:$default_num_cols; + $num_cols = is_numeric(@$pconf['num_rows'])?$pconf['num_rows']:$default_num_cols; $num_rows = ceil(count($stats)/$num_cols); $out .= ''."\n"; @@ -1205,7 +1205,7 @@ class rrdstat { foreach ($snames as $iname) { $newstat = array('name'=>$iname); $sfiles[] = isset($this->config_all[$iname]['file'])?$this->config_all[$iname]['file']:$iname.'.rrd'; - if (is_array($this->config_all[$iname])) { + if (is_array(@$this->config_all[$iname])) { foreach ($this->config_all[$iname] as $key=>$val) { if (substr($key, 0, 5) == 'page.') { $newstat['sub'][] = substr($key, 5); } } -- 2.43.0 From 6e698a41c5017150623531a9f2d6ec3baceda9c2 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 25 Sep 2016 18:48:58 +0200 Subject: [PATCH 03/16] adding a value in createElement doesn't care for escaping but createTextNode does, so actually use appendText in appendElement --- include/cbsm/util/document.php-class | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/include/cbsm/util/document.php-class b/include/cbsm/util/document.php-class index fa269ca..6a36dfc 100755 --- a/include/cbsm/util/document.php-class +++ b/include/cbsm/util/document.php-class @@ -187,7 +187,10 @@ class ExtendedDocument extends DOMDocument { } function appendElement($name, $value = '') { - return $this->appendChild($this->createElement($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; } function appendElementXML($name, $xmldata) { $aelem = $this->appendChild($this->createElement($name)); @@ -270,7 +273,8 @@ class ExtendedDocument extends DOMDocument { } function createElementLink($target, $value = '') { - $link = $this->createElement('a', $value); + $link = $this->createElement('a'); + $link->appendText($value); $link->setAttribute('href', $target); // XXX: take care of & etc. in links return $link; } @@ -499,7 +503,10 @@ class ExtendedElement extends DOMElement { // returns the new child function appendElement($name, $value = '') { - return $this->appendChild($this->ownerDocument->createElement($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; } function appendElementXML($name, $xmldata) { $aelem = $this->appendChild($this->ownerDocument->createElement($name)); @@ -663,7 +670,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment { // returns the new child function appendElement($name, $value = '') { - return $this->appendChild($this->ownerDocument->createElement($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; } function appendElementXML($name, $xmldata) { $aelem = $this->appendChild($this->ownerDocument->createElement($name)); -- 2.43.0 From b8d168371c98b48193b8c61f8521618038feac1e Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Mon, 26 Sep 2016 19:29:43 +0200 Subject: [PATCH 04/16] add a function for adding a form without
(which is fine in HTML5), and add a way to add an ID to either variant of the form addition --- include/cbsm/util/document.php-class | 42 +++++++++++++++++++++------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/include/cbsm/util/document.php-class b/include/cbsm/util/document.php-class index 6a36dfc..1563e9f 100755 --- a/include/cbsm/util/document.php-class +++ b/include/cbsm/util/document.php-class @@ -50,7 +50,11 @@ class ExtendedDocument extends DOMDocument { // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params) // returns the new child // - // function appendFormDiv($action, $method, $name) + // 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
that is a child of the new child // @@ -204,8 +208,11 @@ class ExtendedDocument extends DOMDocument { 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) { @@ -286,11 +293,12 @@ class ExtendedDocument extends DOMDocument { 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; } @@ -430,7 +438,11 @@ class ExtendedElement extends DOMElement { // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params) // returns the new child // - // function appendFormDiv($action, $method, $name) + // 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
that is a child of the new child // @@ -519,8 +531,11 @@ class ExtendedElement extends DOMElement { function appendImage($src, $alt_text = '') { return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text)); } - function appendFormDiv($action, $method, $name) { - $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name)); + 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) { @@ -597,7 +612,11 @@ class ExtendedDocumentFragment extends DOMDocumentFragment { // appends an ExtendedDocument::createElementImage() as a child of this document (see there for params) // returns the new child // - // function appendFormDiv($action, $method, $name) + // 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
that is a child of the new child // @@ -686,8 +705,11 @@ class ExtendedDocumentFragment extends DOMDocumentFragment { function appendImage($src, $alt_text = '') { return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text)); } - function appendFormDiv($action, $method, $name) { - $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name)); + 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) { -- 2.43.0 From 262e0bbb3441a51237f0330fa5ed7e53e70baf0e Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Fri, 30 Sep 2016 00:46:24 +0200 Subject: [PATCH 05/16] add support for number inputs to ExtendedDocument --- include/cbsm/util/document.php-class | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/cbsm/util/document.php-class b/include/cbsm/util/document.php-class index 1563e9f..c64d9a4 100755 --- a/include/cbsm/util/document.php-class +++ b/include/cbsm/util/document.php-class @@ -66,6 +66,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 @@ -143,6 +147,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 @@ -221,6 +229,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)); } @@ -321,6 +332,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'); @@ -454,6 +476,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 @@ -544,6 +570,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)); } @@ -628,6 +657,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 @@ -718,6 +751,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)); } -- 2.43.0 From a8816f4353d72c047dd754a9c4952e9a7c7ae99d Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 2 Oct 2016 01:07:25 +0200 Subject: [PATCH 06/16] actually override createElement to support the escaping --- include/cbsm/util/document.php-class | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/include/cbsm/util/document.php-class b/include/cbsm/util/document.php-class index c64d9a4..d023c99 100755 --- a/include/cbsm/util/document.php-class +++ b/include/cbsm/util/document.php-class @@ -199,10 +199,7 @@ class ExtendedDocument extends DOMDocument { } 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)); @@ -290,9 +287,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; } @@ -541,10 +544,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)); @@ -722,10 +722,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)); -- 2.43.0 From 4bb9d784670b699918e82a2cf21d36835c6db9ee Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Fri, 7 Oct 2016 00:21:08 +0200 Subject: [PATCH 07/16] add support for file input --- include/cbsm/util/document.php-class | 37 ++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/include/cbsm/util/document.php-class b/include/cbsm/util/document.php-class index d023c99..c267623 100755 --- a/include/cbsm/util/document.php-class +++ b/include/cbsm/util/document.php-class @@ -82,6 +82,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 @@ -163,6 +167,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 // @@ -238,6 +245,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)); } @@ -361,7 +371,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; @@ -371,12 +381,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'); @@ -495,6 +514,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 @@ -582,6 +605,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)); } @@ -673,6 +699,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 @@ -760,6 +790,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)); } -- 2.43.0 From 14014b8f766b1c6af7c67eb2b902144510d25e69 Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 23 Oct 2016 20:22:48 +0200 Subject: [PATCH 08/16] add a static function that will initialize a new document as a basic HTML5 template --- include/cbsm/util/document.php-class | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/include/cbsm/util/document.php-class b/include/cbsm/util/document.php-class index c267623..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) @@ -205,6 +203,23 @@ 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 = '') { return $this->appendChild($this->createElement($name, $value)); } -- 2.43.0 From 61cc8aa9e32b806030754bd5988ca7ae0033ee8a Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Sun, 23 Oct 2016 20:25:36 +0200 Subject: [PATCH 09/16] explicitly mark functions as public --- include/cbsm/util/document.php-class | 374 +++++++++++++-------------- 1 file changed, 187 insertions(+), 187 deletions(-) diff --git a/include/cbsm/util/document.php-class b/include/cbsm/util/document.php-class index b708d1c..475f2c4 100755 --- a/include/cbsm/util/document.php-class +++ b/include/cbsm/util/document.php-class @@ -31,168 +31,168 @@ class ExtendedDocument extends DOMDocument { // 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]) + // public function appendElement($name, [$value]) // appends a DOMDocument::createElement() as a child of this document (see there for params) // returns the new child // - // function appendElementXML($name, $xmldata) + // public function appendElementXML($name, $xmldata) // appends a DOMDocument::createElement() with the given name as a child of this document, // with an ExtendedDocument::createXMLFragment() of the given XML data inside // returns the new child // - // function appendLink($target, [$value]) + // public function appendLink($target, [$value]) // appends an ExtendedDocument::createElementLink() as a child of this document (see there for params) // returns the new child // - // function appendImage($src, [$alt_text]) + // public 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]) + // public 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]) + // public function appendFormDiv($action, $method, $name, [$id]) // appends an ExtendedDocument::createElementForm() as a child of this document (see there for params) // returns an HTML
that is a child of the new child // - // function appendInputHidden($name, $value) + // public function appendInputHidden($name, $value) // appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params) // returns the new child // - // function appendInputText($name, $maxlength, $size, [$id], [$value]) + // public function appendInputText($name, $maxlength, $size, [$id], [$value]) // 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]) + // public 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]) + // public 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) + // public function appendInputRadio($name, $id, $value, $checked) // appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params) // returns the new child // - // function appendInputCheckbox($name, $id, $value, $checked) + // public function appendInputCheckbox($name, $id, $value, $checked) // appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params) // returns the new child // - // function appendInputFile($name, $id, $accept) + // public 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) + // public 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) + // public 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]) + // public 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 // - // function appendElementSelect($name, [$id], [$options], [$default]) + // public function appendElementSelect($name, [$id], [$options], [$default]) // appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params) // returns the new child // - // function appendElementOption($key, $desc, [$selected]) + // public function appendElementOption($key, $desc, [$selected]) // appends an ExtendedDocument::createElementOption() as a child of this document (see there for params) // returns the new child // - // function appendLabel($for_id, $value) + // public function appendLabel($for_id, $value) // appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params) // returns the new child // - // function appendText($text) + // public function appendText($text) // appends a DOMDocument::createTextNode() as a child of this document (see there for params) // returns the new child // - // function appendComment($comment_data) + // public 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]) + // public 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 appendXMLMarkup($xmldata, [$parentNode]) + // public function appendXMLMarkup($xmldata, [$parentNode]) // appends a representation of the XML data as children of the given parent node, by default this document // NO return value! // - // function appendJSElement($jsdata) + // public function appendJSElement($jsdata) // appends an ExtendedDocument::createElementJS() as a child of this document (see there for params) // NO return value! // - // function appendCOMElement($module, $attributes) + // public function appendCOMElement($module, $attributes) // appends an ExtendedDocument::createCOMElement() as a child of this document (see there for params) // returns the new child // - // function createElementLink($target, [$value]) + // public function createElementLink($target, [$value]) // returns an ExtendedElement that is an HTML with the given target (href) and (optional) value // - // function createElementImage($src, [$alt_text]) + // public function createElementImage($src, [$alt_text]) // returns an ExtendedElement that is an HTML with the given (src) and alt attributes (set to '' by default) // - // function createElementForm($action, $method, $name) + // public function createElementForm($action, $method, $name) // returns an ExtendedElement that is an HTML
that is a child of an HTML
// with the given action, method, and name // - // function createElementInputHidden($name, $value) + // public function createElementInputHidden($name, $value) // returns an ExtendedElement that is an HTML of type 'hidden' with the given name and value // - // function createElementInputText($name, $maxlength, $size, [$id], [$value]) + // public function createElementInputText($name, $maxlength, $size, [$id], [$value]) // 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]) + // public 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]) + // public 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 // - // function createElementInputRadio($name, $id, $value, $checked) + // public function createElementInputRadio($name, $id, $value, $checked) // returns an ExtendedElement that is an HTML of type 'radio' with the given name, id, value and // checked state // - // function createElementInputCheckbox($name, $id, $value, $checked) + // public function createElementInputCheckbox($name, $id, $value, $checked) // returns an ExtendedElement that is an HTML of type 'checkbox' with the given name, id, value and // checked state // - // function createElementInputFile($name, $id, $accept) + // public 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) + // public function createElementInputSubmit($value) // returns an ExtendedElement that is an HTML of type 'submit' with the given value as label // - // function createElementButton($value, $onclick = null) + // public 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]) + // public function createElementTextArea($name, $columns, $rows, [$id], [$value]) // returns an ExtendedElement that is an HTML