make sure that values like '0' are valid in select options master
authorRobert Kaiser <kairo@kairo.at>
Fri, 12 Apr 2024 23:33:47 +0000 (01:33 +0200)
committerRobert Kaiser <kairo@kairo.at>
Fri, 12 Apr 2024 23:33:47 +0000 (01:33 +0200)
classes/document.php-class
classes/email.php-class
classes/rrdstat.php-class
classes/useragent.php-class
tests/ua_list_raw.txt

index 1f820601cf374befb179a3791669d5bd4aaad58d..c2f0fcfe0d9107d7baf897774dd79bda2d2f44f7 100755 (executable)
@@ -16,6 +16,10 @@ class ExtendedDocument extends DOMDocument {
   //     If a $doc is handed over (an ExtendedDocument or a derived class), load the content into that document.
   //     returns an associative array with the following elements: 'html', 'head', 'title', 'body'
   //
+  // public function loadHTML5($source) {
+  //   A version of loadHTML() - see DOMDocument documentation - that is made for loading HTML5 and not emitting warnings/errors for unknown elements.
+  //     returns true on success, false otherwise, just like loadHTML5.
+  //
   // public function appendElement($name, [$value])
   //   appends a DOMDocument::createElement() as a child of this document (see there for params)
   //     returns the new child
@@ -61,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
@@ -121,6 +129,10 @@ class ExtendedDocument extends DOMDocument {
   //   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
@@ -150,9 +162,13 @@ class ExtendedDocument extends DOMDocument {
   //   appends a representation of the XML data as children of the given parent node, by default this document
   //     NO return value!
   //
+  // public function appendStyleElement($styledata)
+  //   appends an ExtendedDocument::createElementStyle() as a child of this document (see there for params)
+  //     returns the new child
+  //
   // public function appendJSElement($jsdata)
   //   appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
-  //     NO return value!
+  //     returns the new child
   //
   // public function appendJSFile($jsURL, [$defer], [$async])
   //   appends an ExtendedDocument::createElementJSFile() as a child of this document (see there for params)
@@ -165,8 +181,7 @@ class ExtendedDocument extends DOMDocument {
   //   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
@@ -191,6 +206,10 @@ class ExtendedDocument extends DOMDocument {
   //   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
@@ -243,6 +262,12 @@ class ExtendedDocument extends DOMDocument {
   // 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
+  //
   // public function createElementJS($jsdata)
   //   returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
   //
@@ -259,7 +284,7 @@ class ExtendedDocument extends DOMDocument {
 
   static function initHTML5($doc = null) {
     if (is_null($doc)) { $doc = new ExtendedDocument(); }
-    $doc->loadHTML('<!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);
@@ -274,6 +299,35 @@ class ExtendedDocument extends DOMDocument {
                  'body' => $body);
   }
 
+  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)) {
+      // 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) {
+      // $error is a libXMLError, see https://www.php.net/manual/en/class.libxmlerror.php
+      // See http://www.xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors for error numbers
+      if ($error->code != 801) { // XML_HTML_UNKNOWN_TAG gets no output, should not exist for HTML5.
+        trigger_error($errseverity[$error->level].' loading HTML5: '.$error->message.' (code '.$error->code.'), line: '.$error->line, E_USER_WARNING);
+      }
+    }
+    libxml_clear_errors();
+    libxml_use_internal_errors(false);
+    return $result;
+  }
+
   public function appendElement($name, $value = '') {
     return $this->appendChild($this->createElement($name, $value));
   }
@@ -311,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));
   }
@@ -356,6 +413,9 @@ class ExtendedDocument extends DOMDocument {
   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));
   }
