View Full Version : Need code for this.. please help..
shibby2
10-03-2012, 05:09 PM
Hi everyone, I'm using the following code to make the user's avatar appear..
<img src="$vboptions[bbdir]/forums/image.php?u=$bbuserinfo[userid]" alt="Your avatar" border="0" />
This works fine IF they have an avatar. If they don't it shows up as a broken image (red X).
My question is, what code would I have to add to make a "No Avatar" image show up for people who don't have an avatar? I already have the No Avatar image uploaded to the forum directory.
Any help would be HUGE!
Thanks! :)
The situation is a little complicated. A user can have a "standard" avatar, a custom avatar, or no avatar. image.php only returns the custom avatar, so you really shouldn't be calling that unless you already know that the user has one (otherwise you get a broken image). Also, assuming a user does have a custom avatar, you should be putting a timestamp on the url (like image.php?userid=X&dateline=Y) otherwise a browser will cache it and maybe not see a change in a user's custom avatar for days after it happens.
So anyway, you should be checking what kind of avatar a user has and building the url accordingly, instead of always using image.php. What template is your code from?
shibby2
10-03-2012, 08:45 PM
Hmm, ok, thanks for the insight. Unfortunately I dont know much about what youre saying (im dumb). lmao I just found that code somewhere in a post last night while searching vb.org.
The thing is, I'm using the Vietbb side column mod. As you may know, it doesn't work properly when you code it into forum_display (it works on index fine, but if you dont want it on evry page, you ahve to manually add it to whatever pages you want. Since I dont want it on showthread, I had to add it to forum_display only). The User Information box will show up, but the avatar doesnt. Soooo I got it to show with that code above, but not when someone doesnt have an avatar.
Is there a basic piece of code I could use instead of that? Im really not good with this stuff at all. lol
Thanks for the help so far! :)
OK, this really should be done in a plugin, but it is possible to do in a template. Here's what I came up with:
<if condition="$bbuserinfo[avatarid]"><img src="$bbuserinfo[avatarpath]" alt="Your avatar" border="0" /><else /><if condition="$bbuserinfo['hascustomavatar'] AND $vboptions['avatarenabled']"><if condition="$vboptions['usefileavatar']"><img src="{$bbuserinfo[avatarurl]}/avatar{$bbuserinfo[userid]}_{$bbuserinfo[avatarrevision]}.gif"<else /><img src="image.php?{$session[sessionurl_q]}u={$bbuserinfo[userid]}&dateline={$bbuserinfo[avatardateline]}"</if><if condition="$bbuserinfo['avwidth'] AND $bbuserinfo['avheight']"> width="{$bbuserinfo[avwidth]}" height="{$bbuserinfo[avheight]}"</if> alt="Your avatar" border="0" /></if></if>
I put it all on one line so that there wouldn't be any extra spaces in the output, which is why it looks so scary.
One other thing: this only works if the current user's info contains the avatar info, and on a lot of pages (like forumhome) it won't. But it turns out you can fix that by adding this to your config.php file (anywhere after the first line):
define('AVATAR_ON_NAVBAR', 1);
There doesn't seem to be anything that actually puts the avatar on the navbar, so I guess it's something that's left over from an older version (or maybe never got implemented).
shibby2
10-03-2012, 11:17 PM
Ut oh, that didn't work, and now certain forums on my forum wont work. Also, the images in my photo album dont work.
This is the message I get in certain forums even after removing the code from config.php:
Unable to add cookies, header already sent.
File: /home/screamin/public_html/myforum.com/includes/config.php
Line: 1
OK, well, you can take it out to fix things right?
Where exactly did you put it?
shibby2
10-03-2012, 11:21 PM
I took it back out right away, and Im still getting the same message in certain forums. :( I put it after the first line in config.php.
--------------- Added 1349310398 at 1349310398 ---------------
Any forums with new posts (unread) will work, any forums that are 'read' will be blank with only that message displayed.
Album images and avatars are a red X.
:(
Did you put all that code in the config.php? Sorry, only that one line I posted in the second part was supposed to go in there.
If you only changed your config.php, and you took it out but are still having problems, then you must not have gotten it back the way it was. WHat did you use to edit it?
shibby2
10-03-2012, 11:39 PM
Yea, I only put in that one piece from the second part.
I used Notepad.
It looked like there was line breaks after every line in onfig, so I even uploaded a new, fresh cope without line breaks, and Im still getting the same problem.
Ugh, this sucks, I have a fairly active forum too..
:(
You're still getting that same error even after uploading a new copy? Are you sure you uploaded it to the right place (it should be in inlcudes). Also, it has your database and other config stuff in there so you don't want to upload the copy that came with vbulletin (hopefully you knew that, but just to make sure...).
That error definitely looks like what you get when there's something at the beginning of the config.php file other than <?php
shibby2
10-03-2012, 11:48 PM
Yea it was a fresh copy but I edited all the info correctly. Its uploaded in the includes folder.
I really dont know whats up, everything looks fine. THeres nothing in the begining.
Heres how it starts:
<?php
/*================================================= =====================*\
|| ################################################## ################## ||
|| # vBulletin 3.8.4 Patch Level 2
|| # ---------------------------------------------------------------- # ||
|| # All PHP code in this file is �2000-2010 Jelsoft Enterprises Ltd. # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| ################################################## ################## ||
\*================================================ ======================*/
/*-------------------------------------------------------*\
| ****** NOTE REGARDING THE VARIABLES IN THIS FILE ****** |
+---------------------------------------------------------+
| If you get any errors while attempting to connect to |
| MySQL, you will need to email your webhost because we |
| cannot tell you the correct values for the variables |
| in this file. |
\*-------------------------------------------------------*/
Yeah, that looks right to me. Do you know if you have any kind of caching of php code going on on your server?
Another thought is that there could possibly be some invisible characters at the beginning, but I'm pretty sure that notepad is OK to use and shouldn't cause that.
Did you look at the file that's on your server to make sure it's actually getting overwritten?
shibby2
10-04-2012, 12:05 AM
YEa, I looked at the file that is uploaded on the server, looks the same.
I have no idea if I have caching of php code... how can I find that out?
I actually don't know - we have some kind of caching set up where I have to refresh it to get changes to take effect, but we have a web page to do that so I don't know what to tell you. But if you had that then your original change shouldn't have had any effect, so that's probably not the issue. (and your host probably would have given you instructions).
How often do you upload files? I was thinking it might be a problem with ascii vs. binary mode when ftping, but if so you'd probably know it from other files having problems.
If there was some way to get me the file I'd look at it for you, but you probably don't want to post it here and you can't attach to PMs.
shibby2
10-04-2012, 12:14 AM
So you would need the whole config.php file? Can I email it to you or something?
Or woudlnt i be able to just paste it in a PM?
You could paste it, but I'm afraid that might hide what I'd be looking for. Really it's a long shot that I'd notice something that you didn't, but I don't know what else to tell you.
I'll send you a PM.
shibby2
10-04-2012, 12:39 AM
Got it working!!! :)
Wow, that was so weird, Ive never seen anything like that before. It looked fine, but wasnt. lol
I downloaded phpcoder and used that, and sure enough it showed it in there too. Removed it, saved, and reuploaded. Works now! :)
Thank you soooo much for all the help!
So do you think I should try adding that bit of code again? lol
So do you think I should try adding that bit of code again? lol
Glad you got it fixed. I don't know if you're kidding or not, but I think you should be OK as long as you use that new editor.
shibby2
10-04-2012, 03:11 AM
Yea I think it'll be ok now.. but maybe I'll wait til off-peak hours this time. lol
Thanks again! :)
--------------- Added 1349325927 at 1349325927 ---------------
Alright, tried it again. Everything works fine with the code given. The custom avatar does show if a user has one. If he doesnt have one, it's just blank.. no avatar.
So how exactly would I get the "No Avatar" image to show for those who don't have one?
The image is: http://www.myforum.com/forums/images/avatars/noavatar.jpg
Thanks! :)
Oops - that is what you were asking about originally. Try this:
<if condition="$bbuserinfo[avatarid]"><img src="$bbuserinfo[avatarpath]" alt="Your avatar" border="0" /><else /><if condition="$bbuserinfo['hascustomavatar'] AND $vboptions['avatarenabled']"><if condition="$vboptions['usefileavatar']"><img src="{$bbuserinfo[avatarurl]}/avatar{$bbuserinfo[userid]}_{$bbuserinfo[avatarrevision]}.gif"<else /><img src="image.php?{$session[sessionurl_q]}u={$bbuserinfo[userid]}&dateline={$bbuserinfo[avatardateline]}"</if><if condition="$bbuserinfo['avwidth'] AND $bbuserinfo['avheight']"> width="{$bbuserinfo[avwidth]}" height="{$bbuserinfo[avheight]}"</if> alt="Your avatar" border="0" /><else /><img src="images/avatars/noavatar.jpg" alt="Your avatar" border="0" /></if></if>
shibby2
10-04-2012, 08:55 PM
That works! :)
Thank you soooooooooo much for everything, this really helped me out bigtime!
Thanks! :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.