function buddylist_buddylisting_page($uid = NULL, $mode = 'buddies') { global $user; if (empty($uid)) { $uid = $user->uid; } // Check that the uid is valid, not the anonymous user, and the user exists if (!(is_numeric($uid) && ($uid > 0) && $thisuser = user_load(array('uid' => $uid)))) { drupal_not_found(); exit(); } $viewing_own_account = ($user->uid == $uid); if (user_access('maintain buddy list') && $viewing_own_account) { buddylist_setmsg_received($thisuser); } $buddies_per_page = 20; if ($mode == 'buddies') { $sql = "SELECT DISTINCT(b.buddy), u.access FROM {buddylist} b INNER JOIN {users} u ON b.buddy = u.uid WHERE b.uid = %d ORDER BY u.access DESC"; } else { $sql = "SELECT DISTINCT(u.uid) as buddy, u.access FROM {buddylist} b INNER JOIN {users} u ON b.uid = u.uid WHERE b.buddy = %d ORDER BY u.access DESC"; } $result = pager_query($sql, $buddies_per_page, 0 , NULL, $uid); $online_interval = time() - variable_get('user_block_seconds_online', 180); $buddies = array(); while ($account = db_fetch_object($result)) { $online = $account->access > $online_interval; $buddy = user_load(array('uid' => $account->buddy)); $buddy->online = $online; $buddies[] = $buddy; } return theme('buddylisting', $thisuser, $buddies); } function theme_buddylisting($account, $buddies, $buddies_per_page) { drupal_set_title(t('%username\'s @buddylist', array('%username' => $account->name) + buddylist_translation())); $header = array(t('@buddy', buddylist_translation()), t('online')); if (count($buddies)) { foreach ($buddies as $account) { $rows[] = array(theme('username', $account), theme('buddylist_online', $account->online)); } $output .= theme('table', $header, $rows); } else { $output .= variable_get('buddylist_empty_text', t(buddylist_empty_text_default(), buddylist_translation())); } $output .= theme('pager', NULL, $buddies_per_page); return $output; }