diff options
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | core/API/Request.php | 29 | ||||
-rw-r--r-- | plugins/API/API.php | 8 | ||||
-rw-r--r-- | plugins/PrivacyManager/templates/gdprOverview.twig | 2 |
4 files changed, 43 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d1b2661a6..9e27d1a7dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ This is the Developer Changelog for Matomo platform developers. All changes in o The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)** lets you see more details about any Matomo release, such as the list of new guides and FAQs, security fixes, and links to all closed issues. +## Matomo 3.5.1 + +### New APIs + +* Added new method `Piwik\API\Request::isRootRequestApiRequest()` to detect if the root request is an API request. + ## Matomo 3.5.0 ### Breaking Changes diff --git a/core/API/Request.php b/core/API/Request.php index bb6a70ce4a..b4859bb85a 100644 --- a/core/API/Request.php +++ b/core/API/Request.php @@ -10,6 +10,7 @@ namespace Piwik\API; use Exception; use Piwik\Access; +use Piwik\Cache; use Piwik\Common; use Piwik\DataTable; use Piwik\Exception\PluginDeactivatedException; @@ -294,8 +295,34 @@ class Request } /** + * @ignore + * @internal + * @param bool $isRootRequestApiRequest + */ + public static function setIsRootRequestApiRequest($isRootRequestApiRequest) + { + Cache::getTransientCache()->save('API.setIsRootRequestApiRequest', $isRootRequestApiRequest); + } + + /** + * Detect if the root request (the actual request) is an API request or not. To detect whether an API is currently + * request within any request, have a look at {@link isApiRequest()}. + * + * @return bool + * @throws Exception + */ + public static function isRootRequestApiRequest() + { + $isApi = Cache::getTransientCache()->fetch('API.setIsRootRequestApiRequest'); + return !empty($isApi); + } + + /** * Detect if request is an API request. Meaning the module is 'API' and an API method having a valid format was - * specified. + * specified. Note that this method will return true even if the actual request is for example a regular UI + * reporting page request but within this request we are currently processing an API request (eg a + * controller calls Request::processRequest('API.getMatomoVersion')). To find out if the root request is an API + * request or not, call {@link isRootRequestApiRequest()} * * @param array $request eg array('module' => 'API', 'method' => 'Test.getMethod') * @return bool diff --git a/plugins/API/API.php b/plugins/API/API.php index c4553d81b3..dad8a602e2 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -749,10 +749,16 @@ class Plugin extends \Piwik\Plugin public function registerEvents() { return array( - 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles' + 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', + 'Platform.initialized' => 'detectIsApiRequest' ); } + public function detectIsApiRequest() + { + Request::setIsRootRequestApiRequest(Request::isApiRequest($request = null)); + } + public function getStylesheetFiles(&$stylesheets) { $stylesheets[] = "plugins/API/stylesheets/listAllAPI.less"; diff --git a/plugins/PrivacyManager/templates/gdprOverview.twig b/plugins/PrivacyManager/templates/gdprOverview.twig index 790b76f1d3..2ed97438ef 100644 --- a/plugins/PrivacyManager/templates/gdprOverview.twig +++ b/plugins/PrivacyManager/templates/gdprOverview.twig @@ -14,6 +14,8 @@ </p> </div> + {{ postEvent('Template.afterGDPROverviewIntro') }} + <div piwik-content-block content-title="GDPR checklists"> <p>If you are processing personal data of European citizens through Matomo, even if your company is located outside Europe, you need to fulfill GDPR obligations and this guide will help you. <br /><br /> |