first commit

This commit is contained in:
2025-06-17 11:53:18 +02:00
commit 9f0f7ba12b
8804 changed files with 1369176 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_check_files</name>
<author>Joomla! Project</author>
<creationDate>2021-08</creationDate>
<copyright>(C) 2021 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>4.1</version>
<description>PLG_TASK_CHECK_FILES_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\Checkfiles</namespace>
<files>
<folder plugin="checkfiles">services</folder>
<folder>src</folder>
<folder>forms</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_checkfiles.ini</language>
<language tag="en-GB">language/en-GB/plg_task_checkfiles.sys.ini</language>
</languages>
</extension>

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params">
<fieldset name="task_params">
<field
name="path"
type="folderlist"
label="PLG_TASK_CHECK_FILES_LABEL_DIRECTORY"
directory="images"
hide_default="true"
hide_none="true"
required="true"
validate="options"
>
<option value="">JOPTION_DO_NOT_USE</option>
</field>
<field
name="dimension"
type="list"
label="PLG_TASK_CHECK_FILES_LABEL_IMAGE_DIMENSION"
required="true"
default="width"
>
<option value="width">JFIELD_MEDIA_WIDTH_LABEL</option>
<option value="height">JFIELD_MEDIA_HEIGHT_LABEL</option>
</field>
<field
name="limit"
type="number"
label="PLG_TASK_CHECK_FILES_LABEL_DIMENSION_LIMIT"
required="true"
default="1080"
min="1"
step="1"
filter="int"
/>
<field
name="numImages"
type="number"
label="PLG_TASK_CHECK_FILES_LABEL_MAXIMAGES"
description="PLG_TASK_CHECK_FILES_LABEL_MAXIMAGES_DESC"
required="true"
min="1"
step="1"
default="1"
filter="int"
/>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,47 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.CheckFiles
*
* @copyright (C) 2022 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\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Task\Checkfiles\Extension\Checkfiles;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.2.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new Checkfiles(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'checkfiles'),
JPATH_ROOT . '/images/'
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -0,0 +1,168 @@
<?php
/**
* @package Joomla.Plugins
* @subpackage Task.CheckFiles
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\Checkfiles\Extension;
use Joomla\CMS\Image\Image;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status as TaskStatus;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;
use Joomla\Filesystem\Folder;
use Joomla\Filesystem\Path;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Task plugin with routines that offer checks on files.
* At the moment, offers a single routine to check and resize image files in a directory.
*
* @since 4.1.0
*/
final class Checkfiles extends CMSPlugin implements SubscriberInterface
{
use TaskPluginTrait;
/**
* @var string[]
*
* @since 4.1.0
*/
protected const TASKS_MAP = [
'checkfiles.imagesize' => [
'langConstPrefix' => 'PLG_TASK_CHECK_FILES_TASK_IMAGE_SIZE',
'form' => 'image_size',
'method' => 'checkImages',
],
];
/**
* @inheritDoc
*
* @return string[]
*
* @since 4.1.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* @var boolean
* @since 4.1.0
*/
protected $autoloadLanguage = true;
/**
* The root directory path
*
* @var string
* @since 4.2.0
*/
private $rootDirectory;
/**
* Constructor.
*
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
* @param string $rootDirectory The root directory to look for images
*
* @since 4.2.0
*/
public function __construct(DispatcherInterface $dispatcher, array $config, string $rootDirectory)
{
parent::__construct($dispatcher, $config);
$this->rootDirectory = $rootDirectory;
}
/**
* @param ExecuteTaskEvent $event The onExecuteTask event
*
* @return integer The exit code
*
* @since 4.1.0
* @throws \RuntimeException
* @throws \LogicException
*/
protected function checkImages(ExecuteTaskEvent $event): int
{
$params = $event->getArgument('params');
$path = Path::check($this->rootDirectory . $params->path);
$dimension = $params->dimension;
$limit = $params->limit;
$numImages = max(1, (int) $params->numImages ?? 1);
if (!is_dir($path)) {
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_CHECK_FILES_LOG_IMAGE_PATH_NA'), 'warning');
return TaskStatus::NO_RUN;
}
foreach (Folder::files($path, '^.*\.(jpg|jpeg|png|gif|webp)', 2, true) as $imageFilename) {
$properties = Image::getImageFileProperties($imageFilename);
$resize = $properties->$dimension > $limit;
if (!$resize) {
continue;
}
$height = $properties->height;
$width = $properties->width;
$newHeight = $dimension === 'height' ? $limit : $height * $limit / $width;
$newWidth = $dimension === 'width' ? $limit : $width * $limit / $height;
$this->logTask(sprintf(
$this->getApplication()->getLanguage()->_('PLG_TASK_CHECK_FILES_LOG_RESIZING_IMAGE'),
$width,
$height,
$newWidth,
$newHeight,
$imageFilename
));
$image = new Image($imageFilename);
try {
$image->resize($newWidth, $newHeight, false);
} catch (\LogicException $e) {
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_CHECK_FILES_LOG_RESIZE_FAIL'), 'error');
return TaskStatus::KNOCKOUT;
}
if (!$image->toFile($imageFilename, $properties->type)) {
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_CHECK_FILES_LOG_IMAGE_SAVE_FAIL'), 'error');
return TaskStatus::KNOCKOUT;
}
--$numImages;
// We do a limited number of resize per execution
if ($numImages == 0) {
break;
}
}
return TaskStatus::OK;
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_deleteactionlogs</name>
<author>Joomla! Project</author>
<creationDate>2023-07</creationDate>
<copyright>(C) 2023 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>5.0.0</version>
<description>PLG_TASK_DELETEACTIONLOGS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\DeleteActionLogs</namespace>
<files>
<folder>forms</folder>
<folder plugin="deleteactionlogs">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_deleteactionlogs.ini</language>
<language tag="en-GB">language/en-GB/plg_task_deleteactionlogs.sys.ini</language>
</languages>
</extension>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params">
<fieldset name="task_params">
<field
name="logDeletePeriod"
type="number"
label="PLG_TASK_DELETEACTIONLOGS_LOG_DELETE_PERIOD"
default="7"
min="1"
filter="int"
validate="number"
/>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.deletelogs
*
* @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\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Task\DeleteActionLogs\Extension\DeleteActionLogs;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 5.0.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new DeleteActionLogs(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'deleteactionlogs')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
return $plugin;
}
);
}
};

