vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Avatar display issue in template (https://vborg.vbsupport.ru/showthread.php?t=257468)

DataHero 01-20-2011 12:05 PM

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!

kh99 01-20-2011 12:26 PM

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.

DataHero 01-20-2011 12:36 PM

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.

kh99 01-20-2011 12:42 PM

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?

DataHero 01-20-2011 12:55 PM

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.

kh99 01-20-2011 01:11 PM

Quote:

Originally Posted by DataHero (Post 2151936)
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.

DataHero 01-20-2011 01:37 PM

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. :)

kh99 01-20-2011 01:49 PM

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..).

DataHero 01-25-2011 09:52 AM

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.

kh99 01-25-2011 10:28 AM

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.


All times are GMT. The time now is 11:45 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02381 seconds
  • Memory Usage 1,773KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete