View Full Version : How Do You Add user Avatar image on homepage WGO box
Gabe505
07-17-2012, 05:04 AM
I've done several searches and cannot find a solution. I'm Running vb4.1.0 Forum only.
Here is an example of what I'm trying to accomplish.
Gabe505
07-19-2012, 03:37 AM
Any takers?
Sarteck
07-19-2012, 03:58 AM
Sure, I'll bite.
AdminCP -> Products & Plugins -> Add New Plugin
Leave the Product as vBulletin (unless you wanted to make this a product, heh).
Select forumhome_loggedinuser for the Hook Location.
For the name, put something like "The Amazingly Awesome Sarteck's WGO-Avatar Plugin" or whatever.
For the PHP code, try the following:
$loggedin['musername'] = '<img src="image.php?u='.$loggedin['userid'].'&type=thumb" />';
The size of the images is controlled by the size of the thumbs for avatars on your site.
Badabing, that's it.
--------------- Added 1342674039 at 1342674039 ---------------
-----------------
Actually, scratch that... Avatar thumbs would get cached like that. If you don't mind the caching, leave it as is. If you want to make sure the new image is displayed whenever someone changes their avatar, use this instead:
$loggedin['musername'] = '<img src="image.php?u='.$loggedin['userid'].'&type=thumb&dateline='.TIMENOW.'" />';
--------------- Added 1342674110 at 1342674110 ---------------
Awesome username, btw.
--------------- Added 1342675184 at 1342675184 ---------------
Anudder update to that code for ya. If you wanted to force a certain size, add style="max-width:40px;max-height:40px;" to the image tag.
Change "40px" to whatever size you want.
Gabe505
07-20-2012, 02:56 AM
I would love to change my username if possible (I've asked in the past but no dice). I will try this amazingly awesome plugin and update with my results. Thank you Sarteck YOU ROCK!
--------------- Added 1342758879 at 1342758879 ---------------
It works! But, is there a way to only display users with avatars or skip users without a avatar?
Sarteck
07-20-2012, 03:45 AM
Hmmm. I am sure there is, but I don't know it right at the moment. I'll have to look into it some, unless someone else can give ya the answer before me.
--------------- Added 1342760313 at 1342760313 ---------------
Okay, we need to make another plugin on forumhome_loggedinuser_query.
This one needs to have the following:
$hook_query_fields .= ", avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar ";
$hook_query_joins .= " LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) ";
What this does is adds to the database query that looks up online users.
Now, we edit the old plugin we made earlier to use THIS PHP instead:
if ($loggedin['avatarpath'] || $loggedin['hascustomavatar']) {$loggedin['musername'] = 'Whatever you decided for the Image HTML Tag.';}(Change as appropriate.)
What THAT one does is checks to see if the user has an avatar (a pre-set one from whatever you provide them as an Admin OR a custom one).
That -should- do it... But if you suddenly get Database Errors when you enable this, just kill that plugin what adds to the database lookup, because it means I mistyped soemthing. XP
Gabe505
07-20-2012, 03:59 AM
I made the changes you provided above (also couldnt force the width and height). I added another screen shot to help explain.
Sarteck
07-20-2012, 04:11 AM
Yup, I get ya. XD Replied above with a solution. ;)
BTW, if you do not want names to display for those without avatars, but instead a default image that you can choose, try this in the plugin instead:
if ($loggedin['avatarpath'] || $loggedin['hascustomavatar']) {$loggedin['musername'] = 'Whatever you decided for the Image HTML Tag.';} else {$loggedin['musername'] = '<img src="/path/to/your/image" />';}(Again, edit as necessary.)
Gabe505
07-20-2012, 04:51 AM
Thanks for the help and effort. It's working for me now, thank you! I just need to figure a few things out before I get it looking the way I want.
Example: Nothing displays for Invisible users and I would like to learn how to remove the "*" & "," from here.
https://vborg.vbsupport.ru/attachment.php?attachmentid=139947&stc=1&d=1342763435
BTW When searching for this solution I ran into quite a few other people asking how to do this. I'm sure this thread will become useful to others.
Sarteck
07-20-2012, 04:57 AM
UPDATE:
Two plugins.
Name: Avatar --> WGO [Database Query]
Location: forumhome_loggedinuser_query
$hook_query_fields .= ", avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar ";
$hook_query_joins .= " LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON (customavatar.userid = user.userid) ";
Name: Avatar --> WGO [Display]
Location: forumhome_loggedinuser
$display_name_if_no_avatar = true; // Change to false if you do NOT want names appearing
$display_default_image = ''; // Change to the path to an image if you want to use a default image (takes precedence over $display_name_if_no_avatar)
$max_height = '40px'; // Change if you want.
$max_width = '40px'; // Change if you want.
$stylebit = 'max-width:'.$max_width.';max-height:'.$max_height.';';
if ($loggedin['avatarpath'] || $loggedin['hascustomavatar']) {$loggedin['musername'] = '<img src="image.php?u=' . $loggedin['userid'] . '&type=thumb&dateline=' . TIMENOW . '" style="'.$stylebit.'" />';} // Displays user avatar thumbnail
elseif ($display_default_image) {$loggedin['musername'] = '<img src="$display_default_image" style="'.$stylebit.'" />';} // Displays default image
elseif (!$display_name_if_no_avatar) {continue;} // Continues the current loop without processing the username.
Check out the comments so you know what to change.
EDIT: Posted this before I saw your response. I'll check that out in a minute.
EDIT2: Ah, the new stuff I put here already solves that, I think.
Gabe505
07-20-2012, 05:12 AM
Database error in vBulletin 4.1.10:
Invalid SQL:
SELECT
user.username, (user.options & 512) AS invisible, user.usergroupid, user.lastvisit,
session.userid, session.inforum, session.lastactivity, session.badlocation,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
, avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar , avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar
FROM session AS session
LEFT JOIN user AS user ON(user.userid = session.userid)
LEFT JOIN avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN customavatar AS customavatar ON (customavatar.userid = user.userid) LEFT JOIN avatar AS avatar ON (avatar.avatarid = user.avatarid) LEFT JOIN customavatar AS customavatar ON (customavatar.userid = user.userid)
WHERE session.lastactivity > 1342763809
ORDER BY username ASC;
MySQL Error : Not unique table/alias: 'avatar'
Error Number : 1066
Sarteck
07-20-2012, 05:15 AM
X3 X3 X3
Yah got me wrong. That last post of mine, it wasn't additional plugins you'd have to make, it was the ones you already made, just modified slightly. It looks like (from that error) that you went ahead and did it twice, heh.
Gabe505
07-20-2012, 05:21 AM
So just replace with the new code and fill in the options? I got plugin happy, see what you did to me!
Sarteck
07-20-2012, 05:26 PM
Yup. XD I take it no more problems, then?
(Sorry, got distracted by vidya games, then went to sleep.)
Gabe505
07-21-2012, 01:04 AM
I crashed out too. i have to add the new changes listed above and i will report back.
Gabe505
07-25-2012, 01:40 AM
Update: I started fresh by disabling the first two plugins and created the two new plugins listed above here (https://vborg.vbsupport.ru/showpost.php?p=2349745&postcount=9).
It works, but when I change
$display_name_if_no_avatar = true; // Change to false if you do NOT want names appearing to "false" it breaks the board and gives the following error:
Fatal error: Cannot break/continue 1 level in /home/siccness/public_html/vb/forum.php(540) : eval()'d code on line 8
Sarteck
07-25-2012, 05:38 AM
My bad. Should be continue 2;
XD
Just tested it out on my forum and it works.
--------------- Added 1343205372 at 1343205372 ---------------
Hmm. Strike that, it's now NOT working. :hmm: Wonder why. Lemme look into it.
--------------- Added 1343207433 at 1343207433 ---------------
Aaaaand, done.
Seems that we cannot "continue" inside a eval()'d statement. ^^; My bad for not realizing that. But TIMTOWTDI!
It's now fully functional. Delete that crap I gave you earlier and just install the Modification. :)
https://vborg.vbsupport.ru/showthread.php?t=285931
There ya go. :D
Gabe505
07-28-2012, 09:41 PM
Installed! Great job on this @Sarteck! What's the best way to style these avatars? I also don't want to have the comma in between the avatars, do you know how I can remove those without breaking anything? lol
Sarteck
07-29-2012, 12:29 AM
Installed! Great job on this @Sarteck! What's the best way to style these avatars? I also don't want to have the comma in between the avatars, do you know how I can remove those without breaking anything? lol
Hmm. I'll release the option for it on my next plugin update, but you could just add the line in your "[Display]" PHP code:
$loggedin['comma'] = '';
I think so, anyhow.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.