This commit is contained in:
AlexBa16
2026-06-08 15:29:52 +02:00
commit 27903eed4a
9931 changed files with 1535659 additions and 0 deletions
@@ -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);
}
}