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

Avatar URL

Discussion in 'Styling and Customization Questions' started by grantus, Jun 23, 2012.

  1. grantus

    grantus Active Member

    I'm trying to display my members' avatars on my own PHP page (non-xf) but the only thing that's stopping me is this one thing. Here's an example URL:

    mysite.com/forums/data/avatars/m/0/1.jpg?1340366835

    So all I need to know is where does the '0' come from (after the m/)? I looked into the xf_user table but not sure if it's from there. I know 'm' is for the size but I'm stumped on the '0'.

    Any help would be appreciated. Thanks.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    0 is the directory for the first 1000 user_ids. Refer to this code:

    library/XenForo/Template/Helper/Core.php

    Code:
    	protected static function _getCustomAvatarUrl(array $user, $size)
    	{
    		$group = floor($user['user_id'] / 1000);
    		return XenForo_Application::$externalDataUrl . "/avatars/$size/$group/$user[user_id].jpg?$user[avatar_date]";
    	}
    
    This script might be useful to you:

    http://xenforo.com/community/resources/avatar-php.634/

    This script is very convenient for showing avatars, but it does represent one database query for each request which might be a concern if the page is high traffic.
     
    Big Dan likes this.
  3. grantus

    grantus Active Member

    Thanks for the reply! I'm going to mess with this soon and let you know.

    Edit: I used floor() and rounded off, works great!
     

Share This Page