

//This plugin that checks the database to see how many users are logged in and sets a placeholder that the site's template refers to to display the number of users who are currently viewing the site
$storetime = 0;
if(!isset($timestamp)) {
$timestamp=time();
}
$storetime = $timestamp+$modx->config['server_offset_time'];
//select the modx table to use
$table = $modx->getFullTableName("active_users");
//variable to store the number of users who are logged on
$loggedIn = 0;
//iterate through the table and see whish users are logged on. Increment the number of users that are logged in if they are logged in
$result = $modx->db->select("*", $table);
//while there are still more rows in the table check to see if the user is logged in
while($r = modx->db->getRow($result))
{
$user = $r["username"];
$hit = $r["lasthit"];
$tempTimeStore = 0;
//compare the timestamp of the last hit with the current timestamp and see if the last hit occured in the last 10 minutes. If it did not the user is not currently online
$tempTimeStore = $storetime - $hit;
//if the result is
if ($tempTimeStore <= 600)
{
//do not increment the number of users logged in
$loggedIn++;
}
}
//Set the placeholder to display the number of users who are logged in
$modx->setPlaceholder('UsersOnline', "$loggedIn");return $loggedIn;
$modx->setPlaceholder('UsersOnline', "$loggedIn");