Log in

View Full Version : Users online question


DarkWarriorXII
10-06-2005, 09:38 PM
First off I'll say that I'm not the greatest at PHP and all that. Anyway, I was wondering how the forum home gets the current users online list to show up, and say how many users/guests are currently online? I ask this because I have a custom vB page in the same directory as my forum and I want to get that list of online users and the number of online people to show up (Currently Active Users:...), but I can't figure out how to do it. Any help would be appreciated. :)

Andreas
10-12-2005, 11:16 PM
Open index.php, search for // ### LOGGED IN USERS #################################################
and then take a look at the Code block below, that should get you the idea of how to do it.

DarkWarriorXII
10-12-2005, 11:20 PM
Sorry but I can't figure it out. :( I'm not sure what to use, what not to use, how I should add it to my page, etc.

Andreas
10-12-2005, 11:22 PM
It's mainly just a copy & paste job ...

DarkWarriorXII
10-12-2005, 11:28 PM
So basically just copy everything from:

// ### LOGGED IN USERS #################################################

to right before

// ### GET FORUMS & MODERATOR iCACHES ########################

and paste all of that into where I want the list to be displayed?

Andreas
10-12-2005, 11:34 PM
Yep. Then you can use $activeusers, $numberguests, $numberregistered, $numberinvisible, $totalonline, $recordusers, $recorddate, $recordtime.
Make sure that you have cached maxloggedin, otherweise you will corrupt this data.

$specialtemplates = array('maxloggedin');


Or leave out the maxlogedin part completely.

DarkWarriorXII
10-12-2005, 11:52 PM
Well I'm confused. :disappointed: Here's my file as of right now:


<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'index'); // change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
);
// get special data templates from the datastore
$specialtemplates = array(
'online',
);
// pre-cache templates used by all actions
$globaltemplates = array(
'homepage',
'online',
'forumhome_loggedinuser',
'headinclude',
'forumhome',
'maxloggedin',
'wol_spiders',
);
// pre-cache templates used by specific actions
$actiontemplates = array(
'online',
);
// ######################### REQUIRE BACK-END ############################
chdir('/home/dwxii/talkcamp.com/');
require('./global.php');

// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
$navbits = array();
$navbits[$parent] = 'Talk Camp Homepage';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('homepage') . '");');
eval('print_output("' . fetch_template('online') . '");');

// ### LOGGED IN USERS #################################################
$activeusers = '';
if ($vbulletin->options['displayloggedin'] AND !$show['search_engine'])
{
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$numbervisible = 0;
$numberregistered = 0;
$numberguest = 0;
$numberspiders = 0;
$forumusers = $db->query_read("
SELECT
user.username, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.usergroupid,
session.userid, session.inforum, session.lastactivity,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
FROM " . TABLE_PREFIX . "session AS session
LEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = session.userid)
WHERE session.lastactivity > $datecut
" . iif($vbulletin->options['displayloggedin'] == 1, "ORDER BY username ASC") . "
");
$spiders = $db->query_read("
SELECT user.username, session.useragent,user.userid,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
FROM " . TABLE_PREFIX . "session AS session
". iif($vbulletin->options['WOLguests'], " LEFT JOIN " . TABLE_PREFIX . "user AS user
USING (userid) ", ", " . TABLE_PREFIX . "user AS user") ."
WHERE session.lastactivity > $datecut
". iif(!$vbulletin->options['WOLguests'], " AND session.userid = user.userid", "")
."
ORDER BY session.userid
");
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'],
)
);
}
else
{
$userinfos = array();
}
$inforum = array();
while ($loggedin = $db->fetch_array($forumusers))
{
$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]"]++;
}
$loggedin['musername'] = fetch_musername($loggedin);
($hook = vBulletinHook::fetch_hook('forumhome_loggedinuser' )) ? eval($hook) : false;
if (fetch_online_status($loggedin))
{
$numbervisible++;
eval('$activeusers .= ", ' . fetch_template('forumhome_loggedinuser') . '";');
}
}
// memory saving

