From c594112746bc1d6b39149bbcfe667346fbf54e6e Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 2 Mar 2017 11:15:52 +0100 Subject: [PATCH] fixes #424, update mdetect.php to version 2015.05.13 --- include/mdetect.php | 432 +++++++++++++++++++++++++++++--------------- 1 file changed, 284 insertions(+), 148 deletions(-) diff --git a/include/mdetect.php b/include/mdetect.php index c2a06d75d..47810a45b 100644 --- a/include/mdetect.php +++ b/include/mdetect.php @@ -1,31 +1,47 @@ isTierTablet = $this->DetectTierTablet(); //Do first - $this->isTierIphone = $this->DetectTierIphone(); //Do second - $this->isMobilePhone = $this->DetectMobileQuick(); //Do third + $this->isMobilePhone = $this->DetectMobileQuick(); + $this->isTierIphone = $this->DetectTierIphone(); + $this->isTierTablet = $this->DetectTierTablet(); //Optional: Comment these out if you NEVER use them. global $isTierRichCss, $isTierGenericMobile; @@ -248,6 +271,10 @@ class uagent_info } + //***************************** + // Start device detection + //***************************** + //************************** // Detects if the current device is an iPhone. function DetectIphone() @@ -327,11 +354,8 @@ class uagent_info if ((stripos($this->useragent, $this->deviceAndroid) > -1) || ($this->DetectGoogleTV() == $this->true)) return $this->true; - //Special check for the HTC Flyer 7" tablet - if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1)) - return $this->true; - else - return $this->false; + + return $this->false; } //************************** @@ -344,20 +368,20 @@ class uagent_info if ($this->initCompleted == $this->true || $this->isAndroidPhone == $this->true) return $this->isAndroidPhone; - - if (($this->DetectAndroid() == $this->true) && - (stripos($this->useragent, $this->mobile) > -1)) - return $this->true; - - //Special check for Android phones with Opera Mobile. They should report here. - if (($this->DetectOperaAndroidPhone() == $this->true)) - return $this->true; - //Special check for the HTC Flyer 7" tablet. It should report here. - if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1)) - return $this->true; - - else + + //First, let's make sure we're on an Android device. + if ($this->DetectAndroid() == $this->false) return $this->false; + + //If it's Android and has 'mobile' in it, Google says it's a phone. + if (stripos($this->useragent, $this->mobile) > -1) + return $this->true; + + //Special check for Android devices with Opera Mobile/Mini. They should report here. + if (($this->DetectOperaMobile() == $this->true)) + return $this->true; + + return $this->false; } //************************** @@ -369,12 +393,9 @@ class uagent_info if ($this->DetectAndroid() == $this->false) return $this->false; - //Special check for Opera Android Phones. They should NOT report here. + //Special check for Android devices with Opera Mobile/Mini. They should NOT report here. if ($this->DetectOperaMobile() == $this->true) return $this->false; - //Special check for the HTC Flyer 7" tablet. It should NOT report here. - if ((stripos($this->useragent, $this->deviceHtcFlyer) > -1)) - return $this->false; //Otherwise, if it's Android and does NOT have 'mobile' in it, Google says it's a tablet. if (stripos($this->useragent, $this->mobile) > -1) @@ -421,19 +442,20 @@ class uagent_info //************************** - // Detects if the current browser is EITHER a - // Windows Phone 7.x OR 8 device. + // Detects if the current browser is a + // Windows Phone 7, 8, or 10 device. function DetectWindowsPhone() { - if (($this->DetectWindowsPhone8() == $this->true) - || ($this->DetectWindowsPhone7() == $this->true)) + if (($this->DetectWindowsPhone7() == $this->true) + || ($this->DetectWindowsPhone8() == $this->true) + || ($this->DetectWindowsPhone10() == $this->true)) return $this->true; else return $this->false; } //************************** - // Detects a Windows Phone 7.x device (in mobile browsing mode). + // Detects a Windows Phone 7 device (in mobile browsing mode). function DetectWindowsPhone7() { if (stripos($this->useragent, $this->deviceWinPhone7) > -1) @@ -452,6 +474,16 @@ class uagent_info return $this->false; } + //************************** + // Detects a Windows Phone 10 device (in mobile browsing mode). + function DetectWindowsPhone10() + { + if (stripos($this->useragent, $this->deviceWinPhone10) > -1) + return $this->true; + else + return $this->false; + } + //************************** // Detects if the current browser is a Windows Mobile device. // Excludes Windows Phone 7 and later devices. @@ -632,15 +664,17 @@ class uagent_info // Detects if the current browser is on a PalmOS device. function DetectPalmOS() { - //Make sure it's not WebOS first - if ($this->DetectPalmWebOS() == $this->true) - return $this->false; - //Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino. if (stripos($this->useragent, $this->devicePalm) > -1 || stripos($this->useragent, $this->engineBlazer) > -1 || stripos($this->useragent, $this->engineXiino) > -1) + { + //Make sure it's not WebOS first + if ($this->DetectPalmWebOS() == $this->true) + return $this->false; + else return $this->true; + } else return $this->false; } @@ -668,48 +702,28 @@ class uagent_info return $this->false; } + //************************** + // Detects if the current browser is on a WebOS smart TV. + function DetectWebOSTV() + { + if ((stripos($this->useragent, $this->deviceWebOStv) > -1) + && (stripos($this->useragent, $this->smartTV2) > -1)) + return $this->true; + else + return $this->false; + } //************************** // Detects if the current browser is Opera Mobile or Mini. function DetectOperaMobile() { - if (stripos($this->useragent, $this->engineOpera) > -1) - { - if ((stripos($this->useragent, $this->mini) > -1) || - (stripos($this->useragent, $this->mobi) > -1)) + if ((stripos($this->useragent, $this->engineOpera) > -1) && + ((stripos($this->useragent, $this->mini) > -1) || + (stripos($this->useragent, $this->mobi) > -1))) return $this->true; - else - return $this->false; - } - else - return $this->false; - } - //************************** - // Detects if the current browser is Opera Mobile - // running on an Android phone. - function DetectOperaAndroidPhone() - { - if ((stripos($this->useragent, $this->engineOpera) > -1) && - (stripos($this->useragent, $this->deviceAndroid) > -1) && - (stripos($this->useragent, $this->mobi) > -1)) - return $this->true; - else - return $this->false; - } - - //************************** - // Detects if the current browser is Opera Mobile - // running on an Android tablet. - function DetectOperaAndroidTablet() - { - if ((stripos($this->useragent, $this->engineOpera) > -1) && - (stripos($this->useragent, $this->deviceAndroid) > -1) && - (stripos($this->useragent, $this->deviceTablet) > -1)) - return $this->true; - else - return $this->false; + return $this->false; } //************************** @@ -746,7 +760,7 @@ class uagent_info } //************************** - // Detects a device running the Bada smartphone OS from Samsung. + // Detects a device running the Bada OS from Samsung. function DetectBada() { if (stripos($this->useragent, $this->deviceBada) > -1) @@ -759,7 +773,19 @@ class uagent_info // Detects a device running the Tizen smartphone OS. function DetectTizen() { - if (stripos($this->useragent, $this->deviceTizen) > -1) + if ((stripos($this->useragent, $this->deviceTizen) > -1) + && (stripos($this->useragent, $this->mobile) > -1)) + return $this->true; + else + return $this->false; + } + + //************************** + // Detects if the current browser is on a Tizen smart TV. + function DetectTizenTV() + { + if ((stripos($this->useragent, $this->deviceTizen) > -1) + && (stripos($this->useragent, $this->smartTV1) > -1)) return $this->true; else return $this->false; @@ -774,7 +800,117 @@ class uagent_info else return $this->false; } + + //************************** + // Detects a phone running the Meego OS. + function DetectMeegoPhone() + { + if ((stripos($this->useragent, $this->deviceMeego) > -1) + && (stripos($this->useragent, $this->mobi) > -1)) + return $this->true; + else + return $this->false; + } + //************************** + // Detects a mobile device (probably) running the Firefox OS. + function DetectFirefoxOS() + { + if (($this->DetectFirefoxOSPhone() == $this->true) + || ($this->DetectFirefoxOSTablet() == $this->true)) + return $this->true; + else + return $this->false; + } + + //************************** + // Detects a phone (probably) running the Firefox OS. + function DetectFirefoxOSPhone() + { + //First, let's make sure we're NOT on another major mobile OS. + if ($this->DetectIos() == $this->true + || $this->DetectAndroid() == $this->true + || $this->DetectSailfish() == $this->true) + return $this->false; + + if ((stripos($this->useragent, $this->engineFirefox) > -1) && + (stripos($this->useragent, $this->mobile) > -1)) + return $this->true; + + return $this->false; + } + + //************************** + // Detects a tablet (probably) running the Firefox OS. + function DetectFirefoxOSTablet() + { + //First, let's make sure we're NOT on another major mobile OS. + if ($this->DetectIos() == $this->true + || $this->DetectAndroid() == $this->true + || $this->DetectSailfish() == $this->true) + return $this->false; + + if ((stripos($this->useragent, $this->engineFirefox) > -1) && + (stripos($this->useragent, $this->deviceTablet) > -1)) + return $this->true; + + return $this->false; + } + + //************************** + // Detects a device running the Sailfish OS. + function DetectSailfish() + { + if (stripos($this->useragent, $this->deviceSailfish) > -1) + return $this->true; + else + return $this->false; + } + + //************************** + // Detects a phone running the Sailfish OS. + function DetectSailfishPhone() + { + if (($this->DetectSailfish() == $this->true) && + (stripos($this->useragent, $this->mobile) > -1)) + return $this->true; + + return $this->false; + } + + //************************** + // Detects a mobile device running the Ubuntu Mobile OS. + function DetectUbuntu() + { + if (($this->DetectUbuntuPhone() == $this->true) + || ($this->DetectUbuntuTablet() == $this->true)) + return $this->true; + else + return $this->false; + } + + //************************** + // Detects a phone running the Ubuntu Mobile OS. + function DetectUbuntuPhone() + { + if ((stripos($this->useragent, $this->deviceUbuntu) > -1) && + (stripos($this->useragent, $this->mobile) > -1)) + return $this->true; + + return $this->false; + } + + //************************** + // Detects a tablet running the Ubuntu Mobile OS. + function DetectUbuntuTablet() + { + if ((stripos($this->useragent, $this->deviceUbuntu) > -1) && + (stripos($this->useragent, $this->deviceTablet) > -1)) + return $this->true; + + return $this->false; + } + //************************** // Detects the Danger Hiptop device. function DetectDangerHiptop() @@ -829,9 +965,11 @@ class uagent_info // Includes many handheld consoles. function DetectGameConsole() { - if (($this->DetectSonyPlaystation() == $this->true) || - ($this->DetectNintendo() == $this->true) || - ($this->DetectXbox() == $this->true)) + if ($this->DetectSonyPlaystation() == $this->true) + return $this->true; + else if ($this->DetectNintendo() == $this->true) + return $this->true; + else if ($this->DetectXbox() == $this->true) return $this->true; else return $this->false; @@ -930,6 +1068,7 @@ class uagent_info || ($this->DetectSymbianOS() == $this->true) || ($this->DetectWindowsMobile() == $this->true) || ($this->DetectBlackBerry() == $this->true) + || ($this->DetectMeegoPhone() == $this->true) || ($this->DetectPalmWebOS() == $this->true)) return $this->true; else @@ -942,49 +1081,40 @@ class uagent_info // as well as smartphone-class devices. Excludes Apple iPads and other modern tablets. function DetectMobileQuick() { - //Let's exclude tablets - if ($this->isTierTablet == $this->true) - return $this->false; - if ($this->initCompleted == $this->true || $this->isMobilePhone == $this->true) return $this->isMobilePhone; + //Let's exclude tablets + if ($this->isTierTablet == $this->true) + return $this->false; + //Most mobile browsing is done on smartphones if ($this->DetectSmartphone() == $this->true) return $this->true; - if (stripos($this->useragent, $this->mobile) > -1) + //Catch-all for many mobile devices + if (stripos($this->useragent, $this->mobile) > -1) return $this->true; - if (($this->DetectWapWml() == $this->true) - || ($this->DetectBrewDevice() == $this->true) - || ($this->DetectOperaMobile() == $this->true)) + if ($this->DetectOperaMobile() == $this->true) return $this->true; - - if ((stripos($this->useragent, $this->engineObigo) > -1) - || (stripos($this->useragent, $this->engineNetfront) > -1) - || (stripos($this->useragent, $this->engineUpBrowser) > -1) - || (stripos($this->useragent, $this->engineOpenWeb) > -1)) - return $this->true; - - if (($this->DetectDangerHiptop() == $this->true) - || ($this->DetectMidpCapable() == $this->true) - || ($this->DetectMaemoTablet() == $this->true) - || ($this->DetectArchos() == $this->true)) - return $this->true; - if ((stripos($this->useragent, $this->devicePda) > -1) && - !(stripos($this->useragent, $this->disUpdate) > -1)) - return $this->true; - //We also look for Kindle devices if ($this->DetectKindle() == $this->true || $this->DetectAmazonSilk() == $this->true) return $this->true; - else - return $this->false; + if (($this->DetectWapWml() == $this->true) + || ($this->DetectMidpCapable() == $this->true) + || ($this->DetectBrewDevice() == $this->true)) + return $this->true; + + if ((stripos($this->useragent, $this->engineNetfront) > -1) + || (stripos($this->useragent, $this->engineUpBrowser) > -1)) + return $this->true; + + return $this->false; } //************************** @@ -1000,28 +1130,29 @@ class uagent_info return $this->true; if ($this->DetectGameConsole() == $this->true) return $this->true; - if ($this->DetectSonyMylo() == $this->true) + + if (($this->DetectDangerHiptop() == $this->true) + || ($this->DetectMaemoTablet() == $this->true) + || ($this->DetectSonyMylo() == $this->true) + || ($this->DetectArchos() == $this->true)) return $this->true; + if ((stripos($this->useragent, $this->devicePda) > -1) && + !(stripos($this->useragent, $this->disUpdate) > -1)) + return $this->true; + //Detect older phones from certain manufacturers and operators. - if (stripos($this->useragent, $this->uplink) > -1) - return $this->true; - if (stripos($this->useragent, $this->manuSonyEricsson) > -1) - return $this->true; - if (stripos($this->useragent, $this->manuericsson) > -1) - return $this->true; - if (stripos($this->useragent, $this->manuSamsung1) > -1) + if ((stripos($this->useragent, $this->uplink) > -1) + || (stripos($this->useragent, $this->engineOpenWeb) > -1) + || (stripos($this->useragent, $this->manuSamsung1) > -1) + || (stripos($this->useragent, $this->manuSonyEricsson) > -1) + || (stripos($this->useragent, $this->manuericsson) > -1) + || (stripos($this->useragent, $this->svcDocomo) > -1) + || (stripos($this->useragent, $this->svcKddi) > -1) + || (stripos($this->useragent, $this->svcVodafone) > -1)) return $this->true; - if (stripos($this->useragent, $this->svcDocomo) > -1) - return $this->true; - if (stripos($this->useragent, $this->svcKddi) > -1) - return $this->true; - if (stripos($this->useragent, $this->svcVodafone) > -1) - return $this->true; - - else - return $this->false; + return $this->false; } @@ -1043,6 +1174,8 @@ class uagent_info if (($this->DetectIpad() == $this->true) || ($this->DetectAndroidTablet() == $this->true) || ($this->DetectBlackBerryTablet() == $this->true) + || ($this->DetectFirefoxOSTablet() == $this->true) + || ($this->DetectUbuntuTablet() == $this->true) || ($this->DetectWebOSTablet() == $this->true)) return $this->true; else @@ -1054,7 +1187,7 @@ class uagent_info // The quick way to detect for a tier of devices. // This method detects for devices which can // display iPhone-optimized web content. - // Includes iPhone, iPod Touch, Android, Windows Phone 7 and 8, BB10, WebOS, Playstation Vita, etc. + // Includes iPhone, iPod Touch, Android, Windows Phone, BB10, Playstation Vita, etc. function DetectTierIphone() { if ($this->initCompleted == $this->true || @@ -1068,6 +1201,9 @@ class uagent_info || ($this->DetectPalmWebOS() == $this->true) || ($this->DetectBada() == $this->true) || ($this->DetectTizen() == $this->true) + || ($this->DetectFirefoxOSPhone() == $this->true) + || ($this->DetectSailfishPhone() == $this->true) + || ($this->DetectUbuntuPhone() == $this->true) || ($this->DetectGamingHandheld() == $this->true)) return $this->true;