View Full Version : Why doesn't this code to display avatars work?
tomotron
04-14-2009, 08:11 PM
I'm trying to display avatars (hosted in the filesystem) on a non-vb page. Basically, I'm supplying a userid and want to display the avatar...
$avatarid = 1;
require_once('./includes/functions_user.php');
$avatarurl = fetch_avatar_url($avatarid);
if ($avatarurl[0])
{
$avatarurl = $avatarurl[0];
}
else
{
$avatarurl = "noavatar.gif";
}
$avatarurl never contains any data :(
From all the examples I've read it seems like this *should* work, am I making a stupid mistake? Any help is appreciated!
--------------- Added 1239745335 at 1239745335 ---------------
also, just to be clear this file resides in my vbulletin directory so the path to functions_user.php should be good.
tomotron
04-19-2009, 05:17 PM
anybody? is there another solution to display avatars that are NOT hosted in the database on a non vb page?
Lynne
04-19-2009, 05:19 PM
Exactly what is getting displayed in the source code? And maybe it would be better to go:
if (!empty($avatarurl))
{
$avatarurl = $avatarurl;
}
else
{
$avatarurl = "noavatar.gif";
}
tomotron
04-20-2009, 05:39 PM
^^ I think we're basically doing the same thing there?
When i try to run this and print the results using "echo $avatarurl;" for example I get nothing. It doesn't display noavatar.gif which should display if $avatarurl is empty.
I can replace,
$avatarurl = fetch_avatar_url($avatarid);
with
$avatarurl = 1;
and the script runs and I can display the results (which are 1), so my issue lies with the fetch_avatar_url($avatarid); portion which doesn't seem to be pulling the info it's supposed to.
Do I need to include other files to access that function?
Lynne
04-20-2009, 07:07 PM
Did you look at the API for that function? I believe it returns an array. Is $avatarurl defined as an array? According to the API, that is the correct file to include.
tomotron
04-23-2009, 12:52 PM
Yeah looking at the API is where I got most of this code.
The if statement should deal with the array,
basically saying if there is a value for $avatarurl[0] assign it to $avatarurl, otherwise gave $avatarurl the value "noavatar.gif"
EnIgMa1234
04-23-2009, 01:07 PM
Try a
print_r($avatarurl);
tomotron
04-24-2009, 10:02 PM
^^ Tried it, I think $avatarurl = fetch_avatar_url($avatarid); just isn't working :confused:
Lynne
04-24-2009, 11:11 PM
Did you try looking in the vb code to find a some code where this function is and then just copying it?
And, if $avatarurl is defined as an array, you can't then just go use it as if it isn't an array.
tomotron
05-04-2009, 06:19 PM
Did you try looking in the vb code to find a some code where this function is and then just copying it?
And, if $avatarurl is defined as an array, you can't then just go use it as if it isn't an array.
I'm not so sure I think the problem is in my code, but more than I'm trying to do this on a non-vb page and there's a step I'm missing to be able to use that function.
$avatarurl is an array, but I am using it as one... $avatarurl[0] would access the first element in the array which should be the URL for the avatar.
tomotron
05-12-2009, 07:57 PM
bump... still stumped on this one :confused:
RLShare
05-12-2009, 09:44 PM
Are you sure that '1' is a valid avatar ID?
Either way, this is how I grabbed the avatar path in one of my old mods, its was taken almost verbatim from a vbulletin file. Hope it helps.
if($vbulletin->userinfo['avatarid']!=0){
$av_data=$vbulletin->db->query_first("SELECT * FROM ". TABLE_PREFIX ."avatars where id='".$vbulletin->userinfo['avatarid']."'");
$avpath=$av_data['avatarpath'];
}
else if($vbulletin->userinfo['userid']!=0){
if ($vbulletin->options['usefileavatar'])
{
$avpath = $vbulletin->options['avatarurl'] . '/avatar' . $vbulletin->userinfo['userid'] . '_' . $vbulletin->userinfo['avatarrevision'] . '.gif';
}
else
{
$avdata=$vbulletin->db->query_first("SELECT * FROM ". TABLE_PREFIX ."customavatar where userid='".$vbulletin->userinfo['userid']."'");
$avpath = 'image.php?' . $vbulletin->session->vars['sessionurl'] . 'u=' . $vbulletin->userinfo['userid'] . "&dateline=$avdata[dateline]";
}
}
else{
$avpath="images/noavatar.gif";
}
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.