blob: cab362a3c65135a5e886fa44b56dd4bc71a817c4 (
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
|
<?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;
use Piwik\ArchiveProcessor;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Intl\Data\Provider\RegionDataProvider;
use Piwik\Plugins\UserCountry\LocationProvider\GeoIp;
use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Url;
/**
* @see plugins/UserCountry/GeoIPAutoUpdater.php
*/
require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/GeoIPAutoUpdater.php';
/**
*
*/
class UserCountry extends \Piwik\Plugin
{
/**
* @see Piwik\Plugin::registerEvents
*/
public function registerEvents()
{
return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'Tracker.setTrackerCacheGeneral' => 'setTrackerCacheGeneral',
'Insights.addReportToOverview' => 'addReportToInsightsOverview',
);
}
public function addReportToInsightsOverview(&$reports)
{
$reports['UserCountry_getCountry'] = array();
}
public function setTrackerCacheGeneral(&$cache)
{
$cache['currentLocationProviderId'] = LocationProvider::getCurrentProviderId();
}
public function getStylesheetFiles(&$stylesheets)
{
$stylesheets[] = "plugins/UserCountry/stylesheets/userCountry.less";
}
public function getJsFiles(&$jsFiles)
{
$jsFiles[] = "plugins/UserCountry/angularjs/location-provider-selection/location-provider-selection.controller.js";
$jsFiles[] = "plugins/UserCountry/angularjs/location-provider-selection/location-provider-selection.directive.js";
$jsFiles[] = "plugins/UserCountry/angularjs/location-provider-updater/location-provider-updater.controller.js";
$jsFiles[] = "plugins/UserCountry/angularjs/location-provider-updater/location-provider-updater.directive.js";
}
/**
* Returns a list of country codes for a given continent code.
*
* @param string $continent The continent code.
* @return array
*/
public static function getCountriesForContinent($continent)
{
/** @var RegionDataProvider $regionDataProvider */
$regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider');
$result = array();
$continent = strtolower($continent);
foreach ($regionDataProvider->getCountryList() as $countryCode => $continentCode) {
if ($continent == $continentCode) {
$result[] = $countryCode;
}
}
return array('SQL' => "'" . implode("', '", $result) . "', ?",
'bind' => '-'); // HACK: SegmentExpression requires a $bind, even if there's nothing to bind
}
/**
* Returns true if a GeoIP provider is installed & working, false if otherwise.
*
* @return bool
*/
public function isGeoIPWorking()
{
$provider = LocationProvider::getCurrentProvider();
return $provider instanceof GeoIp
&& $provider->isAvailable() === true
&& $provider->isWorking() === true;
}
public function getClientSideTranslationKeys(&$translationKeys)
{
$translationKeys[] = "UserCountry_FatalErrorDuringDownload";
$translationKeys[] = "UserCountry_SetupAutomaticUpdatesOfGeoIP";
$translationKeys[] = "General_Done";
$translationKeys[] = "General_Save";
$translationKeys[] = "General_Continue";
}
public static function isGeoLocationAdminEnabled()
{
return (bool) Config::getInstance()->General['enable_geolocation_admin'];
}
}
|