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->getPrivacyPolicyInformation($app);
$data['requestFormPublished'] = $privacyStatusHelper->getRequestFormMenuStatus($app);
$data['privacyConsentPluginId'] = PrivacyHelper::getPrivacyConsentPluginId();
$data['sendMailEnabled'] = (bool) $app->get('mailonline', 1);
$data['numberOfUrgentRequests'] = $privacyStatusHelper->getNumberOfUrgentRequests();
$data['urgentRequestDays'] = (int) ComponentHelper::getParams('com_privacy')->get('notify', 14);
$data['databaseConnectionEncryption'] = $privacyStatusHelper->getDatabaseConnectionEncryption();

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

namespace Joomla\Module\PrivacyStatus\Administrator\Helper;

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Privacy\CheckPrivacyPolicyPublishedEvent;
use Joomla\CMS\Factory;
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,18 +29,22 @@
*
* @since 4.0.0
*/
class PrivacyStatusHelper
class PrivacyStatusHelper implements DatabaseAwareInterface
{
use DatabaseAwareTrait;

/**
* Get the information about the published privacy policy
*
* @param CMSApplicationInterface $app The application
*
* @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 getPrivacyPolicyInformation(CMSApplicationInterface $app)
{
$dispatcher = Factory::getApplication()->getDispatcher();
$dispatcher = $app->getDispatcher();
$policy = [
'published' => false,
'articlePublished' => false,
Expand All @@ -62,11 +69,14 @@ public static function getPrivacyPolicyInfo()
/**
* Check whether there is a menu item for the request form
*
* @param CMSApplicationInterface $app The application
*
* @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(CMSApplicationInterface $app)
{
$status = [
'exists' => false,
Expand All @@ -75,7 +85,7 @@ public static function getRequestFormPublished()
];
$lang = '';

$db = Factory::getDbo();
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select(
[
Expand Down Expand Up @@ -111,15 +121,14 @@ public static function getRequestFormPublished()
}
}

$linkMode = Factory::getApplication()->get('force_ssl', 0) == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE;
$linkMode = $app->get('force_ssl', 0) == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE;

if (!$menuItem) {
if (Multilanguage::isEnabled()) {
// Find the Itemid of the home menu item tagged to the site default language
$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 +162,17 @@ public static function getRequestFormPublished()
*
* @return integer
*
* @since 4.0.0
* @since __DEPLOY_VERSION__
*/
public static function getNumberUrgentRequests()
public function getNumberOfUrgentRequests()
{
// 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 +186,82 @@ 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 getDatabaseConnectionEncryption()
{
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 getPrivacyPolicyInformation
* Example: Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
* ->getHelper('PrivacyStatusHelper')
* ->getPrivacyPolicyInformation(Factory::getApplication())
*/
public static function getPrivacyPolicyInfo()
{
$app = Factory::getApplication();

return $app->bootModule('mod_privacy_status', 'administrator')
->getHelper('PrivacyStatusHelper')
->getPrivacyPolicyInformation($app);
}

/**
* 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(Factory::getApplication())
*/
public static function getRequestFormPublished()
{
$app = Factory::getApplication();

return $app->bootModule('mod_privacy_status', 'administrator')
->getHelper('PrivacyStatusHelper')
->getRequestFormMenuStatus($app);
}

/**
* 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 getNumberOfUrgentRequests
* Example: Factory::getApplication()->bootModule('mod_privacy_status', 'administrator')
* ->getHelper('PrivacyStatusHelper')
* ->getNumberOfUrgentRequests()
*/
public static function getNumberUrgentRequests()
{
$app = Factory::getApplication();

return $app->bootModule('mod_privacy_status', 'administrator')
->getHelper('PrivacyStatusHelper')
->getNumberOfUrgentRequests();
joomlaweby marked this conversation as resolved.
Show resolved Hide resolved
}
}