Commit 3ff51ecd authored by Nigel McNie's avatar Nigel McNie
Browse files

[sfd08] Online users sideblock, using lastaccess flag.

The length of time since last access that tells whether a user has been online recently is configurable.

The block can also be disabled with a configuration parameter.
parent e79ac4ff
......@@ -145,4 +145,12 @@ $cfg->unzipdirarg = '-d';
// Setting it to zero means the access time will be updated every request
$cfg->accesstimeupdatefrequency = 300;
// How long since their last request before a user is considered to be logged
// out. Note that it makes no sense for this to be less than the
// accesstimeupdatefrequency.
$cfg->accessidletimeout = 600;
// Whether to show the onlineusers sideblock
$cfg->showonlineuserssideblock = true;
?>
......@@ -95,6 +95,10 @@ $string['pendingfriends'] = 'pending friends';
$string['profile'] = 'profile';
$string['views'] = 'Views';
// Online users sideblock strings
$string['onlineusers'] = 'Online users';
$string['lastminutes'] = 'Last %s minutes';
// Links and resources sideblock
$string['linksandresources'] = 'Links and Resources';
......
......@@ -1775,6 +1775,44 @@ function profile_sideblock() {
return $data;
}
/**
* Gets data about users who have been online in the last while.
*
* The time is configured by setting the 'accessidletimeout' configuration
* option.
*
* NOTE: currently returns all online users, this might not be desirable on a
* really busy site.
*/
function onlineusers_sideblock() {
global $USER;
$onlineusers = get_records_select_array('usr', 'lastaccess > ?',
array(db_format_timestamp(time() - get_config('accessidletimeout'))), 'lastaccess DESC');
foreach ($onlineusers as &$user) {
// Use 'profileiconbyid' for the current user, just in case they change their profile icon
if ($user->id == $USER->get('id')) {
$user->profileiconurl = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . (int)$user->profileicon . '&size=20x20';
}
else {
$user->profileiconurl = get_config('wwwroot') . 'thumb.php?type=profileicon&id=' . $user->id . '&size=20x20';
}
// If the user is an MNET user, show where they've come from
$authobj = AuthFactory::create($user->authinstance);
if ($authobj->authname == 'xmlrpc') {
$peer = get_peer($authobj->wwwroot);
$user->loggedinfrom = $peer->name;
}
}
return array(
'users' => $onlineusers,
'count' => count($onlineusers),
'lastminutes' => floor(get_config('accessidletimeout') / 60),
);
}
/**
* Cronjob to recalculate how much quota each user is using and update it as
* appropriate.
......
......@@ -409,6 +409,13 @@ EOF;
'weight' => -20,
'data' => profile_sideblock()
);
if (get_config('showonlineuserssideblock')) {
$SIDEBLOCKS[] = array(
'name' => 'onlineusers',
'weight' => -10,
'data' => onlineusers_sideblock(),
);
}
}
if(defined('GROUP')) {
......
......@@ -787,6 +787,15 @@ div.sidebar ul.sidebar-ul-title ul a {
text-align: center;
font-weight: bold;
}
/* Online users sideblock */
ul#onlineusers {
list-style-type: none;
}
#lastminutes {
float: right;
margin-top: 2px;
}
/* Side Quota Bar */
#quota_message {
text-align: center;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment