/** * Generate the HTML content of this block. * * @param int $block_id * @param bool $template * @param string[] $cfg * * @return string */ public function getBlock($block_id, $template = true, $cfg = array()) { global $WT_TREE; $id = $this->getName() . $block_id; $class = $this->getName() . '_block'; $title = $this->getTitle(); $anonymous = 0; $logged_in = array(); $content = ''; foreach (User::allLoggedIn() as $user) { if (Auth::isAdmin() || $user->getPreference('visibleonline')) { $logged_in[] = $user; } else { $anonymous++; } } $count_logged_in = count($logged_in); $content .= '<div class="logged_in_count">'; if ($anonymous) { $content .= I18N::plural('%s anonymous signed-in user', '%s anonymous signed-in users', $anonymous, I18N::number($anonymous)); if ($count_logged_in) { $content .= ' | '; } } if ($count_logged_in) { $content .= I18N::plural('%s signed-in user', '%s signed-in users', $count_logged_in, I18N::number($count_logged_in)); } $content .= '</div>'; $content .= '<div class="logged_in_list">'; if (Auth::check()) { foreach ($logged_in as $user) { $individual = Individual::getInstance($WT_TREE->getUserPreference($user, 'gedcomid'), $WT_TREE); $content .= '<div class="logged_in_name">'; if ($individual) { $content .= '<a href="' . $individual->getHtmlUrl() . '">' . $user->getRealNameHtml() . '</a>'; } else { $content .= $user->getRealNameHtml(); } $content .= ' - ' . Filter::escapeHtml($user->getUserName()); if (Auth::id() != $user->getUserId() && $user->getPreference('contactmethod') != 'none') { $content .= ' <a class="icon-email" href="#" onclick="return message(\'' . Filter::escapeHtml($user->getUserName()) . '\', \'\', \'' . Filter::escapeHtml(Functions::getQueryUrl()) . '\');" title="' . I18N::translate('Send a message') . '"></a>'; } $content .= '</div>'; } } $content .= '</div>'; if ($anonymous === 0 && $count_logged_in === 0) { return ''; } if ($template) { return Theme::theme()->formatBlock($id, $title, $class, $content); } else { return $content; } }
/** * NUmber of users who are currently logged in? * * @param string $type * * @return int */ private function usersLoggedInTotalQuery($type = 'all') { $anon = 0; $visible = 0; foreach (User::allLoggedIn() as $user) { if (Auth::isAdmin() || $user->getPreference('visibleonline')) { $visible++; } else { $anon++; } } if ($type == 'anon') { return $anon; } elseif ($type == 'visible') { return $visible; } else { return $visible + $anon; } }