$spiderlist = array();
while ($spidercand = $db->fetch_array($spiders))
{
$userid = $spidercand['userid'];
if (!empty($vbulletin->wol_spiders))
{
if (preg_match('#(' . $vbulletin->wol_spiders['spiderstring'] . ')#si', $spidercand['useragent'], $agent))
{
$agent = strtolower($agent[1]);
$spider = $vbulletin->wol_spiders['agents']["$agent"];
$key = $spider['name'];
if(array_key_exists($key,$spiderlist))
{
$spiderlist[$key] = $spiderlist[$key] + 1;
}
else
{
$spiderlist[$key] = 1;

}

}
}
}
while ($spidername = current($spiderlist))
{
if ($spidername > 1) {
$loggedin['musername'] = trim(key($spiderlist)) . "(" . $spidername.")";
}
else
{
$loggedin['musername'] = trim(key($spiderlist));
}
$loggedin['userid'] = 0;
eval('$activeusers .= ", ' . fetch_template('forumhome_loggedinuser') . '";');
$numberspiders = $numberspiders + $spidername;
next($spiderlist);
}

unset($userinfos, $loggedin);
$activeusers = substr($activeusers, 2); // get rid of initial comma
$db->free_result($forumusers);
$numberguest = $numberguest - $numberspiders;
$totalonline = $numberregistered + $numberguest + $numberspiders;
$numberinvisible = $numberregistered - $numbervisible;
}
?>


and if you need the 'homepage' template, here it is:


$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache" />
<!-- end no cache headers -->
<title>TalkCamp.com Homepage</title>
$headinclude
</head>
<body>
$header
$navbar

<TABLE WIDTH="100%" valign="top"><TR><TD WIDTH="75%" valign="top">
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<thead>
<tr>
<td class="tcat" colspan="1">Message</td>
</tr>
<tr>
<td class="thead">We're Under Construction, But Still Open!</td>
</tr>
<tr>
<td class="alt1" colspan="1">
<p>Thanks for visiting TalkCamp.com! Right now, we're under construction, but check back soon for updates. In the mean time, feel free to <b><a href="register.php">register to our site</a></b> (for free) so you'll be set when we open.</p><p>Thanks,<br>Dave<br>Webmaster, Admin</p>
</td>
</tr>
</thead>
<thead>
<tr>
<td class="tcat" colspan="1">Welcome to Talk Camp!</td>
</tr>
<tr>
<td class="alt1" colspan="1">
<p>Welcome to TalkCamp.com! Talk Camp is an online community and website dedicated to those wonderful people who are known as camp counselors. We also serve other camp staff such as specialists, etc. It's the efforts of these people that allow thousands of kids around the world to have the best summers of their lives at camp! We are here to make your camp counseling experience even better. So please join us, become an active part of our community, and help spread the fun and joy of being a camp counselor!</p>
<center><b><a href="forum.php">Click here to go to the forums!</a></b><if condition="is_member_of($bbuserinfo, 1)"> or <br><b><a href="register.php">register</a></b> / <b><a href="login.php">log-in</a></b>!</if>
</td>
</tr>
</thead>
</table>
</TD><TD WIDTH="25%" valign="top">
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center" valign="top">
<thead valign="top">
<tr>
<td class="tcat" colspan="1">Mission Statement</td>
</tr>
<tr>
<td class="alt1" colspan="1">We are here to provide camp counselors and other camp staff with the best information available, as well as the best place to talk about their passion for camp counseling. We hope to make your camp experience the best it can possibly be!</td>
</tr>
</thead>
<thead>
<if condition="$vbulletin->options['externaljs']">
<!-- show latest active threads -->
<thead>
<tr>
<td class="tcat" colspan="1">
<a href="search.php?$session[sessionurl]do=getnew">Latest Active Threads</a>
</td>
</tr>
</thead>
<thead id="collapseobj_forumhome_external" style="$vbcollapse[collapseobj_forumhome_external]">
<tr>

<td class="alt1" width="100%">

<div class="smallfont">
<script type="text/javascript" src="external.php?type=js"></script>
<script language="" type="text/javascript">
<!--
for (x = 0; x < 10; x++)
{
document.writeln("<img class=\"inlineimg\" src=\"$stylevar[imgdir_button]/lastpost.gif\" alt=\"\" border=\"0\" /> <a href=\"showthread.php?t="+threads[x].threadid+"\">"+threads[x].title+"</a> <span class=\"time\">($vbphrase[posted_by]: "+threads[x].poster+")</span><br />");
}
//-->
</script></div>

</td>
</tr>
</thead>
<!-- show latest active threads -->
</if>
</thead>
<thead>
<tr>
<td class="tcat" colspan="1">Users Online</td>
</tr>
<tr>
<td class="alt1" colspan="1">$online
</td>
</tr>
</thead>
</table>
</TD>
</TR>
</TABLE>
$footer
</body>
</html>


The 'online' template is just $activeusers because I have no idea. :p