function get_device_name() { // Do the most exhaustive device detection possible; other method calls // may be used instead of DetectMobileLong if you want to target a narrower // class of devices. $mobile = new uagent_info(); if ($mobile->DetectKindle()) { return 'Kindle'; } elseif ($mobile->DetectKindleFire() || $mobile->DetectAmazonSilk()) { return 'Kindle Fire'; } elseif ($mobile->DetectIpad()) { return 'iPad'; } elseif ($mobile->DetectIphone()) { return 'iPhone'; } elseif ($mobile->DetectMac()) { return 'Mac'; } elseif ($mobile->DetectAndroidPhone()) { return 'Android Phone'; } elseif ($mobile->DetectAndroidTablet()) { return 'Android Tablet'; } elseif ($mobile->DetectBlackBerry()) { return 'BlackBerry'; } elseif ($mobile->DetectGoogleTV()) { return 'Google TV'; } elseif ($mobile->DetectIos()) { return 'iOS'; } else { return 'PC'; } }
/** * Device Detection * * Detect the user's device by using the MobileESP library written by Anthony Hand [http://blog.mobileesp.com/]. * Return the string name of their device. * * @internal Called during object instantiation * @uses get_option, uagent_info * @param void * @return string The current user's device in one of four options: * active, handheld, tablet, low_support */ public function detect_users_device() { //Default is active (default computer theme set by the admin) until it's overridden $device = 'active'; $low_support_device = 'handheld'; $low_support_theme = get_option('dts_low_support_theme'); // Give the handheld theme to any low_support device // UNLESS one has been set in the admin already if (!empty($low_support_theme) && is_array($low_support_theme)) { if (isset($low_support_theme['name'])) { if (!empty($low_support_theme['name'])) { //Detect if the device is a low support device (poor css and javascript rendering / older devices) $low_support_device = 'low_support'; } // end if } // end if } // end if // Check for Varnish Device Detect: https://github.com/varnish/varnish-devicedetect/ // Thanks to Tim Broder for this addition! https://github.com/broderboy | http://timbroder.com/ $http_xua_handheld_devices = array('mobile-iphone', 'mobile-android', 'mobile-firefoxos', 'mobile-smartphone', 'mobile-generic'); $http_xua_tablet_devices = array('tablet-ipad', 'tablet-android'); // Determine if the HTTP X UA server variable is present if (isset($_SERVER['HTTP_X_UA_DEVICE'])) { // if it is, determine which device type is being used if (in_array($_SERVER['HTTP_X_UA_DEVICE'], $http_xua_handheld_devices)) { $device = 'handheld'; } elseif (in_array($_SERVER['HTTP_X_UA_DEVICE'], $http_xua_tablet_devices)) { $device = 'tablet'; } } else { // DEFAULT ACTION - Use MobileESP to sniff the UserAgent string // Include the MobileESP code library for acertaining device user agents include_once 'mobile-esp.php'; // Setup the MobileESP Class $ua = new uagent_info(); // Detect if the device is a handheld if ($ua->DetectSmartphone() || $ua->DetectTierRichCss()) { $device = 'handheld'; } // Detect if the device is a tablet if ($ua->DetectTierTablet() || $ua->DetectKindle() || $ua->DetectAmazonSilk()) { $device = 'tablet'; } // Detect if the device is a low_support device (poor javascript and css support / text-only) if ($ua->DetectBlackBerryLow() || $ua->DetectTierOtherPhones()) { $device = $low_support_device; } } // end if // Return the user's device return $device; }