vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Adding Currently Active Users to your own vB page (https://vborg.vbsupport.ru/showthread.php?t=187388)

Forum Lover 11-15-2008 03:59 AM

Roger that. :)

djxcee 11-16-2008 11:05 AM

Quote:

Originally Posted by mokujin (Post 1656801)
I have it, just add this code for your custom page.
After
Add:
PHP Code:

AND session.location LIKE '%your_script_name.php%' 

Thank you Lynne :)

How do I add more than one file?

Also, will this work on existing vBulletin files? Let's say I want to add it to Social Groups.

Lynne 11-16-2008 03:27 PM

Quote:

Originally Posted by djxcee (Post 1666728)
How do I add more than one file?

Also, will this work on existing vBulletin files? Let's say I want to add it to Social Groups.

The code in this tutorial is for a single page. So, if you want it on Social Groups, you add the code to that page and then add that line to the query with the social groups php page in there.

eh9 daddy 11-21-2008 07:35 AM

1 Attachment(s)
I tryed to add it on vb 3.8 beta2, but it don't work. it don't show any numbers, look at the screenshot. sorry for my bad english

here is my code from my php file

Code:

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'test');


// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array(
        'maxloggedin',
); 

// pre-cache templates used by all actions
$globaltemplates = array(
        'Test',
        'forumhome_loggedinuser',
);



// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_bigthree.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

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


$navbits = array();
$navbits[$parent] = 'Test Page';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('Test') . '");');

// ### LOGGED IN USERS #################################################
$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))
        {
                if ($loggedin['badlocation'])
                {
                        continue;
                }

                $userid = $loggedin['userid'];
                if (!$userid)
                {        // Guest
                        $numberguest++;
                        $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'])
                {
                        $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;
}

?>

and my code from the template

Code:

<!-- logged-in users -->
<table>
        <tr>
                <td class="thead" colspan="2">
                        <a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_activeusers')"><img id="collapseimg_forumhome_activeusers" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_activeusers].gif" alt="" border="0" /></a>
                        <a href="online.php$session[sessionurl_q]">$vbphrase[currently_active_users]</a>: $totalonline (<phrase 1="$numberregistered" 2="$numberguest">$vbphrase[x_members_and_y_guests]</phrase>)
                </td>
        </tr>
</table>
<table id="collapseobj_forumhome_activeusers" style="$vbcollapse[collapseobj_forumhome_activeusers]">
        <tr>
                <td class="alt2"><a href="online.php$session[sessionurl_q]"><img src="$stylevar[imgdir_misc]/whos_online.gif" alt="$vbphrase[view_whos_online]" border="0" /></a></td>
                <td class="alt1" width="100%">
                        <div class="smallfont">
                                <div style="white-space: nowrap"><phrase 1="$recordusers" 2="$recorddate" 3="$recordtime">$vbphrase[most_users_ever_online_was_x_y_at_z]</phrase></div>
                                <div>$activeusers</div>
                        </div>
                </td>
        </tr>
</table>
<!-- end logged-in users -->


Lynne 11-21-2008 03:02 PM

This was written to be used in conjunction with How to create your own vBulletin-powered page! (uses vB templates) or [How-To] vBulletin API Basics: Creating Custom Pages & Misc. You need to eval/fetch your templates after the code like in those articles. This article is NOT stand alone code. You MUST use it with an already working vb powered page.

eh9 daddy 11-21-2008 03:29 PM

i have an working vbulletin powered page. in this page i use for example the vbulletin login, recent forum threads, latest album pictures and so on. everything works in this page, only who's online works not.

Lynne 11-21-2008 03:55 PM

Quote:

Paste these lines into the main part of your page.
You pasted it at the end of your script. You need to put it before you eval your templates - right under "START MAIN SCRIPT", before the $navbits stuff.

eh9 daddy 11-21-2008 04:03 PM

thanks alot, this was the error :)

shoolace 12-27-2008 07:19 PM

Thank you for this article. It explains everything perfectly. Installed in no time.

Voted 5 stars. :up:

Shoolace

Submerge 02-20-2009 05:47 PM

Question;

I have the ability to log in users on all my non-VB pages. If a user comes on a non-VB page, it'll fetch their cookies and automatically log them in if they are a member who selected the Remember Me option. Otherwise it'll act as if they are a Guest user.

I don't want to display the Currently Active Users on my non-VB pages, but I'd like to know if there are users on my non-VB pages by looking at the Currently Active Users on the forumhome.

Do all I need to add to do this then is this?
Code:

// ######################### REQUIRE BACK-END ############################
chdir ('/path/to/your/forums');
require_once('./global.php');
require_once(DIR . '/includes/functions_bigthree.php');

That way Ill know how many vBulletin members are on at a certain time throughout my entire website, not just the forums? (Since I have that code in the header.php file that all non-VB pages use)

[edit]
I tried this out but it's not recognizing users on my site's index.php (which uses the header.php file I'm putting the code into.

Here are the first lines that the header.php file is using to try and get this working:
Code:

<?php
        //vBulletin Member Recognition
        $curdir = getcwd ();
        chdir('forums/');
        require_once('forums/global.php');
        require_once(DIR . '/includes/functions_bigthree.php'); //Fetch current active users?
        chdir ($curdir);



All times are GMT. The time now is 11:02 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.01506 seconds
  • Memory Usage 1,794KB
  • 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)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)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