From de4e6a0ed6080321cd103dcdbf21a9cc245621c3 Mon Sep 17 00:00:00 2001 From: aB0t Date: Mon, 11 Mar 2024 16:14:23 +0200 Subject: [PATCH] Release of v2.0.0 --- componentbuilderlanguagepackaging.php | 107 +++++++++--------- componentbuilderlanguagepackaging.xml | 6 +- ...sion_componentbuilderlanguagepackaging.ini | 2 +- ..._componentbuilderlanguagepackaging.sys.ini | 2 +- script.php | 100 ---------------- 5 files changed, 57 insertions(+), 160 deletions(-) diff --git a/componentbuilderlanguagepackaging.php b/componentbuilderlanguagepackaging.php index ba93dc7..a00b959 100644 --- a/componentbuilderlanguagepackaging.php +++ b/componentbuilderlanguagepackaging.php @@ -13,23 +13,22 @@ defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Application\CMSApplication; -use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Filesystem\Folder; use VDM\Joomla\Utilities\JsonHelper; use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Componentbuilder\Compiler\Factory; use VDM\Joomla\Utilities\StringHelper; -use VDM\Joomla\Utilities\GetHelper; - -JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'); - -use VDM\Joomla\Componentbuilder\Compiler\Factory as CFactory; -use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix; -use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent; - +use VDM\Joomla\Utilities\FileHelper; +use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent; +use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix; +use VDM\Joomla\Utilities\GetHelper; +use VDM\Joomla\Utilities\MathHelper; /** * Extension - Componentbuilder Language Packaging plugin. * * @package ComponentbuilderLanguagePackaging - * @since 1.2.0 + * @since 2.0.0 */ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin { @@ -232,7 +231,7 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin isset($component->params['language_options']['activate']) && $component->params['language_options']['activate'] == 1) { // load the admin component details - $this->activeComponents[$component->id] = CFactory::_('Config')->component_context; + $this->activeComponents[$component->id] = Factory::_('Config')->component_context; $this->activeComponentsNames[$component->id] = StringHelper::safe($component->name_code); $this->activeComponentsRealNames[$component->id] = $component->name; // add excluded list of languages @@ -262,12 +261,12 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin public function jcb_ce_onAfterGet() { // get component id - $id = (int) CFactory::_('Config')->component_id; + $id = (int) Factory::_('Config')->component_id; // check if there is active if (ArrayHelper::check($this->activeComponents) && isset($this->activeComponents[$id]) && $this->percentageLanguageAddOveride != 200) { - CFactory::_('Config')->set('percentage_language_add', $this->percentageLanguageAddOveride); + Factory::_('Config')->set('percentage_language_add', $this->percentageLanguageAddOveride); } } @@ -281,17 +280,17 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin public function jcb_ce_onBeforeSetLangFileData() { // lets map some arrays to the plugin for later use - $this->compilerPath = CFactory::_('Config')->compiler_path; - $this->tempPath = CFactory::_('Config')->tmp_path; - $this->langTag = CFactory::_('Config')->lang_tag; - $this->debugLinenr = CFactory::_('Config')->get('debug_line_nr', false); - $this->component_version = CFactory::_('Config')->get('component_version', '1.0.0'); - $this->joomlaVersion = CFactory::_('Config')->joomla_version; - $this->percentageLanguageAdd = CFactory::_('Config')->percentage_language_add; - $this->removeSiteFolder = CFactory::_('Config')->remove_site_folder; - $this->removeSiteEditFolder = CFactory::_('Config')->remove_site_edit_folder; - $this->componentPath = CFactory::_('Utilities.Paths')->component_path; - $this->componentCodeName = CFactory::_('Config')->component_code_name; + $this->compilerPath = Factory::_('Config')->compiler_path; + $this->tempPath = Factory::_('Config')->tmp_path; + $this->langTag = Factory::_('Config')->lang_tag; + $this->debugLinenr = Factory::_('Config')->get('debug_line_nr', false); + $this->component_version = Factory::_('Config')->get('component_version', '1.0.0'); + $this->joomlaVersion = Factory::_('Config')->joomla_version; + $this->percentageLanguageAdd = Factory::_('Config')->percentage_language_add; + $this->removeSiteFolder = Factory::_('Config')->remove_site_folder; + $this->removeSiteEditFolder = Factory::_('Config')->remove_site_edit_folder; + $this->componentPath = Factory::_('Utilities.Paths')->component_path; + $this->componentCodeName = Factory::_('Config')->component_code_name; } /** @@ -304,14 +303,14 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin public function jcb_ce_onBeforeBuildPluginLangFiles(&$plugin, &$languages) { // get component id - $id = (int) CFactory::_('Config')->component_id; + $id = (int) Factory::_('Config')->component_id; // check if there is active if (ArrayHelper::check($this->activeComponents) && isset($this->activeComponents[$id])) { // set file name $file_name = 'plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->code_name); // extrude the languages that should not remain in the plugin - $this->extrudeLanguages($id, $languages, CFactory::_('Config')->lang_tag, $file_name, 'admin'); + $this->extrudeLanguages($id, $languages, Factory::_('Config')->lang_tag, $file_name, 'admin'); } } @@ -325,12 +324,12 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin public function jcb_ce_onBeforeBuildModuleLangFiles(&$module, &$languages) { // get component id - $id = (int) CFactory::_('Config')->component_id; + $id = (int) Factory::_('Config')->component_id; // check if there is active if (ArrayHelper::check($this->activeComponents) && isset($this->activeComponents[$id])) { // extrude the languages that should not remain in the module - $this->extrudeLanguages($id, $languages, CFactory::_('Config')->lang_tag, $module->file_name, $module->target_client); + $this->extrudeLanguages($id, $languages, Factory::_('Config')->lang_tag, $module->file_name, $module->target_client); } } @@ -344,17 +343,17 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin public function jcb_ce_onBeforeBuildAllLangFiles(&$languages) { // get component id - $id = (int) CFactory::_('Config')->component_id; + $id = (int) Factory::_('Config')->component_id; // check if there is active if (ArrayHelper::check($this->activeComponents) && isset($this->activeComponents[$id])) { // set file name $file_name = 'com_' . $this->activeComponentsNames[$id]; // extrude the languages that should not remain in the module - $this->extrudeLanguages($id, $languages, CFactory::_('Config')->lang_tag, $file_name); + $this->extrudeLanguages($id, $languages, Factory::_('Config')->lang_tag, $file_name); } // build the language packages - $this->buildLanguages($id, CFactory::_('Config')->lang_tag); + $this->buildLanguages($id, Factory::_('Config')->lang_tag); } /** @@ -444,19 +443,19 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin // set the lang xml name for later $langXMLNames[$main_path] = $langCodeName . '_' . $this->activeComponentsNames[$id] ; // we must check if old folder is found and remove it - if (!isset($this->languageTracker[$main_path]) && JFolder::exists($main_path)) + if (!isset($this->languageTracker[$main_path]) && Folder::exists($main_path)) { // remove the main folder - ComponentbuilderHelper::removeFolder($main_path); + Factory::_('Utilities.Folder')->remove($main_path); // do not remove it again $this->languageTracker[$main_path] = true; } // check if exist and create if not - if (!JFolder::exists($main_path)) + if (!Folder::exists($main_path)) { - JFolder::create($main_path); + Folder::create($main_path); // count the folder created - CFactory::_('Utilities.Counter')->folder++; + Factory::_('Utilities.Counter')->folder++; } foreach ($areas as $area => $languageStrings) { @@ -473,7 +472,7 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin array_keys($languageStrings) ); // set the line counter - CFactory::_('Utilities.Counter')->line += count( + Factory::_('Utilities.Counter')->line += count( (array) $lang ); // check that the main folder exist @@ -481,18 +480,18 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin { $client_path = $main_path . $act['target_client'] . '/'; // check if exist and create if not - if (!JFolder::exists($client_path)) + if (!Folder::exists($client_path)) { - JFolder::create($client_path); + Folder::create($client_path); // count the folder created $this->folderCount++; } // write the language data to a file - ComponentbuilderHelper::writeFile( + FileHelper::write( $client_path . $act['file_name'], implode(PHP_EOL, $lang) ); // count the file created - CFactory::_('Utilities.Counter')->line++; + Factory::_('Utilities.Counter')->line++; // build xml strings if (!isset($langXML[$main_path])) { @@ -522,25 +521,25 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin { // get the XML $xml = str_replace( - array_keys(CFactory::_('Compiler.Builder.Content.One')->allActive()), - array_values(CFactory::_('Compiler.Builder.Content.One')->allActive()), + array_keys(Factory::_('Compiler.Builder.Content.One')->allActive()), + array_values(Factory::_('Compiler.Builder.Content.One')->allActive()), $this->getLanguageXML($target_clients, $langPackages[$main_path], $langNames[$main_path]) ); // get the XML File Name $xmlFileName = $langXMLNames[$main_path] . '.xml'; // write the language data to a file - ComponentbuilderHelper::writeFile( + FileHelper::write( $main_path . $xmlFileName, $xml ); // set the zip full path $zipPath = $this->tempPath . '/' . $langZIPNames[$main_path] . '.zip'; // now zip the package - if (ComponentbuilderHelper::zip( + if (FileHelper::zip( $main_path, $zipPath )) { // now remove the package - ComponentbuilderHelper::removeFolder($main_path); + Factory::_('Utilities.Folder')->remove($main_path); } } } @@ -679,17 +678,16 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin * @return bool * */ - protected function shouldLanguageBeAdded(&$tag, &$languageStrings, &$total, - &$file_name - ) { + protected function shouldLanguageBeAdded(&$tag, &$languageStrings, &$total, &$file_name) + { // only log messages for none $this->langTag translations if ($this->langTag !== $tag) { $langStringNr = count($languageStrings); - $langStringSum = ComponentbuilderHelper::bcmath( + $langStringSum = MathHelper::bc( 'mul', $langStringNr, 100 ); - $percentage = ComponentbuilderHelper::bcmath( + $percentage = MathHelper::bc( 'div', $langStringSum, $total ); $stringNAme = ($langStringNr == 1) ? '(string ' @@ -703,7 +701,7 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin if ($percentage < $this->percentageLanguageAdd) { // dont add - CFactory::_('Compiler.Builder.Language.Messages')->set("exclude.$file_name", + Factory::_('Compiler.Builder.Language.Messages')->set("exclude.$file_name", '' . $total . '(total ' . $this->langTag . ' strings) only ' . $langStringNr . '' . $stringNAme @@ -715,7 +713,7 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin } // show if it was added as well - CFactory::_('Compiler.Builder.Language.Messages')->set("include.$file_name", + Factory::_('Compiler.Builder.Language.Messages')->set("include.$file_name", '' . $total . '(total ' . $this->langTag . ' strings) and ' . $langStringNr . '' . $stringNAme . ' = ' @@ -724,6 +722,5 @@ class PlgExtensionComponentbuilderLanguagePackaging extends CMSPlugin } return true; - } - + } } diff --git a/componentbuilderlanguagepackaging.xml b/componentbuilderlanguagepackaging.xml index 555ddb1..9fd0a43 100644 --- a/componentbuilderlanguagepackaging.xml +++ b/componentbuilderlanguagepackaging.xml @@ -1,13 +1,13 @@ - + PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING - 9th March, 2024 + 11th March, 2024 Llewellyn van der Merwe joomla@vdm.io https://dev.vdm.io Copyright (C) 2015 Vast Development Method. All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt - 1.2.0 + 2.0.0 PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING_XML_DESCRIPTION diff --git a/language/en-GB/en-GB.plg_extension_componentbuilderlanguagepackaging.ini b/language/en-GB/en-GB.plg_extension_componentbuilderlanguagepackaging.ini index 6f37179..89ee216 100644 --- a/language/en-GB/en-GB.plg_extension_componentbuilderlanguagepackaging.ini +++ b/language/en-GB/en-GB.plg_extension_componentbuilderlanguagepackaging.ini @@ -1,3 +1,3 @@ PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING="Extension - Componentbuilder Language Packaging" PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING_DESCRIPTION="This plugin is used to add language packaging to JCB. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field." -PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING_XML_DESCRIPTION="

