Skip to content

Commit 18a29a6

Browse files
authored
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 <[email protected]> * More docs * date --------- Signed-off-by: Allon Moritz <[email protected]>
1 parent dd23e49 commit 18a29a6

File tree

1 file changed

+53
-30
lines changed
  • plugins/quickicon/eos/src/Extension

1 file changed

+53
-30
lines changed

plugins/quickicon/eos/src/Extension/Eos.php

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
use Exception;
1414
use Joomla\CMS\Access\Exception\NotAllowed;
15+
use Joomla\CMS\Application\CMSWebApplicationInterface;
1516
use Joomla\CMS\Factory;
1617
use Joomla\CMS\HTML\HTMLHelper;
17-
use Joomla\CMS\Language\Text;
1818
use Joomla\CMS\Plugin\CMSPlugin;
1919
use Joomla\Database\DatabaseAwareTrait;
2020
use Joomla\Event\SubscriberInterface;
@@ -34,12 +34,12 @@ final class Eos extends CMSPlugin implements SubscriberInterface
3434
use DatabaseAwareTrait;
3535

3636
/**
37-
* The EOS date for 4.4. and beyond
37+
* The EOS date for 4.4.
3838
*
3939
* @var string
4040
* @since __DEPLOY_VERSION__
4141
*/
42-
private const EOS_DATE = '2025-10-25';
42+
private const EOS_DATE = '2025-10-17';
4343

4444
/**
4545
* Load the language file on instantiation.
@@ -50,21 +50,21 @@ final class Eos extends CMSPlugin implements SubscriberInterface
5050
protected $autoloadLanguage = false;
5151

5252
/**
53-
* Holding the current valid message to be shown
53+
* Holding the current valid message to be shown.
5454
*
5555
* @var array
5656
* @since __DEPLOY_VERSION__
5757
*/
58-
private array $currentMessage = [];
58+
private $currentMessage = [];
5959

6060
/**
61-
* Are the messages initialised
61+
* Are the messages initialized.
6262
*
6363
* @var bool
6464
* @since __DEPLOY_VERSION__
6565
*/
6666

67-
private bool $messagesInitialized = false;
67+
private $messagesInitialized = false;
6868

