forked from matomo-org/matomo
/
Base.php
86 lines (69 loc) · 2.25 KB
/
Base.php
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
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\UserCountry\Columns;
use Piwik\Common;
use Piwik\Plugin\Dimension\VisitDimension;
use Piwik\Plugins\UserCountry\LocationFetcher;
use Piwik\Plugins\UserCountry\LocationProvider\GeoIp;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig;
use Piwik\IP;
use Piwik\Tracker\Visitor;
use Piwik\Tracker\Request;
abstract class Base extends VisitDimension
{
private $locationFetcher;
protected function getUrlOverrideValueIfAllowed($urlParamToOverride, Request $request)
{
if (!$request->isAuthenticated()) {
return false;
}
$value = Common::getRequestVar($urlParamToOverride, false, 'string', $request->getParams());
if (!empty($value)) {
return $value;
}
return false;
}
public function getRequiredVisitFields()
{
return array('location_ip', 'location_browser_lang');
}
protected function getLocationDetail($userInfo, $locationKey)
{
return $this->getLocationFetcher()->getLocationDetail(
$userInfo,
$locationKey,
empty($GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'])
);
}
protected function getLocationFetcher()
{
if ($this->locationFetcher === null) {
$this->locationFetcher = new LocationFetcher();
}
return $this->locationFetcher;
}
protected function getUserInfo(Request $request, Visitor $visitor)
{
$ipAddress = $this->getIpAddress($visitor->getVisitorColumn('location_ip'), $request);
$language = $visitor->getVisitorColumn('location_browser_lang');
$userInfo = array('lang' => $language, 'ip' => $ipAddress);
return $userInfo;
}
private function getIpAddress($anonymizedIp, \Piwik\Tracker\Request $request)
{
$privacyConfig = new PrivacyManagerConfig();
$ip = $request->getIp();
if ($privacyConfig->useAnonymizedIpForVisitEnrichment) {
$ip = $anonymizedIp;
}
$ipAddress = IP::N2P($ip);
return $ipAddress;
}
}