Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
Mobile | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
detect | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
enable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
enabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Mobile Device Detection Wrapper |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * This file is a wrapper around the mobileesp library for browser detection. |
9 | * We chose mobileesp as VuFind's default option because it is fairly robust |
10 | * and has an Apache license which allows free redistribution. However, it |
11 | * is not the only option available. You can override this file in your local |
12 | * directory if you wish to customize the detection functionality. |
13 | * |
14 | * Copyright (C) Villanova University 2009. |
15 | * |
16 | * This program is free software; you can redistribute it and/or modify |
17 | * it under the terms of the GNU General Public License version 2, |
18 | * as published by the Free Software Foundation. |
19 | * |
20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. |
24 | * |
25 | * You should have received a copy of the GNU General Public License |
26 | * along with this program; if not, write to the Free Software |
27 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
28 | * |
29 | * @category VuFind |
30 | * @package Theme |
31 | * @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net> |
32 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
33 | * @link https://github.com/ahand/mobileesp MobileESP Project |
34 | */ |
35 | |
36 | namespace VuFindTheme; |
37 | |
38 | use uagent_info; |
39 | |
40 | /** |
41 | * Mobile Device Detection Wrapper |
42 | * |
43 | * @category VuFind |
44 | * @package Theme |
45 | * @author Andrew S. Nagy <vufind-tech@lists.sourceforge.net> |
46 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
47 | * @link https://github.com/ahand/mobileesp MobileESP Project |
48 | */ |
49 | class Mobile |
50 | { |
51 | /** |
52 | * Mobile detection object |
53 | * |
54 | * @var uagent_info |
55 | */ |
56 | protected $detector; |
57 | |
58 | /** |
59 | * Are mobile themes enabled? |
60 | * |
61 | * @var bool |
62 | */ |
63 | protected $enabled = false; |
64 | |
65 | /** |
66 | * Constructor |
67 | * |
68 | * @param uagent_info $detector Detector object to wrap (null to create one) |
69 | */ |
70 | public function __construct(uagent_info $detector = null) |
71 | { |
72 | $this->detector = $detector ?? new uagent_info(); |
73 | } |
74 | |
75 | /** |
76 | * Function to detect if a mobile device is being used. |
77 | * |
78 | * @return bool |
79 | */ |
80 | public function detect() |
81 | { |
82 | // Do the most exhaustive device detection possible; other method calls |
83 | // may be used instead of DetectMobileLong if you want to target a narrower |
84 | // class of devices. |
85 | return $this->detector->DetectMobileLong(); |
86 | } |
87 | |
88 | /** |
89 | * Function to set enabled status of mobile themes. |
90 | * |
91 | * @param bool $enabled Are mobile themes enabled? |
92 | * |
93 | * @return void |
94 | */ |
95 | public function enable($enabled = true) |
96 | { |
97 | $this->enabled = $enabled; |
98 | } |
99 | |
100 | /** |
101 | * Function to check whether mobile theme is configured. |
102 | * |
103 | * @return bool |
104 | */ |
105 | public function enabled() |
106 | { |
107 | return $this->enabled; |
108 | } |
109 | } |