Skip to content

Commit

Permalink
Use unavatar.io with fallback SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Aug 11, 2024
1 parent 3ed0d29 commit 5027f4a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 0 additions & 7 deletions src/assets/CpAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ class CpAsset extends AssetBundle
CraftCpAsset::class,
];

/**
* @inheritdoc
*/
public $css = [
'css/cp.css',
];

/**
* @inheritdoc
*/
Expand Down
36 changes: 24 additions & 12 deletions src/elements/ContactElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ protected function defineRules(): array
*/
public function getPostEditUrl(): ?string
{
return UrlHelper::cpUrl("campaign/contacts");
return UrlHelper::cpUrl('campaign/contacts');
}

/**
Expand Down Expand Up @@ -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 = <<<XML
<svg version="1.1" baseProfile="full" width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="50" fill="var(--gray-100)"/>
<text x="50" y="66" font-size="46" font-weight="500" font-family="sans-serif" text-anchor="middle" fill="var(--gray-700)">$initials</text>
</svg>
XML;

$options = [
'class' => 'thumb rounded',
];

return Html::tag('div', $svg, $options)
. Html::tag('div', $image, $options + ['style' => 'position: absolute']);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/resources/css/cp.css

This file was deleted.

0 comments on commit 5027f4a

Please sign in to comment.