Permalink
Browse files

Removing constant REQUEST_MOBILE_UA, and added variable $mobileUA ins…

…tead for mobile browser detection. Also added new user agent string 'webOS', closes #457
  • Loading branch information...
ADmad committed Mar 14, 2010
1 parent 4c7b62b commit 70d0c642836504949a7ac07ad267a621b2399a73
@@ -20,10 +20,6 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-if (!defined('REQUEST_MOBILE_UA')) {
- define('REQUEST_MOBILE_UA', '(Android|iPod|iPhone|MIDP|AvantGo|BlackBerry|J2ME|Opera Mini|DoCoMo|NetFront|Nokia|PalmOS|PalmSource|portalmmm|Plucker|ReqwirelessWeb|SonyEricsson|Symbian|UP\.Browser|Windows CE|Xiino)');
-}
-
/**
* Request object for handling HTTP requests
*
@@ -105,6 +101,37 @@ class RequestHandlerComponent extends Object {
'tar' => 'application/x-tar'
);
+/**
+ * List of regular expressions for matching mobile device's user agent string
+ *
+ * @var array
+ * @access public
+ */
+ var $mobileUA = array(
+ 'Android',
+ 'AvantGo',
+ 'BlackBerry',
+ 'DoCoMo',
+ 'iPod',
+ 'iPhone',
+ 'J2ME',
+ 'MIDP',
+ 'NetFront',
+ 'Nokia',
+ 'Opera Mini',
+ 'PalmOS',
+ 'PalmSource',
+ 'portalmmm',
+ 'Plucker',
+ 'ReqwirelessWeb',
+ 'SonyEricsson',
+ 'Symbian',
+ 'UP\.Browser',
+ 'webOS',
+ 'Windows CE',
+ 'Xiino'
+ );
+
/**
* Content-types accepted by the client. If extension parsing is enabled in the
* Router, and an extension is detected, the corresponding content-type will be
@@ -314,10 +341,16 @@ function isAtom() {
*
* @return boolean True if user agent is a mobile web browser
* @access public
+ * @deprecated Use of constant REQUEST_MOBILE_UA is deprecated and will be removed in future versions
*/
function isMobile() {
- preg_match('/' . REQUEST_MOBILE_UA . '/i', env('HTTP_USER_AGENT'), $match);
- if (!empty($match) || $this->accepts('wap')) {
+ if (defined('REQUEST_MOBILE_UA')) {
+ $regex = '/' . REQUEST_MOBILE_UA . '/i';
+ } else {
+ $regex = '/' . implode('|', $this->mobileUA) . '/i';
+ }
+
+ if (preg_match($regex, env('HTTP_USER_AGENT')) || $this->accepts('wap')) {
return true;
}
return false;
@@ -427,8 +427,14 @@ function testResponseContentType() {
*/
function testMobileDeviceDetection() {
$this->assertFalse($this->RequestHandler->isMobile());
+
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3';
$this->assertTrue($this->RequestHandler->isMobile());
+
+ $_SERVER['HTTP_USER_AGENT'] = 'Some imaginary UA';
+ $this->RequestHandler->mobileUA []= 'imaginary';
+ $this->assertTrue($this->RequestHandler->isMobile());
+ array_pop($this->RequestHandler->mobileUA);
}
/**

0 comments on commit 70d0c64

Please sign in to comment.