first commit

This commit is contained in:
2026-02-08 21:16:11 +01:00
commit e17b7026fd
8881 changed files with 1160453 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage System.sessiongc
*
* @copyright (C) 2023 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\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Session\MetadataManager;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\System\SessionGC\Extension\SessionGC;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.4.0
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new SessionGC(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'sessiongc'),
$container->get(MetadataManager::class)
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="system" method="upgrade">
<name>plg_system_sessiongc</name>
<author>Joomla! Project</author>
<creationDate>2018-02</creationDate>
<copyright>(C) 2018 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.8.6</version>
<description>PLG_SYSTEM_SESSIONGC_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\System\SessionGC</namespace>
<files>
<folder plugin="sessiongc">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_system_sessiongc.ini</language>
<language tag="en-GB">language/en-GB/plg_system_sessiongc.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="enable_session_gc"
type="radio"
label="PLG_SYSTEM_SESSIONGC_ENABLE_SESSION_GC_LABEL"
description="PLG_SYSTEM_SESSIONGC_ENABLE_SESSION_GC_DESC"
layout="joomla.form.field.radio.switcher"
default="1"
filter="uint"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field
name="enable_session_metadata_gc"
type="radio"
label="PLG_SYSTEM_SESSIONGC_ENABLE_SESSION_METADATA_GC_LABEL"
description="PLG_SYSTEM_SESSIONGC_ENABLE_SESSION_METADATA_GC_DESC"
layout="joomla.form.field.radio.switcher"
default="1"
filter="uint"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field
name="gc_probability"
type="number"
label="PLG_SYSTEM_SESSIONGC_GC_PROBABILITY_LABEL"
description="PLG_SYSTEM_SESSIONGC_GC_PROBABILITY_DESC"
filter="uint"
validate="number"
min="1"
default="1"
showon="enable_session_gc:1[OR]enable_session_metadata_gc:1"
/>
<field
name="gc_divisor"
type="number"
label="PLG_SYSTEM_SESSIONGC_GC_DIVISOR_LABEL"
description="PLG_SYSTEM_SESSIONGC_GC_DIVISOR_DESC"
filter="uint"
validate="number"
min="1"
default="100"
showon="enable_session_gc:1[OR]enable_session_metadata_gc:1"
/>
</fieldset>
</fields>
</config>
</extension>

View File

@@ -0,0 +1,84 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage System.sessiongc
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\System\SessionGC\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\MetadataManager;
use Joomla\Event\DispatcherInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Garbage collection handler for session related data
*
* @since 3.8.6
*/
final class SessionGC extends CMSPlugin
{
/**
* The meta data manager
*
* @var MetadataManager
*
* @since 4.4.0
*/
private $metadataManager;
/**
* Constructor.
*
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
* @param MetadataManager $metadataManager The user factory
*
* @since 4.4.0
*/
public function __construct(DispatcherInterface $dispatcher, array $config, MetadataManager $metadataManager)
{
parent::__construct($dispatcher, $config);
$this->metadataManager = $metadataManager;
}
/**
* Runs after the HTTP response has been sent to the client and performs garbage collection tasks
*
* @return void
*
* @since 3.8.6
*/
public function onAfterRespond()
{
if ($this->params->get('enable_session_gc', 1)) {
$probability = $this->params->get('gc_probability', 1);
$divisor = $this->params->get('gc_divisor', 100);
$random = $divisor * lcg_value();
if ($probability > 0 && $random < $probability) {
$this->getApplication()->getSession()->gc();
}
}
if ($this->getApplication()->get('session_handler', 'none') !== 'database' && $this->params->get('enable_session_metadata_gc', 1)) {
$probability = $this->params->get('gc_probability', 1);
$divisor = $this->params->get('gc_divisor', 100);
$random = $divisor * lcg_value();
if ($probability > 0 && $random < $probability) {
$this->metadataManager->deletePriorTo(time() - $this->getApplication()->getSession()->getExpire());
}
}
}
}