Beispiel #1
0
 function content($instance)
 {
     $out = '';
     switch ($instance['type']) {
         case 'users_online':
             $out .= html('div id="useronline-count"', get_users_online());
             break;
         case 'users_browsing_page':
             $out .= html('div id="useronline-browsing-page"', get_users_browsing_page());
             break;
         case 'users_browsing_site':
             $out .= html('div id="useronline-browsing-site"', get_users_browsing_site());
             break;
         case 'users_online_browsing_page':
             $out .= html('div id="useronline-count"', get_users_online());
             $out .= html('div id="useronline-browsing-page"', get_users_browsing_page());
             break;
         case 'users_online_browsing_site':
             $out .= html('div id="useronline-count"', get_users_online());
             $out .= html('div id="useronline-browsing-site"', get_users_browsing_site());
             break;
     }
     echo $out;
 }
function users_online()
{
    echo get_users_online();
}
Beispiel #3
0
 /**
  * return the online status of the passed user, one of three possible
  * states is returned:
  *  - available
  *  - away
  *  - offline
  * 
  * @staticvar type $online_status
  * 
  * @param string $user_id
  * 
  * @return string
  */
 static function getOnlineStatus($user_id)
 {
     static $online_status;
     // check if the corresponding user's profile is visible
     if (get_visibility_by_id($user_id) == false) {
         return 'offline';
     }
     if ($GLOBALS['user']->id == $user_id) {
         return 'available';
     }
     if (!$online_status) {
         $online_users = get_users_online(10);
         foreach ($online_users as $username => $data) {
             if ($data['last_action'] >= 300) {
                 $online_status[$data['user_id']] = 'away';
             } else {
                 $online_status[$data['user_id']] = 'available';
             }
         }
     }
     return $online_status[$user_id] ?: 'offline';
 }
Beispiel #4
0
 /**
  * Creates a list of online users - optionally including the according
  * contact groups.
  * The created list is an array with four elemens:
  * - "total" is the _number_ of all currently online users.
  * - "buddies" is an _array_ containing the data of all the user's buddies
  *   that are currently online.
  * - "users" is an _array_ containing the data of all users that are
  *   currently online and are not a buddy of the current user and are
  *   either globally visible or visible in the current user's domains.
  * - "others" is the number of all other and accordingly invisible users.
  *
  * @param bool $show_buddy_groups Defines whether the list of buddies
  *                                should include the according contact
  *                                groups or not
  * @return Array List of online users as an array (see above)
  */
 private function getOnlineUsers($show_buddy_groups = false)
 {
     $temp = get_users_online(10, $GLOBALS['user']->cfg->ONLINE_NAME_FORMAT);
     $total = count($temp);
     // Filter invisible users
     $visible = array();
     $my_domains = UserDomain::getUserDomainsForUser($GLOBALS['user']->id);
     foreach ($temp as $username => $user) {
         if ($user['is_visible']) {
             continue;
         }
         $global_visibility = get_global_visibility_by_id($user['user_id']);
         $domains = UserDomain::getUserDomainsForUser($user['user_id']);
         $same_domains = array_intersect($domains, $my_domains);
         if ($global_visibility !== 'yes' || !count($same_domains)) {
             unset($temp[$username]);
         }
     }
     // Split list into buddies and other users
     $buddies = array_filter($temp, function ($user) {
         return $user['is_buddy'];
     });
     $users = array_filter($temp, function ($user) {
         return !$user['is_buddy'];
     });
     if ($show_buddy_groups) {
         // Add groups to buddies
         $buddy_ids = array_map(function ($user) {
             return $user['user_id'];
         }, $buddies);
         $name_format = $GLOBALS['user']->cfg->ONLINE_NAME_FORMAT;
         if (!isset($GLOBALS['_fullname_sql'][$name_format])) {
             $name_format = reset(array_keys($GLOBALS['_fullname_sql']));
         }
         $query = "SELECT user_id, statusgruppen.position, name, statusgruppen.statusgruppe_id\n                      FROM statusgruppen\n                        JOIN statusgruppe_user USING (statusgruppe_id)\n                        JOIN auth_user_md5 USING (user_id)\n                      WHERE range_id = :user_id AND user_id IN (:buddy_ids)\n                      ORDER BY statusgruppen.position ASC";
         $statement = DBManager::get()->prepare($query);
         $statement->bindValue(':user_id', $GLOBALS['user']->id);
         $statement->bindValue(':buddy_ids', $buddy_ids ?: array(''), StudipPDO::PARAM_ARRAY);
         $statement->execute();
         $grouped = $statement->fetchGrouped();
         foreach ($buddies as $username => $buddy) {
             if (isset($grouped[$buddy['user_id']])) {
                 $group = $grouped[$buddy['user_id']];
                 $buddies[$username]['group'] = $group['name'];
                 $buddies[$username]['group_id'] = $group['statusgruppe_id'];
                 $buddies[$username]['group_position'] = $group['position'];
             } else {
                 $buddies[$username]['group'] = _('Kontakte ohne Gruppenzuordnung');
                 $buddies[$username]['group_id'] = 'all';
                 $buddies[$username]['group_position'] = 100000;
             }
         }
         usort($buddies, function ($a, $b) {
             return $a['group_position'] - $b['group_position'] ?: strcmp($a['name'], $b['name']);
         });
     }
     $others = $total - count($buddies) - count($users);
     return compact('buddies', 'users', 'total', 'others');
 }