web/lib/Zend/Http/UserAgent/Mobile.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Http
    16  * @package    Zend_Http
    17  * @subpackage UserAgent
    17  * @subpackage UserAgent
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  */
    20  */
    21 
    21 
    22 require_once 'Zend/Http/UserAgent/AbstractDevice.php';
    22 require_once 'Zend/Http/UserAgent/AbstractDevice.php';
    23 
    23 
    25  * Mobile browser type matcher
    25  * Mobile browser type matcher
    26  *
    26  *
    27  * @category   Zend
    27  * @category   Zend
    28  * @package    Zend_Http
    28  * @package    Zend_Http
    29  * @subpackage UserAgent
    29  * @subpackage UserAgent
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    30  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    32  */
    32  */
    33 class Zend_Http_UserAgent_Mobile extends Zend_Http_UserAgent_AbstractDevice
    33 class Zend_Http_UserAgent_Mobile extends Zend_Http_UserAgent_AbstractDevice
    34 {
    34 {
    35 
    35 
    36     const DEFAULT_FEATURES_ADAPTER_CLASSNAME = 'Zend_Http_UserAgent_Features_Adapter_WurflApi';
    36     const DEFAULT_FEATURES_ADAPTER_CLASSNAME = 'Zend_Http_UserAgent_Features_Adapter_Browscap';
    37 
    37 
    38     const DEFAULT_FEATURES_ADAPTER_PATH = 'Zend/Http/UserAgent/Features/Adapter/WurflApi.php';
    38     const DEFAULT_FEATURES_ADAPTER_PATH = 'Zend/Http/UserAgent/Features/Adapter/Browscap.php';
    39 
    39 
    40     /**
    40     /**
    41      * User Agent Signatures
    41      * User Agent Signatures
    42      *
    42      *
    43      * @var array
    43      * @var array
    44      */
    44      */
    45     protected static $_uaSignatures = array(
    45     protected static $_uaSignatures = array(
    46         'iphone', 
    46         'iphone',
    47         'ipod', 
    47         'ipod',
    48         'ipad', 
    48         'ipad',
    49         'android', 
    49         'android',
    50         'blackberry', 
    50         'blackberry',
    51         'opera mini', 
    51         'opera mini',
    52         'opera mobi', 
    52         'opera mobi',
    53         'palm', 
    53         'palm',
    54         'palmos', 
    54         'palmos',
    55         'elaine', 
    55         'elaine',
    56         'windows ce', 
    56         'windows ce',
    57         ' ppc', 
    57         'icab',
    58         '_mms', 
    58         '_mms',
    59         'ahong', 
    59         'ahong',
    60         'archos', 
    60         'archos',
    61         'armv', 
    61         'armv',
    62         'astel', 
    62         'astel',
    63         'avantgo', 
    63         'avantgo',
    64         'benq', 
    64         'benq',
    65         'blazer', 
    65         'blazer',
    66         'brew', 
    66         'brew',
    67         'com2', 
    67         'com2',
    68         'compal', 
    68         'compal',
    69         'danger', 
    69         'danger',
    70         'pocket', 
    70         'pocket',
    71         'docomo', 
    71         'docomo',
    72         'epoc', 
    72         'epoc',
    73         'ericsson', 
    73         'ericsson',
    74         'eudoraweb', 
    74         'eudoraweb',
    75         'hiptop', 
    75         'hiptop',
    76         'htc-', 
    76         'htc-',
    77         'htc_', 
    77         'htc_',
    78         'iemobile', 
    78         'iemobile',
    79         'ipad', 
    79         'iris',
    80         'iris', 
    80         'j-phone',
    81         'j-phone', 
    81         'kddi',
    82         'kddi', 
    82         'kindle',
    83         'kindle', 
    83         'lg ',
    84         'lg ', 
    84         'lg-',
    85         'lg-', 
    85         'lg/',
    86         'lg/', 
    86         'lg;lx',
    87         'lg;lx', 
    87         'lge vx',
    88         'lge vx', 
    88         'lge',
    89         'lge', 
    89         'lge-',
    90         'lge-', 
    90         'lge-cx',
    91         'lge-cx', 
    91         'lge-lx',
    92         'lge-lx', 
    92         'lge-mx',
    93         'lge-mx', 
    93         'linux armv',
    94         'linux armv', 
    94         'maemo',
    95         'maemo', 
    95         'midp',
    96         'midp', 
    96         'mini 9.5',
    97         'mini 9.5', 
    97         'minimo',
    98         'minimo', 
    98         'mob-x',
    99         'mob-x', 
    99         'mobi',
   100         'mobi', 
   100         'mobile',
   101         'mobile', 
   101         'mobilephone',
   102         'mobilephone', 
   102         'mot 24',
   103         'mot 24', 
   103         'mot-',
   104         'mot-', 
   104         'motorola',
   105         'motorola', 
   105         'n410',
   106         'n410', 
   106         'netfront',
   107         'netfront', 
   107         'nintendo wii',
   108         'nintendo wii', 
   108         'nintendo',
   109         'nintendo', 
   109         'nitro',
   110         'nitro', 
   110         'nokia',
   111         'nokia', 
   111         'novarra-vision',
   112         'novarra-vision', 
   112         'nuvifone',
   113         'nuvifone', 
   113         'openweb',
   114         'openweb', 
   114         'opwv',
   115         'opwv', 
   115         'palmsource',
   116         'palmsource', 
   116         'pdxgw',
   117         'pdxgw', 
   117         'phone',
   118         'phone', 
   118         'playstation',
   119         'playstation', 
   119         'polaris',
   120         'polaris', 
   120         'portalmmm',
   121         'portalmmm', 
   121         'qt embedded',
   122         'qt embedded', 
   122         'reqwirelessweb',
   123         'reqwirelessweb', 
   123         'sagem',
   124         'sagem', 
   124         'sam-r',
   125         'sam-r', 
   125         'samsu',
   126         'samsu', 
   126         'samsung',
   127         'samsung', 
   127         'sec-',
   128         'sec-', 
   128         'sec-sgh',
   129         'sec-sgh', 
   129         'semc-browser',
   130         'semc-browser', 
   130         'series60',
   131         'series60', 
   131         'series70',
   132         'series70', 
   132         'series80',
   133         'series80', 
   133         'series90',
   134         'series90', 
   134         'sharp',
   135         'sharp', 
   135         'sie-m',
   136         'sie-m', 
   136         'sie-s',
   137         'sie-s', 
   137         'smartphone',
   138         'smartphone', 
   138         'sony cmd',
   139         'sony cmd', 
   139         'sonyericsson',
   140         'sonyericsson', 
   140         'sprint',
   141         'sprint', 
   141         'spv',
   142         'spv', 
   142         'symbian os',
   143         'symbian os', 
   143         'symbian',
   144         'symbian', 
   144         'symbianos',
   145         'symbianos', 
   145         'telco',
   146         'telco', 
   146         'teleca',
   147         'teleca', 
   147         'treo',
   148         'treo', 
   148         'up.browser',
   149         'up.browser', 
   149         'up.link',
   150         'up.link', 
   150         'vodafone',
   151         'vodafone', 
   151         'vodaphone',
   152         'vodaphone', 
   152         'webos',
   153         'webos', 
   153         'wml',
   154         'webpro', 
   154         'windows phone os 7',
   155         'windows phone os 7', 
   155         'wireless',
   156         'wireless', 
   156         'wm5 pie',
   157         'wm5 pie', 
   157         'wms pie',
   158         'wms pie', 
       
   159         'xiino',
   158         'xiino',
   160         'wap',
   159         'wap',
   161         'up/',
   160         'up/',
   162         'psion',
   161         'psion',
   163         'j2me',
   162         'j2me',
   167 
   166 
   168     /**
   167     /**
   169      * @var array
   168      * @var array
   170      */
   169      */
   171     protected static $_haTerms = array(
   170     protected static $_haTerms = array(
   172         'midp', 
   171         'midp',
   173         'wml', 
   172         'wml',
   174         'vnd.rim', 
   173         'vnd.rim',
   175         'vnd.wap',
   174         'vnd.wap',
       
   175         'j2me',
   176     );
   176     );
   177 
   177 
   178     /**
   178     /**
   179      * first 4 letters of mobile User Agent chains
   179      * first 4 letters of mobile User Agent chains
   180      * 
   180      *
   181      * @var array
   181      * @var array
   182      */
   182      */
   183     protected static $_uaBegin = array(
   183     protected static $_uaBegin = array(
   184         'w3c ', 
   184         'w3c ',
   185         'acs-', 
   185         'acs-',
   186         'alav', 
   186         'alav',
   187         'alca', 
   187         'alca',
   188         'amoi', 
   188         'amoi',
   189         'audi', 
   189         'audi',
   190         'avan', 
   190         'avan',
   191         'benq', 
   191         'benq',
   192         'bird', 
   192         'bird',
   193         'blac', 
   193         'blac',
   194         'blaz', 
   194         'blaz',
   195         'brew', 
   195         'brew',
   196         'cell', 
   196         'cell',
   197         'cldc', 
   197         'cldc',
   198         'cmd-', 
   198         'cmd-',
   199         'dang', 
   199         'dang',
   200         'doco', 
   200         'doco',
   201         'eric', 
   201         'eric',
   202         'hipt', 
   202         'hipt',
   203         'inno', 
   203         'inno',
   204         'ipaq', 
   204         'ipaq',
   205         'java', 
   205         'java',
   206         'jigs', 
   206         'jigs',
   207         'kddi', 
   207         'kddi',
   208         'keji', 
   208         'keji',
   209         'leno', 
   209         'leno',
   210         'lg-c', 
   210         'lg-c',
   211         'lg-d', 
   211         'lg-d',
   212         'lg-g', 
   212         'lg-g',
   213         'lge-', 
   213         'lge-',
   214         'maui', 
   214         'maui',
   215         'maxo', 
   215         'maxo',
   216         'midp', 
   216         'midp',
   217         'mits', 
   217         'mits',
   218         'mmef', 
   218         'mmef',
   219         'mobi', 
   219         'mobi',
   220         'mot-', 
   220         'mot-',
   221         'moto', 
   221         'moto',
   222         'mwbp', 
   222         'mwbp',
   223         'nec-', 
   223         'nec-',
   224         'newt', 
   224         'newt',
   225         'noki', 
   225         'noki',
   226         'oper', 
   226         'palm',
   227         'palm', 
   227         'pana',
   228         'pana', 
   228         'pant',
   229         'pant', 
   229         'phil',
   230         'phil', 
   230         'play',
   231         'play', 
   231         'port',
   232         'port', 
   232         'prox',
   233         'prox', 
   233         'qwap',
   234         'qwap', 
   234         'sage',
   235         'sage', 
   235         'sams',
   236         'sams', 
   236         'sany',
   237         'sany', 
   237         'sch-',
   238         'sch-', 
   238         'sec-',
   239         'sec-', 
   239         'send',
   240         'send', 
   240         'seri',
   241         'seri', 
   241         'sgh-',
   242         'sgh-', 
   242         'shar',
   243         'shar', 
   243         'sie-',
   244         'sie-', 
   244         'siem',
   245         'siem', 
   245         'smal',
   246         'smal', 
   246         'smar',
   247         'smar', 
   247         'sony',
   248         'sony', 
   248         'sph-',
   249         'sph-', 
   249         'symb',
   250         'symb', 
   250         't-mo',
   251         't-mo', 
   251         'teli',
   252         'teli', 
   252         'tim-',
   253         'tim-', 
   253         'tosh',
   254         'tosh', 
   254         'tsm-',
   255         'tsm-', 
   255         'upg1',
   256         'upg1', 
   256         'upsi',
   257         'upsi', 
   257         'vk-v',
   258         'vk-v', 
   258         'voda',
   259         'voda', 
   259         'wap-',
   260         'wap-', 
   260         'wapa',
   261         'wapa', 
   261         'wapi',
   262         'wapi', 
   262         'wapp',
   263         'wapp', 
   263         'wapr',
   264         'wapr', 
   264         'webc',
   265         'webc', 
   265         'winw',
   266         'winw', 
   266         'winw',
   267         'winw', 
   267         'xda',
   268         'xda', 
       
   269         'xda-',
   268         'xda-',
   270     );
   269     );
   271 
   270 
   272     /**
   271     /**
   273      * Comparison of the UserAgent chain and User Agent signatures
   272      * Comparison of the UserAgent chain and User Agent signatures
   283             if (strpos(strtolower(str_replace(' ', '', $server['all_http'])), 'operam') !== false) {
   282             if (strpos(strtolower(str_replace(' ', '', $server['all_http'])), 'operam') !== false) {
   284                 // Opera Mini or Opera Mobi
   283                 // Opera Mini or Opera Mobi
   285                 return true;
   284                 return true;
   286             }
   285             }
   287         }
   286         }
       
   287 
   288         if (isset($server['http_x_wap_profile']) || isset($server['http_profile'])) {
   288         if (isset($server['http_x_wap_profile']) || isset($server['http_profile'])) {
   289             return true;
   289             return true;
   290         }
   290         }
   291 
   291 
   292         if (self::_matchAgentAgainstSignatures($userAgent, self::$_haTerms)) {
   292         if (isset($server['http_accept'])) {
   293             return true;
   293             if (self::_matchAgentAgainstSignatures($server['http_accept'], self::$_haTerms)) {
       
   294                 return true;
       
   295             }
   294         }
   296         }
   295 
   297 
   296         if (self::userAgentStart($userAgent)) {
   298         if (self::userAgentStart($userAgent)) {
   297             return true;
   299             return true;
   298         }
   300         }
   304         return false;
   306         return false;
   305     }
   307     }
   306 
   308 
   307     /**
   309     /**
   308      * Retrieve beginning clause of user agent
   310      * Retrieve beginning clause of user agent
   309      * 
   311      *
   310      * @param  string $userAgent
   312      * @param  string $userAgent
   311      * @return string
   313      * @return string
   312      */
   314      */
   313     public static function userAgentStart($userAgent)
   315     public static function userAgentStart($userAgent)
   314     {
   316     {
   315         
   317 
   316         $mobile_ua = strtolower(substr($userAgent, 0, 4));
   318         $mobile_ua = strtolower(substr($userAgent, 0, 4));
   317         
   319 
   318         return (in_array($mobile_ua, self::$_uaBegin));
   320         return (in_array($mobile_ua, self::$_uaBegin));
   319     }
   321     }
   320 
   322 
   321     /**
   323     /**
   322      * Constructor
   324      * Constructor
   349      * @return string
   351      * @return string
   350      */
   352      */
   351     protected function _defineFeatures()
   353     protected function _defineFeatures()
   352     {
   354     {
   353         $this->setFeature('is_wireless_device', false, 'product_info');
   355         $this->setFeature('is_wireless_device', false, 'product_info');
   354         
   356 
   355         parent::_defineFeatures();
   357         parent::_defineFeatures();
   356         
   358 
   357         if (isset($this->_aFeatures["mobile_browser"])) {
   359         if (isset($this->_aFeatures["mobile_browser"])) {
   358             $this->setFeature("browser_name", $this->_aFeatures["mobile_browser"]);
   360             $this->setFeature("browser_name", $this->_aFeatures["mobile_browser"]);
   359             $this->_browser = $this->_aFeatures["mobile_browser"];
   361             $this->_browser = $this->_aFeatures["mobile_browser"];
   360         }
   362         }
   361         if (isset($this->_aFeatures["mobile_browser_version"])) {
   363         if (isset($this->_aFeatures["mobile_browser_version"])) {
   362             $this->setFeature("browser_version", $this->_aFeatures["mobile_browser_version"]);
   364             $this->setFeature("browser_version", $this->_aFeatures["mobile_browser_version"]);
   363             $this->_browserVersion = $this->_aFeatures["mobile_browser_version"];
   365             $this->_browserVersion = $this->_aFeatures["mobile_browser_version"];
   364         }
   366         }
   365         
   367 
   366         // markup
   368         // markup
   367         if ($this->getFeature('device_os') == 'iPhone OS' 
   369         if ($this->getFeature('device_os') == 'iPhone OS'
   368             || $this->getFeature('device_os_token') == 'iPhone OS'
   370             || $this->getFeature('device_os_token') == 'iPhone OS'
   369         ) {
   371         ) {
   370             $this->setFeature('markup', 'iphone');
   372             $this->setFeature('markup', 'iphone');
   371         } else {
   373         } else {
   372             $this->setFeature('markup', $this->getMarkupLanguage($this->getFeature('preferred_markup')));
   374             $this->setFeature('markup', $this->getMarkupLanguage($this->getFeature('preferred_markup')));
   373         }
   375         }
   374         
   376 
   375         // image format
   377         // image format
   376         $this->_images = array();
   378         $this->_images = array();
   377         
   379 
   378         if ($this->getFeature('png')) {
   380         if ($this->getFeature('png')) {
   379             $this->_images[] = 'png';
   381             $this->_images[] = 'png';
   380         }
   382         }
   381         if ($this->getFeature('jpg')) {
   383         if ($this->getFeature('jpg')) {
   382             $this->_images[] = 'jpg';
   384             $this->_images[] = 'jpg';
   385             $this->_images[] = 'gif';
   387             $this->_images[] = 'gif';
   386         }
   388         }
   387         if ($this->getFeature('wbmp')) {
   389         if ($this->getFeature('wbmp')) {
   388             $this->_images[] = 'wbmp';
   390             $this->_images[] = 'wbmp';
   389         }
   391         }
   390         
   392 
   391         return $this->_aFeatures;
   393         return $this->_aFeatures;
   392     }
   394     }
   393 
   395 
   394     /**
   396     /**
   395      * Determine markup language expected
   397      * Determine markup language expected