Log in

View Full Version : How to show active users of the page other than forumhome, forumdisplay, showthread


SpyCam
11-30-2009, 01:39 PM
Hello,
i'm trying to get a page to show $activeusers content on a page.
Actually it's a Cyb ChatBox for Vb 3.8.4 but it is not supported so i thought it should be simple for me to do that on my own but i failed.

What i tried is i copied the part of code from my SHOWTHREAD template to the chat template. This is the code:

<if condition="$show['activeusers']">
<!-- currently active users -->
<div class="div-header">
<div class="div-header-right" style="float:right"></div>
<div class="div-header-left"></div>
<phrase 1="$totalonline" 2="$numberregistered" 3="$numberguest">$vbphrase[users_viewing_this_thread_x_y_z]</phrase>
</div>
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="alt1" colspan="2"><span class="smallfont">$activeusers</span></td>
</tr>
</table>
<!-- end currently active users -->
</if>
<if condition="$show['activeusers']">$template_hook[showthread_after_activeusers]<br />
</if>


But it didn't work. I'm affraid it's because the page showing the chat actually looks like this in browser's address bar: misc.php?do=cchatbox

Do you have any idea how to show what forum members are currently active on that page? Because on a chat, it's lame to have no list of active users...

Thanks in advance

kh99
11-30-2009, 01:53 PM
The problem is that the template gets it's information from variables which must be set in the php code for the page you're displaying. If you look at showthread.php and search for each occurance of 'activeusers' you'll see that there is quite a bit of code involved in building up the $activeusers variable before it's used in the template (although some of it might be doing other things as well).

SpyCam
11-30-2009, 04:05 PM
I'm not a PHP programmer, but i usually don't have big problems to make small php alterations, at least for vbulleting templates, i inspected the source of the showthread template but didn't really find any other "hooks" of code needed for $activeusers to be displayed.

Could you give me some hints of what to look for in it?

Thanks in advance

kh99
11-30-2009, 04:26 PM
Well, if you search in showthread.php for:

if ($vbulletin->userinfo['userid']) // fakes the user being in this thread


I think this is start of the part that adds the current user. A little below that is:

eval('$activeusers = "' . fetch_template('forumdisplay_loggedinuser') . '";');

So that starts creating the value of $activeusers by adding the current user (which I guess is why you always show up first on the list).

Then below that is a loop which starts:

while ($loggedin = $db->fetch_array($threadusers))


That looks like the part that adds all the other active users, one at a time. A little below that is:

eval('$activeusers .= "' . fetch_template('forumdisplay_loggedinuser') . '";');


The ".=" appends to the string, so that line adds one more user.

Since you are using misc.php whihc doesn't have this code, $activeusers (which appears in the part of the template you borrowed from SHOWTHREAD) will be blank.

So, you could try copying the block of code between these comments:

// ************************************************** *******************************
// Get users browsing this thread
.
.
.
// ************************************************** *******************************
// get similar threads

But I don't know, it might not turn out to be that easy. The thing I'm wondering about is that the comment says "Get users browsing this thread". I haven't studied the code, but if that comment is accurate, it could mean that it won't do exactly what you want.

ETA: ...also, there may be important things that happen in the code before the block I mentioned above, in which case you may need to copy more that just that block.

SpyCam
11-30-2009, 05:34 PM
Thank you. I didn't think at all about that i should edit PHP file. I tried the things you suggested but it didn't work, so now i'm trying different things to find a working solution.

kh99
11-30-2009, 05:48 PM
Yeah, I was kind of afraid that it wouldn't work. I don't know anything about that mod, so I don't know if the code for "users viewing a thread" has anything to do with the code that would be needed for "users currently chatting".

BTW, as far as editing php files, if you have to add code it's better to find a hook and insert the code as plugin, if possible. So if you figure out what code to add to create your list, you might be able to find a hook someplace in misc.php (or in some included file like global.php or init.php) and make it a plugin.

SpyCam
11-30-2009, 06:18 PM
Well, after like 10 tries, i gave up. I don't have brains of a programmer to find the answer :(