PDA

View Full Version : Number of users browsing current forum


Zzed
04-28-2002, 10:00 PM
This is a really simple hack that displays the number of users browsing the current forum along
with the list of users.

It requires no template changes. ;)

In forumdisplay.php

find:

if ($showforumusers) {
$datecut = $ourtimenow - $cookietimeout;
$browsers = '';
$comma = '';
$forumusers = $DB_site->query("SELECT username, invisible, userid
FROM user
WHERE inforum = $foruminfo[forumid]
AND lastactivity > $datecut
AND lastvisit <> lastactivity");
while ($forumuser = $DB_site->fetch_array($forumusers)) {
if ((!$forumuser['invisible'] or $bbuserinfo['usergroupid'] == 6) and $bbuserinfo['userid'] != $forumuser['userid']) {
$userid = $forumuser['userid'];
$username = $forumuser['username'];
if ($forumuser['invisible'] == 1) { // Invisible User but show to Admin
$invisibleuser = '*';
} else {
$invisibleuser = '';
}
eval("\$browsers .= \"".$comma.gettemplate('forumdisplay_loggedinuser')."\";");
$comma = ', ';
}
}
// Don't ask the DB for the user that is viewing the page as they wouldn't be here if they weren't! DOH!
// This way our query up above can hit the inforum index so don't change unless you know what you are doing.
if ((!$bbuserinfo['invisible'] or $bbuserinfo['usergroupid'] == 6) and $bbuserinfo['userid'] <> 0) {
$userid = $bbuserinfo['userid'];
$username = $bbuserinfo['username'];
if ($bbuserinfo['invisible'] == 1) { // Admin is invisible but show himself to himself, get it!
$invisibleuser = '*';
} else {
$invisibleuser = '';
}
eval("\$browsers .= \"".$comma.gettemplate('forumdisplay_loggedinuser')."\";");
}
if ($browsers) {
if (!$moderatedby) {
$onlineusers = "<br>";
}
eval("\$onlineusers .= \"".gettemplate('forumdisplay_loggedinusers')."\";");
}
}


And replace it with:

if ($showforumusers) {
$datecut = $ourtimenow - $cookietimeout;
$browsers = '';
$comma = '';
$usercount = 0;
$forumusers = $DB_site->query("SELECT username, invisible, userid
FROM user
WHERE inforum = $foruminfo[forumid]
AND lastactivity > $datecut
AND lastvisit <> lastactivity");
while ($forumuser = $DB_site->fetch_array($forumusers)) {
if ((!$forumuser['invisible'] or $bbuserinfo['usergroupid'] == 6) and $bbuserinfo['userid'] != $forumuser['userid']) {
$userid = $forumuser['userid'];
$username = $forumuser['username'];
if ($forumuser['invisible'] == 1) { // Invisible User but show to Admin
$invisibleuser = '*';
} else {
$invisibleuser = '';
}
eval("\$browsers .= \"".$comma.gettemplate('forumdisplay_loggedinuser')."\";");
$comma = ', ';
$usercount++;
}
}
// Don't ask the DB for the user that is viewing the page as they wouldn't be here if they weren't! DOH!
// This way our query up above can hit the inforum index so don't change unless you know what you are doing.
if ((!$bbuserinfo['invisible'] or $bbuserinfo['usergroupid'] == 6) and $bbuserinfo['userid'] <> 0) {
$userid = $bbuserinfo['userid'];
$username = $bbuserinfo['username'];
if ($bbuserinfo['invisible'] == 1) { // Admin is invisible but show himself to himself, get it!
$invisibleuser = '*';
} else {
$invisibleuser = '';
}
$usercount++;
eval("\$browsers .= \"".$comma.gettemplate('forumdisplay_loggedinuser')."\";");
}
if ($browsers) {
$browsers = "<b>($usercount users)</b> $browsers";
if (!$moderatedby) {
$onlineusers = "<br>";
}
eval("\$onlineusers .= \"".gettemplate('forumdisplay_loggedinusers')."\";");
}
}


You can see a sample of this at my site: http://www.ls1.com/forums/index.php

Neo
04-29-2002, 05:12 AM
It would be better if the number could be showen on the main forum page :)

Floris
04-29-2002, 06:41 AM
I had the same idea :P

So, this only adds the number of people right? Because vB 2.2.5 already has 'Users browsing this forum: nick1, nick2, ..' by default.

Neo
04-29-2002, 06:58 AM
I will make this tonight if I am not to lazy :P

Zzed
04-29-2002, 08:23 AM
Originally posted by xiphoid
I had the same idea :P

So, this only adds the number of people right? Because vB 2.2.5 already has 'Users browsing this forum: nick1, nick2, ..' by default. Yes, it adds the number of people to the list.

Like this:

(Users Browsing this Forum: (11 users) mrgto*, Mikesbird, ghetto808, INSSANE, 1BADFIREHAWK, oxide, 00camaroSS, TGrits10, Big Spanky, Amuka, Zed*)

RDX1
04-29-2002, 11:53 PM
i dont get what this hack does

Zzed
04-30-2002, 04:56 AM
Look at the bold text in my previous reply.

TECK
04-30-2002, 07:43 PM
this is a great hack.. and it doesnt require to add a new field.. however i'm concerned with the extra query? how is the server load doing?

Zzed
04-30-2002, 07:47 PM
There is no extra query. The counting is being done within the loop. It should have zero effect on the server.

yasunari
04-30-2002, 11:05 PM
I found that it won't count the Guest on the forum?
It would be great if it can count how many guest in each forum :P

Renegade
07-25-2002, 10:16 AM
I am looking for the hack that vbulletin.org uses. It offers the number of users browsing the forum on the main index page. Anybody know how to do this?

Renegade
07-25-2002, 10:17 AM
I am trying to find the hack that vbulletin.org uses in the main forum index page. It displays the number of users browsing the forum in the forum name field??

Barret
09-01-2002, 03:48 AM
Originally posted by Renegade
I am trying to find the hack that vbulletin.org uses in the main forum index page. It displays the number of users browsing the forum in the forum name field??
I`m looking for the same hack! ;)

Chris M
09-01-2002, 08:23 AM
Cool:)

If you could get it for "Users browsing this Thread", that would be cool:)

Satan

Boofo
09-01-2002, 08:36 AM
Just do the same coding in showthread.php and you did the forumdisplay and it will be the same. :) I even went one step further and have it saying:

(1 User Browsing this Thread: Boofo) and
(2 Users Browsing this Thread: Boofo, hellsatan)

Originally posted by hellsatan
Cool:)

If you could get it for "Users browsing this Thread", that would be cool:)

Satan

Chris M
09-01-2002, 08:45 AM
Ok so it would work:)

Cool:)

Thanks:D

Satan

Boofo
09-01-2002, 08:47 AM
I have the code if it would help you. ;)

Chris M
09-01-2002, 09:01 AM
Yes please:)

Satan

Boofo
09-01-2002, 09:37 AM
Here you go. :)

NOTE: You need to have Firefdly's Users browsing this thread hack installed.


-----------------------
In showthread.php:
-----------------------
After this:
-----------------------

if ($showforumusers) {
$datecut = $ourtimenow - $cookietimeout;
$browsers = '';
$comma = '';

-----------------------
Add this:
-----------------------

$usercount = 0;

-----------------------
After this:
-----------------------

} else {
$invisibleuser = '';
}
eval("\$browsers .= \"".$comma.gettemplate('forumdisplay_loggedinuser')."\";");
$comma = ', ';

-----------------------
Add this:
-----------------------

$usercount++;

-----------------------
Before this:
-----------------------

eval("\$browsers .= \"".$comma.gettemplate('forumdisplay_loggedinuser')."\";");

-----------------------
Add this
-----------------------

$usercount++;

-----------------------
After this:
-----------------------

if ($browsers) {

-----------------------
Add this:
-----------------------

$s = 's';
if (intval($usercount) < 1) {
$usercount = 0;
}
if (intval($usercount) == 1) {
$s = '';
}

-----------------------
In the "showthread_browsing" template:
-----------------------
Replace the contents with this:
-----------------------

<br>(<b>$usercount</b> User$s Browsing this Thread: $browsers)

Chris M
09-01-2002, 09:45 AM
Thanks:)

Satan

Barret
09-04-2002, 03:40 PM
But how to get it to show on index.php?