29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-06-20 11:05:08 +00:00

Followup work for the EOS plugin (#40652)

* Followup work for the EOS plugin

* short lines

* cs

* guest

* revert

* More checks

* debug

* more blind tests

* cs

* make PHP 7.2 compatible

* Improve docs

Signed-off-by: Allon Moritz <allon.moritz@digital-peak.com>

* More docs

* date

---------

Signed-off-by: Allon Moritz <allon.moritz@digital-peak.com>
This commit is contained in:
Allon Moritz 2023-05-25 21:23:27 +02:00 committed by GitHub
parent dd23e49c30
commit 18a29a6a4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,9 +12,9 @@ namespace Joomla\Plugin\Quickicon\Eos\Extension;
use Exception;
use Joomla\CMS\Access\Exception\NotAllowed;
use Joomla\CMS\Application\CMSWebApplicationInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Event\SubscriberInterface;
@ -34,12 +34,12 @@ final class Eos extends CMSPlugin implements SubscriberInterface
use DatabaseAwareTrait;
/**
* The EOS date for 4.4. and beyond
* The EOS date for 4.4.
*
* @var string
* @since __DEPLOY_VERSION__
*/
private const EOS_DATE = '2025-10-25';
private const EOS_DATE = '2025-10-17';
/**
* Load the language file on instantiation.
@ -50,21 +50,21 @@ final class Eos extends CMSPlugin implements SubscriberInterface
protected $autoloadLanguage = false;
/**
* Holding the current valid message to be shown
* Holding the current valid message to be shown.
*
* @var array
* @since __DEPLOY_VERSION__
*/
private array $currentMessage = [];
private $currentMessage = [];
/**
* Are the messages initialised
* Are the messages initialized.
*
* @var bool
* @since __DEPLOY_VERSION__
*/
private bool $messagesInitialized = false;
private $messagesInitialized = false;
/**
* Returns an array of events this subscriber will listen to.
@ -82,7 +82,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
}
/**
* Check and show the the alert and quickicon message
* Check and show the the alert and quickicon message.
*
* This method is called when the Quick Icons module is constructing its set
* of icons. You can return an array which defines a single icon and it will
@ -98,25 +98,42 @@ final class Eos extends CMSPlugin implements SubscriberInterface
*/
public function getEndOfServiceNotification(QuickIconsEvent $event): void
{
if ($event->getContext() !== $this->params->get('context', 'update_quickicon') || !$this->shouldDisplayMessage() || !$this->messagesInitialized && $this->setMessage() == []) {
$app = $this->getApplication();
if (
$event->getContext() !== $this->params->get('context', 'update_quickicon')
|| !$this->shouldDisplayMessage()
|| (!$this->messagesInitialized && $this->setMessage() == [])
|| !$app instanceof CMSWebApplicationInterface
) {
return;
}
$this->loadLanguage();
// Show this only when not snoozed
if ($this->params->get('last_snoozed_id', 0) < $this->currentMessage['id']) {
// Build the message to be displayed in the cpanel
$messageText = Text::sprintf($this->currentMessage['messageText'], HTMLHelper::_('date', Eos::EOS_DATE, Text::_('DATE_FORMAT_LC3')), $this->currentMessage['messageLink']);
$messageText = sprintf(
$app->getLanguage()->_($this->currentMessage['messageText']),
HTMLHelper::_('date', Eos::EOS_DATE, $app->getLanguage()->_('DATE_FORMAT_LC3')),
$this->currentMessage['messageLink']
);
if ($this->currentMessage['snoozable']) {
$messageText .= '<p><button class="btn btn-warning eosnotify-snooze-btn" type="button" >' . Text::_('PLG_QUICKICON_EOS_SNOOZE_BUTTON') . '</button></p>';
$messageText .= '<p><button class="btn btn-warning eosnotify-snooze-btn" type="button" >';
$messageText .= $app->getLanguage()->_('PLG_QUICKICON_EOS_SNOOZE_BUTTON') . '</button></p>';
}
$this->getApplication()->enqueueMessage($messageText, $this->currentMessage['messageType']);
$app->enqueueMessage($messageText, $this->currentMessage['messageType']);
}
$this->getApplication()->getDocument()->getWebAssetManager()->registerAndUseScript('plg_quickicon_eos.script', 'plg_quickicon_eos/snooze.js', [], ['type' => 'module']);
$app->getDocument()->getWebAssetManager()
->registerAndUseScript('plg_quickicon_eos.script', 'plg_quickicon_eos/snooze.js', [], ['type' => 'module']);
$result = $event->getArgument('result', []);
$messageTextQuickIcon = Text::sprintf($this->currentMessage['quickiconText'], HTMLHelper::_('date', Eos::EOS_DATE, Text::_('DATE_FORMAT_LC3')));
$messageTextQuickIcon = sprintf(
$app->getLanguage()->_($this->currentMessage['quickiconText']),
HTMLHelper::_('date', Eos::EOS_DATE, $app->getLanguage()->_('DATE_FORMAT_LC3'))
);
// The message as quickicon
@ -135,7 +152,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
}
/**
* Save the plugin parameters
* Save the plugin parameters.
*
* @return bool
*
@ -157,7 +174,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
}
/**
* Determines if the message and quickicon should be displayed
* Determines if the message and quickicon should be displayed.
*
* @return bool
*
@ -167,16 +184,18 @@ final class Eos extends CMSPlugin implements SubscriberInterface
*/
private function shouldDisplayMessage(): bool
{
return !$this->getApplication()->isClient('administrator')
|| $this->getApplication()->getIdentity()->guest
|| $this->getApplication()->getDocument()->getType() !== 'html'
|| $this->getApplication()->getInput()->getCmd('tmpl', 'index') === 'component'
|| $this->getApplication()->getInput()->get('option') !== 'com_cpanel'
? false : true;
// Show only on administration part
return $this->getApplication()->isClient('administrator')
// Only show for HTML requests
&& $this->getApplication()->getDocument()->getType() === 'html'
// Don't show in modal
&& $this->getApplication()->getInput()->getCmd('tmpl', 'index') !== 'component'
// Only show in cpanel
&& $this->getApplication()->getInput()->get('option') === 'com_cpanel';
}
/**
* Return the texts to be displayed based on the time until we reach EOS
* Return the texts to be displayed based on the time until we reach EOS.
*
* @param int $monthsUntilEOS The months until we reach EOS
* @param int $inverted Have we surpassed the EOS date
@ -200,6 +219,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
'snoozable' => false,
];
}
// The security support is ending in 6 months
if ($monthsUntilEOS < 6) {
return [
@ -213,6 +233,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
'snoozable' => true,
];
}
// We are in security only mode now, 12 month to go from now on
if ($monthsUntilEOS < 12) {
return [
@ -226,6 +247,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
'snoozable' => true,
];
}
// We still have 16 month to go, lets remind our users about the pre upgrade checker
if ($monthsUntilEOS < 16) {
return [
@ -239,6 +261,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
'snoozable' => true,
];
}
// Lets start our messages 2 month after the initial release, still 22 month to go
if ($monthsUntilEOS < 22) {
return [
@ -257,7 +280,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
}
/**
* Check if current user is allowed to send the data
* Check if current user is allowed to send the data.
*
* @return bool
*
@ -271,13 +294,13 @@ final class Eos extends CMSPlugin implements SubscriberInterface
}
/**
* User hit the snooze button
* User hit the snooze button.
*
* @return string
*
* @since __DEPLOY_VERSION__
*
* @throws Notallowed If user is not allowed.
* @throws Notallowed If user is not allowed
*
* @throws Exception
*/
@ -287,9 +310,11 @@ final class Eos extends CMSPlugin implements SubscriberInterface
if (!$this->messagesInitialized && $this->setMessage() == []) {
return '';
}
if (!$this->isAllowedUser()) {
throw new Notallowed(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'), 403);
throw new Notallowed($this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_ACCESS_DENIED'), 403);
}
// Make sure only snoozable messages can be snoozed
if ($this->currentMessage['snoozable']) {
$this->params->set('last_snoozed_id', $this->currentMessage['id']);
@ -300,9 +325,7 @@ final class Eos extends CMSPlugin implements SubscriberInterface
}
/**
* setMessage
*
* Calculates how many days and selects correct message
* Calculates how many days and selects correct message.
*
* @return array
*