From d2f94d84fa4e930f6e1e552fa0ab36662f5d1e3d Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 22 Aug 2019 03:54:47 +0200 Subject: [PATCH] Improved the plugin form builder, to allow multi form field relationships. --- README.md | 10 +- admin/README.txt | 10 +- admin/compiler/joomla_3/Helper.php | 32 +- admin/compiler/joomla_3/Helper_site.php | 34 +- admin/compiler/joomla_3/JModelAdmin.php | 2 + admin/compiler/joomla_3/JModelAdmin_site.php | 2 + admin/controllers/compiler.php | 2 +- admin/helpers/compiler.php | 70 +- admin/helpers/compiler/a_Get.php | 716 +++++++++++------- admin/helpers/compiler/b_Structure.php | 148 +++- admin/helpers/compiler/c_Fields.php | 21 +- admin/helpers/compiler/e_Interpretation.php | 134 +++- admin/helpers/compiler/f_Infusion.php | 31 +- admin/helpers/componentbuilder.php | 32 +- .../en-GB/en-GB.com_componentbuilder.ini | 23 +- ...llwidth.php => forms_fields_fullwidth.php} | 0 admin/models/admin_custom_tabs.php | 2 + admin/models/admin_fields.php | 2 + admin/models/admin_fields_conditions.php | 2 + admin/models/admin_fields_relations.php | 2 + admin/models/admin_view.php | 2 + admin/models/class_extends.php | 2 + admin/models/class_method.php | 2 + admin/models/class_property.php | 2 + admin/models/component_admin_views.php | 2 + admin/models/component_config.php | 2 + admin/models/component_custom_admin_menus.php | 2 + admin/models/component_custom_admin_views.php | 2 + admin/models/component_dashboard.php | 2 + admin/models/component_files_folders.php | 2 + admin/models/component_mysql_tweaks.php | 2 + admin/models/component_placeholders.php | 2 + admin/models/component_plugins.php | 2 + admin/models/component_site_views.php | 2 + admin/models/component_updates.php | 2 + admin/models/custom_admin_view.php | 2 + admin/models/custom_code.php | 2 + admin/models/dynamic_get.php | 2 + admin/models/field.php | 2 + admin/models/fields/joomlaplugins.php | 106 ++- admin/models/fields/targetfields.php | 13 +- admin/models/fieldtype.php | 2 + admin/models/forms/joomla_plugin.xml | 142 +++- admin/models/help_document.php | 2 + admin/models/joomla_component.php | 2 + admin/models/joomla_plugin.php | 4 +- .../joomla_plugin_files_folders_urls.php | 2 + admin/models/joomla_plugin_group.php | 2 + admin/models/joomla_plugin_updates.php | 2 + admin/models/language.php | 2 + admin/models/language_translation.php | 2 + admin/models/layout.php | 2 + admin/models/library.php | 2 + admin/models/library_config.php | 2 + admin/models/library_files_folders_urls.php | 2 + admin/models/placeholder.php | 2 + admin/models/server.php | 2 + admin/models/site_view.php | 2 + admin/models/snippet.php | 2 + admin/models/snippet_type.php | 2 + admin/models/template.php | 2 + admin/models/validation_rule.php | 2 + admin/views/joomla_plugin/tmpl/edit.php | 4 +- componentbuilder.xml | 2 +- site/helpers/componentbuilder.php | 34 +- 65 files changed, 1225 insertions(+), 431 deletions(-) rename admin/layouts/joomla_plugin/{configparams_fullwidth.php => forms_fields_fullwidth.php} (100%) diff --git a/README.md b/README.md index 6d8f47c25..9b3d55b92 100644 --- a/README.md +++ b/README.md @@ -146,14 +146,14 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 16th August, 2019 ++ *Last Build*: 22nd August, 2019 + *Version*: 2.10.0 + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **246452** -+ *Field count*: **1319** -+ *File count*: **1595** -+ *Folder count*: **244** ++ *Line count*: **247612** ++ *Field count*: **1343** ++ *File count*: **1604** ++ *Folder count*: **250** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/README.txt b/admin/README.txt index 6d8f47c25..9b3d55b92 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -146,14 +146,14 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 16th August, 2019 ++ *Last Build*: 22nd August, 2019 + *Version*: 2.10.0 + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **246452** -+ *Field count*: **1319** -+ *File count*: **1595** -+ *Folder count*: **244** ++ *Line count*: **247612** ++ *Field count*: **1343** ++ *File count*: **1604** ++ *Folder count*: **250** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/compiler/joomla_3/Helper.php b/admin/compiler/joomla_3/Helper.php index b6ce01384..30b8391bf 100644 --- a/admin/compiler/joomla_3/Helper.php +++ b/admin/compiler/joomla_3/Helper.php @@ -774,7 +774,31 @@ abstract class ###Component###Helper jimport('joomla.form.form'); } // get field type - $field = JFormHelper::loadFieldType($attributes['type'],true); + $field = JFormHelper::loadFieldType($attributes['type'], true); + // get field xml + $XML = self::getFieldXML($attributes, $options); + // setup the field + $field->setup($XML, $default); + // return the field object + return $field; + } + return false; + } + + /** + * get the field xml + * + * @param array $attributes The array of attributes + * @param array $options The options to apply to the XML element + * + * @return object + * + */ + public static function getFieldXML(&$attributes, $options = null) + { + // make sure we have attributes and a type value + if (self::checkArray($attributes)) + { // start field xml $XML = new SimpleXMLElement(''); // load the attributes @@ -785,10 +809,8 @@ abstract class ###Component###Helper // load the options self::xmlAddOptions($XML, $options); } - // setup the field - $field->setup($XML, $default); - // return the field object - return $field; + // return the field xml + return $XML; } return false; } diff --git a/admin/compiler/joomla_3/Helper_site.php b/admin/compiler/joomla_3/Helper_site.php index 9213fb793..cd0f87c48 100644 --- a/admin/compiler/joomla_3/Helper_site.php +++ b/admin/compiler/joomla_3/Helper_site.php @@ -406,7 +406,7 @@ abstract class ###Component###Helper * @return object * */ - public static function getFieldObject($attributes, $default = '', $options = null) + public static function getFieldObject(&$attributes, $default = '', $options = null) { // make sure we have attributes and a type value if (self::checkArray($attributes) && isset($attributes['type'])) @@ -417,7 +417,31 @@ abstract class ###Component###Helper jimport('joomla.form.form'); } // get field type - $field = JFormHelper::loadFieldType($attributes['type'],true); + $field = JFormHelper::loadFieldType($attributes['type'], true); + // get field xml + $XML = self::getFieldXML($attributes, $options); + // setup the field + $field->setup($XML, $default); + // return the field object + return $field; + } + return false; + } + + /** + * get the field xml + * + * @param array $attributes The array of attributes + * @param array $options The options to apply to the XML element + * + * @return object + * + */ + public static function getFieldXML(&$attributes, $options = null) + { + // make sure we have attributes and a type value + if (self::checkArray($attributes)) + { // start field xml $XML = new SimpleXMLElement(''); // load the attributes @@ -428,10 +452,8 @@ abstract class ###Component###Helper // load the options self::xmlAddOptions($XML, $options); } - // setup the field - $field->setup($XML, $default); - // return the field object - return $field; + // return the field xml + return $XML; } return false; } diff --git a/admin/compiler/joomla_3/JModelAdmin.php b/admin/compiler/joomla_3/JModelAdmin.php index f939f76db..30020d7f2 100644 --- a/admin/compiler/joomla_3/JModelAdmin.php +++ b/admin/compiler/joomla_3/JModelAdmin.php @@ -242,6 +242,8 @@ class ###Component###Model###View### extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_###component###.###view###', $data); } return $data; diff --git a/admin/compiler/joomla_3/JModelAdmin_site.php b/admin/compiler/joomla_3/JModelAdmin_site.php index f939f76db..30020d7f2 100644 --- a/admin/compiler/joomla_3/JModelAdmin_site.php +++ b/admin/compiler/joomla_3/JModelAdmin_site.php @@ -242,6 +242,8 @@ class ###Component###Model###View### extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_###component###.###view###', $data); } return $data; diff --git a/admin/controllers/compiler.php b/admin/controllers/compiler.php index cbdcca5a9..6ab2fb822 100644 --- a/admin/controllers/compiler.php +++ b/admin/controllers/compiler.php @@ -288,7 +288,7 @@ class ComponentbuilderControllerCompiler extends JControllerAdmin $pluginId = $jinput->post->get('install_item_id', 0, 'INT'); if ($pluginId > 0 && isset($fileNames[$pluginId]) && $this->installExtension($fileNames[$pluginId])) { - $message = JText::sprintf('COM_COMPONENTBUILDER_ONLY_SZIP_FILE_WAS_REMOVED_THE_FROM_TMP_FOLDER_DURING_INSTALLATION', $fileName); + $message = JText::sprintf('COM_COMPONENTBUILDER_ONLY_SZIP_FILE_WAS_REMOVED_THE_FROM_TMP_FOLDER_DURING_INSTALLATION', $fileNames[$pluginId]); $this->setRedirect($redirect_url, $message, 'message'); return true; } diff --git a/admin/helpers/compiler.php b/admin/helpers/compiler.php index ccf5e1f2c..2aedbd8f7 100644 --- a/admin/helpers/compiler.php +++ b/admin/helpers/compiler.php @@ -20,25 +20,25 @@ ComponentbuilderHelper::autoLoader(); */ class Compiler extends Infusion { - /* + /** * The Temp path - * + * * @var string */ private $tempPath; - /* + /** * The timer - * + * * @var string */ private $time_start; private $time_end; public $secondsCompiled; - /* + /** * The file path array - * + * * @var string */ public $filepath = array( @@ -203,11 +203,11 @@ class Compiler extends Infusion /** * Set the line number in comments - * + * * @param int $nr The line number - * + * * @return void - * + * */ private function setLine($nr) { @@ -260,12 +260,48 @@ class Compiler extends Infusion // free up some memory unset($this->newFiles['dynamic']); // do plugins if found - if (ComponentbuilderHelper::checkArray($this->componentData->joomla_plugins)) + if (ComponentbuilderHelper::checkArray($this->joomlaPlugins)) { - foreach ($this->componentData->joomla_plugins as $plugin) + foreach ($this->joomlaPlugins as $plugin) { if (ComponentbuilderHelper::checkObject($plugin) && isset($this->newFiles[$plugin->key]) && ComponentbuilderHelper::checkArray($this->newFiles[$plugin->key])) { + // move field or rule if needed + if (isset($plugin->fields_rules_paths) && $plugin->fields_rules_paths == 2) + { + // check the config fields + if (isset($plugin->config_fields) && ComponentbuilderHelper::checkArray($plugin->config_fields)) + { + foreach ($plugin->config_fields as $field_name => $fieldsets) + { + foreach ($fieldsets as $fieldset => $fields) + { + foreach ($fields as $field) + { + $this->moveFieldsRules($field, $plugin->folder_path); + } + } + } + } + // check the fieldsets + if (isset($plugin->form_files) && ComponentbuilderHelper::checkArray($plugin->form_files)) + { + foreach($plugin->form_files as $file => $files) + { + foreach ($files as $field_name => $fieldsets) + { + foreach ($fieldsets as $fieldset => $fields) + { + foreach ($fields as $field) + { + $this->moveFieldsRules($field, $plugin->folder_path); + } + } + } + } + } + } + // now move the files foreach ($this->newFiles[$plugin->key] as $plugin_file) { if (JFile::exists($plugin_file['path'])) @@ -355,9 +391,9 @@ class Compiler extends Infusion } } // move the plugins update server to host - if (ComponentbuilderHelper::checkArray($this->componentData->joomla_plugins)) + if (ComponentbuilderHelper::checkArray($this->joomlaPlugins)) { - foreach ($this->componentData->joomla_plugins as $plugin) + foreach ($this->joomlaPlugins as $plugin) { if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->add_update_server) && $plugin->add_update_server == 1 @@ -528,9 +564,9 @@ class Compiler extends Infusion $this->triggerEvent('jcb_ce_onAfterUpdateRepo', array(&$this->componentContext, &$this->componentPath, &$repoFullPath, &$this->componentData)); // move the plugins to local folder repos - if (ComponentbuilderHelper::checkArray($this->componentData->joomla_plugins)) + if (ComponentbuilderHelper::checkArray($this->joomlaPlugins)) { - foreach ($this->componentData->joomla_plugins as $plugin) + foreach ($this->joomlaPlugins as $plugin) { if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->file_name)) { @@ -596,9 +632,9 @@ class Compiler extends Infusion private function zipPlugins() { - if (ComponentbuilderHelper::checkArray($this->componentData->joomla_plugins)) + if (ComponentbuilderHelper::checkArray($this->joomlaPlugins)) { - foreach ($this->componentData->joomla_plugins as $plugin) + foreach ($this->joomlaPlugins as $plugin) { if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->zip_name) && ComponentbuilderHelper::checkString($plugin->zip_name) diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index d92f53c69..dd9e8069a 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -108,6 +108,13 @@ class Get */ public $componentData; + /** + * The Plugins data + * + * @var array + */ + public $joomlaPlugins = array(); + /** * The custom script placeholders - we use the (xxx) to avoid detection it should be (***) * ##################################---> PHP/JS <---#################################### @@ -469,6 +476,13 @@ class Get */ public $validationRules = array(); + /** + * The validation linked to fields + * + * @var array + */ + public $validationLinkedFields = array(); + /** * The admin views data array * @@ -776,6 +790,8 @@ class Get } } } + // Trigger Event: jcb_ce_onBeforeGet + $this->triggerEvent('jcb_ce_onBeforeGet', array(&$config, $this)); // set the Joomla version $this->joomlaVersion = $config['version']; // set the minfy switch of the JavaScript @@ -855,6 +871,9 @@ class Get // set the percentage when a language can be added $this->percentageLanguageAdd = (int) $this->params->get('percentagelanguageadd', 50); + // Trigger Event: jcb_ce_onBeforeGet + $this->triggerEvent('jcb_ce_onAfterGet', array(&$this->componentContext, $this)); + return true; } } @@ -1659,15 +1678,10 @@ class Get $component->addjoomla_plugins = (isset($component->addjoomla_plugins) && ComponentbuilderHelper::checkJson($component->addjoomla_plugins)) ? json_decode($component->addjoomla_plugins, true) : null; if (ComponentbuilderHelper::checkArray($component->addjoomla_plugins)) { - $component->joomla_plugins = array_map(function($array) use(&$component) - { - return $this->getPlugins($array['plugin'], $component); + $joomla_plugins = array_map(function($array) use(&$component) { + return $this->setJoomlaPlugin($array['plugin'], $component); }, array_values($component->addjoomla_plugins)); } - else - { - $component->joomla_plugins = ''; - } unset($component->addjoomla_plugins); // Trigger Event: jcb_ce_onAfterModelComponentData @@ -2834,6 +2848,8 @@ class Get { // make sure it is lowercase $validationRule = ComponentbuilderHelper::safeString($validationRule); + // link this field to this validation + $this->validationLinkedFields[$id] = $validationRule; // make sure it is not already set if (!isset($this->validationRules[$validationRule])) { @@ -2859,8 +2875,14 @@ class Get else { // set the notice that this validation rule is custom and was not found (TODO) + unset($this->validationLinkedFields[$id], $this->validationRules[$validationRule]); } } + else + { + // remove link (we only want custom validations linked) + unset($this->validationLinkedFields[$id]); + } } } } @@ -6160,299 +6182,420 @@ class Get } /** - * get the plugins linked to a component + * set the Joomla plugins * - * @return void + * @return true * */ - protected function getPlugins($id, &$component) + public function setJoomlaPlugin($id, &$component) { - // Create a new query object. - $query = $this->db->getQuery(true); - - $query->select('a.*'); - $query->select( - $this->db->quoteName( - array( - 'g.name', - 'e.name', - 'e.head', - 'e.comment', - 'e.id', - 'f.addfiles', - 'f.addfolders', - 'f.addfilesfullpath', - 'f.addfoldersfullpath', - 'f.addurls', - 'u.version_update', - 'u.id' - ), array( - 'group', - 'extends', - 'class_head', - 'comment', - 'class_id', - 'addfiles', - 'addfolders', - 'addfilesfullpath', - 'addfoldersfullpath', - 'addurls', - 'version_update', - 'version_update_id' - ) - ) - ); - // from these tables - $query->from('#__componentbuilder_joomla_plugin AS a'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_group', 'g') . ' ON (' . $this->db->quoteName('a.joomla_plugin_group') . ' = ' . $this->db->quoteName('g.id') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_class_extends', 'e') . ' ON (' . $this->db->quoteName('a.class_extends') . ' = ' . $this->db->quoteName('e.id') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_updates', 'u') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('u.joomla_plugin') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_files_folders_urls', 'f') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('f.joomla_plugin') . ')'); - $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); - $query->where($this->db->quoteName('a.published') . ' >= 1'); - $this->db->setQuery($query); - $this->db->execute(); - if ($this->db->getNumRows()) + if (isset($this->joomlaPlugins[$id])) { - // get the plugin data - $plugin = $this->db->loadObject(); - // tweak system to set stuff to the plugin domain - $_backup_target = $this->target; - $_backup_lang = $this->lang; - $_backup_langPrefix = $this->langPrefix; - // set some keys - $plugin->target_type = 'P|uG!n'; - $plugin->key = $plugin->id . '_' . $plugin->target_type; - // update to point to plugin - $this->target = $plugin->key; - $this->lang = $plugin->key; - // set version if not set - if (empty($plugin->plugin_version)) - { - $plugin->plugin_version = '1.0.0'; - } - // set GUI mapper - $guiMapper = array( 'table' => 'joomla_plugin', 'id' => (int) $id, 'type' => 'php'); - // update the name if it has dynamic values - $plugin->name = $this->setPlaceholders($this->setDynamicValues($plugin->name), $this->placeholders); - // set official name - $plugin->official_name = ucwords($plugin->group . ' - ' . $plugin->name); - // set langPrefix - $this->langPrefix = 'PLG_' . strtoupper($plugin->group) . '_' . strtoupper($plugin->name); - // set lang prefix - $plugin->lang_prefix = $this->langPrefix; - // set plugin class name - $plugin->class_name = 'Plg' . ucfirst($plugin->group) . ucfirst($plugin->name); - // set plugin install class name - $plugin->installer_class_name = 'plg' . ucfirst($plugin->group) . ucfirst($plugin->name) . 'InstallerScript'; - // set plugin folder name - $plugin->folder_name = 'plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->name); - // set the zip name - $plugin->zip_name = $plugin->folder_name . '_v' . str_replace('.', '_', $plugin->plugin_version). '__J' . $this->joomlaVersion; - // set plugin file name - $plugin->file_name = strtolower($plugin->name); - // set official_name lang strings - $this->setLangContent($plugin->key, $this->langPrefix, $plugin->official_name); - // set description (TODO) add description field to plugin - if (!isset($plugin->description) || !ComponentbuilderHelper::checkString($plugin->description)) - { - $plugin->description = ''; - } - else - { - $plugin->description = $this->setPlaceholders($this->setDynamicValues($plugin->description), $this->placeholders); - $this->setLangContent($plugin->key, $plugin->lang_prefix . '_DESCRIPTION', $plugin->description); - $plugin->description = '

