News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Grabbing the avatar from users

Started by Shunt, February 27, 2010, 07:11:55 AM

Previous topic - Next topic

Shunt

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?

Oldiesmann

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'].
Michael Eshom
Christian Metal Fans

Shunt

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;


Shunt


bloc

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.

Advertisement: