commit aad37a151577f45b66fdf8c21032ea279535344b Author: Llewellyn van der Merwe Date: Thu Oct 14 16:31:41 2021 +0200 first commit - v1.0.0 diff --git a/componentbuilderheaderscompiler.php b/componentbuilderheaderscompiler.php new file mode 100644 index 0000000..a025895 --- /dev/null +++ b/componentbuilderheaderscompiler.php @@ -0,0 +1,155 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\Registry\Registry; + +JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'); + +/** + * Extension - Componentbuilder Headers Compiler plugin. + * + * @package ComponentbuilderHeadersCompiler + * @since 1.0.0 + */ +class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin +{ + /** + * Global switch to see if component have need class headers. + * + * @var boolean + * @since 1.0.0 + */ + protected $loadClassHeaders = false; + + /** + * The Views active with default ordering options + * + * @var array + * @since 1.0.0 + */ + protected $activeViews = array(); + + /** + * The Target + * + * @var string + * @since 1.0.0 + */ + protected $target = 'admin_view_headers'; + + /** + * The Targets + * + * @var array + * @since 1.0.0 + */ + protected $targets + = array( + 'add_admin_view_controller' => array( + 'field' => 'admin_view_controller', + 'context' => 'admin.view.controller', + 'view' => 'name_single' + ), + 'add_admin_views_controller' => array( + 'field' => 'admin_views_controller', + 'context' => 'admin.views.controller', + 'view' => 'name_list' + ), + 'add_admin_view_model' => array( + 'field' => 'admin_view_model', + 'context' => 'admin.view.model', + 'view' => 'name_single' + ), + 'add_admin_views_model' => array( + 'field' => 'admin_views_model', + 'context' => 'admin.views.model', + 'view' => 'name_list' + ) + ); + + /** + * Event Triggered in the compiler [on Before Model View Data] + * + * @return void + * + * @since 1.0 + */ + public function jcb_ce_onBeforeModelViewData(&$context, &$view, + &$placeholders + ) { + // add the privacy + $view->params = (isset($view->params) + && ComponentbuilderHelper::checkJson($view->params)) ? json_decode( + $view->params, true + ) : $view->params; + if (ComponentbuilderHelper::checkArray($view->params) + && isset($view->params[$this->target]) + && ComponentbuilderHelper::checkArray( + $view->params[$this->target] + )) + { + foreach ($this->targets as $target => $event) + { + if (isset($view->params[$this->target][$target]) + && $view->params[$this->target][$target] == 1) + { + // activate the load of the privacy plugin + $this->loadClassHeaders = true; + // setup the view key name + $view_name = ComponentbuilderHelper::safeString( + $view->{$event['view']} + ); + // load the admin view details + $this->activeViews[$view_name][$event['context']] + = $view->params[$this->target][$event['field']]; + } + } + } + } + + /** + * Event Triggered in the compiler [on set ClassHeader] + * + * @return void + * + * @since 1.0 + */ + public function jcb_ce_setClassHeader(&$context, &$event_context, + &$view_name, + &$headers + ) { + if ($this->loadClassHeaders && isset($this->activeViews[$view_name]) + && isset($this->activeViews[$view_name][$event_context])) + { + // we have default headers we actually need + foreach ($headers as $n => $header) + { + // we check if this header is also set from the user + if (strpos( + $this->activeViews[$view_name][$event_context], $header + ) !== false) + { + // since it is set, remove it here + unset($headers[$n]); + } + } + // now add the custom headers + // yes they are below the defaults, unless overridden and remove above + $headers[] = $this->activeViews[$view_name][$event_context]; + } + } + +} diff --git a/componentbuilderheaderscompiler.xml b/componentbuilderheaderscompiler.xml new file mode 100644 index 0000000..c5e0a3c --- /dev/null +++ b/componentbuilderheaderscompiler.xml @@ -0,0 +1,28 @@ + + + PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER + 8th December, 2020 + Llewellyn van der Merwe + llewellyn@joomlacomponentbuilder.com + http://www.joomlacomponentbuilder.com + Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + 1.0.0 + PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION + + + script.php + + + + en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini + en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.sys.ini + + + + + componentbuilderheaderscompiler.php + index.html + language + + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini b/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini new file mode 100644 index 0000000..6bb8c63 --- /dev/null +++ b/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini @@ -0,0 +1,7 @@ +PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER="Extension - Componentbuilder Headers Compiler" +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 admin views where you would like to set Custom Headers." +PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder Headers Compiler (v.1.0.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 admin views 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 new file mode 100644 index 0000000..6bb8c63 --- /dev/null +++ b/language/en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.sys.ini @@ -0,0 +1,7 @@ +PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER="Extension - Componentbuilder Headers Compiler" +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 admin views where you would like to set Custom Headers." +PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder Headers Compiler (v.1.0.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 admin views 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/index.html b/language/en-GB/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/language/en-GB/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/language/index.html b/language/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/language/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/script.php b/script.php new file mode 100644 index 0000000..97c2356 --- /dev/null +++ b/script.php @@ -0,0 +1,79 @@ + + * @github Joomla Component Builder + * @copyright Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + +/** + * Extension - Componentbuilder Headers Compiler script file. + * + * @package PlgExtensionComponentbuilderHeadersCompiler + */ +class plgExtensionComponentbuilderHeadersCompilerInstallerScript +{ + + /** + * Called before any type of action + * + * @param string $route Which action is happening (install|uninstall|discover_install|update) + * @param JAdapterInstance $adapter The object responsible for running this script + * + * @return boolean True on success + */ + public function preflight($route, JAdapterInstance $adapter) + { + // get application + $app = JFactory::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) + { + // 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.11.7 or higher installed + if (count($jcbVersion) == 3 && $jcbVersion[0] >= 2 && $jcbVersion[1] >= 11 && (($jcbVersion[1] == 11 && $jcbVersion[2] >= 7) || ($jcbVersion[1] > 11))) + { + $blockInstall = false; + } + } + // allow install if all conditions are met + if ($blockInstall) + { + $app->enqueueMessage('Please upgrade to JCB 2.12.1 or higher before installing this plugin.', 'error'); + return false; + } + } + + return true; + } +}