View File

@ -0,0 +1,108 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.deleteactionlogs
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\DeleteActionLogs\Extension;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status;
use Joomla\Component\Scheduler\Administrator\Task\Task;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* A task plugin. For Delete Action Logs after x days
* {@see ExecuteTaskEvent}.
*
* @since 5.0.0
*/
final class DeleteActionLogs extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;
use TaskPluginTrait;
/**
* @var string[]
* @since 5.0.0
*/
private const TASKS_MAP = [
'delete.actionlogs' => [
'langConstPrefix' => 'PLG_TASK_DELETEACTIONLOGS_DELETE',
'method' => 'deleteLogs',
'form' => 'deleteForm',
],
];
/**
* @var boolean
* @since 5.0.0
*/
protected $autoloadLanguage = true;
/**
* @inheritDoc
*
* @return string[]
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* @param ExecuteTaskEvent $event The `onExecuteTask` event.
*
* @return integer The routine exit code.
*
* @since 5.0.0
* @throws \Exception
*/
private function deleteLogs(ExecuteTaskEvent $event): int
{
$daysToDeleteAfter = (int) $event->getArgument('params')->logDeletePeriod ?? 0;
$this->logTask(sprintf('Delete Logs after %d days', $daysToDeleteAfter));
$now = Factory::getDate()->toSql();
$db = $this->getDatabase();
$query = $db->getQuery(true);
if ($daysToDeleteAfter > 0) {
$days = -1 * $daysToDeleteAfter;
$query->clear()
->delete($db->quoteName('#__action_logs'))
->where($db->quoteName('log_date') . ' < ' . $query->dateAdd($db->quote($now), $days, 'DAY'));
$db->setQuery($query);
try {
$db->execute();
} catch (\RuntimeException $e) {
// Ignore it
return Status::KNOCKOUT;
}
}
$this->logTask('Delete Logs end');
return Status::OK;
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<form>
<fields name="params">
<fieldset name="task_params">
<field
name="delay"
type="number"
label="PLG_TASK_GLOBALCHECKIN_DELAY_LABEL"
default="1"
required="true"
min="0"
step="1"
validate="number"
filter="int"
/>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_globalcheckin</name>
<author>Joomla! Project</author>
<creationDate>2023-06-22</creationDate>
<copyright>(C) 2023 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>5.0.0</version>
<description>PLG_TASK_GLOBALCHECKIN_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\Globalcheckin</namespace>
<files>
<folder plugin="globalcheckin">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_globalcheckin.ini</language>
<language tag="en-GB">language/en-GB/plg_task_globalcheckin.sys.ini</language>
</languages>
</extension>

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.Globalcheckin
*
* @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\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Task\Globalcheckin\Extension\Globalcheckin;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
* @since 5.0.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = PluginHelper::getPlugin('task', 'globalcheckin');
$dispatcher = $container->get(DispatcherInterface::class);
$checkin = new Globalcheckin(
$dispatcher,
(array) $plugin
);
$checkin->setDatabase($container->get(DatabaseInterface::class));
return $checkin;
}
);
}
};

View File

@ -0,0 +1,125 @@
<?php
/**
* @package Joomla.Plugins
* @subpackage Task.Globalcheckin
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\Globalcheckin\Extension;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status as TaskStatus;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\Exception\ExecutionFailureException;
use Joomla\Event\SubscriberInterface;
/**
* Task plugin with routines to check in a checked out item.
*
* @since 5.0.0
*/
class Globalcheckin extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;
use TaskPluginTrait;
/**
* @var string[]
* @since 5.0.0
*/
protected const TASKS_MAP = [
'plg_task_globalcheckin_task_get' => [
'langConstPrefix' => 'PLG_TASK_GLOBALCHECKIN',
'form' => 'globalcheckin_params',
'method' => 'makeCheckin',
],
];
/**
* @var boolean
* @since 5.0.0
*/
protected $autoloadLanguage = true;
/**
* @inheritDoc
*
* @return string[]
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* Standard method for the checkin routine.
*
* @param ExecuteTaskEvent $event The onExecuteTask event
*
* @return integer The exit code
*
* @since 5.0.0
*/
protected function makeCheckin(ExecuteTaskEvent $event): int
{
$db = $this->getDatabase();
$tables = $db->getTableList();
$prefix = $db->getPrefix();
$delay = (int) $event->getArgument('params')->delay ?? 1;
$failed = false;
foreach ($tables as $tn) {
// Make sure we get the right tables based on prefix.
if (stripos($tn, $prefix) !== 0) {
continue;
}
$fields = $db->getTableColumns($tn, false);
if (!(isset($fields['checked_out']) && isset($fields['checked_out_time']))) {
continue;
}
$query = $db->getQuery(true)
->update($db->quoteName($tn))
->set($db->quoteName('checked_out') . ' = NULL')
->set($db->quoteName('checked_out_time') . ' = NULL');
if ($fields['checked_out']->Null === 'YES') {
$query->where($db->quoteName('checked_out') . ' IS NOT NULL');
} else {
$query->where($db->quoteName('checked_out') . ' > 0');
}
if ($delay > 0) {
$delayTime = Factory::getDate('now', 'UTC')->sub(new \DateInterval('PT' . $delay . 'H'))->toSql();
$query->where(
$db->quoteName('checked_out_time') . ' < ' . $db->quote($delayTime)
);
}
$db->setQuery($query);
try {
$db->execute();
} catch (ExecutionFailureException $e) {
// This failure isn't critical, don't care too much
$failed = true;
}
}
return $failed ? TaskStatus::INVALID_EXIT : TaskStatus::OK;
}
}

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params">
<fieldset name="task_params">
<field
name="consentexpiration"
type="integer"
label="PLG_TASK_PRIVACYCONSENT_CONSENTEXPIRATIONDAYS_LABEL"
description="PLG_TASK_PRIVACYCONSENT_CONSENTEXPIRATIONDAYS_DESC"
first="0"
last="720"
step="30"
default="360"
filter="int"
validate="number"
/>
<field
name="remind"
type="integer"
label="PLG_TASK_PRIVACYCONSENT_REMINDBEFORE_LABEL"
description="PLG_TASK_PRIVACYCONSENT_REMINDBEFORE_DESC"
first="0"
last="120"
step="1"
default="30"
filter="int"
validate="number"
/>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_privacyconsent</name>
<author>Joomla! Project</author>
<creationDate>2023-07</creationDate>
<copyright>(C) 2023 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>5.0.0</version>
<description>PLG_TASK_PRIVACYCONSENT_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\PrivacyConsent</namespace>
<files>
<folder>forms</folder>
<folder plugin="privacyconsent">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_privacyconsent.ini</language>
<language tag="en-GB">language/en-GB/plg_task_privacyconsent.sys.ini</language>
</languages>
</extension>

