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

Reply
 
Thread Tools Display Modes
  #1  
Old 02-14-2015, 12:34 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default look over my code please avatars not displaying correctly

so i managed to get the userids so now im converting them to their avatar.
this code is partially working and i have been toying with it for hours with no success. this is the closest i've come in making this work.

*side note* im not too good with php*

heres the code i came up with after hours of digging (i know... hours, yeah pathetic)
oh and this is on forumbit_display
Code:
$lastpname = $lastpostinfo[lastposter];
$getlastpname = $vbulletin->db->query_first("SELECT userid FROM ". TABLE_PREFIX ."user WHERE username = \"$lastpname\"");   
$lastpid = $getlastpname['userid'];

require_once('./includes/functions_user.php');
$lastpavurl = fetch_avatar_url($vbulletin->userinfo['userid']);
if (!($lastpav)){
	$lastpav = "<img src='http://3.bp.blogspot.com/-mg71OkrgNhY/Uv9zeCV4IsI/AAAAAAAABbc/zqOph-wGgpc/s1600/Batman_avatar-e1263852269689.jpg' />";
}
else{
	$lastpav = "<a href='member.php?u=$lastpid'><img src='image.php?u=$lastpid' alt='$lastpname Profile'></a>";
}
and heres what the results are looking like


so the batman (default image) is posted where 1. there are no threads and 2. when a user doesn't have an avatar as you can see in the SS (or live on my site, in my sig) the image is not appearing in the user with no avatar, nor the last forum with no post.


viewing the source i see
Code:
<img src="http://dirtrif.com/avatars/drbot.gif" alt="DrBot" s="" profile="" title="DrBot">
which.. i mean makes since, but it should be the default image, then for that last one i see:
Code:
<img src="http://dirtrif.com/" alt="" s="" profile="">
which makes no since to me, and should be grabbing the default (batman) image

so im lost and thought id ask for help =)

and happy valentines day everyone
Attached Images
File Type: png Capture.PNG (110.2 KB, 0 views)
Reply With Quote
  #2  
Old 02-14-2015, 01:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's the code that displays the avatar in the postbit:
PHP Code:
        // get avatar
        
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'] . '&amp;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'] > 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;
        } 

You could use that by calling $userinfo = fetch_userinfo($lastpid, FETCH_USERINFO_AVATAR), then using $userinfo in place of $this->post in the above code. One difference is that it looks like the above code allows for no avatar at all instead of giving everyone the default. Also it allows for the "viewing" user having selected the option to not see avatars.

Edit: Also use $vbulletin in place of $this->registry.
Reply With Quote
Благодарность от:
Dr.CustUmz
  #3  
Old 02-14-2015, 01:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Also, for reference, here's the corresponding code from the postbit template:
Code:
<if condition="$show['avatar']"><td class="alt2"><a href="member.php?$session[sessionurl]u=$post[userid]"><img src="$post[avatarurl]" $post[avwidth] $post[avheight] alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" /></a></td></if>
again of course $post would correspond to $userinfo if that's the variable you used in the above code.
Reply With Quote
  #4  
Old 02-14-2015, 01:59 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks kevin, it's something. even though you lost me lol. so i took that snippit and replaced all the $this->registry 's with $vbulletin and the $this->post 's with $userinfo

I appended that code to my existing code, and like i suspected got errors. so i try'd taking out my original if condition and changed the template piece to $userinfo ? rather than $lastpav still errors, unexpected if something, my brains farting so hard right now lol.

im just lost, looking over the code i mean it looks fairly simple, just alot of if elses but if its not vb template php ( $templatecode ) <if>this <else /> that</if> its close to giberish to me although something i REALLY REALLY want to learn and this seemed like a fairly easy outcome i was looking for to help get me started "learning" lol.

so im assuming i can take quite a few of those if conditions out of that snippit, and maybe rename some variables so my template <if> would be to my liking, but yeah brain farts and no sleep go so well together. im gunna wrap this up with im lost, i appreciate the help though =) and maybe just maybe this will result in a cool little plugin.

so have a good valentines day y'all and im passing out <3



and heres the full funked up code, that i totally ruined
Code:
$lastpname = $lastpostinfo[lastposter];
$getlastpname = $vbulletin->db->query_first("SELECT userid FROM ". TABLE_PREFIX ."user WHERE username = \"$lastpname\"");   
$lastpid = $getlastpname['userid'];

require_once('./includes/functions_user.php');
$lastpavurl = fetch_avatar_url($vbulletin->userinfo['userid']);

	$lastpav = "<img src='http://3.bp.blogspot.com/-mg71OkrgNhY/Uv9zeCV4IsI/AAAAAAAABbc/zqOph-wGgpc/s1600/Batman_avatar-e1263852269689.jpg' />";
}
else{
	$lastpav = "<a href='member.php?u=$lastpid'><img src='image.php?u=$lastpid' alt='$lastpname Profile'></a>";
}

