// 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
// appends an ExtendedDocument::createElementInputTime() as a child of this document (see there for params)
// returns the new child
//
+ // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
+ // appends an ExtendedDocument::createElementInputDateTime() as a child of this document (see there for params)
+ // returns the new child
+ //
// public function appendInputColor($name, [$id], [$value])
// appends an ExtendedDocument::createElementInputColor() as a child of this document (see there for params)
// returns the new child
// appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
// returns the new child
//
+ // public function appendElementDatalist([$id], [$options])
+ // appends an ExtendedDocument::createElementDatalist() as a child of this document (see there for params)
+ // returns the new child
+ //
// public function appendText($text)
// appends a DOMDocument::createTextNode() as a child of this document (see there for params)
// returns the new child
// returns an ExtendedElement that is an HTML <img> with the given src and alt attributes (set to '' by default)
//
// public 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 <form> with the given action, method, and name
//
// public function createElementInputHidden($name, $value)
// returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
// returns an ExtendedElement that is an HTML <input> 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 <input> 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 <input> of type 'email' with the given name, maxlength, size,
// and optionally id and value
// returns an ExtendedElement that is an HTML <input> of type 'time' with the given name,
// and optionally id, min, max, and value
//
+ // public function createElementInputDateTime($name, [$id], [$min], [$max], [$value])
+ // returns an ExtendedElement that is an HTML <input> of type 'datetime-local' with the given name,
+ // and optionally id, min, max, and value
+ //
// public function createElementInputColor($name, [$id], [$value])
// returns an ExtendedElement that is an HTML <input> of type 'color' with the given name,
// and optionally id and value
// public function createElementLabel($for_id, $value)
// returns an ExtendedElement that is an HTML <label> with the given 'for' and value
//
+ // public function createElementDatalist([$id], [$options])
+ // returns an ExtendedElement that is an HTML <datalist> with optionally the given id and array of options (key => description)
+ //
// public function createElementStyle($styledata)
// returns an ExtendedElement that is an HTML <style> of CSS type with the style data inside
//
static function initHTML5($doc = null) {
if (is_null($doc)) { $doc = new ExtendedDocument(); }
- $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.
+ $doc->loadHTML5('<?xml version="1.0" encoding="utf-8"?>'."\n".'<!DOCTYPE html>'."\n".'<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);
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*<?xml /', $source)) {
+ if (!preg_match('/^\s*<\?xml /', $source)) {
// Add an XML declaration to force DOMDocument into UTF-8 mode.
$source = '<?xml version="1.0" encoding="utf-8"?>'."\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) {
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));
}
public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
return $this->appendChild($this->createElementInputTime($name, $id, $min, $max, $value));
}
+ public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
+ return $this->appendChild($this->createElementInputDateTime($name, $id, $min, $max, $value));
+ }
public function appendInputColor($name, $id = null, $value = null) {
return $this->appendChild($this->createElementInputColor($name, $id, $value));
}
public function appendLabel($for_id, $value) {
return $this->appendChild($this->createElementLabel($for_id, $value));
}
+ public function appendElementDatalist($id = null, $options = array()) {
+ return $this->appendChild($this->createElementDatalist($id, $options));
+ }
public function appendText($text) {
return $this->appendChild($this->createTextNode($text));
}
// 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('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html><body>'.$htmldata.'</body></html>');
+ $tmpdoc->loadHTML5('<?xml version="1.0" encoding="utf-8"?>'."\n".'<!DOCTYPE html>'."\n".'<html><body>'.$htmldata.'</body></html>');
foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) {
$parentNode->appendChild($this->importNode($child, true));
}
public 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);
- if (strlen($value)) { $aelem->appendText($value); }
+ if (strlen($value ?? '')) { $aelem->appendText($value); }
return $aelem;
}
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');
}
public function createElementInputDate($name, $id = null, $min = null, $max = null, $value = null) {
- $telfield = $this->createElement('input');
- $telfield->setAttribute('type', 'date');
- if (!is_null($id)) { $telfield->setAttribute('id', $id); }
- if (!is_null($min)) { $rgfield->setAttribute('min', $min); }
- if (!is_null($max)) { $rgfield->setAttribute('max', $max); }
- if (!is_null($value)) { $telfield->setAttribute('value', $value); }
- return $telfield;
+ $dtfield = $this->createElement('input');
+ $dtfield->setAttribute('type', 'date');
+ if (!is_null($id)) { $dtfield->setAttribute('id', $id); }
+ $dtfield->setAttribute('name', $name);
+ if (!is_null($min)) { $dtfield->setAttribute('min', $min); }
+ if (!is_null($max)) { $dtfield->setAttribute('max', $max); }
+ if (!is_null($value)) { $dtfield->setAttribute('value', $value); }
+ return $dtfield;
}
public function createElementInputTime($name, $id = null, $min = null, $max = null, $value = null) {
- $telfield = $this->createElement('input');
- $telfield->setAttribute('type', 'time');
- if (!is_null($id)) { $telfield->setAttribute('id', $id); }
- if (!is_null($min)) { $rgfield->setAttribute('min', $min); }
- if (!is_null($max)) { $rgfield->setAttribute('max', $max); }
- if (!is_null($value)) { $telfield->setAttribute('value', $value); }
- return $telfield;
+ $timefield = $this->createElement('input');
+ $timefield->setAttribute('type', 'time');
+ if (!is_null($id)) { $timefield->setAttribute('id', $id); }
+ $timefield->setAttribute('name', $name);
+ if (!is_null($min)) { $timefield->setAttribute('min', $min); }
+ if (!is_null($max)) { $timefield->setAttribute('max', $max); }
+ if (!is_null($value)) { $timefield->setAttribute('value', $value); }
+ return $timefield;
+ }
+
+ public function createElementInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
+ $dtfield = $this->createElement('input');
+ $dtfield->setAttribute('type', 'datetime-local');
+ if (!is_null($id)) { $dtfield->setAttribute('id', $id); }
+ $dtfield->setAttribute('name', $name);
+ if (!is_null($min)) { $dtfield->setAttribute('min', $min); }
+ if (!is_null($max)) { $dtfield->setAttribute('max', $max); }
+ if (!is_null($value)) { $dtfield->setAttribute('value', str_replace(' ', 'T', $value)); }
+ return $dtfield;
}
public function createElementInputColor($name, $id = null, $value = null) {
public function createElementOption($key, $desc, $selected = false) {
$option = $this->createElement('option', $desc);
- $option->setAttribute('value', $key);
- if ($selected) { $option->setAttribute('selected', ''); }
+ if (is_numeric($key) || is_string($key)) {
+ $option->setAttribute('value', $key);
+ }
+ if ($selected) {
+ $option->setAttribute('selected', '');
+ }
return $option;
}
return $label;
}
+ public function createElementDatalist($id = null, $options = array()) {
+ $select = $this->createElement('datalist');
+ if (!is_null($id)) { $select->setAttribute('id', $id); }
+ foreach ($options as $key => $desc) {
+ $select->appendElementOption($key, $desc);
+ }
+ return $select;
+ }
+
public function createElementStyle($styledata) {
$style_elem = $this->createElement('style');
// Note: type can/should be left out for HTML5.
// 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
// appends an ExtendedDocument::createElementInputTime() as a child of this element (see there for params)
// returns the new child
//
+ // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
+ // appends an ExtendedDocument::createElementInputDateTime() as a child of this element (see there for params)
+ // returns the new child
+ //
// public function appendInputColor($name, [$id], [$value])
// appends an ExtendedDocument::createElementInputColor() as a child of this element (see there for params)
//
// appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
// returns the new child
//
+ // public function appendElementDatalist([$id], [$options])
+ // appends an ExtendedDocument::createElementDatalist() as a child of this element (see there for params)
+ // returns the new child
+ //
// public function appendText($text)
// appends a DOMDocument::createTextNode() as a child of this element (see there for params)
// returns the new child
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));
}
public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
}
+ public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
+ return $this->appendChild($this->ownerDocument->createElementInputDateTime($name, $id, $min, $max, $value));
+ }
public function appendInputColor($name, $id = null, $value = null) {
return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
}
public function appendLabel($for_id, $value) {
return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
}
+ public function appendElementDatalist($id = null, $options = array()) {
+ return $this->appendChild($this->ownerDocument->createElementDatalist($id, $options));
+ }
public function appendText($text) {
- return $this->appendChild($this->ownerDocument->createTextNode($text));
+ return $this->appendChild($this->ownerDocument->createTextNode($text ?? ''));
}
public function appendLinebreak() {
return $this->appendChild($this->ownerDocument->createElement('br'));
// 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
// appends an ExtendedDocument::createElementInputTime() as a child of this fragment (see there for params)
// returns the new child
//
+ // public function appendInputDateTime($name, [$id], [$min], [$max], [$value])
+ // appends an ExtendedDocument::createElementInputDateTime() as a child of this fragment (see there for params)
+ // returns the new child
+ //
// public function appendInputColor($name, [$id], [$value])
// appends an ExtendedDocument::createElementInputColor() as a child of this fragment (see there for params)
//
// appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
// returns the new child
//
+ // public function appendElementDatalist([$id], [$options])
+ // appends an ExtendedDocument::createElementDatalist() as a child of this fragment (see there for params)
+ // returns the new child
+ //
// public function appendText($text)
// appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
// returns the new child
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));
}
public function appendInputTime($name, $id = null, $min = null, $max = null, $value = null) {
return $this->appendChild($this->ownerDocument->createElementInputTime($name, $id, $min, $max, $value));
}
+ public function appendInputDateTime($name, $id = null, $min = null, $max = null, $value = null) {
+ return $this->appendChild($this->ownerDocument->createElementInputDateTime($name, $id, $min, $max, $value));
+ }
public function appendInputColor($name, $id = null, $value = null) {
return $this->appendChild($this->ownerDocument->createElementInputColor($name, $id, $value));
}
public function appendLabel($for_id, $value) {
return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
}
+ public function appendElementDatalist($id = null, $options = array()) {
+ return $this->appendChild($this->ownerDocument->createElementDatalist($id, $options));
+ }
public function appendText($text) {
return $this->appendChild($this->ownerDocument->createTextNode($text));
}