View Full Version : look over my code please avatars not displaying correctly
Dr.CustUmz
02-14-2015, 12:34 PM
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) :o
oh and this is on forumbit_display
$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
https://vborg.vbsupport.ru/attachment.php?attachmentid=151873&stc=1&d=1423924124
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
<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:
<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
Here's the code that displays the avatar in the postbit:
// 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'] . '&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;
}
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.
Also, for reference, here's the corresponding code from the postbit template:
<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.
Dr.CustUmz
02-14-2015, 01:59 PM
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
$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'] . '&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...
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.
In your script you do:
if (!($lastpav)){
shouldn't that be something like:
if (empty($lastpavurl)){
Dr.CustUmz
02-14-2015, 02:52 PM
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 =/
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:
var_dump($lastpav);
echo '<br>';
This will then dump the $lastpav variable of each forum loop on top of the screen.
Dr.CustUmz
02-14-2015, 04:09 PM
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:
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: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 1423937537 at 1423937537 ---------------
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
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.
Dr.CustUmz
02-14-2015, 06:12 PM
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.
yes still the same code as in post #1 with the edition of the dump echo, also changing that line results in a mysql error and the way i have it (yes i know youre right on userinfo userid displays current user id) but some how the way i have it, it displays the last poster avatar. (code in post #1) i can confirm this by adding an avatar to the test account and it will display proper avatars even after i flush dns hard refresh, so it is pulling the right id, and it does pull the other users avatar, just when the user has no avatar it should also be the default (batman) img.
Database error in vBulletin 3.8.8:
Invalid SQL:
SELECT user.avatarid, user.avatarrevision, avatarpath, NOT ISNULL(customavatar.userid) AS hascustom, customavatar.dateline,
customavatar.width, customavatar.height, customavatar.width_thumb, customavatar.height_thumb
FROM user AS user
LEFT JOIN avatar AS avatar ON avatar.avatarid = user.avatarid
LEFT JOIN customavatar AS customavatar ON customavatar.userid = user.userid
WHERE user.userid =;
MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6
Error Number : 1064
Request Date : Saturday, February 14th 2015 @ 08:04:33 PM
Error Date : Saturday, February 14th 2015 @ 08:04:34 PM
Script : http://dirtrif.com/
Referrer : http://dirtrif.com/news-announcements/1-dirt-rif-resurrected.html
IP Address : 68.61.*******
Username : DrCustUmz
Classname : vB_Database
MySQL Version : 5.5.40-cll
thats not rly the BIG issue although would be something i would like to work right, i can get around that by forcing avatars at registration. (another addon)
the thing that gets me most is why is it pulling the data (you can see in the dump on my site) for that last forum yet in the last forum box it wont display =/
also i will add an avatar to the test account just so you can see it working correctly (last poster avatar wise) still would like the if no avatar display default img to work though.
ok so after adding the avatar to the test account, the avatar does appear correctly no matter what account / browser im on or even logged off, but i noticed in that echo dump dave had me add, it's not showing the test accounts avatar.....
OK, I think I might see what's happening. The reason you're seeing the test account avatar is because the html has ?u=$lastpid. But I think what you want to do is check $lastpid before calling fetch_avatar_path(), like maybe:
$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');
if ($lastpid) {
$lastpavurl = fetch_avatar_url($lastpid);
}
else {
$lastpavurl = '';
}
if ($lastpavurl==''){
$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>";
}
Dr.CustUmz
02-14-2015, 06:34 PM
OK, I think I might see what's happening. The reason you're seeing the test account avatar is because the html has ?u=$lastpid. But I think what you want to do is check $lastpid before calling fetch_avatar_path(), like maybe:
$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');
if ($lastpid) {
$lastpavurl = fetch_avatar_url($lastpid);
}
else {
$lastpavurl = '';
}
if ($lastpavurl==''){
$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>";
}
i F**K**G LOVE YOU, YOURE AMAZING AFTER ONLY 4+ HOURS OF MESSING WITH IT BEFORE ASKING FOR HELP, THEN ALL THE TIME IN HELP LOL.
that did it and i havent noticed any errors, you rock Kevin
happy valentines day!
btw i didnt just copy and paste that, i compared it to mine, took in my mistakes and learned from them (damn if statement lol) so thanks and i learned quite a bit tinkering with this what seemed to be simple addition =)
side note* if user doesnt have avatar set, it doesnt display the default image, like i have said i can get around it with forced avatars, but would rather have this working fully.... if its possible lol.
i have looked at some other avatar mods, but what i came up with was the best i could do
side note* if user doesnt have avatar set, it doesnt display the default image, like i have said i can get around it with forced avatars, but would rather have this working fully.... if its possible lol.
Hmm...I don't understand why that is, because it looks like fetch_avatar_url should return an empty string in that case. Maybe you can vardump() some things and see what's happening. What does the html look like if the user has no avatar set?
Dr.CustUmz
02-14-2015, 11:13 PM
ok so i've had some time to rest, and figure out whats actually going on in this script so heres what i found out (this is with the code from post #12)
if guest (obviously no avatar set)
https://vborg.vbsupport.ru/attachment.php?attachmentid=151878&stc=1&d=1423962384
(my account)
with avatar set
https://vborg.vbsupport.ru/attachment.php?attachmentid=151879&stc=1&d=1423962398
Broken images pointing to:
<img src="http://dirtrif.com/avatars/drbot.gif" alt="DrBot Profile" title="DrBot Profile">
without avatar set
*same as the first image*
(test user and my account has an avatar)
with test account avatar set
https://vborg.vbsupport.ru/attachment.php?attachmentid=151881&stc=1&d=1423962398
without test account avatar set
*same as the first image*
(test user and my account has no avatar)
with test account avatar set
https://vborg.vbsupport.ru/attachment.php?attachmentid=151882&stc=1&d=1423962398
Broken images pointing to:
<img src="http://dirtrif.com/avatars/drcustumz.gif" alt="DrCustUmz Profile" title="DrCustUmz Profile">
without test account avatar set
*same as the first image*
so in summery, it looks like if the user is logged in, and has an avatar set it works 100%, but if logged in user doesnt set an avatar then they will see batman for everyone.
and if logged in user has an avatar and another user doesnt have an avatar and happens to be the last poster. instead of being the default img, its just a broken img
so even though i thought this was done... it looks like its still has some work to be done. still alot further then anywhere i was with it =)
Dr.CustUmz
02-14-2015, 11:35 PM
i made that default img a smaller img (for easier testing) enabled the debug above the if condition and made a test account for anyone to see whats going on, oh and removed the big under construction overlay cause yall probally thought that was annoying lol (the point of it)
i have printed
<td class="forum bordl">
<a class="forumh_cat" href="forumdisplay.php?$session[sessionurl]f=$forum[forumid]"><b>$forum[title]</b></a>
<br /> $lastpav -lastpav
<br />
$lastpavurl - lastpavur
<br />
$lastpid - lastpid
<br />
$getlastpname - lastpname
<br />
</td>
in my forumbit lvl2 post
and have made a test account for anyone wanting to tinker with this to get a hands on (ahh i see whats going on kinda feel)
username: test
password: 123
http://dirtrif.com
feel free to post give him an avatar or w/e to see what hapens.
--------------- Added 1424001841 at 1424001841 ---------------
sry for the trip posts, but i havent touched this code since yesterday, the code still stands as it did in post #12 and i cant believe i didnt notice it sooner but in forum categorie's it returns an error. and yes im sure its this plugin.
https://s3.amazonaws.com/f.cl.ly/items/0N2e3L350f1i450U2Z2P/Image%202015-02-15%20at%207.02.11%20AM.png
--------------- Added 1424004452 at 1424004452 ---------------
another bump*
i was looking over the code used in postbit and looking over the tables in the DB
heres one thing i noticed:
http://cl.ly/image/342s3m181z0Q/Image%202015-02-15%20at%207.43.03%20AM.png
if the user has set their avatar, it creates a row for them in the table customavatar.
so what i need is an if condition saying if lastpid is in customavatar table then show avatar, else show default.
i started messing around with this, with no luck no matter what variation i tried. looking at the function_user file and i came up with
fetch_avatar_url($vbulletin->customavatar['lastpid']);
i think im on to something (i hope lol) i know such a noob lol, but i dont want to give up on this. Im going to keep toying with this but just thought id share in the mean time =)
--------------- Added 1424004661 at 1424004661 ---------------
heres how my code (kind of working) stands to this point
require_once('./includes/functions_user.php');
$lastpname = $lastpostinfo[lastposter];
$getlastpname = $vbulletin->db->query_first("SELECT userid FROM ". TABLE_PREFIX ."user WHERE username = \"$lastpname\"");
$lastpid = $getlastpname['userid'];
var_dump($getlastpname);
echo '<br>';
if ($lastpid) {
$lastpavurl = fetch_avatar_url($vbulletin->userinfo['userid']);
}
else {
$lastpavurl = '';
}
if ($lastpavurl==''){
$lastpav = "<img src='http://images.fanpop.com/images/image_uploads/Batman-avatar-batman-233977_100_100.jpg' />";
}
else{
$lastpav = "<a href='member.php?u=$lastpid'><img src='image.php?u=$lastpid' alt='$lastpname Profile'></a>";
}
the
var_dump($getlastpname);
echo '<br>';
is only their for debugging (which I really dont quite get yet =/ but i do see result in it lol
--------------- Added 1424006931 at 1424006931 ---------------
another update i came up with this garbage (which doesnt work at all) but maybe just maybe it will help someone in helping me lol
require_once('./includes/functions_user.php');
$lastpname = $lastpostinfo[lastposter];
$getlastpname = $vbulletin->db->query_first("SELECT userid FROM ". TABLE_PREFIX ."user WHERE username = \"$lastpname\"");
$lastpid = $getlastpname['userid'];
$avatarinfo = $vbulletin->db->query_first_slave("SELECT user.avatarid FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON avatar.avatarid = user.avatarid
LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON customavatar.userid = user.userid
WHERE user.userid = \"$lastpid\"");
var_dump($avatarinfo);
echo '<br>';
if (!empty($avatarinfo))
{
$lastpavurl = fetch_avatar_url($vbulletin->userinfo['userid']);
}
else
{
$lastpavurl = '';
}
if ($lastpavurl==''){
$lastpav = "<img src='http://images.fanpop.com/images/image_uploads/Batman-avatar-batman-233977_100_100.jpg' />";
}
else{
$lastpav = "<a href='member.php?u=$lastpid'><img src='image.php?u=$lastpid' alt='$lastpname Profile'></a>";
}
so what im TRYING to get it to do is check if there is a table row for the lastpid under customavatar table, if not then it will display the default image else use the image.
am i thinking about this the right way? is that a good start? wasnt there a plugin that already did this lmao.
--------------- Added 1424007806 at 1424007806 ---------------
well shit -_-
https://vborg.vbsupport.ru/showthread.php?t=269031
and html/css is what im pro with, so adapting it would be no issue
BUT BUT BUT!
i would still like to get this functional (its end result would be the same) but the method completly different, and this is more of a learning curve for me, so it is something i would like to finish since i (we) started just to be able to say it was completed.
TheLastSuperman
02-19-2015, 03:34 AM
Don't use that mod you posted above until you figure out yours first - else you won't have learned anything imho :p.
+1 to kh99 and +1 to Dave for helping!
Dr.CustUmz
02-21-2015, 09:25 PM
kind of past that point lol, but its not on my live site =)
I would LOVE to get this working (even took a look at the guts of the mod i mentioned) but I'm still lost =/
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.