blob: b3f23886cce0e80f65dea06df293ff5cbbe10b7e (
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\UserCountry;
use Exception;
use Piwik\Common;
use Piwik\IP;
use Piwik\Piwik;
use Piwik\Plugin\Manager;
use Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2;
use Piwik\Plugins\UserCountry\LocationProvider\DefaultProvider;
use Piwik\SettingsPiwik;
use Piwik\View;
/**
*
*/
class Controller extends \Piwik\Plugin\ControllerAdmin
{
public function getDistinctCountries()
{
$view = new View('@UserCountry/getDistinctCountries');
$view->urlSparklineCountries = $this->getUrlSparkline('getLastDistinctCountriesGraph');
$view->numberDistinctCountries = $this->getNumberOfDistinctCountries();
return $view->render();
}
public function adminIndex()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
$view = new View('@UserCountry/adminIndex');
$allProviderInfo = LocationProvider::getAllProviderInfo($newline = '<br/>', $includeExtra = true);
$view->locationProviders = $allProviderInfo;
$view->currentProviderId = LocationProvider::getCurrentProviderId();
$view->thisIP = IP::getIpFromHeader();
$view->hasGeoIp2Provider = Manager::getInstance()->isPluginActivated('GeoIp2');
// check if there is a working provider (that isn't the default one)
$isThereWorkingProvider = false;
foreach ($allProviderInfo as $id => $provider) {
if ($id != DefaultProvider::ID
&& $provider['status'] == LocationProvider::INSTALLED
) {
$isThereWorkingProvider = true;
break;
}
}
$view->isThereWorkingProvider = $isThereWorkingProvider;
$configurations = $setUpGuides = '';
foreach (LocationProvider::getAllProviders() as $provider) {
$configurations .= $provider->renderConfiguration();
$setUpGuides .= $provider->renderSetUpGuide();
}
$view->configurations = $configurations;
$view->setUpGuides = $setUpGuides;
$this->setBasicVariablesView($view);
$this->setBasicVariablesAdminView($view);
return $view->render();
}
/**
* Echo's a pretty formatted location using a specific LocationProvider.
*
* Input:
* The 'id' query parameter must be set to the ID of the LocationProvider to use.
*
* Output:
* The pretty formatted location that was obtained. Will be HTML.
*/
public function getLocationUsingProvider()
{
$this->dieIfGeolocationAdminIsDisabled();
Piwik::checkUserHasSuperUserAccess();
$providerId = Common::getRequestVar('id');
$provider = LocationProvider::getProviderById($providerId);
if (empty($provider)) {
throw new Exception("Invalid provider ID: '$providerId'.");
}
$location = $provider->getLocation(array('ip' => IP::getIpFromHeader(),
'lang' => Common::getBrowserLanguage(),
'disable_fallbacks' => true));
$location = LocationProvider::prettyFormatLocation(
$location, $newline = '<br/>', $includeExtra = true);
return $location;
}
public function getNumberOfDistinctCountries()
{
return $this->getNumericValue('UserCountry.getNumberOfDistinctCountries');
}
public function getLastDistinctCountriesGraph()
{
$view = $this->getLastUnitGraph('UserCountry', __FUNCTION__, "UserCountry.getNumberOfDistinctCountries");
$view->config->columns_to_display = array('UserCountry_distinctCountries');
return $this->renderView($view);
}
private function dieIfGeolocationAdminIsDisabled()
{
if (!UserCountry::isGeoLocationAdminEnabled()) {
throw new \Exception('Geo location setting page has been disabled.');
}
}
}
|