Extension - Componentbuilder Language Packaging (v.1.2.0)

This plugin is used to add language packaging to JCB. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.

Created by Llewellyn van der Merwe
Development started 12th October, 2019

" \ No newline at end of file +PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING_XML_DESCRIPTION="

Extension - Componentbuilder Language Packaging (v.2.0.0)

This plugin is used to add language packaging to JCB. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.

Created by Llewellyn van der Merwe
Development started 10th March, 2024

" \ No newline at end of file diff --git a/language/en-GB/en-GB.plg_extension_componentbuilderlanguagepackaging.sys.ini b/language/en-GB/en-GB.plg_extension_componentbuilderlanguagepackaging.sys.ini index 6f37179..89ee216 100644 --- a/language/en-GB/en-GB.plg_extension_componentbuilderlanguagepackaging.sys.ini +++ b/language/en-GB/en-GB.plg_extension_componentbuilderlanguagepackaging.sys.ini @@ -1,3 +1,3 @@ PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING="Extension - Componentbuilder Language Packaging" PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING_DESCRIPTION="This plugin is used to add language packaging to JCB. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field." -PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING_XML_DESCRIPTION="

Extension - Componentbuilder Language Packaging (v.1.2.0)

This plugin is used to add language packaging to JCB. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.