View File

@ -0,0 +1,50 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.PrivacyConsent
*
* @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\User\UserFactoryInterface;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Task\PrivacyConsent\Extension\PrivacyConsent;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 5.0.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new PrivacyConsent(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'privacyconsent')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
$plugin->setUserFactory($container->get(UserFactoryInterface::class));
return $plugin;
}
);
}
};

View File

@ -0,0 +1,261 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.PrivacyConsent
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\PrivacyConsent\Extension;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Mail\Exception\MailDisabledException;
use Joomla\CMS\Mail\MailTemplate;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\User\UserFactoryAwareTrait;
use Joomla\CMS\User\UserHelper;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status;
use Joomla\Component\Scheduler\Administrator\Task\Task;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\ParameterType;
use Joomla\Event\SubscriberInterface;
use PHPMailer\PHPMailer\Exception as phpmailerException;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* A task plugin. Offers 2 task routines Invalidate Expired Consents and Remind Expired Consents
* {@see ExecuteTaskEvent}.
*
* @since 5.0.0
*/
final class PrivacyConsent extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;
use TaskPluginTrait;
use UserFactoryAwareTrait;
/**
* @var string[]
* @since 5.0.0
*/
private const TASKS_MAP = [
'privacy.consent' => [
'langConstPrefix' => 'PLG_TASK_PRIVACYCONSENT_INVALIDATE',
'method' => 'privacyConsents',
'form' => 'privacyconsentForm',
],
];
/**
* @var boolean
*
* @since 5.0.0
*/
protected $autoloadLanguage = true;
/**
* @inheritDoc
*
* @return string[]
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* Method to send the remind for privacy consents renew.
*
* @param ExecuteTaskEvent $event The `onExecuteTask` event.
*
* @return integer The routine exit code.
*
* @since 5.0.0
* @throws \Exception
*/
private function privacyConsents(ExecuteTaskEvent $event): int
{
// Load the parameters.
$expire = (int) $event->getArgument('params')->consentexpiration ?? 365;
$remind = (int) $event->getArgument('params')->remind ?? 30;
if (
$this->invalidateExpiredConsents($expire) === Status::OK
&& $this->remindExpiringConsents($expire, $remind) === Status::OK
) {
return Status::OK;
}
return Status::KNOCKOUT;
}
/**
* Method to send the remind for privacy consents renew.
*
* @param integer $expire
* @param integer $remind
*
* @return integer The routine exit code.
*
* @since 5.0.0
* @throws \Exception
*/
private function remindExpiringConsents($expire, $remind): int
{
$now = Factory::getDate()->toSql();
$period = '-' . ($expire - $remind);
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select($db->quoteName(['r.id', 'r.user_id', 'u.email']))
->from($db->quoteName('#__privacy_consents', 'r'))
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('r.user_id'))
->where($db->quoteName('subject') . ' = ' . $db->quote('PLG_SYSTEM_PRIVACYCONSENT_SUBJECT'))
->where($db->quoteName('remind') . ' = 0')
->where($query->dateAdd($db->quote($now), $period, 'DAY') . ' > ' . $db->quoteName('created'));
try {
$users = $db->setQuery($query)->loadObjectList();
} catch (\RuntimeException $exception) {
return Status::KNOCKOUT;
}
// Do not process further if no expired consents found
if (empty($users)) {
return Status::OK;
}
$app = $this->getApplication();
$linkMode = $app->get('force_ssl', 0) == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE;
foreach ($users as $user) {
$token = ApplicationHelper::getHash(UserHelper::genRandomPassword());
$hashedToken = UserHelper::hashPassword($token);
// The mail
try {
$templateData = [
'sitename' => $app->get('sitename'),
'url' => Uri::root(),
'tokenurl' => Route::link('site', 'index.php?option=com_privacy&view=remind&remind_token=' . $token, false, $linkMode, true),
'formurl' => Route::link('site', 'index.php?option=com_privacy&view=remind', false, $linkMode, true),
'token' => $token,
];
$mailer = new MailTemplate('plg_task_privacyconsent.request.reminder', $app->getLanguage()->getTag());
$mailer->addTemplateData($templateData);
$mailer->addRecipient($user->email);
$mailResult = $mailer->send();
if ($mailResult === false) {
return Status::KNOCKOUT;
}
$userId = (int) $user->id;
// Update the privacy_consents item to not send the reminder again
$query->clear()
->update($db->quoteName('#__privacy_consents'))
->set($db->quoteName('remind') . ' = 1')
->set($db->quoteName('token') . ' = :token')
->where($db->quoteName('id') . ' = :userid')
->bind(':token', $hashedToken)
->bind(':userid', $userId, ParameterType::INTEGER);
$db->setQuery($query);
try {
$db->execute();
} catch (\RuntimeException $e) {
return Status::KNOCKOUT;
}
} catch (MailDisabledException | phpmailerException $exception) {
return Status::KNOCKOUT;
}
}
$this->logTask('Remind end');
return Status::OK;
}
/**
* Method to delete the expired privacy consents.
*
* @param integer $expire
*
* @return integer The routine exit code.
*
* @since 5.0.0
* @throws \Exception
*/
private function invalidateExpiredConsents($expire): int
{
$now = Factory::getDate()->toSql();
$period = '-' . $expire;
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select($db->quoteName(['id', 'user_id']))
->from($db->quoteName('#__privacy_consents'))
->where($query->dateAdd($db->quote($now), $period, 'DAY') . ' > ' . $db->quoteName('created'))
->where($db->quoteName('subject') . ' = ' . $db->quote('PLG_SYSTEM_PRIVACYCONSENT_SUBJECT'))
->where($db->quoteName('state') . ' = 1');
$db->setQuery($query);
try {
$users = $db->loadObjectList();
} catch (\RuntimeException $e) {
return Status::KNOCKOUT;
}
// Do not process further if no expired consents found
if (empty($users)) {
return Status::OK;
}
// Push a notification to the site's super users
/** @var MessageModel $messageModel */
$messageModel = $this->getApplication()->bootComponent('com_messages')->getMVCFactory()->createModel('Message', 'Administrator');
foreach ($users as $user) {
$userId = (int) $user->id;
$query = $db->getQuery(true)
->update($db->quoteName('#__privacy_consents'))
->set($db->quoteName('state') . ' = 0')
->where($db->quoteName('id') . ' = :userid')
->bind(':userid', $userId, ParameterType::INTEGER);
$db->setQuery($query);
try {
$db->execute();
} catch (\RuntimeException $e) {
return Status::KNOCKOUT;
}
$messageModel->notifySuperUsers(
Text::_('PLG_TASK_PRIVACYCONSENT_NOTIFICATION_USER_PRIVACY_EXPIRED_SUBJECT'),
Text::sprintf('PLG_TASK_PRIVACYCONSENT_NOTIFICATION_USER_PRIVACY_EXPIRED_MESSAGE', $this->getUserFactory()->loadUserById($user->user_id)->username)
);
}
return Status::OK;
}
}

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params">
<fieldset name="task_params">
<field
name="url"
type="url"
label="PLG_TASK_REQUESTS_LABEL_REQUEST_URL"
required="true"
validate="url"
filter="url"
/>
<field
name="timeout"
type="number"
label="PLG_TASK_REQUESTS_LABEL_REQUEST_TIMEOUT"
min="1"
step="1"
default="120"
required="true"
filter="int"
validate="number"
/>
<field
name="auth"
type="radio"
label="PLG_TASK_REQUESTS_LABEL_AUTH"
layout="joomla.form.field.radio.switcher"
default="0"
required="true"
filter="integer"
>
<option value="0">JDISABLED</option>
<option value="1">JENABLED</option>
</field>
<field
name="authType"
type="list"
label="PLG_TASK_REQUESTS_LABEL_AUTH_HEADER"
showon="auth:1"
>
<option value="Bearer">PLG_TASK_REQUESTS_BEARER</option>
<option value="X-Joomla-Token">PLG_TASK_REQUESTS_JOOMLA_TOKEN</option>
</field>
<field
name="authKey"
type="text"
label="PLG_TASK_REQUESTS_LABEL_AUTH_KEY"
showon="auth:1"
/>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_requests</name>
<author>Joomla! Project</author>
<creationDate>2021-08</creationDate>
<copyright>(C) 2021 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>4.1</version>
<description>PLG_TASK_REQUESTS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\Requests</namespace>
<files>
<folder plugin="requests">services</folder>
<folder>src</folder>
<folder>forms</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_requests.ini</language>
<language tag="en-GB">language/en-GB/plg_task_requests.sys.ini</language>
</languages>
</extension>

