Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2011, 12:05 PM
DataHero DataHero is offline
 
Join Date: Jun 2009
Location: NL
Posts: 140
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Avatar display issue in template

Hello,

Considering I don't like to bump pretty old threads, thought I'd make a new one. I've been focusing on getting the avatar to display properly in showgroups.php; it should also update as staff members change the avatar.

So far I've gotten pretty far, although I'm a bit stuck now. From my understanding, I can use the fetch_avatar_url() function as to fetch the current avatar url. As such, I did the following:

PHP Code:
#    Require the user functions in includes 
require_once('./includes/functions_user.php'); 

#       Declare variable for global userid and username 
$userid $vbulletin->userinfo['userid']; 
$uname $vbulletin->userinfo['username']; 

#    Fetch the avatar URI 
$avauri =  fetch_avatar_url($userid); 

#    Using an if condition to check whether there is an uri available or not. If not, change uri to that of the 'No avatar'  avatar. 
if(!empty($avauri)) { 
    
$dh_avauri '<a href="member.php?'.$session[sessionurl].'u='.$userid.'"><img src="image.php?u='.$userid.'" width="120" height="120" border="0" alt="'.$uname.'\'s avatar"></a>'
} else { 
    
$dh_avauri '<a href="member.php?'.$session[sessionurl].'u='.$userid.'"><img src="$stylevar[imgdir_misc]/noavatar/noavatar.gif" width="120" height="120" border="0" alt="'.$uname.'\'s avatar"></a>'

And here in the template; used it only to test so the layout isn't as intended ATM (showgroups_usergroup):

PHP Code:
<tr>
    <
td class="thead">&nbsp;</td>
    <
td class="thead" width="100%">$vbphrase[user_name]
              
$dh_avauri
              
<if condition="$show['locationfield']"> / $vbphrase[location_perm]</if></td>
    <if 
condition="$show['contactinfo']"><td class="thead">$vbphrase[contact]</td></if>
</
tr
It did display an avatar, but just that of mine, and the ID of the anchor tag remains at '1' as well. I also see all avatars as the same one; mine.

Help would be greatly appreciated!
Reply With Quote
  #2  
Old 01-20-2011, 12:26 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's always showing yours because you're using the userid and username from $vbulletin->userinfo, which is the logged in user.

ETA: if your code is in that main loop in showgroups.php, it looks like you'd want to use $user['userid'] and $user['username'] instead.
Reply With Quote
  #3  
Old 01-20-2011, 12:36 PM
DataHero DataHero is offline
 
Join Date: Jun 2009
Location: NL
Posts: 140
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the quick response. Much appreciated.

I've searched through the showgroups.php file and I could not seem to figure out which variable to use then. Considering $vbulletin->userinfo[] is for the logged in user, which should I use instead?

If I use $user[userid], $user['userid'], $userinfo['userid'], or $userinfo[userid], I get either a DB error as it would say 'WHERE user.id=', with no id at all. Or otherwise, I would simply have no ID at the end of the URL of the avatar/user.
Reply With Quote
  #4  
Old 01-20-2011, 12:42 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Using $user[userid] and $user[username] should work, but only if your code is inside the loop that starts with:

PHP Code:
        ksort($users); // alphabetically sort users
        
$usergroupbits '';
        foreach (
$users AS $user)
        { 
and it looks like the only hook in there is showgroups_user. Where are you putting the code you posted?
Reply With Quote
  #5  
Old 01-20-2011, 12:55 PM
DataHero DataHero is offline
 
Join Date: Jun 2009
Location: NL
Posts: 140
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Alright, I've changed the hook to showgroups_user and also have added the if condition into the foreach loop. The avatars changed according to the user now, along with the username and ID. Thanks.

However, if I change it in my UserCP, showgroups.php shows the old avatar still. Why is this happening, considering as far as I know, the forum uses the filesystem and/or DB?

EDIT: Also, the usernames seem to have vanished; only avatar is visible now. Tried reverting template, but that didn't work.
Reply With Quote
  #6  
Old 01-20-2011, 01:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by DataHero View Post
However, if I change it in my UserCP, showgroups.php shows the old avatar still. Why is this happening, considering as far as I know, the forum uses the filesystem and/or DB?
I happen to know this one (I think) because someone asked about it not too long ago - the browser caches the image, and unless you put something on the image URL to make it unique, the browser won't see a change. You're calling fetch_avatar_url() which takes care of that (I didn't know that existed), but you're not using the returned value. I think you want something like:

Code:
[S]<img src="$aviurl" ...[/S] (wrong - see below)

I don't know about the user names.
Reply With Quote
  #7  
Old 01-20-2011, 01:37 PM
DataHero DataHero is offline
 
Join Date: Jun 2009
Location: NL
Posts: 140
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well this is getting into the right direction!

I've replaced the img tag's src with:

Code:
<img src="'.(implode($avauri)).'" />
I've tried adding implode because the original return value of the src would be 'Array'. Now that I added the implode(), the src is the following:

Code:
<img src="1image.php?u=1&dateline=1295535226 width=" 120"="" height="26" "="" border="0" alt="" />
There's '1', which I'd assume is the (second) array element. And it also kind of messed up the entire img tag's attributes.

I guess I'm either doing this wrong, or the Array isn't supposed to be there (thus, $avauri)?

Also, much appreciated for taking your time to response.
Reply With Quote
  #8  
Old 01-20-2011, 01:49 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, sorry - I should have looked at fetch_avatar_url before assuming I knew what it returns. It does return an array, and it seems like it either just has one array element with the url, or else it has a "hascustom" element set to 1, with a number of other fields. I looked for other places that call fetch_avatar_url, but I'm still not sure how it's all supposed to be used. Here's one from user.php (in admincp, I think):

PHP Code:
    require_once(DIR '/includes/functions_user.php');
    
$userinfo['avatarurl'] = fetch_avatar_url($userinfo['userid']);

    if (
$userinfo['avatarurl'] == '' OR $userinfo['avatarid'] != 0)
    {
        
$userinfo['avatarurl'] = '<img src="' $vbulletin->options['cleargifurl'] . '" alt="" border="0" />';
    }
    else
    {
        
$userinfo['avatarurl'] = "<img src=\"../" $userinfo['avatarurl'][0] . "\" " $userinfo['avatarurl'][1] . " alt=\"\" border=\"0\" />";
    } 
That code's kind of confusing because the return value is put in $userinfo['avatarurl'] and it's also using $userinfo['avatarid'] that comes from somewhere else, I guess.

It could be that fetch_avatar_url is only used in a few special places because it does a query to get the answer, so if you put it on a page with a lot of avatars it's going to add a lot of queries (which maybe doesn't matter to you, but just so you know..).
Reply With Quote
  #9  
Old 01-25-2011, 09:52 AM
DataHero DataHero is offline
 
Join Date: Jun 2009
Location: NL
Posts: 140
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

My apologies for the slow reply. Been quite busy these few days.

Indeed, the return value of fetch_avatar_url() is set to 1 on both avatar URIs, so I'm assuming that the 1 is the result of 'hascustom', moreso than it being an actual array element identifier.

Oddly enough, using implode() for the variable $avauri (which is fetch_avatar_url()), would result in it actually giving its own width and height parameters, but moreso in a buggy way:

Code:
<img src="1image.php?u=2&dateline=1295528513 width=" 120"="" height="26" "="" 
I've tried using ltrim() to get rid of the 1 in front of the image.php and str_ireplace() for the ones on the right side, but seeing as the values are rather dynamic, I doubt it'd help.

I'm really eager to get this working, for it'd be a great addition to my fourth 'mod'.

Also, I'd like to thank you once more for taking your time to assist me in this matter.
Reply With Quote
  #10  
Old 01-25-2011, 10:28 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I suppose the values were returned that way because sometimes just the path is needed and sometimes the width and height are also needed.

Yes, I don't think it was meant to be imploded because of the hascustom thing in there. I guess you could either use

PHP Code:
$aviuri[0] . ' ' $aviuri[1

or if you wanted to use implode do something like

PHP Code:
$aviuri['hascustom'] = ''

first.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.09011 seconds
  • Memory Usage 2,285KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete