diff options
author | Peter Zhang <peter@innocraft.com> | 2022-01-26 03:14:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-26 03:14:48 +0300 |
commit | a0705d8fd53f3818c517fa386c0e377196937942 (patch) | |
tree | cf19a84c1fbe2eb24c76ff4c02eb8f3eba323260 /core | |
parent | fed704ef22c36ff7e941a713faf5c542c6048b0e (diff) |
add date, period params into common function (#18653)
* Update Common.php
add array check in common request
* Update Common.php
test
* add common period and date function
add common period and date function
* Update core/Piwik.php
Co-authored-by: Stefan Giehl <stefan@matomo.org>
* Update core/Piwik.php
Co-authored-by: Stefan Giehl <stefan@matomo.org>
* update function
update function
* Update core/Piwik.php
Co-authored-by: Stefan Giehl <stefan@matomo.org>
* Update Controller.php
update isset check
Co-authored-by: Stefan Giehl <stefan@matomo.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/Piwik.php | 12 | ||||
-rw-r--r-- | core/Plugin/Controller.php | 27 |
2 files changed, 21 insertions, 18 deletions
diff --git a/core/Piwik.php b/core/Piwik.php index e0c25d81d3..3ac780324b 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -185,7 +185,7 @@ class Piwik $user = APIUsersManager::getInstance()->getUser(Piwik::getCurrentUserLogin()); return $user['date_registered'] ?? ''; } - + /** * Returns the current user's Last Seen. * @@ -889,4 +889,14 @@ class Piwik return $translator->translate($translationId, $args, $language); } + + public static function getPeriod($default = null) + { + return Common::getRequestVar('period', $default, 'string'); + } + + public static function getDate($default = null) + { + return Common::getRequestVar('date', $default, 'string'); + } } diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php index ca2f169895..953fd7eed2 100644 --- a/core/Plugin/Controller.php +++ b/core/Plugin/Controller.php @@ -476,25 +476,18 @@ abstract class Controller */ protected function getGraphParamsModified($paramsToSet = array()) { - if (!isset($paramsToSet['period'])) { - $period = Common::getRequestVar('period'); - } else { - $period = $paramsToSet['period']; + try { + $period = isset($paramsToSet['period']) ?? Piwik::getPeriod(); + } catch (\Exception $e) { + $period = null; } + if ($period === 'range') { return $paramsToSet; } - if (!isset($paramsToSet['range'])) { - $range = 'last30'; - } else { - $range = $paramsToSet['range']; - } - if (!isset($paramsToSet['date'])) { - $endDate = $this->strDate; - } else { - $endDate = $paramsToSet['date']; - } + $range = isset($paramsToSet['range']) ?? 'last30'; + $endDate = isset($paramsToSet['date']) ?? $this->strDate; if (is_null($this->site)) { throw new NoAccessException("Website not initialized, check that you are logged in and/or using the correct token_auth."); @@ -640,10 +633,10 @@ abstract class Controller $maxDate = Date::factory('now', $siteTimezone); $this->setMaxDateView($maxDate, $view); - $rawDate = Common::getRequestVar('date'); + $rawDate = Piwik::getDate(); Period::checkDateFormat($rawDate); - $periodStr = Common::getRequestVar('period'); + $periodStr = Piwik::getPeriod(); if ($periodStr !== 'range') { $date = Date::factory($this->strDate); @@ -923,7 +916,7 @@ abstract class Controller $periodValidator = new PeriodValidator(); - $currentPeriod = Common::getRequestVar('period'); + $currentPeriod = Piwik::getPeriod(); $availablePeriods = $periodValidator->getPeriodsAllowedForUI(); if (! $periodValidator->isPeriodAllowedForUI($currentPeriod)) { |