From 0deda0a71cbfe65cb39d33eae2df28190b1891dd Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sun, 11 Mar 2018 19:03:31 +0200 Subject: [PATCH] Fixed the the dynamic get compiler methods so that the getcustom/s custom PHP scripts gets added in the correct places, fixed gh-239 --- admin/compiler/joomla_3/JControllerLegacy.php | 2 +- admin/controller.php | 2 +- admin/helpers/compiler/a_Get.php | 72 ++++++++----------- admin/helpers/compiler/e_Interpretation.php | 36 +++++++++- 4 files changed, 64 insertions(+), 48 deletions(-) diff --git a/admin/compiler/joomla_3/JControllerLegacy.php b/admin/compiler/joomla_3/JControllerLegacy.php index 93888bf89..d6d5bf94f 100644 --- a/admin/compiler/joomla_3/JControllerLegacy.php +++ b/admin/compiler/joomla_3/JControllerLegacy.php @@ -53,7 +53,7 @@ class ###Component###Controller extends JControllerLegacy parent::__construct($config); } - + /** * display task * diff --git a/admin/controller.php b/admin/controller.php index b433701cf..18a17ee9a 100644 --- a/admin/controller.php +++ b/admin/controller.php @@ -50,7 +50,7 @@ class ComponentbuilderController extends JControllerLegacy parent::__construct($config); } - + /** * display task * diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 8ce7b27d1..e15975fc2 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -2464,55 +2464,39 @@ class Get { $result->php_calculation = $this->setDynamicValues(base64_decode($result->php_calculation)); } - // add php custom scripting (php_before_getitem) - if ($result->add_php_before_getitem == 1 && ComponentbuilderHelper::checkString($result->php_before_getitem)) + // The array of the php scripts that should be added to the script builder + $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 . '_' . $script][$view_code] .= $this->setDynamicValues(PHP_EOL . PHP_EOL . base64_decode($result->{$script})); + // remove from local item + unset($result->{$script}); + unset($result->{'add_'.$script}); + } + else + { + // only for custom gets + $result->{$script} = $this->setDynamicValues(PHP_EOL . base64_decode($result->{$script})); + } } - $this->customScriptBuilder[$this->target . '_php_before_getitem'][$view_code] .= $this->setDynamicValues(PHP_EOL . PHP_EOL . base64_decode($result->php_before_getitem)); - unset($result->php_before_getitem); - } - // add php custom scripting (php_after_getitem) - if ($result->add_php_after_getitem == 1 && ComponentbuilderHelper::checkString($result->php_after_getitem)) - { - if (!isset($this->customScriptBuilder[$this->target . '_php_after_getitem'][$view_code])) + else { - $this->customScriptBuilder[$this->target . '_php_after_getitem'][$view_code] = ''; + // remove from local item + unset($result->{$script}); + unset($result->{'add_'.$script}); } - $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) - if ($result->add_php_before_getitems == 1 && ComponentbuilderHelper::checkString($result->php_before_getitems)) - { - if (!isset($this->customScriptBuilder[$this->target . '_php_before_getitems'][$view_code])) - { - $this->customScriptBuilder[$this->target . '_php_before_getitems'][$view_code] = ''; - } - $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 $result->key = ComponentbuilderHelper::safeString($view_code . ' ' . $result->name . ' ' . $result->id); diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 50460e877..6c1d9e8e9 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -2169,8 +2169,16 @@ class Interpretation extends Fields { $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 - $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 . PHP_EOL . $tab . "\t\t//" . $this->setLine(__LINE__) . " Create a new query object."; $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); // setup the custom gets that returns multipal values $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 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); } if ($type === 'custom') @@ -2367,11 +2381,23 @@ class Interpretation extends Fields $main .= PHP_EOL . "\t\t}"; $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);"; + // 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### <<>> $main .= $this->setCustomViewListQuery($view, $view->code, false); // 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 . "\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 . PHP_EOL . "\t\tif (empty(\$items))"; $main .= PHP_EOL . "\t\t{"; @@ -2954,6 +2980,12 @@ class Interpretation extends Fields } $getItem .= PHP_EOL . "\t\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 if (strlen($getItem) <= 100) {