6969
/**
7070
* Returns an array of events this subscriber will listen to.
@@ -82,7 +82,7 @@ public static function getSubscribedEvents(): array
8282
}
8383

8484
/**
85-
* Check and show the the alert and quickicon message
85+
* Check and show the the alert and quickicon message.
8686
*
8787
* This method is called when the Quick Icons module is constructing its set
8888
* of icons. You can return an array which defines a single icon and it will
@@ -98,25 +98,42 @@ public static function getSubscribedEvents(): array
9898
*/
9999
public function getEndOfServiceNotification(QuickIconsEvent $event): void
100100
{
101-
if ($event->getContext() !== $this->params->get('context', 'update_quickicon') || !$this->shouldDisplayMessage() || !$this->messagesInitialized && $this->setMessage() == []) {
101+
$app = $this->getApplication();
102+
103+
if (
104+
$event->getContext() !== $this->params->get('context', 'update_quickicon')
105+
|| !$this->shouldDisplayMessage()
106+
|| (!$this->messagesInitialized && $this->setMessage() == [])
107+
|| !$app instanceof CMSWebApplicationInterface
108+
) {
102109
return;
103110
}
111+
104112
$this->loadLanguage();
105113

106114
// Show this only when not snoozed
107115
if ($this->params->get('last_snoozed_id', 0) < $this->currentMessage['id']) {
108116
// Build the message to be displayed in the cpanel
109-
$messageText = Text::sprintf($this->currentMessage['messageText'], HTMLHelper::_('date', Eos::EOS_DATE, Text::_('DATE_FORMAT_LC3')), $this->currentMessage['messageLink']);
117+
$messageText = sprintf(
118+
$app->getLanguage()->_($this->currentMessage['messageText']),
119+
HTMLHelper::_('date', Eos::EOS_DATE, $app->getLanguage()->_('DATE_FORMAT_LC3')),
120+
$this->currentMessage['messageLink']
121+
);
110122
if ($this->currentMessage['snoozable']) {
111-
$messageText .= '<p><button class="btn btn-warning eosnotify-snooze-btn" type="button" >' . Text::_('PLG_QUICKICON_EOS_SNOOZE_BUTTON') . '</button></p>';
123+
$messageText .= '<p><button class="btn btn-warning eosnotify-snooze-btn" type="button" >';
124+
$messageText .= $app->getLanguage()->_('PLG_QUICKICON_EOS_SNOOZE_BUTTON') . '</button></p>';
112125
}
113-
$this->getApplication()->enqueueMessage($messageText, $this->currentMessage['messageType']);
126+
$app->enqueueMessage($messageText, $this->currentMessage['messageType']);
114127
}
115128

116-
$this->getApplication()->getDocument()->getWebAssetManager()->registerAndUseScript('plg_quickicon_eos.script', 'plg_quickicon_eos/snooze.js', [], ['type' => 'module']);
129+
$app->getDocument()->getWebAssetManager()
130+
->registerAndUseScript('plg_quickicon_eos.script', 'plg_quickicon_eos/snooze.js', [], ['type' => 'module']);
117131

118132
$result = $event->getArgument('result', []);
119-
$messageTextQuickIcon = Text::sprintf($this->currentMessage['quickiconText'], HTMLHelper::_('date', Eos::EOS_DATE, Text::_('DATE_FORMAT_LC3')));
133+
$messageTextQuickIcon = sprintf(
134+
$app->getLanguage()->_($this->currentMessage['quickiconText']),
135+
HTMLHelper::_('date', Eos::EOS_DATE, $app->getLanguage()->_('DATE_FORMAT_LC3'))
136+
);
120137

121138
// The message as quickicon
122139

@@ -135,7 +152,7 @@ public function getEndOfServiceNotification(QuickIconsEvent $event): void
135152
}
136153

137154
/**
138-
* Save the plugin parameters
155+
* Save the plugin parameters.
139156
*
140157
* @return bool
141158
*
@@ -157,7 +174,7 @@ private function saveParams(): bool
157174
}
158175

159176
/**
160-
* Determines if the message and quickicon should be displayed
177+
* Determines if the message and quickicon should be displayed.
161178
*
162179
* @return bool
163180
*
@@ -167,16 +184,18 @@ private function saveParams(): bool
167184
*/
168185
private function shouldDisplayMessage(): bool
169186
{
170-
return !$this->getApplication()->isClient('administrator')
171-
|| $this->getApplication()->getIdentity()->guest
172-
|| $this->getApplication()->getDocument()->getType() !== 'html'
173-
|| $this->getApplication()->getInput()->getCmd('tmpl', 'index') === 'component'
174-
|| $this->getApplication()->getInput()->get('option') !== 'com_cpanel'
175-
? false : true;
187+
// Show only on administration part
188+
return $this->getApplication()->isClient('administrator')
189+
// Only show for HTML requests
190+
&& $this->getApplication()->getDocument()->getType() === 'html'
191+
// Don't show in modal
192+
&& $this->getApplication()->getInput()->getCmd('tmpl', 'index') !== 'component'
193+
// Only show in cpanel
194+
&& $this->getApplication()->getInput()->get('option') === 'com_cpanel';
176195
}
177196

178197
/**
179-
* Return the texts to be displayed based on the time until we reach EOS
198+
* Return the texts to be displayed based on the time until we reach EOS.
180199
*
181200
* @param int $monthsUntilEOS The months until we reach EOS
182201
* @param int $inverted Have we surpassed the EOS date
@@ -200,6 +219,7 @@ private function getMessageInfo(int $monthsUntilEOS, int $inverted): array
200219
'snoozable' => false,
201220
];
202221
}
222+
203223
// The security support is ending in 6 months
204224
if ($monthsUntilEOS < 6) {
205225
return [
@@ -213,6 +233,7 @@ private function getMessageInfo(int $monthsUntilEOS, int $inverted): array
213233
'snoozable' => true,
214234
];
215235
}
236+
216237
// We are in security only mode now, 12 month to go from now on
217238
if ($monthsUntilEOS < 12) {
218239
return [
@@ -226,6 +247,7 @@ private function getMessageInfo(int $monthsUntilEOS, int $inverted): array
226247
'snoozable' => true,
227248
];
228249
}
250+
229251
// We still have 16 month to go, lets remind our users about the pre upgrade checker
230252
if ($monthsUntilEOS < 16) {
231253
return [
@@ -239,6 +261,7 @@ private function getMessageInfo(int $monthsUntilEOS, int $inverted): array
239261
'snoozable' => true,
240262
];
241263
}
264+
242265
// Lets start our messages 2 month after the initial release, still 22 month to go
243266
if ($monthsUntilEOS < 22) {
244267
return [
@@ -257,7 +280,7 @@ private function getMessageInfo(int $monthsUntilEOS, int $inverted): array
257280
}
258281

259282
/**
260-
* Check if current user is allowed to send the data
283+
* Check if current user is allowed to send the data.
261284
*
262285
* @return bool
263286
*
@@ -271,13 +294,13 @@ private function isAllowedUser(): bool
271294
}
272295

273296
/**
274-
* User hit the snooze button
297+
* User hit the snooze button.
275298
*
276299
* @return string
277300
*
278301
* @since __DEPLOY_VERSION__
279302
*
280-
* @throws Notallowed If user is not allowed.
303+
* @throws Notallowed If user is not allowed
281304
*
282305
* @throws Exception
283306
*/
@@ -287,9 +310,11 @@ public function onAjaxEos(): string
287310
if (!$this->messagesInitialized && $this->setMessage() == []) {
288311
return '';
289312
}
313+
290314
if (!$this->isAllowedUser()) {
291-
throw new Notallowed(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'), 403);
315+
throw new Notallowed($this->getApplication()->getLanguage()->_('JGLOBAL_AUTH_ACCESS_DENIED'), 403);
292316
}
317+
293318
// Make sure only snoozable messages can be snoozed
294319
if ($this->currentMessage['snoozable']) {
295320
$this->params->set('last_snoozed_id', $this->currentMessage['id']);
@@ -300,9 +325,7 @@ public function onAjaxEos(): string
300325
}
301326

302327
/**
303-
* setMessage
304-
*
305-
* Calculates how many days and selects correct message
328+
* Calculates how many days and selects correct message.
306329
*
307330
* @return array
308331
*

0 commit comments

Comments
 (0)