PDA

View Full Version : Currently Active Users widget ?


bart6767
12-16-2009, 01:52 PM
I have added a Currently Active Users widget ? to my CMS and it shows up fine but does anyone know how to make it update and refresh ?

Look at the photo below .

And does anyone know how to do this with PHP ? rather than static HTML

This is the code i used .

<!-- logged-in users -->
<div id="wgo_onlineusers" class="wgo_subblock">
<h3><img src="images/misc/users_online.png" alt="Currently Active Users" />Currently Active Users</h3>
<div>
<p>There are currently <a href="online.php">8 users online</a>. <span class="shade">4 members and 4 guests</span></p>
<p>Most users ever online was 37, 11-29-2009 at <span class="time">02:54 PM</span>.</p>
<ol class="commalist" id="wgo_onlineusers_list">
<b> <font color="red">• Administrators</font> <font color="666600">• Super Moderators</font> • Moderators • Registered Users </b><br /><br /> <li> <a class="username" href="member.php?1-The-Voice-of-champions"> <font color="red">The Voice of champions</font></a></li> <li> <a class="username" href="member.php?49-BIG-SOOTY">BIG SOOTY</a></li> <li> <a class="username" href="member.php?23-Mark-Ryan">Mark Ryan</a>+</li> <li> <a class="username" href="member.php?19-tak1888"><font color="666600">tak1888</font></a>+</li>
</ol>
</div>
</div>
<!-- end logged-in users -->

ZexTasy
12-16-2009, 06:30 PM
That is no PHP code, just static HTML ... you need to use PHP code and queries to get the updated information.

bart6767
12-16-2009, 06:49 PM
That is no PHP code, just static HTML ... you need to use PHP code and queries to get the updated information.

I know that but i posted here to see if anyone knew how to do it ?

Lynne
12-16-2009, 10:13 PM
Have you tried copying the php code from the forum.php page?

Vaupell
12-16-2009, 10:38 PM
im thinking makeing a template, and then make the widget and register the template
and then print_output

just like a normal php page, but inside the widget instead..

bart6767
12-16-2009, 10:43 PM
Have you tried copying the php code from the forum.php page?

Might try that .

Do you know what the code is or the php code that im looking for ?

--------------- Added 1261011165 at 1261011165 ---------------

Ok i found this and i think this is the right code .

How would i go about adding this to the PHP Widget ? what is the output in the last line .

// ### 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, user.lastvisit,
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,
'lastvisit' =>& $vbulletin->userinfo['lastvisit'],
'usergroupid' =>& $vbulletin->userinfo['usergroupid'],
'displaygroupid' =>& $vbulletin->userinfo['displaygroupid'],
'infractiongroupid' =>& $vbulletin->userinfo['infractiongroupid'],
)
);
}
else
{
$userinfos = array();
}
$inforum = array();

while ($loggedin = $db->fetch_array($forumusers))
{
$userid = $loggedin['userid'];
if (!$userid)
{ // Guest
$numberguest++;
if (!isset($inforum["$loggedin[inforum]"]))
{
$inforum["$loggedin[inforum]"] = 0;
}
if (!$loggedin['badlocation'])
{
$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'] AND !$loggedin['badlocation'])
{
if (!isset($inforum["$loggedin[inforum]"]))
{
$inforum["$loggedin[inforum]"] = 0;
}
$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 != '');
$templater = vB_Template::create('forumhome_loggedinuser');
$templater->register('loggedin', $loggedin);
$activeusers .= $templater->render();
}
}

// 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;
}

// ### GET FORUMS & MODERATOR iCACHES ########################
cache_ordered_forums(1, 1);
if ($vbulletin->options['showmoderatorcolumn'])
{
cache_moderators();
}
else if ($vbulletin->userinfo['userid'])
{
cache_moderators($vbulletin->userinfo['userid']);
}

// define max depth for forums display based on $vbulletin->options[forumhomedepth]
define('MAXFORUMDEPTH', $vbulletin->options['forumhomedepth']);

$forumbits = construct_forum_bit($forumid);
$forumhome_markread_script = vB_Template::create('forumhome_markread_script')->render();

Lynne
12-16-2009, 10:53 PM
Might try that .

Do you know what the code is or the php code that im looking for ?
Did you try looking at the file before asking? It's pretty well commented with LOGGED IN USERS in big capital letters to tell you where the code is. :)

bart6767
12-16-2009, 10:58 PM
Did you try looking at the file before asking? It's pretty well commented with LOGGED IN USERS in big capital letters to tell you where the code is. :)

lol found it before you posted :D

And what should the full code be to add it to the widget so i can try it .

I posted it in post 6 but not sure what the last line should be with the output .

Lynne
12-16-2009, 11:06 PM
You'll have to try things out and see what you need. The php code is in the forum.php file and the template code needed to output it is probably in the FORUMHOME template. If it isn't in there, then do this to find the template - vboptions > General Settings > Add Template Name in HTML Comments > set to Yes . Then go back to your page and view the source code and you will see the name of the template called around your part of the code.

That should give you plenty of information to go try this out on your test site and get it working.

bart6767
12-16-2009, 11:29 PM
You'll have to try things out and see what you need. The php code is in the forum.php file and the template code needed to output it is probably in the FORUMHOME template. If it isn't in there, then do this to find the template - vboptions > General Settings > Add Template Name in HTML Comments > set to Yes . Then go back to your page and view the source code and you will see the name of the template called around your part of the code.

