e; } $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( self::is_opera_mini() ) { if ( strpos( $ua, 'android' ) !== false || strpos( $ua, 'iphone' ) !== false || strpos( $ua, 'ipod' ) !== false || strpos( $ua, 'ipad' ) !== false || strpos( $ua, 'blackberry' ) !== false ) { return false; } else { return true; } } else { return false; } } /** * Detects if the current browser is Opera Mobile or Mini. * DEPRECATED: use is_opera_mobile or is_opera_mini * * Opera Mini 5 Beta: Opera/9.80 (J2ME/MIDP; Opera Mini/5.0.15650/756; U; en) Presto/2.2.0 * Opera Mini 8: Opera/8.01 (J2ME/MIDP; Opera Mini/3.0.6306/1528; en; U; ssr) */ public static function is_OperaMobile() { _deprecated_function( __FUNCTION__, 'always', 'is_opera_mini() or is_opera_mobile()' ); if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( strpos( $ua, 'opera' ) !== false ) { if ( ( strpos( $ua, 'mini' ) !== false ) || ( strpos( $ua, 'mobi' ) !== false ) ) { return true; } else { return false; } } else { return false; } } /** * Detects if the current browser is a Windows Phone 7 device. * ex: Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910) */ public static function is_WindowsPhone7() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( false === strpos( $ua, 'windows phone os 7' ) ) { return false; } else { if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } else { return true; } } } /** * Detects if the current browser is a Windows Phone 8 device. * ex: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; ARM; Touch; IEMobile/10.0; ; [;]) */ public static function is_windows_phone_8() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( strpos( $ua, 'windows phone 8' ) === false ) { return false; } else { return true; } } /** * Detects if the current browser is on a Palm device running the new WebOS. This EXCLUDES TouchPad. * * Ex1: Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1 * Ex2: Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pixi/1.1 */ public static function is_PalmWebOS() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( false === strpos( $ua, 'webos' ) ) { return false; } else { if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } else { return true; } } } /** * Detects if the current browser is the HP TouchPad default browser. This excludes phones wt WebOS. * * TouchPad Emulator: Mozilla/5.0 (hp-desktop; Linux; hpwOS/2.0; U; it-IT) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 Desktop/1.0 * TouchPad: Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0 */ public static function is_TouchPad() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $http_user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( false !== strpos( $http_user_agent, 'hp-tablet' ) || false !== strpos( $http_user_agent, 'hpwos' ) || false !== strpos( $http_user_agent, 'touchpad' ) ) { if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } else { return true; } } else { return false; } } /** * Detects if the current browser is the Series 60 Open Source Browser. * * OSS Browser 3.2 on E75: Mozilla/5.0 (SymbianOS/9.3; U; Series60/3.2 NokiaE75-1/110.48.125 Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413 * * 7.0 Browser (Nokia 5800 XpressMusic (v21.0.025)) : Mozilla/5.0 (SymbianOS/9.4; U; Series60/5.0 Nokia5800d-1/21.0.025; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413 * * Browser 7.1 (Nokia N97 (v12.0.024)) : Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/12.0.024; Profile/MIDP-2.1 Configuration/CLDC-1.1; en-us) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.12344 */ public static function is_S60_OSSBrowser() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } $pos_webkit = strpos( $agent, 'webkit' ); if ( false !== $pos_webkit ) { // First, test for WebKit, then make sure it's either Symbian or S60. if ( strpos( $agent, 'symbian' ) !== false || strpos( $agent, 'series60' ) !== false ) { return true; } else { return false; } } elseif ( strpos( $agent, 'symbianos' ) !== false && strpos( $agent, 'series60' ) !== false ) { return true; } elseif ( strpos( $agent, 'nokia' ) !== false && strpos( $agent, 'series60' ) !== false ) { return true; } return false; } /** * Detects if the device platform is the Symbian Series 60. */ public static function is_symbian_platform() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_webkit = strpos( $agent, 'webkit' ); if ( false !== $pos_webkit ) { // First, test for WebKit, then make sure it's either Symbian or S60. if ( strpos( $agent, 'symbian' ) !== false || strpos( $agent, 'series60' ) !== false ) { return true; } else { return false; } } elseif ( strpos( $agent, 'symbianos' ) !== false && strpos( $agent, 'series60' ) !== false ) { return true; } elseif ( strpos( $agent, 'nokia' ) !== false && strpos( $agent, 'series60' ) !== false ) { return true; } elseif ( strpos( $agent, 'opera mini' ) !== false ) { if ( strpos( $agent, 'symbianos' ) !== false || strpos( $agent, 'symbos' ) !== false || strpos( $agent, 'series 60' ) !== false ) { return true; } } return false; } /** * Detects if the device platform is the Symbian Series 40. * Nokia Browser for Series 40 is a proxy based browser, previously known as Ovi Browser. * This browser will report 'NokiaBrowser' in the header, however some older version will also report 'OviBrowser'. */ public static function is_symbian_s40_platform() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( strpos( $agent, 'series40' ) !== false ) { if ( strpos( $agent, 'nokia' ) !== false || strpos( $agent, 'ovibrowser' ) !== false || strpos( $agent, 'nokiabrowser' ) !== false ) { return true; } } return false; } /** * Returns if the device belongs to J2ME capable family. * * @return bool */ public static function is_J2ME_platform() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( strpos( $agent, 'j2me/midp' ) !== false ) { return true; } elseif ( strpos( $agent, 'midp' ) !== false && strpos( $agent, 'cldc' ) ) { return true; } return false; } /** * Detects if the current UA is on one of the Maemo-based Nokia Internet Tablets. */ public static function is_MaemoTablet() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_maemo = strpos( $agent, 'maemo' ); if ( false === $pos_maemo ) { return false; } // Must be Linux + Tablet, or else it could be something else. if ( strpos( $agent, 'tablet' ) !== false && strpos( $agent, 'linux' ) !== false ) { if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } else { return true; } } else { return false; } } /** * Detects if the current UA is a MeeGo device (Nokia Smartphone). */ public static function is_MeeGo() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( false === strpos( $ua, 'meego' ) ) { return false; } else { if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } else { return true; } } } /** * The is_webkit() method can be used to check the User Agent for an webkit generic browser. */ public static function is_webkit() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_webkit = strpos( $agent, 'webkit' ); if ( false !== $pos_webkit ) { return true; } else { return false; } } /** * Detects if the current browser is the Native Android browser. * * @return boolean true if the browser is Android otherwise false */ public static function is_android() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_android = strpos( $agent, 'android' ); if ( false !== $pos_android ) { if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } else { return true; } } else { return false; } } /** * Detects if the current browser is the Native Android Tablet browser. * Assumes 'Android' should be in the user agent, but not 'mobile' * * @return boolean true if the browser is Android and not 'mobile' otherwise false */ public static function is_android_tablet() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_android = strpos( $agent, 'android' ); $pos_mobile = strpos( $agent, 'mobile' ); $post_android_app = strpos( $agent, 'wp-android' ); if ( false !== $pos_android && false === $pos_mobile && false === $post_android_app ) { if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } else { return true; } } else { return false; } } /** * Detects if the current browser is the Kindle Fire Native browser. * * Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true * Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=false * * @return boolean true if the browser is Kindle Fire Native browser otherwise false */ public static function is_kindle_fire() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_silk = strpos( $agent, 'silk/' ); $pos_silk_acc = strpos( $agent, 'silk-accelerated=' ); if ( false !== $pos_silk && false !== $pos_silk_acc ) { return true; } else { return false; } } /** * Detects if the current browser is the Kindle Touch Native browser * * Mozilla/5.0 (X11; U; Linux armv7l like Android; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/533.2+ Kindle/3.0+ * * @return boolean true if the browser is Kindle monochrome Native browser otherwise false */ public static function is_kindle_touch() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_kindle_touch = strpos( $agent, 'kindle/3.0+' ); if ( false !== $pos_kindle_touch && false === self::is_kindle_fire() ) { return true; } else { return false; } } /** * Detect if user agent is the WordPress.com Windows 8 app (used ONLY on the custom oauth stylesheet) */ public static function is_windows8_auth() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos = strpos( $agent, 'msauthhost' ); if ( false !== $pos ) { return true; } else { return false; } } /** * Detect if user agent is the WordPress.com Windows 8 app. */ public static function is_wordpress_for_win8() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos = strpos( $agent, 'wp-windows8' ); if ( false !== $pos ) { return true; } else { return false; } } /** * Detect if user agent is the WordPress.com Desktop app. */ public static function is_wordpress_desktop_app() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos = strpos( $agent, 'WordPressDesktop' ); if ( false !== $pos ) { return true; } else { return false; } } /** * The is_blackberry_tablet() method can be used to check the User Agent for a RIM blackberry tablet. * The user agent of the BlackBerry® Tablet OS follows a format similar to the following: * Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/0.0.1 Safari/534.8+ */ public static function is_blackberry_tablet() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_playbook = stripos( $agent, 'PlayBook' ); $pos_rim_tablet = stripos( $agent, 'RIM Tablet' ); if ( ( false === $pos_playbook ) || ( false === $pos_rim_tablet ) ) { return false; } else { return true; } } /** * The is_blackbeberry() method can be used to check the User Agent for a blackberry device. * Note that opera mini on BB matches this rule. */ public static function is_blackbeberry() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_blackberry = strpos( $agent, 'blackberry' ); if ( false !== $pos_blackberry ) { if ( self::is_opera_mini() || self::is_opera_mobile() || self::is_firefox_mobile() ) { return false; } else { return true; } } else { return false; } } /** * The is_blackberry_10() method can be used to check the User Agent for a BlackBerry 10 device. */ public static function is_blackberry_10() { $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); return ( strpos( $agent, 'bb10' ) !== false ) && ( strpos( $agent, 'mobile' ) !== false ); } /** * Retrieve the blackberry OS version. * * Return strings are from the following list: * - blackberry-10 * - blackberry-7 * - blackberry-6 * - blackberry-torch //only the first edition. The 2nd edition has the OS7 onboard and doesn't need any special rule. * - blackberry-5 * - blackberry-4.7 * - blackberry-4.6 * - blackberry-4.5 * * @return string Version of the BB OS. * If version is not found, get_blackbeberry_OS_version will return boolean false. */ public static function get_blackbeberry_OS_version() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } if ( self::is_blackberry_10() ) { return 'blackberry-10'; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); $pos_blackberry = stripos( $agent, 'blackberry' ); if ( false === $pos_blackberry ) { // Not a blackberry device. return false; } // Blackberry devices OS 6.0 or higher. // Mozilla/5.0 (BlackBerry; U; BlackBerry 9670; en) AppleWebKit/534.3+ (KHTML, like Gecko) Version/6.0.0.286 Mobile Safari/534.3+. // Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+. // Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0 Mobile Safari/534.11+. $pos_webkit = stripos( $agent, 'webkit' ); if ( false !== $pos_webkit ) { // Detected blackberry webkit browser. $pos_torch = stripos( $agent, 'BlackBerry 9800' ); if ( false !== $pos_torch ) { return 'blackberry-torch'; // Match the torch first edition. the 2nd edition should use the OS7 and doesn't need any special rule. } else { // Detecting the BB OS version for devices running OS 6.0 or higher. if ( preg_match( '#Version\/([\d\.]+)#i', $agent, $matches ) ) { $version = $matches[1]; $version_num = explode( '.', $version ); if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) { return 'blackberry-6'; // not a BB device that match our rule. } else { return 'blackberry-' . $version_num[0]; } } else { // if doesn't match returns the minimun version with a webkit browser. we should never fall here. return 'blackberry-6'; // not a BB device that match our rule. } } } // Blackberry devices <= 5.XX. // BlackBerry9000/5.0.0.93 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/179. if ( preg_match( '#BlackBerry\w+\/([\d\.]+)#i', $agent, $matches ) ) { $version = $matches[1]; } else { return false; // not a BB device that match our rule. } $version_num = explode( '.', $version ); if ( is_array( $version_num ) === false || count( $version_num ) <= 1 ) { return false; } $version_num_major = (int) $version_num[0]; $version_num_minor = (int) $version_num[1]; if ( 5 === $version_num_major ) { return 'blackberry-5'; } elseif ( 4 === $version_num_major && 7 === $version_num_minor ) { return 'blackberry-4.7'; } elseif ( 4 === $version_num_major && 6 === $version_num_minor ) { return 'blackberry-4.6'; } elseif ( 4 === $version_num_major && 5 === $version_num_minor ) { return 'blackberry-4.5'; } else { return false; } } /** * Retrieve the blackberry browser version. * * Return string are from the following list: * - blackberry-10 * - blackberry-webkit * - blackberry-5 * - blackberry-4.7 * - blackberry-4.6 * * @return string Type of the BB browser. * If browser's version is not found, detect_blackbeberry_browser_version will return boolean false. */ public static function detect_blackberry_browser_version() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( self::is_blackberry_10() ) { return 'blackberry-10'; } $pos_blackberry = strpos( $agent, 'blackberry' ); if ( false === $pos_blackberry ) { // Not a blackberry device. return false; } $pos_webkit = strpos( $agent, 'webkit' ); if ( ! ( false === $pos_webkit ) ) { return 'blackberry-webkit'; } else { if ( ! preg_match( '#BlackBerry\w+\/([\d\.]+)#i', $agent, $matches ) ) { return false; // not a BB device that match our rule. } $version_num = explode( '.', $matches[1] ); if ( false === is_array( $version_num ) || count( $version_num ) <= 1 ) { return false; } $version_num_major = (int) $version_num[0]; $version_num_minor = (int) $version_num[1]; if ( 5 === $version_num_major ) { return 'blackberry-5'; } elseif ( 4 === $version_num_major && 7 === $version_num_minor ) { return 'blackberry-4.7'; } elseif ( 4 === $version_num_major && 6 === $version_num_minor ) { return 'blackberry-4.6'; } else { // A very old BB device is found or this is a BB device that doesn't match our rules. return false; } } } /** * Checks if a visitor is coming from one of the WordPress mobile apps. * * @return bool */ public static function is_mobile_app() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( isset( $_SERVER['X_USER_AGENT'] ) && preg_match( '|wp-webos|', $_SERVER['X_USER_AGENT'] ) ) { return true; // Wp4webos 1.1 or higher. } $app_agents = array( 'wp-android', 'wp-blackberry', 'wp-iphone', 'wp-nokia', 'wp-webos', 'wp-windowsphone' ); // the mobile reader on iOS has an incorrect UA when loading the reader // currently it is the default one provided by the iOS framework which // causes problems with 2-step-auth // User-Agent WordPress/3.1.4 CFNetwork/609 Darwin/13.0.0. $app_agents[] = 'wordpress/3.1'; foreach ( $app_agents as $app_agent ) { if ( false !== strpos( $agent, $app_agent ) ) { return true; } } return false; } /** * Detects if the current browser is Nintendo 3DS handheld. * * Example: Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7498.US * can differ in language, version and region */ public static function is_Nintendo_3DS() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = strtolower( $_SERVER['HTTP_USER_AGENT'] ); if ( strpos( $ua, 'nintendo 3ds' ) !== false ) { return true; } return false; } /** * Was the current request made by a known bot? * * @return boolean */ public static function is_bot() { static $is_bot = null; if ( is_null( $is_bot ) ) { $is_bot = self::is_bot_user_agent( $_SERVER['HTTP_USER_AGENT'] ); } return $is_bot; } /** * Is the given user-agent a known bot? * If you want an is_bot check for the current request's UA, use is_bot() instead of passing a user-agent to this method. * * @param string $ua A user-agent string. * * @return boolean */ public static function is_bot_user_agent( $ua = null ) { if ( empty( $ua ) ) { return false; } $bot_agents = array( 'alexa', 'altavista', 'ask jeeves', 'attentio', 'baiduspider', 'bingbot', 'chtml generic', 'crawler', 'fastmobilecrawl', 'feedfetcher-google', 'firefly', 'froogle', 'gigabot', 'googlebot', 'googlebot-mobile', 'heritrix', 'httrack', 'ia_archiver', 'irlbot', 'iescholar', 'infoseek', 'jumpbot', 'linkcheck', 'lycos', 'mediapartners', 'mediobot', 'motionbot', 'msnbot', 'mshots', 'openbot', 'pss-webkit-request', 'pythumbnail', 'scooter', 'slurp', 'snapbot', 'spider', 'taptubot', 'technoratisnoop', 'teoma', 'twiceler', 'yahooseeker', 'yahooysmcm', 'yammybot', 'ahrefsbot', 'pingdom.com_bot', 'kraken', 'yandexbot', 'twitterbot', 'tweetmemebot', 'openhosebot', 'queryseekerspider', 'linkdexbot', 'grokkit-crawler', 'livelapbot', 'germcrawler', 'domaintunocrawler', 'grapeshotcrawler', 'cloudflare-alwaysonline', ); foreach ( $bot_agents as $bot_agent ) { if ( false !== stripos( $ua, $bot_agent ) ) { return true; } } return false; } }