correct detection of presto in Opera's Firefox-spoofing UA
[php-utility-classes.git] / include / classes / useragent.php-class
index 9a28094682a406b42f56d74eb369eb99cec62c04..eba3ed2a308a5c1a3329dce344edf70b18cb962e 100755 (executable)
@@ -16,7 +16,7 @@
  *
  * The Initial Developer of the Original Code is
  * KaiRo - Robert Kaiser.
- * Portions created by the Initial Developer are Copyright (C) 2003
+ * Portions created by the Initial Developer are Copyright (C) 2003-2007
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s): Robert Kaiser <kairo@kairo.at>
@@ -164,6 +164,11 @@ class userAgent {
       $this->version = $regs[1];
       $this->bot = false;
     }
+    elseif (preg_match('|Navigator/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Netscape';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
     elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
       $this->brand = 'Chimera';
       $this->version = $regs[1];
@@ -189,11 +194,6 @@ class userAgent {
       $this->version = $regs[1];
       $this->bot = false;
     }
-    elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
-      $this->brand = 'Firefox';
-      $this->version = $regs[1];
-      $this->bot = false;
-    }
     elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
       $this->brand = 'SeaMonkey';
       $this->version = $regs[1];
@@ -209,6 +209,16 @@ class userAgent {
       $this->version = $regs[1];
       $this->bot = false;
     }
+    elseif (preg_match('|Minefield/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'Minefield';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Minimo/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'Minimo';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
     elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
       $this->brand = 'Galeon';
       $this->version = $regs[1];
@@ -229,18 +239,6 @@ class userAgent {
       $this->version = $regs[1];
       $this->bot = false;
     }
-    elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
-            strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
-      $this->brand = 'Mozilla';
-      $this->version = $regs[1];
-      $this->bot = false;
-    }
-    elseif (preg_match('|m([0-9]+)\)|', $this->uastring, $regs) &&
-            strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
-      $this->brand = 'Mozilla';
-      $this->version = 'M'.$regs[1];
-      $this->bot = false;
-    }
     elseif (preg_match('|Opera\/([^\(]+) \(.*; Opera Mini; |', $this->uastring, $regs)) {
       $this->brand = 'Opera Mini';
       $this->version = $regs[1];
@@ -286,6 +284,23 @@ class userAgent {
       $this->version = $regs[1];
       $this->bot = false;
     }
+    elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Firefox';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
+            strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
+      $this->brand = 'Mozilla';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|m([0-9]+)\)|', $this->uastring, $regs) &&
+            strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
+      $this->brand = 'Mozilla';
+      $this->version = 'M'.$regs[1];
+      $this->bot = false;
+    }
     elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
       $this->brand = 'Microsoft FrontPage';
       $this->version = $regs[1];
@@ -731,7 +746,7 @@ class userAgent {
     if (!isset($this->uadata['engine'])) {
       $this->uadata['engine'] = 'unknown';
       $this->uadata['geckodate'] = null;
-      if (preg_match('|Gecko/([0-9]+)|', $this->uastring, $regs)) {
+      if (preg_match('|Gecko/([0-9]+)|', $this->uastring, $regs) && (strpos($this->brand, 'Opera') === false)) {
         $this->uadata['engine'] = 'gecko';
         $this->uadata['geckodate'] = $regs[1];
       }
@@ -941,6 +956,12 @@ class userAgent {
           $this->uadata['os'] = $regs[1];
           $this->uadata['lang'] = $regs[2];
         }
+        // Opera 9 Firefox-spoofing
+        elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+); rv:([^\);]+)\) Gecko\/\d+ Firefox\/[0-9a-zA-Z\.+]+ Opera [^ ]+/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
       }
       elseif ($this->hasEngine('nscp')) {
         if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(X11; [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {