This script requires VTS to be installed. The replacement tag uses the VTS database tables to get the number of users currently online. There are probably other ways to do this, but this is the way I'm doing it...
Put the following code in frontend_render:
Code: Select all
<?php
// AUTHOR: Jens Zetterström
// USAGE: {VTS_USERS_ONLINE}
// Define how long the maximum amount of time (in minutes) the session can be inactive.
define("MAX_IDLE_TIME", 3);
// get users online by looking at vts database tables
function vts_GetUsersOnline()
{
$count = 0;
$sql = sprintf(
"SELECT COUNT(DISTINCT(accesslog.accesslog_id)) AS num_visitors_online
FROM %s accesslog,
%s visitors
WHERE visitors.client_id = '%d'
AND visitors.accesslog_id = accesslog.accesslog_id
AND accesslog.timestamp >= '%d'",
DB_PREPEND . "pot_accesslog",
DB_PREPEND . "pot_visitors",
1,
time() - (MAX_IDLE_TIME * 60)
);
$result = mysql_query($sql, $GLOBALS["db"]);
if(mysql_num_rows($result) > 0)
{
$row = mysql_fetch_assoc($result);
$count = intval($row['num_visitors_online']);
}
if($count == 0)
{
$count = 1;
}
return $count;
}
// {VTS_USERS_ONLINE}
// most article sorted by popularity
if( ! ( strpos($content["all"],'{VTS_USERS_ONLINE}')===false ) )
{
$content["all"] = preg_replace('/\{VTS_USERS_ONLINE\}/e','vts_GetUsersOnline();', $content["all"]);
}
?>
Jens