18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 4369c0ce6SGreg Roach * Copyright (C) 2016 webtrees development team 58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 88c2e8227SGreg Roach * (at your option) any later version. 98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128c2e8227SGreg Roach * GNU General Public License for more details. 138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 158c2e8227SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1776692c8bSGreg Roach 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter; 203d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\Functions; 210e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\Theme; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\User; 258c2e8227SGreg Roach 268c2e8227SGreg Roach/** 278c2e8227SGreg Roach * Class LoggedInUsersModule 288c2e8227SGreg Roach */ 29e2a378d3SGreg Roachclass LoggedInUsersModule extends AbstractModule implements ModuleBlockInterface { 308c2e8227SGreg Roach /** {@inheritdoc} */ 318c2e8227SGreg Roach public function getTitle() { 328c2e8227SGreg Roach return /* I18N: Name of a module. (A list of users who are online now) */ I18N::translate('Who is online'); 338c2e8227SGreg Roach } 348c2e8227SGreg Roach 358c2e8227SGreg Roach /** {@inheritdoc} */ 368c2e8227SGreg Roach public function getDescription() { 378c2e8227SGreg Roach return /* I18N: Description of the “Who is online” module */ I18N::translate('A list of users and visitors who are currently online.'); 388c2e8227SGreg Roach } 398c2e8227SGreg Roach 4076692c8bSGreg Roach /** 4176692c8bSGreg Roach * Generate the HTML content of this block. 4276692c8bSGreg Roach * 4376692c8bSGreg Roach * @param int $block_id 4476692c8bSGreg Roach * @param bool $template 45727f238cSGreg Roach * @param string[] $cfg 4676692c8bSGreg Roach * 4776692c8bSGreg Roach * @return string 4876692c8bSGreg Roach */ 49*13abd6f3SGreg Roach public function getBlock($block_id, $template = true, $cfg = []) { 50e3fb86dfSGreg Roach global $WT_TREE; 51e3fb86dfSGreg Roach 528c2e8227SGreg Roach $id = $this->getName() . $block_id; 538c2e8227SGreg Roach $class = $this->getName() . '_block'; 548c2e8227SGreg Roach $title = $this->getTitle(); 558c2e8227SGreg Roach $anonymous = 0; 56*13abd6f3SGreg Roach $logged_in = []; 578c2e8227SGreg Roach $content = ''; 588c2e8227SGreg Roach foreach (User::allLoggedIn() as $user) { 598c2e8227SGreg Roach if (Auth::isAdmin() || $user->getPreference('visibleonline')) { 608c2e8227SGreg Roach $logged_in[] = $user; 618c2e8227SGreg Roach } else { 628c2e8227SGreg Roach $anonymous++; 638c2e8227SGreg Roach } 648c2e8227SGreg Roach } 658c2e8227SGreg Roach $count_logged_in = count($logged_in); 668c2e8227SGreg Roach $content .= '<div class="logged_in_count">'; 678c2e8227SGreg Roach if ($anonymous) { 68cdc90107SGreg Roach $content .= I18N::plural('%s anonymous signed-in user', '%s anonymous signed-in users', $anonymous, I18N::number($anonymous)); 698c2e8227SGreg Roach if ($count_logged_in) { 708c2e8227SGreg Roach $content .= ' | '; 718c2e8227SGreg Roach } 728c2e8227SGreg Roach } 738c2e8227SGreg Roach if ($count_logged_in) { 74cdc90107SGreg Roach $content .= I18N::plural('%s signed-in user', '%s signed-in users', $count_logged_in, I18N::number($count_logged_in)); 758c2e8227SGreg Roach } 768c2e8227SGreg Roach $content .= '</div>'; 778c2e8227SGreg Roach $content .= '<div class="logged_in_list">'; 788c2e8227SGreg Roach if (Auth::check()) { 798c2e8227SGreg Roach foreach ($logged_in as $user) { 80e3fb86dfSGreg Roach $individual = Individual::getInstance($WT_TREE->getUserPreference($user, 'gedcomid'), $WT_TREE); 81e3fb86dfSGreg Roach 828c2e8227SGreg Roach $content .= '<div class="logged_in_name">'; 83e3fb86dfSGreg Roach if ($individual) { 84e3fb86dfSGreg Roach $content .= '<a href="' . $individual->getHtmlUrl() . '">' . $user->getRealNameHtml() . '</a>'; 85e3fb86dfSGreg Roach } else { 86e3fb86dfSGreg Roach $content .= $user->getRealNameHtml(); 87e3fb86dfSGreg Roach } 88e3fb86dfSGreg Roach $content .= ' - ' . Filter::escapeHtml($user->getUserName()); 898c2e8227SGreg Roach if (Auth::id() != $user->getUserId() && $user->getPreference('contactmethod') != 'none') { 903d7a8a4cSGreg Roach $content .= ' <a class="icon-email" href="#" onclick="return message(\'' . Filter::escapeHtml($user->getUserName()) . '\', \'\', \'' . Filter::escapeHtml(Functions::getQueryUrl()) . '\');" title="' . I18N::translate('Send a message') . '"></a>'; 918c2e8227SGreg Roach } 928c2e8227SGreg Roach $content .= '</div>'; 938c2e8227SGreg Roach } 948c2e8227SGreg Roach } 958c2e8227SGreg Roach $content .= '</div>'; 968c2e8227SGreg Roach 978c2e8227SGreg Roach if ($anonymous === 0 && $count_logged_in === 0) { 988c2e8227SGreg Roach return ''; 998c2e8227SGreg Roach } 1008c2e8227SGreg Roach 1018c2e8227SGreg Roach if ($template) { 1028c2e8227SGreg Roach return Theme::theme()->formatBlock($id, $title, $class, $content); 1038c2e8227SGreg Roach } else { 1048c2e8227SGreg Roach return $content; 1058c2e8227SGreg Roach } 1068c2e8227SGreg Roach } 1078c2e8227SGreg Roach 1088c2e8227SGreg Roach /** {@inheritdoc} */ 1098c2e8227SGreg Roach public function loadAjax() { 1108c2e8227SGreg Roach return false; 1118c2e8227SGreg Roach } 1128c2e8227SGreg Roach 1138c2e8227SGreg Roach /** {@inheritdoc} */ 1148c2e8227SGreg Roach public function isUserBlock() { 1158c2e8227SGreg Roach return true; 1168c2e8227SGreg Roach } 1178c2e8227SGreg Roach 1188c2e8227SGreg Roach /** {@inheritdoc} */ 1198c2e8227SGreg Roach public function isGedcomBlock() { 1208c2e8227SGreg Roach return true; 1218c2e8227SGreg Roach } 1228c2e8227SGreg Roach 12376692c8bSGreg Roach /** 12476692c8bSGreg Roach * An HTML form to edit block settings 12576692c8bSGreg Roach * 12676692c8bSGreg Roach * @param int $block_id 12776692c8bSGreg Roach */ 1288c2e8227SGreg Roach public function configureBlock($block_id) { 1298c2e8227SGreg Roach } 1308c2e8227SGreg Roach} 131