static function ThemekeyBrowserDetection::getBrowser in ThemeKey 7.3
Same name and namespace in other branches
- 7 modules/themekey_browser_detection.php \ThemekeyBrowserDetection::getBrowser()
- 7.2 modules/themekey_browser_detection.php \ThemekeyBrowserDetection::getBrowser()
Get browser name and version
@static @access public
Parameters
string user agent:
Return value
string browser name and version or 'unknown' if unrecognized
1 call to ThemekeyBrowserDetection::getBrowser()
- themekey_dummy2user_browser in modules/
themekey.system.inc - ThemeKey mapping function to set a ThemeKey property's value (destination) with the aid of another ThemeKey property (source).
File
- modules/
themekey_browser_detection.php, line 53 - Derived from Browser Detection Class by Dragan Dinic <dragan@dinke.net> and modified to fit the needs of ThemeKey Properties.
Class
- ThemekeyBrowserDetection
- Browser Detection class contains common static method for getting browser version and OS
Code
static function getBrowser($useragent) {
// check for most popular browsers first
// unfortunately, that's IE. We also ignore Opera and Netscape 8
// because they sometimes send msie agent
if (strpos($useragent, 'MSIE') !== FALSE && strpos($useragent, 'Opera') === FALSE && strpos($useragent, 'Netscape') === FALSE) {
//deal with Blazer
if (preg_match("/Blazer\\/([0-9]{1}\\.[0-9]{1}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Blazer ' . $matches[1];
}
//deal with IE
if (preg_match("/MSIE ([0-9]{1,2}\\.[0-9]{1,2})/", $useragent, $matches)) {
return 'Internet Explorer ' . $matches[1];
}
}
elseif (strpos($useragent, 'IEMobile') !== FALSE) {
if (preg_match("/IEMobile\\/([0-9]{1,2}\\.[0-9]{1,2})/", $useragent, $matches)) {
return 'Internet Explorer Mobile ' . $matches[1];
}
}
elseif (strpos($useragent, 'Gecko')) {
//deal with Gecko based
//if firefox
if (preg_match("/Firefox\\/([0-9]{1,2}\\.[0-9]{1,2}(\\.[0-9]{1,2})?)/", $useragent, $matches)) {
return 'Mozilla Firefox ' . $matches[1];
}
//if Netscape (based on gecko)
if (preg_match("/Netscape\\/([0-9]{1}\\.[0-9]{1}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Netscape ' . $matches[1];
}
//check chrome before safari because chrome agent contains both
if (preg_match("/Chrome\\/([^\\s]+)/", $useragent, $matches)) {
return 'Google Chrome ' . $matches[1];
}
//if Safari (based on gecko)
if (preg_match("/Safari\\/([0-9]{2,3}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Safari ' . $matches[1];
}
//if Galeon (based on gecko)
if (preg_match("/Galeon\\/([0-9]{1}\\.[0-9]{1}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Galeon ' . $matches[1];
}
//if Konqueror (based on gecko)
if (preg_match("/Konqueror\\/([0-9]{1}\\.[0-9]{1}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Konqueror ' . $matches[1];
}
// if Fennec (based on gecko)
if (preg_match("/Fennec\\/([0-9]{1}\\.[0-9]{1}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Fennec' . $matches[1];
}
// if Maemo (based on gecko)
if (preg_match("/Maemo\\/([0-9]{1}\\.[0-9]{1}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Maemo' . $matches[1];
}
//no specific Gecko found
//return generic Gecko
return 'Gecko based';
}
elseif (strpos($useragent, 'Opera') !== FALSE) {
//deal with Opera
if (preg_match("/Opera[\\/ ]([0-9]{1}\\.[0-9]{1}([0-9])?)/", $useragent, $matches)) {
return 'Opera ' . $matches[1];
}
}
elseif (strpos($useragent, 'Lynx') !== FALSE) {
//deal with Lynx
if (preg_match("/Lynx\\/([0-9]{1}\\.[0-9]{1}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Lynx ' . $matches[1];
}
}
elseif (strpos($useragent, 'Netscape') !== FALSE) {
//NN8 with IE string
if (preg_match("/Netscape\\/([0-9]{1}\\.[0-9]{1}(\\.[0-9])?)/", $useragent, $matches)) {
return 'Netscape ' . $matches[1];
}
}
else {
//unrecognized, this should be less than 1% of browsers (not counting bots like google etc)!
return 'unknown';
}
}