From 6a43cc2bc337c63eaed132e1fb0cf31909460dc5 Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Sun, 14 Feb 2021 21:33:02 +0100 Subject: [PATCH] allow also showing the avatar in the visitor log --- ProfileAvatar.php | 18 ++++++++++++++++++ UserSettings.php | 18 ++++++++++++++++-- VisitorDetails.php | 5 ----- lang/de.json | 4 +++- lang/en.json | 4 +++- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/ProfileAvatar.php b/ProfileAvatar.php index ac807f9..bacba1c 100644 --- a/ProfileAvatar.php +++ b/ProfileAvatar.php @@ -2,9 +2,27 @@ namespace Piwik\Plugins\ProfileAvatar; +use Piwik\DataTable\Row; use Piwik\Plugin; class ProfileAvatar extends Plugin { + public function registerEvents() + { + return array( + 'Live.renderVisitorDetails' => 'addImageToTemplate', + ); + } + public function addImageToTemplate(string &$outString, Row $visit) + { + $settings = new UserSettings(); + if (!$settings->showInVisitorLog->getValue()) { + return; + } + $visitorID = $visit->getColumn("visitorId"); + $hash = hash("sha256", $visitorID); + + $outString .= ""; + } } diff --git a/UserSettings.php b/UserSettings.php index c2e3d96..727c1cc 100644 --- a/UserSettings.php +++ b/UserSettings.php @@ -20,6 +20,9 @@ class UserSettings extends \Piwik\Settings\Plugin\UserSettings /** @var Setting */ public $dataURLs; + /** @var Setting */ + public $showInVisitorLog; + protected $title = "Visitor Profile Avatar"; protected function init() @@ -27,9 +30,11 @@ class UserSettings extends \Piwik\Settings\Plugin\UserSettings $this->avatarType = $this->createAvatarTypeSetting(); $this->dataURLs = $this->createDataURLsSetting(); + + $this->showInVisitorLog = $this->createShowInVisitorLogSetting(); } - private function createAvatarTypeSetting():Setting + private function createAvatarTypeSetting(): Setting { return $this->makeSetting("avatarType", "CatAvatar", FieldConfig::TYPE_STRING, function (FieldConfig $field) { $field->title = Piwik::translate('ProfileAvatar_AvatarTypeTitle');; @@ -39,7 +44,7 @@ class UserSettings extends \Piwik\Settings\Plugin\UserSettings }); } - private function createDataURLsSetting():Setting + private function createDataURLsSetting(): Setting { return $this->makeSetting("dataURLs", FALSE, FieldConfig::TYPE_BOOL, function (FieldConfig $field) { $field->title = Piwik::translate('ProfileAvatar_DataURLsTitle'); @@ -47,4 +52,13 @@ class UserSettings extends \Piwik\Settings\Plugin\UserSettings $field->description = Piwik::translate('ProfileAvatar_DataURLsDescription'); }); } + + private function createShowInVisitorLogSetting(): Setting + { + return $this->makeSetting("showInVisitorLog", FALSE, FieldConfig::TYPE_BOOL, function (FieldConfig $field) { + $field->title = Piwik::translate('ProfileAvatar_ShowInVisitorLogTitle'); + $field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX; + $field->description = Piwik::translate('ProfileAvatar_ShowInVisitorLogDescription'); + }); + } } diff --git a/VisitorDetails.php b/VisitorDetails.php index a6836af..e54558f 100644 --- a/VisitorDetails.php +++ b/VisitorDetails.php @@ -20,9 +20,4 @@ class VisitorDetails extends VisitorDetailsAbstract $profile['visitorAvatar'] = "?module=ProfileAvatar&action=getProfileAvatar&hash=$hash"; } } - - public function extendVisitorDetails(&$visitor) - { - } - } diff --git a/lang/de.json b/lang/de.json index a07273e..97a6a74 100644 --- a/lang/de.json +++ b/lang/de.json @@ -3,6 +3,8 @@ "AvatarTypeTitle": "Avatar Typ", "AvatarTypeDescription": "Wähle das Aussehen der Avatars aus.", "DataURLsTitle": "Verwende data URLs", - "DataURLsDescription": "Wenn dies aktiviert ist, werden die Bilder in der ursprünglichen Anfrage mitgesendet, was die Ladezeit verringert, aber vor allem bei den größeren Bildern die Größe von API Anfragen stark erhöhen kann." + "DataURLsDescription": "Wenn dies aktiviert ist, werden die Bilder in der ursprünglichen Anfrage mitgesendet, was die Ladezeit verringert, aber vor allem bei den größeren Bildern die Größe von API Anfragen stark erhöhen kann.", + "ShowInVisitorLogTitle": "Im Besucher-Log anzeigen", + "ShowInVisitorLogDescription": "Wenn dies aktiviert ist, werden die Avatare auch im Besucher-Log angezeigt." } } diff --git a/lang/en.json b/lang/en.json index b59be32..cc1d3f0 100644 --- a/lang/en.json +++ b/lang/en.json @@ -3,6 +3,8 @@ "AvatarTypeTitle": "Avatar Type", "AvatarTypeDescription": "Choose the mode for generating avatars.", "DataURLsTitle": "Use data URLs", - "DataURLsDescription": "Enabling this ships the images in the main request which causes them to load much faster, but especially with larger images this can bloat the API requests." + "DataURLsDescription": "Enabling this ships the images in the main request which causes them to load much faster, but especially with larger images this can bloat the API requests.", + "ShowInVisitorLogTitle": "Show in Visitor Log", + "ShowInVisitorLogDescription": "Enabling this also shows the avatar in the Visitor Log." } }