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

Default Avatars

Discussion in 'XenForo Development Discussions' started by Mario Estrada, May 3, 2012.

  1. Mario Estrada

    Mario Estrada New Member

    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.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. Mario Estrada

    Mario Estrada New Member

    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($urltrue);
            }
     
            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";
        }
     
    CurveGotti likes this.

Share This Page