• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Default Avatars

#1
In the TechSpot Forums we have the default avatars set depending on their user id if they haven't set a custom avatar. If it ends with 0, 1, ... or 9 it shows a different avatar.

Currently we made the changes directly to XenForo_Template_Helper_Core but I know this is not ideal, I want to create an add-on to rewrite the _getDefaultAvatarUrl if it's possible. Ideally being able to subclass XenForo_Template_Helper_Core would solve it.

I'll try replacing the 'avatar' helper and copying some of the functions to my helpers class.
 
#3
Thanks that's what I used to solve it, for those interested:

PHP:
XenForo_Template_Helper_Core::$helperCallbacks['avatar'] = array('Techspot_Helpers', 'helperAvatarUrl');
PHP:
    public static function helperAvatarUrl($user, $size, $forceType = null, $canonical = false)
    {
        $url = XenForo_Template_Helper_Core::helperAvatarUrl($user, $size, $forceType, $canonical);
        $default_url = XenForo_Template_Helper_Core::helperAvatarUrl($user, $size, 'default', $canonical);
       
        if($url === $default_url)
        {
            $url = self::_getDefaultAvatarUrl($user, $size);
        }
 
        if ($canonical)
        {
            $url = XenForo_Link::convertUriToAbsoluteUri($url, true);
        }
 
        return htmlspecialchars($url);
    }
   
    protected static function _getDefaultAvatarUrl(array $user, $size)
    {
        $num = ($user['user_id'] % 10) + 1;
       
        if (!$imagePath = XenForo_Template_Helper_Core::styleProperty('imagePath'))
        {
            $imagePath = 'styles/default';
        }
       
        return "{$imagePath}/xenforo/avatars/ts/avatars_{$num}_{$size}.png";
    }