Fix cropping of existing avatars
authorMatthias Schmidt <gravatronics@live.com>
Mon, 22 Dec 2014 09:37:17 +0000 (10:37 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 22 Dec 2014 09:37:17 +0000 (10:37 +0100)
com.woltlab.wcf/templates/avatarEdit.tpl
wcfsetup/install/files/lib/data/user/avatar/DefaultAvatar.class.php
wcfsetup/install/files/lib/data/user/avatar/IUserAvatar.class.php
wcfsetup/install/files/lib/data/user/avatar/UserAvatar.class.php

index 56c25c17cf073dbddc5e47aee2b39d9acb3d06e4..bb593609062038b26275dcbcb24c35bc6c1c07a6 100644 (file)
                                <dl class="jsOnly{if $errorField == 'custom'} formError{/if}" id="avatarUpload">
                                        <dt class="framed">
                                                {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}
                                                        <img src="{@$__wcf->getPath()}images/avatars/avatar-default.svg" alt="" class="icon96" />
                                                {/if}
index 4b4a62ccbca64d1a83a34cc0d953aa0ebb7b9037..684bf3d8a308dfd1b4dd296178ec63b9b7547ae1 100644 (file)
@@ -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 '';
+       }
 }
index a37178c8e4b7be0d56bda1c55d754c0684eb337f..aa0d7fb61b9aeb51ba876e012e2c8c5d960d051d 100644 (file)
@@ -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.
         * 
index a46e6f156b5fb65664bfc73e8bd6d8551959f032..f6fc54dc575721039dd6bfd1de70c2c7bf073e9a 100644 (file)
@@ -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 '<img src="'.StringUtil::encodeHTML($this->getURL($size)).'" '.($retinaSize !== null ? ('srcset="'.StringUtil::encodeHTML($this->getURL($retinaSize)).' 2x" ') : '').'style="width: '.$width.'px; height: '.$height.'px" alt="'.WCF::getLanguage()->get('wcf.user.avatar.alt').'" class="userAvatarImage" />';
        }
        
+       /**
+        * @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()
         */