/** * Displays the privacy settings of a user. */ public function index_action() { // Get visibility settings from database. $this->global_visibility = get_global_visibility_by_id($this->user->user_id); $this->online_visibility = get_local_visibility_by_id($this->user->user_id, 'online'); $this->search_visibility = get_local_visibility_by_id($this->user->user_id, 'search'); $this->email_visibility = get_local_visibility_by_id($this->user->user_id, 'email'); // Get default visibility for homepage elements. $this->default_homepage_visibility = Visibility::get_default_homepage_visibility(); $this->NOT_HIDEABLE_FIELDS = $GLOBALS['NOT_HIDEABLE_FIELDS']; $this->user_perm = $GLOBALS['perm']->get_perm($this->user->user_id); $this->user_domains = UserDomain::getUserDomains(); // Calculate colWidth and colCount for different visibilities $this->colCount = Visibility::getColCount(); $this->colWidth = 67 / $this->colCount; $this->visibilities = Visibility::getVisibilities(); $this->homepage_elements = Visibility::getHTMLArgs(); }
/** * Gets the global visibility for a given username. This is just a wrapper * function for <code>get_global_visibility_by_id</code>, operating with a * usename instead of an ID. * * @param string $username username to check * @return string User visibility as returned by * <code>get_global_visibility_by_id</code>. */ function get_global_visibility_by_username($username) { return get_global_visibility_by_id(get_userid($username)); }
/** * 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'); }