|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace awssat\Visits\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Spatie\Referer\Referer; |
|
6
|
|
|
|
|
7
|
|
|
trait Record |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param $inc |
|
11
|
|
|
*/ |
|
12
|
|
|
protected function recordCountry($inc) |
|
13
|
|
|
{ |
|
14
|
|
|
$this->redis->zincrby($this->keys->visits."_countries:{$this->keys->id}", $inc, $this->getVisitorCountry()); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param $inc |
|
19
|
|
|
*/ |
|
20
|
|
|
protected function recordRefer($inc) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->redis->zincrby($this->keys->visits."_referers:{$this->keys->id}", $inc, $this->getVisitorReferer()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param $inc |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function recordOperatingSystem($inc) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->redis->zincrby($this->keys->visits."_OSes:{$this->keys->id}", $inc, $this->getVisitorOperatingSystem()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param $inc |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function recordLanguage($inc) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->redis->zincrby($this->keys->visits."_languages:{$this->keys->id}", $inc, $this->getVisitorLanguage()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param $inc |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function recordPeriods($inc) |
|
45
|
|
|
{ |
|
46
|
|
|
foreach ($this->periods as $period) { |
|
47
|
|
|
$periodKey = $this->keys->period($period); |
|
48
|
|
|
|
|
49
|
|
|
$this->redis->zincrby($periodKey, $inc, $this->keys->id); |
|
50
|
|
|
$this->redis->incrby($periodKey.'_total', $inc); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Gets visitor country code |
|
56
|
|
|
* @return mixed|string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getVisitorCountry() |
|
59
|
|
|
{ |
|
60
|
|
|
return strtolower(geoip()->getLocation()->iso_code); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Gets visitor operating system |
|
65
|
|
|
* @return mixed|string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getVisitorOperatingSystem() |
|
68
|
|
|
{ |
|
69
|
|
|
$osArray = [ |
|
70
|
|
|
'/windows|win32|win16|win95/i' => 'Windows', |
|
71
|
|
|
'/iphone/i' => 'iPhone', |
|
72
|
|
|
'/ipad/i' => 'iPad', |
|
73
|
|
|
'/macintosh|mac os x|mac_powerpc/i' => 'MacOS', |
|
74
|
|
|
'/(?=.*mobile)android/i' => 'AndroidMobile', |
|
75
|
|
|
'/(?!.*mobile)android/i' => 'AndroidTablet', |
|
76
|
|
|
'/android/i' => 'Android', |
|
77
|
|
|
'/blackberry/i' => 'BlackBerry', |
|
78
|
|
|
'/linux/i' => 'Linux', |
|
79
|
|
|
]; |
|
80
|
|
|
|
|
81
|
|
|
foreach ($osArray as $regex => $value) { |
|
82
|
|
|
if (preg_match($regex, request()->server('HTTP_USER_AGENT') ?? '')) { |
|
83
|
|
|
return $value; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return 'unknown'; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Gets visitor language |
|
92
|
|
|
* @return mixed|string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getVisitorLanguage() |
|
95
|
|
|
{ |
|
96
|
|
|
$language = request()->getPreferredLanguage(); |
|
97
|
|
|
if (false !== $position = strpos($language, '_')) { |
|
98
|
|
|
$language = substr($language, 0, $position); |
|
99
|
|
|
} |
|
100
|
|
|
return $language; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Gets visitor referer |
|
105
|
|
|
* @return mixed|string |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getVisitorReferer() |
|
108
|
|
|
{ |
|
109
|
|
|
return app(Referer::class)->get(); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.