Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions modules/mod_whosonline/mod_whosonline.php

This file was deleted.

2 changes: 1 addition & 1 deletion modules/mod_whosonline/mod_whosonline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>MOD_WHOSONLINE_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\Whosonline</namespace>
<files>
<filename module="mod_whosonline">mod_whosonline.php</filename>
<folder module="mod_whosonline">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
41 changes: 41 additions & 0 deletions modules/mod_whosonline/services/provider.php
Original file line number Diff line number Diff line change
@@ -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 __DEPLOY_VERSION__
*/
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
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());
}
};
103 changes: 103 additions & 0 deletions modules/mod_whosonline/src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
@@ -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 __DEPLOY_VERSION__
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;

/**
* Runs the dispatcher.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
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 __DEPLOY_VERSION__
*/
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;
}
}
77 changes: 65 additions & 12 deletions modules/mod_whosonline/src/Helper/WhosonlineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

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;
Expand All @@ -21,25 +25,29 @@
*
* @since 1.5
*/
class WhosonlineHelper
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 1.5
* @since __DEPLOY_VERSION__
**/
public static function getOnlineCount()
public function getOnlineUsersCount(CMSApplicationInterface $app): array
{
$db = Factory::getDbo();
$db = $this->getDatabase();

// Calculate number of guests and users
$result = [];
$user_array = 0;
$guest_array = 0;

$whereCondition = Factory::getApplication()->get('shared_session', '0') ? 'IS NULL' : '= 0';
$whereCondition = $app->get('shared_session', '0') ? 'IS NULL' : '= 0';

$query = $db->getQuery(true)
->select('guest, client_id')
Expand Down Expand Up @@ -74,27 +82,28 @@ public static function getOnlineCount()
}

/**
* Show online member names
* Fetch online user names
*
* @param mixed $params The parameters
* @param CMSApplicationInterface $app The application instance
* @param Registry $params The parameters
*
* @return array (array) $db->loadObjectList() The names of the online users.
*
* @since 1.5
* @since __DEPLOY_VERSION__
**/
public static function getOnlineUserNames($params)
public function fetchOnlineUserNames(CMSApplicationInterface $app, Registry $params): array
{
$whereCondition = Factory::getApplication()->get('shared_session', '0') ? 'IS NULL' : '= 0';
$whereCondition = $app->get('shared_session', '0') ? 'IS NULL' : '= 0';

$db = Factory::getDbo();
$db = $this->getDatabase();
$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();
$user = $app->getIdentity();

if (!$user->authorise('core.admin') && $params->get('filter_groups', 0) == 1) {
$groups = $user->getAuthorisedGroups();
Expand All @@ -117,4 +126,48 @@ public static function getOnlineUserNames($params)
return [];
}
}

/**
* Show online count
*
* @return array The number of Users and Guests online.
*
* @since 1.5
*
* @deprecated __DEPLOY_VERSION__ 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 __DEPLOY_VERSION__ 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);
}
}