Fixed the the dynamic get compiler methods so that the getcustom/s custom PHP scripts gets added in the correct places, fixed gh-239

This commit is contained in:
Llewellyn van der Merwe 2018-03-11 19:03:31 +02:00
parent 1991a46689
commit 0deda0a71c
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
4 changed files with 64 additions and 48 deletions

View File

@ -2464,55 +2464,39 @@ class Get
{ {
$result->php_calculation = $this->setDynamicValues(base64_decode($result->php_calculation)); $result->php_calculation = $this->setDynamicValues(base64_decode($result->php_calculation));
} }
// add php custom scripting (php_before_getitem) // The array of the php scripts that should be added to the script builder
if ($result->add_php_before_getitem == 1 && ComponentbuilderHelper::checkString($result->php_before_getitem)) $phpSripts = array('php_before_getitem', 'php_after_getitem', 'php_before_getitems', 'php_after_getitems', 'php_getlistquery');
// load the php scripts
foreach ($phpSripts as $script)
{ {
if (!isset($this->customScriptBuilder[$this->target . '_php_before_getitem'][$view_code])) // add php script to the script builder
if (isset($result->{'add_'.$script}) && $result->{'add_'.$script} == 1
&& isset($result->{$script}) && ComponentbuilderHelper::checkString($result->{$script}))
{ {
$this->customScriptBuilder[$this->target . '_php_before_getitem'][$view_code] = ''; // move all main gets out to the customscript builder
if ($result->gettype <= 2)
{
if (!isset($this->customScriptBuilder[$this->target . '_' . $script][$view_code]))
{
$this->customScriptBuilder[$this->target . '_' . $script][$view_code] = '';
} }
$this->customScriptBuilder[$this->target . '_php_before_getitem'][$view_code] .= $this->setDynamicValues(PHP_EOL . PHP_EOL . base64_decode($result->php_before_getitem)); $this->customScriptBuilder[$this->target . '_' . $script][$view_code] .= $this->setDynamicValues(PHP_EOL . PHP_EOL . base64_decode($result->{$script}));
unset($result->php_before_getitem); // remove from local item
unset($result->{$script});
unset($result->{'add_'.$script});
} }
// add php custom scripting (php_after_getitem) else
if ($result->add_php_after_getitem == 1 && ComponentbuilderHelper::checkString($result->php_after_getitem))
{ {
if (!isset($this->customScriptBuilder[$this->target . '_php_after_getitem'][$view_code])) // only for custom gets
{ $result->{$script} = $this->setDynamicValues(PHP_EOL . base64_decode($result->{$script}));
$this->customScriptBuilder[$this->target . '_php_after_getitem'][$view_code] = '';
} }
$this->customScriptBuilder[$this->target . '_php_after_getitem'][$view_code] .= $this->setDynamicValues(PHP_EOL . PHP_EOL . base64_decode($result->php_after_getitem));
unset($result->php_after_getitem);
} }
// add php custom scripting (php_before_getitems) else
if ($result->add_php_before_getitems == 1 && ComponentbuilderHelper::checkString($result->php_before_getitems))
{ {
if (!isset($this->customScriptBuilder[$this->target . '_php_before_getitems'][$view_code])) // remove from local item
{ unset($result->{$script});
$this->customScriptBuilder[$this->target . '_php_before_getitems'][$view_code] = ''; unset($result->{'add_'.$script});
} }
$this->customScriptBuilder[$this->target . '_php_before_getitems'][$view_code] .= $this->setDynamicValues(PHP_EOL . PHP_EOL . base64_decode($result->php_before_getitems));
unset($result->php_before_getitems);
}
// add php custom scripting (php_after_getitems)
if ($result->add_php_after_getitems == 1 && ComponentbuilderHelper::checkString($result->php_after_getitems))
{
if (!isset($this->customScriptBuilder[$this->target . '_php_after_getitems'][$view_code]))
{
$this->customScriptBuilder[$this->target . '_php_after_getitems'][$view_code] = '';
}
$this->customScriptBuilder[$this->target . '_php_after_getitems'][$view_code] .= $this->setDynamicValues(PHP_EOL . PHP_EOL . base64_decode($result->php_after_getitems));
unset($result->php_after_getitems);
}
// add php custom scripting (php_getlistquery)
if ($result->add_php_getlistquery == 1 && ComponentbuilderHelper::checkString($result->php_getlistquery))
{
if (!isset($this->customScriptBuilder[$this->target . '_php_getlistquery'][$view_code]))
{
$this->customScriptBuilder[$this->target . '_php_getlistquery'][$view_code] = '';
}
$this->customScriptBuilder[$this->target . '_php_getlistquery'][$view_code] .= $this->setDynamicValues(PHP_EOL . base64_decode($result->php_getlistquery));
unset($result->php_getlistquery);
} }
// set the getmethod code name // set the getmethod code name
$result->key = ComponentbuilderHelper::safeString($view_code . ' ' . $result->name . ' ' . $result->id); $result->key = ComponentbuilderHelper::safeString($view_code . ' ' . $result->name . ' ' . $result->id);

