Merge pull request #5 from mokoconsulting-tech/copilot/fix-175766570-1130771363-2505b04d-52e1-423e-a7b0-e37eee4416b4

Fix InstallerScriptInterface method return type declarations
This commit is contained in:
2026-02-26 14:53:58 -06:00
committed by GitHub
21 changed files with 703 additions and 107 deletions
-92
View File
@@ -1,92 +0,0 @@
<?php
/**
* Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
*
* 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
}
}
@@ -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)
; -----------------------------------------------------------------------------
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><title></title></head><body></body></html>
@@ -0,0 +1,19 @@
; -----------------------------------------------------------------------------
; Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
; 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."
@@ -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)
; -----------------------------------------------------------------------------
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><title></title></head><body></body></html>
@@ -0,0 +1,22 @@
; -----------------------------------------------------------------------------
; Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
; 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."
@@ -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
-->
<extension type="plugin" group="system" method="upgrade">
@@ -29,19 +29,27 @@
<license>GNU General Public License version 3 or later; see LICENSE.md</license>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl>
<version>01.04.00</version>
<version>01.06.00</version>
<description>PLG_SYSTEM_MOKOWAASBRAND_XML_DESCRIPTION</description>
<namespace path="src">Moko\Plugin\System\MokoWaaSBrand</namespace>
<scriptfile>script.php</scriptfile>
<files>
<filename plugin="mokowaasbrand">mokowaasbrand.php</filename>
<filename plugin="mokowaasbrand">script.php</filename>
<folder>src</folder>
<folder>services</folder>
<folder>language</folder>
<folder>administrator</folder>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/plg_system_mokowaasbrand.ini</language>
<language tag="en-US">en-US/plg_system_mokowaasbrand.ini</language>
</languages>
<languages folder="administrator/language">
<language tag="en-GB">en-GB/plg_system_mokowaasbrand.sys.ini</language>
<language tag="en-US">en-US/plg_system_mokowaasbrand.sys.ini</language>
</languages>
<administration>
+441
View File
@@ -0,0 +1,441 @@
<?php
/**
* Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
*
* 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);
}
}
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
@@ -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')
);
@@ -0,0 +1,187 @@
<?php
/**
* Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
*
* 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
}
}