diff --git a/componentbuilderheaderscompiler.php b/componentbuilderheaderscompiler.php index 27cb988..b1bde1f 100644 --- a/componentbuilderheaderscompiler.php +++ b/componentbuilderheaderscompiler.php @@ -22,7 +22,7 @@ JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/c * Extension - Componentbuilder Headers Compiler plugin. * * @package ComponentbuilderHeadersCompiler - * @since 2.0.1 + * @since 2.1.0 */ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin { @@ -581,9 +581,9 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin } // load the headers if power if (isset($params['power_' . $get['field']]) && ComponentbuilderHelper::checkArray($params['power_' . $get['field']], true) - && ($use = $this->getPowers($params['power_' . $get['field']])) !== false) + && ($powers = $this->getPowers($params['power_' . $get['field']])) !== false) { - $headers[] = 'use ' . implode(';' . PHP_EOL . 'use ', $use) . ';'; + $headers[] = $powers; } // check if we found some header values if (ComponentbuilderHelper::checkArray($headers, true)) @@ -637,30 +637,60 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin * * @since 1.0.6 */ - protected function getPowers($guids) + protected function getPowers($rows) { - // if none are found - $namspaces = false; - // add to active powers - if (($namspaces = ComponentbuilderHelper::getVars('power', $guids, 'guid', 'namespace', 'IN_STRINGS')) !== false) - { - foreach ($guids as $guid) - { - $this->linkedPowers[$guid] = $guid; + // load the active powers + $powers = array_filter( + // get the power namespace + array_map(function ($row) { + if (($power = ComponentbuilderHelper::getGUID($row['power'], 'power', ['a.guid', 'a.namespace'])) !== false) + { + $power->build = (int) $row['build']; + $power->as = (string) $row['as']; + return $power; + } + return false; + }, $rows), + // check that we have valid powers + function ($row) { + return is_object($row) && isset($row->guid); } + ); + // add to active powers + if (ComponentbuilderHelper::checkArray($powers)) + { // convert the dots to namespace - $namspaces = array_map(function ($namespace) { - return ComponentbuilderHelper::safeNamespace( + $powers = array_map(function ($power) { + // add to compiler (to build) + if ($power->build != 6) + { + // secure that always will remain always even if only set that way once + if (empty($this->linkedPowers[$power->guid]) || $power->build == 1) + { + $this->linkedPowers[$power->guid] = $power->build; + } + } + // build the namespace + $namespace = ComponentbuilderHelper::safeNamespace( str_replace( array_keys($this->placeholders), array_values($this->placeholders), - str_replace('.', '\\', $namespace) + str_replace('.', '\\', $power->namespace) ) ); - }, $namspaces); + // check if it has an AS option + if (ComponentbuilderHelper::checkString($power->as) && $power->as !== 'default') + { + return 'use ' . $namespace . ' as ' . $power->as . ';'; + } + return 'use ' . $namespace . ';'; + }, $powers); + + // return the found powers + return implode(PHP_EOL, $powers); } - return $namspaces; + return false; } } diff --git a/componentbuilderheaderscompiler.xml b/componentbuilderheaderscompiler.xml index f7a31d5..78b5848 100644 --- a/componentbuilderheaderscompiler.xml +++ b/componentbuilderheaderscompiler.xml @@ -1,13 +1,13 @@ PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER - 9th May, 2022 + 18th May, 2022 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 - 2.0.1 + 2.1.0 PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION diff --git a/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini b/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini index ad9fb28..f85c644 100644 --- a/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini +++ b/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini @@ -2,6 +2,6 @@ PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER="Extension - Componentbuilder Head PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_DESCRIPTION="This plugin is used to set the custom headers for your classes during compilation. 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. Also be sure to set your code where you would like to set Custom Headers." -PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder Headers Compiler (v.2.0.1)

This plugin is used to set the custom headers for your classes during compilation. 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_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder Headers Compiler (v.2.1.0)

This plugin is used to set the custom headers for your classes during compilation. 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. Also be sure to set your code where you would like to set Custom Headers.

Created by Llewellyn van der Merwe
Development started 24th May, 2020

" \ No newline at end of file diff --git a/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.sys.ini b/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.sys.ini index ad9fb28..f85c644 100644 --- a/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.sys.ini +++ b/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.sys.ini @@ -2,6 +2,6 @@ PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER="Extension - Componentbuilder Head PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_DESCRIPTION="This plugin is used to set the custom headers for your classes during compilation. 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. Also be sure to set your code where you would like to set Custom Headers." -PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder Headers Compiler (v.2.0.1)

This plugin is used to set the custom headers for your classes during compilation. 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_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder Headers Compiler (v.2.1.0)

This plugin is used to set the custom headers for your classes during compilation. 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. Also be sure to set your code where you would like to set Custom Headers.

Created by Llewellyn van der Merwe
Development started 24th May, 2020

" \ No newline at end of file diff --git a/script.php b/script.php index bdc9388..bc9558b 100644 --- a/script.php +++ b/script.php @@ -61,10 +61,10 @@ class plgExtensionComponentbuilderHeadersCompilerInstallerScript { // get the version $jcbVersion = explode('.', $manifest->version); - // check that we have JCB 3.0.11 or higher installed + // check that we have JCB 3.0.14 or higher installed if (count($jcbVersion) == 3 && $jcbVersion[0] >= 3 && ( - ($jcbVersion[0] == 3 && $jcbVersion[1] == 0 && $jcbVersion[2] >= 11) || + ($jcbVersion[0] == 3 && $jcbVersion[1] == 0 && $jcbVersion[2] >= 14) || ($jcbVersion[0] == 3 && $jcbVersion[1] > 0) || $jcbVersion[0] > 3) ) @@ -75,7 +75,7 @@ class plgExtensionComponentbuilderHeadersCompilerInstallerScript // allow install if all conditions are met if ($blockInstall) { - $app->enqueueMessage('Please upgrade to JCB-Pro v3.0.11 or higher before installing this plugin.', 'error'); + $app->enqueueMessage('Please upgrade to JCB-Pro v3.0.14 or higher before installing this plugin.', 'error'); return false; } }