From f5c6fa899d148dec9d79b67985527380f8ddcf7a Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 2 Aug 2018 07:36:47 +0200 Subject: [PATCH] Added a fix to prefent language strings colliding on compilation. Added the option to use []+, in the custom code arg values. Added easy debug option for the setDynamicValues method in the compiler. Fixed the editor issue in the fields view. --- README.md | 4 +- admin/README.txt | 4 +- admin/compiler/joomla_3/Helper.php | 6 +- admin/compiler/joomla_3/Helper_site.php | 4 +- admin/helpers/compiler/a_Get.php | 126 ++++++++++++++++++-- admin/helpers/compiler/e_Interpretation.php | 11 +- admin/helpers/componentbuilder.php | 6 +- admin/models/field.php | 17 +++ admin/models/fields/aliasbuilder.php | 2 +- componentbuilder.xml | 2 +- site/helpers/componentbuilder.php | 4 +- 11 files changed, 154 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 12a34de6b..84b60c0d5 100644 --- a/README.md +++ b/README.md @@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *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*: 31st July, 2018 ++ *Last Build*: 2nd August, 2018 + *Version*: 2.8.5 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **186347** ++ *Line count*: **186364** + *Field count*: **1059** + *File count*: **1239** + *Folder count*: **197** diff --git a/admin/README.txt b/admin/README.txt index 12a34de6b..84b60c0d5 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *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*: 31st July, 2018 ++ *Last Build*: 2nd August, 2018 + *Version*: 2.8.5 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **186347** ++ *Line count*: **186364** + *Field count*: **1059** + *File count*: **1239** + *Folder count*: **197** diff --git a/admin/compiler/joomla_3/Helper.php b/admin/compiler/joomla_3/Helper.php index ec0a5c897..55458e6a6 100644 --- a/admin/compiler/joomla_3/Helper.php +++ b/admin/compiler/joomla_3/Helper.php @@ -763,10 +763,10 @@ 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 a type - if (isset($attributes['type'])) + // make sure we have attributes and a type value + if (self::checkArray($attributes) && isset($attributes['type'])) { // make sure the form helper class is loaded if (!method_exists('JFormHelper', 'loadFieldType')) diff --git a/admin/compiler/joomla_3/Helper_site.php b/admin/compiler/joomla_3/Helper_site.php index d405849de..2dbc8149c 100644 --- a/admin/compiler/joomla_3/Helper_site.php +++ b/admin/compiler/joomla_3/Helper_site.php @@ -411,8 +411,8 @@ abstract class ###Component###Helper */ public static function getFieldObject($attributes, $default = '', $options = null) { - // make sure we have a type - if (isset($attributes['type'])) + // make sure we have attributes and a type value + if (self::checkArray($attributes) && isset($attributes['type'])) { // make sure the form helper class is loaded if (!method_exists('JFormHelper', 'loadFieldType')) diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index ddcc9fe3d..b966f5339 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -74,6 +74,18 @@ class Get */ public $addPlaceholders = false; + /** + * The placeholders for custom code keys + * + * @var array + */ + protected $customCodeKeyPlacholders = array( + '[' => '[', + ']' => ']', + ',' => ',', + '+' => '+' + ); + /** * The Component data * @@ -2817,7 +2829,7 @@ class Get case 3: // set custom script $result->main_get[0]['selection'] = array( - 'select' => base64_decode($result->php_custom_get), + 'select' => $this->setDynamicValues(base64_decode($result->php_custom_get)), 'from' => '', 'table' => '', 'type' => ''); break; } @@ -3840,6 +3852,8 @@ class Get { $langOnly[] = ComponentbuilderHelper::getAllBetween($content, "JustTEXT:" . ":_('", "')"); $langOnly[] = ComponentbuilderHelper::getAllBetween($content, 'JustTEXT:' . ':_("', '")'); + // merge lang only + $langOnly = ComponentbuilderHelper::mergeArrays($langOnly); } // set language data foreach ($langStringTargets as $langStringTarget) @@ -3865,6 +3879,11 @@ class Get // load the language targets foreach ($langStringTargets as $langStringTarget) { + // need some special treatment here + if ($langStringTarget === 'JustTEXT:' . ':_(') + { + continue; + } $langHolders[$langStringTarget . "'" . $string . "'"] = $langStringTarget . "'" . $keyLang . "'"; $langHolders[$langStringTarget . '"' . $string . '"'] = $langStringTarget . '"' . $keyLang . '"'; } @@ -3874,7 +3893,6 @@ class Get // the uppercase loading only (for arrays and other tricks) if (ComponentbuilderHelper::checkArray($langOnly)) { - $langOnly = ComponentbuilderHelper::mergeArrays($langOnly); foreach ($langOnly as $string) { if ($keyLang = $this->setLang($string)) @@ -4331,15 +4349,23 @@ class Get * Set the dynamic values in strings here * * @param string $string The content to check + * @param int $debug The switch to debug the update + * We can now at any time debug the + * dynamic build values if it gets broken * * @return string * */ - public function setDynamicValues($string) + public function setDynamicValues($string, $debug = 0) { if (ComponentbuilderHelper::checkString($string)) { - return $this->setLangStrings($this->setCustomCodeData($this->setExternalCodeString($string))); + $string = $this->setLangStrings($this->setCustomCodeData($this->setExternalCodeString($string, $debug), $debug)); + } + // if debug + if ($debug) + { + jexit(); } return $string; } @@ -4348,15 +4374,22 @@ class Get * Set the external code string & load it in to string * * @param string $string The content to check + * @param int $debug The switch to debug the update * * @return string * */ - public function setExternalCodeString($string) + public function setExternalCodeString($string, $debug = 0) { // check if content has custom code place holder if (strpos($string, '[EXTERNA' . 'LCODE=') !== false) { + // if debug + if ($debug) + { + echo 'External Code String:'; + var_dump($string); + } // target content $bucket = array(); $found = ComponentbuilderHelper::getAllBetween($string, '[EXTERNA' . 'LCODE=', ']'); @@ -4402,6 +4435,12 @@ class Get $string = $this->setPlaceholders($string, $bucket); } } + // if debug + if ($debug) + { + echo 'External Code String After Update:'; + var_dump($string); + } } return $string; } @@ -4481,17 +4520,24 @@ class Get * We start set the custom code data & can load it in to string * * @param string $string The content to check + * @param int $debug The switch to debug the update * * @return string * */ - public function setCustomCodeData($string) + public function setCustomCodeData($string, $debug = 0) { // insure the code is loaded $loaded = false; // check if content has custom code place holder if (strpos($string, '[CUSTO' . 'MCODE=') !== false) { + // if debug + if ($debug) + { + echo 'Custom Code String:'; + var_dump($string); + } // the ids found in this content $bucket = array(); $found = ComponentbuilderHelper::getAllBetween($string, '[CUSTO' . 'MCODE=', ']'); @@ -4499,6 +4545,12 @@ class Get { foreach ($found as $key) { + // if debug + if ($debug) + { + echo '$key before update:'; + var_dump($key); + } // check if we have args if (is_numeric($key)) { @@ -4554,12 +4606,16 @@ class Get { if (strpos($array[1], ',') !== false) { - $this->customCodeData[$id]['args'][$key] = explode(',', $array[1]); + // update the function values with the custom code key placholdres (this allow the use of [] + and , in the values) + $this->customCodeData[$id]['args'][$key] = array_map(function($_key) { + return $this->setPlaceholders($_key, $this->customCodeKeyPlacholders); + }, (array) explode(',', $array[1])); } elseif (ComponentbuilderHelper::checkString($array[1])) { $this->customCodeData[$id]['args'][$key] = array(); - $this->customCodeData[$id]['args'][$key][] = $array[1]; + // update the function values with the custom code key placholdres (this allow the use of [] + and , in the values) + $this->customCodeData[$id]['args'][$key][] = $this->setPlaceholders($array[1], $this->customCodeKeyPlacholders); } } } @@ -4571,6 +4627,12 @@ class Get $bucket[$id] = $id; } } + // if debug + if ($debug) + { + echo 'Bucket:'; + var_dump($bucket); + } // check if any custom code placeholders where found if (ComponentbuilderHelper::checkArray($bucket)) { @@ -4582,10 +4644,22 @@ class Get // revert lang to current setting $this->lang = $_tmpLang; } + // if debug + if ($debug) + { + echo 'Loaded:'; + var_dump($loaded); + } // when the custom code is loaded if ($loaded === true) { - $string = $this->insertCustomCode($string); + $string = $this->insertCustomCode($string, $debug); + } + // if debug + if ($debug) + { + echo 'Custom Code String After Update:'; + var_dump($string); } } return $string; @@ -4595,16 +4669,31 @@ class Get * Insert the custom code into the string * * @param string $string The content to check + * @param int $debug The switch to debug the update * * @return string on success * */ - protected function insertCustomCode($string) + protected function insertCustomCode($string, $debug = 0) { $code = array(); + // if debug + if ($debug) + { + echo '$this->customCode:'; + var_dump($this->customCode); + } foreach ($this->customCode as $item) { - $this->buildCustomCodePlaceholders($item, $code); + $this->buildCustomCodePlaceholders($item, $code, $debug); + } + // if debug + if ($debug) + { + echo 'Place holders to Update String:'; + var_dump($code); + echo 'Custom Code String Before Update:'; + var_dump($string); } // now update the string return $this->setPlaceholders($string, $code); @@ -4614,21 +4703,34 @@ class Get * Insert the custom code into the string * * @param string $string The content to check + * @param int $debug The switch to debug the update * * @return string on success * */ - protected function buildCustomCodePlaceholders($item, &$code) + protected function buildCustomCodePlaceholders($item, &$code, $debug = 0) { // check if there is args for this code if (isset($this->customCodeData[$item['id']]['args']) && ComponentbuilderHelper::checkArray($this->customCodeData[$item['id']]['args'])) { // since we have args we cant update this code via IDE (TODO) $placeholder = $this->getPlaceHolder(3, null); + // if debug + if ($debug) + { + echo 'Custom Code Placeholders:'; + var_dump($placeholder); + } // we have args and so need to load each foreach ($this->customCodeData[$item['id']]['args'] as $key => $args) { $this->setThesePlaceHolders('arg', $args); + // if debug + if ($debug) + { + echo 'Custom Code Global Placholders:'; + var_dump($this->placeholders); + } $code['[CUSTOM' . 'CODE=' . $key . ']'] = $placeholder['start'] . PHP_EOL . $this->setPlaceholders($item['code'], $this->placeholders) . $placeholder['end']; } // always clear the args diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 3ee87f583..45e162028 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -1578,16 +1578,19 @@ class Interpretation extends Fields { // load this unuiqe key $this->customViewQueryChecker[$this->target][] = $checker; - if (ComponentbuilderHelper::checkString($the_get['selection']['type'])) + if (isset($the_get['selection']['type']) && ComponentbuilderHelper::checkString($the_get['selection']['type'])) { $getItem = PHP_EOL . PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . "//" . $this->setLine(__LINE__) . " Get from " . $the_get['selection']['table'] . " as " . $the_get['as']; + // set the selection + $getItem .= PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . $the_get['selection']['select']; } else { $getItem = PHP_EOL . PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . "//" . $this->setLine(__LINE__) . " Get data"; + // set the selection + $getItem .= PHP_EOL . $this->setPlaceholders($the_get['selection']['select'], $this->placeholders); } - // set the selection - $getItem .= PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . $the_get['selection']['select']; + // load the from selection if (($nr == 0 && (!isset($the_get['join_field']) || !ComponentbuilderHelper::checkString($the_get['join_field'])) && (isset($the_get['selection']['type']) && ComponentbuilderHelper::checkString($the_get['selection']['type']))) || ($type === 'custom' && (isset($the_get['selection']['type']) && ComponentbuilderHelper::checkString($the_get['selection']['type'])))) { @@ -5108,7 +5111,7 @@ class Interpretation extends Fields { foreach ($viewArray['settings']->main_get->main_get as $get) { - if ($get['as'] === 'a') + if (isset($get['as']) && $get['as'] === 'a') { if (isset($get['selection']) && ComponentbuilderHelper::checkArray($get['selection']) && isset($get['selection']['select_gets']) && ComponentbuilderHelper::checkArray($get['selection']['select_gets'])) { diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 111411a7d..a615821dc 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -4741,10 +4741,10 @@ abstract class ComponentbuilderHelper * @return object * */ - public static function getFieldObject($attributes, $default = '', $options = null) + public static function getFieldObject(&$attributes, $default = '', $options = null) { - // make sure we have a type - if (isset($attributes['type'])) + // make sure we have attributes and a type value + if (self::checkArray($attributes) && isset($attributes['type'])) { // make sure the form helper class is loaded if (!method_exists('JFormHelper', 'loadFieldType')) diff --git a/admin/models/field.php b/admin/models/field.php index 1c8789469..b7cdf238b 100644 --- a/admin/models/field.php +++ b/admin/models/field.php @@ -231,6 +231,23 @@ class ComponentbuilderModelField extends JModelAdmin $form->setValue($redirectedField, null, $redirectedValue); } } + + // update all editors to use this components global editor + $global_editor = JComponentHelper::getParams('com_componentbuilder')->get('editor', 'none'); + // now get all the editor fields + $editors = $form->getXml()->xpath("//field[@type='editor']"); + // check if we found any + if (ComponentbuilderHelper::checkArray($editors)) + { + foreach ($editors as $editor) + { + // get the field names + $name = (string) $editor['name']; + // set the field editor value (with none as fallback) + $form->setFieldAttribute($name, 'editor', $global_editor . '|none'); + } + } + return $form; } diff --git a/admin/models/fields/aliasbuilder.php b/admin/models/fields/aliasbuilder.php index b5ca7834d..daf9124aa 100644 --- a/admin/models/fields/aliasbuilder.php +++ b/admin/models/fields/aliasbuilder.php @@ -35,7 +35,7 @@ class JFormFieldAliasbuilder extends JFormFieldList */ public function getOptions() { - // load the db opbject + // load the db object $db = JFactory::getDBO(); // get the input from url $jinput = JFactory::getApplication()->input; diff --git a/componentbuilder.xml b/componentbuilder.xml index 2592174c9..47e28242e 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 31st July, 2018 + 2nd August, 2018 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index fa5d434c2..f5b5dbd83 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -4029,8 +4029,8 @@ abstract class ComponentbuilderHelper */ public static function getFieldObject($attributes, $default = '', $options = null) { - // make sure we have a type - if (isset($attributes['type'])) + // make sure we have attributes and a type value + if (self::checkArray($attributes) && isset($attributes['type'])) { // make sure the form helper class is loaded if (!method_exists('JFormHelper', 'loadFieldType'))