55class 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
0 commit comments