Simple Machines Community Forum

Customizing SMF => Bridges and Integrations => Topic started by: Shunt on February 27, 2010, 07:11:55 AM

Title: Grabbing the avatar from users
Post by: Shunt on February 27, 2010, 07:11:55 AM
Hey there,

I'm using SMF to have an integrated user system throughout my website, for example: people can post comments on several locations such as the videogallery, the system uses the SSI information to store info about the current user, linked to the user ID.
Comments are displayed, and I'm using simple sql statements to fetch user records, so the poster's name is shown next to the comment, simple as that.

The problem is, I don't understand how the avatar location is stored. I can't seem to find it in the members table, well... there is a column for it, but it only seems to be for avatars located on some external website. Now, I've noticed the filenames are stored in the attachment table. Does this mean I'd have to check both tables every single time?
Title: Re: Grabbing the avatar from users
Post by: Oldiesmann on February 28, 2010, 03:15:18 PM
When you're using SSI.php, all the member data will be loaded by SMF, so you just need to use the appropriate variable to get the info you want :)

The easiest way to output the avatar is to just do this:
echo $context['member']['avatar']['image'];

That will output the appropriate HTML code to display the member's avatar.

If you want to tweak it further (such as forcing it to be displayed at a specific size), you can get the URL for the user's avatar by using $context['member']['avatar']['href'].
Title: Re: Grabbing the avatar from users
Post by: Shunt on March 06, 2010, 07:40:38 AM
Quote from: Oldiesmann on February 28, 2010, 03:15:18 PM
When you're using SSI.php, all the member data will be loaded by SMF, so you just need to use the appropriate variable to get the info you want :)

The easiest way to output the avatar is to just do this:
echo $context['member']['avatar']['image'];

That will output the appropriate HTML code to display the member's avatar.

If you want to tweak it further (such as forcing it to be displayed at a specific size), you can get the URL for the user's avatar by using $context['member']['avatar']['href'].

Doesn't that just show me the current user's information? What about other members?
Also, any chance SSI will become OO-based someday? Walking through a global variable might be a bit better performance-wise, you gotta agree something like looks nicer:


$user = SmfFactory::GetUser(); //Leave params empty for current, or perhaps enter a user-id to fetch a different user?
echo $user->avatar->image;

Title: Re: Grabbing the avatar from users
Post by: Shunt on March 11, 2010, 04:15:05 AM
Anyone?
Title: Re: Grabbing the avatar from users
Post by: bloc on March 11, 2010, 08:11:00 AM
Avatars are stored with a id_attach in the members table, true, but you need to fetch the actual image from the attachment table using that id_attach. Also some functions to decrypt the actual avatar needs to be run. Study SSI on how its done.