-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I deserve a gold medal or a beer
- Loading branch information
Showing
243 changed files
with
3,520 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,249 @@ | ||
<?php | ||
/** | ||
* Piwik - 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\UserCountryMapIslandora; | ||
|
||
use Exception; | ||
use Piwik\API\Request; | ||
use Piwik\Common; | ||
use Piwik\Config; | ||
use Piwik\Container\StaticContainer; | ||
use Piwik\Piwik; | ||
use Piwik\Plugins\Goals\API as APIGoals; | ||
use Piwik\Plugins\VisitsSummary\API as VisitsSummaryAPI; | ||
use Piwik\Site; | ||
use Piwik\Translation\Translator; | ||
use Piwik\View; | ||
|
||
require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php'; | ||
|
||
/** | ||
* | ||
*/ | ||
class Controller extends \Piwik\Plugin\Controller | ||
{ | ||
// By default plot up to the last 3 days of visitors on the map, for low traffic sites | ||
const REAL_TIME_WINDOW = 'last3'; | ||
|
||
/** | ||
* @var Translator | ||
*/ | ||
private $translator; | ||
|
||
public function __construct(Translator $translator) | ||
{ | ||
$this->translator = $translator; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
public function visitorMap($fetch = false, $segmentOverride = false) | ||
{ | ||
$this->checkUserCountryPluginEnabled(); | ||
|
||
$this->checkSitePermission(); | ||
Piwik::checkUserHasViewAccess($this->idSite); | ||
|
||
$period = Common::getRequestVar('period'); | ||
$date = Common::getRequestVar('date'); | ||
|
||
if (!empty($segmentOverride)) { | ||
$segment = $segmentOverride; | ||
} else { | ||
$segment = Request::getRawSegmentFromRequest(); | ||
if (empty($segment)) { | ||
$segment = ''; | ||
} | ||
} | ||
|
||
$token_auth = Piwik::getCurrentUserTokenAuth(); | ||
|
||
$view = new View('@UserCountryMapIslandora/visitorMap'); | ||
|
||
// request visits summary | ||
$request = new Request( | ||
'method=VisitsSummary.get&format=php' | ||
. '&idSite=' . $this->idSite | ||
. '&period=' . $period | ||
. '&date=' . $date | ||
. '&segment=' . $segment | ||
. '&token_auth=' . $token_auth | ||
. '&filter_limit=-1' | ||
); | ||
$config = array(); | ||
$config['visitsSummary'] = Common::safe_unserialize($request->process()); | ||
$config['countryDataUrl'] = $this->_report('UserCountry', 'getCountry', | ||
$this->idSite, $period, $date, $token_auth, false, $segment); | ||
$config['regionDataUrl'] = $this->_report('UserCountry', 'getRegion', | ||
$this->idSite, $period, $date, $token_auth, true, $segment); | ||
$config['cityDataUrl'] = $this->_report('UserCountry', 'getCity', | ||
$this->idSite, $period, $date, $token_auth, true, $segment); | ||
$config['countrySummaryUrl'] = $this->getApiRequestUrl('VisitsSummary', 'get', | ||
$this->idSite, $period, $date, $token_auth, true, $segment); | ||
$view->defaultMetric = array_key_exists('nb_uniq_visitors', $config['visitsSummary']) ? 'nb_uniq_visitors' : 'nb_visits'; | ||
|
||
$noVisitTranslation = $this->translator->translate('UserCountryMapIslandora_NoVisit'); | ||
// some translations containing metric number | ||
$translations = array( | ||
'nb_visits' => $this->translator->translate('General_NVisits'), | ||
'no_visit' => $noVisitTranslation, | ||
'nb_actions' => $this->translator->translate('VisitsSummary_NbActionsDescription'), | ||
'nb_actions_per_visit' => $this->translator->translate('VisitsSummary_NbActionsPerVisit'), | ||
'bounce_rate' => $this->translator->translate('VisitsSummary_NbVisitsBounced'), | ||
'avg_time_on_site' => $this->translator->translate('VisitsSummary_AverageVisitDuration'), | ||
'and_n_others' => $this->translator->translate('UserCountryMapIslandora_AndNOthers'), | ||
'nb_uniq_visitors' => $this->translator->translate('General_NUniqueVisitors'), | ||
'nb_users' => $this->translator->translate('VisitsSummary_NbUsers'), | ||
); | ||
|
||
foreach ($translations as &$translation) { | ||
if (false === strpos($translation, '%s') | ||
&& $translation !== $noVisitTranslation) { | ||
$translation = '%s ' . $translation; | ||
} | ||
} | ||
|
||
$translations['one_visit'] = $this->translator->translate('General_OneVisit'); | ||
$translations['no_data'] = $this->translator->translate('CoreHome_ThereIsNoDataForThisReport'); | ||
|
||
$view->localeJSON = json_encode($translations); | ||
|
||
$view->reqParamsJSON = $this->getEnrichedRequest($params = array( | ||
'period' => $period, | ||
'idSite' => $this->idSite, | ||
'date' => $date, | ||
'segment' => $segment, | ||
'token_auth' => $token_auth, | ||
'enable_filter_excludelowpop' => 1, | ||
'filter_excludelowpop_value' => -1 | ||
)); | ||
|
||
$view->metrics = $config['metrics'] = $this->getMetrics($this->idSite, $period, $date, $token_auth); | ||
// Reuse Original Plugins data | ||
$config['svgBasePath'] = 'plugins/UserCountryMap/svg/'; | ||
// Allow our own CSS override | ||
$config['mapCssPath'] = 'plugins/plugin-UserCountryMapIslandora/stylesheets/map.css'; | ||
$view->config = json_encode($config); | ||
$view->noData = empty($config['visitsSummary']['nb_visits']); | ||
|
||
$countriesByIso = array(); | ||
$regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); | ||
$countries = array_keys($regionDataProvider->getCountryList()); | ||
|
||
foreach ($countries AS $country) { | ||
$countriesByIso[strtoupper($country)] = Piwik::translate('Intl_Country_'.strtoupper($country)); | ||
} | ||
|
||
$view->countriesByIso = $countriesByIso; | ||
|
||
$view->continents = array( | ||
'AF' => \Piwik\Plugins\UserCountry\continentTranslate('afr'), | ||
'AS' => \Piwik\Plugins\UserCountry\continentTranslate('asi'), | ||
'EU' => \Piwik\Plugins\UserCountry\continentTranslate('eur'), | ||
'NA' => \Piwik\Plugins\UserCountry\continentTranslate('amn'), | ||
'OC' => \Piwik\Plugins\UserCountry\continentTranslate('oce'), | ||
'SA' => \Piwik\Plugins\UserCountry\continentTranslate('ams') | ||
); | ||
|
||
return $view->render(); | ||
} | ||
|
||
|
||
private function getEnrichedRequest($params, $encode = true) | ||
{ | ||
$params['format'] = 'json'; | ||
$params['showRawMetrics'] = 1; | ||
if (empty($params['segment'])) { | ||
$segment = Request::getRawSegmentFromRequest(); | ||
if (!empty($segment)) { | ||
$params['segment'] = $segment; | ||
} | ||
} | ||
|
||
if (!empty($params['segment'])) { | ||
$params['segment'] = urldecode($params['segment']); | ||
} | ||
|
||
if ($encode) { | ||
$params = json_encode($params); | ||
} | ||
|
||
return $params; | ||
} | ||
|
||
private function checkUserCountryPluginEnabled() | ||
{ | ||
if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated('UserCountry')) { | ||
throw new Exception($this->translator->translate('General_Required', 'Plugin UserCountry')); | ||
} | ||
// Check also if we have the parent plugin enabled. | ||
if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated('UserCountryMap')) { | ||
throw new Exception($this->translator->translate('General_Required', 'Plugin UserCountryMap')); | ||
} | ||
} | ||
|
||
private function getMetrics($idSite, $period, $date, $token_auth) | ||
{ | ||
$request = new Request( | ||
'method=API.getMetadata&format=PHP' | ||
. '&apiModule=UserCountry&apiAction=getCountry' | ||
. '&idSite=' . $idSite | ||
. '&period=' . $period | ||
. '&date=' . $date | ||
. '&token_auth=' . $token_auth | ||
. '&filter_limit=-1' | ||
); | ||
$metaData = Common::safe_unserialize($request->process()); | ||
|
||
$metrics = array(); | ||
if (!empty($metaData[0]['metrics']) && is_array($metaData[0]['metrics'])) { | ||
foreach ($metaData[0]['metrics'] as $id => $val) { | ||
// todo: should use SettingsPiwik::isUniqueVisitorsEnabled ? | ||
if (Common::getRequestVar('period') == 'day' || $id != 'nb_uniq_visitors') { | ||
$metrics[] = array($id, $val); | ||
} | ||
} | ||
} | ||
if (!empty($metaData[0]['processedMetrics']) && is_array($metaData[0]['processedMetrics'])) { | ||
foreach ($metaData[0]['processedMetrics'] as $id => $val) { | ||
$metrics[] = array($id, $val); | ||
} | ||
} | ||
return $metrics; | ||
} | ||
|
||
private function getApiRequestUrl($module, $action, $idSite, $period, $date, $token_auth, $filter_by_country = false, $segmentOverride = false) | ||
{ | ||
// use processed reports | ||
$url = "?module=" . $module | ||
. "&method=" . $module . "." . $action . "&format=JSON" | ||
. "&idSite=" . $idSite | ||
. "&period=" . $period | ||
. "&date=" . $date | ||
. "&token_auth=" . $token_auth | ||
. "&segment=" . ($segmentOverride ? : Request::getRawSegmentFromRequest()) | ||
. "&enable_filter_excludelowpop=1" | ||
. "&showRawMetrics=1"; | ||
|
||
if ($filter_by_country) { | ||
$url .= "&filter_column=country" | ||
. "&filter_sort_column=nb_visits" | ||
. "&filter_limit=-1" | ||
. "&filter_pattern="; | ||
} else { | ||
$url .= "&filter_limit=-1"; | ||
} | ||
return $url; | ||
} | ||
|
||
private function _report($module, $action, $idSite, $period, $date, $token_auth, $filter_by_country = false, $segmentOverride = false) | ||
{ | ||
return $this->getApiRequestUrl('API', 'getProcessedReport&apiModule=' . $module . '&apiAction=' . $action, | ||
$idSite, $period, $date, $token_auth, $filter_by_country, $segmentOverride); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Piwik - 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\UserCountryMapIslandora; | ||
|
||
use Piwik\FrontController; | ||
use Piwik\Piwik; | ||
use Piwik\Plugins\UserCountryMap | ||
|
||
/** | ||
*/ | ||
class UserCountryMap extends Piwik\Plugins\UserCountryMap | ||
{ | ||
public function postLoad() | ||
{ | ||
Piwik::addAction('Template.leftColumnUserCountry', array('Piwik\Plugins\UserCountryMapIslandora\UserCountryMapIslandora', 'insertMapInLocationReport')); | ||
} | ||
|
||
public static function insertMapInLocationReport(&$out) | ||
{ | ||
$out = '<h2>' . Piwik::translate('UserCountryMapIslandora_VisitorMap') . '</h2>'; | ||
$out .= FrontController::getInstance()->fetchDispatch('UserCountryMapIslandora', 'visitorMap'); | ||
} | ||
|
||
public function registerEvents() | ||
{ | ||
$hooks = array( | ||
'AssetManager.getJavaScriptFiles' => 'getJsFiles', | ||
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', | ||
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys' | ||
); | ||
return $hooks; | ||
} | ||
|
||
public function getJsFiles(&$jsFiles) | ||
{ | ||
$jsFiles[] = "libs/bower_components/visibilityjs/lib/visibility.core.js"; | ||
$jsFiles[] = "plugins/UserCountryMapIslandora/javascripts/vendor/raphael.min.js"; | ||
$jsFiles[] = "plugins/UserCountryMapIslandora/javascripts/vendor/jquery.qtip.min.js"; | ||
$jsFiles[] = "plugins/UserCountryMapIslandora/javascripts/vendor/kartograph.min.js"; | ||
$jsFiles[] = "libs/bower_components/chroma-js/chroma.min.js"; | ||
$jsFiles[] = "plugins/UserCountryMapIslandora/javascripts/visitor-map.js"; | ||
} | ||
|
||
public function getStylesheetFiles(&$stylesheets) | ||
{ | ||
$stylesheets[] = "plugins/UserCountryMapIslandora/stylesheets/visitor-map.less"; | ||
} | ||
|
||
public function getClientSideTranslationKeys(&$translationKeys) | ||
{ | ||
$translationKeys[] = 'UserCountryMapIslandora_WithUnknownRegion'; | ||
$translationKeys[] = 'UserCountryMapIslandora_WithUnknownCity'; | ||
$translationKeys[] = 'General_UserId'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Piwik - 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\UserCountryMapIslandora\Widgets; | ||
|
||
use Piwik\Widget\WidgetConfig; | ||
|
||
class GetVisitorMap extends \Piwik\Widget\Widget | ||
{ | ||
public static function configure(WidgetConfig $config) | ||
{ | ||
$config->setCategoryId('General_Visitors'); | ||
$config->setSubcategoryId('UserCountry_SubmenuLocations'); | ||
$config->setName('UserCountryMapIslandora_VisitorMap'); | ||
$config->setAction('visitorMap'); | ||
$config->setOrder(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
return array(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
return array(); | ||
?> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.