vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Problems with avatar if conditional (https://vborg.vbsupport.ru/showthread.php?t=248285)

DataHero 08-27-2010 06: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:
Code:

$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:
HTML Code:

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 07: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-27-2010 11:37 PM

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'])):

Code:

$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 01: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 04:27 AM

Okay, I see the part where it's being fetched (if I am right), which starts at:
PHP Code:

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 01: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 07: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 09: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.


All times are GMT. The time now is 01:26 PM.

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.02316 seconds
  • Memory Usage 1,745KB
  • 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
  • (2)bbcode_code_printable
  • (1)bbcode_html_printable
  • (1)bbcode_php_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
  • (8)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