fix some warnings from modern PHP versions
[php-utility-classes.git] / classes / useragent.php-class
index 9026179b8ed99bfe0855c769241ecb95020b207f..bebf5535a55a78e42b2a492f8bfc23133e991898 100755 (executable)
@@ -1,39 +1,7 @@
 <?php
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is KaiRo's userAgent detection.
- *
- * The Initial Developer of the Original Code is
- * KaiRo - Robert Kaiser.
- * Portions created by the Initial Developer are Copyright (C) 2003-2007
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s): Robert Kaiser <kairo@kairo.at>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 class userAgent {
   // userAgent PHP class
@@ -1035,12 +1003,17 @@ class userAgent {
   public function getAcceptLanguages() {
     if (!isset($this->uadata['accept-languages'])) {
       $headers = getAllHeaders();
-      $accLcomp = explode(',', $headers['Accept-Language']);
+      $accLcomp = explode(',', ($headers['Accept-Language'] ?? ''));
       $accLang = array();
       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;
@@ -1581,7 +1554,7 @@ class userAgent {
         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'];