1<?php 2namespace Fisharebest\Webtrees\Module; 3 4/** 5 * webtrees: online genealogy 6 * Copyright (C) 2015 webtrees development team 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18use Fisharebest\Webtrees\Auth; 19use Fisharebest\Webtrees\Filter; 20use Fisharebest\Webtrees\Functions\Functions; 21use Fisharebest\Webtrees\I18N; 22use Fisharebest\Webtrees\Individual; 23use Fisharebest\Webtrees\Theme; 24use Fisharebest\Webtrees\User; 25 26/** 27 * Class LoggedInUsersModule 28 */ 29class LoggedInUsersModule extends AbstractModule implements ModuleBlockInterface { 30 /** {@inheritdoc} */ 31 public function getTitle() { 32 return /* I18N: Name of a module. (A list of users who are online now) */ I18N::translate('Who is online'); 33 } 34 35 /** {@inheritdoc} */ 36 public function getDescription() { 37 return /* I18N: Description of the “Who is online” module */ I18N::translate('A list of users and visitors who are currently online.'); 38 } 39 40 /** {@inheritdoc} */ 41 public function getBlock($block_id, $template = true, $cfg = null) { 42 global $WT_TREE; 43 44 $id = $this->getName() . $block_id; 45 $class = $this->getName() . '_block'; 46 $title = $this->getTitle(); 47 $anonymous = 0; 48 $logged_in = array(); 49 $content = ''; 50 foreach (User::allLoggedIn() as $user) { 51 if (Auth::isAdmin() || $user->getPreference('visibleonline')) { 52 $logged_in[] = $user; 53 } else { 54 $anonymous++; 55 } 56 } 57 $count_logged_in = count($logged_in); 58 $content .= '<div class="logged_in_count">'; 59 if ($anonymous) { 60 $content .= I18N::plural('%s anonymous logged-in user', '%s anonymous logged-in users', $anonymous, I18N::number($anonymous)); 61 if ($count_logged_in) { 62 $content .= ' | '; 63 } 64 } 65 if ($count_logged_in) { 66 $content .= I18N::plural('%s logged-in user', '%s logged-in users', $count_logged_in, I18N::number($count_logged_in)); 67 } 68 $content .= '</div>'; 69 $content .= '<div class="logged_in_list">'; 70 if (Auth::check()) { 71 foreach ($logged_in as $user) { 72 $individual = Individual::getInstance($WT_TREE->getUserPreference($user, 'gedcomid'), $WT_TREE); 73 74 $content .= '<div class="logged_in_name">'; 75 if ($individual) { 76 $content .= '<a href="' . $individual->getHtmlUrl() . '">' . $user->getRealNameHtml() . '</a>'; 77 } else { 78 $content .= $user->getRealNameHtml(); 79 } 80 $content .= ' - ' . Filter::escapeHtml($user->getUserName()); 81 if (Auth::id() != $user->getUserId() && $user->getPreference('contactmethod') != 'none') { 82 $content .= ' <a class="icon-email" href="#" onclick="return message(\'' . Filter::escapeHtml($user->getUserName()) . '\', \'\', \'' . Filter::escapeHtml(Functions::getQueryUrl()) . '\');" title="' . I18N::translate('Send a message') . '"></a>'; 83 } 84 $content .= '</div>'; 85 } 86 } 87 $content .= '</div>'; 88 89 if ($anonymous === 0 && $count_logged_in === 0) { 90 return ''; 91 } 92 93 if ($template) { 94 return Theme::theme()->formatBlock($id, $title, $class, $content); 95 } else { 96 return $content; 97 } 98 } 99 100 /** {@inheritdoc} */ 101 public function loadAjax() { 102 return false; 103 } 104 105 /** {@inheritdoc} */ 106 public function isUserBlock() { 107 return true; 108 } 109 110 /** {@inheritdoc} */ 111 public function isGedcomBlock() { 112 return true; 113 } 114 115 /** {@inheritdoc} */ 116 public function configureBlock($block_id) { 117 } 118} 119