View File

@ -0,0 +1,49 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.requests
*
* @copyright (C) 2022 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\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Http\HttpFactory;
use Joomla\Plugin\Task\Requests\Extension\Requests;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.2.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new Requests(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'requests'),
new HttpFactory(),
JPATH_ROOT . '/tmp'
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -0,0 +1,169 @@
<?php
/**
* @package Joomla.Plugins
* @subpackage Task.Requests
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\Requests\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status as TaskStatus;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Path;
use Joomla\Http\HttpFactory;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Task plugin with routines to make HTTP requests.
* At the moment, offers a single routine for GET requests.
*
* @since 4.1.0
*/
final class Requests extends CMSPlugin implements SubscriberInterface
{
use TaskPluginTrait;
/**
* @var string[]
* @since 4.1.0
*/
protected const TASKS_MAP = [
'plg_task_requests_task_get' => [
'langConstPrefix' => 'PLG_TASK_REQUESTS_TASK_GET_REQUEST',
'form' => 'get_requests',
'method' => 'makeGetRequest',
],
];
/**
* Returns an array of events this subscriber will listen to.
*
* @return string[]
*
* @since 4.1.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* @var boolean
* @since 4.1.0
*/
protected $autoloadLanguage = true;
/**
* The http factory
*
* @var HttpFactory
* @since 4.2.0
*/
private $httpFactory;
/**
* The root directory
*
* @var string
* @since 4.2.0
*/
private $rootDirectory;
/**
* Constructor.
*
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
* @param HttpFactory $httpFactory The http factory
* @param string $rootDirectory The root directory to store the output file in
*
* @since 4.2.0
*/
public function __construct(DispatcherInterface $dispatcher, array $config, HttpFactory $httpFactory, string $rootDirectory)
{
parent::__construct($dispatcher, $config);
$this->httpFactory = $httpFactory;
$this->rootDirectory = $rootDirectory;
}
/**
* Standard routine method for the get request routine.
*
* @param ExecuteTaskEvent $event The onExecuteTask event
*
* @return integer The exit code
*
* @since 4.1.0
* @throws \Exception
*/
protected function makeGetRequest(ExecuteTaskEvent $event): int
{
$id = $event->getTaskId();
$params = $event->getArgument('params');
$url = $params->url;
$timeout = $params->timeout;
$auth = (string) $params->auth ?? 0;
$authType = (string) $params->authType ?? '';
$authKey = (string) $params->authKey ?? '';
$headers = [];
if ($auth && $authType && $authKey) {
$headers = ['Authorization' => $authType . ' ' . $authKey];
}
try {
$response = $this->httpFactory->getHttp([])->get($url, $headers, $timeout);
} catch (\Exception $e) {
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_TIMEOUT'));
return TaskStatus::TIMEOUT;
}
$responseCode = $response->code;
$responseBody = $response->body;
// @todo this handling must be rethought and made safe. stands as a good demo right now.
$responseFilename = Path::clean($this->rootDirectory . "/task_{$id}_response.html");
try {
File::write($responseFilename, $responseBody);
$this->snapshot['output_file'] = $responseFilename;
$responseStatus = 'SAVED';
} catch (\Exception $e) {
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_UNWRITEABLE_OUTPUT'), 'error');
$responseStatus = 'NOT_SAVED';
}
$this->snapshot['output'] = <<< EOF
======= Task Output Body =======
> URL: $url
> Response Code: $responseCode
> Response: $responseStatus
EOF;
$this->logTask(sprintf($this->getApplication()->getLanguage()->_('PLG_TASK_REQUESTS_TASK_GET_REQUEST_LOG_RESPONSE'), $responseCode));
if ($response->code !== 200) {
return TaskStatus::KNOCKOUT;
}
return TaskStatus::OK;
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params">
<fieldset name="task_params">
<field
name="logstokeep"
type="integer"
label="PLG_TASK_ROTATELOGS_LOGSTOKEEP_LABEL"
first="1"
last="10"
step="1"
default="1"
filter="int"
validate="number"
/>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_rotatelogs</name>
<author>Joomla! Project</author>
<creationDate>2023-07</creationDate>
<copyright>(C) 2023 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>5.0.0</version>
<description>PLG_TASK_ROTATELOGS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\RotateLogs</namespace>
<files>
<folder>forms</folder>
<folder plugin="rotatelogs">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_rotatelogs.ini</language>
<language tag="en-GB">language/en-GB/plg_task_rotatelogs.sys.ini</language>
</languages>
</extension>

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.rotatelogs
*
* @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\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Task\RotateLogs\Extension\RotateLogs;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 5.0.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new RotateLogs(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'rotatelogs')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
return $plugin;
}
);
}
};

