first commit
This commit is contained in:
31
modules/mod_whosonline/mod_whosonline.php
Normal file
31
modules/mod_whosonline/mod_whosonline.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_whosonline
|
||||
*
|
||||
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Helper\ModuleHelper;
|
||||
use Joomla\Module\Whosonline\Site\Helper\WhosonlineHelper;
|
||||
|
||||
// Check if session metadata tracking is enabled
|
||||
if ($app->get('session_metadata', true)) {
|
||||
$showmode = $params->get('showmode', 0);
|
||||
|
||||
if ($showmode == 0 || $showmode == 2) {
|
||||
$count = WhosonlineHelper::getOnlineCount();
|
||||
}
|
||||
|
||||
if ($showmode > 0) {
|
||||
$names = WhosonlineHelper::getOnlineUserNames($params);
|
||||
}
|
||||
|
||||
require ModuleHelper::getLayoutPath('mod_whosonline', $params->get('layout', 'default'));
|
||||
} else {
|
||||
require ModuleHelper::getLayoutPath('mod_whosonline', 'disabled');
|
||||
}
|
||||
90
modules/mod_whosonline/mod_whosonline.xml
Normal file
90
modules/mod_whosonline/mod_whosonline.xml
Normal file
@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="module" client="site" method="upgrade">
|
||||
<name>mod_whosonline</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2004-07</creationDate>
|
||||
<copyright>(C) 2005 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.0.0</version>
|
||||
<description>MOD_WHOSONLINE_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Module\Whosonline</namespace>
|
||||
<files>
|
||||
<filename module="mod_whosonline">mod_whosonline.php</filename>
|
||||
<folder>src</folder>
|
||||
<folder>tmpl</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/mod_whosonline.ini</language>
|
||||
<language tag="en-GB">language/en-GB/mod_whosonline.sys.ini</language>
|
||||
</languages>
|
||||
<help key="Site_Modules:_Who%27s_Online" />
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="showmode"
|
||||
type="list"
|
||||
label="MOD_WHOSONLINE_SHOWMODE_LABEL"
|
||||
default="0"
|
||||
filter="integer"
|
||||
validate="options"
|
||||
>
|
||||
<option value="0">MOD_WHOSONLINE_FIELD_VALUE_NUMBER</option>
|
||||
<option value="1">MOD_WHOSONLINE_FIELD_VALUE_NAMES</option>
|
||||
<option value="2">MOD_WHOSONLINE_FIELD_VALUE_BOTH</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="filter_groups"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="MOD_WHOSONLINE_FIELD_FILTER_GROUPS_LABEL"
|
||||
description="MOD_WHOSONLINE_FIELD_FILTER_GROUPS_DESC"
|
||||
default="0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
<fieldset name="advanced">
|
||||
<field
|
||||
name="layout"
|
||||
type="modulelayout"
|
||||
label="JFIELD_ALT_LAYOUT_LABEL"
|
||||
class="form-select"
|
||||
validate="moduleLayout"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="moduleclass_sfx"
|
||||
type="textarea"
|
||||
label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
|
||||
rows="3"
|
||||
validate="CssIdentifier"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="cache"
|
||||
type="list"
|
||||
label="COM_MODULES_FIELD_CACHING_LABEL"
|
||||
default="0"
|
||||
filter="integer"
|
||||
validate="options"
|
||||
>
|
||||
<option value="0">COM_MODULES_FIELD_VALUE_NOCACHING</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="cache_time"
|
||||
type="number"
|
||||
label="COM_MODULES_FIELD_CACHE_TIME_LABEL"
|
||||
default="900"
|
||||
filter="integer"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
120
modules/mod_whosonline/src/Helper/WhosonlineHelper.php
Normal file
120
modules/mod_whosonline/src/Helper/WhosonlineHelper.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_whosonline
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Module\Whosonline\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Helper for mod_whosonline
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class WhosonlineHelper
|
||||
{
|
||||
/**
|
||||
* Show online count
|
||||
*
|
||||
* @return array The number of Users and Guests online.
|
||||
*
|
||||
* @since 1.5
|
||||
**/
|
||||
public static function getOnlineCount()
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Calculate number of guests and users
|
||||
$result = [];
|
||||
$user_array = 0;
|
||||
$guest_array = 0;
|
||||
|
||||
$whereCondition = Factory::getApplication()->get('shared_session', '0') ? 'IS NULL' : '= 0';
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('guest, client_id')
|
||||
->from('#__session')
|
||||
->where('client_id ' . $whereCondition);
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$sessions = (array) $db->loadObjectList();
|
||||
} catch (\RuntimeException $e) {
|
||||
$sessions = [];
|
||||
}
|
||||
|
||||
if (\count($sessions)) {
|
||||
foreach ($sessions as $session) {
|
||||
// If guest increase guest count by 1
|
||||
if ($session->guest == 1) {
|
||||
$guest_array++;
|
||||
}
|
||||
|
||||
// If member increase member count by 1
|
||||
if ($session->guest == 0) {
|
||||
$user_array++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result['user'] = $user_array;
|
||||
$result['guest'] = $guest_array;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show online member names
|
||||
*
|
||||
* @param mixed $params The parameters
|
||||
*
|
||||
* @return array (array) $db->loadObjectList() The names of the online users.
|
||||
*
|
||||
* @since 1.5
|
||||
**/
|
||||
public static function getOnlineUserNames($params)
|
||||
{
|
||||
$whereCondition = Factory::getApplication()->get('shared_session', '0') ? 'IS NULL' : '= 0';
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName(['a.username', 'a.userid', 'a.client_id']))
|
||||
->from($db->quoteName('#__session', 'a'))
|
||||
->where($db->quoteName('a.userid') . ' != 0')
|
||||
->where($db->quoteName('a.client_id') . ' ' . $whereCondition)
|
||||
->group($db->quoteName(['a.username', 'a.userid', 'a.client_id']));
|
||||
|
||||
$user = Factory::getUser();
|
||||
|
||||
if (!$user->authorise('core.admin') && $params->get('filter_groups', 0) == 1) {
|
||||
$groups = $user->getAuthorisedGroups();
|
||||
|
||||
if (empty($groups)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$query->leftJoin($db->quoteName('#__user_usergroup_map', 'm'), $db->quoteName('m.user_id') . ' = ' . $db->quoteName('a.userid'))
|
||||
->leftJoin($db->quoteName('#__usergroups', 'ug'), $db->quoteName('ug.id') . ' = ' . $db->quoteName('m.group_id'))
|
||||
->whereIn($db->quoteName('ug.id'), $groups)
|
||||
->where($db->quoteName('ug.id') . ' <> 1');
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
return (array) $db->loadObjectList();
|
||||
} catch (\RuntimeException $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
36
modules/mod_whosonline/tmpl/default.php
Normal file
36
modules/mod_whosonline/tmpl/default.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_whosonline
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
?>
|
||||
|
||||
<div class="mod-whosonline">
|
||||
<?php if ($showmode == 0 || $showmode == 2) : ?>
|
||||
<?php $guest = Text::plural('MOD_WHOSONLINE_GUESTS', $count['guest']); ?>
|
||||
<?php $member = Text::plural('MOD_WHOSONLINE_MEMBERS', $count['user']); ?>
|
||||
<p><?php echo Text::sprintf('MOD_WHOSONLINE_WE_HAVE', $guest, $member); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (($showmode > 0) && count($names)) : ?>
|
||||
<?php if ($params->get('filter_groups', 0)) : ?>
|
||||
<p><?php echo Text::_('MOD_WHOSONLINE_SAME_GROUP_MESSAGE'); ?></p>
|
||||
<?php endif; ?>
|
||||
<ul class="nav flex-column">
|
||||
<?php foreach ($names as $name) : ?>
|
||||
<li>
|
||||
<?php echo $name->username; ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
18
modules/mod_whosonline/tmpl/disabled.php
Normal file
18
modules/mod_whosonline/tmpl/disabled.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_whosonline
|
||||
*
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
?>
|
||||
<div class="mod-whosonline-disabled">
|
||||
<p><?php echo Text::_('MOD_WHOSONLINE_NO_SESSION_METADATA'); ?></p>
|
||||
</div>
|
||||
Reference in New Issue
Block a user