From d949e64b2ebd5ed19a5921d05cec073eefb6890b Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 7 Sep 2014 13:58:27 +0200 Subject: [PATCH] Reduced number of avatar requests / improved retina support --- .../data/user/avatar/DefaultAvatar.class.php | 3 +- .../lib/data/user/avatar/Gravatar.class.php | 36 +++++++++++++++++++ .../lib/data/user/avatar/UserAvatar.class.php | 29 +++++++++++++-- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/data/user/avatar/DefaultAvatar.class.php b/wcfsetup/install/files/lib/data/user/avatar/DefaultAvatar.class.php index 0413ec696f..4b4a62ccbc 100644 --- a/wcfsetup/install/files/lib/data/user/avatar/DefaultAvatar.class.php +++ b/wcfsetup/install/files/lib/data/user/avatar/DefaultAvatar.class.php @@ -1,6 +1,7 @@ size; - return ''.WCF::getLanguage()->get('wcf.user.avatar.alt').''; + return ''.WCF::getLanguage()->get('wcf.user.avatar.alt').''; } /** diff --git a/wcfsetup/install/files/lib/data/user/avatar/Gravatar.class.php b/wcfsetup/install/files/lib/data/user/avatar/Gravatar.class.php index 5c4d5badaf..a3a5ac4458 100644 --- a/wcfsetup/install/files/lib/data/user/avatar/Gravatar.class.php +++ b/wcfsetup/install/files/lib/data/user/avatar/Gravatar.class.php @@ -4,6 +4,7 @@ use wcf\system\exception\SystemException; use wcf\system\request\LinkHandler; use wcf\system\WCF; use wcf\util\FileUtil; +use wcf\util\StringUtil; /** * Represents a gravatar. @@ -69,6 +70,17 @@ class Gravatar extends DefaultAvatar { */ public function getURL($size = null) { if ($size === null) $size = $this->size; + else { + switch ($size) { + case 16: + case 24: + $size = 32; + break; + case 48: + $size = 96; + break; + } + } if (!isset($this->url[$size])) { // try to use cached gravatar @@ -104,6 +116,30 @@ class Gravatar extends DefaultAvatar { } } + /** + * @see \wcf\data\user\avatar\IUserAvatar::getImageTag() + */ + public function getImageTag($size = null) { + if ($size === null) $size = $this->size; + + $retinaSize = null; + switch ($size) { + case 16: + $retinaSize = 32; + break; + case 24: + case 32: + case 48: + $retinaSize = 96; + break; + case 96: + $retinaSize = 128; + break; + } + + return ''.WCF::getLanguage()->get('wcf.user.avatar.alt').''; + } + /** * @see \wcf\data\user\avatar\IUserAvatar::canCrop() */ diff --git a/wcfsetup/install/files/lib/data/user/avatar/UserAvatar.class.php b/wcfsetup/install/files/lib/data/user/avatar/UserAvatar.class.php index c8f06c2e14..06fefa0bb3 100644 --- a/wcfsetup/install/files/lib/data/user/avatar/UserAvatar.class.php +++ b/wcfsetup/install/files/lib/data/user/avatar/UserAvatar.class.php @@ -19,7 +19,7 @@ class UserAvatar extends DatabaseObject implements IUserAvatar { * needed avatar thumbnail sizes * @var array */ - public static $avatarThumbnailSizes = array(16, 24, 32, 48, 96, 128); + public static $avatarThumbnailSizes = array(32, 96, 128); /** * @see \wcf\data\DatabaseObject::$databaseTableName @@ -54,6 +54,16 @@ class UserAvatar extends DatabaseObject implements IUserAvatar { * @return string */ public function getFilename($size = null) { + switch ($size) { + case 16: + case 24: + $size = 32; + break; + case 48: + $size = 96; + break; + } + return substr($this->fileHash, 0, 2) . '/' . ($this->avatarID) . '-' . $this->fileHash . ($size !== null ? ('-' . $size) : '') . '.' . $this->avatarExtension; } @@ -93,7 +103,22 @@ class UserAvatar extends DatabaseObject implements IUserAvatar { } } - return ''.WCF::getLanguage()->get('wcf.user.avatar.alt').''; + $retinaSize = null; + switch ($size) { + case 16: + $retinaSize = 32; + break; + case 24: + case 32: + case 48: + $retinaSize = 96; + break; + case 96: + $retinaSize = 128; + break; + } + + return ''.WCF::getLanguage()->get('wcf.user.avatar.alt').''; } /** -- 2.20.1