1
0
Fork 0
mirror of https://github.com/Findus23/plugin-ProfileAvatar.git synced 2024-09-19 15:23:45 +02:00

allow also showing the avatar in the visitor log

This commit is contained in:
Lukas Winkler 2021-02-14 21:33:02 +01:00
parent 268adcd2d0
commit 6a43cc2bc3
Signed by: lukas
GPG key ID: 54DE4D798D244853
5 changed files with 40 additions and 9 deletions

View file

@ -2,9 +2,27 @@
namespace Piwik\Plugins\ProfileAvatar; namespace Piwik\Plugins\ProfileAvatar;
use Piwik\DataTable\Row;
use Piwik\Plugin; use Piwik\Plugin;
class ProfileAvatar extends 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 .= "<img width='32' height='32' alt='user profile' src='?module=ProfileAvatar&action=getProfileAvatar&hash=$hash' aria-hidden='true'>";
}
} }

View file

@ -20,6 +20,9 @@ class UserSettings extends \Piwik\Settings\Plugin\UserSettings
/** @var Setting */ /** @var Setting */
public $dataURLs; public $dataURLs;
/** @var Setting */
public $showInVisitorLog;
protected $title = "Visitor Profile Avatar"; protected $title = "Visitor Profile Avatar";
protected function init() protected function init()
@ -27,9 +30,11 @@ class UserSettings extends \Piwik\Settings\Plugin\UserSettings
$this->avatarType = $this->createAvatarTypeSetting(); $this->avatarType = $this->createAvatarTypeSetting();
$this->dataURLs = $this->createDataURLsSetting(); $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) { return $this->makeSetting("avatarType", "CatAvatar", FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = Piwik::translate('ProfileAvatar_AvatarTypeTitle');; $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) { return $this->makeSetting("dataURLs", FALSE, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('ProfileAvatar_DataURLsTitle'); $field->title = Piwik::translate('ProfileAvatar_DataURLsTitle');
@ -47,4 +52,13 @@ class UserSettings extends \Piwik\Settings\Plugin\UserSettings
$field->description = Piwik::translate('ProfileAvatar_DataURLsDescription'); $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');
});
}
} }

View file

@ -20,9 +20,4 @@ class VisitorDetails extends VisitorDetailsAbstract
$profile['visitorAvatar'] = "?module=ProfileAvatar&action=getProfileAvatar&hash=$hash"; $profile['visitorAvatar'] = "?module=ProfileAvatar&action=getProfileAvatar&hash=$hash";
} }
} }
public function extendVisitorDetails(&$visitor)
{
}
} }

View file

@ -3,6 +3,8 @@
"AvatarTypeTitle": "Avatar Typ", "AvatarTypeTitle": "Avatar Typ",
"AvatarTypeDescription": "Wähle das Aussehen der Avatars aus.", "AvatarTypeDescription": "Wähle das Aussehen der Avatars aus.",
"DataURLsTitle": "Verwende data URLs", "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."
} }
} }

View file

@ -3,6 +3,8 @@
"AvatarTypeTitle": "Avatar Type", "AvatarTypeTitle": "Avatar Type",
"AvatarTypeDescription": "Choose the mode for generating avatars.", "AvatarTypeDescription": "Choose the mode for generating avatars.",
"DataURLsTitle": "Use data URLs", "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."
} }
} }