commit cfa453fa1bac8d8ac6c7227faec3ebb84b3c3c20 Author: Llewellyn van der Merwe Date: Fri Dec 3 04:46:29 2021 +0200 first commit - v1.0.0 diff --git a/componentbuilderpowersautoloadercompiler.php b/componentbuilderpowersautoloadercompiler.php new file mode 100644 index 0000000..18e7e70 --- /dev/null +++ b/componentbuilderpowersautoloadercompiler.php @@ -0,0 +1,111 @@ + + * @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 +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 Powers Autoloader Compiler plugin. + * + * @package ComponentbuilderPowersAutoloaderCompiler + * @since 1.0.0 + */ +class PlgExtensionComponentbuilderPowersAutoloaderCompiler extends CMSPlugin +{ + /** + * Affects constructor behavior. If true, language files will be loaded automatically. + * + * @var boolean + * @since 1.0.0 + */ + protected $autoloadLanguage = true; + + /** + * Event Triggered in the compiler [on After Get] + * + * @return void + * + * @since 1.0 + */ + public function jcb_ce_onAfterGet(&$context, $compiler) + { + // check if this component needs a power autoloader plugin loaded + if ($this->componentActive($context) && ComponentbuilderHelper::checkArray($compiler->powers)) + { + // now get the plugin ID if set + if (($id = (int) $this->params->get('plugin', 0)) !== 0) + { + // load the power autoloader plugin + $compiler->setJoomlaPlugin($id, $compiler->componentData); + // now set the plugin powers placeholder + $compiler->fileContentStatic[$compiler->hhh . 'PLUGIN_POWER_AUTOLOADER' . $compiler->hhh] = ''; + } + else + { + JFactory::getApplication()->enqueueMessage(JText::_('PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_YOU_DO_NOT_HAVE_A_GLOBAL_POWER_PLUGIN_SETUP_SO_THE_POWERS_PLUGIN_AUTOLOADER_COULD_NOT_BE_ADDED'), 'Error'); + } + } + } + + /** + * The array of active components + * + * @var array + */ + protected $componentsActive; + + /** + * The activate option + * + * @var int + */ + protected $activateOption = 0; + + /** + * Set the line number in comments + * + * @param string $context The context of the current executing component + * + * @return bool + * + */ + protected function componentActive(&$context) + { + // check the active option + if (!$this->activateOption) + { + $this->activateOption = $this->params->get('activate_option', 1); + } + // active for all components + if ($this->activateOption == 1) + { + return true; + } + // first check is we have the active components set + if ($this->activateOption == 2 && !ComponentbuilderHelper::checkArray($this->componentsActive)) + { + $this->componentsActive = $this->params->get('components'); + } + // only check if there are active + if (ComponentbuilderHelper::checkArray($this->componentsActive)) + { + return in_array((int) filter_var($context, FILTER_SANITIZE_NUMBER_INT), $this->componentsActive); + } + return false; + } + +} diff --git a/componentbuilderpowersautoloadercompiler.xml b/componentbuilderpowersautoloadercompiler.xml new file mode 100644 index 0000000..94e5520 --- /dev/null +++ b/componentbuilderpowersautoloadercompiler.xml @@ -0,0 +1,81 @@ + + + PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER + 3rd December, 2021 + 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 + 1.0.0 + PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_XML_DESCRIPTION + + + script.php + + + + en-GB/en-GB.plg_extension_componentbuilderpowersautoloadercompiler.ini + en-GB/en-GB.plg_extension_componentbuilderpowersautoloadercompiler.sys.ini + + + + + componentbuilderpowersautoloadercompiler.php + index.html + language + fields + 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/fields/joomlacomponents.php b/fields/joomlacomponents.php new file mode 100644 index 0000000..9122f6f --- /dev/null +++ b/fields/joomlacomponents.php @@ -0,0 +1,57 @@ + + * @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 +defined('_JEXEC') or die('Restricted access'); + +// import the list field type +jimport('joomla.form.helper'); +JFormHelper::loadFieldClass('list'); + +/** + * Joomlacomponents Form Field class for the Componentbuilder component + */ +class JFormFieldJoomlacomponents extends JFormFieldList +{ + /** + * The joomlacomponents field type. + * + * @var string + */ + public $type = 'joomlacomponents'; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + */ + protected function getOptions() + { + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id','a.system_name'),array('id','components_system_name'))); + $query->from($db->quoteName('#__componentbuilder_joomla_component', 'a')); + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->order('a.system_name ASC'); + $db->setQuery((string)$query); + $items = $db->loadObjectList(); + $options = array(); + if ($items) + { + foreach($items as $item) + { + $options[] = JHtml::_('select.option', $item->id, $item->components_system_name); + } + } + + return $options; + } +} diff --git a/fields/joomlaplugins.php b/fields/joomlaplugins.php new file mode 100644 index 0000000..7120198 --- /dev/null +++ b/fields/joomlaplugins.php @@ -0,0 +1,177 @@ + + * @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 +defined('_JEXEC') or die('Restricted access'); + +// import the list field type +jimport('joomla.form.helper'); +JFormHelper::loadFieldClass('list'); + +/** + * Joomlaplugins Form Field class for the Componentbuilder component + */ +class JFormFieldJoomlaplugins extends JFormFieldList +{ + /** + * The joomlaplugins field type. + * + * @var string + */ + public $type = 'joomlaplugins'; + + /** + * Override to add new button + * + * @return string The field input markup. + * + * @since 3.2 + */ + protected function getInput() + { + // see if we should add buttons + $set_button = $this->getAttribute('button'); + // get html + $html = parent::getInput(); + // if true set button + if ($set_button === 'true') + { + $button = array(); + $script = array(); + $button_code_name = $this->getAttribute('name'); + // get the input from url + $app = JFactory::getApplication(); + $jinput = $app->input; + // get the view name & id + $values = $jinput->getArray(array( + 'id' => 'int', + 'view' => 'word' + )); + // check if new item + $ref = ''; + $refJ = ''; + if (!is_null($values['id']) && strlen($values['view'])) + { + // only load referral if not new item. + $ref = '&ref=' . $values['view'] . '&refid=' . $values['id']; + $refJ = '&ref=' . $values['view'] . '&refid=' . $values['id']; + // get the return value. + $_uri = (string) JUri::getInstance(); + $_return = urlencode(base64_encode($_uri)); + // load return value. + $ref .= '&return=' . $_return; + $refJ .= '&return=' . $_return; + } + // get button label + $button_label = trim($button_code_name); + $button_label = preg_replace('/_+/', ' ', $button_label); + $button_label = preg_replace('/\s+/', ' ', $button_label); + $button_label = preg_replace("/[^A-Za-z ]/", '', $button_label); + $button_label = ucfirst(strtolower($button_label)); + // get user object + $user = JFactory::getUser(); + // only add if user allowed to create joomla_plugin + if ($user->authorise('joomla_plugin.create', 'com_componentbuilder') && $app->isAdmin()) // TODO for now only in admin area. + { + // build Create button + $button[] = ' + '; + } + // only add if user allowed to edit joomla_plugin + if ($user->authorise('joomla_plugin.edit', 'com_componentbuilder') && $app->isAdmin()) // TODO for now only in admin area. + { + // build edit button + $button[] = ''; + // build script + $script[] = " + jQuery(document).ready(function() { + jQuery('#adminForm').on('change', '#jform_".$button_code_name."',function (e) { + e.preventDefault(); + var ".$button_code_name."Value = jQuery('#jform_".$button_code_name."').val(); + ".$button_code_name."Button(".$button_code_name."Value); + }); + var ".$button_code_name."Value = jQuery('#jform_".$button_code_name."').val(); + ".$button_code_name."Button(".$button_code_name."Value); + }); + function ".$button_code_name."Button(value) { + if (value > 0) { + // hide the create button + jQuery('#".$button_code_name."Create').hide(); + // show edit button + jQuery('#".$button_code_name."Edit').show(); + var url = 'index.php?option=com_componentbuilder&view=joomla_plugins&task=joomla_plugin.edit&id='+value+'".$refJ."'; + jQuery('#".$button_code_name."Edit').attr('href', url); + } else { + // show the create button + jQuery('#".$button_code_name."Create').show(); + // hide edit button + jQuery('#".$button_code_name."Edit').hide(); + } + }"; + } + // check if button was created for joomla_plugin field. + if (is_array($button) && count($button) > 0) + { + // Load the needed script. + $document = JFactory::getDocument(); + $document->addScriptDeclaration(implode(' ',$script)); + // return the button attached to input field. + return '
' .$html . implode('',$button).'
'; + } + } + return $html; + } + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + */ + protected function getOptions() + { + // Get the user object. + $user = JFactory::getUser(); + // Get the databse object. + $db = JFactory::getDBO(); + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id','a.system_name','a.name','b.name','c.name'),array('id','plugin_system_name','name','class_extends_name','joomla_plugin_group_name'))); + $query->from($db->quoteName('#__componentbuilder_joomla_plugin', 'a')); + $query->join('LEFT', $db->quoteName('#__componentbuilder_class_extends', 'b') . ' ON (' . $db->quoteName('a.class_extends') . ' = ' . $db->quoteName('b.id') . ')'); + $query->join('LEFT', $db->quoteName('#__componentbuilder_joomla_plugin_group', 'c') . ' ON (' . $db->quoteName('a.joomla_plugin_group') . ' = ' . $db->quoteName('c.id') . ')'); + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->order('a.system_name ASC'); + // Implement View Level Access (if set in table) + if (!$user->authorise('core.options', 'com_componentbuilder')) + { + $columns = $db->getTableColumns('#__componentbuilder_joomla_plugin'); + if(isset($columns['access'])) + { + $groups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + } + } + $db->setQuery((string)$query); + $items = $db->loadObjectList(); + $options = array(); + if ($items) + { + $options[] = JHtml::_('select.option', '', 'Select a plugin'); + foreach($items as $item) + { + // set a full class name + $options[] = JHtml::_('select.option', $item->id, '( ' . $item->plugin_system_name . ' ) class Plg' . ucfirst($item->joomla_plugin_group_name) . $item->name . ' extends ' . $item->class_extends_name); + } + } + return $options; + } +} 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_componentbuilderpowersautoloadercompiler.ini b/language/en-GB/en-GB.plg_extension_componentbuilderpowersautoloadercompiler.ini new file mode 100644 index 0000000..f71485a --- /dev/null +++ b/language/en-GB/en-GB.plg_extension_componentbuilderpowersautoloadercompiler.ini @@ -0,0 +1,14 @@ +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER="Extension - Componentbuilder Powers Autoloader Compiler" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_DESCRIPTION="This plugin is used to build the power autoloader plugin for your component 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_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder Powers Autoloader Compiler (v.1.0.0)

