JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

End of Support Plugin for Joomla 4.4 #350

Closed joomlapl-bot closed 10 months ago

joomlapl-bot commented 1 year ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/40565 Poniżej zmiany w oryginale:

Click to expand the diff! ```diff diff --git a/administrator/components/com_admin/sql/updates/mysql/4.4.0-2023-05-08.sql b/administrator/components/com_admin/sql/updates/mysql/4.4.0-2023-05-08.sql new file mode 100644 index 000000000000..4c621665e1d7 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/4.4.0-2023-05-08.sql @@ -0,0 +1,2 @@ +INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES + (0, 'plg_quickicon_eos', 'plugin', 'eos', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 7, 0); diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.4.0-2023-05-08.sql b/administrator/components/com_admin/sql/updates/postgresql/4.4.0-2023-05-08.sql new file mode 100644 index 000000000000..46f7bf62de40 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/4.4.0-2023-05-08.sql @@ -0,0 +1,2 @@ +INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES + (0, 'plg_quickicon_eos', 'plugin', 'eos', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 7, 0); diff --git a/administrator/language/en-GB/plg_quickicon_eos.ini b/administrator/language/en-GB/plg_quickicon_eos.ini new file mode 100644 index 000000000000..f4af7d0ce768 --- /dev/null +++ b/administrator/language/en-GB/plg_quickicon_eos.ini @@ -0,0 +1,39 @@ +; Joomla! Project +; (C) 2023 Open Source Matters, Inc. +; License GNU General Public License version 2 or later; see LICENSE.txt +; Note : All ini files need to be saved as UTF-8 + +PLG_QUICKICON_EOS="Quick Icon - Joomla! End Of Support Notification" +PLG_QUICKICON_EOS_GROUPNAME_EOS="End Of Support" +PLG_QUICKICON_EOS_GROUPNAME_INFO="Upgrade Information" +PLG_QUICKICON_EOS_GROUPNAME_WARNING="Support Status" +PLG_QUICKICON_EOS_MESSAGE_ERROR_SUPPORT_ENDED="

Support has ended for your version of Joomla. Migrate to the next version as soon as possible.

" +PLG_QUICKICON_EOS_MESSAGE_ERROR_SUPPORT_ENDED_SHORT="Support has ended for your version of Joomla " +PLG_QUICKICON_EOS_MESSAGE_INFO_01="

The latest version of Joomla has arrived! Find out all that it has to offer you. Check the landing page for its features and improvements.

" +PLG_QUICKICON_EOS_MESSAGE_INFO_01_SHORT="The latest version of Joomla has arrived! " +PLG_QUICKICON_EOS_MESSAGE_INFO_02="

When is the time to migrate to the next version? Once the extensions your site needs are compatible. Learn how to use the Pre-Update Checker.

" +PLG_QUICKICON_EOS_MESSAGE_INFO_02_SHORT="Use Pre-Update Check for extension compatibility " +PLG_QUICKICON_EOS_MESSAGE_WARNING_SECURITY_ONLY="

This version of Joomla has entered security only mode. Support ends %1$s. Start planning to migrate to the next version of Joomla today.

" +PLG_QUICKICON_EOS_MESSAGE_WARNING_SECURITY_ONLY_SHORT="This version of Joomla ends support on %1$s. " +PLG_QUICKICON_EOS_MESSAGE_WARNING_SUPPORT_ENDING="

Support ends on %1$s for this version of Joomla. Migrate to the latest version of Joomla as soon as possible.

" +PLG_QUICKICON_EOS_MESSAGE_WARNING_SUPPORT_ENDING_SHORT="End of support for this version of Joomla on %1$s. " +PLG_QUICKICON_EOS_SNOOZE_BUTTON="Snooze this message for all users" +PLG_QUICKICON_EOS_XML_DESCRIPTION="Checks for the end of support status of Joomla and notifies you when visiting the Control Panel page." +; Below is a copy of the 3.10 text definitions for reference. +PLG_QUICKICON_EOS310="Quick Icon - Joomla 3.10 End Of Support Notification" +PLG_QUICKICON_EOS310_GROUPNAME_EOS="End Of Support" +PLG_QUICKICON_EOS310_GROUPNAME_INFO="Upgrade Information" +PLG_QUICKICON_EOS310_GROUPNAME_WARNING="Support Status" +PLG_QUICKICON_EOS310_MESSAGE_ERROR_SUPPORT_ENDED="

Support has ended for your version of Joomla 3.10. Migrate to Joomla 4 as soon as possible.

" +PLG_QUICKICON_EOS310_MESSAGE_ERROR_SUPPORT_ENDED_SHORT="Support has ended for Joomla 3.10 " +PLG_QUICKICON_EOS310_MESSAGE_INFO_01="

Joomla 4 has arrived! Find out all that Joomla 4 has to offer you. Check the landing page for Joomla 4 features and improvements.

" +PLG_QUICKICON_EOS310_MESSAGE_INFO_01_SHORT="Joomla 4 has arrived! " +PLG_QUICKICON_EOS310_MESSAGE_INFO_02="

When is the time to migrate to Joomla 4? Once the extensions your site needs are compatible. Learn how to use the Pre-Update Checker.

" +PLG_QUICKICON_EOS310_MESSAGE_INFO_02_SHORT="Use Pre-Update Check for extension compatibility " +PLG_QUICKICON_EOS310_MESSAGE_WARNING_SECURITY_ONLY="

Joomla 3.10 has entered security only mode. Support ends %1$s. Start planning to migrate to Joomla 4 today.

" +PLG_QUICKICON_EOS310_MESSAGE_WARNING_SECURITY_ONLY_SHORT="Joomla 3.10 to end support on %1$s. " +PLG_QUICKICON_EOS310_MESSAGE_WARNING_SUPPORT_ENDING="

Support ends on %1$s for Joomla 3.10. Migrate to Joomla 4 as soon as possible.

" +PLG_QUICKICON_EOS310_MESSAGE_WARNING_SUPPORT_ENDING_SHORT="End of support for Joomla 3.10 on %1$s. " +PLG_QUICKICON_EOS310_SNOOZE_BUTTON="Snooze this message for all users" +PLG_QUICKICON_EOS310_XML_DESCRIPTION="Checks for the end of support status of Joomla 3.10 and notifies you when visiting the Control Panel page." +;All of this text is currently being written for Joomla 5 by Phil Watson and Jenn Gress. TODO diff --git a/administrator/language/en-GB/plg_quickicon_eos.sys.ini b/administrator/language/en-GB/plg_quickicon_eos.sys.ini new file mode 100644 index 000000000000..9e3b85198e25 --- /dev/null +++ b/administrator/language/en-GB/plg_quickicon_eos.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; (C) 2023 Open Source Matters, Inc. +; License GNU General Public License version 2 or later; see LICENSE.txt +; Note : All ini files need to be saved as UTF-8 + +PLG_QUICKICON_EOS="Quick Icon - Joomla! End Of Support Notification" +PLG_QUICKICON_EOS_XML_DESCRIPTION="Checks for the end of support status of Joomla and places a notification on the Control Panel page." diff --git a/build/media_source/plg_quickicon_eos/js/snooze.es6.js b/build/media_source/plg_quickicon_eos/js/snooze.es6.js new file mode 100644 index 000000000000..cda59294cbbc --- /dev/null +++ b/build/media_source/plg_quickicon_eos/js/snooze.es6.js @@ -0,0 +1,37 @@ +/** + * @package Joomla.Plugin + * @subpackage Quickicon.eos + * @copyright (C) 2023 Open Source Matters, Inc. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ +if (!Joomla) { + throw new Error('Joomla API is not properly initialised'); +} + +const url = new URL(`${Joomla.getOptions('system.paths').baseFull}index.php?option=com_ajax&group=quickicon&plugin=eos&format=json`); + +async function onMutatedMessagesContainer(mutationList, observer) { + // eslint-disable-next-line no-restricted-syntax + for (const mutation of mutationList) { + const nodes = Array.from(mutation.addedNodes); + if (!nodes.length) { + return; + } + + const alerts = nodes.filter((node) => node.querySelector('.eosnotify-snooze-btn')); + if (!alerts.length) { + return; + } + + observer.disconnect(); + alerts[0].querySelector('.eosnotify-snooze-btn').addEventListener('click', () => fetch(url, { headers: { 'X-CSRF-Token': Joomla.getOptions('csrf.token') || '' } }) + .then((response) => { + if (response.ok) { + alerts[0].closest('joomla-alert').close(); + } + })); + } +} + +const observer = new MutationObserver(onMutatedMessagesContainer); +observer.observe(document.querySelector('#system-message-container'), { attributes: false, childList: true, subtree: true }); diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index 6cbe27732c7c..2757cd2a5b39 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -328,6 +328,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_quickicon_downloadkey', 'plugin', 'downloadkey', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 4, 0), (0, 'plg_quickicon_privacycheck', 'plugin', 'privacycheck', 'quickicon', 0, 1, 1, 0, 1, '', '{}', '', 5, 0), (0, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 6, 0), +(0, 'plg_quickicon_eos', 'plugin', 'eos', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 7, 0), (0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 1, 0), (0, 'plg_sampledata_multilang', 'plugin', 'multilang', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 2, 0), (0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', '', 1, 0), diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index eaf4db92ad35..3cab39bfccc6 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -334,6 +334,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_quickicon_downloadkey', 'plugin', 'downloadkey', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 4, 0), (0, 'plg_quickicon_privacycheck', 'plugin', 'privacycheck', 'quickicon', 0, 1, 1, 0, 1, '', '{}', '', 5, 0), (0, 'plg_quickicon_phpversioncheck', 'plugin', 'phpversioncheck', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 6, 0), +(0, 'plg_quickicon_eos', 'plugin', 'eos', 'quickicon', 0, 1, 1, 0, 1, '', '', '', 7, 0), (0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 1, 0), (0, 'plg_sampledata_multilang', 'plugin', 'multilang', 'sampledata', 0, 1, 1, 0, 1, '', '', '', 2, 0), (0, 'plg_system_accessibility', 'plugin', 'accessibility', 'system', 0, 0, 1, 0, 1, '', '{}', '', 1, 0), diff --git a/libraries/src/Extension/ExtensionHelper.php b/libraries/src/Extension/ExtensionHelper.php index aec5e4eb2c34..167ef57a3142 100644 --- a/libraries/src/Extension/ExtensionHelper.php +++ b/libraries/src/Extension/ExtensionHelper.php @@ -273,6 +273,7 @@ class ExtensionHelper ['plugin', 'overridecheck', 'quickicon', 0], ['plugin', 'phpversioncheck', 'quickicon', 0], ['plugin', 'privacycheck', 'quickicon', 0], + ['plugin', 'eos', 'quickicon', 0], // Core plugin extensions - sample data ['plugin', 'blog', 'sampledata', 0], diff --git a/plugins/quickicon/eos/eos.xml b/plugins/quickicon/eos/eos.xml new file mode 100644 index 000000000000..e0f325e1aa16 --- /dev/null +++ b/plugins/quickicon/eos/eos.xml @@ -0,0 +1,31 @@ + + + plg_quickicon_eos + Joomla! Project + 2023-05 + (C) 2023 Open Source Matters, Inc. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 4.4.0 + PLG_QUICKICON_EOS_XML_DESCRIPTION + Joomla\Plugin\Quickicon\Eos + + services + src + + + language/en-GB/plg_quickicon_eos.ini + language/en-GB/plg_quickicon_eos.sys.ini + + + +
+ +
+
+
+
diff --git a/plugins/quickicon/eos/services/provider.php b/plugins/quickicon/eos/services/provider.php new file mode 100644 index 000000000000..5d8413f769b3 --- /dev/null +++ b/plugins/quickicon/eos/services/provider.php @@ -0,0 +1,51 @@ + + * @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\Quickicon\Eos\Extension\Eos; + +return new class () implements ServiceProviderInterface { + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * + * @since __DEPLOY_VERSION__ + * + * @throws Exception + */ + public function register(Container $container): void + { + $container->set( + PluginInterface::class, + function (Container $container) { + $dispatcher = $container->get(DispatcherInterface::class); + $plugin = new Eos( + $dispatcher, + (array) PluginHelper::getPlugin('quickicon', 'eos') + ); + $plugin->setApplication(Factory::getApplication()); + $plugin->setDatabase($container->get(DatabaseInterface::class)); + + return $plugin; + } + ); + } +}; diff --git a/plugins/quickicon/eos/src/Extension/Eos.php b/plugins/quickicon/eos/src/Extension/Eos.php new file mode 100644 index 000000000000..d60335583eed --- /dev/null +++ b/plugins/quickicon/eos/src/Extension/Eos.php @@ -0,0 +1,320 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\Plugin\Quickicon\Eos\Extension; + +use Exception; +use Joomla\CMS\Access\Exception\NotAllowed; +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; +use Joomla\Module\Quickicon\Administrator\Event\QuickIconsEvent; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * Joomla! end of support notification plugin + * + * @since __DEPLOY_VERSION__ + */ +final class Eos extends CMSPlugin implements SubscriberInterface +{ + use DatabaseAwareTrait; + + /** + * The EOS date for 4.4. and beyond + * + * @var string + * @since __DEPLOY_VERSION__ + */ + private const EOS_DATE = '2025-10-25'; + + /** + * Load the language file on instantiation. + * + * @var bool + * @since __DEPLOY_VERSION__ + */ + protected $autoloadLanguage = false; + + /** + * Holding the current valid message to be shown + * + * @var array + * @since __DEPLOY_VERSION__ + */ + private array $currentMessage = []; + + /** + * Are the messages initialised + * + * @var bool + * @since __DEPLOY_VERSION__ + */ + + private bool $messagesInitialized = false; + + /** + * Returns an array of events this subscriber will listen to. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public static function getSubscribedEvents(): array + { + return [ + 'onGetIcons' => 'getEndOfServiceNotification', + 'onAjaxEos' => 'onAjaxEos', + ]; + } + + /** + * 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 + * be rendered right after the stock Quick Icons. + * + * @param QuickIconsEvent $event The event object + * + * @return void + * + * @since __DEPLOY_VERSION__ + * + * @throws Exception + */ + public function getEndOfServiceNotification(QuickIconsEvent $event): void + { + if ($event->getContext() !== $this->params->get('context', 'update_quickicon') || !$this->shouldDisplayMessage() || !$this->messagesInitialized && $this->setMessage() == []) { + 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']); + if ($this->currentMessage['snoozable']) { + $messageText .= '

'; + } + $this->getApplication()->enqueueMessage($messageText, $this->currentMessage['messageType']); + } + + $this->getApplication()->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'))); + + // The message as quickicon + + $result[] = [ + [ + 'link' => $this->currentMessage['messageLink'], + 'image' => $this->currentMessage['image'], + 'text' => $messageTextQuickIcon, + 'id' => 'plg_quickicon_eos', + 'group' => $this->currentMessage['groupText'], + 'class' => $this->currentMessage['messageType'], + ], + ]; + + $event->setArgument('result', $result); + } + + /** + * Save the plugin parameters + * + * @return bool + * + * @since __DEPLOY_VERSION__ + */ + private function saveParams(): bool + { + $params = $this->params->toString('JSON'); + $db = $this->getDatabase(); + $query = $db->getQuery(true) + ->update($db->quoteName('#__extensions')) + ->set($db->quoteName('params') . ' = :params') + ->where($db->quoteName('type') . ' = ' . $db->quote('plugin')) + ->where($db->quoteName('folder') . ' = ' . $db->quote('quickicon')) + ->where($db->quoteName('element') . ' = ' . $db->quote('eos')) + ->bind(':params', $params); + + return $db->setQuery($query)->execute(); + } + + /** + * Determines if the message and quickicon should be displayed + * + * @return bool + * + * @since __DEPLOY_VERSION__ + * + * @throws Exception + */ + 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; + } + + /** + * 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 + * + * @return array An array with the message to be displayed or false + * + * @since __DEPLOY_VERSION__ + */ + private function getMessageInfo(int $monthsUntilEOS, int $inverted): array + { + // The EOS date has passed - Support has ended + if ($inverted === 1) { + return [ + 'id' => 5, + 'messageText' => 'PLG_QUICKICON_EOS_MESSAGE_ERROR_SUPPORT_ENDED', + 'quickiconText' => 'PLG_QUICKICON_EOS_MESSAGE_ERROR_SUPPORT_ENDED_SHORT', + 'messageType' => 'error', + 'image' => 'fa fa-life-ring', + 'messageLink' => 'https://docs.joomla.org/Special:MyLanguage/Planning_for_Mini-Migration_-_Joomla_3.10.x_to_4.x', + 'groupText' => 'PLG_QUICKICON_EOS_GROUPNAME_EOS', + 'snoozable' => false, + ]; + } + // The security support is ending in 6 months + if ($monthsUntilEOS < 6) { + return [ + 'id' => 4, + 'messageText' => 'PLG_QUICKICON_EOS_MESSAGE_WARNING_SUPPORT_ENDING', + 'quickiconText' => 'PLG_QUICKICON_EOS_MESSAGE_WARNING_SUPPORT_ENDING_SHORT', + 'messageType' => 'warning', + 'image' => 'fa fa-life-ring', + 'messageLink' => 'https://docs.joomla.org/Special:MyLanguage/Planning_for_Mini-Migration_-_Joomla_3.10.x_to_4.x', + 'groupText' => 'PLG_QUICKICON_EOS_GROUPNAME_WARNING', + 'snoozable' => true, + ]; + } + // We are in security only mode now, 12 month to go from now on + if ($monthsUntilEOS < 12) { + return [ + 'id' => 3, + 'messageText' => 'PLG_QUICKICON_EOS_MESSAGE_WARNING_SECURITY_ONLY', + 'quickiconText' => 'PLG_QUICKICON_EOS_MESSAGE_WARNING_SECURITY_ONLY_SHORT', + 'messageType' => 'warning', + 'image' => 'fa fa-life-ring', + 'messageLink' => 'https://docs.joomla.org/Special:MyLanguage/Planning_for_Mini-Migration_-_Joomla_3.10.x_to_4.x', + 'groupText' => 'PLG_QUICKICON_EOS_GROUPNAME_WARNING', + 'snoozable' => true, + ]; + } + // We still have 16 month to go, lets remind our users about the pre upgrade checker + if ($monthsUntilEOS < 16) { + return [ + 'id' => 2, + 'messageText' => 'PLG_QUICKICON_EOS_MESSAGE_INFO_02', + 'quickiconText' => 'PLG_QUICKICON_EOS_MESSAGE_INFO_02_SHORT', + 'messageType' => 'info', + 'image' => 'fa fa-life-ring', + 'messageLink' => 'https://docs.joomla.org/Special:MyLanguage/Pre-Update_Check', + 'groupText' => 'PLG_QUICKICON_EOS_GROUPNAME_INFO', + 'snoozable' => true, + ]; + } + // Lets start our messages 2 month after the initial release, still 22 month to go + if ($monthsUntilEOS < 22) { + return [ + 'id' => 1, + 'messageText' => 'PLG_QUICKICON_EOS_MESSAGE_INFO_01', + 'quickiconText' => 'PLG_QUICKICON_EOS_MESSAGE_INFO_01_SHORT', + 'messageType' => 'info', + 'image' => 'fa fa-life-ring', + 'messageLink' => 'https://www.joomla.org/4/#features', + 'groupText' => 'PLG_QUICKICON_EOS_GROUPNAME_INFO', + 'snoozable' => true, + ]; + } + + return []; + } + + /** + * Check if current user is allowed to send the data + * + * @return bool + * + * @since __DEPLOY_VERSION__ + * + * @throws Exception + */ + private function isAllowedUser(): bool + { + return $this->getApplication()->getIdentity()->authorise('core.login.admin'); + } + + /** + * User hit the snooze button + * + * @return string + * + * @since __DEPLOY_VERSION__ + * + * @throws Notallowed If user is not allowed. + * + * @throws Exception + */ + public function onAjaxEos(): string + { + // No messages yet so nothing to snooze + if (!$this->messagesInitialized && $this->setMessage() == []) { + return ''; + } + if (!$this->isAllowedUser()) { + throw new Notallowed(Text::_('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']); + $this->saveParams(); + } + + return ''; + } + + /** + * setMessage + * + * Calculates how many days and selects correct message + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + private function setMessage(): array + { + $diff = Factory::getDate()->diff(Factory::getDate(Eos::EOS_DATE)); + $message = $this->getMessageInfo(floor($diff->days / 30.417), $diff->invert); + $this->currentMessage = $message; + $this->messagesInitialized = true; + + return $message; + } +} ```