diff --git a/src/mokowaasbrand.php b/src/mokowaasbrand.php deleted file mode 100644 index 69b62652..00000000 --- a/src/mokowaasbrand.php +++ /dev/null @@ -1,92 +0,0 @@ - - * - * This file is part of a Moko Consulting project. - * - * SPDX-LICENSE-IDENTIFIER: GPL-3.0-or-later - * - * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License (./LICENSE.md). - * - * FILE INFORMATION - * DEFGROUP: Joomla.Plugin - * INGROUP: MokoWaaS-Brand - * REPO: https://github.com/mokoconsulting-tech/mokowaasbrand - * VERSION: 01.04.00 - * PATH: /src/mokowaasbrand.php - * BRIEF: Main plugin file for MokoWaaS-Brand system plugin - * NOTE: Handles Joomla system events for rebranding functionality - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\Plugin\CMSPlugin; - -/** - * MokoWaaS Brand System Plugin - * - * This plugin rebrands the Joomla system interface with MokoWaaS identity. - * It applies language overrides and ensures consistent branding across the platform. - * - * @since 01.04.00 - */ -class PlgSystemMokoWaaSBrand extends CMSPlugin -{ - /** - * Load the language file on instantiation. - * - * @var boolean - * @since 01.04.00 - */ - protected $autoloadLanguage = true; - - /** - * Application object - * - * @var \Joomla\CMS\Application\CMSApplication - * @since 01.04.00 - */ - protected $app; - - /** - * Event triggered after the framework has loaded and the application initialise method has been called. - * - * This plugin relies on Joomla's native language override system. Language override files - * placed in the standard Joomla override directories will be automatically loaded by Joomla. - * - * @return void - * - * @since 01.04.00 - */ - public function onAfterInitialise() - { - if (!$this->params->get('enable_branding', 1)) - { - return; - } - - // Language overrides are handled by Joomla's core system - // Additional branding functionality can be added here if needed - } - - /** - * Event triggered after the route has been determined. - * - * @return void - * - * @since 01.04.00 - */ - public function onAfterRoute() - { - if (!$this->params->get('enable_branding', 1)) - { - return; - } - - // Apply additional branding logic if needed - } -} diff --git a/src/index.html b/src/plugins/system/mokowaasbrand/administrator/language/en-GB/index.html similarity index 100% rename from src/index.html rename to src/plugins/system/mokowaasbrand/administrator/language/en-GB/index.html diff --git a/src/language/en-GB/plg_system_mokowaasbrand.sys.ini b/src/plugins/system/mokowaasbrand/administrator/language/en-GB/plg_system_mokowaasbrand.sys.ini similarity index 81% rename from src/language/en-GB/plg_system_mokowaasbrand.sys.ini rename to src/plugins/system/mokowaasbrand/administrator/language/en-GB/plg_system_mokowaasbrand.sys.ini index 39abf5bc..6646bf8a 100644 --- a/src/language/en-GB/plg_system_mokowaasbrand.sys.ini +++ b/src/plugins/system/mokowaasbrand/administrator/language/en-GB/plg_system_mokowaasbrand.sys.ini @@ -6,11 +6,11 @@ ; ----------------------------------------------------------------------------- ; FILE INFORMATION ; Defgroup: Joomla Language -; Ingroup: MokoWaaS-Brand -; Version: 01.04.00 +; Ingroup: MokoWaaSBrand +; Version: 01.05.00 ; File: plg_system_mokowaasbrand.sys.ini -; Path: /src/language/en-GB/plg_system_mokowaasbrand.sys.ini -; Brief: System language strings for MokoWaaS-Brand plugin installation +; Path: /src/plugins/system/mokowaasbrand/language/en-GB/plg_system_mokowaasbrand.sys.ini +; Brief: System language strings for MokoWaaSBrand plugin installation ; Notes: Contains strings used during plugin installation and management ; Variables: (none) ; ----------------------------------------------------------------------------- diff --git a/src/plugins/system/mokowaasbrand/administrator/language/en-US/index.html b/src/plugins/system/mokowaasbrand/administrator/language/en-US/index.html new file mode 100644 index 00000000..09b7ab1c --- /dev/null +++ b/src/plugins/system/mokowaasbrand/administrator/language/en-US/index.html @@ -0,0 +1 @@ + diff --git a/src/plugins/system/mokowaasbrand/administrator/language/en-US/plg_system_mokowaasbrand.sys.ini b/src/plugins/system/mokowaasbrand/administrator/language/en-US/plg_system_mokowaasbrand.sys.ini new file mode 100644 index 00000000..e2620df8 --- /dev/null +++ b/src/plugins/system/mokowaasbrand/administrator/language/en-US/plg_system_mokowaasbrand.sys.ini @@ -0,0 +1,19 @@ +; ----------------------------------------------------------------------------- +; Copyright (C) 2025 Moko Consulting +; This file is part of a Moko Consulting project. +; SPDX-LICENSE-IDENTIFIER: GPL-3.0-or-later +; REPO: https://github.com/mokoconsulting-tech/mokowaasbrand +; ----------------------------------------------------------------------------- +; FILE INFORMATION +; Defgroup: Joomla Language +; Ingroup: MokoWaaSBrand +; Version: 01.06.00 +; File: plg_system_mokowaasbrand.sys.ini +; Path: /src/plugins/system/mokowaasbrand/language/en-US/plg_system_mokowaasbrand.sys.ini +; Brief: US English system language strings for MokoWaaSBrand plugin installation +; Notes: Contains strings used during plugin installation and management +; Variables: (none) +; ----------------------------------------------------------------------------- + +PLG_SYSTEM_MOKOWAASBRAND="System - MokoWaaS Brand" +PLG_SYSTEM_MOKOWAASBRAND_XML_DESCRIPTION="This plugin rebrands the Joomla system interface with MokoWaaS identity. It applies language overrides and ensures consistent branding across the platform." diff --git a/src/administrator/language/overrides/en-GB.override.ini b/src/plugins/system/mokowaasbrand/administrator/language/overrides/en-GB.override.ini similarity index 100% rename from src/administrator/language/overrides/en-GB.override.ini rename to src/plugins/system/mokowaasbrand/administrator/language/overrides/en-GB.override.ini diff --git a/src/administrator/language/overrides/en-US.override.ini b/src/plugins/system/mokowaasbrand/administrator/language/overrides/en-US.override.ini similarity index 100% rename from src/administrator/language/overrides/en-US.override.ini rename to src/plugins/system/mokowaasbrand/administrator/language/overrides/en-US.override.ini diff --git a/src/administrator/language/overrides/index.html b/src/plugins/system/mokowaasbrand/administrator/language/overrides/index.html similarity index 100% rename from src/administrator/language/overrides/index.html rename to src/plugins/system/mokowaasbrand/administrator/language/overrides/index.html diff --git a/src/language/en-GB/index.html b/src/plugins/system/mokowaasbrand/index.html similarity index 100% rename from src/language/en-GB/index.html rename to src/plugins/system/mokowaasbrand/index.html diff --git a/src/services/index.html b/src/plugins/system/mokowaasbrand/language/en-GB/index.html similarity index 100% rename from src/services/index.html rename to src/plugins/system/mokowaasbrand/language/en-GB/index.html diff --git a/src/language/en-GB/plg_system_mokowaasbrand.ini b/src/plugins/system/mokowaasbrand/language/en-GB/plg_system_mokowaasbrand.ini similarity index 84% rename from src/language/en-GB/plg_system_mokowaasbrand.ini rename to src/plugins/system/mokowaasbrand/language/en-GB/plg_system_mokowaasbrand.ini index b087640c..074a95c8 100644 --- a/src/language/en-GB/plg_system_mokowaasbrand.ini +++ b/src/plugins/system/mokowaasbrand/language/en-GB/plg_system_mokowaasbrand.ini @@ -6,11 +6,11 @@ ; ----------------------------------------------------------------------------- ; FILE INFORMATION ; Defgroup: Joomla Language -; Ingroup: MokoWaaS-Brand -; Version: 01.04.00 +; Ingroup: MokoWaaSBrand +; Version: 01.05.00 ; File: plg_system_mokowaasbrand.ini -; Path: /src/language/en-GB/plg_system_mokowaasbrand.ini -; Brief: English language strings for MokoWaaS-Brand system plugin +; Path: /src/plugins/system/mokowaasbrand/language/en-GB/plg_system_mokowaasbrand.ini +; Brief: English language strings for MokoWaaSBrand system plugin ; Notes: Contains translatable strings for plugin functionality ; Variables: (none) ; ----------------------------------------------------------------------------- diff --git a/src/plugins/system/mokowaasbrand/language/en-US/index.html b/src/plugins/system/mokowaasbrand/language/en-US/index.html new file mode 100644 index 00000000..09b7ab1c --- /dev/null +++ b/src/plugins/system/mokowaasbrand/language/en-US/index.html @@ -0,0 +1 @@ + diff --git a/src/plugins/system/mokowaasbrand/language/en-US/plg_system_mokowaasbrand.ini b/src/plugins/system/mokowaasbrand/language/en-US/plg_system_mokowaasbrand.ini new file mode 100644 index 00000000..634c49d9 --- /dev/null +++ b/src/plugins/system/mokowaasbrand/language/en-US/plg_system_mokowaasbrand.ini @@ -0,0 +1,22 @@ +; ----------------------------------------------------------------------------- +; Copyright (C) 2025 Moko Consulting +; This file is part of a Moko Consulting project. +; SPDX-LICENSE-IDENTIFIER: GPL-3.0-or-later +; REPO: https://github.com/mokoconsulting-tech/mokowaasbrand +; ----------------------------------------------------------------------------- +; FILE INFORMATION +; Defgroup: Joomla Language +; Ingroup: MokoWaaSBrand +; Version: 01.06.00 +; File: plg_system_mokowaasbrand.ini +; Path: /src/plugins/system/mokowaasbrand/language/en-US/plg_system_mokowaasbrand.ini +; Brief: US English language strings for MokoWaaSBrand system plugin +; Notes: Contains translatable strings for plugin functionality +; Variables: (none) +; ----------------------------------------------------------------------------- + +PLG_SYSTEM_MOKOWAASBRAND="System - MokoWaaS Brand" +PLG_SYSTEM_MOKOWAASBRAND_XML_DESCRIPTION="This plugin rebrands the Joomla system interface with MokoWaaS identity. It applies language overrides and ensures consistent branding across the platform." + +PLG_SYSTEM_MOKOWAASBRAND_ENABLE_BRANDING_LABEL="Enable Branding" +PLG_SYSTEM_MOKOWAASBRAND_ENABLE_BRANDING_DESC="Enable or disable the MokoWaaS branding across the system." diff --git a/src/language/overrides/en-GB.override.ini b/src/plugins/system/mokowaasbrand/language/overrides/en-GB.override.ini similarity index 100% rename from src/language/overrides/en-GB.override.ini rename to src/plugins/system/mokowaasbrand/language/overrides/en-GB.override.ini diff --git a/src/language/overrides/en-US.override.ini b/src/plugins/system/mokowaasbrand/language/overrides/en-US.override.ini similarity index 100% rename from src/language/overrides/en-US.override.ini rename to src/plugins/system/mokowaasbrand/language/overrides/en-US.override.ini diff --git a/src/language/overrides/index.html b/src/plugins/system/mokowaasbrand/language/overrides/index.html similarity index 100% rename from src/language/overrides/index.html rename to src/plugins/system/mokowaasbrand/language/overrides/index.html diff --git a/src/mokowaasbrand.xml b/src/plugins/system/mokowaasbrand/mokowaasbrand.xml similarity index 81% rename from src/mokowaasbrand.xml rename to src/plugins/system/mokowaasbrand/mokowaasbrand.xml index 1d691fb6..386cbd24 100644 --- a/src/mokowaasbrand.xml +++ b/src/plugins/system/mokowaasbrand/mokowaasbrand.xml @@ -14,11 +14,11 @@ # FILE INFORMATION DEFGROUP: Joomla.Plugin - INGROUP: MokoWaaS-Brand + INGROUP: MokoWaaSBrand REPO: https://github.com/mokoconsulting-tech/mokowaasbrand - VERSION: 01.04.00 - PATH: /src/mokowaasbrand.xml - BRIEF: Plugin manifest for MokoWaaS-Brand system plugin + VERSION: 01.06.00 + PATH: /src/plugins/system/mokowaasbrand/mokowaasbrand.xml + BRIEF: Plugin manifest for MokoWaaSBrand system plugin NOTE: Defines installation metadata, files, and configuration for Joomla --> @@ -29,19 +29,27 @@ GNU General Public License version 3 or later; see LICENSE.md hello@mokoconsulting.tech https://mokoconsulting.tech - 01.04.00 + 01.06.00 PLG_SYSTEM_MOKOWAASBRAND_XML_DESCRIPTION Moko\Plugin\System\MokoWaaSBrand + script.php - mokowaasbrand.php + script.php + src services language + administrator en-GB/plg_system_mokowaasbrand.ini + en-US/plg_system_mokowaasbrand.ini + + + en-GB/plg_system_mokowaasbrand.sys.ini + en-US/plg_system_mokowaasbrand.sys.ini diff --git a/src/plugins/system/mokowaasbrand/script.php b/src/plugins/system/mokowaasbrand/script.php new file mode 100644 index 00000000..757ae516 --- /dev/null +++ b/src/plugins/system/mokowaasbrand/script.php @@ -0,0 +1,441 @@ + + * + * This file is part of a Moko Consulting project. + * + * SPDX-LICENSE-IDENTIFIER: GPL-3.0-or-later + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License (./LICENSE.md). + * + * FILE INFORMATION + * DEFGROUP: Joomla.Plugin + * INGROUP: MokoWaaSBrand + * REPO: https://github.com/mokoconsulting-tech/mokowaasbrand + * VERSION: 01.06.00 + * PATH: /src/plugins/system/mokowaasbrand/script.php + * BRIEF: Installation script for MokoWaaSBrand plugin + * NOTE: Handles installation, update, and uninstallation tasks including language override deployment + */ + +defined('_JEXEC') or die; + +use Joomla\CMS\Factory; +use Joomla\CMS\Installer\InstallerAdapter; +use Joomla\CMS\Installer\InstallerScriptInterface; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Log\Log; +use Joomla\Filesystem\File; +use Joomla\Filesystem\Folder; + +/** + * Installation script for MokoWaaSBrand plugin + * + * This script handles the installation and uninstallation of language override files + * to Joomla's global language override directories. + * + * @since 01.06.00 + */ +class plgSystemMokoWaaSBrandInstallerScript implements InstallerScriptInterface +{ + /** + * Minimum Joomla version required to install the extension. + * + * @var string + * @since 01.06.00 + */ + private $minimumJoomla = '5.0.0'; + + /** + * Minimum PHP version required to install the extension. + * + * @var string + * @since 01.06.00 + */ + private $minimumPhp = '8.1.0'; + + /** + * Language tags supported by this plugin. + * + * @var array + * @since 01.06.00 + */ + private $languageTags = ['en-GB', 'en-US']; + + /** + * Called before any type of action. + * + * @param string $type Which action is happening (install|uninstall|discover_install|update) + * @param InstallerAdapter $adapter The object responsible for running this script + * + * @return boolean True on success + * + * @since 01.06.00 + */ + public function preflight($type, $adapter): bool + { + // Check minimum Joomla version + if (version_compare(JVERSION, $this->minimumJoomla, '<')) + { + Factory::getApplication()->enqueueMessage( + sprintf('This extension requires Joomla %s or later.', $this->minimumJoomla), + 'error' + ); + return false; + } + + // Check minimum PHP version + if (version_compare(PHP_VERSION, $this->minimumPhp, '<')) + { + Factory::getApplication()->enqueueMessage( + sprintf('This extension requires PHP %s or later.', $this->minimumPhp), + 'error' + ); + return false; + } + + return true; + } + + /** + * Called after any type of action. + * + * @param string $type Which action is happening (install|uninstall|discover_install|update) + * @param InstallerAdapter $adapter The object responsible for running this script + * + * @return boolean True on success + * + * @since 01.06.00 + */ + public function postflight($type, $adapter): bool + { + // Only install overrides on install or update + if ($type === 'install' || $type === 'update') + { + $this->installLanguageOverrides(); + } + + return true; + } + + /** + * Called on installation. + * + * @param InstallerAdapter $adapter The object responsible for running this script + * + * @return boolean True on success + * + * @since 01.06.00 + */ + public function install(InstallerAdapter $adapter): bool + { + return true; + } + + /** + * Called on update. + * + * @param InstallerAdapter $adapter The object responsible for running this script + * + * @return boolean True on success + * + * @since 01.06.00 + */ + public function update(InstallerAdapter $adapter): bool + { + return true; + } + + /** + * Called on uninstallation. + * + * @param InstallerAdapter $adapter The object responsible for running this script + * + * @return boolean True on success + * + * @since 01.06.00 + */ + public function uninstall(InstallerAdapter $adapter): bool + { + // Remove language overrides on uninstall + $this->uninstallLanguageOverrides(); + + return true; + } + + /** + * Install language override files to Joomla's global override directories. + * + * This method copies the plugin's language override files to Joomla's global + * language override directories where they will be automatically loaded by Joomla. + * + * @return void + * + * @since 01.06.00 + */ + private function installLanguageOverrides() + { + $app = Factory::getApplication(); + $pluginPath = JPATH_PLUGINS . '/system/mokowaasbrand'; + + // Install frontend overrides + foreach ($this->languageTags as $tag) + { + $source = $pluginPath . '/language/overrides/' . $tag . '.override.ini'; + $dest = JPATH_ROOT . '/language/overrides/' . $tag . '.override.ini'; + + if (file_exists($source)) + { + // Ensure destination directory exists + $destDir = dirname($dest); + if (!is_dir($destDir)) + { + Folder::create($destDir); + } + + // Read existing overrides if they exist + $existingOverrides = []; + if (file_exists($dest)) + { + $existingOverrides = $this->parseLanguageFile($dest); + } + + // Read plugin overrides + $pluginOverrides = $this->parseLanguageFile($source); + + // Merge overrides (plugin overrides take precedence) + $mergedOverrides = array_merge($existingOverrides, $pluginOverrides); + + // Write merged overrides + if ($this->writeLanguageFile($dest, $mergedOverrides)) + { + $app->enqueueMessage( + sprintf('Installed frontend language overrides for %s', $tag), + 'message' + ); + } + else + { + $app->enqueueMessage( + sprintf('Failed to install frontend language overrides for %s', $tag), + 'warning' + ); + } + } + } + + // Install administrator overrides + foreach ($this->languageTags as $tag) + { + $source = $pluginPath . '/administrator/language/overrides/' . $tag . '.override.ini'; + $dest = JPATH_ADMINISTRATOR . '/language/overrides/' . $tag . '.override.ini'; + + if (file_exists($source)) + { + // Ensure destination directory exists + $destDir = dirname($dest); + if (!is_dir($destDir)) + { + Folder::create($destDir); + } + + // Read existing overrides if they exist + $existingOverrides = []; + if (file_exists($dest)) + { + $existingOverrides = $this->parseLanguageFile($dest); + } + + // Read plugin overrides + $pluginOverrides = $this->parseLanguageFile($source); + + // Merge overrides (plugin overrides take precedence) + $mergedOverrides = array_merge($existingOverrides, $pluginOverrides); + + // Write merged overrides + if ($this->writeLanguageFile($dest, $mergedOverrides)) + { + $app->enqueueMessage( + sprintf('Installed administrator language overrides for %s', $tag), + 'message' + ); + } + else + { + $app->enqueueMessage( + sprintf('Failed to install administrator language overrides for %s', $tag), + 'warning' + ); + } + } + } + } + + /** + * Remove language override files from Joomla's global override directories. + * + * This method removes the plugin's language overrides from Joomla's global + * language override directories on uninstallation. + * + * @return void + * + * @since 01.06.00 + */ + private function uninstallLanguageOverrides() + { + $app = Factory::getApplication(); + $pluginPath = JPATH_PLUGINS . '/system/mokowaasbrand'; + + // Remove frontend overrides + foreach ($this->languageTags as $tag) + { + $source = $pluginPath . '/language/overrides/' . $tag . '.override.ini'; + $dest = JPATH_ROOT . '/language/overrides/' . $tag . '.override.ini'; + + if (file_exists($source) && file_exists($dest)) + { + // Read plugin overrides + $pluginOverrides = $this->parseLanguageFile($source); + + // Read existing overrides + $existingOverrides = $this->parseLanguageFile($dest); + + // Remove plugin overrides from existing + foreach (array_keys($pluginOverrides) as $key) + { + unset($existingOverrides[$key]); + } + + // Write remaining overrides or delete file if empty + if (!empty($existingOverrides)) + { + $this->writeLanguageFile($dest, $existingOverrides); + } + else + { + File::delete($dest); + } + + $app->enqueueMessage( + sprintf('Removed frontend language overrides for %s', $tag), + 'message' + ); + } + } + + // Remove administrator overrides + foreach ($this->languageTags as $tag) + { + $source = $pluginPath . '/administrator/language/overrides/' . $tag . '.override.ini'; + $dest = JPATH_ADMINISTRATOR . '/language/overrides/' . $tag . '.override.ini'; + + if (file_exists($source) && file_exists($dest)) + { + // Read plugin overrides + $pluginOverrides = $this->parseLanguageFile($source); + + // Read existing overrides + $existingOverrides = $this->parseLanguageFile($dest); + + // Remove plugin overrides from existing + foreach (array_keys($pluginOverrides) as $key) + { + unset($existingOverrides[$key]); + } + + // Write remaining overrides or delete file if empty + if (!empty($existingOverrides)) + { + $this->writeLanguageFile($dest, $existingOverrides); + } + else + { + File::delete($dest); + } + + $app->enqueueMessage( + sprintf('Removed administrator language overrides for %s', $tag), + 'message' + ); + } + } + } + + /** + * Parse a language INI file and return the strings as an associative array. + * + * @param string $filePath The path to the language file + * + * @return array Array of language strings (key => value) + * + * @since 01.06.00 + */ + private function parseLanguageFile($filePath) + { + $strings = []; + + if (!file_exists($filePath)) + { + return $strings; + } + + $content = file_get_contents($filePath); + $lines = explode("\n", $content); + + foreach ($lines as $line) + { + $line = trim($line); + + // Skip empty lines and comments + if (empty($line) || $line[0] === ';') + { + continue; + } + + // Parse KEY="VALUE" format + if (preg_match('/^([A-Z0-9_]+)="(.+)"$/i', $line, $matches)) + { + $key = strtoupper($matches[1]); + $value = $matches[2]; + $strings[$key] = $value; + } + } + + return $strings; + } + + /** + * Write language strings to an INI file. + * + * @param string $filePath The path to the language file + * @param array $strings Array of language strings (key => value) + * + * @return boolean True on success, false on failure + * + * @since 01.06.00 + */ + private function writeLanguageFile($filePath, $strings) + { + if (empty($strings)) + { + return false; + } + + $content = "; MokoWaaS Language Overrides\n"; + $content .= "; Generated by MokoWaaSBrand Plugin\n"; + $content .= "; Last updated: " . date('Y-m-d H:i:s') . "\n\n"; + + foreach ($strings as $key => $value) + { + // Escape quotes in value + $value = str_replace('"', '\"', $value); + $content .= strtoupper($key) . '="' . $value . '"' . "\n"; + } + + return File::write($filePath, $content); + } +} diff --git a/src/plugins/system/mokowaasbrand/services/index.html b/src/plugins/system/mokowaasbrand/services/index.html new file mode 100644 index 00000000..71695153 --- /dev/null +++ b/src/plugins/system/mokowaasbrand/services/index.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/services/provider.php b/src/plugins/system/mokowaasbrand/services/provider.php similarity index 95% rename from src/services/provider.php rename to src/plugins/system/mokowaasbrand/services/provider.php index f2a9c834..481ab323 100644 --- a/src/services/provider.php +++ b/src/plugins/system/mokowaasbrand/services/provider.php @@ -30,6 +30,7 @@ use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; +use Moko\Plugin\System\MokoWaaSBrand\Extension\MokoWaaSBrand; return new class () implements ServiceProviderInterface { /** @@ -46,7 +47,7 @@ return new class () implements ServiceProviderInterface { $container->set( PluginInterface::class, function (Container $container) { - $plugin = new PlgSystemMokoWaaSBrand( + $plugin = new MokoWaaSBrand( $container->get(DispatcherInterface::class), (array) PluginHelper::getPlugin('system', 'mokowaasbrand') ); diff --git a/src/plugins/system/mokowaasbrand/src/Extension/MokoWaaSBrand.php b/src/plugins/system/mokowaasbrand/src/Extension/MokoWaaSBrand.php new file mode 100644 index 00000000..48f61929 --- /dev/null +++ b/src/plugins/system/mokowaasbrand/src/Extension/MokoWaaSBrand.php @@ -0,0 +1,187 @@ + + * + * This file is part of a Moko Consulting project. + * + * SPDX-LICENSE-IDENTIFIER: GPL-3.0-or-later + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License (./LICENSE.md). + * + * FILE INFORMATION + * DEFGROUP: Joomla.Plugin + * INGROUP: MokoWaaS-Brand + * REPO: https://github.com/mokoconsulting-tech/mokowaasbrand + * VERSION: 01.04.00 + * PATH: /src/plugins/system/mokowaasbrand/src/Extension/MokoWaaSBrand.php + * BRIEF: Main plugin class for MokoWaaS-Brand system plugin + * NOTE: Handles Joomla system events for rebranding functionality + */ + +namespace Moko\Plugin\System\MokoWaaSBrand\Extension; + +defined('_JEXEC') or die; + +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Language\Language; + +/** + * MokoWaaS Brand System Plugin + * + * This plugin rebrands the Joomla system interface with MokoWaaS identity. + * It applies language overrides and ensures consistent branding across the platform. + * + * @since 01.04.00 + */ +class MokoWaaSBrand extends CMSPlugin +{ + /** + * Load the language file on instantiation. + * + * @var boolean + * @since 01.04.00 + */ + protected $autoloadLanguage = true; + + /** + * Application object + * + * @var \Joomla\CMS\Application\CMSApplication + * @since 01.04.00 + */ + protected $app; + + /** + * Event triggered after the framework has loaded and the application initialise method has been called. + * + * This method loads language override files from the plugin directory to rebrand Joomla + * with MokoWaaS identity. The override files replace core Joomla language strings. + * + * @return void + * + * @since 01.04.00 + */ + public function onAfterInitialise() + { + if (!$this->params->get('enable_branding', 1)) + { + return; + } + + // Load language overrides + $this->loadLanguageOverrides(); + } + + /** + * Load language override files from the plugin directory. + * + * This method loads the override files that replace core Joomla language strings + * with MokoWaaS branding. + * + * @return void + * + * @since 01.06.00 + */ + protected function loadLanguageOverrides() + { + $language = $this->app->getLanguage(); + $tag = $language->getTag(); + + // Get the plugin path + $pluginPath = JPATH_PLUGINS . '/system/mokowaasbrand'; + + // Determine if we're in administrator or site + $isAdmin = $this->app->isClient('administrator'); + + // Load the appropriate override file + if ($isAdmin) + { + $overridePath = $pluginPath . '/administrator/language/overrides/' . $tag . '.override.ini'; + } + else + { + $overridePath = $pluginPath . '/language/overrides/' . $tag . '.override.ini'; + } + + // Load the override file if it exists + if (file_exists($overridePath)) + { + $language->load('', $pluginPath, $tag, true, false); + + // Parse and load the override file manually + $strings = $this->parseLanguageFile($overridePath); + + if (!empty($strings)) + { + foreach ($strings as $key => $value) + { + $language->_strings[$key] = $value; + } + } + } + } + + /** + * Parse a language INI file and return the strings. + * + * @param string $filePath The path to the language file + * + * @return array Array of language strings + * + * @since 01.06.00 + */ + protected function parseLanguageFile($filePath) + { + $strings = []; + + if (!file_exists($filePath)) + { + return $strings; + } + + $content = file_get_contents($filePath); + $lines = explode("\n", $content); + + foreach ($lines as $line) + { + $line = trim($line); + + // Skip empty lines and comments + if (empty($line) || $line[0] === ';') + { + continue; + } + + // Parse KEY="VALUE" format + if (preg_match('/^([A-Z0-9_]+)="(.+)"$/i', $line, $matches)) + { + $key = strtoupper($matches[1]); + $value = $matches[2]; + $strings[$key] = $value; + } + } + + return $strings; + } + + /** + * Event triggered after the route has been determined. + * + * @return void + * + * @since 01.04.00 + */ + public function onAfterRoute() + { + if (!$this->params->get('enable_branding', 1)) + { + return; + } + + // Apply additional branding logic if needed + } +}