@@ -371,19 +431,22 @@ class ExtendedDocument extends DOMDocument {
   public function appendClonedElement($dom_element, $deep = true) {
     return $this->appendChild($dom_element->cloneNode($deep));
   }
+  public function appendStyleElement($styledata) {
+    return $this->appendChild($this->createElementStyle($styledata));
+  }
   public function appendJSElement($jsdata) {
     return $this->appendChild($this->createElementJS($jsdata));
   }
-  public function appendJSFile($jsdata, $defer = false, $async = false) {
-    return $this->appendChild($this->createElementJSFile($jsdata, $defer, $async));
+  public function appendJSFile($jsURL, $defer = false, $async = false) {
+    return $this->appendChild($this->createElementJSFile($jsURL, $defer, $async));
   }
 
   public function appendHTMLMarkup($htmldata, $parentNode = null) {
     if (is_null($parentNode)) { $parentNode =& $this; }
-    // Use loadHTML() to parse and turn the markup into proper HTML.
+    // 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->loadHTML('<?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));
     }
@@ -404,7 +467,7 @@ class ExtendedDocument extends DOMDocument {
   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;
   }
 
@@ -484,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');
@@ -518,23 +592,25 @@ class ExtendedDocument extends DOMDocument {
   }
 
   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 createElementInputColor($name, $id = null, $value = null) {
@@ -611,8 +687,12 @@ class ExtendedDocument extends DOMDocument {
 
   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;
   }
 
@@ -622,6 +702,23 @@ class ExtendedDocument extends DOMDocument {
     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.
+    $style_elem->setAttribute('type', 'text/css');
+    $style_elem->appendChild($this->createCDATASection($styledata));
+    return $style_elem;
+  }
+
   public function createElementJS($jsdata) {
     $jselem = $this->createElement('script');
     // Note: type can/should be left out for HTML5.
@@ -694,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
@@ -753,6 +854,10 @@ class ExtendedElement extends DOMElement {
   //   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
@@ -782,6 +887,10 @@ class ExtendedElement extends DOMElement {
   //   appends a representation of the XML data as children of this element
   //     NO return value!
   //
+  // public function appendStyleElement($styledata)
+  //   appends an ExtendedDocument::createElementStyle() as a child of this element (see there for params)
+  //     returns the new child
+  //
   // public function appendJSElement($jsdata)
   //   appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
   //     returns the new child
@@ -836,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));
   }
@@ -881,8 +993,11 @@ class ExtendedElement extends DOMElement {
   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'));
@@ -902,11 +1017,14 @@ class ExtendedElement extends DOMElement {
   public function appendXMLMarkup($xmldata) {
     $this->ownerDocument->appendXMLMarkup($xmldata, $this);
   }
+  public function appendStyleElement($styledata) {
+    return $this->appendChild($this->ownerDocument->createElementStyle($styledata));
+  }
   public function appendJSElement($jsdata) {
     return $this->appendChild($this->ownerDocument->createElementJS($jsdata));
   }
-  public function appendJSFile($jsdata, $defer = false, $async = false) {
-    return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));
+  public function appendJSFile($jsURL, $defer = false, $async = false) {
+    return $this->appendChild($this->ownerDocument->createElementJSFile($jsURL, $defer, $async));
   }
   public function setClass($classname) {
     $this->setAttribute('class', $classname);
@@ -972,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
@@ -1031,6 +1153,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   //   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
@@ -1060,6 +1186,10 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   //   appends a representation of the XML data as children of this fragment
   //     NO return value!
   //
+  // public function appendStyleElement($styledata)
+  //   appends an ExtendedDocument::createElementStyle() as a child of this element (see there for params)
+  //     returns the new child
+  //
   // public function appendJSElement($jsdata)
   //   appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
   //     returns the new child
@@ -1104,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));
   }
@@ -1149,6 +1282,9 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   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));
   }
