[feat] support high resolution avatar

This commit is contained in:
joyqi 2023-09-24 17:31:35 +08:00
parent 157de39b54
commit 3296151409
2 changed files with 17 additions and 4 deletions

View File

@ -281,7 +281,7 @@ class Comments extends Base implements QueryInterface
* @param integer $size 头像尺寸
* @param string|null $default 默认输出头像
*/
public function gravatar(int $size = 32, ?string $default = null)
public function gravatar(int $size = 32, ?string $default = null, $highRes = false)
{
if ($this->options->commentsAvatar && 'comment' == $this->type) {
$rating = $this->options->commentsAvatarRating;
@ -289,7 +289,15 @@ class Comments extends Base implements QueryInterface
Comments::pluginHandle()->trigger($plugged)->call('gravatar', $size, $rating, $default, $this);
if (!$plugged) {
$url = Common::gravatarUrl($this->mail, $size, $rating, $default, $this->request->isSecure());
echo '<img class="avatar" loading="lazy" src="' . $url . '" alt="' .
$srcset = '';
if ($highRes) {
$url2x = Common::gravatarUrl($this->mail, $size * 2, $rating, $default, $this->request->isSecure());
$url3x = Common::gravatarUrl($this->mail, $size * 3, $rating, $default, $this->request->isSecure());
$srcset = ' srcset="' . $url2x . ' 2x, ' . $url3x . ' 3x"';
}
echo '<img class="avatar" loading="lazy" src="' . $url . '"' . $srcset . ' alt="' .
$this->author . '" width="' . $size . '" height="' . $size . '" />';
}
}

View File

@ -285,7 +285,8 @@ class Archive extends Comments
'replyWord' => _t('回复'),
'commentStatus' => _t('您的评论正等待审核!'),
'avatarSize' => 32,
'defaultAvatar' => null
'defaultAvatar' => null,
'avatarHighRes' => false
]);
self::pluginHandle()->trigger($plugged)->call('listComments', $this->singleCommentOptions, $this);
@ -335,7 +336,11 @@ class Archive extends Comments
<div class="comment-author" itemprop="creator" itemscope itemtype="http://schema.org/Person">
<span
itemprop="image">
<?php $this->gravatar($singleCommentOptions->avatarSize, $singleCommentOptions->defaultAvatar); ?>
<?php $this->gravatar(
$singleCommentOptions->avatarSize,
$singleCommentOptions->defaultAvatar,
$singleCommentOptions->avatarHighRes
); ?>
</span>
<cite class="fn" itemprop="name"><?php $singleCommentOptions->beforeAuthor();
$this->author();