Improved the get snippets area to load one library at a time. started on the adaptation of the compiler that is needed for the new libraries

This commit is contained in:
2017-12-03 20:09:04 +02:00
parent 82df61aa4a
commit 19d4d77305
45 changed files with 1841 additions and 712 deletions

View File

@ -497,6 +497,20 @@ class Get
* @var array
*/
public $updateSQL = array();
/**
* The Library Manager
*
* @var array
*/
public $libManager = array();
/**
* The Libraries
*
* @var array
*/
public $libraries = array();
/***
* Constructor
@ -855,7 +869,7 @@ class Get
unset($component->addcustom_admin_views);
}
// ser the config data
// set the config data
$component->addconfig = (isset($component->addconfig) && ComponentbuilderHelper::checkJson($component->addconfig)) ? json_decode($component->addconfig,true):null;
if (ComponentbuilderHelper::checkArray($component->addconfig))
{
@ -1717,6 +1731,45 @@ class Get
// }
}
}
// load the library
if (!isset($this->libManager[$this->target]) || !isset($this->libManager[$this->target][$view->code]))
{
// prep array
if (!isset($this->libManager[$this->target]))
{
$this->libManager[$this->target] = array();
}
if (!isset($this->libManager[$this->target][$view->code]))
{
$this->libManager[$this->target][$view->code] = array();
}
// make sure json become array
if (ComponentbuilderHelper::checkJson($view->libraries))
{
$view->libraries = json_decode($view->libraries, true);
}
// if we have an array add it
if (ComponentbuilderHelper::checkArray($view->libraries))
{
foreach ($view->libraries as $library)
{
if (!isset($this->libManager[$this->target][$view->code][$library]))
{
if ($this->getLibrary($library))
{
$this->libManager[$this->target][$view->code][$library] = true;
}
}
}
}
elseif (is_numeric($view->libraries) && !isset($this->libManager[$this->target][$view->code][(int) $view->libraries]))
{
if ($this->getLibrary((int) $view->libraries))
{
$this->libManager[$this->target][$view->code][(int) $view->libraries] = true;
}
}
}
// add_Ajax for this view
if (isset($view->add_php_ajax) && $view->add_php_ajax == 1)
{
@ -2726,7 +2779,7 @@ class Get
* @return array The data found with the alias
*
*/
public function getDataWithAlias($n_ame,$table,$view)
public function getDataWithAlias($n_ame, $table, $view)
{
// Create a new query object.
$query = $this->db->getQuery(true);
@ -2789,12 +2842,200 @@ class Get
$this->getModule[$this->target][$view] = true;
}
}
// load the library
if (!isset($this->libManager[$this->target]) || !isset($this->libManager[$this->target][$view]))
{
// prep array
if (!isset($this->libManager[$this->target]))
{
$this->libManager[$this->target] = array();
}
if (!isset($this->libManager[$this->target][$view]))
{
$this->libManager[$this->target][$view] = array();
}
// make sure json become array
if (ComponentbuilderHelper::checkJson($row->libraries))
{
$row->libraries = json_decode($row->libraries, true);
}
// if we have an array add it
if (ComponentbuilderHelper::checkArray($row->libraries))
{
foreach ($row->libraries as $library)
{
if (!isset($this->libManager[$this->target][$view][$library]))
{
if ($this->getLibrary($library))
{
$this->libManager[$this->target][$view][$library] = true;
}
}
}
}
elseif (is_numeric($row->libraries) && !isset($this->libManager[$this->target][$view][(int) $row->libraries]))
{
if ($this->getLibrary((int) $row->libraries))
{
$this->libManager[$this->target][$view][(int) $row->libraries] = true;
}
}
}
return array('id' => $row->id, 'html' => $contnent, 'php_view' => $php_view);
}
}
return false;
}
/**
* Get Library Data and store globaly
*
* @param string $id the library id
*
* @return bool true on success
*
*/
protected function getLibrary($id)
{
// check if the lib has already been set
if (!isset($this->libraries[$id]))
{
$query = $this->db->getQuery(true);
$query->select('a.*');
$query->select(
$this->db->quoteName(
array(
'a.id',
'a.name',
'a.how',
'a.type',
'a.addconditions',
'b.addconfig',
'c.addfiles',
'c.addfolders',
'c.addurls',
'a.php_preparedocument',
'a.php_setdocument'
),
array(
'id',
'name',
'how',
'type',
'addconditions',
'addconfig',
'addfiles',
'addfolders',
'addurls',
'php_preparedocument',
'php_setdocument'
)
)
);
// from these tables
$query->from('#__componentbuilder_library AS a');
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_library_config', 'b') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('b.library') . ')');
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_library_files_folders_urls', 'c') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('c.library') . ')');
$query->where($this->db->quoteName('a.id') . ' = '. (int) $id);
// Reset the query using our newly populated query object.
$this->db->setQuery($query);
// Load the results as a list of stdClass objects
$library = $this->db->loadObject();
// check if this lib has dynamic behaviour
if ($library->how > 0)
{
// unset original value
unset($library->addconfig);
// set the addfolders data
$library->addfolders = (isset($library->addfolders) && ComponentbuilderHelper::checkJson($library->addfolders)) ? json_decode($library->addfolders,true):null;
if (ComponentbuilderHelper::checkArray($library->addfolders))
{
$library->folders = array_values($library->addfolders);
}
unset($library->addfolders);
// set the addfiles data
$library->addfiles = (isset($library->addfiles) && ComponentbuilderHelper::checkJson($library->addfiles)) ? json_decode($library->addfiles,true):null;
if (ComponentbuilderHelper::checkArray($library->addfiles))
{
$library->files = array_values($library->addfiles);
}
unset($library->addfiles);
// set the addurls data
$library->addurls = (isset($library->addurls) && ComponentbuilderHelper::checkJson($library->addurls)) ? json_decode($library->addurls,true):null;
if (ComponentbuilderHelper::checkArray($library->addurls))
{
$library->urls = array_values($library->addurls);
}
unset($library->addurls);
// add config fields only if needed
if ($library->how > 1)
{
// set the config data
$library->addconfig = (isset($library->addconfig) && ComponentbuilderHelper::checkJson($library->addconfig)) ? json_decode($library->addconfig,true):null;
if (ComponentbuilderHelper::checkArray($library->addconfig))
{
$library->config = array_map(function($array) {
$array['alias'] = 0;
$array['title'] = 0;
$array['settings'] = $this->getFieldData($array['field']);
return $array;
}, array_values($library->addconfig));
}
}
// if this lib is controlled by custom script
if (3 == $library->how)
{
// set Needed PHP
$phpMethods = array('preparedocument', 'setdocument');
foreach ($phpMethods as $method)
{
if (isset($library->{'php_'.$method}) && ComponentbuilderHelper::checkString($library->{'php_'.$method}))
{
$library->{$method} = $this->setDynamicValues(base64_decode($library->{'php_'.$method}));
}
}
}
// if this lib is controlled by conditions
elseif (2 == $library->how)
{
// set the addconditions data
$library->addconditions = (isset($library->addconditions) && ComponentbuilderHelper::checkJson($library->addconditions)) ? json_decode($library->addconditions,true):null;
if (ComponentbuilderHelper::checkArray($library->addconditions))
{
$library->conditions = array_values($library->addconditions);
}
}
// if this lib is always being added
else
{
}
unset($library->php_preparedocument);
unset($library->php_setdocument);
unset($library->addconditions);
}
else
{
$this->libraries[$id] = false;
}
}
// if set return
if (isset($this->libraries[$id]))
{
return $this->libraries[$id];
}
return false;
}
/**
* Set Language Place Holders
*
@ -3233,7 +3474,7 @@ class Get
}
/**
* Check for getModules script
* Check for get Google Chart script
*
* @param string $content The content to check
*

View File

@ -1048,83 +1048,92 @@ class Fields extends Structure
$fieldsSet = array();
foreach ($fieldAttributes as $property => $value)
{
if ($property != 'fields')
if ($property != 'fields' && $property != 'formsource')
{
$fieldSet .= PHP_EOL."\t\t\t" . $property . '="' . $value . '"';
}
}
$fieldSet .= ">";
$fieldSet .= PHP_EOL."\t\t\t" . '<form hidden="true" name="list_' . $fieldAttributes['name'] . '_modal" repeat="true">';
if (strpos($fieldAttributes['fields'], ',') !== false)
// if we detect formsource we do not add the form
if (isset($fieldAttributes['formsource']) && ComponentbuilderHelper::checkString($fieldAttributes['formsource']))
{
// mulitpal fields
$fieldsSets = (array) explode(',', $fieldAttributes['fields']);
$fieldSet .= PHP_EOL."\t\t\tformsource". '="' . $fieldAttributes['formsource'] . '"';
$fieldSet .= PHP_EOL."\t\t />";
}
elseif (is_numeric($fieldAttributes['fields']))
else
{
// single field
$fieldsSets[] = (int) $fieldAttributes['fields'];
}
// only continue if we have a field set
if (ComponentbuilderHelper::checkArray($fieldsSets))
{
foreach ($fieldsSets as $fieldId)
$fieldSet .= ">";
$fieldSet .= PHP_EOL."\t\t\t" . '<form hidden="true" name="list_' . $fieldAttributes['name'] . '_modal" repeat="true">';
if (strpos($fieldAttributes['fields'], ',') !== false)
{
// get the field data
$fieldData = array();
$fieldData['settings'] = $this->getFieldData($fieldId, $viewName);
if (ComponentbuilderHelper::checkObject($fieldData['settings']))
// mulitpal fields
$fieldsSets = (array) explode(',', $fieldAttributes['fields']);
}
elseif (is_numeric($fieldAttributes['fields']))
{
// single field
$fieldsSets[] = (int) $fieldAttributes['fields'];
}
// only continue if we have a field set
if (ComponentbuilderHelper::checkArray($fieldsSets))
{
foreach ($fieldsSets as $fieldId)
{
$r_name = ComponentbuilderHelper::safeString($fieldData['settings']->name);
$r_typeName = ComponentbuilderHelper::safeString($fieldData['settings']->type_name);
$r_multiple = false;
$r_langLabel = '';
// add the tabs needed
$taber = "\t\t";
// get field values
$r_fieldValues = $this->setFieldAttributes($fieldData, $view, $r_name, $r_typeName, $r_multiple, $r_langLabel, $langView, $spacerCounter, $listViewName, $viewName, $placeholders, true);
// check if values were set
if (ComponentbuilderHelper::checkArray($r_fieldValues))
// get the field data
$fieldData = array();
$fieldData['settings'] = $this->getFieldData($fieldId, $viewName);
if (ComponentbuilderHelper::checkObject($fieldData['settings']))
{
//reset options array
$r_optionArray = array();
if ($this->defaultField($r_typeName, 'option'))
$r_name = ComponentbuilderHelper::safeString($fieldData['settings']->name);
$r_typeName = ComponentbuilderHelper::safeString($fieldData['settings']->type_name);
$r_multiple = false;
$r_langLabel = '';
// add the tabs needed
$taber = "\t\t";
// get field values
$r_fieldValues = $this->setFieldAttributes($fieldData, $view, $r_name, $r_typeName, $r_multiple, $r_langLabel, $langView, $spacerCounter, $listViewName, $viewName, $placeholders, true);
// check if values were set
if (ComponentbuilderHelper::checkArray($r_fieldValues))
{
// now add to the field set
$fieldSet .= $this->setField('option', $taber, $r_fieldValues, $r_name, $r_typeName, $langView, $viewName, $listViewName, $placeholders, $r_optionArray);
}
elseif ($this->defaultField($r_typeName, 'plain'))
{
// now add to the field set
$fieldSet .= $this->setField('plain', $taber, $r_fieldValues, $r_name, $r_typeName, $langView, $viewName, $listViewName, $placeholders, $r_optionArray);
}
elseif (ComponentbuilderHelper::checkArray($r_fieldValues['custom']))
{
// add to custom
$custom = $r_fieldValues['custom'];
unset($r_fieldValues['custom']);
// now add to the field set
$fieldSet .= $this->setField('custom', $taber, $r_fieldValues, $r_name, $r_typeName, $langView, $viewName, $listViewName, $placeholders, $r_optionArray);
// set lang (just incase)
$r_listLangName = $langView . '_' . ComponentbuilderHelper::safeString($r_name, 'U');
// add to lang array
$this->langContent[$this->lang][$r_listLangName] = ComponentbuilderHelper::safeString($r_name, 'W');
// if label was set use instead
if (ComponentbuilderHelper::checkString($r_langLabel))
//reset options array
$r_optionArray = array();
if ($this->defaultField($r_typeName, 'option'))
{
$r_listLangName = $r_langLabel;
// now add to the field set
$fieldSet .= $this->setField('option', $taber, $r_fieldValues, $r_name, $r_typeName, $langView, $viewName, $listViewName, $placeholders, $r_optionArray);
}
elseif ($this->defaultField($r_typeName, 'plain'))
{
// now add to the field set
$fieldSet .= $this->setField('plain', $taber, $r_fieldValues, $r_name, $r_typeName, $langView, $viewName, $listViewName, $placeholders, $r_optionArray);
}
elseif (ComponentbuilderHelper::checkArray($r_fieldValues['custom']))
{
// add to custom
$custom = $r_fieldValues['custom'];
unset($r_fieldValues['custom']);
// now add to the field set
$fieldSet .= $this->setField('custom', $taber, $r_fieldValues, $r_name, $r_typeName, $langView, $viewName, $listViewName, $placeholders, $r_optionArray);
// set lang (just incase)
$r_listLangName = $langView . '_' . ComponentbuilderHelper::safeString($r_name, 'U');
// add to lang array
$this->langContent[$this->lang][$r_listLangName] = ComponentbuilderHelper::safeString($r_name, 'W');
// if label was set use instead
if (ComponentbuilderHelper::checkString($r_langLabel))
{
$r_listLangName = $r_langLabel;
}
// set the custom array
$data = array('type' => $r_typeName, 'code' => $r_name, 'lang' => $r_listLangName, 'custom' => $custom);
// set the custom field file
$this->setCustomFieldTypeFile($data, $listViewName, $viewName);
}
// set the custom array
$data = array('type' => $r_typeName, 'code' => $r_name, 'lang' => $r_listLangName, 'custom' => $custom);
// set the custom field file
$this->setCustomFieldTypeFile($data, $listViewName, $viewName);
}
}
}
}
$fieldSet .= PHP_EOL."\t\t\t</form>";
$fieldSet .= PHP_EOL."\t\t</field>";
}
$fieldSet .= PHP_EOL."\t\t\t</form>";
$fieldSet .= PHP_EOL."\t\t</field>";
}
}
elseif ($setType === 'custom')
@ -1419,7 +1428,7 @@ class Fields extends Structure
$name = $this->setPlaceholders($xmlValue, $placeholders);
}
}
elseif ($property['name'] === 'extension' || $property['name'] === 'directory')
elseif ($property['name'] === 'extension' || $property['name'] === 'directory' || $property['name'] === 'formsource')
{
$xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"');
// replace the placeholders