View File

@ -2169,8 +2169,16 @@ class Interpretation extends Fields
{ {
$this->siteDecrypt[$cryptionType][$code] = false; $this->siteDecrypt[$cryptionType][$code] = false;
} }
// start the get Item
$getItem = '';
// set before item php
if (isset($get->add_php_before_getitem) && $get->add_php_before_getitem == 1
&& isset($get->php_before_getitem) && ComponentbuilderHelper::checkString($get->php_before_getitem))
{
$getItem .= $this->setPlaceholders($get->php_before_getitem, $this->placeholders);
}
// start loadin the get Item // start loadin the get Item
$getItem = PHP_EOL . "\t" . $tab . "\t//" . $this->setLine(__LINE__) . " Get a db connection."; $getItem .= PHP_EOL . "\t" . $tab . "\t//" . $this->setLine(__LINE__) . " Get a db connection.";
$getItem .= PHP_EOL . "\t" . $tab . "\t\$db = JFactory::getDbo();"; $getItem .= PHP_EOL . "\t" . $tab . "\t\$db = JFactory::getDbo();";
$getItem .= PHP_EOL . PHP_EOL . $tab . "\t\t//" . $this->setLine(__LINE__) . " Create a new query object."; $getItem .= PHP_EOL . PHP_EOL . $tab . "\t\t//" . $this->setLine(__LINE__) . " Create a new query object.";
$getItem .= PHP_EOL . "\t" . $tab . "\t\$query = \$db->getQuery(true);"; $getItem .= PHP_EOL . "\t" . $tab . "\t\$query = \$db->getQuery(true);";
@ -2290,10 +2298,16 @@ class Interpretation extends Fields
$getItem .= $this->setCustomViewGlobals($get->global, '$data', $asBucket, $tab); $getItem .= $this->setCustomViewGlobals($get->global, '$data', $asBucket, $tab);
// setup the custom gets that returns multipal values // setup the custom gets that returns multipal values
$getItem .= $this->setCustomViewCustomJoin($get->custom_get, '$data', $code, $asBucket, $tab); $getItem .= $this->setCustomViewCustomJoin($get->custom_get, '$data', $code, $asBucket, $tab);
// set after item php
if (isset($get->add_php_after_getitem) && $get->add_php_after_getitem == 1
&& isset($get->php_after_getitem) && ComponentbuilderHelper::checkString($get->php_after_getitem))
{
$getItem .= $this->setPlaceholders($get->php_after_getitem, $this->placeholders);
}
// set calculations // set calculations
if ($get->addcalculation == 1) if ($get->addcalculation == 1)
{ {
$get->php_calculation = (array) explode(PHP_EOL, $get->php_calculation); $get->php_calculation = (array) explode(PHP_EOL, $this->setPlaceholders($get->php_calculation, $this->placeholders));
$getItem .= PHP_EOL . "\t" . $tab . "\t" . implode(PHP_EOL . "\t" . $tab . "\t", $get->php_calculation); $getItem .= PHP_EOL . "\t" . $tab . "\t" . implode(PHP_EOL . "\t" . $tab . "\t", $get->php_calculation);
} }
if ($type === 'custom') if ($type === 'custom')
@ -2367,11 +2381,23 @@ class Interpretation extends Fields
$main .= PHP_EOL . "\t\t}"; $main .= PHP_EOL . "\t\t}";
$main .= PHP_EOL . PHP_EOL . "\t\t//" . $this->setLine(__LINE__) . " Get the global params"; $main .= PHP_EOL . PHP_EOL . "\t\t//" . $this->setLine(__LINE__) . " Get the global params";
$main .= PHP_EOL . "\t\t\$globalParams = JComponentHelper::getParams('com_" . $this->fileContentStatic['###component###'] . "', true);"; $main .= PHP_EOL . "\t\t\$globalParams = JComponentHelper::getParams('com_" . $this->fileContentStatic['###component###'] . "', true);";
// set php before listquery
if (isset($view->add_php_getlistquery) && $view->add_php_getlistquery == 1
&& isset($view->php_getlistquery) && ComponentbuilderHelper::checkString($view->php_getlistquery))
{
$main .= $this->setPlaceholders($view->php_getlistquery, $this->placeholders);
}
// ###SITE_GET_LIST_QUERY### <<<DYNAMIC>>> // ###SITE_GET_LIST_QUERY### <<<DYNAMIC>>>
$main .= $this->setCustomViewListQuery($view, $view->code, false); $main .= $this->setCustomViewListQuery($view, $view->code, false);
// load the object list // load the object list
$main .= PHP_EOL . PHP_EOL . "\t\t//" . $this->setLine(__LINE__) . " Reset the query using our newly populated query object."; $main .= PHP_EOL . PHP_EOL . "\t\t//" . $this->setLine(__LINE__) . " Reset the query using our newly populated query object.";
$main .= PHP_EOL . "\t\t\$db->setQuery(\$query);"; $main .= PHP_EOL . "\t\t\$db->setQuery(\$query);";
// set before items php
if (isset($view->add_php_before_getitems) && $view->add_php_before_getitems == 1
&& isset($view->php_before_getitems) && ComponentbuilderHelper::checkString($view->php_before_getitems))
{
$main .= $this->setPlaceholders($view->php_before_getitems, $this->placeholders);
}
$main .= PHP_EOL . "\t\t\$items = \$db->loadObjectList();"; $main .= PHP_EOL . "\t\t\$items = \$db->loadObjectList();";
$main .= PHP_EOL . PHP_EOL . "\t\tif (empty(\$items))"; $main .= PHP_EOL . PHP_EOL . "\t\tif (empty(\$items))";
$main .= PHP_EOL . "\t\t{"; $main .= PHP_EOL . "\t\t{";
@ -2954,6 +2980,12 @@ class Interpretation extends Fields
} }
$getItem .= PHP_EOL . "\t\t\t}"; $getItem .= PHP_EOL . "\t\t\t}";
$getItem .= PHP_EOL . "\t\t}"; $getItem .= PHP_EOL . "\t\t}";
// set after items php
if (isset($get->add_php_after_getitems) && $get->add_php_after_getitems == 1
&& isset($get->php_after_getitems) && ComponentbuilderHelper::checkString($get->php_after_getitems))
{
$getItem .= $this->setPlaceholders($get->php_after_getitems, $this->placeholders);
}
// remove empty foreach // remove empty foreach
if (strlen($getItem) <= 100) if (strlen($getItem) <= 100)
{ {