From d6cf620a84f0240430f36dc53f92f6d4f95126d6 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 14 Oct 2021 16:30:44 +0200 Subject: [PATCH] first commit - v1.0.0 --- componentbuildercustomadminheaderstabs.php | 73 +++++++++ componentbuildercustomadminheaderstabs.xml | 31 ++++ fields/index.html | 1 + forms/custom_admin_view.xml | 146 ++++++++++++++++++ forms/index.html | 1 + index.html | 1 + ...componentbuildercustomadminheaderstabs.ini | 30 ++++ ...onentbuildercustomadminheaderstabs.sys.ini | 30 ++++ language/en-GB/index.html | 1 + language/index.html | 1 + rules/code.php | 53 +++++++ rules/index.html | 1 + script.php | 79 ++++++++++ 13 files changed, 448 insertions(+) create mode 100644 componentbuildercustomadminheaderstabs.php create mode 100644 componentbuildercustomadminheaderstabs.xml create mode 100644 fields/index.html create mode 100644 forms/custom_admin_view.xml create mode 100644 forms/index.html create mode 100644 index.html create mode 100644 language/en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.ini create mode 100644 language/en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.sys.ini create mode 100644 language/en-GB/index.html create mode 100644 language/index.html create mode 100644 rules/code.php create mode 100644 rules/index.html create mode 100644 script.php diff --git a/componentbuildercustomadminheaderstabs.php b/componentbuildercustomadminheaderstabs.php new file mode 100644 index 0000000..077f19c --- /dev/null +++ b/componentbuildercustomadminheaderstabs.php @@ -0,0 +1,73 @@ + + * @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\Form\Form; +use Joomla\CMS\Plugin\CMSPlugin; + +JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php'); + +/** + * Content - Componentbuilder Custom Admin Headers Tabs plugin. + * + * @package ComponentbuilderCustomAdminHeadersTabs + * @since 1.0.0 + */ +class PlgContentComponentbuilderCustomAdminHeadersTabs extends CMSPlugin +{ + /** + * Affects constructor behavior. If true, language files will be loaded automatically. + * + * @var boolean + * @since 1.0 + */ + protected $autoloadLanguage = true; + + /** + * Runs on content preparation of form. + * + * @param JForm $form The form + * @param stdClass $data The data + * + * @return boolean + * + * @since 1.0 + */ + public function onContentPrepareForm(Form $form, $data) + { + $context = $form->getName(); + + // When this is componentbuilder admin view + if (strpos($context, 'com_componentbuilder.custom_admin_view') === 0) + { + // Add the forms path + Form::addFormPath(__DIR__ . '/forms'); + // add the admin view params for privacy integration + $form->loadFile('custom_admin_view'); + // update all editors to use this components global editor + $global_editor = JComponentHelper::getParams('com_componentbuilder')->get('editor', 'none'); + // set the field editor value (with none as fallback) + $editors = $form->getXml()->xpath('descendant::fields[@name="custom_admin_view_headers"]//field[@type="editor"]'); + // check if we found any + if (ComponentbuilderHelper::checkArray($editors)) + { + foreach ($editors as $editor) + { + // set the editor to the global option + $editor['editor'] = $global_editor . '|none'; + } + } + } + return true; + } +} diff --git a/componentbuildercustomadminheaderstabs.xml b/componentbuildercustomadminheaderstabs.xml new file mode 100644 index 0000000..d595e12 --- /dev/null +++ b/componentbuildercustomadminheaderstabs.xml @@ -0,0 +1,31 @@ + + + PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS + 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_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_XML_DESCRIPTION + + + script.php + + + + en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.ini + en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.sys.ini + + + + + componentbuildercustomadminheaderstabs.php + index.html + language + fields + forms + rules + + \ No newline at end of file diff --git a/fields/index.html b/fields/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/fields/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/forms/custom_admin_view.xml b/forms/custom_admin_view.xml new file mode 100644 index 0000000..17d4132 --- /dev/null +++ b/forms/custom_admin_view.xml @@ -0,0 +1,146 @@ + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/forms/index.html b/forms/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/forms/index.html @@ -0,0 +1 @@ + \ 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_content_componentbuildercustomadminheaderstabs.ini b/language/en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.ini new file mode 100644 index 0000000..2047097 --- /dev/null +++ b/language/en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.ini @@ -0,0 +1,30 @@ +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS="Content - Componentbuilder Custom Admin Headers Tabs" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_DESCRIPTION="This plugin is used to set custom admin class custom headers." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_XML_DESCRIPTION="

