xref: /webtrees/app/Module/LoggedInUsersModule.php (revision 3d7a8a4ca809135634f38216b734b15acff479f7)
18c2e8227SGreg Roach<?php
20e62c4b8SGreg Roachnamespace Fisharebest\Webtrees\Module;
38c2e8227SGreg Roach
48c2e8227SGreg Roach/**
58c2e8227SGreg Roach * webtrees: online genealogy
68c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team
78c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
88c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
98c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
108c2e8227SGreg Roach * (at your option) any later version.
118c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
128c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
138c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148c2e8227SGreg Roach * GNU General Public License for more details.
158c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
168c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
178c2e8227SGreg Roach */
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter;
20*3d7a8a4cSGreg 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
408c2e8227SGreg Roach	/** {@inheritdoc} */
418c2e8227SGreg Roach	public function getBlock($block_id, $template = true, $cfg = null) {
42e3fb86dfSGreg Roach		global $WT_TREE;
43e3fb86dfSGreg Roach
448c2e8227SGreg Roach		$id        = $this->getName() . $block_id;
458c2e8227SGreg Roach		$class     = $this->getName() . '_block';
468c2e8227SGreg Roach		$title     = $this->getTitle();
478c2e8227SGreg Roach		$anonymous = 0;
488c2e8227SGreg Roach		$logged_in = array();
498c2e8227SGreg Roach		$content   = '';
508c2e8227SGreg Roach		foreach (User::allLoggedIn() as $user) {
518c2e8227SGreg Roach			if (Auth::isAdmin() || $user->getPreference('visibleonline')) {
528c2e8227SGreg Roach				$logged_in[] = $user;
538c2e8227SGreg Roach			} else {
548c2e8227SGreg Roach				$anonymous++;
558c2e8227SGreg Roach			}
568c2e8227SGreg Roach		}
578c2e8227SGreg Roach		$count_logged_in = count($logged_in);
588c2e8227SGreg Roach		$content .= '<div class="logged_in_count">';
598c2e8227SGreg Roach		if ($anonymous) {
60def7396fSGreg Roach			$content .= I18N::plural('%s anonymous logged-in user', '%s anonymous logged-in users', $anonymous, I18N::number($anonymous));
618c2e8227SGreg Roach			if ($count_logged_in) {
628c2e8227SGreg Roach				$content .= '&nbsp;|&nbsp;';
638c2e8227SGreg Roach			}
648c2e8227SGreg Roach		}
658c2e8227SGreg Roach		if ($count_logged_in) {
66def7396fSGreg Roach			$content .= I18N::plural('%s logged-in user', '%s logged-in users', $count_logged_in, I18N::number($count_logged_in));
678c2e8227SGreg Roach		}
688c2e8227SGreg Roach		$content .= '</div>';
698c2e8227SGreg Roach		$content .= '<div class="logged_in_list">';
708c2e8227SGreg Roach		if (Auth::check()) {
718c2e8227SGreg Roach			foreach ($logged_in as $user) {
72e3fb86dfSGreg Roach				$individual = Individual::getInstance($WT_TREE->getUserPreference($user, 'gedcomid'), $WT_TREE);
73e3fb86dfSGreg Roach
748c2e8227SGreg Roach				$content .= '<div class="logged_in_name">';
75e3fb86dfSGreg Roach				if ($individual) {
76e3fb86dfSGreg Roach					$content .= '<a href="' . $individual->getHtmlUrl() . '">' . $user->getRealNameHtml() . '</a>';
77e3fb86dfSGreg Roach				} else {
78e3fb86dfSGreg Roach					$content .= $user->getRealNameHtml();
79e3fb86dfSGreg Roach				}
80e3fb86dfSGreg Roach				$content .= ' - ' . Filter::escapeHtml($user->getUserName());
818c2e8227SGreg Roach				if (Auth::id() != $user->getUserId() && $user->getPreference('contactmethod') != 'none') {
82*3d7a8a4cSGreg 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>';
838c2e8227SGreg Roach				}
848c2e8227SGreg Roach				$content .= '</div>';
858c2e8227SGreg Roach			}
868c2e8227SGreg Roach		}
878c2e8227SGreg Roach		$content .= '</div>';
888c2e8227SGreg Roach
898c2e8227SGreg Roach		if ($anonymous === 0 && $count_logged_in === 0) {
908c2e8227SGreg Roach			return '';
918c2e8227SGreg Roach		}
928c2e8227SGreg Roach
938c2e8227SGreg Roach		if ($template) {
948c2e8227SGreg Roach			return Theme::theme()->formatBlock($id, $title, $class, $content);
958c2e8227SGreg Roach		} else {
968c2e8227SGreg Roach			return $content;
978c2e8227SGreg Roach		}
988c2e8227SGreg Roach	}
998c2e8227SGreg Roach
1008c2e8227SGreg Roach	/** {@inheritdoc} */
1018c2e8227SGreg Roach	public function loadAjax() {
1028c2e8227SGreg Roach		return false;
1038c2e8227SGreg Roach	}
1048c2e8227SGreg Roach
1058c2e8227SGreg Roach	/** {@inheritdoc} */
1068c2e8227SGreg Roach	public function isUserBlock() {
1078c2e8227SGreg Roach		return true;
1088c2e8227SGreg Roach	}
1098c2e8227SGreg Roach
1108c2e8227SGreg Roach	/** {@inheritdoc} */
1118c2e8227SGreg Roach	public function isGedcomBlock() {
1128c2e8227SGreg Roach		return true;
1138c2e8227SGreg Roach	}
1148c2e8227SGreg Roach
1158c2e8227SGreg Roach	/** {@inheritdoc} */
1168c2e8227SGreg Roach	public function configureBlock($block_id) {
1178c2e8227SGreg Roach	}
1188c2e8227SGreg Roach}
119