init
This commit is contained in:
@@ -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>
|
||||
<folder module="mod_whosonline">services</folder>
|
||||
<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>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_whosonline
|
||||
*
|
||||
* @copyright (C) 2025 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\Extension\Service\Provider\HelperFactory;
|
||||
use Joomla\CMS\Extension\Service\Provider\Module;
|
||||
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
|
||||
/**
|
||||
* The who's online module service provider.
|
||||
*
|
||||
* @since 5.4.0
|
||||
*/
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public function register(Container $container): void
|
||||
{
|
||||
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Whosonline'));
|
||||
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Whosonline\\Site\\Helper'));
|
||||
|
||||
$container->registerServiceProvider(new Module());
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage mod_whosonline
|
||||
*
|
||||
* @copyright (C) 2025 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\Dispatcher;
|
||||
|
||||
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
|
||||
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
|
||||
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
|
||||
use Joomla\CMS\Helper\ModuleHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Dispatcher class for mod_whosonline
|
||||
*
|
||||
* @since 5.4.0
|
||||
*/
|
||||
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
|
||||
{
|
||||
use HelperFactoryAwareTrait;
|
||||
|
||||
/**
|
||||
* Runs the dispatcher.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
$this->loadLanguage();
|
||||
|
||||
$displayData = $this->getLayoutData();
|
||||
|
||||
// Stop when display data is false
|
||||
if ($displayData === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Execute the layout without the module context
|
||||
$loader = static function (array $displayData) {
|
||||
// If $displayData doesn't exist in extracted data, unset the variable.
|
||||
if (!\array_key_exists('displayData', $displayData)) {
|
||||
extract($displayData);
|
||||
unset($displayData);
|
||||
} else {
|
||||
extract($displayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracted variables
|
||||
* -----------------
|
||||
* @var \stdClass $module
|
||||
* @var Registry $params
|
||||
*/
|
||||
|
||||
if ($app->get('session_metadata', true)) {
|
||||
require ModuleHelper::getLayoutPath('mod_whosonline', $params->get('layout', 'default'));
|
||||
} else {
|
||||
require ModuleHelper::getLayoutPath('mod_whosonline', 'disabled');
|
||||
}
|
||||
};
|
||||
|
||||
$loader($displayData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the layout data.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 5.4.0
|
||||
*/
|
||||
protected function getLayoutData(): array
|
||||
{
|
||||
$data = parent::getLayoutData();
|
||||
$helper = $this->getHelperFactory()->getHelper('WhosonlineHelper');
|
||||
|
||||
// Check if session metadata tracking is enabled
|
||||
if ($data['app']->get('session_metadata', true)) {
|
||||
$data['showmode'] = $data['params']->get('showmode', 0);
|
||||
|
||||
if ($data['showmode'] == 0 || $data['showmode'] == 2) {
|
||||
$data['count'] = $helper->getOnlineUsersCount($data['app']);
|
||||
}
|
||||
|
||||
if ($data['showmode'] > 0) {
|
||||
$data['names'] = $helper->fetchOnlineUserNames($data['app'], $data['params']);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
<?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\Application\CMSApplicationInterface;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\Database\DatabaseAwareInterface;
|
||||
use Joomla\Database\DatabaseAwareTrait;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Helper for mod_whosonline
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class WhosonlineHelper implements DatabaseAwareInterface
|
||||
{
|
||||
use DatabaseAwareTrait;
|
||||
|
||||
/**
|
||||
* Show online count
|
||||
*
|
||||
* @param CMSApplicationInterface $app The application instance
|
||||
*
|
||||
* @return array The number of Users and Guests online.
|
||||
*
|
||||
* @since 5.4.0
|
||||
**/
|
||||
public function getOnlineUsersCount(CMSApplicationInterface $app): array
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
|
||||
// Calculate number of guests and users
|
||||
$result = [];
|
||||
$user_array = 0;
|
||||
$guest_array = 0;
|
||||
|
||||
$whereCondition = $app->get('shared_session', '0') ? 'IS NULL' : '= 0';
|
||||
|
||||
$query = $db->createQuery()
|
||||
->select('guest, client_id')
|
||||
->from('#__session')
|
||||
->where('client_id ' . $whereCondition);
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$sessions = (array) $db->loadObjectList();
|
||||
} catch (\RuntimeException) {
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch online user names
|
||||
*
|
||||
* @param CMSApplicationInterface $app The application instance
|
||||
* @param Registry $params The parameters
|
||||
*
|
||||
* @return array (array) $db->loadObjectList() The names of the online users.
|
||||
*
|
||||
* @since 5.4.0
|
||||
**/
|
||||
public function fetchOnlineUserNames(CMSApplicationInterface $app, Registry $params): array
|
||||
{
|
||||
$whereCondition = $app->get('shared_session', '0') ? 'IS NULL' : '= 0';
|
||||
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->createQuery()
|
||||
->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 = $app->getIdentity();
|
||||
|
||||
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) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show online count
|
||||
*
|
||||
* @return array The number of Users and Guests online.
|
||||
*
|
||||
* @since 1.5
|
||||
*
|
||||
* @deprecated 5.4.0 will be removed in 7.0
|
||||
* Use the non-static method getOnlineUsersCount
|
||||
* Example: Factory::getApplication()->bootModule('mod_whosonline', 'site')
|
||||
* ->getHelper('WhosonlineHelper')
|
||||
* ->getOnlineUsersCount(Factory::getApplication())
|
||||
**/
|
||||
public static function getOnlineCount()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
return $app->bootModule('mod_whosonline', 'site')
|
||||
->getHelper('WhosonlineHelper')
|
||||
->getOnlineUsersCount($app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show online member names
|
||||
*
|
||||
* @param mixed $params The parameters
|
||||
*
|
||||
* @return array (array) $db->loadObjectList() The names of the online users.
|
||||
*
|
||||
* @since 1.5
|
||||
*
|
||||
* @deprecated 5.4.0 will be removed in 7.0
|
||||
* Use the non-static method fetchOnlineUserNames
|
||||
* Example: Factory::getApplication()->bootModule('mod_whosonline', 'site')
|
||||
* ->getHelper('WhosonlineHelper')
|
||||
* ->fetchOnlineUserNames(Factory::getApplication(), $params)
|
||||
**/
|
||||
public static function getOnlineUserNames($params)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
return $app->bootModule('mod_whosonline', 'site')
|
||||
->getHelper('WhosonlineHelper')
|
||||
->fetchOnlineUserNames($app, $params);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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