This plugin is used to build the power autoloader plugin for your component 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.

Created by Llewellyn van der Merwe
Development started 13th November, 2021

" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_YOU_DO_NOT_HAVE_A_GLOBAL_POWER_PLUGIN_SETUP_SO_THE_POWERS_PLUGIN_AUTOLOADER_COULD_NOT_BE_ADDED="You do not have a global power plugin setup, so the powers plugin autoloader could not be added." +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_GLOBAL_AUTOLOADER="Global Autoloader" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_NOTE_SELECT_POWER_PLUGIN_LABEL="Select your power autoloader plugin here." +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_NOTE_SELECT_POWER_PLUGIN_DESCRIPTION="If you don't yet have a global powers autoloader plugin, watch this tutorial to see how to setup it up." +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_PLUGIN_LABEL="Plugins" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_ACTIVATE_OPTION_LABEL="Activate Options" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_ACTIVATE_OPTION_DESCRIPTION="You can select the kind of activation control you would like to use. All will target all components, and Selected will let you select only those you want to be active." +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_ALL="All" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_SELECTED="Selected" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_COMPONENTS_LABEL="Components" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_COMPONENTS_DESCRIPTION="Select the components you would like to be targeted." \ No newline at end of file diff --git a/language/en-GB/en-GB.plg_extension_componentbuilderpowersautoloadercompiler.sys.ini b/language/en-GB/en-GB.plg_extension_componentbuilderpowersautoloadercompiler.sys.ini new file mode 100644 index 0000000..f71485a --- /dev/null +++ b/language/en-GB/en-GB.plg_extension_componentbuilderpowersautoloadercompiler.sys.ini @@ -0,0 +1,14 @@ +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER="Extension - Componentbuilder Powers Autoloader Compiler" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_DESCRIPTION="This plugin is used to build the power autoloader plugin for your component 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_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_XML_DESCRIPTION="

