X-Git-Url: https://git-public.kairo.at/?p=php-utility-classes.git;a=blobdiff_plain;f=classes%2Fdocument.php-class;h=c2f0fcfe0d9107d7baf897774dd79bda2d2f44f7;hp=4490589210b157a29f6442c8ff8a1ce0c386d281;hb=HEAD;hpb=c79be4c2c1230110175194a8aee78a5eb20d6af0 diff --git a/classes/document.php-class b/classes/document.php-class index 4490589..c2f0fcf 100755 --- a/classes/document.php-class +++ b/classes/document.php-class @@ -65,6 +65,10 @@ class ExtendedDocument extends DOMDocument { // appends an ExtendedDocument::createElementInputRange() as a child of this document (see there for params) // returns the new child // + // public function appendInputSearch($name, $maxlength, $size, [$id], [$value]) + // appends an ExtendedDocument::createElementInputSearch() as a child of this document (see there for params) + // returns the new child + // // public function appendInputUrl($name, $maxlength, $size, [$id], [$value]) // appends an ExtendedDocument::createElementInputUrl() as a child of this document (see there for params) // returns the new child @@ -202,6 +206,10 @@ class ExtendedDocument extends DOMDocument { // returns an ExtendedElement that is an HTML of type 'url' with the given name, maxlength, size, // and optionally id and value // + // public function createElementInputSearch($name, $maxlength, $size, [$id], [$value]) + // returns an ExtendedElement that is an HTML of type 'search' with the given name, maxlength, size, + // and optionally id and value + // // public function createElementInputEmail($name, $maxlength, $size, [$id], [$value]) // returns an ExtendedElement that is an HTML of type 'email' with the given name, maxlength, size, // and optionally id and value @@ -276,7 +284,7 @@ class ExtendedDocument extends DOMDocument { static function initHTML5($doc = null) { if (is_null($doc)) { $doc = new ExtendedDocument(); } - $doc->loadHTML5(''); // this seems to be the only way to get the DOCTYPE set properly. + $doc->loadHTML5(''."\n".''."\n".''); // this seems to be the only way to get the DOCTYPE set properly. // Created basic HTML document structure. $root = $doc->getElementsByTagName('html')->item(0); @@ -294,11 +302,18 @@ class ExtendedDocument extends DOMDocument { public function loadHTML5($source) { // Do our own handling of DOMDocument error reporting so we can ignore "unknown tags" which are usually fine in HTML5. libxml_use_internal_errors(true); - if (!preg_match('/^\s*'."\n".$source; } $result = $this->loadHTML($source); + // Set encoding directly a,d remove any processing node that isn't the first node + $this->encoding = 'utf-8'; + foreach ($this->childNodes as $i => $child) { + if ($i && $child->nodeType == XML_PI_NODE) { + $this->removeChild($child); + } + } // Handle DOMDocument loading errors, throw away warnings on unknown tags as HTML5 allows all kinds. $errseverity = array(LIBXML_ERR_WARNING => 'Warning', LIBXML_ERR_ERROR => 'Error', LIBXML_ERR_FATAL => 'Fatal'); foreach (libxml_get_errors() as $error) { @@ -350,6 +365,9 @@ class ExtendedDocument extends DOMDocument { public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) { return $this->appendChild($this->createElementInputRange($name, $id, $min, $max, $step, $value)); } + public function appendInputSearch($name, $maxlength, $size, $id = null, $value = null) { + return $this->appendChild($this->createElementInputSearch($name, $maxlength, $size, $id, $value)); + } public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) { return $this->appendChild($this->createElementInputUrl($name, $maxlength, $size, $id, $value)); } @@ -428,7 +446,7 @@ class ExtendedDocument extends DOMDocument { // Use loadHTML5() to parse and turn the markup into proper HTML. $tmpdoc = new ExtendedDocument; // The XML line is needed to tell the parser that we need UTF-8 parsing. - $tmpdoc->loadHTML5(''.$htmldata.''); + $tmpdoc->loadHTML5(''."\n".''."\n".''.$htmldata.''); foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) { $parentNode->appendChild($this->importNode($child, true)); } @@ -529,6 +547,17 @@ class ExtendedDocument extends DOMDocument { return $rgfield; } + public function createElementInputSearch($name, $maxlength, $size, $id = null, $value = null) { + $urlfield = $this->createElement('input'); + $urlfield->setAttribute('type', 'search'); + if (!is_null($id)) { $urlfield->setAttribute('id', $id); } + $urlfield->setAttribute('name', $name); + $urlfield->setAttribute('maxlength', $maxlength); + $urlfield->setAttribute('size', $size); + if (!is_null($value)) { $urlfield->setAttribute('value', $value); } + return $urlfield; + } + public function createElementInputUrl($name, $maxlength, $size, $id = null, $value = null) { $urlfield = $this->createElement('input'); $urlfield->setAttribute('type', 'url'); @@ -658,10 +687,12 @@ class ExtendedDocument extends DOMDocument { public function createElementOption($key, $desc, $selected = false) { $option = $this->createElement('option', $desc); - if ($key) { + if (is_numeric($key) || is_string($key)) { $option->setAttribute('value', $key); } - if ($selected) { $option->setAttribute('selected', ''); } + if ($selected) { + $option->setAttribute('selected', ''); + } return $option; } @@ -760,6 +791,10 @@ class ExtendedElement extends DOMElement { // appends an ExtendedDocument::createElementInputRange() as a child of this element (see there for params) // returns the new child // + // public function appendInputSearch($name, $maxlength, $size, [$id], [$value]) + // appends an ExtendedDocument::createElementInputSearch() as a child of this element (see there for params) + // returns the new child + // // public function appendInputUrl($name, $maxlength, $size, [$id], [$value]) // appends an ExtendedDocument::createElementInputUrl() as a child of this element (see there for params) // returns the new child @@ -910,6 +945,9 @@ class ExtendedElement extends DOMElement { public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) { return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value)); } + public function appendInputSearch($name, $maxlength, $size, $id = null, $value = null) { + return $this->appendChild($this->ownerDocument->createElementInputSearch($name, $maxlength, $size, $id, $value)); + } public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) { return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value)); } @@ -1052,6 +1090,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment { // appends an ExtendedDocument::createElementInputRange() as a child of this fragment (see there for params) // returns the new child // + // public function appendInputSearch($name, $maxlength, $size, [$id], [$value]) + // appends an ExtendedDocument::createElementInputSearch() as a child of this fragment (see there for params) + // returns the new child + // // public function appendInputUrl($name, $maxlength, $size, [$id], [$value]) // appends an ExtendedDocument::createElementInputUrl() as a child of this fragment (see there for params) // returns the new child @@ -1192,6 +1234,9 @@ class ExtendedDocumentFragment extends DOMDocumentFragment { public function appendInputRange($name, $id, $min, $max, $step = null, $value = null) { return $this->appendChild($this->ownerDocument->createElementInputRange($name, $id, $min, $max, $step, $value)); } + public function appendInputSearch($name, $maxlength, $size, $id = null, $value = null) { + return $this->appendChild($this->ownerDocument->createElementInputSearch($name, $maxlength, $size, $id, $value)); + } public function appendInputUrl($name, $maxlength, $size, $id = null, $value = null) { return $this->appendChild($this->ownerDocument->createElementInputUrl($name, $maxlength, $size, $id, $value)); }