From 02a067c40cff3ecd1c152420e097a00d3273155c Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 22 Dec 2014 10:37:17 +0100 Subject: [PATCH] Fix cropping of existing avatars --- com.woltlab.wcf/templates/avatarEdit.tpl | 8 +++----- .../data/user/avatar/DefaultAvatar.class.php | 7 +++++++ .../data/user/avatar/IUserAvatar.class.php | 8 ++++++++ .../lib/data/user/avatar/UserAvatar.class.php | 20 ++++++++++++++++--- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/com.woltlab.wcf/templates/avatarEdit.tpl b/com.woltlab.wcf/templates/avatarEdit.tpl index 56c25c17cf..bb59360906 100644 --- a/com.woltlab.wcf/templates/avatarEdit.tpl +++ b/com.woltlab.wcf/templates/avatarEdit.tpl @@ -57,13 +57,11 @@
{if $avatarType == 'custom'} - {assign var='__customAvatar' value=$__wcf->getUserProfileHandler()->getAvatar()->getImageTag(96)} {if $__wcf->getUserProfileHandler()->getAvatar()->canCrop()} - {assign var='__customAvatar' value=$__customAvatar|substr:0:-2} - {assign var='__customAvatarTitle' value='wcf.user.avatar.type.custom.crop'|language} - {append var='__customAvatar' value='class="userAvatarCrop jsTooltip" title="'|concat:$__customAvatarTitle:'" />'} + {@$__wcf->getUserProfileHandler()->getAvatar()->getCropImageTag(96)} + {else} + {@$__wcf->getUserProfileHandler()->getAvatar()->getImageTag(96)} {/if} - {@$__customAvatar} {else} {/if} 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 4b4a62ccbc..684bf3d8a3 100644 --- a/wcfsetup/install/files/lib/data/user/avatar/DefaultAvatar.class.php +++ b/wcfsetup/install/files/lib/data/user/avatar/DefaultAvatar.class.php @@ -58,4 +58,11 @@ class DefaultAvatar implements IUserAvatar { public function canCrop() { return false; } + + /** + * @see \wcf\data\user\avatar\IUserAvatar::getCropImageTag() + */ + public function getCropImageTag($size = null) { + return ''; + } } diff --git a/wcfsetup/install/files/lib/data/user/avatar/IUserAvatar.class.php b/wcfsetup/install/files/lib/data/user/avatar/IUserAvatar.class.php index a37178c8e4..aa0d7fb61b 100644 --- a/wcfsetup/install/files/lib/data/user/avatar/IUserAvatar.class.php +++ b/wcfsetup/install/files/lib/data/user/avatar/IUserAvatar.class.php @@ -35,6 +35,14 @@ interface IUserAvatar { */ public function getImageTag($size = null); + /** + * Returns the image tag used for cropping. + * + * @param integer $size + * @return string + */ + public function getCropImageTag($size = null); + /** * Returns the width of this avatar. * 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 a46e6f156b..f6fc54dc57 100644 --- a/wcfsetup/install/files/lib/data/user/avatar/UserAvatar.class.php +++ b/wcfsetup/install/files/lib/data/user/avatar/UserAvatar.class.php @@ -114,21 +114,35 @@ class UserAvatar extends DatabaseObject implements IUserAvatar { switch ($size) { case 16: $retinaSize = 32; - break; + break; + case 24: case 32: case 48: $retinaSize = 96; - break; + break; + case 64: case 96: $retinaSize = 128; - break; + break; } return ''.WCF::getLanguage()->get('wcf.user.avatar.alt').''; } + /** + * @see \wcf\data\user\avatar\IUserAvatar::getCropImageTag() + */ + public function getCropImageTag($size = null) { + $imageTag = $this->getImageTag($size); + + // append CSS classes and append title + $title = StringUtil::encodeHTML(WCF::getLanguage()->get('wcf.user.avatar.type.custom.crop')); + + return str_replace('class="userAvatarImage"', 'class="userAvatarImage userAvatarCrop jsTooltip" title="'.$title.'"', $imageTag); + } + /** * @see \wcf\data\user\avatar\IUserAvatar::getWidth() */ -- 2.20.1