@@ -1170,11 +1306,14 @@ class ExtendedDocumentFragment extends DOMDocumentFragment {
   public function appendXMLMarkup($xmldata) {
     $this->ownerDocument->appendXMLMarkup($xmldata, $this);
   }
+  public function appendStyleElement($styledata) {
+    return $this->appendChild($this->ownerDocument->createElementStyle($styledata));
+  }
   public function appendJSElement($jsdata) {
     return $this->appendChild($this->ownerDocument->createElementJS($jsdata));
   }
-  public function appendJSFile($jsdata, $defer = false, $async = false) {
-    return $this->appendChild($this->ownerDocument->createElementJSFile($jsdata, $defer, $async));
+  public function appendJSFile($jsURL, $defer = false, $async = false) {
+    return $this->appendChild($this->ownerDocument->createElementJSFile($jsURL, $defer, $async));
   }
 }
 ?>
index 4f35aa2054ce4d299892ac61aa22693f7933dd1e..7c20b5a1c34d3140a0a78328a33e4781ea7ec580 100644 (file)
@@ -169,7 +169,7 @@ class email {
 
     if (in_array('to', $addrtype)) {
       foreach ($this->recipients as $address) {
-        if (strlen(@$address['mail'])) {
+        if (strlen($address['mail'] ?? '')) {
           $mailaddresses[] = array('mail'=>$address['mail'],
                                    'name'=>strlen($address['name'])?$address['name']:'',
                                    'addrtype'=>'to');
@@ -178,7 +178,7 @@ class email {
     }
     if (in_array('cc', $addrtype)) {
       foreach ($this->cc as $address) {
-        if (strlen(@$address['mail'])) {
+        if (strlen($address['mail'] ?? '')) {
           $mailaddresses[] = array('mail'=>$address['mail'],
                                    'name'=>strlen($address['name'])?$address['name']:'',
                                    'addrtype'=>'cc');
@@ -187,7 +187,7 @@ class email {
     }
     if (in_array('bcc', $addrtype)) {
       foreach ($this->bcc as $address) {
-        if (strlen(@$address['mail'])) {
+        if (strlen($address['mail'] ?? '')) {
           $mailaddresses[] = array('mail'=>$address['mail'],
                                    'name'=>strlen($address['name'])?$address['name']:'',
                                    'addrtype'=>'bcc');
@@ -216,7 +216,7 @@ class email {
     if (count($this->recipients)) {
       $recpt = '';
       foreach ($this->recipients as $address) {
-        if (strlen(@$address['mail'])) {
+        if (strlen($address['mail'] ?? '')) {
           if (strlen($address['name'])) { $recpt .= $this->mimeencode($address['name'], true).' <'.$address['mail'].'>,'; }
           else { $recpt .= $address['mail'].','; }
         }
@@ -252,7 +252,7 @@ class email {
     if (count($this->attachments)) {
       // create random boundary, 20 chars, always beginning with KaiRo ;-)
       $boundary = 'KaiRo';
-      for ($i = 1; $i <= 15; $i++)     {
+      for ($i = 1; $i <= 15; $i++) {
         $r = rand(0, 61);
         if ($r < 10) { $boundary .= chr($r + 48); }
         elseif ($r < 36) { $boundary .= chr($r + 55); }
@@ -373,7 +373,7 @@ class email {
       // encode x09,x20 at lineends
       {
         $iLength = strlen($sLine);
-        $iLastChar = ord($sLine{$iLength-1});
+        $iLastChar = ord($sLine[$iLength-1]);
 
         //              !!!!!!!!
         // imap_8_bit does not encode x20 at the very end of a text,
@@ -383,7 +383,7 @@ class email {
         if (!($bEmulate_imap_8bit && ($i==count($aLines)-1)))
 
         if (($iLastChar==0x09)||($iLastChar==0x20)) {
-          $sLine{$iLength-1}='=';
+          $sLine[$iLength-1]='=';
           $sLine .= ($iLastChar==0x09)?'09':'20';
         }
       }    // imap_8bit encodes x20 before chr(13), too
index 74e2012e6eb2370e9063d54b00300c0cfef0b7ac..9743e7a55b7c1ca0b1b328c091183d6c69c44838 100644 (file)
@@ -206,11 +206,11 @@ class rrdstat {
       $this->status = 'graphonly';
     }
     elseif (isset($iinfo['file'])) {
-      $this->rrd_file = (($iinfo['file']{0} != '/')?$this->basedir:'').$iinfo['file'];
+      $this->rrd_file = (($iinfo['file'][0] != '/')?$this->basedir:'').$iinfo['file'];
       $this->basename = basename((substr($this->rrd_file, -4) == '.rrd')?substr($this->rrd_file, 0, -4):$this->rrd_file);
     }
     elseif (!is_null($conf_id) && file_exists($conf_id.'.rrd')) {
-      $this->rrd_file = (($iinfo['file']{0} != '/')?$this->basedir:'').$conf_id.'.rrd';
+      $this->rrd_file = (($iinfo['file'][0] != '/')?$this->basedir:'').$conf_id.'.rrd';
       $this->basename = $conf_id;
     }
     else {
@@ -326,12 +326,17 @@ class rrdstat {
     if ($this->status != 'ok') { trigger_error('Cannot update non-writeable file', E_USER_WARNING); return false; }
     $upvals = array();
     if (isset($this->config_raw['update'])) {
-      if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $this->config_raw['update'], $regs)) {
-        $upfunc = create_function('', $regs[1]);
-        $upvals = $upfunc();
+      if (is_object($this->config_raw['update'])) {
+        // We assume it's an anonymous function
+        $upvals = $this->config_raw['update']();
       }
       else {
-        $evalcode = $this->config_raw['update'];
+        if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $this->config_raw['update'], $regs)) {
+          $evalcode = '$upfunc = function() {'."\n".$regs[1]."\n".'};'."\n".'print(implode("\n", $upfunc()));';
+        }
+        else {
+          $evalcode = $this->config_raw['update'];
+        }
         if (!is_null($evalcode)) {
           ob_start();
           eval($evalcode);
@@ -345,9 +350,13 @@ class rrdstat {
       foreach ($this->rrd_fields as $ds) {
         if (is_array($upArray) && isset($upArray[$ds['name']])) { $val = $upArray[$ds['name']]; }
         elseif (isset($ds['update'])) {
-          $val = null; $evalcode = null;
-          if (substr($ds['update'], 0, 4) == 'val:') {
-            $evalcode = 'function { return trim('.substr($ds['update'], 4).')); }';
+          $val = null;
+          if (is_object($ds['update'])) {
+            // We assume it's an anonymous function
+            $val = $ds['update']();
+          }
+          elseif (substr($ds['update'], 0, 4) == 'val:') {
+            $val = trim(substr($ds['update'], 4));
           }
           elseif (substr($ds['update'], 0, 8) == 'snmp-if:') {
             if (substr_count($ds['update'], ':') >= 4) {
@@ -366,19 +375,22 @@ class rrdstat {
             if ($valtype == 'in') { $oid = '1.3.6.1.2.1.2.2.1.10.'.$ifnr; }
             elseif ($valtype == 'out') { $oid = '1.3.6.1.2.1.2.2.1.16.'.$ifnr; }
             if (!is_null($ifnr) && !is_null($oid)) {
-              $evalcode = 'function { return trim(substr(strrchr(`snmpget -v2c -c '.$snmpcomm.' '.$snmphost.' '.$oid.'`,":"),1)); }';
+              $val = trim(substr(strrchr(`snmpget -v2c -c $snmpcomm $snmphost $oid`,":"),1));
             }
           }
-          else { $evalcode = $ds['update']; }
-          if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $evalcode, $regs)) {
-            $upfunc = create_function('', $regs[1]);
-            $val = $upfunc();
-          }
-          elseif (!is_null($evalcode)) {
-            ob_start();
-            eval($evalcode);
-            $val = ob_get_contents();
-            ob_end_clean();
+          else {
+            if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $ds['update'], $regs)) {
+              $evalcode = '$upfunc = function() {'."\n".$regs[1]."\n".'};'."\n".'print($upfunc());';
+            }
+            else {
+              $evalcode = $ds['update'];
+            }
+            if (!is_null($evalcode)) {
+              ob_start();
+              eval($evalcode);
+              $val = ob_get_contents();
+              ob_end_clean();
+            }
           }
         }
         else { $val = null; }
@@ -396,8 +408,7 @@ class rrdstat {
         $upvals[$akey] = $keys_have_names?$lastvals[$akey]:$lastvals[$rowids[$akey]];
       }
     }
-    $walkfunc = create_function('&$val,$key', '$val = is_numeric(trim($val))?trim($val):"U";');
-    array_walk($upvals, $walkfunc);
+    array_walk($upvals, function(&$val, $key) { $val = is_numeric(trim($val)) ? trim($val) : "U"; });
     $return = null;
     if (count($upvals)) {
       $update_cmd = $this->rrdtool_bin.' update '.$this->rrd_file
@@ -485,7 +496,7 @@ class rrdstat {
 
     // assemble configuration
     $gconf = (array)$extra;
-    if (!is_null($sub) && is_array($this->config_raw['graph.'.$sub])) {
+    if (!is_null($sub) && array_key_exists('graph.'.$sub, $this->config_raw) && is_array($this->config_raw['graph.'.$sub])) {
       $gconf = $gconf + $this->config_raw['graph.'.$sub];
     }
     $gconf = $gconf + (array)$this->config_graph;
@@ -509,8 +520,8 @@ class rrdstat {
     $fname = str_replace('%t', $timeframe, $fname);
     $fname = str_replace('%f', $fmt_ext, $fname);
     if (substr($fname, -strlen($fmt_ext)) != $fmt_ext) { $fname .= $fmt_ext; }
-    if (isset($gconf['path']) && ($fname{0} != '/')) { $fname = $gconf['path'].'/'.$fname; }
-    if ($fname{0} != '/') { $fname = $this->basedir.$fname; }
+    if (isset($gconf['path']) && ($fname[0] != '/')) { $fname = $gconf['path'].'/'.$fname; }
+    if ($fname[0] != '/') { $fname = $this->basedir.$fname; }
     $fname = str_replace('//', '/', $fname);
 
     $graphrows = array(); $specialrows = array(); $gC = 0;
@@ -565,7 +576,7 @@ class rrdstat {
         }
         foreach (array('scale_time_src','scale_time_tgt') as $st) {
           if (!isset($erow[$st]) || !is_numeric($erow[$st])) {
-            switch (@$erow[$st]) {
+            switch ($erow[$st] ?? null) {
               case 'dyn':
               case 'auto':
                 $erow[$st] = $slice;
@@ -760,25 +771,26 @@ class rrdstat {
     }
 
     $graph_cmd = $this->rrdtool_bin.' graph '.str_replace('*', '\*', $fname.$gOpts.$gDefs.$gGraphs.$addSpecial);
-    $return = `$graph_cmd 2>&1`;
-
-    if (strpos($return, 'ERROR') !== false) {
-      trigger_error($this->rrd_file.' - rrd graph error: '.$return, E_USER_WARNING);
-      $return = 'command:'.$graph_cmd."\n\n".$return;
+    if ((file_exists($fname) && !is_writable($fname)) ||
+        (!file_exists($fname) && !is_writable(dirname($fname)))) {
+      trigger_error($this->rrd_file.' - graph file not writable: '.$fname, E_USER_WARNING);
+      return 'command:'.$graph_cmd."\n\n".'unwritable file: '.$fname;
     }
-    if (0) {
-      // debug output
-      $return = 'command:'.$graph_cmd."\n\n".$return;
+    $graph_out = `$graph_cmd 2>&1`;
+
+    if (strpos($graph_out, 'ERROR') !== false) {
+      trigger_error($this->rrd_file.' - rrd graph error: '.$graph_out, E_USER_WARNING);
+      return 'command:'.$graph_cmd."\n\n".$graph_out;
     }
     $legendlines = '';
     foreach ($graphrows as $grow) {
       $legendline = isset($grow['desc'])?$grow['desc']:(isset($grow['legend'])?$grow['legend']:$grow['name']);
-      $legendline .= '|'.@$grow['color'];
+      $legendline .= '|'.($grow['color'] ?? '');
       $legendline .= '|'.(isset($grow['color_bg'])?$grow['color_bg']:'');
       $legendline .= '|'.(isset($grow['legend_long'])?$grow['legend_long']:'');
       $legendlines .= 'legend:'.$legendline."\n";
     }
-    $return = 'file:'.$fname."\n".$legendlines.$return;
+    $return = 'file:'.$fname."\n".$legendlines.$graph_out;
   return $return;
   }
 
@@ -833,7 +845,7 @@ class rrdstat {
     $pconf = $pconf + (array)$this->config_page;
 
     $return = null;
-    switch (@$pconf['type']) {
+    switch ($pconf['type'] ?? null) {
       case 'index':
         $return = $this->page_index($pconf);
         break;
@@ -959,9 +971,9 @@ class rrdstat {
     if (isset($pconf['stats_url_add'])) { $sURL_add = $pconf['stats_url_add']; }
     else { $sURL_add = '&amp;sub=%s'; }
 
-    $default_num_cols = $GLOBALS['ua']->isMobile()?1:2;
-    $num_cols = is_numeric(@$pconf['num_rows'])?$pconf['num_rows']:$default_num_cols;
-    $num_rows = ceil(count($stats)/$num_cols);
+    $default_num_cols = $GLOBALS['ua']->isMobile() ? 1 : 2;
+    $num_cols = is_numeric($pconf['num_rows'] ?? null) ? $pconf['num_rows'] : $default_num_cols;
+    $num_rows = ceil(count($stats) / $num_cols);
 
     $out .= '<table class="overview">'."\n";
     for ($row = 0; $row < $num_rows; $row++) {
@@ -972,7 +984,7 @@ class rrdstat {
         if ($idx < count($stats)) {
           @list($sname, $s_psub) = explode('|', $stats[$idx]['name'], 2);
           $s_psname = 'page'.(isset($s_psub)?'.'.$s_psub:'');
-          $g_sub = @$this->config_all[$sname][$s_psname]['graph_sub'];
+          $g_sub = $this->config_all[$sname][$s_psname]['graph_sub'] ?? '';
 
           if (isset($this->config_all[$sname][$s_psname]['title_page'])) {
             $s_ptitle = $this->config_all[$sname][$s_psname]['title_page'];
@@ -1177,7 +1189,7 @@ class rrdstat {
     $snames = array(); $s_exclude = array(); $sfiles = array();
     if (isset($pconf['index_ids'])) {
       foreach (explode(',', $pconf['index_ids']) as $iid) {
-        if ($iid{0} == '-') { $s_exclude[] = substr($iid, 1); }
+        if ($iid[0] == '-') { $s_exclude[] = substr($iid, 1); }
         else { $snames[] = $iid; }
       }
     }
@@ -1192,7 +1204,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] ?? null)) {
         foreach ($this->config_all[$iname] as $key=>$val) {
           if (substr($key, 0, 5) == 'page.') { $newstat['sub'][] = substr($key, 5); }
         }
index 407c48d465c3f2f0675a2004a1fa6a04024e6dcf..190e539119befaa46f1f2b2c569170ba1111147a 100755 (executable)
@@ -97,7 +97,7 @@ class userAgent {
   private $version;
   private $bot = false;
   private $mobile = false;
-  private $uadata = array();
+  private $uadata = [];
 
   function __construct($ua_string = '') {
     // *** constructor ***
@@ -980,12 +980,15 @@ class userAgent {
       $this->bot = false;
     }
 
-    $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','Schmozilla','42_HAL',
-                      'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver',
-                      'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch',
-                      'appie','larbin','NutchCVS','Webchat','Mediapartners-Google','sitecheck.internetseer.com',
-                      'FavOrg','findlinks','DataCha0s','ichiro','Francis','CoralWebPrx','DoCoMo','Ocelli','Sogou Video',
-                      'Yandex','Yeti','Austronaut-URL-Checker');
+    $botArray = [
+      'Scooter', 'Spinne', 'Vagabondo', 'Firefly', 'Scrubby', 'NG', 'Pompos', 'Szukacz', 'Schmozilla', '42_HAL',
+      'NetResearchServer', 'LinkWalker', 'Zeus', 'W3C_Validator', 'ZyBorg', 'Ask Jeeves', 'ia_archiver', 'ichiro',
+      'PingALink Monitoring Services', 'IlTrovatore-Setaccio', 'Nutch', 'Mercator', 'search.ch', 'appie', 'larbin',
+      'NutchCVS', 'Webchat', 'Mediapartners-Google', 'sitecheck.internetseer.com', 'FavOrg', 'findlinks', 'DataCha0s',
+      'Francis', 'CoralWebPrx', 'DoCoMo', 'Ocelli', 'Sogou Video', 'Yandex', 'Yeti', 'SEO Scanner', 'Feedbin feed-id',
+      'Austronaut-URL-Checker', 'check_ssl_cert', 'check_http', 'vdirsyncer', 'FreshRSS', 'UniversalFeedParser',
+      'Cloudflare Custom Hostname Verification', 'Scoop.it',
+    ];
 
     if (in_array($this->brand, $botArray)) {
       $this->bot = true;
@@ -997,26 +1000,38 @@ class userAgent {
     }
   }
 
-  public function getBrand() { return $this->brand; }
-  public function getVersion() { return $this->version; }
+  public function getBrand() {
+    return $this->brand;
+  }
+
+  public function getVersion() {
+    return $this->version;
+  }
 
   public function getAcceptLanguages() {
     if (!isset($this->uadata['accept-languages'])) {
       $headers = getAllHeaders();
-      $accLcomp = explode(',', $headers['Accept-Language']);
-      $accLang = array();
+      $accLcomp = explode(',', ($headers['Accept-Language'] ?? ''));
+      $accLang = [];
       foreach ($accLcomp as $lcomp) {
         if (strlen($lcomp)) {
           $ldef = explode(';', $lcomp);
-          $accLang[$ldef[0]] = (float)((strpos(@$ldef[1],'q=')===0)?substr($ldef[1],2):1);
+          if (count($ldef) > 1 && strpos($ldef[1], 'q=') === 0) {
+            $accLang[$ldef[0]] = substr($ldef[1], 2);
+          }
+          else {
+            $accLang[$ldef[0]] = 1;
+          }
         }
       }
       $this->uadata['accept-languages'] = $accLang;
     }
-  return $this->uadata['accept-languages'];
+    return $this->uadata['accept-languages'];
   }
 
-  public function getUAString() { return $this->uastring; }
+  public function getUAString() {
+    return $this->uastring;
+  }
 
   public function getEngine() {
     // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|netfront|unknown
@@ -1101,10 +1116,12 @@ class userAgent {
         }
       }
     }
-  return $this->uadata['engine'];
+    return $this->uadata['engine'];
   }
 
-  public function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); }
+  public function hasEngine($rnd_engine) {
+    return ($this->getEngine() == $rnd_engine);
+  }
 
   public function getEngineVersion() {
     if (!isset($this->uadata['eng_version'])) {
@@ -1112,7 +1129,7 @@ class userAgent {
       // getOS() should get the date for us
       $this->getOS();
     }
-  return $this->uadata['eng_version'];
+    return $this->uadata['eng_version'];
   }
 
   public function getOS() {
@@ -1213,6 +1230,9 @@ class userAgent {
             $this->uadata['lang'] = null;
             $this->uadata['eng_version'] = null;
           }
+          if (($this->brand == 'Firefox') && (intval($this->version) >= 110)) {
+            $this->uadata['eng_version'] = $this->version;
+          }
         }
         elseif ($this->hasEngine('edgehtml')) {
           if (preg_match('#Mozilla/5.0 \(([^;]+); (WOW64|Win64); ([^\);]+)\)#', $this->uastring, $regs)) {
@@ -1499,60 +1519,60 @@ class userAgent {
         elseif ($this->uadata['os'] == 'WinNT') { $this->uadata['os'] = 'Windows NT'; }
         elseif ($this->uadata['os'] == 'Win32') { $this->uadata['os'] = 'Windows (32bit)'; }
         elseif ($this->uadata['os'] == 'Win64') { $this->uadata['os'] = 'Windows (64bit)'; }
-        elseif (preg_match('/iPhone OS ([\d_]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'iOS '.str_replace('_', '.', $regs[1]); }
-        elseif (preg_match('/Mac ?OS ?X/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; }
-        elseif (preg_match('/Mac_P(ower|)PC/i', $this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; }
-        elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
-        elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
-        elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
-        elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
-        elseif (preg_match('/(?:web|hpw)OS\/([0-9a-zA-Z\._+]+)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'webOS '.$regs[1]; }
-        elseif (preg_match('/Android \(Linux (.+)\)/i', $this->uadata['os'], $regs)) { $this->uadata['os'] = 'Android '.$regs[1]; }
-        elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
+        elseif (preg_match('/iPhone OS ([\d_]+)/i', ($this->uadata['os'] ?? ''), $regs)) { $this->uadata['os'] = 'iOS '.str_replace('_', '.', $regs[1]); }
+        elseif (preg_match('/Mac ?OS ?X/i', ($this->uadata['os'] ?? ''))) { $this->uadata['os'] = 'MacOS X'; }
+        elseif (preg_match('/Mac_P(ower|)PC/i', ($this->uadata['os'] ?? ''))) { $this->uadata['os'] = 'MacOS'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
+        elseif (preg_match('/(?:web|hpw)OS\/([0-9a-zA-Z\._+]+)/i', ($this->uadata['os'] ?? ''), $regs)) { $this->uadata['os'] = 'webOS '.$regs[1]; }
+        elseif (preg_match('/Android \(Linux (.+)\)/i', ($this->uadata['os'] ?? ''), $regs)) { $this->uadata['os'] = 'Android '.$regs[1]; }
+        elseif (strpos($this->uadata['os'] ?? '', 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
         elseif (preg_match('/SymbianOS[\/ ]([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) { $this->uadata['os'] = 'SymbianOS '.$regs[1]; }
-        elseif (preg_match('/Symbian ?OS/i', $this->uadata['os'])) { $this->uadata['os'] = 'SymbianOS'; }
+        elseif (preg_match('/Symbian ?OS/i', ($this->uadata['os'] ?? ''))) { $this->uadata['os'] = 'SymbianOS'; }
 
-        if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
-        elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
-        elseif (strpos($this->uadata['os'], 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; }
-        elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
-        elseif (strpos($this->uadata['os'], 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; }
-        elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'Linux'; }
-        elseif (strpos($this->uadata['os'], 'Android') !== false) { $this->uadata['platform'] = 'Android'; }
-        elseif (strpos($this->uadata['os'], 'Firefox OS') !== false) { $this->uadata['platform'] = 'Firefox OS'; }
-        elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
-        elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
-        elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
-        elseif (strpos($this->uadata['os'], 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; }
-        elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
-        elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
-        elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
-        elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
-        elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
-        elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
-        elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
-        elseif (strpos($this->uadata['os'], 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; }
-        elseif (strpos($this->uadata['os'], 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
-        elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
-        elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
-        elseif (strpos($this->uadata['os'], 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; }
-        elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
-        elseif (strpos($this->uadata['os'], 'BlackBerry') !== false) { $this->uadata['platform'] = 'BlackBerry'; }
-        elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; }
-        elseif (strpos($this->uadata['os'], 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; }
-        elseif (strpos($this->uadata['os'], 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; }
-        elseif (strpos($this->uadata['os'], 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; }
-        elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
-        elseif (strpos($this->uadata['os'], 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; }
+        if (strpos($this->uadata['os'] ?? '', 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'iOS') !== false) { $this->uadata['platform'] = 'Macintosh'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'MeeGo') !== false) { $this->uadata['platform'] = 'Linux'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'webOS') !== false) { $this->uadata['platform'] = 'Linux'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Android') !== false) { $this->uadata['platform'] = 'Android'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Firefox OS') !== false) { $this->uadata['platform'] = 'Firefox OS'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'BePC') !== false) { $this->uadata['platform'] = 'BeOS'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'webOS') !== false) { $this->uadata['platform'] = 'webOS'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'OS/2') !== false) { $this->uadata['platform'] = 'OS/2'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'BlackBerry') !== false) { $this->uadata['platform'] = 'BlackBerry'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Gameboy') !== false) { $this->uadata['platform'] = 'Nintendo'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Wii') !== false) { $this->uadata['platform'] = 'Nintendo'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Nintendo') !== false) { $this->uadata['platform'] = 'Nintendo'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'J2ME') !== false) { $this->uadata['platform'] = 'Java'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
+        elseif (strpos($this->uadata['os'] ?? '', 'mingw') !== false) { $this->uadata['platform'] = 'Windows'; }
         else { $this->uadata['platform'] = $this->uadata['os']; }
 
-        if (strpos($this->uadata['os'], 'Windows Phone OS') !== false) { $this->mobile = true; }
-        elseif (strpos($this->uadata['os'], 'Gameboy') !== false) { $this->mobile = true; }
+        if (strpos($this->uadata['os'] ?? '', 'Windows Phone OS') !== false) { $this->mobile = true; }
+        elseif (strpos($this->uadata['os'] ?? '', 'Gameboy') !== false) { $this->mobile = true; }
 
-        $this->uadata['lang'] = str_replace('_', '-', @$this->uadata['lang']);
+        $this->uadata['lang'] = str_replace('_', '-', ($this->uadata['lang'] ?? ''));
       }
     }
-  return $this->uadata['os'];
+    return $this->uadata['os'];
   }
 
   public function getPlatform() {
@@ -1561,7 +1581,7 @@ class userAgent {
       // getOS() should get the date for us
       $this->getOS();
     }
-  return $this->uadata['platform'];
+    return $this->uadata['platform'];
   }
 
   public function getLanguage() {
@@ -1570,7 +1590,7 @@ class userAgent {
       // getOS() should get the date for us
       $this->getOS();
     }
-  return $this->uadata['lang'];
+    return $this->uadata['lang'];
   }
 
   public function getGeckoDate() {
@@ -1579,7 +1599,7 @@ class userAgent {
       // getEngine() should get the date for us
       $this->getEngine();
     }
-  return $this->uadata['geckodate'];
+    return $this->uadata['geckodate'];
   }
 
   public function getGeckoTime() {
@@ -1597,10 +1617,12 @@ class userAgent {
         if ($use_time) { date_default_timezone_set($old_tz); }
       }
     }
-  return $this->uadata['geckotime'];
+    return $this->uadata['geckotime'];
   }
 
-  public function isBot() { return $this->bot; }
+  public function isBot() {
+    return $this->bot;
+  }
 
   public function isMobile() {
     if (!isset($this->uadata['os'])) {
index e7a69c59d68392f6e3ed359072619be965761283..03494e10fadce0bb424c6b3d43b92d733dfc79ff 100755 (executable)
@@ -55,6 +55,7 @@ Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
 Mozilla/5.0 (X11; Linux i686 on x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
 Mozilla/5.0 (X11; Linux i686; rv:2.0b6pre) Gecko/20100907 Firefox/4.0b6pre
 Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20.0 Firefox/20.0
+Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
 Mozilla/5.0 (Android; Mobile; rv:12.0) Gecko/12.0 Firefox/12.0
 Mozilla/5.0 (Android; Tablet; rv:14.0a1) Gecko/14 Firefox/14.0a1
 Mozilla/5.0 (Android; Tablet; rv:28.0) Gecko/28.0 Firefox/28.0
@@ -83,6 +84,10 @@ Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0
 Mozilla/5.0 (Mobile; LG-D300; rv:18.1) Gecko/18.1 Firefox/18.1
 Mozilla/5.0 (Tablet; rv:26.0) Gecko/26.0 Firefox/26.0
 Mozilla/5.0 (Tablet; Saga G1; rv:26.0) Gecko/26.0 Firefox/26.0
+Mozilla/5.0 (Mobile; ALCATEL4044V; rv:37.0) Gecko/37.0 Firefox/37.0 KaiOS/1.0
+Mozilla/5.0 (Mobile; Nokia_8110_4G; rv:48.0) Gecko/48.0 Firefox/48.0 KAIOS/2.5
+Mozilla/5.0 (Mobile; rv:68.0) Gecko/68.0 KAIOS/3.0
+Mozilla/5.0 (Mobile; rv:76.0) Gecko/20100101 Firefox/76.0 B2GOS/3.0
 Mozilla/5.0 (FreeBSD; Viera; rv:34.0) Gecko/20100101 Firefox/34.0
 Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.1.4pre) Gecko/20090928 Lightning/1.0pre Shredder/3.0pre
 Mozilla/5.0 (Windows; U; Windows NT 6.1; WOW64; en-US; rv:1.9.3a5pre) Gecko/20100514 Lanikai/3.1b1