From 5027f4a0b496d12ac2db93e64356b32ed63540d1 Mon Sep 17 00:00:00 2001 From: bencroker Date: Sun, 11 Aug 2024 10:18:14 +0200 Subject: [PATCH] Use unavatar.io with fallback SVG --- CHANGELOG.md | 6 ++++++ composer.json | 2 +- src/assets/CpAsset.php | 7 ------- src/elements/ContactElement.php | 36 ++++++++++++++++++++++----------- src/resources/css/cp.css | 5 ----- 5 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 src/resources/css/cp.css diff --git a/CHANGELOG.md b/CHANGELOG.md index 538fa8d8..de4876ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes for Campaign +## 3.4.3 - Unreleased + +### Changed + +- Contact avatars are now fetched from unavatar.io instead of gravatar.com, and a fallback SVG with initials is used if none is found. + ## 3.4.2 - 2024-08-02 ### Changed diff --git a/composer.json b/composer.json index 084be03b..c4328186 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "putyourlightson/craft-campaign", "description": "Send and manage email campaigns, contacts and mailing lists.", - "version": "3.4.2", + "version": "3.4.3", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/campaign", "license": "proprietary", diff --git a/src/assets/CpAsset.php b/src/assets/CpAsset.php index 35398fae..8648fcc1 100644 --- a/src/assets/CpAsset.php +++ b/src/assets/CpAsset.php @@ -28,13 +28,6 @@ class CpAsset extends AssetBundle CraftCpAsset::class, ]; - /** - * @inheritdoc - */ - public $css = [ - 'css/cp.css', - ]; - /** * @inheritdoc */ diff --git a/src/elements/ContactElement.php b/src/elements/ContactElement.php index e17c38ac..e251f376 100755 --- a/src/elements/ContactElement.php +++ b/src/elements/ContactElement.php @@ -462,7 +462,7 @@ protected function defineRules(): array */ public function getPostEditUrl(): ?string { - return UrlHelper::cpUrl("campaign/contacts"); + return UrlHelper::cpUrl('campaign/contacts'); } /** @@ -895,20 +895,32 @@ public function getStatus(): ?string } /** - * @inheritdoc + * Returns an image from unavatar.io, with an SVG behind it as a fallback. + * + * @see User::getThumbHtml() */ - public function thumbUrl(int $size): ?string + public function getThumbHtml(int $size): ?string { - // Get image from Gravatar, defaulting to a blank image - return 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($this->email))) . '?d=blank&s=' . $size; - } + $value = strtolower(trim($this->email)); + $image = Html::img('https://unavatar.io/' . $value . '?fallback=false', [ + 'width' => $size, + 'height' => $size, + ]); - /** - * @inheritdoc - */ - public function hasRoundedThumb(): bool - { - return true; + $initials = mb_strtoupper(mb_substr(str_replace('@', '', $value), 0, 2)); + $svg = << + + $initials + + XML; + + $options = [ + 'class' => 'thumb rounded', + ]; + + return Html::tag('div', $svg, $options) + . Html::tag('div', $image, $options + ['style' => 'position: absolute']); } /** diff --git a/src/resources/css/cp.css b/src/resources/css/cp.css deleted file mode 100644 index 47278c4d..00000000 --- a/src/resources/css/cp.css +++ /dev/null @@ -1,5 +0,0 @@ -.element.hasthumb[data-type="putyourlightson\\campaign\\elements\\ContactElement"] .elementthumb { - background: url('../images/user.svg'); - background-size: cover; - border-radius: 50%; -}