|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* MobileDetect.php |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright More in license.md |
|
6
|
|
|
* @license http://www.ipublikuj.eu |
|
7
|
|
|
* @author Adam Kadlec http://www.ipublikuj.eu |
|
8
|
|
|
* @package iPublikuj:MobileDetect! |
|
9
|
|
|
* @subpackage common |
|
10
|
|
|
* @since 1.0.0 |
|
11
|
|
|
* |
|
12
|
|
|
* @date 21.04.14 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
|
16
|
|
|
|
|
17
|
|
|
namespace IPub\MobileDetect; |
|
18
|
|
|
|
|
19
|
|
|
use Nette; |
|
20
|
|
|
use Nette\Http; |
|
21
|
|
|
|
|
22
|
|
|
use IPub; |
|
23
|
|
|
use IPub\MobileDetect\Helpers; |
|
24
|
|
|
use IPub\MobileDetect\Templating; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Mobile detect detector service |
|
28
|
|
|
* |
|
29
|
|
|
* @package iPublikuj:MobileDetect! |
|
30
|
|
|
* @subpackage common |
|
31
|
|
|
* |
|
32
|
|
|
* @author Adam Kadlec <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
1 |
|
final class MobileDetect extends \Jenssegers\Agent\Agent |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* @var Helpers\DeviceView |
|
38
|
|
|
*/ |
|
39
|
|
|
private $deviceView; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param Helpers\DeviceView $deviceView |
|
43
|
|
|
* @param Http\Request $httpRequest |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
Helpers\DeviceView $deviceView, |
|
47
|
|
|
Http\Request $httpRequest |
|
48
|
|
|
) { |
|
49
|
|
|
// Get http headers |
|
50
|
1 |
|
$httpHeaders = $httpRequest->getHeaders(); |
|
51
|
|
|
|
|
52
|
1 |
|
$userAgent = NULL; |
|
53
|
|
|
|
|
54
|
|
|
// If user agent info is set in headers... |
|
55
|
1 |
|
if (isset($httpHeaders['user-agent'])) { |
|
56
|
|
|
// ...set user agent details |
|
57
|
|
|
$userAgent = $httpHeaders['user-agent']; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
parent::__construct($httpHeaders, $userAgent); |
|
61
|
|
|
|
|
62
|
1 |
|
$this->deviceView = $deviceView; |
|
63
|
1 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Check if the device is not mobile phone |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
|
|
public function isNotPhone() : bool |
|
71
|
|
|
{ |
|
72
|
|
|
return (($this->isMobile() && $this->isTablet()) || !$this->isMobile()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function view() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->deviceView->getViewType(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function browserVersion() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->version($this->browser()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function platformVersion() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->version($this->platform()); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|