예제 #1
0
파일: kirby.php 프로젝트: sdvig/kirbycms
 /** 
  * The core detection method, which parses the user agent string
  *
  * @todo   add new browser versions
  * @param  string  $ua The user agent string
  * @return array   An array with all parsed info 
  */
 static function detect($ua = null)
 {
     $ua = $ua ? str::lower($ua) : str::lower(server::get('http_user_agent'));
     // don't do the detection twice
     if (self::$ua == $ua) {
         return array('name' => self::$name, 'engine' => self::$engine, 'version' => self::$version, 'platform' => self::$platform, 'agent' => self::$ua, 'mobile' => self::$mobile, 'iphone' => self::$iphone, 'ios' => self::$ios);
     }
     self::$ua = $ua;
     self::$name = false;
     self::$engine = false;
     self::$version = false;
     self::$platform = false;
     // browser
     if (!preg_match('/opera|webtv/i', self::$ua) && preg_match('/msie\\s(\\d)/', self::$ua, $array)) {
         self::$version = $array[1];
         self::$name = 'ie';
         self::$engine = 'trident';
     } else {
         if (strstr(self::$ua, 'firefox/3.6')) {
             self::$version = 3.6;
             self::$name = 'fx';
             self::$engine = 'gecko';
         } else {
             if (strstr(self::$ua, 'firefox/3.5')) {
                 self::$version = 3.5;
                 self::$name = 'fx';
                 self::$engine = 'gecko';
             } else {
                 if (preg_match('/firefox\\/(\\d+)/i', self::$ua, $array)) {
                     self::$version = $array[1];
                     self::$name = 'fx';
                     self::$engine = 'gecko';
                 } else {
                     if (preg_match('/opera(\\s|\\/)(\\d+)/', self::$ua, $array)) {
                         self::$engine = 'presto';
                         self::$name = 'opera';
                         self::$version = $array[2];
                     } else {
                         if (strstr(self::$ua, 'konqueror')) {
                             self::$name = 'konqueror';
                             self::$engine = 'webkit';
                         } else {
                             if (strstr(self::$ua, 'iron')) {
                                 self::$name = 'iron';
                                 self::$engine = 'webkit';
                             } else {
                                 if (strstr(self::$ua, 'chrome')) {
                                     self::$name = 'chrome';
                                     self::$engine = 'webkit';
                                     if (preg_match('/chrome\\/(\\d+)/i', self::$ua, $array)) {
                                         self::$version = $array[1];
                                     }
                                 } else {
                                     if (strstr(self::$ua, 'applewebkit/')) {
                                         self::$name = 'safari';
                                         self::$engine = 'webkit';
                                         if (preg_match('/version\\/(\\d+)/i', self::$ua, $array)) {
                                             self::$version = $array[1];
                                         }
                                     } else {
                                         if (strstr(self::$ua, 'mozilla/')) {
                                             self::$engine = 'gecko';
                                             self::$name = 'fx';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // platform
     if (strstr(self::$ua, 'j2me')) {
         self::$platform = 'mobile';
     } else {
         if (strstr(self::$ua, 'iphone')) {
             self::$platform = 'iphone';
         } else {
             if (strstr(self::$ua, 'ipod')) {
                 self::$platform = 'ipod';
             } else {
                 if (strstr(self::$ua, 'ipad')) {
                     self::$platform = 'ipad';
                 } else {
                     if (strstr(self::$ua, 'mac')) {
                         self::$platform = 'mac';
                     } else {
                         if (strstr(self::$ua, 'darwin')) {
                             self::$platform = 'mac';
                         } else {
                             if (strstr(self::$ua, 'webtv')) {
                                 self::$platform = 'webtv';
                             } else {
                                 if (strstr(self::$ua, 'win')) {
                                     self::$platform = 'win';
                                 } else {
                                     if (strstr(self::$ua, 'freebsd')) {
                                         self::$platform = 'freebsd';
                                     } else {
                                         if (strstr(self::$ua, 'x11') || strstr(self::$ua, 'linux')) {
                                             self::$platform = 'linux';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     self::$mobile = self::$platform == 'mobile' ? true : false;
     self::$iphone = in_array(self::$platform, array('ipod', 'iphone')) ? true : false;
     self::$ios = in_array(self::$platform, array('ipod', 'iphone', 'ipad')) ? true : false;
     return array('name' => self::$name, 'engine' => self::$engine, 'version' => self::$version, 'platform' => self::$platform, 'agent' => self::$ua, 'mobile' => self::$mobile, 'iphone' => self::$iphone, 'ios' => self::$ios);
 }
예제 #2
0
파일: browser.php 프로젝트: rev087/kennel
 function detect($ua = null)
 {
     $ua = $ua ? str::lower($ua) : strtolower($_SERVER['HTTP_USER_AGENT']);
     // don't do the detection twice
     if (self::$ua == $ua) {
         return array('browser' => self::$browser, 'engine' => self::$engine, 'version' => self::$version, 'platform' => self::$platform);
     }
     self::$ua = $ua;
     self::$browser = false;
     self::$engine = false;
     self::$version = false;
     self::$platform = false;
     // browser
     if (!preg_match('/opera|webtv/i', self::$ua) && preg_match('/msie\\s(\\d)/', self::$ua, $array)) {
         self::$version = $array[1];
         self::$browser = 'ie';
         self::$engine = 'trident';
     } else {
         if (strstr(self::$ua, 'firefox/2')) {
             self::$version = 2;
             self::$browser = 'fx';
             self::$engine = 'gecko';
         } else {
             if (strstr(self::$ua, 'firefox/3.5')) {
                 self::$version = 3.5;
                 self::$browser = 'fx';
                 self::$engine = 'gecko';
             } else {
                 if (strstr(self::$ua, 'firefox/3')) {
                     self::$version = 3;
                     self::$browser = 'fx';
                     self::$engine = 'gecko';
                 } else {
                     if (strstr(self::$ua, 'gecko/')) {
                         self::$browser = 'gecko';
                         self::$engine = 'gecko';
                     } else {
                         if (preg_match('/opera(\\s|\\/)(\\d+)/', self::$ua, $array)) {
                             self::$engine = 'presto';
                             self::$browser = 'opera';
                             self::$version = $array[2];
                         } else {
                             if (strstr(self::$ua, 'konqueror')) {
                                 self::$browser = 'konqueror';
                                 self::$engine = 'webkit';
                             } else {
                                 if (strstr(self::$ua, 'chrome')) {
                                     self::$browser = 'chrome';
                                     self::$engine = 'webkit';
                                 } else {
                                     if (strstr(self::$ua, 'iron')) {
                                         self::$browser = 'iron';
                                         self::$engine = 'webkit';
                                     } else {
                                         if (strstr(self::$ua, 'applewebkit/')) {
                                             self::$browser = 'safari';
                                             self::$engine = 'webkit';
                                             if (preg_match('/version\\/(\\d+)/i', self::$ua, $array)) {
                                                 self::$version = $array[1];
                                             }
                                         } else {
                                             if (strstr(self::$ua, 'mozilla/')) {
                                                 self::$engine = 'gecko';
                                                 self::$browser = 'mozilla';
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // platform
     if (strstr(self::$ua, 'j2me')) {
         self::$platform = 'mobile';
     } else {
         if (strstr(self::$ua, 'iphone')) {
             self::$platform = 'iphone';
         } else {
             if (strstr(self::$ua, 'ipod')) {
                 self::$platform = 'ipod';
             } else {
                 if (strstr(self::$ua, 'mac')) {
                     self::$platform = 'mac';
                 } else {
                     if (strstr(self::$ua, 'darwin')) {
                         self::$platform = 'mac';
                     } else {
                         if (strstr(self::$ua, 'webtv')) {
                             self::$platform = 'webtv';
                         } else {
                             if (strstr(self::$ua, 'win')) {
                                 self::$platform = 'win';
                             } else {
                                 if (strstr(self::$ua, 'freebsd')) {
                                     self::$platform = 'freebsd';
                                 } else {
                                     if (strstr(self::$ua, 'x11') || strstr(self::$ua, 'linux')) {
                                         self::$platform = 'linux';
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return array('browser' => self::$browser, 'engine' => self::$engine, 'version' => self::$version, 'platform' => self::$platform);
 }