View File

@ -0,0 +1,183 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.rotatelogs
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\RotateLogs\Extension;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status;
use Joomla\Component\Scheduler\Administrator\Task\Task;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Event\SubscriberInterface;
use Joomla\Filesystem\Path;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* A task plugin. Offers 1 task routines Rotate Logs
* {@see ExecuteTaskEvent}.
*
* @since 5.0.0
*/
final class RotateLogs extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;
use TaskPluginTrait;
/**
* @var string[]
* @since 5.0.0
*/
private const TASKS_MAP = [
'rotation.logs' => [
'langConstPrefix' => 'PLG_TASK_ROTATELOGS_ROTATION',
'method' => 'rotateLogs',
'form' => 'rotateForm',
],
];
/**
* @var boolean
* @since 5.0.0
*/
protected $autoloadLanguage = true;
/**
* @inheritDoc
*
* @return string[]
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* Method for the logs rotation task.
*
* @param ExecuteTaskEvent $event The `onExecuteTask` event.
*
* @return integer The routine exit code.
*
* @since 5.0.0
* @throws \Exception
*/
private function rotateLogs(ExecuteTaskEvent $event): int
{
$logsToKeep = (int) $event->getArgument('params')->logstokeep ?? 1;
// Get the log path
$logPath = Path::clean($this->getApplication()->get('log_path'));
// Invalid path, stop processing further
if (!is_dir($logPath)) {
return Status::KNOCKOUT;
}
$logFiles = $this->getLogFiles($logPath);
// Sort log files by version number in reverse order
krsort($logFiles, SORT_NUMERIC);
foreach ($logFiles as $version => $files) {
if ($version >= $logsToKeep) {
// Delete files which have version greater than or equals $logsToKeep
foreach ($files as $file) {
File::delete($logPath . '/' . $file);
}
} else {
// For files which have version smaller than $logsToKeep, rotate (increase version number)
foreach ($files as $file) {
$this->rotate($logPath, $file, $version);
}
}
}
return Status::OK;
}
/**
* Method to rotate (increase version) of a log file
*
* @param string $path Path to file to rotate
* @param string $filename Name of file to rotate
* @param int $currentVersion The current version number
*
* @return void
*
* @since 5.0.0
*/
private function rotate($path, $filename, $currentVersion)
{
if ($currentVersion === 0) {
$rotatedFile = $path . '/1.' . $filename;
} else {
/*
* Rotated log file has this filename format [VERSION].[FILENAME].php. To rotate it, we just need to explode
* the filename into an array, increase value of first element (keep version) and implode it back to get the
* rotated file name
*/
$parts = explode('.', $filename);
$parts[0] = $currentVersion + 1;
$rotatedFile = $path . '/' . implode('.', $parts);
}
File::move($path . '/' . $filename, $rotatedFile);
}
/**
* Get log files from log folder
*
* @param string $path The folder to get log files
*
* @return array The log files in the given path grouped by version number (not rotated files have number 0)
*
* @since 5.0.0
*/
private function getLogFiles($path)
{
$logFiles = [];
$files = Folder::files($path, '\.php$');
foreach ($files as $file) {
$parts = explode('.', $file);
/*
* Rotated log file has this filename format [VERSION].[FILENAME].php. So if $parts has at least 3 elements
* and the first element is a number, we know that it's a rotated file and can get it's current version
*/
if (\count($parts) >= 3 && is_numeric($parts[0])) {
$version = (int) $parts[0];
} else {
$version = 0;
}
if (!isset($logFiles[$version])) {
$logFiles[$version] = [];
}
$logFiles[$version][] = $file;
}
return $logFiles;
}
}

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params">
<fieldset name="task_params">
<field
name="enable_session_gc"
type="radio"
label="PLG_TASK_SESSIONGC_ENABLE_SESSION_GC_LABEL"
description="PLG_TASK_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_TASK_SESSIONGC_ENABLE_SESSION_METADATA_GC_LABEL"
description="PLG_TASK_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>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.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\Task\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 5.0.0
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new SessionGC(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'sessiongc'),
$container->get(MetadataManager::class)
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_sessiongc</name>
<author>Joomla! Project</author>
<creationDate>2023-08</creationDate>
<copyright>(C) 2023 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>5.0.0</version>
<description>PLG_TASK_SESSIONGC_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\SessionGC</namespace>
<files>
<folder plugin="sessiongc">services</folder>
<folder>src</folder>
<folder>forms</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_sessiongc.ini</language>
<language tag="en-GB">language/en-GB/plg_task_sessiongc.sys.ini</language>
</languages>
</extension>

