Getting an avatar from a URL

TimeWizardCosmo

Well-known member
Would someone be willing to help me figure out how to grab an avatar using something like:

HTML:
<img src="http://mysite.com/avatar.php?userid=1" width="50" height="50">

I realize some code would need to be written to make avatar.php work, but I'm not sure where to start.

What I'm trying to do is find a way to pull my user's avatars into AddonChat... I can return values containing the user ID and username in the chat message templates, but I need some kind of external script to make the above snippet useful.

Any help would be greatly appreciated... New to xF coding (and a novice in PHP) so I'm not sure where to start with this.
 
Here is the function for it:

library/XenForo/Template/Helper/Core.php

Code:
	/**
	 * Returns the URL to a user's custom avatar
	 *
	 * @param array $user
	 * @param string $size (s,m,l)
	 *
	 * @return string
	 */
	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]";
	}
 
Here is the function for it:

library/XenForo/Template/Helper/Core.php

Code:
/**
* Returns the URL to a user's custom avatar
*
* @param array $user
* @param string $size (s,m,l)
*
* @return string
*/
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]";
}

Greatly appreciated, this definitely helps.

The code makes sense, but I'm not sure how to put it to any use... I tried putting it in it's own php file:
http://curiouscosmos.com/community/avatar.php?user=Cosmo&size=s

But it returns:
Parse error: syntax error, unexpected T_PROTECTED in /home/XXXX/public_html/community/avatar.php on line 11

I apologize for my lack of knowledge here... Do I need to call something at the beginning of the file? I've been up all night taking care of sick dogs so maybe I'm not following or putting 2 and 2 together.

Thank you for your help, Jake.
 
I have no idea what I'm doing:

avatar.php:
HTML:
<?php
include_once "../community/library/XenForo/Template/Helper/Core.php";
include_once "../community/library/XenForo/Application.php";
$chatterid = (int)$_GET['chatterid'];
$group = floor($user['user_id'] / 1000);
$avatar = XenForo_Application::$externalDataUrl . "/avatars/s/$group/$chatterid.jpg?$chatterid[avatar_date]";
print $avatar;

Result: http://curiouscosmos.com/community/avatar.php?chatterid=1
 
Oh man... You are an absolute hero right now, you have no idea.

I spent most of my day trying to figure this out, and ended up steam cleaning the carpets of my entire apartment out of frustration.

I don't even know how to thank you right now, you're awesome.

:eek:
 
Top Bottom