That should give you plenty of information to go try this out on your test site and get it working.

Thanks i will try that and see what happens .:up:

Charlie98902
12-17-2009, 12:25 AM
Dang Bart thought you hit the jackpot till Lynne replied :D

Awaiting to hear how to do this or give the wiget to others in the mod section.

bart6767
12-17-2009, 12:29 AM
Dang Bart thought you hit the jackpot till Lynne replied :D

Awaiting to hear how to do this or give the wiget to others in the mod section.

Lol someone will get it to work :D

Charlie98902
12-17-2009, 01:10 AM
Lol someone will get it to work :D

We nominated you to be "The One" :D

bart6767
12-17-2009, 01:26 AM
We nominated you to be "The One" :D

no luck here :(

Lynne
12-17-2009, 02:49 AM
Did anybody try it? It really is just that code with a couple of tweaks - must include functions_bigthread and also make $vbulletin and $db global. It gets spit out as a list on my site now cuz I didn't do anything css-wise, but it works.

Vaupell
12-17-2009, 06:10 AM
welll tryed using the forum.php code
and then print_output a template with only one line
i took from the whats goin on box..


Php widget
$globaltemplates = array('EOnlinebox',
);


// ### 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, user.lastvisit,
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,
'lastvisit' =>& $vbulletin->userinfo['lastvisit'],
'usergroupid' =>& $vbulletin->userinfo['usergroupid'],
'displaygroupid' =>& $vbulletin->userinfo['displaygroupid'],
'infractiongroupid' =>& $vbulletin->userinfo['infractiongroupid'],
)
);
}
else
{
$userinfos = array();
}
$inforum = array();

while ($loggedin = $db->fetch_array($forumusers))
{
$userid = $loggedin['userid'];
if (!$userid)
{ // Guest
$numberguest++;
if (!isset($inforum["$loggedin[inforum]"]))
{
$inforum["$loggedin[inforum]"] = 0;
}
if (!$loggedin['badlocation'])
{
$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'] AND !$loggedin['badlocation'])
{
if (!isset($inforum["$loggedin[inforum]"]))
{
$inforum["$loggedin[inforum]"] = 0;
}
$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 != '');
$templater = vB_Template::create('forumhome_loggedinuser');
$templater->register('loggedin', $loggedin);
$activeusers .= $templater->render();
}
}

// 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;
}

$templater = vB_Template::create('EOnlinebox");
$templater->register_page_templates();
$templater->register('EOnlinebox', $totalonline);
print_output($templater->render());




yeah its a mess, and needs cleanup, lots of wasted features, but just took the code from forum.php
figureing makeing that work, it would be better to clean up later.




Template : [EOnlinebox]

<!-- logged-in users -->
{vb:rawphrase there_are_x_online, {vb:raw totalonline}} {vb:rawphrase x_members_and_y_guests, {vb:raw numberregistered}, {vb:raw numberguest}}
<!-- end logged-in users -->

tryed a few things out, and resultet in some different things

- cleared entire cms page and only wrote the online line
- added errors ontop of the cms page where the widget is placed
- result in db errors

so kinda clueless to makeing it work in a widget,
and cant find any php widgets to download and see how they work as a eksample..

ragtek
12-17-2009, 06:47 AM
Did anybody try it? It really is just that code with a couple of tweaks - must include functions_bigthread and also make $vbulletin and $db global. It gets spit out as a list on my site now cuz I didn't do anything css-wise, but it works.

$vbulletin and $db global? aeeeeeehm pls not;) use vB::$db-> and vB::$vbulletin-> in widgets ;)

bart6767
12-17-2009, 07:23 AM
Did anybody try it? It really is just that code with a couple of tweaks - must include functions_bigthread and also make $vbulletin and $db global. It gets spit out as a list on my site now cuz I didn't do anything css-wise, but it works.

I tryed a few things with no luck .

Can you post the code you used that worked for you ? so i can test it .

Lynne
12-17-2009, 03:48 PM
$vbulletin and $db global? aeeeeeehm pls not;) use vB::$db-> and vB::$vbulletin-> in widgets ;)
Thanks. I was just doing it real quick to see that it would work before actually doing it correctly. :)
I tryed a few things with no luck .

Can you post the code you used that worked for you ? so i can test it .
I'll try to put it together (need to put together an install text file) and post it in the widget mods area if no one else does sooner.

ragtek
12-17-2009, 04:08 PM
I'll try to put it together (need to put together an install text file) and post it in the widget mods area if no one else does sooner.

yea, sounds nice:)

bart6767
12-17-2009, 04:15 PM
Thanks. I was just doing it real quick to see that it would work before actually doing it correctly. :)

I'll try to put it together (need to put together an install text file) and post it in the widget mods area if no one else does sooner.

Thanks Lynne .

Lynne
12-17-2009, 11:43 PM
I put this up here - Widget - Users Online (https://vborg.vbsupport.ru/showthread.php?t=230428)

bart6767
12-18-2009, 08:01 AM
I put this up here - Widget - Users Online (https://vborg.vbsupport.ru/showthread.php?t=230428)

Nice one :D

cory_booth
01-02-2010, 03:13 PM
Lynne and others...

Any plans on taking this to also incorporate Upcoming Events / Forum Statistics?

I have two widgets I scrapped together that do it, but I'd like to know if anyone is working on these as well....