View File

@ -0,0 +1,122 @@
<?php
/**
* @package Joomla.Plugins
* @subpackage Task.sessiongc
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\SessionGC\Extension;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\MetadataManager;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status;
use Joomla\Component\Scheduler\Administrator\Task\Task;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* A task plugin. Session data purge task.
* {@see ExecuteTaskEvent}.
*
* @since 5.0.0
*/
final class SessionGC extends CMSPlugin implements SubscriberInterface
{
use TaskPluginTrait;
/**
* The meta data manager
*
* @var MetadataManager
*
* @since 4.4.0
*/
private $metadataManager;
/**
* @var string[]
* @since 5.0.0
*/
private const TASKS_MAP = [
'session.gc' => [
'langConstPrefix' => 'PLG_TASK_SESSIONGC',
'method' => 'sessionGC',
'form' => 'sessionGCForm',
],
];
/**
* @var boolean
* @since 5.0.0
*/
protected $autoloadLanguage = true;
/**
* 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;
}
/**
* @inheritDoc
*
* @return string[]
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* @param ExecuteTaskEvent $event The `onExecuteTask` event.
*
* @return integer The routine exit code.
*
* @since 5.0.0
* @throws \Exception
*/
private function sessionGC(ExecuteTaskEvent $event): int
{
$enableGC = (int) $event->getArgument('params')->enable_session_gc ?? 1;
if ($enableGC) {
$this->getApplication()->getSession()->gc();
}
$enableMetadata = (int) $event->getArgument('params')->enable_session_metadata_gc ?? 1;
if ($this->getApplication()->get('session_handler', 'none') !== 'database' && $enableMetadata) {
$this->metadataManager->deletePriorTo(time() - $this->getApplication()->getSession()->getExpire());
}
$this->logTask('SessionGC end');
return Status::OK;
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.SiteStatus
*
* @copyright (C) 2022 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\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Task\SiteStatus\Extension\SiteStatus;
use Joomla\Utilities\ArrayHelper;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.2.0
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new SiteStatus(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'sitestatus'),
ArrayHelper::fromObject(new JConfig()),
JPATH_CONFIGURATION . '/configuration.php'
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_site_status</name>
<author>Joomla! Project</author>
<creationDate>2021-08</creationDate>
<copyright>(C) 2021 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>4.1</version>
<description>PLG_TASK_SITE_STATUS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\SiteStatus</namespace>
<files>
<folder plugin="sitestatus">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_sitestatus.ini</language>
<language tag="en-GB">language/en-GB/plg_task_sitestatus.sys.ini</language>
</languages>
</extension>

View File

@ -0,0 +1,192 @@
<?php
/**
* @package Joomla.Plugins
* @subpackage Task.SiteStatus
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\SiteStatus\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Task plugin with routines to change the offline status of the site. These routines can be used to control planned
* maintenance periods and related operations.
*
* @since 4.1.0
*/
final class SiteStatus extends CMSPlugin implements SubscriberInterface
{
use TaskPluginTrait;
/**
* @var string[]
* @since 4.1.0
*/
protected const TASKS_MAP = [
'plg_task_toggle_offline' => [
'langConstPrefix' => 'PLG_TASK_SITE_STATUS',
'toggle' => true,
],
'plg_task_toggle_offline_set_online' => [
'langConstPrefix' => 'PLG_TASK_SITE_STATUS_SET_ONLINE',
'toggle' => false,
'offline' => false,
],
'plg_task_toggle_offline_set_offline' => [
'langConstPrefix' => 'PLG_TASK_SITE_STATUS_SET_OFFLINE',
'toggle' => false,
'offline' => true,
],
];
/**
* Autoload the language file.
*
* @var boolean
* @since 4.1.0
*/
protected $autoloadLanguage = true;
/**
* @inheritDoc
*
* @return string[]
*
* @since 4.1.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'alterSiteStatus',
];
}
/**
* The old config
*
* @var array
* @since 4.2.0
*/
private $oldConfig;
/**
* The config file
*
* @var string
* @since 4.2.0
*/
private $configFile;
/**
* Constructor.
*
* @param DispatcherInterface $dispatcher The dispatcher
* @param array $config An optional associative array of configuration settings
* @param array $oldConfig The old config
* @param string $configFile The config
*
* @since 4.2.0
*/
public function __construct(DispatcherInterface $dispatcher, array $config, array $oldConfig, string $configFile)
{
parent::__construct($dispatcher, $config);
$this->oldConfig = $oldConfig;
$this->configFile = $configFile;
}
/**
* @param ExecuteTaskEvent $event The onExecuteTask event
*
* @return void
*
* @since 4.1.0
* @throws \Exception
*/
public function alterSiteStatus(ExecuteTaskEvent $event): void
{
if (!\array_key_exists($event->getRoutineId(), self::TASKS_MAP)) {
return;
}
$this->startRoutine($event);
$config = $this->oldConfig;
$toggle = self::TASKS_MAP[$event->getRoutineId()]['toggle'];
$oldStatus = $config['offline'] ? 'offline' : 'online';
if ($toggle) {
$config['offline'] = !$config['offline'];
} else {
$config['offline'] = self::TASKS_MAP[$event->getRoutineId()]['offline'];
}
$newStatus = $config['offline'] ? 'offline' : 'online';
$exit = $this->writeConfigFile(new Registry($config));
$this->logTask(sprintf($this->getApplication()->getLanguage()->_('PLG_TASK_SITE_STATUS_TASK_LOG_SITE_STATUS'), $oldStatus, $newStatus));
$this->endRoutine($event, $exit);
}
/**
* Method to write the configuration to a file.
*
* @param Registry $config A Registry object containing all global config data.
*
* @return integer The task exit code
*
* @since 4.1.0
* @throws \Exception
*/
private function writeConfigFile(Registry $config): int
{
// Set the configuration file path.
$file = $this->configFile;
// Attempt to make the file writeable.
if (file_exists($file) && Path::isOwner($file) && !Path::setPermissions($file)) {
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_SITE_STATUS_ERROR_CONFIGURATION_PHP_NOTWRITABLE'), 'notice');
}
try {
// Attempt to write the configuration file as a PHP class named JConfig.
$configuration = $config->toString('PHP', ['class' => 'JConfig', 'closingtag' => false]);
File::write($file, $configuration);
} catch (\Exception $e) {
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_SITE_STATUS_ERROR_WRITE_FAILED'), 'error');
return Status::KNOCKOUT;
}
// Invalidates the cached configuration file
if (\function_exists('opcache_invalidate')) {
opcache_invalidate($file);
}
// Attempt to make the file un-writeable.
if (Path::isOwner($file) && !Path::setPermissions($file, '0444')) {
$this->logTask($this->getApplication()->getLanguage()->_('PLG_TASK_SITE_STATUS_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'), 'notice');
}
return Status::OK;
}
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="params">
<fieldset name="task_params">
<field
name="email"
type="text"
label="PLG_TASK_UPDATENOTIFICATION_EMAIL_LBL"
description="PLG_TASK_UPDATENOTIFICATION_EMAIL_DESC"
default=""
/>
<field
name="language_override"
type="language"
label="PLG_TASK_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_LBL"
description="PLG_TASK_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_DESC"
default=""
client="administrator"
>
<option value="">PLG_TASK_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_NONE</option>
</field>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.updatenotification
*
* @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\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Task\UpdateNotification\Extension\UpdateNotification;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 5.0.0
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new UpdateNotification(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'updatenotification')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
return $plugin;
}
);
}
};

