PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Zend/Http/UserAgent/Mobile.php

https://gitlab.com/blingbang2016/shop
PHP | 536 lines | 363 code | 37 blank | 136 comment | 22 complexity | 00d3e607c4ac5e298492bd3d7762c555 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Http
  17. * @subpackage UserAgent
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
  22. /**
  23. * Mobile browser type matcher
  24. *
  25. * @category Zend
  26. * @package Zend_Http
  27. * @subpackage UserAgent
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Http_UserAgent_Mobile extends Zend_Http_UserAgent_AbstractDevice
  32. {
  33. const DEFAULT_FEATURES_ADAPTER_CLASSNAME = 'Zend_Http_UserAgent_Features_Adapter_Browscap';
  34. const DEFAULT_FEATURES_ADAPTER_PATH = 'Zend/Http/UserAgent/Features/Adapter/Browscap.php';
  35. /**
  36. * User Agent Signatures
  37. *
  38. * @var array
  39. */
  40. protected static $_uaSignatures = array(
  41. 'iphone',
  42. 'ipod',
  43. 'ipad',
  44. 'android',
  45. 'blackberry',
  46. 'opera mini',
  47. 'opera mobi',
  48. 'palm',
  49. 'palmos',
  50. 'elaine',
  51. 'windows ce',
  52. 'icab',
  53. '_mms',
  54. 'ahong',
  55. 'archos',
  56. 'armv',
  57. 'astel',
  58. 'avantgo',
  59. 'benq',
  60. 'blazer',
  61. 'brew',
  62. 'com2',
  63. 'compal',
  64. 'danger',
  65. 'pocket',
  66. 'docomo',
  67. 'epoc',
  68. 'ericsson',
  69. 'eudoraweb',
  70. 'hiptop',
  71. 'htc-',
  72. 'htc_',
  73. 'iemobile',
  74. 'iris',
  75. 'j-phone',
  76. 'kddi',
  77. 'kindle',
  78. 'lg ',
  79. 'lg-',
  80. 'lg/',
  81. 'lg;lx',
  82. 'lge vx',
  83. 'lge',
  84. 'lge-',
  85. 'lge-cx',
  86. 'lge-lx',
  87. 'lge-mx',
  88. 'linux armv',
  89. 'maemo',
  90. 'midp',
  91. 'mini 9.5',
  92. 'minimo',
  93. 'mob-x',
  94. 'mobi',
  95. 'mobile',
  96. 'mobilephone',
  97. 'mot 24',
  98. 'mot-',
  99. 'motorola',
  100. 'n410',
  101. 'netfront',
  102. 'nintendo wii',
  103. 'nintendo',
  104. 'nitro',
  105. 'nokia',
  106. 'novarra-vision',
  107. 'nuvifone',
  108. 'openweb',
  109. 'opwv',
  110. 'palmsource',
  111. 'pdxgw',
  112. 'phone',
  113. 'playstation',
  114. 'polaris',
  115. 'portalmmm',
  116. 'qt embedded',
  117. 'reqwirelessweb',
  118. 'sagem',
  119. 'sam-r',
  120. 'samsu',
  121. 'samsung',
  122. 'sec-',
  123. 'sec-sgh',
  124. 'semc-browser',
  125. 'series60',
  126. 'series70',
  127. 'series80',
  128. 'series90',
  129. 'sharp',
  130. 'sie-m',
  131. 'sie-s',
  132. 'smartphone',
  133. 'sony cmd',
  134. 'sonyericsson',
  135. 'sprint',
  136. 'spv',
  137. 'symbian os',
  138. 'symbian',
  139. 'symbianos',
  140. 'telco',
  141. 'teleca',
  142. 'treo',
  143. 'up.browser',
  144. 'up.link',
  145. 'vodafone',
  146. 'vodaphone',
  147. 'webos',
  148. 'wml',
  149. 'windows phone os 7',
  150. 'wireless',
  151. 'wm5 pie',
  152. 'wms pie',
  153. 'xiino',
  154. 'wap',
  155. 'up/',
  156. 'psion',
  157. 'j2me',
  158. 'klondike',
  159. 'kbrowser'
  160. );
  161. /**
  162. * @var array
  163. */
  164. protected static $_haTerms = array(
  165. 'midp',
  166. 'wml',
  167. 'vnd.rim',
  168. 'vnd.wap',
  169. 'j2me',
  170. );
  171. /**
  172. * first 4 letters of mobile User Agent chains
  173. *
  174. * @var array
  175. */
  176. protected static $_uaBegin = array(
  177. 'w3c ',
  178. 'acs-',
  179. 'alav',
  180. 'alca',
  181. 'amoi',
  182. 'audi',
  183. 'avan',
  184. 'benq',
  185. 'bird',
  186. 'blac',
  187. 'blaz',
  188. 'brew',
  189. 'cell',
  190. 'cldc',
  191. 'cmd-',
  192. 'dang',
  193. 'doco',
  194. 'eric',
  195. 'hipt',
  196. 'inno',
  197. 'ipaq',
  198. 'java',
  199. 'jigs',
  200. 'kddi',
  201. 'keji',
  202. 'leno',
  203. 'lg-c',
  204. 'lg-d',
  205. 'lg-g',
  206. 'lge-',
  207. 'maui',
  208. 'maxo',
  209. 'midp',
  210. 'mits',
  211. 'mmef',
  212. 'mobi',
  213. 'mot-',
  214. 'moto',
  215. 'mwbp',
  216. 'nec-',
  217. 'newt',
  218. 'noki',
  219. 'palm',
  220. 'pana',
  221. 'pant',
  222. 'phil',
  223. 'play',
  224. 'port',
  225. 'prox',
  226. 'qwap',
  227. 'sage',
  228. 'sams',
  229. 'sany',
  230. 'sch-',
  231. 'sec-',
  232. 'send',
  233. 'seri',
  234. 'sgh-',
  235. 'shar',
  236. 'sie-',
  237. 'siem',
  238. 'smal',
  239. 'smar',
  240. 'sony',
  241. 'sph-',
  242. 'symb',
  243. 't-mo',
  244. 'teli',
  245. 'tim-',
  246. 'tosh',
  247. 'tsm-',
  248. 'upg1',
  249. 'upsi',
  250. 'vk-v',
  251. 'voda',
  252. 'wap-',
  253. 'wapa',
  254. 'wapi',
  255. 'wapp',
  256. 'wapr',
  257. 'webc',
  258. 'winw',
  259. 'winw',
  260. 'xda',
  261. 'xda-',
  262. );
  263. /**
  264. * Comparison of the UserAgent chain and User Agent signatures
  265. *
  266. * @param string $userAgent User Agent chain
  267. * @param array $server $_SERVER like param
  268. * @return bool
  269. */
  270. public static function match($userAgent, $server)
  271. {
  272. // To have a quick identification, try light-weight tests first
  273. if (isset($server['all_http'])) {
  274. if (strpos(strtolower(str_replace(' ', '', $server['all_http'])), 'operam') !== false) {
  275. // Opera Mini or Opera Mobi
  276. return true;
  277. }
  278. }
  279. if (isset($server['http_x_wap_profile']) || isset($server['http_profile'])) {
  280. return true;
  281. }
  282. if (isset($server['http_accept'])) {
  283. if (self::_matchAgentAgainstSignatures($server['http_accept'], self::$_haTerms)) {
  284. return true;
  285. }
  286. }
  287. if (self::userAgentStart($userAgent)) {
  288. return true;
  289. }
  290. if (self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures)) {
  291. return true;
  292. }
  293. return false;
  294. }
  295. /**
  296. * Retrieve beginning clause of user agent
  297. *
  298. * @param string $userAgent
  299. * @return string
  300. */
  301. public static function userAgentStart($userAgent)
  302. {
  303. $mobile_ua = strtolower(substr($userAgent, 0, 4));
  304. return (in_array($mobile_ua, self::$_uaBegin));
  305. }
  306. /**
  307. * Constructor
  308. *
  309. * @return void
  310. */
  311. public function __construct($userAgent = null, array $server = array(), array $config = array())
  312. {
  313. // For mobile detection, an adapter must be defined
  314. if (empty($config['mobile']['features'])) {
  315. $config['mobile']['features']['path'] = self::DEFAULT_FEATURES_ADAPTER_PATH;
  316. $config['mobile']['features']['classname'] = self::DEFAULT_FEATURES_ADAPTER_CLASSNAME;
  317. }
  318. parent::__construct($userAgent, $server, $config);
  319. }
  320. /**
  321. * Gives the current browser type
  322. *
  323. * @return string
  324. */
  325. public function getType()
  326. {
  327. return 'mobile';
  328. }
  329. /**
  330. * Look for features
  331. *
  332. * @return string
  333. */
  334. protected function _defineFeatures()
  335. {
  336. $this->setFeature('is_wireless_device', false, 'product_info');
  337. parent::_defineFeatures();
  338. if (isset($this->_aFeatures["mobile_browser"])) {
  339. $this->setFeature("browser_name", $this->_aFeatures["mobile_browser"]);
  340. $this->_browser = $this->_aFeatures["mobile_browser"];
  341. }
  342. if (isset($this->_aFeatures["mobile_browser_version"])) {
  343. $this->setFeature("browser_version", $this->_aFeatures["mobile_browser_version"]);
  344. $this->_browserVersion = $this->_aFeatures["mobile_browser_version"];
  345. }
  346. // markup
  347. if ($this->getFeature('device_os') == 'iPhone OS'
  348. || $this->getFeature('device_os_token') == 'iPhone OS'
  349. ) {
  350. $this->setFeature('markup', 'iphone');
  351. } else {
  352. $this->setFeature('markup', $this->getMarkupLanguage($this->getFeature('preferred_markup')));
  353. }
  354. // image format
  355. $this->_images = array();
  356. if ($this->getFeature('png')) {
  357. $this->_images[] = 'png';
  358. }
  359. if ($this->getFeature('jpg')) {
  360. $this->_images[] = 'jpg';
  361. }
  362. if ($this->getFeature('gif')) {
  363. $this->_images[] = 'gif';
  364. }
  365. if ($this->getFeature('wbmp')) {
  366. $this->_images[] = 'wbmp';
  367. }
  368. return $this->_aFeatures;
  369. }
  370. /**
  371. * Determine markup language expected
  372. *
  373. * @access public
  374. * @return __TYPE__
  375. */
  376. public function getMarkupLanguage($preferredMarkup = null)
  377. {
  378. $return = '';
  379. switch ($preferredMarkup) {
  380. case 'wml_1_1':
  381. case 'wml_1_2':
  382. case 'wml_1_3':
  383. $return = 'wml'; //text/vnd.wap.wml encoding="ISO-8859-15"
  384. case 'html_wi_imode_compact_generic':
  385. case 'html_wi_imode_html_1':
  386. case 'html_wi_imode_html_2':
  387. case 'html_wi_imode_html_3':
  388. case 'html_wi_imode_html_4':
  389. case 'html_wi_imode_html_5':
  390. $return = 'chtml'; //text/html
  391. case 'html_wi_oma_xhtmlmp_1_0': //application/vnd.wap.xhtml+xml
  392. case 'html_wi_w3_xhtmlbasic': //application/xhtml+xml DTD XHTML Basic 1.0
  393. $return = 'xhtml';
  394. case 'html_web_3_2': //text/html DTD Html 3.2 Final
  395. case 'html_web_4_0': //text/html DTD Html 4.01 Transitional
  396. $return = '';
  397. }
  398. return $return;
  399. }
  400. /**
  401. * Determine image format support
  402. *
  403. * @return array
  404. */
  405. public function getImageFormatSupport()
  406. {
  407. return $this->_images;
  408. }
  409. /**
  410. * Determine maximum image height supported
  411. *
  412. * @return int
  413. */
  414. public function getMaxImageHeight()
  415. {
  416. return $this->getFeature('max_image_height');
  417. }
  418. /**
  419. * Determine maximum image width supported
  420. *
  421. * @return int
  422. */
  423. public function getMaxImageWidth()
  424. {
  425. return $this->getFeature('max_image_width');
  426. }
  427. /**
  428. * Determine physical screen height
  429. *
  430. * @return int
  431. */
  432. public function getPhysicalScreenHeight()
  433. {
  434. return $this->getFeature('physical_screen_height');
  435. }
  436. /**
  437. * Determine physical screen width
  438. *
  439. * @return int
  440. */
  441. public function getPhysicalScreenWidth()
  442. {
  443. return $this->getFeature('physical_screen_width');
  444. }
  445. /**
  446. * Determine preferred markup
  447. *
  448. * @return string
  449. */
  450. public function getPreferredMarkup()
  451. {
  452. return $this->getFeature("markup");
  453. }
  454. /**
  455. * Determine X/HTML support level
  456. *
  457. * @return int
  458. */
  459. public function getXhtmlSupportLevel()
  460. {
  461. return $this->getFeature('xhtml_support_level');
  462. }
  463. /**
  464. * Does the device support Flash?
  465. *
  466. * @return bool
  467. */
  468. public function hasFlashSupport()
  469. {
  470. return $this->getFeature('fl_browser');
  471. }
  472. /**
  473. * Does the device support PDF?
  474. *
  475. * @return bool
  476. */
  477. public function hasPdfSupport()
  478. {
  479. return $this->getFeature('pdf_support');
  480. }
  481. /**
  482. * Does the device have an associated phone number?
  483. *
  484. * @return bool
  485. */
  486. public function hasPhoneNumber()
  487. {
  488. return $this->getFeature('can_assign_phone_number');
  489. }
  490. /**
  491. * Does the device support HTTPS?
  492. *
  493. * @return bool
  494. */
  495. public function httpsSupport()
  496. {
  497. return ($this->getFeature('https_support') == 'supported');
  498. }
  499. }