diff --git a/componentbuilderheaderscompiler.php b/componentbuilderheaderscompiler.php index c8583ec..62eabc6 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.1.1 + * @since 2.1.2 */ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin { @@ -441,28 +441,26 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin public function jcb_ce_setClassHeader(&$context, &$event_context, &$view_name, &$headers) { if ($this->loadHeaders && isset($this->activeHeaders[$view_name]) - && isset($this->activeHeaders[$view_name][$event_context])) + && isset($this->activeHeaders[$view_name][$event_context]) + && is_array($this->activeHeaders[$view_name][$event_context])) { - // we have default headers we actually need - foreach ($headers as $n => $header) + // work with the header values as keys + $_headers = array_flip($headers); + + // new headers + $new = $this->activeHeaders[$view_name][$event_context]; + + // now add the new headers + foreach ($new as $n => $header) { - // if an empty line is found just skip it - if (empty($header)) + // if an empty line is found just skip it + // we check if this header is already set + if (empty($header) || isset($_headers[$header])) { continue; } - // we check if this header is also set from the user - if (isset($this->activeHeaders[$view_name][$event_context]) && strpos( - $this->activeHeaders[$view_name][$event_context], $header - ) !== false) - { - // since it is set, remove it here - unset($headers[$n]); - } + $headers[] = $header; } - // now add the custom headers - // yes they are below the defaults, unless overridden and removed above - $headers[] = $this->activeHeaders[$view_name][$event_context]; } } @@ -577,13 +575,28 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin // load the headers if text if (isset($params[$get['field']]) && ComponentbuilderHelper::checkString($params[$get['field']])) { - $headers[] = $params[$get['field']]; + if (($_headers = explode(PHP_EOL, $params[$get['field']])) !== false) + { + foreach ($_headers as $header) + { + $header = trim($header); + if (empty($header)) + { + continue; + } + $headers[$header] = $header; + } + } } // load the headers if power if (isset($params['power_' . $get['field']]) && ComponentbuilderHelper::checkArray($params['power_' . $get['field']], true) && ($powers = $this->getPowers($params['power_' . $get['field']])) !== false) { - $headers[] = $powers; + foreach ($powers as $power) + { + $power = trim($power); + $headers[$power] = $power; + } } // check if we found some header values if (ComponentbuilderHelper::checkArray($headers, true)) @@ -594,15 +607,14 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin if (!isset($this->activeHeaders[$view_name][$get['context']])) { // start the active header - $this->activeHeaders[$view_name][$get['context']] = ''; + $this->activeHeaders[$view_name][$get['context']] = []; } - else + // load the found headers and avoid adding the same header twice + foreach ($headers as $header) { - // each addition we add a new line - $this->activeHeaders[$view_name][$get['context']] .= PHP_EOL; + $header = trim($header); + $this->activeHeaders[$view_name][$get['context']][$header] = $header; } - // load the found headers - $this->activeHeaders[$view_name][$get['context']] .= implode(PHP_EOL, $headers); } } } @@ -633,11 +645,11 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin /** * get the powers header use strings * - * @return mixed + * @return array|null * * @since 1.0.6 */ - protected function getPowers($rows) + protected function getPowers($rows): ?array { // load the active powers $powers = array_filter( @@ -660,7 +672,7 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin if (ComponentbuilderHelper::checkArray($powers)) { // convert the dots to namespace - $powers = array_map(function ($power) { + return array_map(function ($power) { // add to compiler (to build) if ($power->build != 6) { @@ -685,12 +697,9 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin } return 'use ' . $namespace . ';'; }, $powers); - - // return the found powers - return implode(PHP_EOL, $powers); } - return false; + return null; } } diff --git a/componentbuilderheaderscompiler.xml b/componentbuilderheaderscompiler.xml index a70f606..f348b33 100644 --- a/componentbuilderheaderscompiler.xml +++ b/componentbuilderheaderscompiler.xml @@ -7,7 +7,7 @@ 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.1.1 + 2.1.2 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 df9fa89..c41ee6b 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.1.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.2)

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 df9fa89..c41ee6b 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.1.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.2)

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