deal with Firefox spoofing and detect Minimo, Minefield and Netscape9
[php-utility-classes.git] / include / classes / useragent.php-class
index 2aa2ddc08fbec5dc6af9ad34f59bb4cd5cc604f8..e71505a73c533c8e6a5693dbade5cc7370230597 100755 (executable)
@@ -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];
@@ -273,7 +271,12 @@ class userAgent {
     }
     elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
       $this->brand = 'Safari';
-      $this->version = $regs[1];
+      if (preg_match('|Version/([0-9a-zA-Z\.+]+)|', $this->uastring, $vregs)) {
+        $this->version = $vregs[1];
+      }
+      else {
+        $this->version = '('.$regs[1].')';
+      }
       $this->bot = false;
     }
     elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
@@ -281,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];
@@ -1019,6 +1039,7 @@ class userAgent {
       elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
       elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
       elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
+      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'; }