Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Mobile.php
Go to the documentation of this file.
1 <?php
22 #require_once 'Zend/Http/UserAgent/AbstractDevice.php';
23 
34 {
35 
36  const DEFAULT_FEATURES_ADAPTER_CLASSNAME = 'Zend_Http_UserAgent_Features_Adapter_Browscap';
37 
38  const DEFAULT_FEATURES_ADAPTER_PATH = 'Zend/Http/UserAgent/Features/Adapter/Browscap.php';
39 
45  protected static $_uaSignatures = array(
46  'iphone',
47  'ipod',
48  'ipad',
49  'android',
50  'blackberry',
51  'opera mini',
52  'opera mobi',
53  'palm',
54  'palmos',
55  'elaine',
56  'windows ce',
57  'icab',
58  '_mms',
59  'ahong',
60  'archos',
61  'armv',
62  'astel',
63  'avantgo',
64  'benq',
65  'blazer',
66  'brew',
67  'com2',
68  'compal',
69  'danger',
70  'pocket',
71  'docomo',
72  'epoc',
73  'ericsson',
74  'eudoraweb',
75  'hiptop',
76  'htc-',
77  'htc_',
78  'iemobile',
79  'iris',
80  'j-phone',
81  'kddi',
82  'kindle',
83  'lg ',
84  'lg-',
85  'lg/',
86  'lg;lx',
87  'lge vx',
88  'lge',
89  'lge-',
90  'lge-cx',
91  'lge-lx',
92  'lge-mx',
93  'linux armv',
94  'maemo',
95  'midp',
96  'mini 9.5',
97  'minimo',
98  'mob-x',
99  'mobi',
100  'mobile',
101  'mobilephone',
102  'mot 24',
103  'mot-',
104  'motorola',
105  'n410',
106  'netfront',
107  'nintendo wii',
108  'nintendo',
109  'nitro',
110  'nokia',
111  'novarra-vision',
112  'nuvifone',
113  'openweb',
114  'opwv',
115  'palmsource',
116  'pdxgw',
117  'phone',
118  'playstation',
119  'polaris',
120  'portalmmm',
121  'qt embedded',
122  'reqwirelessweb',
123  'sagem',
124  'sam-r',
125  'samsu',
126  'samsung',
127  'sec-',
128  'sec-sgh',
129  'semc-browser',
130  'series60',
131  'series70',
132  'series80',
133  'series90',
134  'sharp',
135  'sie-m',
136  'sie-s',
137  'smartphone',
138  'sony cmd',
139  'sonyericsson',
140  'sprint',
141  'spv',
142  'symbian os',
143  'symbian',
144  'symbianos',
145  'telco',
146  'teleca',
147  'treo',
148  'up.browser',
149  'up.link',
150  'vodafone',
151  'vodaphone',
152  'webos',
153  'wml',
154  'windows phone os 7',
155  'wireless',
156  'wm5 pie',
157  'wms pie',
158  'xiino',
159  'wap',
160  'up/',
161  'psion',
162  'j2me',
163  'klondike',
164  'kbrowser'
165  );
166 
170  protected static $_haTerms = array(
171  'midp',
172  'wml',
173  'vnd.rim',
174  'vnd.wap',
175  'j2me',
176  );
177 
183  protected static $_uaBegin = array(
184  'w3c ',
185  'acs-',
186  'alav',
187  'alca',
188  'amoi',
189  'audi',
190  'avan',
191  'benq',
192  'bird',
193  'blac',
194  'blaz',
195  'brew',
196  'cell',
197  'cldc',
198  'cmd-',
199  'dang',
200  'doco',
201  'eric',
202  'hipt',
203  'inno',
204  'ipaq',
205  'java',
206  'jigs',
207  'kddi',
208  'keji',
209  'leno',
210  'lg-c',
211  'lg-d',
212  'lg-g',
213  'lge-',
214  'maui',
215  'maxo',
216  'midp',
217  'mits',
218  'mmef',
219  'mobi',
220  'mot-',
221  'moto',
222  'mwbp',
223  'nec-',
224  'newt',
225  'noki',
226  'palm',
227  'pana',
228  'pant',
229  'phil',
230  'play',
231  'port',
232  'prox',
233  'qwap',
234  'sage',
235  'sams',
236  'sany',
237  'sch-',
238  'sec-',
239  'send',
240  'seri',
241  'sgh-',
242  'shar',
243  'sie-',
244  'siem',
245  'smal',
246  'smar',
247  'sony',
248  'sph-',
249  'symb',
250  't-mo',
251  'teli',
252  'tim-',
253  'tosh',
254  'tsm-',
255  'upg1',
256  'upsi',
257  'vk-v',
258  'voda',
259  'wap-',
260  'wapa',
261  'wapi',
262  'wapp',
263  'wapr',
264  'webc',
265  'winw',
266  'winw',
267  'xda',
268  'xda-',
269  );
270 
278  public static function match($userAgent, $server)
279  {
280  // To have a quick identification, try light-weight tests first
281  if (isset($server['all_http'])) {
282  if (strpos(strtolower(str_replace(' ', '', $server['all_http'])), 'operam') !== false) {
283  // Opera Mini or Opera Mobi
284  return true;
285  }
286  }
287 
288  if (isset($server['http_x_wap_profile']) || isset($server['http_profile'])) {
289  return true;
290  }
291 
292  if (isset($server['http_accept'])) {
293  if (self::_matchAgentAgainstSignatures($server['http_accept'], self::$_haTerms)) {
294  return true;
295  }
296  }
297 
298  if (self::userAgentStart($userAgent)) {
299  return true;
300  }
301 
302  if (self::_matchAgentAgainstSignatures($userAgent, self::$_uaSignatures)) {
303  return true;
304  }
305 
306  return false;
307  }
308 
315  public static function userAgentStart($userAgent)
316  {
317 
318  $mobile_ua = strtolower(substr($userAgent, 0, 4));
319 
320  return (in_array($mobile_ua, self::$_uaBegin));
321  }
322 
328  public function __construct($userAgent = null, array $server = array(), array $config = array())
329  {
330  // For mobile detection, an adapter must be defined
331  if (empty($config['mobile']['features'])) {
332  $config['mobile']['features']['path'] = self::DEFAULT_FEATURES_ADAPTER_PATH;
333  $config['mobile']['features']['classname'] = self::DEFAULT_FEATURES_ADAPTER_CLASSNAME;
334  }
335  parent::__construct($userAgent, $server, $config);
336  }
337 
343  public function getType()
344  {
345  return 'mobile';
346  }
347 
353  protected function _defineFeatures()
354  {
355  $this->setFeature('is_wireless_device', false, 'product_info');
356 
357  parent::_defineFeatures();
358 
359  if (isset($this->_aFeatures["mobile_browser"])) {
360  $this->setFeature("browser_name", $this->_aFeatures["mobile_browser"]);
361  $this->_browser = $this->_aFeatures["mobile_browser"];
362  }
363  if (isset($this->_aFeatures["mobile_browser_version"])) {
364  $this->setFeature("browser_version", $this->_aFeatures["mobile_browser_version"]);
365  $this->_browserVersion = $this->_aFeatures["mobile_browser_version"];
366  }
367 
368  // markup
369  if ($this->getFeature('device_os') == 'iPhone OS'
370  || $this->getFeature('device_os_token') == 'iPhone OS'
371  ) {
372  $this->setFeature('markup', 'iphone');
373  } else {
374  $this->setFeature('markup', $this->getMarkupLanguage($this->getFeature('preferred_markup')));
375  }
376 
377  // image format
378  $this->_images = array();
379 
380  if ($this->getFeature('png')) {
381  $this->_images[] = 'png';
382  }
383  if ($this->getFeature('jpg')) {
384  $this->_images[] = 'jpg';
385  }
386  if ($this->getFeature('gif')) {
387  $this->_images[] = 'gif';
388  }
389  if ($this->getFeature('wbmp')) {
390  $this->_images[] = 'wbmp';
391  }
392 
393  return $this->_aFeatures;
394  }
395 
402  public function getMarkupLanguage($preferredMarkup = null)
403  {
404  $return = '';
405  switch ($preferredMarkup) {
406  case 'wml_1_1':
407  case 'wml_1_2':
408  case 'wml_1_3':
409  $return = 'wml'; //text/vnd.wap.wml encoding="ISO-8859-15"
410  case 'html_wi_imode_compact_generic':
411  case 'html_wi_imode_html_1':
412  case 'html_wi_imode_html_2':
413  case 'html_wi_imode_html_3':
414  case 'html_wi_imode_html_4':
415  case 'html_wi_imode_html_5':
416  $return = 'chtml'; //text/html
417  case 'html_wi_oma_xhtmlmp_1_0': //application/vnd.wap.xhtml+xml
418  case 'html_wi_w3_xhtmlbasic': //application/xhtml+xml DTD XHTML Basic 1.0
419  $return = 'xhtml';
420  case 'html_web_3_2': //text/html DTD Html 3.2 Final
421  case 'html_web_4_0': //text/html DTD Html 4.01 Transitional
422  $return = '';
423  }
424  return $return;
425  }
426 
432  public function getImageFormatSupport()
433  {
434  return $this->_images;
435  }
436 
442  public function getMaxImageHeight()
443  {
444  return $this->getFeature('max_image_height');
445  }
446 
452  public function getMaxImageWidth()
453  {
454  return $this->getFeature('max_image_width');
455  }
456 
462  public function getPhysicalScreenHeight()
463  {
464  return $this->getFeature('physical_screen_height');
465  }
466 
472  public function getPhysicalScreenWidth()
473  {
474  return $this->getFeature('physical_screen_width');
475  }
476 
482  public function getPreferredMarkup()
483  {
484  return $this->getFeature("markup");
485  }
486 
492  public function getXhtmlSupportLevel()
493  {
494  return $this->getFeature('xhtml_support_level');
495  }
496 
502  public function hasFlashSupport()
503  {
504  return $this->getFeature('fl_browser');
505  }
506 
512  public function hasPdfSupport()
513  {
514  return $this->getFeature('pdf_support');
515  }
516 
522  public function hasPhoneNumber()
523  {
524  return $this->getFeature('can_assign_phone_number');
525  }
526 
532  public function httpsSupport()
533  {
534  return ($this->getFeature('https_support') == 'supported');
535  }
536 }
getMarkupLanguage($preferredMarkup=null)
Definition: Mobile.php:402
$config
Definition: fraud_order.php:17
static userAgentStart($userAgent)
Definition: Mobile.php:315
static match($userAgent, $server)
Definition: Mobile.php:278
__construct($userAgent=null, array $server=array(), array $config=array())
Definition: Mobile.php:328
const DEFAULT_FEATURES_ADAPTER_PATH
Definition: Mobile.php:38
const DEFAULT_FEATURES_ADAPTER_CLASSNAME
Definition: Mobile.php:36
setFeature($feature, $value=false, $group='')