Skip to content

Commit 47856c5

Browse files
committed
fix: allow different outputs for better backwards compatibility
1 parent 0c63e3a commit 47856c5

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

lib/AvatarHandler.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
class AvatarHandler
66
{
77

8-
public function __construct(private ?string $avatarReturnType = null, private ?string $avatarService = null)
8+
public function __construct(private ?string $avatarReturnType = null, private ?string $avatarService = null, private ?bool $webmentionAvatars = null)
99
{
1010
$this->avatarReturnType = $avatarReturnType ?? option('mauricerenck.komments.avatar.returnType', 'img');
1111
$this->avatarService = $avatarService ?? option('mauricerenck.komments.avatar.service', 'gravatar');
12+
$this->webmentionAvatars = $avatarService ?? option('mauricerenck.komments.avatar.webmentionAvatars', true);
1213
}
1314

14-
public function getAvatar(string $authorGravatar, string $authorName): ?string
15+
public function getAvatar(string $authorAvatarUrl, string $authorName): ?string
1516
{
16-
$avatarString = $this->getAvatarByType($authorGravatar, $authorName);
17+
$avatarString = $this->getAvatarByType($authorAvatarUrl, $authorName);
1718

1819
if ($this->avatarService !== 'gravatar' && $this->avatarReturnType === 'svg') {
1920
return $avatarString;
@@ -24,17 +25,23 @@ public function getAvatar(string $authorGravatar, string $authorName): ?string
2425
}
2526

2627
return <<<HTMLTAG
27-
<img class="u-photo" src="$avatarString" alt="$authorName" />
28+
<img class="u-photo" src="$avatarString" alt="$authorName" />
2829
HTMLTAG;
2930
}
3031

31-
public function getAvatarByType(string $authorGravatar, string $authorName): ?string
32+
public function getAvatarByType(string $authorAvatarUrl, string $authorName): ?string
3233
{
3334
if ($this->avatarService === 'gravatar') {
34-
return $authorGravatar;
35+
return $authorAvatarUrl;
3536
}
3637

37-
if ($this->avatarReturnType) {
38+
if ($this->avatarService !== 'gravatar' && $this->webmentionAvatars) {
39+
if (strpos($authorAvatarUrl, 'gravatar.com') === false) {
40+
return $authorAvatarUrl;
41+
}
42+
}
43+
44+
if ($this->avatarReturnType === 'svg') {
3845
return $this->author_initials_svg_data_uri($authorName)['svg'];
3946
}
4047

tests/KommentsModerationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
final class KommentsModerationTest extends TestCaseMocked
77
{
8-
private $avatar = '<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" class="komment-avatar-initials"> <style> .author-initials-bg { fill: var(--author-bg, #1391a4); } .author-initials-text { fill: var(--author-text, #fff); font-family: var(--author-font-family, system-ui, sans-serif); font-size: var(--author-font-size, 40px); font-weight: var(--author-font-weight, bold); dominant-baseline: middle; text-anchor: middle; text-transform: uppercase; } </style> <rect class="author-initials-bg" width="100" height="100"/> <text x="50" y="55" class="author-initials-text" dominant-baseline="middle" text-anchor="middle" >AN</text> </svg>';
8+
private $avatar = '<img class="u-photo" src="https://api.dicebear.com/9.x/pixel-art/png?seed=AuthorName" alt="Author Name" />';
99

1010
public function setUp(): void
1111
{

vendor/composer/installed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php return array(
22
'root' => array(
33
'name' => 'mauricerenck/komments',
4-
'pretty_version' => '3.1.1',
5-
'version' => '3.1.1.0',
4+
'pretty_version' => '3.2.1',
5+
'version' => '3.2.1.0',
66
'reference' => null,
77
'type' => 'kirby-plugin',
88
'install_path' => __DIR__ . '/../../',
@@ -29,8 +29,8 @@
2929
'dev_requirement' => false,
3030
),
3131
'mauricerenck/komments' => array(
32-
'pretty_version' => '3.1.1',
33-
'version' => '3.1.1.0',
32+
'pretty_version' => '3.2.1',
33+
'version' => '3.2.1.0',
3434
'reference' => null,
3535
'type' => 'kirby-plugin',
3636
'install_path' => __DIR__ . '/../../',

0 commit comments

Comments
 (0)