PDA

View Full Version : customized avatar system


bharvey42
04-08-2003, 06:44 AM
I have a customized avatar system that stores custom avatars as the users username.gif

Now In the postbit template I would like to be able to display that avatar

$userinfo[username].gif when I use this i get a broken link if the user hasn't uploaded there avatar yet. I made it so it would load a transparent gif and stuck the gif into a table as a background but it repeats if it isn't 66x64.

So what would be the best way to check if the file exists and display it and if not just display the transparent image and fill where the avatar would be?

This does not use vB's avatar field so simply checking the usersinfo on the user won't work.

Thanks

jakoz
04-10-2003, 05:09 AM
if (file_exists("some.file")==1) {
doStuff();
}

bharvey42
04-10-2003, 05:19 AM
This should work if I have the hack that allows me to use php in the templates?

Xenon
04-10-2003, 01:20 PM
you'll have to hack functions.php

or i think a htaccess way will work to, like a 404 error just if an img file doesn't exists use another one, but i don't know if this really possible, i just think so ;)

jakoz
04-11-2003, 03:42 PM
in admin/functions.php

find:

if ($post[avatarid]!=0) {
$avatarurl=$post[avatarpath];
} else {
if ($post[hascustomavatar] and $avatarenabled) {
$avatarurl="avatar.php?userid=$post[userid]&dateline=$post[avatardateline]";
} else {
$avatarurl="";
}
}



comment that out and put:

if ((file_exists("$userinfo[username].gif ")==1) && $avatarenabled) {
$avatarurl="$userinfo[username].gif";
} else {
$avatarurl="";
}
}


you should then not have to make any template changes at all from the original to display this avatar instead. remember to get rid of the !($bbuserinfo[showavatars]) bit on the line below it if you havent tied this system in with the users showavatar variable. forgive any errors... been up for 2 days with a busted jaw :(

hope that helps :)

bharvey42
04-11-2003, 04:41 PM
Thanks for all the responses. I ended up figuring this out with my old code that I had for the avatar system, with some assistance from another person who was up at 4:30 am in the vB chatroom :)