Created by Llewellyn van der Merwe
Development started 12th October, 2019

" \ No newline at end of file +PLG_EXTENSION_COMPONENTBUILDERLANGUAGEPACKAGING_XML_DESCRIPTION="

Extension - Componentbuilder Language Packaging (v.2.0.0)

This plugin is used to add language packaging to JCB. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.

Created by Llewellyn van der Merwe
Development started 10th March, 2024

" \ No newline at end of file diff --git a/script.php b/script.php index f98dec4..baeb649 100644 --- a/script.php +++ b/script.php @@ -24,104 +24,4 @@ use Joomla\CMS\Filesystem\Folder; */ class plgExtensionComponentbuilderLanguagePackagingInstallerScript { - - /** - * Called before any type of action - * - * @param string $route Which action is happening (install|uninstall|discover_install|update) - * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script - * - * @return boolean True on success - */ - public function preflight($route, $adapter) - { - // get application - $app = Factory::getApplication(); - - // the default for both install and update - $jversion = new JVersion(); - if (!$jversion->isCompatible('3.8.0')) - { - $app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error'); - return false; - } - - if ('install' === $route) - { -// needs fix - - - // check that componentbuilder is installed - $pathToCore = JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'; - if (!JFile::exists($pathToCore)) - { - $app->enqueueMessage('Joomla Component Builder must first be installed from Joomla Component Builder.', 'error'); - return false; - } - - // load the helper class - JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'); - - // block install - $blockInstall = true; - - // check the version of JCB - $manifest = ComponentbuilderHelper::manifest(); - if (isset($manifest->version) && strpos($manifest->version, '.') !== false) - { - // get the version - $jcbVersion = explode('.', $manifest->version); - // check that we have JCB 3.0.0 or higher installed - if (count($jcbVersion) == 3 && $jcbVersion[0] >= 3 && - ( - ($jcbVersion[0] == 3 && $jcbVersion[1] == 0 && $jcbVersion[2] >= 0) || - ($jcbVersion[0] == 3 && $jcbVersion[1] > 0) || - $jcbVersion[0] > 3) - ) - { - $blockInstall = false; - } - } - - // allow install if all conditions are met - if ($blockInstall) - { - $app->enqueueMessage('Please upgrade to JCB v3.0.0 or higher before installing this plugin.', 'error'); - return false; - } - - - // check that componentbuilder is installed - $pathToCore = JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'; - if (!JFile::exists($pathToCore)) - { - $app->enqueueMessage('Joomla Component Builder must first be installed from Joomla Component Builder.', 'error'); - return false; - } - // load the helper class - JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'); - // block install - $blockInstall = true; - // check the version of JCB - $manifest = ComponentbuilderHelper::manifest(); - if (isset($manifest->version) && strpos($manifest->version, '.') !== false) - { - // get the version - $jcbVersion = explode('.', $manifest->version); - // check that we have JCB 2.10.13 or higher installed - if (count($jcbVersion) == 3 && (($jcbVersion[0] == 2 && $jcbVersion[1] >= 10 && (($jcbVersion[1] == 10 && $jcbVersion[2] >= 13) || ($jcbVersion[1] > 10))) || $jcbVersion[0] >= 3)) - { - $blockInstall = false; - } - } - // allow install if all conditions are met - if ($blockInstall) - { - $app->enqueueMessage('Please upgrade to JCB 2.10.13 or higher before installing this plugin.', 'error'); - return false; - } - } - - return true; - } }