Extension - Componentbuilder Powers Autoloader Compiler (v.1.0.0)

This plugin is used to build the power autoloader plugin for your component 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.

Created by Llewellyn van der Merwe
Development started 13th November, 2021

" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_YOU_DO_NOT_HAVE_A_GLOBAL_POWER_PLUGIN_SETUP_SO_THE_POWERS_PLUGIN_AUTOLOADER_COULD_NOT_BE_ADDED="You do not have a global power plugin setup, so the powers plugin autoloader could not be added." +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_GLOBAL_AUTOLOADER="Global Autoloader" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_NOTE_SELECT_POWER_PLUGIN_LABEL="Select your power autoloader plugin here." +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_NOTE_SELECT_POWER_PLUGIN_DESCRIPTION="If you don't yet have a global powers autoloader plugin, watch this tutorial to see how to setup it up." +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_PLUGIN_LABEL="Plugins" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_ACTIVATE_OPTION_LABEL="Activate Options" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_ACTIVATE_OPTION_DESCRIPTION="You can select the kind of activation control you would like to use. All will target all components, and Selected will let you select only those you want to be active." +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_ALL="All" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_SELECTED="Selected" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_COMPONENTS_LABEL="Components" +PLG_EXTENSION_COMPONENTBUILDERPOWERSAUTOLOADERCOMPILER_COMPONENTS_DESCRIPTION="Select the components you would like to be targeted." \ 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/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..f42a53e --- /dev/null +++ b/script.php @@ -0,0 +1,57 @@ + + * @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 +defined('_JEXEC') or die('Restricted access'); + +/** + * Extension - Componentbuilder Powers Autoloader Compiler script file. + * + * @package PlgExtensionComponentbuilderPowersAutoloaderCompiler + */ +class plgExtensionComponentbuilderPowersAutoloaderCompilerInstallerScript +{ + + /** + * 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; + } + } + + return true; + } +}