View File

@ -0,0 +1,309 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Task.updatenotification
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Task\UpdateNotification\Extension;
use Joomla\CMS\Access\Access;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\Mail\Exception\MailDisabledException;
use Joomla\CMS\Mail\MailTemplate;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Updater\Updater;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Version;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\ParameterType;
use Joomla\Event\SubscriberInterface;
use PHPMailer\PHPMailer\Exception as phpMailerException;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* A task plugin. Offers 2 task routines Invalidate Expired Consents and Remind Expired Consents
* {@see ExecuteTaskEvent}.
*
* @since 5.0.0
*/
final class UpdateNotification extends CMSPlugin implements SubscriberInterface
{
use DatabaseAwareTrait;
use TaskPluginTrait;
/**
* @var string[]
* @since 5.0.0
*/
private const TASKS_MAP = [
'update.notification' => [
'langConstPrefix' => 'PLG_TASK_UPDATENOTIFICATION_SEND',
'method' => 'sendNotification',
'form' => 'sendForm',
],
];
/**
* @var boolean
* @since 5.0.0
*/
protected $autoloadLanguage = true;
/**
* @inheritDoc
*
* @return string[]
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* Method to send the update notification.
*
* @param ExecuteTaskEvent $event The `onExecuteTask` event.
*
* @return integer The routine exit code.
*
* @since 5.0.0
* @throws \Exception
*/
private function sendNotification(ExecuteTaskEvent $event): int
{
// Load the parameters.
$specificEmail = $event->getArgument('params')->email ?? '';
$forcedLanguage = $event->getArgument('params')->language_override ?? '';
// This is the extension ID for Joomla! itself
$eid = ExtensionHelper::getExtensionRecord('joomla', 'file')->extension_id;
// Get any available updates
$updater = Updater::getInstance();
$results = $updater->findUpdates([$eid], 0);
// If there are no updates our job is done. We need BOTH this check AND the one below.
if (!$results) {
return Status::OK;
}
// Get the update model and retrieve the Joomla! core updates
$model = $this->getApplication()->bootComponent('com_installer')
->getMVCFactory()->createModel('Update', 'Administrator', ['ignore_request' => true]);
$model->setState('filter.extension_id', $eid);
$updates = $model->getItems();
// If there are no updates we don't have to notify anyone about anything. This is NOT a duplicate check.
if (empty($updates)) {
return Status::OK;
}
// Get the available update
$update = array_pop($updates);
// Check the available version. If it's the same or less than the installed version we have no updates to notify about.
if (version_compare($update->version, JVERSION, 'le')) {
return Status::OK;
}
// If we're here, we have updates. First, get a link to the Joomla! Update component.
$baseURL = Uri::base();
$baseURL = rtrim($baseURL, '/');
$baseURL .= (substr($baseURL, -13) !== 'administrator') ? '/administrator/' : '/';
$baseURL .= 'index.php?option=com_joomlaupdate';
$uri = new Uri($baseURL);
/**
* Some third party security solutions require a secret query parameter to allow log in to the administrator
* backend of the site. The link generated above will be invalid and could probably block the user out of their
* site, confusing them (they can't understand the third party security solution is not part of Joomla! proper).
* So, we're calling the onBuildAdministratorLoginURL system plugin event to let these third party solutions
* add any necessary secret query parameters to the URL. The plugins are supposed to have a method with the
* signature:
*
* public function onBuildAdministratorLoginURL(Uri &$uri);
*
* The plugins should modify the $uri object directly and return null.
*/
$this->getApplication()->triggerEvent('onBuildAdministratorLoginURL', [&$uri]);
// Let's find out the email addresses to notify
$superUsers = [];
if (!empty($specificEmail)) {
$superUsers = $this->getSuperUsers($specificEmail);
}
if (empty($superUsers)) {
$superUsers = $this->getSuperUsers();
}
if (empty($superUsers)) {
return Status::KNOCKOUT;
}
/*
* Load the appropriate language. We try to load English (UK), the current user's language and the forced
* language preference, in this order. This ensures that we'll never end up with untranslated strings in the
* update email which would make Joomla! seem bad. So, please, if you don't fully understand what the
* following code does DO NOT TOUCH IT. It makes the difference between a hobbyist CMS and a professional
* solution!
*/
$jLanguage = $this->getApplication()->getLanguage();
$jLanguage->load('plg_task_updatenotification', JPATH_ADMINISTRATOR, 'en-GB', true, true);
$jLanguage->load('plg_task_updatenotification', JPATH_ADMINISTRATOR, null, true, false);
// Then try loading the preferred (forced) language
if (!empty($forcedLanguage)) {
$jLanguage->load('plg_task_updatenotification', JPATH_ADMINISTRATOR, $forcedLanguage, true, false);
}
// Replace merge codes with their values
$newVersion = $update->version;
$jVersion = new Version();
$currentVersion = $jVersion->getShortVersion();
$sitename = $this->getApplication()->get('sitename');
$substitutions = [
'newversion' => $newVersion,
'curversion' => $currentVersion,
'sitename' => $sitename,
'url' => Uri::base(),
'link' => $uri->toString(),
'releasenews' => 'https://www.joomla.org/announcements/release-news/',
];
// Send the emails to the Super Users
foreach ($superUsers as $superUser) {
try {
$mailer = new MailTemplate('plg_task_updatenotification.mail', $jLanguage->getTag());
$mailer->addRecipient($superUser->email);
$mailer->addTemplateData($substitutions);
$mailer->send();
} catch (MailDisabledException | phpMailerException $exception) {
try {
$this->logTask($jLanguage->_($exception->getMessage()));
} catch (\RuntimeException $exception) {
return Status::KNOCKOUT;
}
}
}
$this->logTask('UpdateNotification end');
return Status::OK;
}
/**
* Returns the Super Users email information. If you provide a comma separated $email list
* we will check that these emails do belong to Super Users and that they have not blocked
* system emails.
*
* @param null|string $email A list of Super Users to email
*
* @return array The list of Super User emails
*
* @since 3.5
*/
private function getSuperUsers($email = null)
{
$db = $this->getDatabase();
$emails = [];
// Convert the email list to an array
if (!empty($email)) {
$temp = explode(',', $email);
foreach ($temp as $entry) {
$emails[] = trim($entry);
}
$emails = array_unique($emails);
}
// Get a list of groups which have Super User privileges
$ret = [];
try {
$rootId = Table::getInstance('Asset')->getRootId();
$rules = Access::getAssetRules($rootId)->getData();
$rawGroups = $rules['core.admin']->getData();
$groups = [];
if (empty($rawGroups)) {
return $ret;
}
foreach ($rawGroups as $g => $enabled) {
if ($enabled) {
$groups[] = $g;
}
}
if (empty($groups)) {
return $ret;
}
} catch (\Exception $exc) {
return $ret;
}
// Get the user IDs of users belonging to the SA groups
try {
$query = $db->getQuery(true)
->select($db->quoteName('user_id'))
->from($db->quoteName('#__user_usergroup_map'))
->whereIn($db->quoteName('group_id'), $groups);
$db->setQuery($query);
$userIDs = $db->loadColumn(0);
if (empty($userIDs)) {
return $ret;
}
} catch (\Exception $exc) {
return $ret;
}
// Get the user information for the Super Administrator users
try {
$query = $db->getQuery(true)
->select($db->quoteName(['id', 'username', 'email']))
->from($db->quoteName('#__users'))
->whereIn($db->quoteName('id'), $userIDs)
->where($db->quoteName('block') . ' = 0')
->where($db->quoteName('sendEmail') . ' = 1');
if (!empty($emails)) {
$lowerCaseEmails = array_map('strtolower', $emails);
$query->whereIn('LOWER(' . $db->quoteName('email') . ')', $lowerCaseEmails, ParameterType::STRING);
}
$db->setQuery($query);
$ret = $db->loadObjectList();
} catch (\Exception $exc) {
return $ret;
}
return $ret;
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>plg_task_updatenotification</name>
<author>Joomla! Project</author>
<creationDate>2023-07</creationDate>
<copyright>(C) 2023 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>5.0.0</version>
<description>PLG_TASK_UPDATENOTIFICATION_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\UpdateNotification</namespace>
<files>
<folder>forms</folder>
<folder plugin="updatenotification">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_updatenotification.ini</language>
<language tag="en-GB">language/en-GB/plg_task_updatenotification.sys.ini</language>
</languages>
</extension>