PDA

View Full Version : Getting user avatar URL?


findingpeace
07-29-2014, 04:43 PM
I try to use the official avatarurl because it has the dateline built in (so stuff doesn't get stuck in cache when people update their avatar), but it's not in a lot of templates. So I've tried making a plugin to make it work manually, but I'm having some trouble.

Example with MEMBERINFO:

require_once('./includes/functions_user.php');
$avatarurl = fetch_avatar_url($vbulletin->userinfo['userid']);

vB_Template::preRegister('MEMBERINFO', array('avatarurl' => $avatarurl[0]));

Then in MEMBERINFO, I use:
{vb:raw avatarurl}

It sort of works, except it displays my OWN avatar everywhere! Basically it just seems to take the current user's avatar and display it.

What I need is for the user ID to match the user ID of the profile I'm viewing. So if I'm user 1, and I view user 5's profile, I should see user 5's avatar, not my own.

Thanks!

tbworld
07-29-2014, 05:20 PM
What hook are you using for your plugin?

cellarius
07-29-2014, 05:25 PM
$vbulletin->userinfo holds the userid of the user browsing the page (in this case: you). You need to get the id of the user who owns the profile. What variable to use depends on the hook you use.

findingpeace
07-29-2014, 05:37 PM
I'm just using global_start so I can register the variable in multiple templates. Is this wrong? How would you recommend I do this just do display on MEMBERINFO, for example?

tbworld
07-29-2014, 08:31 PM
The only problem you are having is your target. As @Cellarius stated the variable you are trying to use is incorrect.

The following will work in MEMBERINFO template, although I did not check the dateline param which I should have added -- if possible.

<img src="{vb:raw vboptions.bburl}/image.php?{vb:raw session.sessionurl}u={vb:raw show_userid}" />
I did not have much time to look into this, a bit busy with life. Your code should have worked on hook "member_complete" with variable "$vbulletin->GPC['userid']", but for some reason it did not. I will take a look at it later.

--------------- Added 29 Jul 2014 at 22:04 ---------------

The hook code works fine. I had missed creating an actual avatar for the test user. :) That stuff happens when you are juggling too many things.



//Hook: member_complete

require_once('./includes/functions_user.php');
$avatarurl = fetch_avatar_url($vbulletin->GPC['userid']);
vB_Template::preRegister('MEMBERINFO', array('avatarurl' => $avatarurl));
:)

findingpeace
07-30-2014, 11:34 AM
Thank you so much tbworld! I am out of "Likes" to give you :)