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', |
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'; |