View Full Version : Problems with avatar if conditional
DataHero
08-09-2010, 09:02 PM
I'm currently working on overhauling the entire showgroups template, but it seems I've come across one small issue that I'd like to fix before releasing my first 'mod'. Apparently, I've added an if conditional for showing the avatar. As such, I want it so that if a user has an avatar, it'll be displayed. Otherwise, it won't. In my case, however, neither will appear.
If I take away the if conditional, the avatar does appear, but then an annoying 2px by 2px image file appears for those who don't have an avatar. Here's the code I'm using for the avatar bit:
<if condition="$show['avatar']">
<a href="member.php?$session[sessionurl]u=$userinfo[userid]"><img class="thumbnailAvatar" alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" style="<if condition="$userinfo['avwidthpx'] > 60"> max-width:60px !important; width:auto; height:auto;<else />display:inline;</if>" /></a>
</if>
Any help would be greatly appreciated. :)
Lynne
08-09-2010, 09:28 PM
Which template is this in? And it's on the showgroups.php page? Is $show['avatar'] defined in the showgroups.php page? Or have you added a plugin to define it - if so, where and what are the contents?
DataHero
08-09-2010, 09:38 PM
The piece of code is in the 'showgroups_usergroupbit' template. Beside editing the templates itself, I've not done anything else to it.
Lynne
08-09-2010, 09:56 PM
I don't understand how an avatar is even showing when you have no "src" in your <img> tag and when $userinfo is not even the variable being used in that template. :/ Who's avatar is showing? Do you have a link to this page?
DataHero
08-09-2010, 10:02 PM
I don't understand how an avatar is even showing when you have no "src" in your <img> tag
But I did try the following src:
src='image.php?u=$user[userid]'
However, that was the case which I mentioned: the avatar did display then, but an annoying 2px by 2px (or so) image file displayed with the same link as which the src is (image.php?u=X).
And I'd rather keep the board's url private from these boards as of yet, as it's in a beta still. I could PM you it however, if you'd like.
Edit: see attachment.
Lynne
08-09-2010, 10:46 PM
You cannot use image.php?u=$user[userid]. That is only valid if the avatar is in the database, not filesystem (and it's not complete at that - you should have &dateline=xxx on the end of it).
Take a look at the $posts query in showthreads.php around line 989. Look at the way the customavatar gets included. You need to include that in part of the query in showgroups.php (which is going to be a bit difficult since there isn't a hook to use). Then look at class_postbit.php, the function preocess_registered_user() where the avatar gets processed and $show['avatar'] gets defined. That is the sort of thing you will need to put into your code somewhere.
DataHero
08-10-2010, 07:07 AM
I took a look at both files and at the right location (which you mentioned). I'm not an expert at PHP but do understand most statements and whatnot. However, I did a search and came across this post (https://vborg.vbsupport.ru/showpost.php?p=1205059&postcount=5).
If what Brad has said is true, where would I have to put the code? That is, the script.
Cheers. :)
Edit: Well I've added a plugin with the contents of the first code block that Brad posted (see link), and tried global_start. That didn't bring up errors, but it wasn't displayed either. Then I tried the showgroups_complete, showgroups_start and showgroups_usergroup, which gave me two errors (the page didn't stop loading though).
Lynne
08-10-2010, 03:07 PM
Brad's script will not work for you without quite a few changes (if even then). It's for getting the avatar of the person viewing the page - you - which is different than getting it for someone else in a query.
DataHero
08-11-2010, 04:29 PM
So I'm pretty much better off leaving that 2px / 2px image for those who don't have an avatar, than to try getting this to work? I've been messing around and tried to include some query after looking at said PHP files more, but I couldn't.
Lynne
08-11-2010, 04:37 PM
What you have done is not going to work at all if you have your avatars in the filesystem instead of the database.
DataHero
08-27-2010, 07:06 PM
Alright, I looked at showgroups.php once more and tried to figure out what the vital parts of the query would be. I came up with this:
$showgroups = $db->query_read("
SELECT
user.*, userfield.*, usertextfield.*,
" . iif($vbulletin->options['avatarenabled'], 'avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight,') . "
postparsed.pagetext_html, postparsed.hasimages,
$hook_showgroups_complete
LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)") . "
");
I've added that to the plug-in text-area thing, set the hook to showgroups_complete and also added this in the field:
if ($this->post['avatarid'])
{
$this->post['avatarurl'] = $this->post['avatarpath'];
}
else
{
if ($this->post['hascustomavatar'] AND $this->registry->options['avatarenabled'])
{
if ($this->registry->options['usefileavatar'])
{
$this->post['avatarurl'] = $this->registry->options['avatarurl'] . '/avatar' . $this->post['userid'] . '_' . $this->post['avatarrevision'] . '.gif';
}
else
{
$this->post['avatarurl'] = 'image.php?' . $this->registry->session->vars['sessionurl'] . 'u=' . $this->post['userid'] . '&dateline=' . $this->post['avatardateline'];
}
if ($this->post['avwidth'] AND $this->post['avheight'])
{
$this->post['avwidth'] = 'width="' . $this->post['avwidth'] . '"';
$this->post['avheight'] = 'height="' . $this->post['avheight'] . '"';
}
else
{
$this->post['avwidth'] = '';
$this->post['avheight'] = '';
}
}
else
{
$this->post['avatarurl'] = '';
}
}
if ( // no avatar defined for this user
empty($this->post['avatarurl'])
OR // visitor doesn't want to see avatars
($this->registry->userinfo['userid'] > 0 AND !$this->registry->userinfo['showavatars'])
OR // user has a custom avatar but no permission to display it
(!$this->post['avatarid'] AND !($this->cache['perms'][$this->post['userid']]['genericpermissions'] & $this->registry->bf_ugp_genericpermissions['canuseavatar']) AND !$this->post['adminavatar']) //
)
{
$show['avatar'] = false;
}
else
{
$show['avatar'] = true;
}
Is this any better or close to what I should do?
Lynne
08-27-2010, 08:17 PM
Yes, that is much closer. I haven't actually read the code line for line, but it looks more like what I am used to seeing when an avatar is included.
DataHero
08-28-2010, 12:37 AM
Seems I keep getting an SQL error, but I don't know where it's coming from. :(
This is the query_read (or something, I'm a novice with SQL; used this query part from showthread.php (changed $posts to $show['avatar'])):
$show['avatar'] = $db->query_read("
SELECT
user.*, userfield.*, usertextfield.*,
" . iif($vbulletin->options['avatarenabled'], 'avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight,') . "
$hook_query_fields
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = post.userid)
LEFT JOIN " . TABLE_PREFIX . "userfield AS userfield ON(userfield.userid = user.userid)
LEFT JOIN " . TABLE_PREFIX . "usertextfield AS usertextfield ON(usertextfield.userid = user.userid)
" . iif($vbulletin->options['avatarenabled'], "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)") . "
$hook_query_joins
");
Lynne
08-28-2010, 02:00 AM
A query is not just the query_read part. You then just get left with pointers and have to get that data out of there by doing something like a fetch_array. *Then* you end up with variables you can do something with (you can see that in the showthread.php page).
DataHero
08-29-2010, 05:27 AM
Okay, I see the part where it's being fetched (if I am right), which starts at:
while ($post = $db->fetch_array($posts)) { etc }
And then I have the bit where $posts is defined. So basically, I'll have to adjust the query of $posts accordingly (and rename the defined variable), and then make a similar while for the newly defined variable?
Also, after having this done, should I pretty much edit the showgroups.php page to include the defined $show['avatar'] from the class_postbit.php?
And as a last thing: should the case be that I have to adjust the query accordingly, what would be the best way to know which table (or whatever it is?) should be selected/called/queried?
Lynne
08-29-2010, 02:05 PM
If you already have a query in the showgroups page that then goes through a while loop like we are talking about, most likely, you just want to combine the two queries into one query and do everything at once. Is that what you are doing right now?
DataHero
08-29-2010, 08:12 PM
I'm not quite certain whether or not I understood it correctly. Is showgroups.php supposed to have a query related to that already (seeing how you have referred to 'two queries into one')?
And no, I haven't edited the showgroups.php itself yet. I wanted to be certain how I should go on about this before messing up everything.
My idea (my last post) was to basically copy the $show['avatar'] bit and put it in showgroups.php as well, so it's defined (which I could then use as a variable in the showgroups template). The same goes for the query from class_postbit.php. Or am I understanding this completely wrong?
Lynne
08-29-2010, 10:30 PM
I assumed from your first post that you were going to be showing the avatars for the users in the groups on the showgroups page. If so, there is already a query to grab the users in each group, so you would then want to add the extra stuff to select to that query, I would think.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.