$userinfo = fetch_userinfo($lastpid, FETCH_USERINFO_AVATAR)

  // get avatar
        if ($userinfo['avatarid'])
        {
            $userinfo['avatarurl'] = $userinfo['avatarpath'];
        }
        else
        {
            if ($userinfo['hascustomavatar'] AND $vbulletin->options['avatarenabled'])
            {
                if ($vbulletin->options['usefileavatar'])
                {
                    $userinfo['avatarurl'] = $vbulletin->options['avatarurl'] . '/avatar' . $userinfo['userid'] . '_' . $userinfo['avatarrevision'] . '.gif';
                }
                else
                {
                    $userinfo['avatarurl'] = 'image.php?' . $vbulletin->session->vars['sessionurl'] . 'u=' . $userinfo['userid'] . '&amp;dateline=' . $userinfo['avatardateline'];
                }
                if ($userinfo['avwidth'] AND $userinfo['avheight'])
                {
                    $userinfo['avwidth'] = 'width="' . $userinfo['avwidth'] . '"';
                    $userinfo['avheight'] = 'height="' . $userinfo['avheight'] . '"';
                }
                else
                {
                    $userinfo['avwidth'] = '';
                    $userinfo['avheight'] = '';
                }
            }
            else
            {
                $userinfo['avatarurl'] = '';
            }
        }

        if ( // no avatar defined for this user
            empty($userinfo['avatarurl'])
            OR // visitor doesn't want to see avatars
            ($vbulletin->userinfo['userid'] > 0 AND !$vbulletin->userinfo['showavatars'])
            OR // user has a custom avatar but no permission to display it
            (!$userinfo['avatarid'] AND !($this->cache['perms'][$userinfo['userid']]['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar']) AND !$userinfo['adminavatar']) //
        )
        {
            $show['avatar'] = false;
        }
        else
        {
            $show['avatar'] = true;
        }
but my original code was pretty much working.... it just had a few hickups, i dont see why i would need to add soooo much for such a little effect...
Reply With Quote
  #5  
Old 02-14-2015, 02:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dr.CustUmz View Post
but my original code was pretty much working.... it just had a few hickups, i dont see why i would need to add soooo much for such a little effect...
Yeah, I know how you feel. To be honest, I just couldn't figure out how your code was supposed to work or how to make it handle all the possible options, but maybe you don't really need it to. Maybe someone else will see how to fix the last issue with your code.
Reply With Quote
  #6  
Old 02-14-2015, 02:24 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In your script you do:

PHP Code:
if (!($lastpav)){ 
shouldn't that be something like:

PHP Code:
if (empty($lastpavurl)){ 
Reply With Quote
Благодарность от:
TheLastSuperman
  #7  
Old 02-14-2015, 02:52 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i tried the empty if that resulted in all of the avatars being batman.

the end result is rly simple... well i would think

it will show the last posters avatar (check)
if user has no avatar it will show default avatar (half check)
if no threads in forum it shows default avatar (half checked)

maybe i can avoid the issue of the if user has no avatar show default by requiring a avatar at reg (theres already a mod for that)

but still that doesnt solve why it doesnt display the batman pic in the very last forum =/
Reply With Quote
  #8  
Old 02-14-2015, 03:00 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The easiest way to find out why it's not working is to debug: dump your variables and see what it contains. Now it's a guessing game.

For example, above the if statement, add:

PHP Code:
var_dump($lastpav);
echo 
'<br>'
This will then dump the $lastpav variable of each forum loop on top of the screen.
Reply With Quote
  #9  
Old 02-14-2015, 04:09 PM
Dr.CustUmz's Avatar
Dr.CustUmz Dr.CustUmz is offline
 
Join Date: Aug 2013
Location: USA
Posts: 647
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave View Post
The easiest way to find out why it's not working is to debug: dump your variables and see what it contains. Now it's a guessing game.

For example, above the if statement, add:

PHP Code:
var_dump($lastpav);
echo 
'<br>'
This will then dump the $lastpav variable of each forum loop on top of the screen.
that actually worked amazingly, although it returned everything it was supposed to and correctly i have no idea what to do with this information.

the result of running the dump (to big for a screenshot)
Legend for dump:
batman (means full default img)
me (means my avatar)

and the results:

NULL
string(126) "batman"
NULL
NULL
string(126) "batman"
string(78) "me"
string(78) "me"
string(126) "batman"


so it looks to be correctly getting the information, and even though it gets that last batman img its not were it supposed to be as seen in the 1st post image. as for the user with no avatar (i believe is the 2nd NULL) im guessing i need an if condition for if user has avatar which i thought i was doing with:
Code:
fetch_avatar_url($vbulletin->userinfo['userid']);
so now that i have essentially debugged this... anyone know where to go from here, cause im still lost (especially on that last post not displaying the avatar even though the echo showed its getting the info (img) for it

--------------- Added [DATE]1423937537[/DATE] at [TIME]1423937537[/TIME] ---------------

also i left the dump echo on my site you wont miss it (sry for the big img overlay which rly isnt hard to disable in chrome) but you can see the results starting at the top of the page http://dirtrif.com
this is with the original code from the first post
Reply With Quote
  #10  
Old 02-14-2015, 05:42 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I still can't figure out how that code is working. It looks like there's only 2 options, it either your avatar or it's batman, so I don't see how you're getting the html you posted for the last one. Is the code you're using still what you posted in post #1?

BTW, I think what you want is $lastpavurl = fetch_avatar_url($lastpid), because using $vbulletin->userinfo['userid'] will always be your avatar.
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 12:01 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.04957 seconds
  • Memory Usage 2,325KB
  • Queries Executed 12 (?)
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
  • (6)bbcode_code
  • (5)bbcode_php
  • (2)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
  • (2)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (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_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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete