The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Adding Currently Active Users to your own vB page
Adding Currently Active Users to your own vB page I've seen a few users asking about how to add the list of Currently Active Users to their own vB page. Below I document the lines of code you must add after creating your own page using one of these articles - How to create your own vBulletin-powered page! (uses vB templates) or [How-To] vBulletin API Basics: Creating Custom Pages & Misc. This article only documents what to add to a working page in order to get your Currently Active Users. You should make sure your page is working first before adding this code. I'll refer to your working page as test.php and the template in your working page as 'TEST'. Instructions Open your working php page and ADD the maxloggedin template to the specialtemplates array (your maxloggedin users will get reset all the time if you don't add this - I learned that the hard way!): PHP Code:
PHP Code:
PHP Code:
PHP Code:
END lines. Paste these lines into the main part of your page. (You might want to copy this code from a default index.php if you have modified your index.php page.) START with: PHP Code:
PHP Code:
HTML Code:
<!-- logged-in users --> <tbody> <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]" rel="nofollow">$vbphrase[currently_active_users]</a>: $totalonline (<phrase 1="$numberregistered" 2="$numberguest">$vbphrase[x_members_and_y_guests]</phrase>) </td> </tr> </tbody> <tbody id="collapseobj_forumhome_activeusers" style="$vbcollapse[collapseobj_forumhome_activeusers]"> <tr> <td class="alt2"><a href="online.php$session[sessionurl_q]" rel="nofollow"><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> </tbody> <!-- end logged-in users --> HTML Code:
<tr> <td class="tcat" colspan="2">Title</td> </tr> <tr> <td class="alt1" colspan="2">Text</td> </tr> |
#32
|
|||
|
|||
Roger that.
|
#33
|
|||
|
|||
Quote:
Also, will this work on existing vBulletin files? Let's say I want to add it to Social Groups. |
#34
|
||||
|
||||
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.
|
#35
|
|||
|
|||
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; } ?> 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 --> |
#36
|
||||
|
||||
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.
|
#37
|
|||
|
|||
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.
|
#38
|
||||
|
||||
Quote:
|
#39
|
|||
|
|||
thanks alot, this was the error
|
#40
|
|||
|
|||
Thank you for this article. It explains everything perfectly. Installed in no time.
Voted 5 stars. :up: Shoolace |
#41
|
|||
|
|||
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'); [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); |
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|