function _author_pane_is_user_online in Author Pane 7.2
Help function for Author Pane to check if a user is online.
Parameters
int $uid: A user id of the user to check if is online.
Return value
TRUE if the user is onlie, else FALSE.
1 call to _author_pane_is_user_online()
- template_preprocess_author_pane in ./
author_pane.module - Process variables for author-pane.tpl.php.
File
- ./
author_pane.module, line 398 - Gathers information from user related modules into one template.
Code
function _author_pane_is_user_online($uid) {
global $user;
// Use a static to save database calls,
// if this function is called for the same user more then once.
$static =& drupal_static(__FUNCTION__);
if (isset($static[$uid])) {
return $static[$uid];
}
// If current users is not anonymous and is watching its own author pane then the user is online.
if ($user->uid != 0 && $user->uid == $uid) {
return $static[$uid] = TRUE;
}
// How long back to check if the user has been active.
$time = REQUEST_TIME - variable_get('user_block_seconds_online', 900);
// Check if the user has a session active and that it has been used for the last $time ago.
if (db_query("SELECT 1 FROM {sessions} WHERE uid = :uid and timestamp > :time", array(
':uid' => $uid,
':time' => $time,
))
->fetchField()) {
return $static[$uid] = TRUE;
}
return $static[$uid] = FALSE;
}