' . $plugin->description . '

'; - } - $plugin->xml_description = "

" . $plugin->official_name . " (v." . $plugin->plugin_version . ")

" . $plugin->description . "

Created by " . trim(JFilterOutput::cleanText($component->author)) . "
Development started " . JFactory::getDate($plugin->created)->format("jS F, Y") . "

"; - // set xml discription - $this->setLangContent($plugin->key, $plugin->lang_prefix . '_XML_DESCRIPTION', $plugin->xml_description); - // update the readme if set - if ($plugin->addreadme == 1 && !empty($plugin->readme)) - { - $plugin->readme = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->readme)), $this->placeholders); - } - else - { - $plugin->addreadme = 0; - unset($plugin->readme); - } - // open some base64 strings - if (!empty($plugin->main_class_code)) - { - // set GUI mapper field - $guiMapper['field'] = 'main_class_code'; - // base64 Decode main_class_code. - $plugin->main_class_code = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->main_class_code)), $this->placeholders), - $guiMapper - ); - } - // set the head :) - if ($plugin->add_head == 1 && !empty($plugin->head)) - { - // set GUI mapper field - $guiMapper['field'] = 'head'; - // base64 Decode head. - $plugin->head = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->head)), $this->placeholders), - $guiMapper - ); - } - elseif (!empty($plugin->class_head)) - { - // base64 Decode head. - $plugin->head = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->class_head)), $this->placeholders), - array( - 'table' => 'class_extends', - 'field' => 'head', - 'id' => (int) $plugin->class_id, - 'type' => 'php') - ); - } - unset($plugin->class_head); - // set the comment - if (!empty($plugin->comment)) - { - // base64 Decode comment. - $plugin->comment = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->comment)), $this->placeholders), - array( - 'table' => 'class_extends', - 'field' => 'comment', - 'id' => (int) $plugin->class_id, - 'type' => 'php') - ); - } - // set the fields data - $plugin->fields = (isset($plugin->fields) && ComponentbuilderHelper::checkJson($plugin->fields)) ? json_decode($plugin->fields, true) : null; - if (ComponentbuilderHelper::checkArray($plugin->fields)) - { - $key = $plugin->key; - $plugin->config_fields = array_map(function($field) use ($key){ - // make sure the alias and title is 0 - $field['alias'] = 0; - $field['title'] = 0; - // set the field details - $this->setFieldDetails($field, $key); - // set unique name counter - $this->setUniqueNameCounter($field['base_name'], $key); - // return field - return $field; - }, array_values($plugin->fields)); + return true; + } + else + { + // Create a new query object. + $query = $this->db->getQuery(true); - // do some house cleaning (for fields) - foreach ($plugin->config_fields as $field) + $query->select('a.*'); + $query->select( + $this->db->quoteName( + array( + 'g.name', + 'e.name', + 'e.head', + 'e.comment', + 'e.id', + 'f.addfiles', + 'f.addfolders', + 'f.addfilesfullpath', + 'f.addfoldersfullpath', + 'f.addurls', + 'u.version_update', + 'u.id' + ), array( + 'group', + 'extends', + 'class_head', + 'comment', + 'class_id', + 'addfiles', + 'addfolders', + 'addfilesfullpath', + 'addfoldersfullpath', + 'addurls', + 'version_update', + 'version_update_id' + ) + ) + ); + // from these tables + $query->from('#__componentbuilder_joomla_plugin AS a'); + $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_group', 'g') . ' ON (' . $this->db->quoteName('a.joomla_plugin_group') . ' = ' . $this->db->quoteName('g.id') . ')'); + $query->join('LEFT', $this->db->quoteName('#__componentbuilder_class_extends', 'e') . ' ON (' . $this->db->quoteName('a.class_extends') . ' = ' . $this->db->quoteName('e.id') . ')'); + $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_updates', 'u') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('u.joomla_plugin') . ')'); + $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_files_folders_urls', 'f') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('f.joomla_plugin') . ')'); + $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); + $query->where($this->db->quoteName('a.published') . ' >= 1'); + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) + { + // get the plugin data + $plugin = $this->db->loadObject(); + // tweak system to set stuff to the plugin domain + $_backup_target = $this->target; + $_backup_lang = $this->lang; + $_backup_langPrefix = $this->langPrefix; + // set some keys + $plugin->target_type = 'P|uG!n'; + $plugin->key = $plugin->id . '_' . $plugin->target_type; + // update to point to plugin + $this->target = $plugin->key; + $this->lang = $plugin->key; + // set version if not set + if (empty($plugin->plugin_version)) { - // so first we lock the field name in - $this->getFieldName($field, $plugin->key); + $plugin->plugin_version = '1.0.0'; } - // unset original value - unset($plugin->fields); - } - // set the add targets - $addArray = array('files' => 'files', 'folders' => 'folders', 'urls' => 'urls', 'filesfullpath' => 'files', 'foldersfullpath' => 'folders'); - foreach ($addArray as $addTarget => $targetHere) - { - // set the add target data - $plugin->{'add' . $addTarget} = (isset($plugin->{'add' . $addTarget}) && ComponentbuilderHelper::checkJson($plugin->{'add' . $addTarget})) ? json_decode($plugin->{'add' . $addTarget}, true) : null; - if (ComponentbuilderHelper::checkArray($plugin->{'add' . $addTarget})) + // set GUI mapper + $guiMapper = array( 'table' => 'joomla_plugin', 'id' => (int) $id, 'type' => 'php'); + // update the name if it has dynamic values + $plugin->name = $this->setPlaceholders($this->setDynamicValues($plugin->name), $this->placeholders); + // update the name if it has dynamic values + $plugin->code_name = ComponentbuilderHelper::safeClassFunctionName($plugin->name); + // set official name + $plugin->official_name = ucwords($plugin->group . ' - ' . $plugin->name); + // set langPrefix + $this->langPrefix = 'PLG_' . strtoupper($plugin->group) . '_' . strtoupper($plugin->code_name); + // set lang prefix + $plugin->lang_prefix = $this->langPrefix; + // set plugin class name + $plugin->class_name = 'Plg' . ucfirst($plugin->group) . ucfirst($plugin->code_name); + // set plugin install class name + $plugin->installer_class_name = 'plg' . ucfirst($plugin->group) . ucfirst($plugin->code_name) . 'InstallerScript'; + // set plugin folder name + $plugin->folder_name = 'plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->code_name); + // set the zip name + $plugin->zip_name = $plugin->folder_name . '_v' . str_replace('.', '_', $plugin->plugin_version). '__J' . $this->joomlaVersion; + // set plugin file name + $plugin->file_name = strtolower($plugin->code_name); + // set official_name lang strings + $this->setLangContent($plugin->key, $this->langPrefix, $plugin->official_name); + // set description (TODO) add description field to plugin + if (!isset($plugin->description) || !ComponentbuilderHelper::checkString($plugin->description)) { - if (isset($plugin->{$targetHere}) && ComponentbuilderHelper::checkArray($plugin->{$targetHere})) - { - foreach ($plugin->{'add' . $addTarget} as $taget) - { - $plugin->{$targetHere}[] = $taget; - } - } - else - { - $plugin->{$targetHere} = array_values($plugin->{'add' . $addTarget}); - } - } - unset($plugin->{'add' . $addTarget}); - } - // add PHP in plugin install - $plugin->add_install_script = false; - $addScriptMethods = array('php_preflight', 'php_postflight', 'php_method'); - $addScriptTypes = array('install', 'update', 'uninstall'); - foreach ($addScriptMethods as $scriptMethod) - { - foreach ($addScriptTypes as $scriptType) - { - if (isset($plugin->{'add_' . $scriptMethod . '_' . $scriptType}) && $plugin->{'add_' . $scriptMethod . '_' . $scriptType} == 1 && ComponentbuilderHelper::checkString($plugin->{$scriptMethod . '_' . $scriptType})) - { - // set GUI mapper field - $guiMapper['field'] = $scriptMethod . '_' . $scriptType; - $plugin->{$scriptMethod . '_' . $scriptType} = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->{$scriptMethod . '_' . $scriptType})), $this->placeholders), - $guiMapper - ); - $plugin->add_install_script = true; - } - else - { - unset($plugin->{$scriptMethod . '_' . $scriptType}); - $plugin->{'add_' . $scriptMethod . '_' . $scriptType} = 0; - } - } - } - // add_sql - if ($plugin->add_sql == 1 && ComponentbuilderHelper::checkString($plugin->sql)) - { - $plugin->sql = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->sql)), $this->placeholders); - } - else - { - unset($plugin->sql); - $plugin->add_sql = 0; - } - // add_sql_uninstall - if ($plugin->add_sql_uninstall == 1 && ComponentbuilderHelper::checkString($plugin->sql_uninstall)) - { - $plugin->sql_uninstall = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->sql_uninstall)), $this->placeholders); - } - else - { - unset($plugin->sql_uninstall); - $plugin->add_sql_uninstall = 0; - } - // update the URL of the update_server if set - if ($plugin->add_update_server == 1 && ComponentbuilderHelper::checkString($plugin->update_server_url)) - { - $plugin->update_server_url = $this->setPlaceholders($this->setDynamicValues($plugin->update_server_url), $this->placeholders); - } - // add the update/sales server FTP details if that is the expected protocol - $serverArray = array('update_server', 'sales_server'); - foreach ($serverArray as $server) - { - if ($plugin->{'add_' . $server} == 1 && is_numeric($plugin->{$server}) && $plugin->{$server} > 0) - { - // get the server protocol - $plugin->{$server . '_protocol'} = ComponentbuilderHelper::getVar('server', (int) $plugin->{$server}, 'id', 'protocol'); + $plugin->description = ''; } else { - $plugin->{$server} = 0; - // only change this for sales server (update server can be added loacaly to the zip file) - if ('sales_server' === $server) - { - $plugin->{'add_' . $server} = 0; - } - $plugin->{$server . '_protocol'} = 0; + $plugin->description = $this->setPlaceholders($this->setDynamicValues($plugin->description), $this->placeholders); + $this->setLangContent($plugin->key, $plugin->lang_prefix . '_DESCRIPTION', $plugin->description); + $plugin->description = '