Content - Componentbuilder Custom Admin Headers Tabs (v.1.0.0)

This plugin is used to set custom admin class custom headers.

Created by Llewellyn van der Merwe
Development started 8th December, 2020

" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CLASS_HEADERS="Class Headers" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEW_CONTROLLER_LABEL="Target Custom Admin View
Controller Header" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEW_CONTROLLER_DESCRIPTION="Only use this option if you have a getItem as your Main Get, and have custom code in the PHP (controller methods) under the Custom Buttons tab." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_YES="Yes" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_NO="No" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEW_CONTROLLER_LABEL="Class Header
+(custom.admin.view.controller)
+getItem" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEW_CONTROLLER_DESCRIPTION="The class header for custom admin view controller. Only use this option if you have a getItem as your Main Get, and have custom code in the PHP (controller methods) under the Custom Buttons tab." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEW_MODEL_LABEL="Target Custom Admin View
Model Header" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEW_MODEL_DESCRIPTION="Only use this option if you have a getItem as your Main Get." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEW_MODEL_LABEL="Class Header
+(custom.admin.view.model)
+getItem" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEW_MODEL_DESCRIPTION="The class header for custom admin view model. Only use this option if you have a getItem as your Main Get." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEWS_CONTROLLER_LABEL="Target Custom Admin Views
Controller Header" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEWS_CONTROLLER_DESCRIPTION="Only use this option if you have a getListQuery as your Main Get, and have custom code in the PHP (controller methods) under the Custom Buttons tab." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEWS_CONTROLLER_LABEL="Class Header
+(custom.admin.views.controller)
+getListQuery" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEWS_CONTROLLER_DESCRIPTION="The class header for custom admin views controller. Only use this option if you have a getListQuery as your Main Get, and have custom code in the PHP (controller methods) under the Custom Buttons tab." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEWS_MODEL_LABEL="Target Custom Admin Views
Model Header" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEWS_MODEL_DESCRIPTION="Only use this option if you have a getListQuery as your Main Get." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEWS_MODEL_LABEL="Class Header
+(custom.admin.views.model)
+getListQuery" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEWS_MODEL_DESCRIPTION="The class header for custom admin views model. Only use this option if you have a getListQuery as your Main Get." \ No newline at end of file diff --git a/language/en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.sys.ini b/language/en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.sys.ini new file mode 100644 index 0000000..2047097 --- /dev/null +++ b/language/en-GB/en-GB.plg_content_componentbuildercustomadminheaderstabs.sys.ini @@ -0,0 +1,30 @@ +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS="Content - Componentbuilder Custom Admin Headers Tabs" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_DESCRIPTION="This plugin is used to set custom admin class custom headers." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_XML_DESCRIPTION="

Content - Componentbuilder Custom Admin Headers Tabs (v.1.0.0)

This plugin is used to set custom admin class custom headers.

Created by Llewellyn van der Merwe
Development started 8th December, 2020

" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CLASS_HEADERS="Class Headers" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEW_CONTROLLER_LABEL="Target Custom Admin View
Controller Header" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEW_CONTROLLER_DESCRIPTION="Only use this option if you have a getItem as your Main Get, and have custom code in the PHP (controller methods) under the Custom Buttons tab." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_YES="Yes" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_NO="No" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEW_CONTROLLER_LABEL="Class Header
+(custom.admin.view.controller)
+getItem" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEW_CONTROLLER_DESCRIPTION="The class header for custom admin view controller. Only use this option if you have a getItem as your Main Get, and have custom code in the PHP (controller methods) under the Custom Buttons tab." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEW_MODEL_LABEL="Target Custom Admin View
Model Header" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEW_MODEL_DESCRIPTION="Only use this option if you have a getItem as your Main Get." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEW_MODEL_LABEL="Class Header
+(custom.admin.view.model)
+getItem" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEW_MODEL_DESCRIPTION="The class header for custom admin view model. Only use this option if you have a getItem as your Main Get." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEWS_CONTROLLER_LABEL="Target Custom Admin Views
Controller Header" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEWS_CONTROLLER_DESCRIPTION="Only use this option if you have a getListQuery as your Main Get, and have custom code in the PHP (controller methods) under the Custom Buttons tab." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEWS_CONTROLLER_LABEL="Class Header
+(custom.admin.views.controller)
+getListQuery" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEWS_CONTROLLER_DESCRIPTION="The class header for custom admin views controller. Only use this option if you have a getListQuery as your Main Get, and have custom code in the PHP (controller methods) under the Custom Buttons tab." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEWS_MODEL_LABEL="Target Custom Admin Views
Model Header" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_ADD_CUSTOM_ADMIN_VIEWS_MODEL_DESCRIPTION="Only use this option if you have a getListQuery as your Main Get." +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEWS_MODEL_LABEL="Class Header
+(custom.admin.views.model)
+getListQuery" +PLG_CONTENT_COMPONENTBUILDERCUSTOMADMINHEADERSTABS_CUSTOM_ADMIN_VIEWS_MODEL_DESCRIPTION="The class header for custom admin views model. Only use this option if you have a getListQuery as your Main Get." \ 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/rules/code.php b/rules/code.php new file mode 100644 index 0000000..0f97f97 --- /dev/null +++ b/rules/code.php @@ -0,0 +1,53 @@ + + * @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('JPATH_PLATFORM') or die; + +use Joomla\CMS\Form\Form; +use Joomla\CMS\Form\FormRule; +use Joomla\Registry\Registry; + +/** + * Form Rule (Code) class for the Joomla Platform. + */ +class JFormRuleCode extends FormRule +{ + /** + * Method to test the value. + * + * @param \SimpleXMLElement $element The SimpleXMLElement object representing the `` tag for the form field object. + * @param mixed $value The form field value to validate. + * @param string $group The field name group control value. This acts as an array container for the field. + * For example if the field has name="foo" and the group value is set to "bar" then the + * full field name would end up being "bar[foo]". + * @param Registry $input An optional Registry object with the entire data set to validate against the entire form. + * @param Form $form The form object for which the field is being tested. + * + * @return boolean True if the value is valid, false otherwise. + */ + public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) + { + // This removes all validation (is dangerous) but needed to submit code via JCB + return true; + + /** + * My idea is to add some kind of validation to improve JCB code (per/language) + * + * So at this time this code validation is used for JavaScript,CSS,HTML and PHP. + * We can see what language is being worked on with the syntax property in the $element. (in JCB) + * What complicates things is the placeholders, of both custom code, component, and view names. + * Ideally we could strip them and then validate the code to being syntactically correct. + * But since some of the placeholders form part of the class/function names and the more, it seems like we are pressed for a much more advance solution. + * If you have any ideas to how we can go about to do this, then please open an issue on github and lets begin. (this is a nice to have, so don't break a leg...) + */ + } +} diff --git a/rules/index.html b/rules/index.html new file mode 100644 index 0000000..fa6d84e --- /dev/null +++ b/rules/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..adb495d --- /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'); + +/** + * Content - Componentbuilder Custom Admin Headers Tabs script file. + * + * @package PlgContentComponentbuilderCustomAdminHeadersTabs + */ +class plgContentComponentbuilderCustomAdminHeadersTabsInstallerScript +{ + + /** + * 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.12.1 or higher installed + if (count($jcbVersion) == 3 && $jcbVersion[0] >= 2 && $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; + } +}