blob: e966aaa93a516f62406efa1e08bb4de8db6c7aca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
<?php
if (!class_exists('WMobilePack_Detect')) {
/**
*
* WMobilePack_Detect
*
* Main class for detecting the user's device and browser.
*
*/
class WMobilePack_Detect {
/* ----------------------------------*/
/* Methods */
/* ----------------------------------*/
/**
* Check if we have tablet themes support
*
* @return int
*/
protected function is_allowed_tablets(){
return WMobilePack_Options::get_setting('enable_tablets') == 1;
}
/**
*
* Check the browser's user agent and return true if the device is a supported smartphone
*
*/
public function detect_device()
{
$is_supported_device = 0;
$is_supported_os = 0;
$is_supported_browser = 0;
$is_tablet = 0;
if (!class_exists('WMP_Mobile_Detect')) {
require_once (WMP_PLUGIN_PATH.'libs/Mobile-Detect-2.8.25/Mobile_Detect.php');
}
$detect = new WMP_Mobile_Detect();
if ($detect->isMobile() || $detect->isTablet())
$is_supported_device = 1;
if ($detect->isTablet()) {
$is_tablet = 1;
}
if ($detect->is('iOS') || $detect->is('AndroidOS')) {
$is_supported_os = 1;
}
if ($detect->is('WebKit')) {
$is_supported_browser = 1;
}
// set load app variable
$load_app = false;
if ($is_supported_device && $is_supported_os && $is_supported_browser) {
if ($is_tablet == 0 || $this->is_allowed_tablets()){
$load_app = true;
}
}
// set load app cookie
$this->set_load_app_cookie(intval($load_app));
return $load_app;
}
/**
*
* Set the set_load_app_cookie
* The cookie is set in a separate method to allow mocking for unit testing.
*
* @param $value
*/
protected function set_load_app_cookie($value)
{
$WMobilePackCookie = new WMobilePack_Cookie();
$WMobilePackCookie->set_cookie('load_app', $value);
}
}
}
|