From cbbe81168d9a4aab1c9cc169dc14e9cc60175039 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Fri, 3 Dec 2021 04:46:17 +0200 Subject: [PATCH] update - v1.0.7 --- componentbuilderheaderscompiler.php | 223 ++++++++++++++---- componentbuilderheaderscompiler.xml | 10 +- ...ension_componentbuilderheaderscompiler.ini | 4 +- ...on_componentbuilderheaderscompiler.sys.ini | 4 +- script.php | 22 +- 5 files changed, 200 insertions(+), 63 deletions(-) diff --git a/componentbuilderheaderscompiler.php b/componentbuilderheaderscompiler.php index 6a004af..25ad800 100644 --- a/componentbuilderheaderscompiler.php +++ b/componentbuilderheaderscompiler.php @@ -1,12 +1,12 @@ - * @github Joomla Component Builder - * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. - * @license GNU General Public License version 2 or later; see LICENSE.txt +/** + * @package Joomla.Component.Builder + * + * @created 30th April, 2015 + * @author Llewellyn van der Merwe + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access to this file @@ -22,11 +22,11 @@ JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/c * Extension - Componentbuilder Headers Compiler plugin. * * @package ComponentbuilderHeadersCompiler - * @since 1.0.5 + * @since 1.0.7 */ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin { - /** +/** * Global switch to see if a file has custom headers. * * @var boolean @@ -42,6 +42,22 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin */ protected $activeFiles = array(); + /** + * The compiler placeholders values + * + * @var array + * @since 1.0.6 + */ + protected $placeholders = array(); + + /** + * The powers to include in project + * + * @var array + * @since 1.0.6 + */ + protected $linkedPowers = array(); + /** * The Targets * @@ -61,6 +77,16 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin 'context' => 'admin.view', 'view' => 'name_single' ), + 'add_admin_view_html' => array( + 'field' => 'admin_view_html', + 'context' => 'admin.view.html', + 'view' => 'name_single' + ), + 'add_site_admin_view_html' => array( + 'field' => 'site_admin_view_html', + 'context' => 'site.admin.view.html', + 'view' => 'name_single' + ), 'add_admin_view_controller' => array( 'field' => 'admin_view_controller', 'context' => 'admin.view.controller', @@ -76,6 +102,11 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin 'context' => 'admin.views', 'view' => 'name_list' ), + 'add_admin_views_html' => array( + 'field' => 'admin_views_html', + 'context' => 'admin.views.html', + 'view' => 'name_list' + ), 'add_admin_views_controller' => array( 'field' => 'admin_views_controller', 'context' => 'admin.views.controller', @@ -94,6 +125,11 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin 'context' => 'site.view', 'view' => 'code' ), + 'add_site_view_html' => array( + 'field' => 'site_view_html', + 'context' => 'site.view.html', + 'view' => 'code' + ), 'add_site_view_controller' => array( 'field' => 'site_view_controller', 'context' => 'site.view.controller', @@ -109,6 +145,11 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin 'context' => 'site.views', 'view' => 'code' ), + 'add_site_views_html' => array( + 'field' => 'site_views_html', + 'context' => 'site.views.html', + 'view' => 'code' + ), 'add_site_views_controller' => array( 'field' => 'site_views_controller', 'context' => 'site.views.controller', @@ -127,6 +168,11 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin 'context' => 'custom.admin.view', 'view' => 'code' ), + 'add_custom_admin_view_html' => array( + 'field' => 'custom_admin_view_html', + 'context' => 'custom.admin.view.html', + 'view' => 'code' + ), 'add_custom_admin_view_controller' => array( 'field' => 'custom_admin_view_controller', 'context' => 'custom.admin.view.controller', @@ -142,6 +188,11 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin 'context' => 'custom.admin.views', 'view' => 'code' ), + 'add_custom_admin_views_html' => array( + 'field' => 'custom_admin_views_html', + 'context' => 'custom.admin.views.html', + 'view' => 'code' + ), 'add_custom_admin_views_controller' => array( 'field' => 'custom_admin_views_controller', 'context' => 'custom.admin.views.controller', @@ -183,7 +234,7 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin public function jcb_ce_onBeforeModelViewData(&$context, &$view, &$placeholders ) { - // add the privacy + // add the headers $view->params = (isset($view->params) && ComponentbuilderHelper::checkJson($view->params)) ? json_decode( $view->params, true @@ -199,15 +250,8 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin if (isset($view->params['admin_view_headers'][$target]) && $view->params['admin_view_headers'][$target] == 1) { - // activate the load of the privacy plugin - $this->loadHeaders = true; - // setup the view key name - $view_name = ComponentbuilderHelper::safeString( - $view->{$event['view']} - ); - // load the headers - $this->activeFiles[$view_name][$event['context']] - = $view->params['admin_view_headers'][$event['field']]; + // get the header string if set + $this->getHeaderString($view, $event, 'admin_view_headers'); } } } @@ -223,7 +267,7 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin public function jcb_ce_onBeforeModelCustomViewData(&$context, &$view, &$id, &$table ) { - // add the privacy + // add the headers $view->params = (isset($view->params) && ComponentbuilderHelper::checkJson($view->params)) ? json_decode( $view->params, true @@ -240,15 +284,8 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin if (isset($view->params['site_view_headers'][$target]) && $view->params['site_view_headers'][$target] == 1) { - // activate the load of the privacy plugin - $this->loadHeaders = true; - // setup the view key name - $view_name = ComponentbuilderHelper::safeString( - $view->{$event['view']} - ); - // load the headers - $this->activeFiles[$view_name][$event['context']] - = $view->params['site_view_headers'][$event['field']]; + // get the header string if set + $this->getHeaderString($view, $event, 'site_view_headers'); } } } @@ -264,15 +301,8 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin if (isset($view->params['custom_admin_view_headers'][$target]) && $view->params['custom_admin_view_headers'][$target] == 1) { - // activate the load of the privacy plugin - $this->loadHeaders = true; - // setup the view key name - $view_name = ComponentbuilderHelper::safeString( - $view->{$event['view']} - ); - // load the headers - $this->activeFiles[$view_name][$event['context']] - = $view->params['custom_admin_view_headers'][$event['field']]; + // get the header string if set + $this->getHeaderString($view, $event, 'custom_admin_view_headers'); } } } @@ -303,7 +333,7 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin if (isset($component->params['joomla_component_headers'][$target]) && $component->params['joomla_component_headers'][$target] == 1) { - // activate the load of the privacy plugin + // activate the load of the headers $this->loadHeaders = true; // load the headers $this->activeFiles[$event['view']][$event['context']] @@ -313,6 +343,85 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin } } + /** + * get the header string + * + * @return void + * + * @since 1.0 + */ + protected function getHeaderString(&$view, &$get, $key, $view_name = null) + { + // we first check if the value is set + if (isset($view->params[$key][$get['field']]) || isset($view->params[$key]['power_' . $get['field']])) + { + // activate the load of the headers + $this->loadHeaders = true; + // setup the view key name + if (!$view_name) + { + $view_name = ComponentbuilderHelper::safeString( + $view->{$get['view']} + ); + } + // we start this field if not already + if (!isset($this->activeFiles[$view_name][$get['context']])) + { + $this->activeFiles[$view_name][$get['context']] = ''; + } + // start little bucket + $bucket = array(); + // load the headers if text + if (isset($view->params[$key][$get['field']]) && ComponentbuilderHelper::checkString($view->params[$key][$get['field']])) + { + $bucket[] = $view->params[$key][$get['field']]; + } + // load the headers if power + if (isset($view->params[$key]['power_' . $get['field']]) && ComponentbuilderHelper::checkArray($view->params[$key]['power_' . $get['field']], true) + && ($use = $this->getPowers($view->params[$key]['power_' . $get['field']])) !== false) + { + $bucket[] = 'use ' . implode(';' . PHP_EOL . 'use ', $use) . ';'; + } + // we start this field if not already + if (ComponentbuilderHelper::checkArray($bucket, true)) + { + $this->activeFiles[$view_name][$get['context']] .= implode(PHP_EOL, $bucket); + } + } + } + + /** + * get the powers header use strings + * + * @return string + * + * @since 1.0.6 + */ + protected function getPowers($ids) + { + // if none are found + $namspaces = false; + // add to active powers + if (($namspaces = ComponentbuilderHelper::getVars('power', $ids, 'id', 'namespace')) !== false) + { + foreach ($ids as $id) + { + $this->linkedPowers[$id] = $id; + } + // convert the dots to namespace + $namspaces = array_map( function($namespace) { + return ComponentbuilderHelper::safeNamespace( + str_replace( + array_keys($this->placeholders), + array_values($this->placeholders), + str_replace('.', '\\', $namespace) + ) + ); + }, $namspaces ); + } + return $namspaces; + } + /** * Event Triggered in the compiler [on set Class Header] * @@ -331,9 +440,9 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin foreach ($headers as $n => $header) { // we check if this header is also set from the user - if (strpos( + if (empty($header) || (isset($this->activeFiles[$view_name][$event_context]) && strpos( $this->activeFiles[$view_name][$event_context], $header - ) !== false) + ) !== false)) { // since it is set, remove it here unset($headers[$n]); @@ -344,5 +453,33 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin $headers[] = $this->activeFiles[$view_name][$event_context]; } } - + + /** + * Event Triggered in the compiler [on Before Get Component Data] + * + * @return void + * + * @since 1.0.6 + */ + public function jcb_ce_onBeforeGetComponentData(&$context, $compiler) + { + // get placeholders from the compiler + $this->placeholders = $compiler->globalPlaceholders; + } + + /** + * Event Triggered in the compiler [on After Get Component Data] + * + * @return void + * + * @since 1.0.6 + */ + public function jcb_ce_onAfterGetComponentData(&$context, $compiler) + { + // add the powers to the component + if (ComponentbuilderHelper::checkArray($this->linkedPowers, true)) + { + $compiler->linkedPowers = $this->linkedPowers; + } + } } diff --git a/componentbuilderheaderscompiler.xml b/componentbuilderheaderscompiler.xml index 8bccec3..b6ca497 100644 --- a/componentbuilderheaderscompiler.xml +++ b/componentbuilderheaderscompiler.xml @@ -1,13 +1,13 @@ - + PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER - 20th February, 2021 + 3rd December, 2021 Llewellyn van der Merwe - llewellyn@joomlacomponentbuilder.com - http://www.joomlacomponentbuilder.com + 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.0.5 + 1.0.7 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 b70002c..0f1cd0a 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.1.0.5)

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.1.0.7)

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 +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 b70002c..0f1cd0a 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.1.0.5)

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.1.0.7)

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 +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 44a5e4f..497c857 100644 --- a/script.php +++ b/script.php @@ -1,12 +1,12 @@ - * @github Joomla Component Builder - * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. - * @license GNU General Public License version 2 or later; see LICENSE.txt +/** + * @package Joomla.Component.Builder + * + * @created 30th April, 2015 + * @author Llewellyn van der Merwe + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access to this file @@ -60,8 +60,8 @@ class plgExtensionComponentbuilderHeadersCompilerInstallerScript { // get the version $jcbVersion = explode('.', $manifest->version); - // check that we have JCB 2.12.6 or higher installed - if (count($jcbVersion) == 3 && $jcbVersion[0] >= 2 && (($jcbVersion[1] == 12 && $jcbVersion[2] >= 6) || $jcbVersion[1] > 12)) + // check that we have JCB 2.12.14 or higher installed + if (count($jcbVersion) == 3 && (($jcbVersion[0] == 2 && (($jcbVersion[1] == 12 && $jcbVersion[2] >= 14) || ($jcbVersion[1] > 12))) || $jcbVersion[0] >= 3)) { $blockInstall = false; } @@ -69,7 +69,7 @@ class plgExtensionComponentbuilderHeadersCompilerInstallerScript // allow install if all conditions are met if ($blockInstall) { - $app->enqueueMessage('Please upgrade to JCB 2.12.6 or higher before installing this plugin.', 'error'); + $app->enqueueMessage('Please upgrade to JCB-PRO 2.12.14 or higher before installing this plugin.', 'error'); return false; } }