Improved the plugin form builder, to allow multi form field relationships.

This commit is contained in:
2019-08-22 03:54:47 +02:00
parent c13c752abb
commit d2f94d84fa
65 changed files with 1225 additions and 431 deletions

View File

@ -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 = '<p>' . $plugin->description . '</p>';
}
$plugin->xml_description = "<h1>" . $plugin->official_name . " (v." . $plugin->plugin_version . ")</h1> <div style='clear: both;'></div>" . $plugin->description . "<p>Created by <a href='" . trim($component->website) . "' target='_blank'>" . trim(JFilterOutput::cleanText($component->author)) . "</a><br /><small>Development started " . JFactory::getDate($plugin->created)->format("jS F, Y") . "</small></p>";
// 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 = '<p>' . $plugin->description . '</p>';
}
$plugin->xml_description = "<h1>" . $plugin->official_name . " (v." . $plugin->plugin_version . ")</h1> <div style='clear: both;'></div>" . $plugin->description . "<p>Created by <a href='" . trim($component->website) . "' target='_blank'>" . trim(JFilterOutput::cleanText($component->author)) . "</a><br /><small>Development started " . JFactory::getDate($plugin->created)->format("jS F, Y") . "</small></p>";
// 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) . '<description>' . $plugin->lang_prefix . '_XML_DESCRIPTION</description>';
$xml .= $this->hhh . 'MAINXML' . $this->hhh;
$xml .= PHP_EOL . '</extension>';
$dates = array();
return $xml;
}