' . $plugin->description . '

'; } + $plugin->xml_description = "

" . $plugin->official_name . " (v." . $plugin->plugin_version . ")

" . $plugin->description . "

Created by " . trim(JFilterOutput::cleanText($component->author)) . "
Development started " . JFactory::getDate($plugin->created)->format("jS F, Y") . "

"; + // set xml discription + $this->setLangContent($plugin->key, $plugin->lang_prefix . '_XML_DESCRIPTION', $plugin->xml_description); + // update the readme if set + if ($plugin->addreadme == 1 && !empty($plugin->readme)) + { + $plugin->readme = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->readme)), $this->placeholders); + } + else + { + $plugin->addreadme = 0; + unset($plugin->readme); + } + // open some base64 strings + if (!empty($plugin->main_class_code)) + { + // set GUI mapper field + $guiMapper['field'] = 'main_class_code'; + // base64 Decode main_class_code. + $plugin->main_class_code = $this->setGuiCodePlaceholder( + $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->main_class_code)), $this->placeholders), + $guiMapper + ); + } + // set the head :) + if ($plugin->add_head == 1 && !empty($plugin->head)) + { + // set GUI mapper field + $guiMapper['field'] = 'head'; + // base64 Decode head. + $plugin->head = $this->setGuiCodePlaceholder( + $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->head)), $this->placeholders), + $guiMapper + ); + } + elseif (!empty($plugin->class_head)) + { + // base64 Decode head. + $plugin->head = $this->setGuiCodePlaceholder( + $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->class_head)), $this->placeholders), + array( + 'table' => 'class_extends', + 'field' => 'head', + 'id' => (int) $plugin->class_id, + 'type' => 'php') + ); + } + unset($plugin->class_head); + // set the comment + if (!empty($plugin->comment)) + { + // base64 Decode comment. + $plugin->comment = $this->setGuiCodePlaceholder( + $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->comment)), $this->placeholders), + array( + 'table' => 'class_extends', + 'field' => 'comment', + 'id' => (int) $plugin->class_id, + 'type' => 'php') + ); + } + // start the config array + $plugin->config_fields = array(); + // create the form arrays + $plugin->form_files = array(); + $plugin->fieldsets_label = array(); + $plugin->fieldsets_paths = array(); + // set global fields rule to default component path + $plugin->fields_rules_paths = 1; + // set the fields data + $plugin->fields = (isset($plugin->fields) && ComponentbuilderHelper::checkJson($plugin->fields)) ? json_decode($plugin->fields, true) : null; + if (ComponentbuilderHelper::checkArray($plugin->fields)) + { + // ket global key + $key = $plugin->key; + $dynamic_fields = array('fieldset' => 'basic', 'fields_name' => 'params', 'file' => 'config'); + foreach ($plugin->fields as $n => &$form) + { + if (isset($form['fields']) && ComponentbuilderHelper::checkArray($form['fields'])) + { + // make sure the dynamic_field is set to dynamic_value by default + foreach ($dynamic_fields as $dynamic_field => $dynamic_value) + { + if (!isset($form[$dynamic_field]) || !ComponentbuilderHelper::checkString($form[$dynamic_field])) + { + $form[$dynamic_field] = $dynamic_value; + } + else + { + $form[$dynamic_field] = ComponentbuilderHelper::safeString($form[$dynamic_field]); + } + } + // check if field is external form file + if (!isset($form['plugin']) || $form['plugin'] != 1) + { + // now build the form key + $unique = $form['file'] . $form['fields_name'] . $form['fieldset']; + } + else + { + // now build the form key + $unique = $form['fields_name'] . $form['fieldset']; + } + // set global fields rule path switchs + if ($plugin->fields_rules_paths == 1 && isset($form['fields_rules_paths']) && $form['fields_rules_paths'] == 2) + { + $plugin->fields_rules_paths = 2; + } + // set where to path is pointing + $plugin->fieldsets_paths[$unique] = $form['fields_rules_paths']; + // add the label if set to lang + if (isset($form['label']) && ComponentbuilderHelper::checkString($form['label'])) + { + $plugin->fieldsets_label[$unique] = $this->setLang($form['label']); + } + // build the fields + $form['fields'] = array_map(function($field) use ($key, $unique){ + // make sure the alias and title is 0 + $field['alias'] = 0; + $field['title'] = 0; + // set the field details + $this->setFieldDetails($field, $key, $key, $unique); + // update the default if set + if (ComponentbuilderHelper::checkString($field['custom_value']) && isset($field['settings'])) + { + if (($old_default = ComponentbuilderHelper::getBetween($field['settings']->xml, 'default="', '"', false)) !== false) + { + // replace old default + $field['settings']->xml = str_replace('default="' . $old_default . '"', 'default="' . $field['custom_value'] . '"', $field['settings']->xml); + } + else + { + // add the default (hmmm not ideal but okay it should work) + $field['settings']->xml = 'default="' . $field['custom_value'] . '" ' . $field['settings']->xml; + } + } + unset($field['custom_value']); + // return field + return $field; + }, array_values($form['fields'])); + // check if field is external form file + if (!isset($form['plugin']) || $form['plugin'] != 1) + { + // load the form file + if (!isset($plugin->form_files[$form['file']])) + { + $plugin->form_files[$form['file']] = array(); + } + if (!isset($plugin->form_files[$form['file']][$form['fields_name']])) + { + $plugin->form_files[$form['file']][$form['fields_name']] = array(); + } + if (!isset($plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']])) + { + $plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']] = array(); + } + // do some house cleaning (for fields) + foreach ($form['fields'] as $field) + { + // so first we lock the field name in + $this->getFieldName($field, $plugin->key, $unique); + // add the fields to the global form file builder + $plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']][] = $field; + } + // remove form + unset($plugin->fields[$n]); + } + else + { + // load the cofig form + if (!isset($plugin->config_fields[$form['fields_name']])) + { + $plugin->config_fields[$form['fields_name']] = array(); + } + if (!isset($plugin->config_fields[$form['fields_name']][$form['fieldset']])) + { + $plugin->config_fields[$form['fields_name']][$form['fieldset']] = array(); + } + // do some house cleaning (for fields) + foreach ($form['fields'] as $field) + { + // so first we lock the field name in + $this->getFieldName($field, $plugin->key, $unique); + // add the fields to the config builder + $plugin->config_fields[$form['fields_name']][$form['fieldset']][] = $field; + } + // remove form + unset($plugin->fields[$n]); + } + } + else + { + unset($plugin->fields[$n]); + } + } + } + unset($plugin->fields); + // set the add targets + $addArray = array('files' => 'files', 'folders' => 'folders', 'urls' => 'urls', 'filesfullpath' => 'files', 'foldersfullpath' => 'folders'); + foreach ($addArray as $addTarget => $targetHere) + { + // set the add target data + $plugin->{'add' . $addTarget} = (isset($plugin->{'add' . $addTarget}) && ComponentbuilderHelper::checkJson($plugin->{'add' . $addTarget})) ? json_decode($plugin->{'add' . $addTarget}, true) : null; + if (ComponentbuilderHelper::checkArray($plugin->{'add' . $addTarget})) + { + if (isset($plugin->{$targetHere}) && ComponentbuilderHelper::checkArray($plugin->{$targetHere})) + { + foreach ($plugin->{'add' . $addTarget} as $taget) + { + $plugin->{$targetHere}[] = $taget; + } + } + else + { + $plugin->{$targetHere} = array_values($plugin->{'add' . $addTarget}); + } + } + unset($plugin->{'add' . $addTarget}); + } + // add PHP in plugin install + $plugin->add_install_script = false; + $addScriptMethods = array('php_preflight', 'php_postflight', 'php_method'); + $addScriptTypes = array('install', 'update', 'uninstall'); + foreach ($addScriptMethods as $scriptMethod) + { + foreach ($addScriptTypes as $scriptType) + { + if (isset($plugin->{'add_' . $scriptMethod . '_' . $scriptType}) && $plugin->{'add_' . $scriptMethod . '_' . $scriptType} == 1 && ComponentbuilderHelper::checkString($plugin->{$scriptMethod . '_' . $scriptType})) + { + // set GUI mapper field + $guiMapper['field'] = $scriptMethod . '_' . $scriptType; + $plugin->{$scriptMethod . '_' . $scriptType} = $this->setGuiCodePlaceholder( + $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->{$scriptMethod . '_' . $scriptType})), $this->placeholders), + $guiMapper + ); + $plugin->add_install_script = true; + } + else + { + unset($plugin->{$scriptMethod . '_' . $scriptType}); + $plugin->{'add_' . $scriptMethod . '_' . $scriptType} = 0; + } + } + } + // add_sql + if ($plugin->add_sql == 1 && ComponentbuilderHelper::checkString($plugin->sql)) + { + $plugin->sql = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->sql)), $this->placeholders); + } + else + { + unset($plugin->sql); + $plugin->add_sql = 0; + } + // add_sql_uninstall + if ($plugin->add_sql_uninstall == 1 && ComponentbuilderHelper::checkString($plugin->sql_uninstall)) + { + $plugin->sql_uninstall = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->sql_uninstall)), $this->placeholders); + } + else + { + unset($plugin->sql_uninstall); + $plugin->add_sql_uninstall = 0; + } + // update the URL of the update_server if set + if ($plugin->add_update_server == 1 && ComponentbuilderHelper::checkString($plugin->update_server_url)) + { + $plugin->update_server_url = $this->setPlaceholders($this->setDynamicValues($plugin->update_server_url), $this->placeholders); + } + // add the update/sales server FTP details if that is the expected protocol + $serverArray = array('update_server', 'sales_server'); + foreach ($serverArray as $server) + { + if ($plugin->{'add_' . $server} == 1 && is_numeric($plugin->{$server}) && $plugin->{$server} > 0) + { + // get the server protocol + $plugin->{$server . '_protocol'} = ComponentbuilderHelper::getVar('server', (int) $plugin->{$server}, 'id', 'protocol'); + } + else + { + $plugin->{$server} = 0; + // only change this for sales server (update server can be added loacaly to the zip file) + if ('sales_server' === $server) + { + $plugin->{'add_' . $server} = 0; + } + $plugin->{$server . '_protocol'} = 0; + } + } + // set the update server stuff (TODO) + // update_server_xml_path + // update_server_xml_file_name + + // rest globals + $this->target = $_backup_target; + $this->lang = $_backup_lang; + $this->langPrefix = $_backup_langPrefix; + + $this->joomlaPlugins[$id] = $plugin; + + return true; } - // set the update server stuff (TODO) - // update_server_xml_path - // update_server_xml_file_name - - // rest globals - $this->target = $_backup_target; - $this->lang = $_backup_lang; - $this->langPrefix = $_backup_langPrefix; - - return $plugin; } return false; } @@ -6478,7 +6621,6 @@ class Get $xml .= PHP_EOL . $this->_t(1) . '' . $plugin->lang_prefix . '_XML_DESCRIPTION'; $xml .= $this->hhh . 'MAINXML' . $this->hhh; $xml .= PHP_EOL . ''; - $dates = array(); return $xml; } diff --git a/admin/helpers/compiler/b_Structure.php b/admin/helpers/compiler/b_Structure.php index 7519a0d6d..79d7cbe1c 100644 --- a/admin/helpers/compiler/b_Structure.php +++ b/admin/helpers/compiler/b_Structure.php @@ -372,7 +372,7 @@ class Structure extends Get // load the libraries files/folders and url's $this->setLibraries(); // load the plugin files/folders and url's - $this->setPlugins(); + $this->buildPlugins(); // set the Joomla Version Data $this->joomlaVersionData = $this->setJoomlaVersionData(); // Trigger Event: jcb_ce_onAfterSetJoomlaVersionData @@ -422,13 +422,13 @@ class Structure extends Get * @return void * */ - private function setPlugins() + private function buildPlugins() { - if (ComponentbuilderHelper::checkArray($this->componentData->joomla_plugins)) + if (ComponentbuilderHelper::checkArray($this->joomlaPlugins)) { // Trigger Event: jcb_ce_onBeforeSetPlugins - $this->triggerEvent('jcb_ce_onBeforeSetPlugins', array(&$this->componentContext, &$this->componentData->joomla_plugins)); - foreach ($this->componentData->joomla_plugins as $plugin) + $this->triggerEvent('jcb_ce_onBeforeBuildPlugins', array(&$this->componentContext, &$this->joomlaPlugins)); + foreach ($this->joomlaPlugins as $plugin) { if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->folder_name) && ComponentbuilderHelper::checkString($plugin->folder_name)) @@ -491,6 +491,88 @@ class Structure extends Get // count the file created $this->fileCount++; } + // set fields & rules folders if needed + if (isset($plugin->fields_rules_paths) && $plugin->fields_rules_paths == 2) + { + // create fields folder + if (!JFolder::exists($plugin->folder_path . '/fields')) + { + JFolder::create($plugin->folder_path . '/fields'); + // count the folder created + $this->folderCount++; + $this->indexHTML($plugin->folder_name . '/fields', $this->compilerPath); + } + // create rules folder + if (!JFolder::exists($plugin->folder_path . '/rules')) + { + JFolder::create($plugin->folder_path . '/rules'); + // count the folder created + $this->folderCount++; + $this->indexHTML($plugin->folder_name . '/rules', $this->compilerPath); + } + } + // set forms folder if needed + if (isset($plugin->form_files) && ComponentbuilderHelper::checkArray($plugin->form_files)) + { + // create forms folder + if (!JFolder::exists($plugin->folder_path . '/forms')) + { + JFolder::create($plugin->folder_path . '/forms'); + // count the folder created + $this->folderCount++; + $this->indexHTML($plugin->folder_name . '/forms', $this->compilerPath); + } + // set the template files + foreach($plugin->form_files as $file => $fields) + { + // set file details + $fileDetails = array('path' => $plugin->folder_path . '/forms/' . $file . '.xml', + 'name' => $file . '.xml', 'zip' => 'forms/' . $file . '.xml'); + // biuld basic XML + $xml = ''; + $xml .= PHP_EOL . ''; + $xml .= PHP_EOL . '_t(1) . 'addrulepath="/administrator/components/com_' . $this->componentCodeName . '/models/rules"'; + $xml .= PHP_EOL . $this->_t(1) . 'addfieldpath="/administrator/components/com_' . $this->componentCodeName . '/models/fields"'; + $xml .= PHP_EOL . '>'; + foreach ($fields as $field_name => $fieldsets) + { + $xml .= PHP_EOL . $this->_t(1) . ''; + foreach ($fieldsets as $fieldset => $field) + { + // default to the field set name + $label = $fieldset; + if (isset($plugin->fieldsets_label[$file.$field_name.$fieldset])) + { + $label = $plugin->fieldsets_label[$file.$field_name.$fieldset]; + } + // add path to plugin rules and custom fields + if (isset($plugin->fieldsets_paths[$file.$field_name.$fieldset]) && $plugin->fieldsets_paths[$file.$field_name.$fieldset] == 2) + { + $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) . '
_t(2) . 'addrulepath="/plugins/' . strtolower($plugin->group) . '/' . strtolower($plugin->code_name) . '/rules"'; + $xml .= PHP_EOL . $this->_t(2) . 'addfieldpath="/plugins/' . strtolower($plugin->group) . '/' . strtolower($plugin->code_name) . '/fields"'; + $xml .= PHP_EOL . $this->_t(1) . '>'; + } + else + { + $xml .= PHP_EOL . $this->_t(1) . '
'; + } + // add the placeholder of the fields + $xml .= $this->hhh . 'FIELDSET_' . $file.$field_name.$fieldset . $this->hhh; + $xml .= PHP_EOL . $this->_t(1) . '
'; + } + $xml .= PHP_EOL . $this->_t(1) . ''; + } + $xml .= PHP_EOL . ''; + // add xml to file + $this->writeFile($fileDetails['path'], $xml); + $this->newFiles[$plugin->key][] = $fileDetails; + // count the file created + $this->fileCount++; + } + } // set SQL stuff if needed if ($plugin->add_sql || $plugin->add_sql_uninstall) { @@ -1279,13 +1361,50 @@ class Structure extends Get return false; } + /** + * move the fields and Rules + * + * @param array $field The field data + * @param string $path The path to move to + * + * @return void + * + */ + public function moveFieldsRules($field, $path) + { + // check if this is a custom field that should be moved + if (isset($this->extentionCustomfields[$field['type_name']])) + { + // check files exist + if (JFile::exists($this->componentPath . '/admin/models/fields/' . $field['type_name'] . '.php')) + { + // move the custom field + JFile::copy($this->componentPath . '/admin/models/fields/' . $field['type_name'] . '.php', $path . '/fields/' . $field['type_name'] . '.php'); + } + // do this just once + unset($this->extentionCustomfields[$field['type_name']]); + } + // check if this has validation that should be moved + if (isset($this->validationLinkedFields[$field['field']])) + { + // check files exist + if (JFile::exists($this->componentPath . '/admin/models/rules/' . $this->validationLinkedFields[$field['field']] . '.php')) + { + // move the custom field + JFile::copy($this->componentPath . '/admin/models/rules/' . $this->validationLinkedFields[$field['field']] . '.php', $path . '/rules/' . $this->validationLinkedFields[$field['field']] . '.php'); + } + // do this just once + unset($this->validationLinkedFields[$field['field']]); + } + } + /** * get the created date of the (view) - * + * * @param array $view The view values - * + * * @return string Last Modified Date - * + * */ public function getCreatedDate($view) { @@ -1304,11 +1423,11 @@ class Structure extends Get /** * get the last modified date of a MVC (view) - * + * * @param array $view The view values - * + * * @return string Last Modified Date - * + * */ public function getLastModifiedDate($view) { @@ -1487,10 +1606,9 @@ class Structure extends Get /** * set the Joomla Version Data - * * * @return oject The version data - * + * */ private function setJoomlaVersionData() { @@ -1722,11 +1840,11 @@ class Structure extends Get /** * set the index.html file in a folder path - * + * * @param string $path The path to place the index.html file in * * @return void - * + * */ private function indexHTML($path, $root = 'component') { diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php index d3a3eb53c..2ccffe31f 100644 --- a/admin/helpers/compiler/c_Fields.php +++ b/admin/helpers/compiler/c_Fields.php @@ -333,6 +333,13 @@ class Fields extends Structure */ public $movedPublishingFields = array(); + /** + * Extention Custom Fields + * + * @var array + */ + public $extentionCustomfields = array(); + /** * Set the line number in comments * @@ -1659,7 +1666,8 @@ class Fields extends Structure } $field .= PHP_EOL . $this->_t(2) . $taber . "/>"; // incase the field is in the config and has not been set - if ('config' === $view_name_single && 'configs' === $view_name_list) + if ('config' === $view_name_single && 'configs' === $view_name_list|| + strpos($view_name_single, 'P|uG!n') !== false) { // set lang (just incase) $listLangName = $langView . '_' . ComponentbuilderHelper::safeString($name, 'U'); @@ -2144,8 +2152,9 @@ class Fields extends Structure $field->fieldXML->addAttribute($property, $value); } } - // incase the field is in the config and has not been set - if ('config' === $view_name_single && 'configs' === $view_name_list) + // incase the field is in the config and has not been set (or is part of a plugin or module) + if (('config' === $view_name_single && 'configs' === $view_name_list) || + strpos($view_name_single, 'P|uG!n') !== false) { // set lang (just incase) $listLangName = $langView . '_' . ComponentbuilderHelper::safeString($name, 'U'); @@ -3241,6 +3250,12 @@ class Fields extends Structure $this->fileContentDynamic['customfield_' . $data['type']][$this->hhh . 'ADD_BUTTON' . $this->hhh] = $this->setAddButtonToListField($data['custom']); } } + // if this field gets used in plugin or module we should track it so if needed we can copy it over + if (strpos($view_name_single, 'P|uG!n') !== false && + isset($data['custom']) && isset($data['custom']['type'])) + { + $this->extentionCustomfields[$data['type']] = $data['custom']['type']; + } } /** diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index ac27493e5..61fddfa43 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -16296,13 +16296,7 @@ function vdm_dkim() { public function getPluginMainXML(&$plugin) { - // tweak system to set stuff to the plugin domain - $_backup_target = $this->target; - $_backup_lang = $this->lang; - $_backup_langPrefix = $this->langPrefix; - $this->target = $plugin->key; - $this->lang = $plugin->key; - $this->langPrefix = $plugin->lang_prefix; + // set some defaults $view = ''; $viewType = 0; // set the custom table key @@ -16310,31 +16304,21 @@ function vdm_dkim() { // build the xml $xml = ''; // build the config fields - $config_field = ''; + $config_fields = array(); if (isset($plugin->config_fields) && ComponentbuilderHelper::checkArray($plugin->config_fields)) { - foreach ($plugin->config_fields as $field) + foreach ($plugin->config_fields as $field_name => $fieldsets) { - // check the field builder type - if ($this->fieldBuilderType == 1) + foreach ($fieldsets as $fieldset => $fields) { - // string manipulation - $xmlField = $this->setDynamicField($field, $view, $viewType, $plugin->lang_prefix, $plugin->key, $plugin->key, $this->globalPlaceholders, $dbkey, false); - } - else - { - // simpleXMLElement class - $newxmlField = $this->setDynamicField($field, $view, $viewType, $plugin->lang_prefix, $plugin->key, $plugin->key, $this->globalPlaceholders, $dbkey, false); - if (isset($newxmlField->fieldXML)) + // get the field set + $xmlFields = $this->getPluginFieldsetXML($plugin, $fields, $dbkey); + // make sure the xml is set and a string + if (isset($xmlFields) && ComponentbuilderHelper::checkString($xmlFields)) { - $xmlField = dom_import_simplexml($newxmlField->fieldXML); - $xmlField = PHP_EOL . $this->_t(2) . "' . PHP_EOL . $this->_t(1) . $this->xmlPrettyPrint($xmlField, 'field'); + $config_fields[$field_name.$fieldset] = $xmlFields; } - } - // make sure the xml is set and a string - if (isset($xmlField) && ComponentbuilderHelper::checkString($xmlField)) - { - $config_field .= $xmlField; + $dbkey++; } } } @@ -16348,8 +16332,8 @@ function vdm_dkim() { return $placeholder . '="' . $langstring . '"'; }, $this->langContent[$plugin->key], array_keys($this->langContent[$plugin->key])); // add to language file - $this->writeFile($plugin->folder_path . '/language/' . $this->langTag . '/' . $this->langTag . '.plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->name) . '.ini', implode(PHP_EOL, $lang)); - $this->writeFile($plugin->folder_path . '/language/' . $this->langTag . '/' . $this->langTag . '.plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->name) . '.sys.ini', implode(PHP_EOL, $lang)); + $this->writeFile($plugin->folder_path . '/language/' . $this->langTag . '/' . $this->langTag . '.plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->code_name) . '.ini', implode(PHP_EOL, $lang)); + $this->writeFile($plugin->folder_path . '/language/' . $this->langTag . '/' . $this->langTag . '.plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->code_name) . '.sys.ini', implode(PHP_EOL, $lang)); // set the line counter $this->lineCount = $this->lineCount + count((array) $lang); unset($lang); @@ -16392,8 +16376,8 @@ function vdm_dkim() { { $xml .= PHP_EOL . PHP_EOL . $this->_t(1) . ''; $xml .= PHP_EOL . $this->_t(1) . ''; - $xml .= PHP_EOL . $this->_t(2) . '' . $this->langTag . '/' . $this->langTag . '.plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->name) . '.ini'; - $xml .= PHP_EOL . $this->_t(2) . '' . $this->langTag . '/' . $this->langTag . '.plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->name) . '.sys.ini'; + $xml .= PHP_EOL . $this->_t(2) . '' . $this->langTag . '/' . $this->langTag . '.plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->code_name) . '.ini'; + $xml .= PHP_EOL . $this->_t(2) . '' . $this->langTag . '/' . $this->langTag . '.plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->code_name) . '.sys.ini'; $xml .= PHP_EOL . $this->_t(1) . ''; } // add the plugin files @@ -16436,15 +16420,49 @@ function vdm_dkim() { } $xml .= PHP_EOL . $this->_t(1) . ''; // now add the Config Params if needed - if (ComponentbuilderHelper::checkString($config_field)) + if (ComponentbuilderHelper::checkArray($config_fields)) { $xml .= PHP_EOL . PHP_EOL . $this->_t(1) . ''; - $xml .= PHP_EOL . $this->_t(1) . ''; - $xml .= PHP_EOL . $this->_t(1) . ''; - $xml .= PHP_EOL . $this->_t(1) . '
'; - $xml .= $config_field; - $xml .= PHP_EOL . $this->_t(1) . '
'; - $xml .= PHP_EOL . $this->_t(1) . '
'; + // add path to plugin rules and custom fields + $xml .= PHP_EOL . $this->_t(1) . '_t(2) . 'addrulepath="/administrator/components/com_' . $this->componentCodeName . '/models/rules"'; + $xml .= PHP_EOL . $this->_t(2) . 'addfieldpath="/administrator/components/com_' . $this->componentCodeName . '/models/fields"'; + $xml .= PHP_EOL . $this->_t(1) . '>'; + + foreach ($plugin->config_fields as $field_name => $fieldsets) + { + $xml .= PHP_EOL . $this->_t(1) . ''; + foreach ($fieldsets as $fieldset => $fields) + { + // default to the field set name + $label = $fieldset; + if (isset($plugin->fieldsets_label[$field_name.$fieldset])) + { + $label = $plugin->fieldsets_label[$field_name.$fieldset]; + } + // add path to plugin rules and custom fields + if (isset($plugin->fieldsets_paths[$field_name.$fieldset]) && $plugin->fieldsets_paths[$field_name.$fieldset] == 2) + { + $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) . '
_t(2) . 'addrulepath="/plugins/' . strtolower($plugin->group) . '/' . strtolower($plugin->code_name) . '/rules"'; + $xml .= PHP_EOL . $this->_t(2) . 'addfieldpath="/plugins/' . strtolower($plugin->group) . '/' . strtolower($plugin->code_name) . '/fields"'; + $xml .= PHP_EOL . $this->_t(1) . '>'; + } + else + { + $xml .= PHP_EOL . $this->_t(1) . '
'; + } + // load the fields + if (isset($config_fields[$field_name.$fieldset])) + { + $xml .= $config_fields[$field_name.$fieldset]; + unset($config_fields[$field_name.$fieldset]); + } + $xml .= PHP_EOL . $this->_t(1) . '
'; + } + $xml .= PHP_EOL . $this->_t(1) . ''; + } $xml .= PHP_EOL . $this->_t(1) . ''; } // set update server if found @@ -16455,14 +16473,48 @@ function vdm_dkim() { $xml .= PHP_EOL . $this->_t(2) . '' . $plugin->update_server_url . ''; $xml .= PHP_EOL . $this->_t(1) . ''; } - // rest globals - $this->target = $_backup_target; - $this->lang = $_backup_lang; - $this->langPrefix = $_backup_langPrefix; return $xml; } + public function getPluginFieldsetXML(&$plugin, &$fields, $dbkey = 'zz') + { + // set some defaults + $view = ''; + $viewType = 0; + // build the fieldset + $fieldset = ''; + + if (ComponentbuilderHelper::checkArray($fields)) + { + foreach ($fields as $field) + { + // check the field builder type + if ($this->fieldBuilderType == 1) + { + // string manipulation + $xmlField = $this->setDynamicField($field, $view, $viewType, $plugin->lang_prefix, $plugin->key, $plugin->key, $this->globalPlaceholders, $dbkey, false); + } + else + { + // simpleXMLElement class + $newxmlField = $this->setDynamicField($field, $view, $viewType, $plugin->lang_prefix, $plugin->key, $plugin->key, $this->globalPlaceholders, $dbkey, false); + if (isset($newxmlField->fieldXML)) + { + $xmlField = dom_import_simplexml($newxmlField->fieldXML); + $xmlField = PHP_EOL . $this->_t(2) . "' . PHP_EOL . $this->_t(1) . $this->xmlPrettyPrint($xmlField, 'field'); + } + } + // make sure the xml is set and a string + if (isset($xmlField) && ComponentbuilderHelper::checkString($xmlField)) + { + $fieldset .= $xmlField; + } + } + } + return $fieldset; + } + public function getPluginInstallClass(&$plugin) { // yes we are adding it diff --git a/admin/helpers/compiler/f_Infusion.php b/admin/helpers/compiler/f_Infusion.php index 32d568c9d..6172b7649 100644 --- a/admin/helpers/compiler/f_Infusion.php +++ b/admin/helpers/compiler/f_Infusion.php @@ -1033,12 +1033,19 @@ class Infusion extends Interpretation } // infuze plugin data if set - if (ComponentbuilderHelper::checkArray($this->componentData->joomla_plugins)) + if (ComponentbuilderHelper::checkArray($this->joomlaPlugins)) { - foreach ($this->componentData->joomla_plugins as $plugin) + foreach ($this->joomlaPlugins as $plugin) { if (ComponentbuilderHelper::checkObject($plugin)) { + // tweak system to set stuff to the plugin domain + $_backup_target = $this->target; + $_backup_lang = $this->lang; + $_backup_langPrefix = $this->langPrefix; + $this->target = $plugin->key; + $this->lang = $plugin->key; + $this->langPrefix = $plugin->lang_prefix; // MAINCLASS $this->fileContentDynamic[$plugin->key][$this->hhh . 'MAINCLASS' . $this->hhh] = $this->getPluginMainClass($plugin); // only add install script if needed @@ -1047,8 +1054,28 @@ class Infusion extends Interpretation // INSTALLCLASS $this->fileContentDynamic[$plugin->key][$this->hhh . 'INSTALLCLASS' . $this->hhh] = $this->getPluginInstallClass($plugin); } + // FIELDSET + if (isset($plugin->form_files) && ComponentbuilderHelper::checkArray($plugin->form_files)) + { + foreach($plugin->form_files as $file => $files) + { + foreach ($files as $field_name => $fieldsets) + { + foreach ($fieldsets as $fieldset => $fields) + { + // FIELDSET_ . $file.$field_name.$fieldset + $this->fileContentDynamic[$plugin->key][$this->hhh . 'FIELDSET_' . $file.$field_name.$fieldset . $this->hhh] = + $this->getPluginFieldsetXML($plugin, $fields); + } + } + } + } // MAINXML $this->fileContentDynamic[$plugin->key][$this->hhh . 'MAINXML' . $this->hhh] = $this->getPluginMainXML($plugin); + // rest globals + $this->target = $_backup_target; + $this->lang = $_backup_lang; + $this->langPrefix = $_backup_langPrefix; } } } diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index cff883ed2..bcc867e8f 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -6406,7 +6406,31 @@ abstract class ComponentbuilderHelper jimport('joomla.form.form'); } // get field type - $field = JFormHelper::loadFieldType($attributes['type'],true); + $field = JFormHelper::loadFieldType($attributes['type'], true); + // get field xml + $XML = self::getFieldXML($attributes, $options); + // setup the field + $field->setup($XML, $default); + // return the field object + return $field; + } + return false; + } + + /** + * get the field xml + * + * @param array $attributes The array of attributes + * @param array $options The options to apply to the XML element + * + * @return object + * + */ + public static function getFieldXML(&$attributes, $options = null) + { + // make sure we have attributes and a type value + if (self::checkArray($attributes)) + { // start field xml $XML = new SimpleXMLElement(''); // load the attributes @@ -6417,10 +6441,8 @@ abstract class ComponentbuilderHelper // load the options self::xmlAddOptions($XML, $options); } - // setup the field - $field->setup($XML, $default); - // return the field object - return $field; + // return the field xml + return $XML; } return false; } diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index 0c0f74f62..09f062ea3 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -6017,7 +6017,7 @@ COM_COMPONENTBUILDER_JOOMLA_PLUGIN_ADD_UPDATE_SERVER_LABEL="Add Update Server" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CLASS_EXTENDS="Class Extends" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CLASS_EXTENDS_LABEL="Extends" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CODE="Code" -COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CONFIGPARAMS="Config/Params" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_COMPONENT="Component" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CREATED_BY_DESC="The user that created this Joomla Plugin." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CREATED_BY_LABEL="Created By" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_CREATED_DATE_DESC="The date this Joomla Plugin was created." @@ -6034,7 +6034,16 @@ COM_COMPONENTBUILDER_JOOMLA_PLUGIN_EDIT="Editing the Joomla Plugin" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_ERROR_UNIQUE_ALIAS="Another Joomla Plugin has the same alias." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD="Field" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS="Fields" -COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_LABEL="Fields" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDSET_DESCRIPTION="Leave default if you don't know what this should be" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDSET_HINT="basic" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDSET_LABEL="Fieldset Name" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_DESCRIPTION="All the field that belong to this form." +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_LABEL="Related Forms" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_NAME_DESCRIPTION="Leave default if you don't know what this should be." +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_NAME_HINT="params" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_NAME_LABEL="Fields Name" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_RULES_PATHS_DESCRIPTION="Where should the custom fields and rules be placed." +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_RULES_PATHS_LABEL="Fields & Rules Paths" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_DESCRIPTION="Select a field" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_LABEL="Field" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILES_FOLDERS_URLS="Joomla Plugin Files, Folders & URLs" @@ -6153,6 +6162,10 @@ COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILES_FOLDERS_URLS_URL_LABEL="URL" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILES_FOLDERS_URLS_URL_MESSAGE="Error! Please add url here." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILES_FOLDERS_URLS_VERSION_DESC="A count of the number of times this Joomla Plugin Files, Folders & URLs has been revised." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILES_FOLDERS_URLS_VERSION_LABEL="Revision" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILE_DESCRIPTION="Leave default if you don't know what this should be. This field is ignored if this form belongs to the plugin config area." +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILE_HINT="config" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FILE_LABEL="File Name" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FORMS_FIELDS="Forms & Fields" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_GET_BOILERPLATE_BUTTON_ACCESS="Joomla Plugin Get Boilerplate Button Access" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_GET_BOILERPLATE_BUTTON_ACCESS_DESC="Allows the users in this group to access the get boilerplate button." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_GROUP="Joomla Plugin Group" @@ -6215,6 +6228,9 @@ COM_COMPONENTBUILDER_JOOMLA_PLUGIN_HEAD_LABEL="Class Head" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_ID="Id" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_JOOMLA_PLUGIN_GROUP="Joomla Plugin Group" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_JOOMLA_PLUGIN_GROUP_LABEL="Joomla Plugin Group" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_DESCRIPTION="Not mandatory, used to Label the Fieldset" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_HINT="Name" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_LABEL="Label" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MAIN_CLASS_CODE="Main Class Code" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MAIN_CLASS_CODE_DESCRIPTION="Add the class properties & methods here." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MAIN_CLASS_CODE_LABEL="Class Properties & Methods" @@ -6272,6 +6288,9 @@ COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PHP_PREFLIGHT_UPDATE_LABEL="PHP Preflight (up COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PHP_SCRIPT_CONSTRUCT="Php Script Construct" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PHP_SCRIPT_CONSTRUCT_DESCRIPTION="PHP script that should run in __construct of script." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PHP_SCRIPT_CONSTRUCT_LABEL="PHP Script Construct" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN="Plugin" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN_DESCRIPTION="Add this form the the Plugin Config area." +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN_LABEL="Add to Plugin Config" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN_VERSION="Plugin Version" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN_VERSION_DESCRIPTION="Add Version Number Here" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PLUGIN_VERSION_HINT="1.0.0" diff --git a/admin/layouts/joomla_plugin/configparams_fullwidth.php b/admin/layouts/joomla_plugin/forms_fields_fullwidth.php similarity index 100% rename from admin/layouts/joomla_plugin/configparams_fullwidth.php rename to admin/layouts/joomla_plugin/forms_fields_fullwidth.php diff --git a/admin/models/admin_custom_tabs.php b/admin/models/admin_custom_tabs.php index 2f02ef692..28d206821 100644 --- a/admin/models/admin_custom_tabs.php +++ b/admin/models/admin_custom_tabs.php @@ -363,6 +363,8 @@ class ComponentbuilderModelAdmin_custom_tabs extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.admin_custom_tabs', $data); } return $data; diff --git a/admin/models/admin_fields.php b/admin/models/admin_fields.php index 9e7504f88..c0647e9d1 100644 --- a/admin/models/admin_fields.php +++ b/admin/models/admin_fields.php @@ -384,6 +384,8 @@ class ComponentbuilderModelAdmin_fields extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.admin_fields', $data); } return $data; diff --git a/admin/models/admin_fields_conditions.php b/admin/models/admin_fields_conditions.php index 2e2013d7e..d8ae43fe2 100644 --- a/admin/models/admin_fields_conditions.php +++ b/admin/models/admin_fields_conditions.php @@ -384,6 +384,8 @@ class ComponentbuilderModelAdmin_fields_conditions extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.admin_fields_conditions', $data); } return $data; diff --git a/admin/models/admin_fields_relations.php b/admin/models/admin_fields_relations.php index 555d5a17f..c8a4b3b05 100644 --- a/admin/models/admin_fields_relations.php +++ b/admin/models/admin_fields_relations.php @@ -395,6 +395,8 @@ class ComponentbuilderModelAdmin_fields_relations extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.admin_fields_relations', $data); } return $data; diff --git a/admin/models/admin_view.php b/admin/models/admin_view.php index cd22a3bdd..397995d35 100644 --- a/admin/models/admin_view.php +++ b/admin/models/admin_view.php @@ -893,6 +893,8 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.admin_view', $data); } return $data; diff --git a/admin/models/class_extends.php b/admin/models/class_extends.php index e76ee6c01..87bfe0110 100644 --- a/admin/models/class_extends.php +++ b/admin/models/class_extends.php @@ -426,6 +426,8 @@ class ComponentbuilderModelClass_extends extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.class_extends', $data); } return $data; diff --git a/admin/models/class_method.php b/admin/models/class_method.php index d6a4a8f97..4b0e11468 100644 --- a/admin/models/class_method.php +++ b/admin/models/class_method.php @@ -435,6 +435,8 @@ class ComponentbuilderModelClass_method extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.class_method', $data); } return $data; diff --git a/admin/models/class_property.php b/admin/models/class_property.php index aa9bb5f1c..e723628fb 100644 --- a/admin/models/class_property.php +++ b/admin/models/class_property.php @@ -426,6 +426,8 @@ class ComponentbuilderModelClass_property extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.class_property', $data); } return $data; diff --git a/admin/models/component_admin_views.php b/admin/models/component_admin_views.php index 41ea25f34..87cd48e18 100644 --- a/admin/models/component_admin_views.php +++ b/admin/models/component_admin_views.php @@ -395,6 +395,8 @@ class ComponentbuilderModelComponent_admin_views extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_admin_views', $data); } return $data; diff --git a/admin/models/component_config.php b/admin/models/component_config.php index 6d2601dc4..d51bd02b5 100644 --- a/admin/models/component_config.php +++ b/admin/models/component_config.php @@ -394,6 +394,8 @@ class ComponentbuilderModelComponent_config extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_config', $data); } return $data; diff --git a/admin/models/component_custom_admin_menus.php b/admin/models/component_custom_admin_menus.php index 6ad3c4e29..735f98485 100644 --- a/admin/models/component_custom_admin_menus.php +++ b/admin/models/component_custom_admin_menus.php @@ -394,6 +394,8 @@ class ComponentbuilderModelComponent_custom_admin_menus extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_custom_admin_menus', $data); } return $data; diff --git a/admin/models/component_custom_admin_views.php b/admin/models/component_custom_admin_views.php index fa75cb6e0..e8700e541 100644 --- a/admin/models/component_custom_admin_views.php +++ b/admin/models/component_custom_admin_views.php @@ -395,6 +395,8 @@ class ComponentbuilderModelComponent_custom_admin_views extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_custom_admin_views', $data); } return $data; diff --git a/admin/models/component_dashboard.php b/admin/models/component_dashboard.php index 38d85aca3..691091f0b 100644 --- a/admin/models/component_dashboard.php +++ b/admin/models/component_dashboard.php @@ -432,6 +432,8 @@ class ComponentbuilderModelComponent_dashboard extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_dashboard', $data); } return $data; diff --git a/admin/models/component_files_folders.php b/admin/models/component_files_folders.php index a055f8093..a0781b791 100644 --- a/admin/models/component_files_folders.php +++ b/admin/models/component_files_folders.php @@ -431,6 +431,8 @@ class ComponentbuilderModelComponent_files_folders extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_files_folders', $data); } return $data; diff --git a/admin/models/component_mysql_tweaks.php b/admin/models/component_mysql_tweaks.php index ea0bfa93b..6f2940d95 100644 --- a/admin/models/component_mysql_tweaks.php +++ b/admin/models/component_mysql_tweaks.php @@ -394,6 +394,8 @@ class ComponentbuilderModelComponent_mysql_tweaks extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_mysql_tweaks', $data); } return $data; diff --git a/admin/models/component_placeholders.php b/admin/models/component_placeholders.php index 1255bc8ab..66ef2998b 100644 --- a/admin/models/component_placeholders.php +++ b/admin/models/component_placeholders.php @@ -363,6 +363,8 @@ class ComponentbuilderModelComponent_placeholders extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_placeholders', $data); } return $data; diff --git a/admin/models/component_plugins.php b/admin/models/component_plugins.php index e2f2f116f..bb470b131 100644 --- a/admin/models/component_plugins.php +++ b/admin/models/component_plugins.php @@ -364,6 +364,8 @@ class ComponentbuilderModelComponent_plugins extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_plugins', $data); } return $data; diff --git a/admin/models/component_site_views.php b/admin/models/component_site_views.php index 49a5ca3c1..cbee6cb86 100644 --- a/admin/models/component_site_views.php +++ b/admin/models/component_site_views.php @@ -395,6 +395,8 @@ class ComponentbuilderModelComponent_site_views extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_site_views', $data); } return $data; diff --git a/admin/models/component_updates.php b/admin/models/component_updates.php index d5736ca78..e48692dac 100644 --- a/admin/models/component_updates.php +++ b/admin/models/component_updates.php @@ -394,6 +394,8 @@ class ComponentbuilderModelComponent_updates extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.component_updates', $data); } return $data; diff --git a/admin/models/custom_admin_view.php b/admin/models/custom_admin_view.php index f73f7132c..27feae8e4 100644 --- a/admin/models/custom_admin_view.php +++ b/admin/models/custom_admin_view.php @@ -599,6 +599,8 @@ class ComponentbuilderModelCustom_admin_view extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.custom_admin_view', $data); } return $data; diff --git a/admin/models/custom_code.php b/admin/models/custom_code.php index 534c3b3cd..9d43b8aa1 100644 --- a/admin/models/custom_code.php +++ b/admin/models/custom_code.php @@ -435,6 +435,8 @@ class ComponentbuilderModelCustom_code extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.custom_code', $data); } return $data; diff --git a/admin/models/dynamic_get.php b/admin/models/dynamic_get.php index 0d899b1c5..bfd62a426 100644 --- a/admin/models/dynamic_get.php +++ b/admin/models/dynamic_get.php @@ -613,6 +613,8 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.dynamic_get', $data); } return $data; diff --git a/admin/models/field.php b/admin/models/field.php index 26463a098..a088bc29f 100644 --- a/admin/models/field.php +++ b/admin/models/field.php @@ -483,6 +483,8 @@ class ComponentbuilderModelField extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.field', $data); } return $data; diff --git a/admin/models/fields/joomlaplugins.php b/admin/models/fields/joomlaplugins.php index 7f626b7d5..dbe243a41 100644 --- a/admin/models/fields/joomlaplugins.php +++ b/admin/models/fields/joomlaplugins.php @@ -26,7 +26,111 @@ class JFormFieldJoomlaplugins extends JFormFieldList * * @var string */ - public $type = 'joomlaplugins'; + 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. diff --git a/admin/models/fields/targetfields.php b/admin/models/fields/targetfields.php index f76be0b5f..7439b32ac 100644 --- a/admin/models/fields/targetfields.php +++ b/admin/models/fields/targetfields.php @@ -41,19 +41,26 @@ class JFormFieldTargetfields extends JFormFieldList $jinput = JFactory::getApplication()->input; // get the id $ID = $jinput->getInt('id', 0); + // get the view name + $VIEW = $jinput->get('view', null, 'WORD'); // rest the fields ids $fieldIds = array(); - if (is_numeric($ID) && $ID >= 1) + // if this is an actual admin view then we are done + if ('admin_view' === $VIEW && is_numeric($ID) && $ID >= 1) + { + $adminView = $ID; + } + elseif (is_numeric($ID) && $ID >= 1) { // get the admin view ID $adminView = ComponentbuilderHelper::getVar('admin_fields_conditions', (int) $ID, 'id', 'admin_view'); } - else + elseif ('admin_view' !== $VIEW) { // get the admin view ID $adminView = $jinput->getInt('refid', 0); } - if (is_numeric($adminView) && $adminView >= 1) + if (isset($adminView) && is_numeric($adminView) && $adminView >= 1) { // get all the fields linked to the admin view if ($addFields = ComponentbuilderHelper::getVar('admin_fields', (int) $adminView, 'admin_view', 'addfields')) diff --git a/admin/models/fieldtype.php b/admin/models/fieldtype.php index 3e025683c..07f155050 100644 --- a/admin/models/fieldtype.php +++ b/admin/models/fieldtype.php @@ -630,6 +630,8 @@ class ComponentbuilderModelFieldtype extends JModelAdmin if (empty($data)) { $data = $this->getItem(); + // run the perprocess of the data + $this->preprocessData('com_componentbuilder.fieldtype', $data); } return $data; diff --git a/admin/models/forms/joomla_plugin.xml b/admin/models/forms/joomla_plugin.xml index 0c5450730..09b9f5df6 100644 --- a/admin/models/forms/joomla_plugin.xml +++ b/admin/models/forms/joomla_plugin.xml @@ -409,38 +409,134 @@ type="subform" name="fields" label="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELDS_LABEL" - layout="joomla.form.field.subform.repeatable-table" + layout="joomla.form.field.subform.repeatable" multiple="true" buttons="add,remove,move" icon="list" - max="50"> + max="10">