From 514fc90f0f13f1150b8707176e199a70024728f8 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 12 Sep 2018 17:30:53 -0700 Subject: [PATCH 1/2] In Overlay do not call API directly since it does not have access to the token auth. --- plugins/Overlay/Controller.php | 22 ++++++++++++++++++++++ plugins/Overlay/client/client.js | 5 ++--- plugins/Overlay/client/followingpages.js | 4 ++-- plugins/Overlay/client/translations.js | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/plugins/Overlay/Controller.php b/plugins/Overlay/Controller.php index 8b8b5b6df75..d264b7c184b 100644 --- a/plugins/Overlay/Controller.php +++ b/plugins/Overlay/Controller.php @@ -12,6 +12,7 @@ use Piwik\API\Request; use Piwik\Common; use Piwik\Config; +use Piwik\FrontController; use Piwik\Metrics; use Piwik\Piwik; use Piwik\Plugin\Report; @@ -37,6 +38,21 @@ public function __construct(SegmentFormatter $segmentFormatter) parent::__construct(); } + public function getTranslations() + { + return $this->apiRequest('getTranslations'); + } + + public function getExcludedQueryParameters() + { + return $this->apiRequest('getExcludedQueryParameters'); + } + + public function getFollowingPages() + { + return $this->apiRequest('getFollowingPages'); + } + /** The index of the plugin */ public function index() { @@ -235,4 +251,10 @@ protected function outputCORSHeaders() $corsHandler = new CORSHandler(); $corsHandler->handle(); } + + private function apiRequest($methodName) + { + $_GET['method'] = $_POST['method'] = 'Overlay.' . $methodName; + return FrontController::getInstance()->dispatch('API', 'index'); + } } diff --git a/plugins/Overlay/client/client.js b/plugins/Overlay/client/client.js index 9ae78cf3b1d..9a0a7b8a837 100644 --- a/plugins/Overlay/client/client.js +++ b/plugins/Overlay/client/client.js @@ -143,9 +143,8 @@ var Piwik_Overlay_Client = (function () { }, /** Piwik Overlay API Request */ - api: function (method, callback, additionalParams) { - var url = piwikRoot + 'index.php?module=API&method=Overlay.' + method - + '&idSite=' + idSite + '&period=' + period + '&date=' + date + '&format=JSON&filter_limit=-1'; + controller: function (method, callback, additionalParams) { + var url = piwikRoot + 'index.php?module=Overlay&action=' + method + '&idSite=' + idSite + '&period=' + period + '&date=' + date + '&format=JSON&filter_limit=-1'; if (segment) { url += '&segment=' + segment; diff --git a/plugins/Overlay/client/followingpages.js b/plugins/Overlay/client/followingpages.js index bc22d0a53c1..335e88b1648 100644 --- a/plugins/Overlay/client/followingpages.js +++ b/plugins/Overlay/client/followingpages.js @@ -29,7 +29,7 @@ var Piwik_Overlay_FollowingPages = (function () { var followingPagesLoaded = false; // load excluded params - Piwik_Overlay_Client.api('getExcludedQueryParameters', function (data) { + Piwik_Overlay_Client.controller('getExcludedQueryParameters', function (data) { for (var i = 0; i < data.length; i++) { if (typeof data[i] == 'object') { data[i] = data[i][0]; @@ -44,7 +44,7 @@ var Piwik_Overlay_FollowingPages = (function () { }); // load following pages - Piwik_Overlay_Client.api('getFollowingPages', function (data) { + Piwik_Overlay_Client.controller('getFollowingPages', function (data) { followingPages = data; processFollowingPages(); diff --git a/plugins/Overlay/client/translations.js b/plugins/Overlay/client/translations.js index 9665b920a91..40cc7722d8f 100644 --- a/plugins/Overlay/client/translations.js +++ b/plugins/Overlay/client/translations.js @@ -11,7 +11,7 @@ var Piwik_Overlay_Translations = (function () { */ initialize: function (callback) { // Load translation data - Piwik_Overlay_Client.api('getTranslations', function (data) { + Piwik_Overlay_Client.controller('getTranslations', function (data) { translations = data[0]; callback(); }); From 12ae29a5a723e5f521918dd36084999d5e37e47b Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 12 Sep 2018 18:44:17 -0700 Subject: [PATCH 2/2] Use API Request object instead of going through API controller. --- plugins/Overlay/Controller.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/Overlay/Controller.php b/plugins/Overlay/Controller.php index d264b7c184b..bbc4d3ffce3 100644 --- a/plugins/Overlay/Controller.php +++ b/plugins/Overlay/Controller.php @@ -12,15 +12,12 @@ use Piwik\API\Request; use Piwik\Common; use Piwik\Config; -use Piwik\FrontController; use Piwik\Metrics; use Piwik\Piwik; -use Piwik\Plugin\Report; use Piwik\Plugins\Actions\ArchivingHelper; use Piwik\Plugins\SegmentEditor\SegmentFormatter; use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\ProxyHttp; -use Piwik\Segment; use Piwik\Tracker\Action; use Piwik\Tracker\PageUrl; use Piwik\View; @@ -254,7 +251,7 @@ protected function outputCORSHeaders() private function apiRequest($methodName) { - $_GET['method'] = $_POST['method'] = 'Overlay.' . $methodName; - return FrontController::getInstance()->dispatch('API', 'index'); + $request = new Request('method=Overlay.'.$methodName); + return $request->process(); } }