diff options
author | Stefan Giehl <stefan@matomo.org> | 2022-04-12 10:18:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-12 10:18:44 +0300 |
commit | 341265be9076ce16b96b023029092ddfb0c8b155 (patch) | |
tree | 91a6fa1938c40ef1f3edbfd804d044247c6fb7bf /plugins | |
parent | c45534af3667986cb7b282111f2e683e94fa44c7 (diff) |
Hide visitor id in visits log if profile is disabled (#19078)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Live/Controller.php | 1 | ||||
-rw-r--r-- | plugins/Live/Live.php | 24 | ||||
-rw-r--r-- | plugins/Live/VisitorDetails.php | 20 | ||||
-rw-r--r-- | plugins/Live/templates/_visitorDetails.twig | 2 | ||||
-rw-r--r-- | plugins/Live/templates/_visitorLogIcons.twig | 2 | ||||
-rw-r--r-- | plugins/Live/templates/getLastVisitsStart.twig | 2 |
6 files changed, 29 insertions, 22 deletions
diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php index 8625805495..c94c4e0d58 100644 --- a/plugins/Live/Controller.php +++ b/plugins/Live/Controller.php @@ -98,6 +98,7 @@ class Controller extends \Piwik\Plugin\Controller $_GET['period'] = 'day'; $view = new View('@Live/getLastVisitsStart'); + $view->isProfileEnabled = Live::isVisitorProfileEnabled(); $view->idSite = (int) $this->idSite; $error = ''; $visitors = new DataTable(); diff --git a/plugins/Live/Live.php b/plugins/Live/Live.php index 00b1f4bbae..2fde5cd4e3 100644 --- a/plugins/Live/Live.php +++ b/plugins/Live/Live.php @@ -1,4 +1,5 @@ <?php + /** * Matomo - free/libre analytics platform * @@ -6,6 +7,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * */ + namespace Piwik\Plugins\Live; use Piwik\Cache; @@ -23,7 +25,7 @@ class Live extends \Piwik\Plugin */ public function registerEvents() { - return array( + return [ 'AssetManager.getJavaScriptFiles' => 'getJsFiles', 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', @@ -33,7 +35,7 @@ class Live extends \Piwik\Plugin 'Live.renderVisitorIcons' => 'renderVisitorIcons', 'Template.jsGlobalVariables' => 'addJsGlobalVariables', 'API.getPagesComparisonsDisabledFor' => 'getPagesComparisonsDisabledFor', - ); + ]; } public function getPagesComparisonsDisabledFor(&$pages) @@ -46,8 +48,8 @@ class Live extends \Piwik\Plugin { $actionsToDisplayCollapsed = (int)StaticContainer::get('Live.pageViewActionsToDisplayCollapsed'); $out .= " - piwik.visitorLogEnabled = ".json_encode(self::isVisitorLogEnabled())."; - piwik.visitorProfileEnabled = ".json_encode(self::isVisitorProfileEnabled())."; + piwik.visitorLogEnabled = " . json_encode(self::isVisitorLogEnabled()) . "; + piwik.visitorProfileEnabled = " . json_encode(self::isVisitorProfileEnabled()) . "; piwik.visitorLogActionsToDisplayCollapsed = $actionsToDisplayCollapsed; "; } @@ -77,7 +79,7 @@ class Live extends \Piwik\Plugin $settings = new MeasurableSettings($idSite); if ($settings->disableVisitorLog->getValue() === true) { - throw new \Exception('Visits log is deactivated in website settings. A user with at least admin access can enable this feature in the settings for this website (idSite='.$idSite.').'); + throw new \Exception('Visits log is deactivated in website settings. A user with at least admin access can enable this feature in the settings for this website (idSite=' . $idSite . ').'); } } } @@ -126,7 +128,7 @@ class Live extends \Piwik\Plugin $settings = new MeasurableSettings($idSite); if ($settings->disableVisitorProfile->getValue() === true) { - throw new \Exception('Visitor profile is deactivated in website settings. A user with at least admin access can enable this feature in the settings for this website (idSite='.$idSite.').'); + throw new \Exception('Visitor profile is deactivated in website settings. A user with at least admin access can enable this feature in the settings for this website (idSite=' . $idSite . ').'); } } } @@ -200,11 +202,11 @@ class Live extends \Piwik\Plugin $detailEntries = array_merge($detailEntries, $instance->renderActionTooltip($action, $visitInfo)); } - usort($detailEntries, function($a, $b) { + usort($detailEntries, function ($a, $b) { return version_compare($a[0], $b[0]); }); - foreach ($detailEntries AS $detailEntry) { + foreach ($detailEntries as $detailEntry) { $tooltip .= $detailEntry[1]; } } @@ -218,11 +220,11 @@ class Live extends \Piwik\Plugin $detailEntries = array_merge($detailEntries, $instance->renderVisitorDetails($visitorDetails)); } - usort($detailEntries, function($a, $b) { + usort($detailEntries, function ($a, $b) { return version_compare($a[0], $b[0]); }); - foreach ($detailEntries AS $detailEntry) { + foreach ($detailEntries as $detailEntry) { $renderedDetails .= $detailEntry[1]; } } @@ -267,4 +269,4 @@ class Live extends \Piwik\Plugin return $result; } -}
\ No newline at end of file +} diff --git a/plugins/Live/VisitorDetails.php b/plugins/Live/VisitorDetails.php index 97f78d255d..e709ffbb39 100644 --- a/plugins/Live/VisitorDetails.php +++ b/plugins/Live/VisitorDetails.php @@ -1,4 +1,5 @@ <?php + /** * Matomo - free/libre analytics platform * @@ -6,6 +7,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * */ + namespace Piwik\Plugins\Live; use Piwik\API\Request; @@ -31,7 +33,7 @@ class VisitorDetails extends VisitorDetailsAbstract $currency = $website->getCurrency(); $currencies = APISitesManager::getInstance()->getCurrencySymbols(); - $visitor += array( + $visitor += [ 'idSite' => $idSite, 'idVisit' => $this->getIdVisit(), 'visitIp' => $this->getIp(), @@ -49,7 +51,7 @@ class VisitorDetails extends VisitorDetailsAbstract 'visitServerHour' => $this->getVisitServerHour(), 'lastActionTimestamp' => $this->getTimestampLastAction(), 'lastActionDateTime' => $this->getDateTimeLastAction(), - ); + ]; $visitor['siteCurrency'] = $currency; $visitor['siteCurrencySymbol'] = @$currencies[$visitor['siteCurrency']]; @@ -121,6 +123,7 @@ class VisitorDetails extends VisitorDetailsAbstract public function renderVisitorDetails($visitorDetails) { $view = new View('@Live/_visitorDetails.twig'); + $view->isProfileEnabled = Live::isVisitorProfileEnabled(); $view->sendHeadersWhenRendering = false; $view->visitInfo = $visitorDetails; return [[ 0, $view->render() ]]; @@ -129,6 +132,7 @@ class VisitorDetails extends VisitorDetailsAbstract public function renderIcons($visitorDetails) { $view = new View('@Live/_visitorLogIcons.twig'); + $view->isProfileEnabled = Live::isVisitorProfileEnabled(); $view->sendHeadersWhenRendering = false; $view->visitor = $visitorDetails; return $view->render(); @@ -247,17 +251,16 @@ class VisitorDetails extends VisitorDetailsAbstract $today = Date::today(); $serverDate = $visit->getColumn('firstActionTimestamp'); - return array( + return [ 'date' => $serverDate, 'prettyDate' => Date::factory($serverDate)->getLocalized(Date::DATE_FORMAT_LONG), 'daysAgo' => (int)Date::secondsToDays($today->getTimestamp() - Date::factory($serverDate)->getTimestamp()), 'referrerType' => $visit->getColumn('referrerType'), 'referrerUrl' => $visit->getColumn('referrerUrl') ?: '', 'referralSummary' => self::getReferrerSummaryForVisit($visit), - ); + ]; } - /** * Returns a summary for a visit's referral. * @@ -267,7 +270,8 @@ class VisitorDetails extends VisitorDetailsAbstract public static function getReferrerSummaryForVisit($visit) { $referrerType = $visit->getColumn('referrerType'); - if ($referrerType === false + if ( + $referrerType === false || $referrerType == 'direct' ) { return Piwik::translate('Referrers_DirectEntry'); @@ -277,7 +281,8 @@ class VisitorDetails extends VisitorDetailsAbstract $referrerName = $visit->getColumn('referrerName'); $keyword = $visit->getColumn('referrerKeyword'); - if ($keyword !== false + if ( + $keyword !== false && $keyword != APIReferrers::getKeywordNotDefinedString() ) { $referrerName .= ' (' . $keyword . ')'; @@ -286,7 +291,6 @@ class VisitorDetails extends VisitorDetailsAbstract } if ($referrerType == 'campaign') { - $summary = Piwik::translate('Referrers_ColumnCampaign') . ': ' . $visit->getColumn('referrerName'); $keyword = $visit->getColumn('referrerKeyword'); if (!empty($keyword)) { diff --git a/plugins/Live/templates/_visitorDetails.twig b/plugins/Live/templates/_visitorDetails.twig index f0e22943ce..18b23d1be7 100644 --- a/plugins/Live/templates/_visitorDetails.twig +++ b/plugins/Live/templates/_visitorDetails.twig @@ -3,7 +3,7 @@ {% if isWidget %}<br/>{% else %}-{% endif %} {{ visitInfo.getColumn('serverTimePrettyFirstAction') }}</strong> {% if visitInfo.getColumn('visitIp') is not empty %} <span class="visitor-log-ip-location visitorLogTooltip" title="{% if visitInfo.getColumn('userId') is not empty %}{{ 'General_UserId'|translate }}: {{ visitInfo.getColumn('userId')|rawSafeDecoded }} -{% endif %}{% if visitInfo.getColumn('visitorId') is not empty %}{{ 'General_VisitorID'|translate }}: {{ visitInfo.getColumn('visitorId') }} +{% endif %}{% if isProfileEnabled and visitInfo.getColumn('visitorId') is not empty %}{{ 'General_VisitorID'|translate }}: {{ visitInfo.getColumn('visitorId') }} {% endif %}{% if visitInfo.getColumn('idVisit') is not empty %} {{ 'General_Visit'|translate }} ID: {{ visitInfo.getColumn('idVisit') }} {% endif %}{% if visitInfo.getColumn('latitude') or visitInfo.getColumn('longitude') %}{{ visitInfo.getColumn('location') }} diff --git a/plugins/Live/templates/_visitorLogIcons.twig b/plugins/Live/templates/_visitorLogIcons.twig index 5c85b234a4..f743c9ae3f 100644 --- a/plugins/Live/templates/_visitorLogIcons.twig +++ b/plugins/Live/templates/_visitorLogIcons.twig @@ -23,7 +23,7 @@ {% if visitor.getColumn('language') %}<li>{{ 'UserLanguage_BrowserLanguage'|translate }}: {{ visitor.getColumn('language') }}</li>{% endif %} {% if visitor.getColumn('providerName') %}<li>{{ 'Provider_ColumnProvider'|translate }}: {{ visitor.getColumn('providerName') }}</li>{% endif %} <li>{{ 'General_IP'|translate }}: {{ visitor.getColumn('visitIp') }}</li> - {% if visitor.getColumn('visitorId') is not empty %}<li>{{ 'General_VisitorID'|translate }}: {{ visitor.getColumn('visitorId') }}</li>{% endif %} + {% if isProfileEnabled and visitor.getColumn('visitorId') is not empty %}<li>{{ 'General_VisitorID'|translate }}: {{ visitor.getColumn('visitorId') }}</li>{% endif %} </ul> </span> diff --git a/plugins/Live/templates/getLastVisitsStart.twig b/plugins/Live/templates/getLastVisitsStart.twig index 1218136e45..5440796ead 100644 --- a/plugins/Live/templates/getLastVisitsStart.twig +++ b/plugins/Live/templates/getLastVisitsStart.twig @@ -20,7 +20,7 @@ {% endif %} {{ postEvent('Live.renderVisitorIcons', visitor) }} - {% if not userIsAnonymous %} + {% if isProfileEnabled and not userIsAnonymous %} <a class="visits-live-launch-visitor-profile rightLink" title="{{ 'Live_ViewVisitorProfile'|translate }} {% if visitor.getColumn('userId') is not empty %}{{ visitor.getColumn('userId') }}{% endif %}" data-visitor-id="{{ visitor.getColumn('visitorId') }}"> <span class="icon-visitor-profile"></span> </a> |