vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   $totalonline, $numbervisible, $numberguests in navbar? (https://vborg.vbsupport.ru/showthread.php?t=248118)

slobra 08-06-2010 04:31 PM

$totalonline, $numbervisible, $numberguests in navbar?
 
I added the code in red to my navbar template:

Code:

<strong><phrase 1="$bbuserinfo[username]" 2="member.php?$session[sessionurl]u=$bbuserinfo[userid]">$vbphrase[welcome_x_link_y]</phrase></strong><br />

$vbphrase[currently_active_users]: $totalonline (<phrase 1="$numbervisible" 2="$numberguests">$vbphrase[x_members_and_y_guests]</phrase>)<br />


But when I view the page, it shows up as follows: Online Users: 217 ( members and guests) - notice it's not getting the values for members and guests. What else do I need to add to display those values? Thanks for the help guys.

Lynne 08-06-2010 05:14 PM

You would need to add a plugin that then has the code that creates those variables for you. The code is on the bottom of the index.php page (if I recall correctly).

slobra 08-06-2010 10:09 PM

Thanks for the help, Lynne. I'm confused. I tried creating a new plugin with a hook location of global_start and the following code...

Code:

$activeusers = '';
if (($vbulletin->options['displayloggedin'] == 1 OR $vbulletin->options['displayloggedin'] == 2 OR ($vbulletin->options['displayloggedin'] > 2 AND $vbulletin->userinfo['userid'])) AND !$show['search_engine'])
{
        $datecut = TIMENOW - $vbulletin->options['cookietimeout'];
        $numbervisible = 0;
        $numberregistered = 0;
        $numberguest = 0;

        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        ($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser_query')) ? eval($hook) : false;

        $forumusers = $db->query_read_slave("
                SELECT
                        user.username, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.usergroupid,
                        session.userid, session.inforum, session.lastactivity, session.badlocation,
                        IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid
                        $hook_query_fields
                FROM " . TABLE_PREFIX . "session AS session
                LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = session.userid)
                $hook_query_joins
                WHERE session.lastactivity > $datecut
                        $hook_query_where
                " . iif($vbulletin->options['displayloggedin'] == 1 OR $vbulletin->options['displayloggedin'] == 3, "ORDER BY username ASC") . "
        ");

        if ($vbulletin->userinfo['userid'])
        {
                // fakes the user being online for an initial page view of index.php
                $vbulletin->userinfo['joingroupid'] = iif($vbulletin->userinfo['displaygroupid'], $vbulletin->userinfo['displaygroupid'], $vbulletin->userinfo['usergroupid']);
                $userinfos = array
                (
                        $vbulletin->userinfo['userid'] => array
                        (
                                'userid'            =>& $vbulletin->userinfo['userid'],
                                'username'          =>& $vbulletin->userinfo['username'],
                                'invisible'        =>& $vbulletin->userinfo['invisible'],
                                'inforum'          => 0,
                                'lastactivity'      => TIMENOW,
                                'usergroupid'      =>& $vbulletin->userinfo['usergroupid'],
                                'displaygroupid'    =>& $vbulletin->userinfo['displaygroupid'],
                                'infractiongroupid' =>& $vbulletin->userinfo['infractiongroupid'],
                        )
                );
        }
        else
        {
                $userinfos = array();
        }
        $inforum = array();

        while ($loggedin = $db->fetch_array($forumusers))
        {
                $userid = $loggedin['userid'];
                if (!$userid)
                {        // Guest
                        $numberguest++;
                        if (!$loggedin['badlocation'])
                        {
                                $inforum["$loggedin[inforum]"]++;
                        }
                }
                else if (empty($userinfos["$userid"]) OR ($userinfos["$userid"]['lastactivity'] < $loggedin['lastactivity']))
                {
                        $userinfos["$userid"] = $loggedin;
                }
        }

        if (!$vbulletin->userinfo['userid'] AND $numberguest == 0)
        {
                $numberguest++;
        }

        foreach ($userinfos AS $userid => $loggedin)
        {
                $numberregistered++;
                if ($userid != $vbulletin->userinfo['userid'] AND !$loggedin['badlocation'])
                {
                        $inforum["$loggedin[inforum]"]++;
                }
                fetch_musername($loggedin);

                ($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser')) ? eval($hook) : false;

                if (fetch_online_status($loggedin))
                {
                        $numbervisible++;
                        $show['comma_leader'] = ($activeusers != '');
                        eval('$activeusers .= "' . fetch_template('forumhome_loggedinuser') . '";');
                }
        }

        // memory saving
        unset($userinfos, $loggedin);

        $db->free_result($forumusers);

        $totalonline = $numberregistered + $numberguest;
        $numberinvisible = $numberregistered - $numbervisible;

        // ### MAX LOGGEDIN USERS ################################
        if (intval($vbulletin->maxloggedin['maxonline']) <= $totalonline)
        {
                $vbulletin->maxloggedin['maxonline'] = $totalonline;
                $vbulletin->maxloggedin['maxonlinedate'] = TIMENOW;
                build_datastore('maxloggedin', serialize($vbulletin->maxloggedin), 1);
        }

        $recordusers = vb_number_format($vbulletin->maxloggedin['maxonline']);
        $recorddate = vbdate($vbulletin->options['dateformat'], $vbulletin->maxloggedin['maxonlinedate'], true);
        $recordtime = vbdate($vbulletin->options['timeformat'], $vbulletin->maxloggedin['maxonlinedate']);

        $show['loggedinusers'] = true;
}
else
{
        $show['loggedinusers'] = false;
}


...but it didn't work. No doubt I don't quite understand plugins well enough, but I'm learning! :)

Lynne 08-07-2010 02:45 AM

I hope you didn't do that on a live site cuz my guess is you have zapped your max logged in users now.

The best thing you can do is start troubleshooting it by spiting out variables and see exactly what is going through there. Do you know if your code went through the if or else path? Find that out first. Then start doing other little things to find exactly what is going on.

slobra 08-07-2010 07:48 PM

Uh oh, zapping sounds bad. Site works fine, though. :shrug: Here's an excerpt from my navbar template, looks like it's going through the if path? If that's what you mean.

Code:

<if condition="$show['member']">
<td class="alt2" nowrap="nowrap">
<div class="smallfont">
<strong><phrase 1="$bbuserinfo[username]" 2="member.php?$session[sessionurl]u=$bbuserinfo[userid]">$vbphrase[welcome_x_link_y]</phrase></strong><br />

$vbphrase[currently_active_users]: $totalonline (<phrase 1="$numbervisible" 2="$numberguests">$vbphrase[x_members_and_y_guests]</phrase>)<br />

<if condition="$show['notifications']">
<div>
<if condition="$bbuserinfo['pmunread']">
<a href="http://www.truestreetcars.com/forums/private.php?"><img border="0" src="/forums/images/misc/newpm.gif" width="22" height="10"></a>
</if>


I found this post on vbulletin.com. Would this accomplish what I'm trying to do? For example would I be able to paste this code...

Code:

        $db->free_result($forumusers);

        $totalonline = $numberregistered + $numberguest;
        $numberinvisible = $numberregistered - $numbervisible;

        // ### MAX LOGGEDIN USERS ################################
        if (intval($vbulletin->maxloggedin['maxonline']) <= $totalonline)
        {
                $vbulletin->maxloggedin['maxonline'] = $totalonline;
                $vbulletin->maxloggedin['maxonlinedate'] = TIMENOW;
                build_datastore('maxloggedin', serialize($vbulletin->maxloggedin), 1);
        }

        $recordusers = vb_number_format($vbulletin->maxloggedin['maxonline']);
        $recorddate = vbdate($vbulletin->options['dateformat'], $vbulletin->maxloggedin['maxonlinedate'], true);
        $recordtime = vbdate($vbulletin->options['timeformat'], $vbulletin->maxloggedin['maxonlinedate']);

        $show['loggedinusers'] = true;
}


...somewhere in global.php? Usually I can figure these things out pretty quickly but this one is proving elusive. I must be missing something. LOL


All times are GMT. The time now is 06:12 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.04135 seconds
  • Memory Usage 1,758KB
  • 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
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete