Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Convert mod_privacy_status to service provider #44752

Open
wants to merge 11 commits into
base: 5.3-dev
Choose a base branch
from
41 changes: 0 additions & 41 deletions administrator/modules/mod_privacy_status/mod_privacy_status.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>MOD_PRIVACY_STATUS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\PrivacyStatus</namespace>
<files>
<filename module="mod_privacy_status">mod_privacy_status.php</filename>
<folder module="mod_privacy_status">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
41 changes: 41 additions & 0 deletions administrator/modules/mod_privacy_status/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage mod_privacy_status
*
* @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 privacy status 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)
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\PrivacyStatus'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\PrivacyStatus\\Administrator\\Helper'));

$container->registerServiceProvider(new Module());
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage mod_privacy_status
*
* @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\PrivacyStatus\Administrator\Dispatcher;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
use Joomla\Component\Privacy\Administrator\Helper\PrivacyHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Dispatcher class for mod_privacy_status
*
* @since __DEPLOY_VERSION__
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;

/**
* Runs the dispatcher.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function dispatch()
{
$app = $this->getApplication();

// Only super user can view this data
if (!$app->getIdentity()->authorise('core.admin')) {
return;
}

// Boot component to ensure HTML helpers are loaded
$app->bootComponent('com_privacy');

// Load the privacy component language file.
$lang = $app->getLanguage();
$lang->load('com_privacy', JPATH_ADMINISTRATOR)
|| $lang->load('com_privacy', JPATH_ADMINISTRATOR . '/components/com_privacy');

parent::dispatch();
}

/**
* Returns the layout data.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();

$app = $this->getApplication();
$privacyStatusHelper = $this->getHelperFactory()->getHelper('PrivacyStatusHelper');

$data['privacyPolicyInfo'] = $privacyStatusHelper->getPrivacyPolicyMenuStatus();
$data['requestFormPublished'] = $privacyStatusHelper->getRequestFormMenuStatus();
$data['privacyConsentPluginId'] = PrivacyHelper::getPrivacyConsentPluginId();
$data['sendMailEnabled'] = (bool) $app->get('mailonline', 1);
$data['numberOfUrgentRequests'] = $privacyStatusHelper->getUrgentRequestsNumber();
$data['urgentRequestDays'] = (int) ComponentHelper::getParams('com_privacy')->get('notify', 14);
$data['databaseConnectionEncryption'] = $privacyStatusHelper->getEncryption();

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\Database\DatabaseAwareInterface;
use Joomla\Database\DatabaseAwareTrait;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -26,16 +28,18 @@
*
* @since 4.0.0
*/
class PrivacyStatusHelper
class PrivacyStatusHelper implements DatabaseAwareInterface
{
use DatabaseAwareTrait;

/**
* Get the information about the published privacy policy
*
* @return array Array containing a status of whether a privacy policy is set and a link to the policy document for editing
*
* @since 4.0.0
* @since __DEPLOY_VERSION__
*/
public static function getPrivacyPolicyInfo()
public function getPrivacyPolicyMenuStatus()
joomlaweby marked this conversation as resolved.
Show resolved Hide resolved
joomlaweby marked this conversation as resolved.
Show resolved Hide resolved
{
$dispatcher = Factory::getApplication()->getDispatcher();
$policy = [
Expand Down Expand Up @@ -64,9 +68,10 @@ public static function getPrivacyPolicyInfo()
*
* @return array Array containing a status of whether a menu is published for the request form and its current link
*
* @since 4.0.0
* @since __DEPLOY_VERSION__
*
*/
public static function getRequestFormPublished()
public function getRequestFormMenuStatus()
{
$status = [
'exists' => false,
Expand All @@ -75,7 +80,7 @@ public static function getRequestFormPublished()
];
$lang = '';

$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select(
[
Expand Down Expand Up @@ -119,7 +124,6 @@ public static function getRequestFormPublished()
$params = ComponentHelper::getParams('com_languages');
$defaultSiteLanguage = $params->get('site');

$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__menu'))
Expand Down Expand Up @@ -153,17 +157,17 @@ public static function getRequestFormPublished()
*
* @return integer
*
* @since 4.0.0
* @since __DEPLOY_VERSION__
*/
public static function getNumberUrgentRequests()
public function getUrgentRequestsNumber()
joomlaweby marked this conversation as resolved.
Show resolved Hide resolved
{
// Load the parameters.
$params = ComponentHelper::getComponent('com_privacy')->getParams();
$notify = (int) $params->get('notify', 14);
$now = Factory::getDate()->toSql();
$period = '-' . $notify;

$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select('COUNT(*)')
->from($db->quoteName('#__privacy_requests'))
Expand All @@ -177,4 +181,70 @@ public static function getNumberUrgentRequests()

return (int) $db->loadResult();
}

/**
* Method to return database encryption details
*
* @return string The database encryption details
*
* @since __DEPLOY_VERSION__
*/
public function getEncryption()
joomlaweby marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->getDatabase()->getConnectionEncryption();
}

/**
* Get the information about the published privacy policy
*
* @return array Array containing a status of whether a privacy policy is set and a link to the policy document for editing
*
* @since 4.0.0
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getPrivacyPolicyMenuStatus
* Example: Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
* ->getHelper('PrivacyStatusHelper')
* ->getPrivacyPolicyMenuStatus()
*/
public static function getPrivacyPolicyInfo()
{
return (new self())->getPrivacyPolicyMenuStatus();
joomlaweby marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Check whether there is a menu item for the request form
*
* @return array Array containing a status of whether a menu is published for the request form and its current link
*
* @since 4.0.0
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getRequestFormMenuStatus
* Example: Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
* ->getHelper('PrivacyStatusHelper')
* ->getRequestFormMenuStatus()
*/
public static function getRequestFormPublished()
{
return (new self())->getRequestFormMenuStatus();
}

/**
* Method to return number privacy requests older than X days.
*
* @return integer
*
* @since 4.0.0
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getUrgentRequestsNumber
* Example: Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
* ->getHelper('PrivacyStatusHelper')
* ->getUrgentRequestsNumber()
*/
public static function getNumberUrgentRequests()
{
return (new self())->getUrgentRequestsNumber();
}
}