From b37a7dd1bef3632bfa192b0501b2461ee2ea074b Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Thu, 4 Jun 2026 23:03:14 -0500 Subject: [PATCH] feat(license): warn admins when no download key is configured MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds onAfterRoute hook that checks the update site for a valid MOKO-XXXX license key and shows a warning message once per session if missing — directs users to System > Update Sites. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/Extension/MokoJoomCross.php | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/packages/plg_system_mokojoomcross/src/Extension/MokoJoomCross.php b/src/packages/plg_system_mokojoomcross/src/Extension/MokoJoomCross.php index 2afd6263..7f7615e6 100644 --- a/src/packages/plg_system_mokojoomcross/src/Extension/MokoJoomCross.php +++ b/src/packages/plg_system_mokojoomcross/src/Extension/MokoJoomCross.php @@ -34,10 +34,20 @@ class MokoJoomCross extends CMSPlugin implements SubscriberInterface public static function getSubscribedEvents(): array { return [ + 'onAfterRoute' => 'onAfterRoute', 'onAfterRender' => 'onAfterRender', ]; } + public function onAfterRoute(): void + { + $app = $this->getApplication(); + + if ($app->isClient('administrator')) { + $this->warnMissingLicenseKey(); + } + } + /** * Process queued posts on page load (backend and/or frontend). * @@ -83,6 +93,59 @@ class MokoJoomCross extends CMSPlugin implements SubscriberInterface \Joomla\Component\MokoJoomCross\Administrator\Helper\QueueProcessor::processQueue(5); } + /** + * Warn administrators once per session when no license key is configured. + * + * @return void + */ + private function warnMissingLicenseKey(): void + { + $session = Factory::getSession(); + + if ($session->get('mokojoomcross.license_warned', false)) { + return; + } + + $user = Factory::getUser(); + + if ($user->guest || !$user->authorise('core.manage')) { + return; + } + + $session->set('mokojoomcross.license_warned', true); + + try { + $db = Factory::getDbo(); + + $query = $db->getQuery(true) + ->select($db->quoteName('extra_query')) + ->from($db->quoteName('#__update_sites')) + ->where($db->quoteName('name') . ' = ' . $db->quote('MokoJoomCross Updates')) + ->setLimit(1); + $db->setQuery($query); + $extraQuery = (string) $db->loadResult(); + + if (!empty($extraQuery)) { + parse_str($extraQuery, $parsed); + + if (!empty($parsed['dlid']) && preg_match('/^MOKO-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/', $parsed['dlid'])) { + return; + } + } + + $this->getApplication()->enqueueMessage( + 'Moko Consulting License Key Required — ' + . 'No download key is configured. Updates will not be available until a valid license key is entered. ' + . 'Go to System → Update Sites ' + . 'and enter your license key (MOKO-XXXX-XXXX-XXXX-XXXX) in the Download Key field ' + . 'for the MokoJoomCross update site.', + 'warning' + ); + } catch (\Throwable $e) { + // Don't break admin over a license check + } + } + /** * Store the last page-load run timestamp. */