function _drupalchat_buddylist_online in DrupalChat 6.2
Same name and namespace in other branches
- 6 drupalchat.module \_drupalchat_buddylist_online()
- 7.2 drupalchat.module \_drupalchat_buddylist_online()
- 7 drupalchat.module \_drupalchat_buddylist_online()
2 calls to _drupalchat_buddylist_online()
- drupalchat_poll in ./
drupalchat.module - Process and get messages
- _drupalchat_chat in ./
drupalchat.module
File
- ./
drupalchat.module, line 715 - Module code for DrupalChat.
Code
function _drupalchat_buddylist_online($buddylist) {
global $user;
$users = array();
if (variable_get('drupalchat_enable_chatroom', 1) == 1) {
$users['c-0'] = array(
'name' => t('Public Chatroom'),
'status' => '1',
);
}
if (variable_get('drupalchat_rel', DRUPALCHAT_REL_AUTH) > DRUPALCHAT_REL_AUTH) {
// Return empty on an empty buddylist
if (empty($buddylist)) {
$users['total'] = 0;
return $users;
}
foreach ($buddylist as $uid) {
$where[] = 'uid = %d';
$args[] = $uid;
}
$result = db_query('SELECT uid, name, status FROM {drupalchat_users} WHERE timestamp >= ' . (time() - variable_get('drupalchat_user_latency', 2)) . ' AND (' . implode(' OR ', $where) . ') ORDER BY status, name', $args);
}
else {
if ($user->uid > 0) {
$result = db_query('SELECT uid, name, status, session
FROM {drupalchat_users}
WHERE timestamp >= %d
AND uid <> %d
ORDER BY status, name', time() - variable_get('drupalchat_user_latency', 2), $user->uid);
}
else {
$result = db_query('SELECT uid, name, status, session
FROM {drupalchat_users}
WHERE timestamp >= %d
AND session <> \'%s\'
ORDER BY status, name', time() - variable_get('drupalchat_user_latency', 2), _drupalchat_get_sid());
}
}
while ($buddy = db_fetch_object($result)) {
if ($buddy->uid > 0) {
$users[$buddy->uid] = array(
'name' => check_plain($buddy->name),
'status' => $buddy->status,
);
}
else {
$users[$buddy->uid . '-' . $buddy->session] = array(
'name' => check_plain($buddy->name),
'status' => $buddy->status,
);
}
}
$users['total'] = count($users);
if (variable_get('drupalchat_enable_chatroom', 1) == 1) {
$users['total']--;
}
return $users;
}