From abe9b5d227d15d65cd369bef075cec35028cfaed Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Wed, 31 Aug 2022 13:49:01 +0200 Subject: [PATCH] Adds the customcode dispencer class --- README.md | 6 +- admin/README.txt | 6 +- admin/helpers/compiler/a_Get.php | 340 ++++++------------ admin/helpers/compiler/b_Structure.php | 4 +- admin/helpers/compiler/e_Interpretation.php | 104 +++--- admin/helpers/compiler/f_Infusion.php | 68 ++-- componentbuilder.xml | 2 +- .../Compiler/Customcode/Dispenser.php | 283 +++++++++++++++ .../Compiler/Customcode/Hash.php | 110 ++++++ .../Compiler/Customcode/LockBase.php | 85 +++++ .../Compiler/Service/Customcode.php | 61 ++++ 11 files changed, 739 insertions(+), 330 deletions(-) create mode 100644 libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/Dispenser.php create mode 100644 libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/Hash.php create mode 100644 libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/LockBase.php diff --git a/README.md b/README.md index 84cd3b690..6f5a0b002 100644 --- a/README.md +++ b/README.md @@ -140,13 +140,13 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 30th August, 2022 ++ *Last Build*: 31st August, 2022 + *Version*: 3.1.5 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **319334** ++ *Line count*: **319873** + *Field count*: **2002** -+ *File count*: **2087** ++ *File count*: **2090** + *Folder count*: **359** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). diff --git a/admin/README.txt b/admin/README.txt index 84cd3b690..6f5a0b002 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -140,13 +140,13 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 30th August, 2022 ++ *Last Build*: 31st August, 2022 + *Version*: 3.1.5 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **319334** ++ *Line count*: **319873** + *Field count*: **2002** -+ *File count*: **2087** ++ *File count*: **2090** + *Folder count*: **359** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 5da9bf912..bafeb57cf 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -648,6 +648,7 @@ class Get * The Custom Script Builder * * @var array + * @deprecated 3.3 Use CFactory::_('Customcode.Dispenser')->hub; */ public $customScriptBuilder = array(); @@ -1716,17 +1717,17 @@ class Get // add_javascript if ($component->add_javascript == 1) { - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->javascript, 'component_js', - false, - false, + null, + null, $guiMapper ); } else { - $this->customScriptBuilder['component_js'] = ''; + CFactory::_('Customcode.Dispenser')->hub['component_js'] = ''; } unset($component->javascript); @@ -1742,14 +1743,14 @@ class Get $component->{'css_' . $area} )) { - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->{'css_' . $area}, 'component_css_' . $area ); } else { - $this->customScriptBuilder['component_css_' . $area] = ''; + CFactory::_('Customcode.Dispenser')->hub['component_css_' . $area] = ''; } unset($component->{'css_' . $area}); } @@ -1776,17 +1777,17 @@ class Get { // set GUI mapper field $guiMapper['field'] = $scriptMethod . '_' . $scriptType; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->{$scriptMethod . '_' . $scriptType}, $scriptMethod, $scriptType, - false, + null, $guiMapper ); } else { - $this->customScriptBuilder[$scriptMethod][$scriptType] = ''; + CFactory::_('Customcode.Dispenser')->hub[$scriptMethod][$scriptType] = ''; } unset($component->{$scriptMethod . '_' . $scriptType}); } @@ -1801,18 +1802,18 @@ class Get // update GUI mapper $guiMapper['field'] = 'php_helper_admin'; $guiMapper['prefix'] = PHP_EOL . PHP_EOL; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->php_helper_admin, 'component_php_helper_admin', - false, - false, + null, + null, $guiMapper ); unset($guiMapper['prefix']); } else { - $this->customScriptBuilder['component_php_helper_admin'] = ''; + CFactory::_('Customcode.Dispenser')->hub['component_php_helper_admin'] = ''; } unset($component->php_helper); // add_admin_event @@ -1822,17 +1823,17 @@ class Get CFactory::_('Config')->lang_target = 'admin'; // update GUI mapper field $guiMapper['field'] = 'php_admin_event'; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->php_admin_event, 'component_php_admin_event', - false, - false, + null, + null, $guiMapper ); } else { - $this->customScriptBuilder['component_php_admin_event'] = ''; + CFactory::_('Customcode.Dispenser')->hub['component_php_admin_event'] = ''; } unset($component->php_admin_event); // add_php_helper_both @@ -1843,18 +1844,18 @@ class Get // update GUI mapper field $guiMapper['field'] = 'php_helper_both'; $guiMapper['prefix'] = PHP_EOL . PHP_EOL; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->php_helper_both, 'component_php_helper_both', - false, - false, + null, + null, $guiMapper ); unset($guiMapper['prefix']); } else { - $this->customScriptBuilder['component_php_helper_both'] = ''; + CFactory::_('Customcode.Dispenser')->hub['component_php_helper_both'] = ''; } // add_php_helper_site if ($component->add_php_helper_site == 1 @@ -1864,18 +1865,18 @@ class Get // update GUI mapper field $guiMapper['field'] = 'php_helper_site'; $guiMapper['prefix'] = PHP_EOL . PHP_EOL; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->php_helper_site, 'component_php_helper_site', - false, - false, + null, + null, $guiMapper ); unset($guiMapper['prefix']); } else { - $this->customScriptBuilder['component_php_helper_site'] = ''; + CFactory::_('Customcode.Dispenser')->hub['component_php_helper_site'] = ''; } unset($component->php_helper); // add_site_event @@ -1885,23 +1886,23 @@ class Get CFactory::_('Config')->lang_target = 'site'; // update GUI mapper field $guiMapper['field'] = 'php_site_event'; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->php_site_event, 'component_php_site_event', - false, - false, + null, + null, $guiMapper ); } else { - $this->customScriptBuilder['component_php_site_event'] = ''; + CFactory::_('Customcode.Dispenser')->hub['component_php_site_event'] = ''; } unset($component->php_site_event); // add_sql if ($component->add_sql == 1) { - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->sql, 'sql', 'component_sql' @@ -1911,7 +1912,7 @@ class Get // add_sql_uninstall if ($component->add_sql_uninstall == 1) { - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $component->sql_uninstall, 'sql_uninstall' ); @@ -2259,13 +2260,13 @@ class Get ); // setup token check - if (!isset($this->customScriptBuilder['token'])) + if (!isset(CFactory::_('Customcode.Dispenser')->hub['token'])) { - $this->customScriptBuilder['token'] = array(); + CFactory::_('Customcode.Dispenser')->hub['token'] = []; } - $this->customScriptBuilder['token'][$view->name_single_code] + CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_single_code] = false; - $this->customScriptBuilder['token'][$view->name_list_code] = false; + CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_list_code] = false; // set some placeholders CFactory::_('Placeholder')->active[Placefix::_h('view')] = $view->name_single_code; @@ -2940,11 +2941,11 @@ class Get ); // update GUI mapper field $guiMapper['field'] = $scripter; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $view->{$scripter}, $scripter_target, $view->name_single_code, - false, + null, $guiMapper, true, true, @@ -2956,9 +2957,9 @@ class Get $view->$scripter, "task=ajax" ) !== false) { - if (!$this->customScriptBuilder['token'][$view->name_single_code]) + if (!CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_single_code]) { - $this->customScriptBuilder['token'][$view->name_single_code] + CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_single_code] = true; } } @@ -2974,11 +2975,11 @@ class Get && $view->{'add_' . $scripter} == 1 && StringHelper::check($view->{$scripter})) { - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $view->{$scripter}, $scripter, $view->name_single_code, - false, + null, array('prefix' => PHP_EOL), true, true, @@ -3006,11 +3007,11 @@ class Get { // update GUI mapper field $guiMapper['field'] = $scripter; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $view->{$scripter}, $scripter, $view->name_single_code, - false, + null, $guiMapper ); @@ -3089,11 +3090,11 @@ class Get { $guiMapper['type'] = 'html'; } - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $view->$importScripter, $importScripter, 'import_' . $view->name_list_code, - false, + null, $guiMapper ); unset($view->$importScripter); @@ -3101,7 +3102,7 @@ class Get else { // load the default - $this->customScriptBuilder[$importScripter]['import_' + CFactory::_('Customcode.Dispenser')->hub[$importScripter]['import_' . $view->name_list_code] = ComponentbuilderHelper::getDynamicScripts( $importScripter, true @@ -3113,7 +3114,7 @@ class Get if (isset($view->add_php_ajax) && $view->add_php_ajax == 1) { // insure the token is added to edit view atleast - $this->customScriptBuilder['token'][$view->name_single_code] + CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_single_code] = true; $addAjaxSite = false; if (isset($this->siteEditView[$id]) && $this->siteEditView[$id]) @@ -3133,10 +3134,10 @@ class Get { if ($addAjaxSite) { - $this->customScriptBuilder['site']['ajax_controller'][$view->name_single_code] + CFactory::_('Customcode.Dispenser')->hub['site']['ajax_controller'][$view->name_single_code] = array_values($view->ajax_input); } - $this->customScriptBuilder['admin']['ajax_controller'][$view->name_single_code] + CFactory::_('Customcode.Dispenser')->hub['admin']['ajax_controller'][$view->name_single_code] = array_values($view->ajax_input); $this->addAjax = true; unset($view->ajax_input); @@ -3147,7 +3148,7 @@ class Get $guiMapper['type'] = 'php'; // update GUI mapper field $guiMapper['field'] = 'php_ajaxmethod'; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $view->php_ajaxmethod, 'admin', 'ajax_model', @@ -3157,7 +3158,7 @@ class Get if ($addAjaxSite) { - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $view->php_ajaxmethod, 'site', 'ajax_model', @@ -3215,7 +3216,7 @@ class Get if ($view->source == 1 && isset($view->tables)) { // build and add the SQL dump - $this->customScriptBuilder['sql'][$view->name_single_code] + CFactory::_('Customcode.Dispenser')->hub['sql'][$view->name_single_code] = $this->buildSqlDump( $view->tables, $view->name_single_code, $id ); @@ -3224,7 +3225,7 @@ class Get elseif ($view->source == 2 && isset($view->sql)) { // add the SQL dump string - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $view->sql, 'sql', $view->name_single_code @@ -3577,7 +3578,7 @@ class Get ? json_decode($view->ajax_input, true) : null; if (ArrayHelper::check($view->ajax_input)) { - $this->customScriptBuilder[$target]['ajax_controller'][$view->code] + CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_controller'][$view->code] = array_values($view->ajax_input); $setAjax = true; } @@ -3587,7 +3588,7 @@ class Get { // set field $guiMapper['field'] = 'php_ajaxmethod'; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $view->php_ajaxmethod, $target, 'ajax_model', @@ -3931,11 +3932,11 @@ class Get { $convert__ = false; } - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $this->_fieldData[$id]->javascript_view_footer, 'view_footer', $name_single, - false, + null, array( 'table' => 'field', 'id' => (int) $id, @@ -3960,14 +3961,14 @@ class Get "task=ajax" ) !== false) { - if (!isset($this->customScriptBuilder['token'])) + if (!isset(CFactory::_('Customcode.Dispenser')->hub['token'])) { - $this->customScriptBuilder['token'] = array(); + CFactory::_('Customcode.Dispenser')->hub['token'] = []; } - if (!isset($this->customScriptBuilder['token'][$name_single]) - || !$this->customScriptBuilder['token'][$name_single]) + if (!isset(CFactory::_('Customcode.Dispenser')->hub['token'][$name_single]) + || !CFactory::_('Customcode.Dispenser')->hub['token'][$name_single]) { - $this->customScriptBuilder['token'][$name_single] + CFactory::_('Customcode.Dispenser')->hub['token'][$name_single] = true; } } @@ -3982,11 +3983,11 @@ class Get { $convert__ = false; } - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $this->_fieldData[$id]->css_view, 'css_view', $name_single, - false, + null, array('prefix' => PHP_EOL), $convert__, $convert__, @@ -4014,11 +4015,11 @@ class Get { $convert__ = false; } - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $this->_fieldData[$id]->javascript_views_footer, 'views_footer', $name_single, - false, + null, array( 'table' => 'field', 'id' => (int) $id, @@ -4043,14 +4044,14 @@ class Get "task=ajax" ) !== false) { - if (!isset($this->customScriptBuilder['token'])) + if (!isset(CFactory::_('Customcode.Dispenser')->hub['token'])) { - $this->customScriptBuilder['token'] = array(); + CFactory::_('Customcode.Dispenser')->hub['token'] = []; } - if (!isset($this->customScriptBuilder['token'][$name_list]) - || !$this->customScriptBuilder['token'][$name_list]) + if (!isset(CFactory::_('Customcode.Dispenser')->hub['token'][$name_list]) + || !CFactory::_('Customcode.Dispenser')->hub['token'][$name_list]) { - $this->customScriptBuilder['token'][$name_list] + CFactory::_('Customcode.Dispenser')->hub['token'][$name_list] = true; } } @@ -4064,11 +4065,11 @@ class Get { $convert__ = false; } - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $this->_fieldData[$id]->css_views, 'css_views', $name_single, - false, + null, array('prefix' => PHP_EOL), $convert__, $convert__, @@ -4668,11 +4669,11 @@ class Get // set GUI mapper field $guiMapper['field'] = $script; $guiMapper['prefix'] = PHP_EOL . PHP_EOL; - $this->setCustomScriptBuilder( + CFactory::_('Customcode.Dispenser')->set( $result->{$script}, CFactory::_('Config')->build_target . '_' . $script, $view_code, - false, + null, $guiMapper, true, true, @@ -5131,135 +5132,35 @@ class Get } /** - * set the script for the custom script builder + * Set the script for the customcode dispenser * - * @param string $script The script - * @param string $first The first key - * @param string $second The second key (if not set we use only first key) - * @param string $third The third key (if not set we use only first and second key) - * @param array $config The config options - * @param bool $base64 The switch to decode base64 the script - * default: true - * @param bool $dynamic The switch to dynamic update the script - * default: true - * @param bool $add The switch to add to exiting instead of replace - * default: false - * - * @return boolean true on success + * @param string $script The script + * @param string $first The first key + * @param string|null $second The second key (if not set we use only first key) + * @param string|null $third The third key (if not set we use only first and second key) + * @param array $config The config options + * @param bool $base64 The switch to decode base64 the script + * default: true + * @param bool $dynamic The switch to dynamic update the script + * default: true + * @param bool $add The switch to add to exiting instead of replace + * default: false * + * @return bool true on success + * @deprecated 3.3 Use CFactory::_('Customcode.Dispenser')->set($script, $first, $second, $third, $config, $base64, $dynamic, $add); */ - public function setCustomScriptBuilder(&$script, $first, $second = false, - $third = false, $config = array(), $base64 = true, $dynamic = true, - $add = false - ) + public function setCustomScriptBuilder( + &$script, + string $first, + ?string $second = null, + ?string $third = null, + array $config = array(), + bool $base64 = true, + bool $dynamic = true, + bool $add = false + ): bool { - // only load if we have a string - if (!StringHelper::check($script)) - { - return false; - } - // this needs refactoring (TODO) - if (!isset($this->customScriptBuilder[$first]) - || ($second - && !isset($this->customScriptBuilder[$first][$second]))) - { - // check if the script first key is set - if ($second && !isset($this->customScriptBuilder[$first])) - { - $this->customScriptBuilder[$first] = array(); - } - elseif ($add && !$second - && !isset($this->customScriptBuilder[$first])) - { - $this->customScriptBuilder[$first] = ''; - } - // check if the script second key is set - if ($second && $third - && !isset($this->customScriptBuilder[$first][$second])) - { - $this->customScriptBuilder[$first][$second] = array(); - } - elseif ($add && $second && !$third - && !isset($this->customScriptBuilder[$first][$second])) - { - $this->customScriptBuilder[$first][$second] = ''; - } - // check if the script third key is set - if ($add && $second && $third - && !isset($this->customScriptBuilder[$first][$second][$third])) - { - $this->customScriptBuilder[$first][$second][$third] = ''; - } - } - // prep the script string - if ($base64 && $dynamic) - { - $script = CFactory::_('Customcode')->add(base64_decode($script)); - } - elseif ($base64) - { - $script = base64_decode($script); - } - elseif ($dynamic) // this does not happen (just incase) - { - $script = CFactory::_('Customcode')->add($script); - } - // check if we still have a string - if (StringHelper::check($script)) - { - // now load the placeholder snippet if needed - if ($base64 || $dynamic) - { - $script = CFactory::_('Customcode.Gui')->set($script, $config); - } - // add Dynamic HASHING option of a file/string - $script = $this->setDynamicHASHING($script); - // add base64 locking option of a string - $script = $this->setBase64LOCK($script); - // load the script - if ($first && $second && $third) - { - // now act on loading option - if ($add) - { - $this->customScriptBuilder[$first][$second][$third] - .= $script; - } - else - { - $this->customScriptBuilder[$first][$second][$third] - = $script; - } - } - elseif ($first && $second) - { - // now act on loading option - if ($add) - { - $this->customScriptBuilder[$first][$second] .= $script; - } - else - { - $this->customScriptBuilder[$first][$second] = $script; - } - } - else - { - // now act on loading option - if ($add) - { - $this->customScriptBuilder[$first] .= $script; - } - else - { - $this->customScriptBuilder[$first] = $script; - } - } - - return true; - } - - return false; + return CFactory::_('Customcode.Dispenser')->set($script, $first, $second, $third, $config, $base64, $dynamic, $add); } /** @@ -5274,44 +5175,13 @@ class Get * @param string $sufix The sufix to add after the script if found * * @return mix The string/script if found or the default value if not found - * + * @deprecated 3.3 Use CFactory::_('Customcode.Dispenser')->get($first, $second, $prefix, $note, $unset, $default, $sufix); */ public function getCustomScriptBuilder($first, $second, $prefix = '', $note = null, $unset = null, $default = null, $sufix = '' ) { - // default is to return an empty string - $script = ''; - // check if there is any custom script - if (isset($this->customScriptBuilder[$first][$second]) - && StringHelper::check( - $this->customScriptBuilder[$first][$second] - )) - { - // add not if set - if ($note) - { - $script .= $note; - } - // load the actual script - $script .= $prefix . str_replace( - array_keys(CFactory::_('Placeholder')->active), - array_values(CFactory::_('Placeholder')->active), - $this->customScriptBuilder[$first][$second] - ) . $sufix; - // clear some memory - if ($unset) - { - unset($this->customScriptBuilder[$first][$second]); - } - } - // if not found return default - if (!StringHelper::check($script) && $default) - { - return $default; - } - - return $script; + return CFactory::_('Customcode.Dispenser')->get($first, $second, $prefix, $note, $unset, $default, $sufix); } /** @@ -10198,7 +10068,7 @@ class Get * @param string $string The code string * * @return string - * + * @deprecated 3.3 Use CFactory::_('Customcode.Hash')->set($script); */ protected function setDynamicHASHING($script) { @@ -10259,7 +10129,7 @@ class Get * @param string $string The code string * * @return string - * + * @deprecated 3.3 Use CFactory::_('Customcode.LockBase')->set($script); */ protected function setBase64LOCK($script) { diff --git a/admin/helpers/compiler/b_Structure.php b/admin/helpers/compiler/b_Structure.php index 5efa2d28a..8f3da1daa 100644 --- a/admin/helpers/compiler/b_Structure.php +++ b/admin/helpers/compiler/b_Structure.php @@ -754,7 +754,7 @@ class Structure extends Get $module->add_scripts_field = false; $field_script_bucket = array(); // add any css from the fields - if (($css = $this->getCustomScriptBuilder( + if (($css = CFactory::_('Customcode.Dispenser')->get( 'css_view', $module->key )) !== null && StringHelper::check($css)) @@ -789,7 +789,7 @@ class Structure extends Get } } // add any JavaScript from the fields - if (($javascript = $this->getCustomScriptBuilder( + if (($javascript = CFactory::_('Customcode.Dispenser')->get( 'view_footer', $module->key )) !== null && StringHelper::check($javascript)) diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 71e0592f4..0bcaa928e 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -4784,7 +4784,7 @@ class Interpretation extends Fields // set main get query $getItem .= $this->setCustomViewQuery($get->main_get, $code); // check if there is any custom script - $getItem .= $this->getCustomScriptBuilder( + $getItem .= CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_getlistquery', $code, '', PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_( __LINE__,__CLASS__ @@ -7403,7 +7403,7 @@ class Interpretation extends Fields $script .= PHP_EOL . Indent::_(3) . "}"; } // add custom php to getitem method - $script .= $this->getCustomScriptBuilder( + $script .= CFactory::_('Customcode.Dispenser')->get( 'php_getitem', $view, PHP_EOL . PHP_EOL ); @@ -7442,7 +7442,7 @@ class Interpretation extends Fields $Component = $this->fileContentStatic[Placefix::_h('Component')]; $component = CFactory::_('Config')->component_code_name; // check if there was script added before modeling of data - $script .= $this->getCustomScriptBuilder( + $script .= CFactory::_('Customcode.Dispenser')->get( 'php_before_save', $view, PHP_EOL . PHP_EOL ); // turn array into JSON string @@ -7627,7 +7627,7 @@ class Interpretation extends Fields } } // add custom PHP to the save method - $script .= $this->getCustomScriptBuilder( + $script .= CFactory::_('Customcode.Dispenser')->get( 'php_save', $view, PHP_EOL . PHP_EOL ); @@ -7901,7 +7901,7 @@ class Interpretation extends Fields . PHP_EOL; } // add the custom script - $script .= $this->getCustomScriptBuilder( + $script .= CFactory::_('Customcode.Dispenser')->get( 'php_postflight', 'install', PHP_EOL . PHP_EOL, null, true ); // add the Intelligent Fix script if needed @@ -7930,7 +7930,7 @@ class Interpretation extends Fields // reset script $script = $this->setComponentToContentTypes('update'); // add the custom script - $script .= $this->getCustomScriptBuilder( + $script .= CFactory::_('Customcode.Dispenser')->get( 'php_postflight', 'update', PHP_EOL . PHP_EOL, null, true ); if (isset($this->componentData->admin_views) @@ -8427,7 +8427,7 @@ class Interpretation extends Fields // add the Intelligent Reversal script if needed $script .= $this->getAssetsTableIntelligentUninstall(); // add the custom uninstall script - $script .= $this->getCustomScriptBuilder( + $script .= CFactory::_('Customcode.Dispenser')->get( 'php_method', 'uninstall', "", null, true, null, PHP_EOL ); @@ -9104,7 +9104,7 @@ class Interpretation extends Fields $category = $this->catCodeBuilder[$nameSingleCode]['code']; } // prepare custom script - $customScript = $this->getCustomScriptBuilder( + $customScript = CFactory::_('Customcode.Dispenser')->get( 'php_batchmove', $nameSingleCode, PHP_EOL . PHP_EOL, null, true ); @@ -9381,7 +9381,7 @@ class Interpretation extends Fields } } // prepare custom script - $customScript = $this->getCustomScriptBuilder( + $customScript = CFactory::_('Customcode.Dispenser')->get( 'php_batchcopy', $nameSingleCode, PHP_EOL . PHP_EOL, null, true ); @@ -10528,13 +10528,13 @@ class Interpretation extends Fields $db .= $db_ . PHP_EOL . PHP_EOL; } // add custom sql dump to the file - if (isset($this->customScriptBuilder['sql']) + if (isset(CFactory::_('Customcode.Dispenser')->hub['sql']) && ArrayHelper::check( - $this->customScriptBuilder['sql'] + CFactory::_('Customcode.Dispenser')->hub['sql'] )) { foreach ( - $this->customScriptBuilder['sql'] as $for => $customSql + CFactory::_('Customcode.Dispenser')->hub['sql'] as $for => $customSql ) { $placeholders = array(Placefix::_('component') => $component, @@ -10543,7 +10543,7 @@ class Interpretation extends Fields $customSql, $placeholders ) . PHP_EOL . PHP_EOL; } - unset($this->customScriptBuilder['sql']); + unset(CFactory::_('Customcode.Dispenser')->hub['sql']); } // WHY DO WE NEED AN ASSET TABLE FIX? @@ -10640,16 +10640,16 @@ class Interpretation extends Fields } } // add custom sql uninstall dump to the file - if (isset($this->customScriptBuilder['sql_uninstall']) + if (isset(CFactory::_('Customcode.Dispenser')->hub['sql_uninstall']) && StringHelper::check( - $this->customScriptBuilder['sql_uninstall'] + CFactory::_('Customcode.Dispenser')->hub['sql_uninstall'] )) { $db .= CFactory::_('Placeholder')->update( - $this->customScriptBuilder['sql_uninstall'], + CFactory::_('Customcode.Dispenser')->hub['sql_uninstall'], $this->placeholders ) . PHP_EOL; - unset($this->customScriptBuilder['sql_uninstall']); + unset(CFactory::_('Customcode.Dispenser')->hub['sql_uninstall']); } // check if this component used larger rules @@ -14528,7 +14528,7 @@ class Interpretation extends Fields . "') . ' = ' . \$db->quoteName('c.id') . ')');"; } // add custom filtering php - $query .= $this->getCustomScriptBuilder( + $query .= CFactory::_('Customcode.Dispenser')->get( 'php_getlistquery', $nameSingleCode, PHP_EOL . PHP_EOL ); // add the custom fields query @@ -14949,7 +14949,7 @@ class Interpretation extends Fields $query .= PHP_EOL . Indent::_(3) . "}"; } // add custom php to getitems method after all - $query .= $this->getCustomScriptBuilder( + $query .= CFactory::_('Customcode.Dispenser')->get( 'php_getitems_after_all', $nameSingleCode, PHP_EOL . PHP_EOL . Indent::_(1) ); @@ -15213,7 +15213,7 @@ class Interpretation extends Fields $query .= PHP_EOL . Indent::_(3) . "}"; // add custom filtering php - $query .= $this->getCustomScriptBuilder( + $query .= CFactory::_('Customcode.Dispenser')->get( 'php_getlistquery', $nameSingleCode, PHP_EOL . PHP_EOL . Indent::_(1) ); @@ -15337,7 +15337,7 @@ class Interpretation extends Fields $query .= PHP_EOL . Indent::_(3) . "}"; } // add custom php to getItems method after all - $query .= $this->getCustomScriptBuilder( + $query .= CFactory::_('Customcode.Dispenser')->get( 'php_getitems_after_all', $nameSingleCode, PHP_EOL . PHP_EOL . Indent::_(2) ); @@ -15361,7 +15361,7 @@ class Interpretation extends Fields $header = ComponentbuilderHelper::getDynamicScripts('headers'); // add getExImPortHeaders - $query .= $this->getCustomScriptBuilder( + $query .= CFactory::_('Customcode.Dispenser')->get( 'php_import_headers', 'import_' . $nameListCode, PHP_EOL . PHP_EOL, null, true, // set a default script for those with no custom script @@ -15597,40 +15597,40 @@ class Interpretation extends Fields // load the custom script to the files // IMPORT_EXT_METHOD <<>> $this->fileContentDynamic['import_' . $nameListCode][Placefix::_h('IMPORT_EXT_METHOD')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_import_ext', 'import_' . $nameListCode, PHP_EOL, null, true ); // IMPORT_DISPLAY_METHOD_CUSTOM <<>> $this->fileContentDynamic['import_' . $nameListCode][Placefix::_h('IMPORT_DISPLAY_METHOD_CUSTOM')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_import_display', 'import_' . $nameListCode, PHP_EOL, null, true ); // IMPORT_SETDATA_METHOD <<>> $this->fileContentDynamic['import_' . $nameListCode][Placefix::_h('IMPORT_SETDATA_METHOD')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_import_setdata', 'import_' . $nameListCode, PHP_EOL, null, true ); // IMPORT_METHOD_CUSTOM <<>> $this->fileContentDynamic['import_' . $nameListCode][Placefix::_h('IMPORT_METHOD_CUSTOM')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_import', 'import_' . $nameListCode, PHP_EOL, null, true ); // IMPORT_SAVE_METHOD <<>> $this->fileContentDynamic['import_' . $nameListCode][Placefix::_h('IMPORT_SAVE_METHOD')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_import_save', 'import_' . $nameListCode, PHP_EOL, null, true ); // IMPORT_DEFAULT_VIEW_CUSTOM <<>> $this->fileContentDynamic['import_' . $nameListCode][Placefix::_h('IMPORT_DEFAULT_VIEW_CUSTOM')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'html_import_view', 'import_' . $nameListCode, PHP_EOL, null, true @@ -15700,7 +15700,7 @@ class Interpretation extends Fields . "') . ' = ' . \$db->quoteName('c.id') . ')');"; } // add custom filtering php - $query .= $this->getCustomScriptBuilder( + $query .= CFactory::_('Customcode.Dispenser')->get( 'php_getlistquery', $nameSingleCode, PHP_EOL . PHP_EOL ); // add the custom fields query @@ -16734,17 +16734,17 @@ class Interpretation extends Fields { $fileScript = ''; } - $fileScript .= $this->getCustomScriptBuilder( + $fileScript .= CFactory::_('Customcode.Dispenser')->get( 'view_file', $nameSingleCode, PHP_EOL . PHP_EOL, null, true, '' ); // add custom script to footer - if (isset($this->customScriptBuilder['view_footer'][$nameSingleCode]) + if (isset(CFactory::_('Customcode.Dispenser')->hub['view_footer'][$nameSingleCode]) && StringHelper::check( - $this->customScriptBuilder['view_footer'][$nameSingleCode] + CFactory::_('Customcode.Dispenser')->hub['view_footer'][$nameSingleCode] )) { $customFooterScript = PHP_EOL . PHP_EOL . CFactory::_('Placeholder')->update( - $this->customScriptBuilder['view_footer'][$nameSingleCode], + CFactory::_('Customcode.Dispenser')->hub['view_footer'][$nameSingleCode], $this->placeholders ); if (strpos($customFooterScript, 'name_list_code; // add custom script to list view JS file - if (($list_fileScript = $this->getCustomScriptBuilder( + if (($list_fileScript = CFactory::_('Customcode.Dispenser')->get( 'views_file', $nameSingleCode, PHP_EOL . PHP_EOL, null, true, false )) !== false @@ -17733,8 +17733,8 @@ class Interpretation extends Fields public function setAjaxToke(&$view) { $fix = ''; - if (isset($this->customScriptBuilder['token'][$view]) - && $this->customScriptBuilder['token'][$view]) + if (isset(CFactory::_('Customcode.Dispenser')->hub['token'][$view]) + && CFactory::_('Customcode.Dispenser')->hub['token'][$view]) { $fix .= PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Add Ajax Token"; @@ -17748,14 +17748,14 @@ class Interpretation extends Fields public function setRegisterAjaxTask($target) { $tasks = ''; - if (isset($this->customScriptBuilder[$target]['ajax_controller']) + if (isset(CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_controller']) && ArrayHelper::check( - $this->customScriptBuilder[$target]['ajax_controller'] + CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_controller'] )) { $taskArray = array(); foreach ( - $this->customScriptBuilder[$target]['ajax_controller'] as $view + CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_controller'] as $view ) { foreach ($view as $task) @@ -17779,9 +17779,9 @@ class Interpretation extends Fields public function setAjaxInputReturn($target) { $cases = ''; - if (isset($this->customScriptBuilder[$target]['ajax_controller']) + if (isset(CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_controller']) && ArrayHelper::check( - $this->customScriptBuilder[$target]['ajax_controller'] + CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_controller'] )) { $input = array(); @@ -17790,7 +17790,7 @@ class Interpretation extends Fields $getModel = array(); $userCheck = array(); foreach ( - $this->customScriptBuilder[$target]['ajax_controller'] as $view + CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_controller'] as $view ) { foreach ($view as $task) @@ -17911,13 +17911,13 @@ class Interpretation extends Fields public function setAjaxModelMethods($target) { $methods = ''; - if (isset($this->customScriptBuilder[$target]['ajax_model']) + if (isset(CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_model']) && ArrayHelper::check( - $this->customScriptBuilder[$target]['ajax_model'] + CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_model'] )) { foreach ( - $this->customScriptBuilder[$target]['ajax_model'] as $view => + CFactory::_('Customcode.Dispenser')->hub[$target]['ajax_model'] as $view => $method ) { @@ -19005,7 +19005,7 @@ class Interpretation extends Fields // set component name $component = $this->componentCodeName; // prepare custom permission script - $customAllow = $this->getCustomScriptBuilder( + $customAllow = CFactory::_('Customcode.Dispenser')->get( 'php_allowadd', $nameSingleCode, '', null, true ); // setup correct core target @@ -19162,7 +19162,7 @@ class Interpretation extends Fields // set component name $component = $this->componentCodeName; // prepare custom permission script - $customAllow = $this->getCustomScriptBuilder( + $customAllow = CFactory::_('Customcode.Dispenser')->get( 'php_allowedit', $nameSingleCode, '', null, true ); // setup correct core target @@ -19953,7 +19953,7 @@ class Interpretation extends Fields . "\$form->setValue(\$redirectedField, null, \$redirectedValue);"; $getForm[] = Indent::_(3) . "}"; // load custom script if found - $getForm[] = Indent::_(2) . "}" . $this->getCustomScriptBuilder( + $getForm[] = Indent::_(2) . "}" . CFactory::_('Customcode.Dispenser')->get( 'php_getform', $nameSingleCode, PHP_EOL ); // setup the default script @@ -20117,7 +20117,7 @@ class Interpretation extends Fields // set component name $component = $this->componentCodeName; // prepare custom permission script - $customAllow = $this->getCustomScriptBuilder( + $customAllow = CFactory::_('Customcode.Dispenser')->get( 'php_allowedit', $nameSingleCode, Indent::_(2) . "\$recordId = (int) isset(\$data[\$key]) ? \$data[\$key] : 0;" . PHP_EOL @@ -22268,7 +22268,7 @@ class Interpretation extends Fields } // add custom php to getitems method - $fix .= $this->getCustomScriptBuilder( + $fix .= CFactory::_('Customcode.Dispenser')->get( 'php_getitems', $nameSingleCode, PHP_EOL . PHP_EOL . $tab ); @@ -28029,14 +28029,14 @@ function vdm_dkim() { // first add the header $default = PHP_EOL . $module->default_header . PHP_EOL . '?>'; // add any css from the fields - $default .= $this->getCustomScriptBuilder( + $default .= CFactory::_('Customcode.Dispenser')->get( 'css_views', $key, PHP_EOL . '' . PHP_EOL ); // now add the body $default .= PHP_EOL . $module->default . PHP_EOL; // add any JavaScript from the fields - $default .= $this->getCustomScriptBuilder( + $default .= CFactory::_('Customcode.Dispenser')->get( 'views_footer', $key, PHP_EOL . '' . PHP_EOL diff --git a/admin/helpers/compiler/f_Infusion.php b/admin/helpers/compiler/f_Infusion.php index 212fd1a47..65dc4de66 100644 --- a/admin/helpers/compiler/f_Infusion.php +++ b/admin/helpers/compiler/f_Infusion.php @@ -216,38 +216,38 @@ class Infusion extends Interpretation // ADMINJS $this->fileContentStatic[Placefix::_h('ADMINJS')] = CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_js'], CFactory::_('Placeholder')->active + CFactory::_('Customcode.Dispenser')->hub['component_js'], CFactory::_('Placeholder')->active ); // SITEJS $this->fileContentStatic[Placefix::_h('SITEJS')] = CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_js'], CFactory::_('Placeholder')->active + CFactory::_('Customcode.Dispenser')->hub['component_js'], CFactory::_('Placeholder')->active ); // ADMINCSS $this->fileContentStatic[Placefix::_h('ADMINCSS')] = CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_css_admin'], + CFactory::_('Customcode.Dispenser')->hub['component_css_admin'], CFactory::_('Placeholder')->active ); // SITECSS $this->fileContentStatic[Placefix::_h('SITECSS')] = CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_css_site'], + CFactory::_('Customcode.Dispenser')->hub['component_css_site'], CFactory::_('Placeholder')->active ); // CUSTOM_HELPER_SCRIPT $this->fileContentStatic[Placefix::_h('CUSTOM_HELPER_SCRIPT')] = CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_php_helper_admin'], + CFactory::_('Customcode.Dispenser')->hub['component_php_helper_admin'], CFactory::_('Placeholder')->active ); // BOTH_CUSTOM_HELPER_SCRIPT $this->fileContentStatic[Placefix::_h('BOTH_CUSTOM_HELPER_SCRIPT')] = CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_php_helper_both'], + CFactory::_('Customcode.Dispenser')->hub['component_php_helper_both'], CFactory::_('Placeholder')->active ); @@ -284,7 +284,7 @@ class Infusion extends Interpretation .= PHP_EOL . Indent::_(1) . '{'; $this->fileContentStatic[Placefix::_h('ADMIN_GLOBAL_EVENT_HELPER')] .= PHP_EOL . CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_php_admin_event'], + CFactory::_('Customcode.Dispenser')->hub['component_php_admin_event'], CFactory::_('Placeholder')->active ); $this->fileContentStatic[Placefix::_h('ADMIN_GLOBAL_EVENT_HELPER')] @@ -447,7 +447,7 @@ class Infusion extends Interpretation ); // DOCUMENT_CUSTOM_PHP <<>> - if ($phpDocument = $this->getCustomScriptBuilder( + if ($phpDocument = CFactory::_('Customcode.Dispenser')->get( 'php_document', $nameSingleCode, PHP_EOL, null, true, false @@ -512,28 +512,28 @@ class Infusion extends Interpretation // JMODELADMIN_BEFORE_DELETE <<>> $this->fileContentDynamic[$nameSingleCode][Placefix::_h('JMODELADMIN_BEFORE_DELETE')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_before_delete', $nameSingleCode, PHP_EOL ); // JMODELADMIN_AFTER_DELETE <<>> $this->fileContentDynamic[$nameSingleCode][Placefix::_h('JMODELADMIN_AFTER_DELETE')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_after_delete', $nameSingleCode, PHP_EOL . PHP_EOL ); // JMODELADMIN_BEFORE_DELETE <<>> $this->fileContentDynamic[$nameSingleCode][Placefix::_h('JMODELADMIN_BEFORE_PUBLISH')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_before_publish', $nameSingleCode, PHP_EOL ); // JMODELADMIN_AFTER_DELETE <<>> $this->fileContentDynamic[$nameSingleCode][Placefix::_h('JMODELADMIN_AFTER_PUBLISH')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_after_publish', $nameSingleCode, PHP_EOL . PHP_EOL ); @@ -552,7 +552,7 @@ class Infusion extends Interpretation // POSTSAVEHOOK <<>> $this->fileContentDynamic[$nameSingleCode][Placefix::_h('POSTSAVEHOOK')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_postsavehook', $nameSingleCode, PHP_EOL, null, true, PHP_EOL . Indent::_(2) . "return;", @@ -561,7 +561,7 @@ class Infusion extends Interpretation // VIEWCSS <<>> $this->fileContentDynamic[$nameSingleCode][Placefix::_h('VIEWCSS')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'css_view', $nameSingleCode, '', null, true ); @@ -746,7 +746,7 @@ class Infusion extends Interpretation // GET_ITEMS_METHOD_AFTER_ALL <<>> $this->fileContentDynamic[$nameListCode][Placefix::_h('GET_ITEMS_METHOD_AFTER_ALL')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_getitems_after_all', $nameSingleCode, PHP_EOL ); @@ -912,7 +912,7 @@ class Infusion extends Interpretation // VIEWSCSS <<>> $this->fileContentDynamic[$nameListCode][Placefix::_h('VIEWSCSS')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'css_views', $nameSingleCode, '', null, true ); @@ -927,7 +927,7 @@ class Infusion extends Interpretation $scriptNote = PHP_EOL . '//' . Line::_(__Line__, __Class__) . ' ' . $nameListCode . ' footer script'; - if (($footerScript = $this->getCustomScriptBuilder( + if (($footerScript = CFactory::_('Customcode.Dispenser')->get( 'views_footer', $nameSingleCode, '', $scriptNote, true, false, PHP_EOL @@ -1040,17 +1040,17 @@ class Infusion extends Interpretation // JCONTROLLERFORM_BEFORECANCEL <<>> $this->fileContentDynamic[$nameSingleCode][Placefix::_h('JCONTROLLERFORM_BEFORECANCEL')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_before_cancel', $nameSingleCode, - PHP_EOL, null, null, + PHP_EOL, null, false, '' ); // JCONTROLLERFORM_AFTERCANCEL <<>> $this->fileContentDynamic[$nameSingleCode][Placefix::_h('JCONTROLLERFORM_AFTERCANCEL')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_after_cancel', $nameSingleCode, - PHP_EOL, null, null, + PHP_EOL, null, false, '' ); @@ -1280,7 +1280,7 @@ class Infusion extends Interpretation { // CUSTOM_ADMIN_BEFORE_GET_ITEM <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('CUSTOM_ADMIN_BEFORE_GET_ITEM')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_before_getitem', $view['settings']->code, '', null, true ); @@ -1294,7 +1294,7 @@ class Infusion extends Interpretation // CUSTOM_ADMIN_AFTER_GET_ITEM <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('CUSTOM_ADMIN_AFTER_GET_ITEM')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_after_getitem', $view['settings']->code, '', null, true ); @@ -1309,14 +1309,14 @@ class Infusion extends Interpretation // CUSTOM_ADMIN_CUSTOM_BEFORE_LIST_QUERY <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('CUSTOM_ADMIN_CUSTOM_BEFORE_LIST_QUERY')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_getlistquery', $view['settings']->code, PHP_EOL, null, true ); // CUSTOM_ADMIN_BEFORE_GET_ITEMS <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('CUSTOM_ADMIN_BEFORE_GET_ITEMS')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_before_getitems', $view['settings']->code, PHP_EOL, null, true ); @@ -1329,7 +1329,7 @@ class Infusion extends Interpretation // CUSTOM_ADMIN_AFTER_GET_ITEMS <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('CUSTOM_ADMIN_AFTER_GET_ITEMS')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_after_getitems', $view['settings']->code, PHP_EOL, null, true ); @@ -1768,7 +1768,7 @@ class Infusion extends Interpretation // SITE_BEFORE_GET_ITEM <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('SITE_BEFORE_GET_ITEM')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_before_getitem', $view['settings']->code, '', null, true ); @@ -1782,7 +1782,7 @@ class Infusion extends Interpretation // SITE_AFTER_GET_ITEM <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('SITE_AFTER_GET_ITEM')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_after_getitem', $view['settings']->code, '', null, true ); @@ -1800,7 +1800,7 @@ class Infusion extends Interpretation // SITE_BEFORE_GET_ITEMS <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('SITE_BEFORE_GET_ITEMS')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_before_getitems', $view['settings']->code, PHP_EOL, null, true ); @@ -1813,7 +1813,7 @@ class Infusion extends Interpretation // SITE_AFTER_GET_ITEMS <<>> $this->fileContentDynamic[$view['settings']->code][Placefix::_h('SITE_AFTER_GET_ITEMS')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( CFactory::_('Config')->build_target . '_php_after_getitems', $view['settings']->code, PHP_EOL, null, true ); @@ -1969,7 +1969,7 @@ class Infusion extends Interpretation // SITE_CUSTOM_HELPER_SCRIPT $this->fileContentStatic[Placefix::_h('SITE_CUSTOM_HELPER_SCRIPT')] = CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_php_helper_site'], + CFactory::_('Customcode.Dispenser')->hub['component_php_helper_site'], CFactory::_('Placeholder')->active ); // SITE_GLOBAL_EVENT_HELPER @@ -2004,7 +2004,7 @@ class Infusion extends Interpretation .= PHP_EOL . Indent::_(1) . '{'; $this->fileContentStatic[Placefix::_h('SITE_GLOBAL_EVENT_HELPER')] .= PHP_EOL . CFactory::_('Placeholder')->update( - $this->customScriptBuilder['component_php_site_event'], + CFactory::_('Customcode.Dispenser')->hub['component_php_site_event'], CFactory::_('Placeholder')->active ); $this->fileContentStatic[Placefix::_h('SITE_GLOBAL_EVENT_HELPER')] @@ -2014,13 +2014,13 @@ class Infusion extends Interpretation // PREINSTALLSCRIPT $this->fileContentStatic[Placefix::_h('PREINSTALLSCRIPT')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_preflight', 'install', PHP_EOL, null, true ); // PREUPDATESCRIPT $this->fileContentStatic[Placefix::_h('PREUPDATESCRIPT')] - = $this->getCustomScriptBuilder( + = CFactory::_('Customcode.Dispenser')->get( 'php_preflight', 'update', PHP_EOL, null, true ); diff --git a/componentbuilder.xml b/componentbuilder.xml index 3a5f4b84d..32501cb36 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 30th August, 2022 + 31st August, 2022 Llewellyn van der Merwe joomla@vdm.io https://dev.vdm.io diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/Dispenser.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/Dispenser.php new file mode 100644 index 000000000..cb851db07 --- /dev/null +++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/Dispenser.php @@ -0,0 +1,283 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Compiler\Customcode; + + +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler; +use VDM\Joomla\Componentbuilder\Compiler\Customcode; +use VDM\Joomla\Componentbuilder\Compiler\Placeholder; +use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui; +use VDM\Joomla\Componentbuilder\Compiler\Customcode\Hash; +use VDM\Joomla\Componentbuilder\Compiler\Customcode\LockBase; + + +/** + * Compiler Custom Code Dispenser + * + * @since 3.2.0 + */ +class Dispenser +{ + /** + * Customcode Dispenser Hub + * + * @var array + * @since 3.2.0 + **/ + public array $hub; + + /** + * Compiler Customcode + * + * @var Customcode + * @since 3.2.0 + **/ + protected Customcode $customcode; + + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Compiler Customcode in Gui + * + * @var Gui + * @since 3.2.0 + **/ + protected Gui $gui; + + /** + * Compiler Customcode to Hash + * + * @var Hash + * @since 3.2.0 + **/ + protected Hash $hash; + + /** + * Compiler Customcode to LockBase + * + * @var LockBase + * @since 3.2.0 + **/ + protected LockBase $base64; + + /** + * Constructor. + * + * @param Customcode|null $customcode The compiler customcode object. + * @param Placeholder|null $placeholder The compiler placeholder object. + * @param Gui|null $gui The compiler customcode gui object. + * @param Hash|null $hash The compiler customcode hash object. + * @param LockBase|null $base64 The compiler customcode lock base64 object. + * + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null, ?Customcode $customcode = null, + ?Gui $gui = null, ?Hash $hash = null, ?LockBase $base64 = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + $this->customcode = $customcode ?: Compiler::_('Customcode'); + $this->gui = $gui ?: Compiler::_('Customcode.Gui'); + $this->hash = $hash ?: Compiler::_('Customcode.Hash'); + $this->base64 = $base64 ?: Compiler::_('Customcode.LockBase'); + } + + /** + * Set the script for the customcode dispenser + * + * @param string $script The script + * @param string $first The first key + * @param string|null $second The second key (if not set we use only first key) + * @param string|null $third The third key (if not set we use only first and second key) + * @param array $config The config options + * @param bool $base64 The switch to decode base64 the script + * default: true + * @param bool $dynamic The switch to dynamic update the script + * default: true + * @param bool $add The switch to add to exiting instead of replace + * default: false + * + * @return bool true on success + * @since 3.2.0 + */ + public function set(&$script, string $first, ?string $second = null, ?string $third = null, + array $config = array(), bool $base64 = true, bool $dynamic = true, bool $add = false): bool + { + // only load if we have a string + if (!StringHelper::check($script)) + { + return false; + } + // this needs refactoring (TODO) + if (!isset($this->hub[$first]) + || ($second + && !isset($this->hub[$first][$second]))) + { + // check if the script first key is set + if ($second && !isset($this->hub[$first])) + { + $this->hub[$first] = array(); + } + elseif ($add && !$second + && !isset($this->hub[$first])) + { + $this->hub[$first] = ''; + } + // check if the script second key is set + if ($second && $third + && !isset($this->hub[$first][$second])) + { + $this->hub[$first][$second] = array(); + } + elseif ($add && $second && !$third + && !isset($this->hub[$first][$second])) + { + $this->hub[$first][$second] = ''; + } + // check if the script third key is set + if ($add && $second && $third + && !isset($this->hub[$first][$second][$third])) + { + $this->hub[$first][$second][$third] = ''; + } + } + // prep the script string + if ($base64 && $dynamic) + { + $script = $this->customcode->add(base64_decode($script)); + } + elseif ($base64) + { + $script = base64_decode($script); + } + elseif ($dynamic) // this does not happen (just incase) + { + $script = $this->customcode->add($script); + } + // check if we still have a string + if (StringHelper::check($script)) + { + // now load the placeholder snippet if needed + if ($base64 || $dynamic) + { + $script = $this->gui->set($script, $config); + } + // add Dynamic HASHING option of a file/string + $script = $this->hash->set($script); + // add base64 locking option of a string + $script = $this->base64->set($script); + // load the script + if ($first && $second && $third) + { + // now act on loading option + if ($add) + { + $this->hub[$first][$second][$third] + .= $script; + } + else + { + $this->hub[$first][$second][$third] + = $script; + } + } + elseif ($first && $second) + { + // now act on loading option + if ($add) + { + $this->hub[$first][$second] .= $script; + } + else + { + $this->hub[$first][$second] = $script; + } + } + else + { + // now act on loading option + if ($add) + { + $this->hub[$first] .= $script; + } + else + { + $this->hub[$first] = $script; + } + } + + return true; + } + + return false; + } + + /** + * Get the script from the customcode dispenser + * + * @param string $first The first key + * @param string $second The second key + * @param string $prefix The prefix to add in front of the script if found + * @param string|null $note The switch/note to add to the script + * @param bool $unset The switch to unset the value if found + * @param mixed|null $default The switch/string to use as default return if script not found + * @param string $suffix The suffix to add after the script if found + * + * @return mixed The string/script if found or the default value if not found + * + * @since 3.2.0 + */ + public function get(string $first, string $second, string $prefix = '', ?string $note = null, + bool $unset = false, $default = null, string $suffix = '') + { + // default is to return an empty string + $script = ''; + // check if there is any custom script + if (isset($this->hub[$first][$second]) + && StringHelper::check( + $this->hub[$first][$second] + )) + { + // add not if set + if ($note) + { + $script .= $note; + } + // load the actual script + $script .= $prefix . str_replace( + array_keys($this->placeholder->active), + array_values($this->placeholder->active), + $this->hub[$first][$second] + ) . $suffix; + // clear some memory + if ($unset) + { + unset($this->hub[$first][$second]); + } + } + // if not found return default + if (!StringHelper::check($script) && $default) + { + return $default; + } + + return $script; + } + +} + diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/Hash.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/Hash.php new file mode 100644 index 000000000..bca67e38d --- /dev/null +++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/Hash.php @@ -0,0 +1,110 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Compiler\Customcode; + + +use VDM\Joomla\Utilities\GetHelper; +use VDM\Joomla\Utilities\FileHelper; +use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler; +use VDM\Joomla\Componentbuilder\Compiler\Placeholder; + + +/** + * Compiler Custom Code MD5 + * + * @since 3.2.0 + */ +class Hash +{ + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Constructor. + * + * @param Placeholder|null $placeholder The compiler placeholder object. + * + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + } + + /** + * Set the the MD5 hashed string or file or string + * + * @param string $script The code string + * + * @return string + * @since 3.2.0 + */ + public function set(string $script): string + { + // check if we should hash a string + if (\strpos($script, 'HASH' . 'STRING((((') !== false) + { + // get the strings + $values = GetHelper::allBetween( + $script, 'HASH' . 'STRING((((', '))))' + ); + $locker = array(); + // convert them + foreach ($values as $value) + { + $locker['HASH' . 'STRING((((' . $value . '))))'] + = \md5($value); + } + + // update the script + return $this->placeholder->update($script, $locker); + } + // check if we should hash a file + if (\strpos($script, 'HASH' . 'FILE((((') !== false) + { + // get the strings + $values = GetHelper::allBetween( + $script, 'HASH' . 'FILE((((', '))))' + ); + $locker = array(); + // convert them + foreach ($values as $path) + { + // we first get the file if it exist + if ($value = FileHelper::getContent($path)) + { + // now we hash the file content + $locker['HASH' . 'FILE((((' . $path . '))))'] + = \md5($value); + } + else + { + // could not retrieve the file so we show error + $locker['HASH' . 'FILE((((' . $path . '))))'] + = 'ERROR'; + } + } + + // update the script + return $this->placeholder->update($script, $locker); + } + + return $script; + } + +} + diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/LockBase.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/LockBase.php new file mode 100644 index 000000000..d7243967e --- /dev/null +++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Customcode/LockBase.php @@ -0,0 +1,85 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Compiler\Customcode; + + +use VDM\Joomla\Utilities\GetHelper; +use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent; +use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler; +use VDM\Joomla\Componentbuilder\Compiler\Placeholder; + + +/** + * Compiler Custom Code Base64 + * + * @since 3.2.0 + */ +class LockBase +{ + /** + * Compiler Placeholder + * + * @var Placeholder + * @since 3.2.0 + **/ + protected Placeholder $placeholder; + + /** + * Constructor. + * + * @param Placeholder|null $placeholder The compiler placeholder object. + * + * @since 3.2.0 + */ + public function __construct(?Placeholder $placeholder = null) + { + $this->placeholder = $placeholder ?: Compiler::_('Placeholder'); + } + + /** + * Set a string as bsae64 (basic) + * + * @param string $script The code string + * + * @return string + * @since 3.2.0 + */ + public function set(string $script): string + { + if (\strpos($script, 'LOCK'.'BASE64((((') !== false) + { + // get the strings + $values = GetHelper::allBetween( + $script, 'LOCK'.'BASE64((((', '))))' + ); + $locker = array(); + // convert them + foreach ($values as $value) + { + $locker['LOCK'.'BASE64((((' . $value . '))))'] + = "base64_decode( preg_replace('/\s+/', ''," . + PHP_EOL . Indent::_(2) . "'" . + \wordwrap( + \base64_encode($value), 64, PHP_EOL . Indent::_(2), true + ) . + "'))"; + } + + // update the script + return $this->placeholder->update($script, $locker); + } + + return $script; + } + +} + diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Service/Customcode.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Service/Customcode.php index ad55c797e..424445438 100644 --- a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Service/Customcode.php +++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Service/Customcode.php @@ -17,6 +17,9 @@ use Joomla\DI\ServiceProviderInterface; use VDM\Joomla\Componentbuilder\Compiler\Customcode as CompilerCustomcode; use VDM\Joomla\Componentbuilder\Compiler\Customcode\External; use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui; +use VDM\Joomla\Componentbuilder\Compiler\Customcode\Hash; +use VDM\Joomla\Componentbuilder\Compiler\Customcode\LockBase; +use VDM\Joomla\Componentbuilder\Compiler\Customcode\Dispenser; /** @@ -44,6 +47,15 @@ class Customcode implements ServiceProviderInterface $container->alias(Gui::class, 'Customcode.Gui') ->share('Customcode.Gui', [$this, 'getGui'], true); + + $container->alias(Hash::class, 'Customcode.Hash') + ->share('Customcode.Hash', [$this, 'getHash'], true); + + $container->alias(LockBase::class, 'Customcode.LockBase') + ->share('Customcode.LockBase', [$this, 'getLockBase'], true); + + $container->alias(Dispenser::class, 'Customcode.Dispenser') + ->share('Customcode.Dispenser', [$this, 'getDispenser'], true); } /** @@ -94,6 +106,55 @@ class Customcode implements ServiceProviderInterface $container->get('Placeholder.Reverse') ); } + + /** + * Get the Customcode Hash + * + * @param Container $container The DI container. + * + * @return Hash + * @since 3.2.0 + */ + public function getHash(Container $container): Hash + { + return new Hash( + $container->get('Placeholder') + ); + } + + /** + * Get the Customcode LockBase64 + * + * @param Container $container The DI container. + * + * @return LockBase + * @since 3.2.0 + */ + public function getLockBase(Container $container): LockBase + { + return new LockBase( + $container->get('Placeholder') + ); + } + + /** + * Get the Customcode Dispenser + * + * @param Container $container The DI container. + * + * @return Dispenser + * @since 3.2.0 + */ + public function getDispenser(Container $container): Dispenser + { + return new Dispenser( + $container->get('Placeholder'), + $container->get('Customcode'), + $container->get('Customcode.Gui'), + $container->get('Customcode.Hash'), + $container->get('Customcode.LockBase') + ); + } }