Gazelle/classes/useragent.class.php

157 lines
4.1 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
2013-06-20 08:01:00 +00:00
class UserAgent {
2013-06-25 08:00:52 +00:00
private static $Browsers = array(
2011-03-28 14:21:28 +00:00
//Less popular
'Shiira' => 'Shiira',
'Songbird' => 'Songbird',
'SeaMonkey' => 'SeaMonkey',
'OmniWeb' => 'OmniWeb',
'Camino' => 'Camino',
'Chimera' => 'Chimera',
'Epiphany' => 'Epiphany',
'Konqueror' => 'Konqueror',
'Iceweasel' => 'Iceweasel',
'Lynx' => 'Lynx',
'Links' => 'Links',
'libcurl' => 'cURL',
'midori' => 'Midori',
2013-06-24 08:00:28 +00:00
'Blackberry' => 'BlackBerry Browser',
2011-03-28 14:21:28 +00:00
//Big names
'Firefox' => 'Firefox',
2013-08-29 08:00:48 +00:00
'OPR' => 'Opera Blink', # Opera 15+ (the version running Blink)
'Opera' => 'Opera',
2011-03-28 14:21:28 +00:00
'Chrome' => 'Chrome',
'Safari' => 'Safari',
2013-08-29 08:00:48 +00:00
//Put Chrome Frame above IE
2011-03-28 14:21:28 +00:00
'chromeframe' => 'Chrome Frame',
'x-clock' => 'Chrome Frame',
'MSIE' => 'Internet Explorer',
//Firefox versions
'Shiretoko' => 'Firefox (Experimental)',
'Minefield' => 'Firefox (Experimental)',
'GranParadiso' => 'Firefox (Experimental)',
'Namoroka' => 'Firefox (Experimental)',
'AppleWebKit' => 'WebKit',
'Mozilla' => 'Mozilla'
//Weird shit
/*
'WWW-Mechanize' => 'Perl',
'Wget' => 'Wget',
'BTWebClient' => 'µTorrent',
'Transmission' => 'Transmission',
'Java' => 'Java',
'RSS' => 'RSS Downloader'
*/
);
2013-02-22 08:00:24 +00:00
2013-06-25 08:00:52 +00:00
private static $OperatingSystems = array(
2011-03-28 14:21:28 +00:00
//Mobile
'SymbianOS' => 'Symbian',
'blackberry' => 'BlackBerry',
'iphone' => 'iPhone',
'ipod' => 'iPhone',
'android' => 'Android',
'palm' => 'Palm',
'mot-razr' => 'Motorola Razr',
2013-06-09 08:01:21 +00:00
// 'tablet PC' => 'Windows RT',
// 'ARM; Trident' => 'Windows RT',
2011-03-28 14:21:28 +00:00
//Windows
2013-10-25 08:00:59 +00:00
'Windows NT 6.3' => 'Windows 8.1',
'Windows 8.1' => 'Windows 8.1',
2013-05-21 08:01:09 +00:00
'Windows NT 6.2' => 'Windows 8',
'Windows 8' => 'Windows 8',
2011-03-28 14:21:28 +00:00
'Windows NT 6.1' => 'Windows 7',
'Windows 7' => 'Windows 7',
'Windows NT 6.0' => 'Windows Vista',
'Windows Vista' => 'Windows Vista',
'windows nt 5.2' => 'Windows 2003',
'windows 2003' => 'Windows 2003',
'windows nt 5.0' => 'Windows 2000',
'windows 2000' => 'Windows 2000',
'windows nt 5.1' => 'Windows XP',
'windows xp' => 'Windows XP',
'Win 9x 4.90' => 'Windows ME',
'Windows Me' => 'Windows ME',
'windows nt' => 'Windows NT',
'winnt' => 'Windows NT',
'windows 98' => 'Windows 98',
'windows ce' => 'Windows CE',
'win98' => 'Windows 98',
'windows 95' => 'Windows 95',
'windows 95' => 'Windows 95',
'win95' => 'Windows 95',
'win16' => 'Windows 3.1',
//'windows' => 'Windows',
//OS X
'os x' => 'Mac OS X',
'macintosh' => 'Mac OS X',
'darwin' => 'Mac OS X',
//Less popular
'ubuntu' => 'Ubuntu',
'debian' => 'Debian',
'fedora' => 'Fedora',
'freebsd' => 'FreeBSD',
'openbsd' => 'OpenBSD',
'bsd' => 'BSD',
'x11' => 'Linux',
'gnu' => 'Linux',
'linux' => 'Linux',
'unix' => 'Unix',
'Sun OS' => 'Sun',
'Sun' => 'Sun',
//Weird shit
/*
'WWW-Mechanize' => 'Perl',
'Wget' => 'Wget',
'BTWebClient' => 'µTorrent',
'Transmission' => 'Transmission',
'Java' => 'Java',
'RSS' => 'RSS Downloader',
*/
//Catch-all
'win' => 'Windows',
'mac' => 'Mac OS X'
);
2013-02-22 08:00:24 +00:00
2013-06-20 08:01:00 +00:00
public static function operating_system(&$UserAgentString) {
2011-03-28 14:21:28 +00:00
if (empty($UserAgentString)) {
return 'Hidden';
}
2013-06-25 08:00:52 +00:00
foreach (self::$OperatingSystems as $String => $OperatingSystem) {
2011-03-28 14:21:28 +00:00
if (stripos($UserAgentString, $String) !== false) {
2013-05-21 08:01:09 +00:00
return $OperatingSystem;
2011-03-28 14:21:28 +00:00
}
}
2013-05-21 08:01:09 +00:00
return 'Unknown';
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-06-20 08:01:00 +00:00
public static function mobile(&$UserAgentString) {
2013-06-24 08:00:28 +00:00
if (strpos($UserAgentString, 'iPad') !== false) {
2011-03-28 14:21:28 +00:00
return false;
}
2013-02-22 08:00:24 +00:00
2013-06-24 08:00:28 +00:00
// "Mobi" catches "Mobile" too
if (strpos($UserAgentString, 'Device') || strpos($UserAgentString, 'Mobi') || strpos($UserAgentString, 'Mini') || strpos($UserAgentString, 'webOS')) {
2011-03-28 14:21:28 +00:00
return true;
}
return false;
}
2013-02-22 08:00:24 +00:00
2013-06-20 08:01:00 +00:00
public static function browser(&$UserAgentString) {
2011-03-28 14:21:28 +00:00
if (empty($UserAgentString)) {
return 'Hidden';
}
$Return = 'Unknown';
2013-06-25 08:00:52 +00:00
foreach (self::$Browsers as $String => $Browser) {
2011-03-28 14:21:28 +00:00
if (strpos($UserAgentString, $String) !== false) {
$Return = $Browser;
break;
}
}
2013-06-20 08:01:00 +00:00
if (self::mobile($UserAgentString)) {
2011-03-28 14:21:28 +00:00
$Return .= ' Mobile';
}
return $Return;
}
}