Moved all placeholder behaviour to class function. Moved dynamic content to the content class.

This commit is contained in:
Llewellyn van der Merwe 2022-12-11 17:06:13 +02:00
parent 4217b22f67
commit a2ec013566
Signed by: Llewellyn
GPG Key ID: A9201372263741E7
17 changed files with 1816 additions and 1625 deletions

View File

@ -140,14 +140,14 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 4th December, 2022 + *Last Build*: 11th December, 2022
+ *Version*: 3.1.13 + *Version*: 3.1.13
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **336766** + *Line count*: **337314**
+ *Field count*: **2009** + *Field count*: **2009**
+ *File count*: **2204** + *File count*: **2206**
+ *Folder count*: **387** + *Folder count*: **388**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com). > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)

View File

@ -140,14 +140,14 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 4th December, 2022 + *Last Build*: 11th December, 2022
+ *Version*: 3.1.13 + *Version*: 3.1.13
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **336766** + *Line count*: **337314**
+ *Field count*: **2009** + *Field count*: **2009**
+ *File count*: **2204** + *File count*: **2206**
+ *Folder count*: **387** + *Folder count*: **388**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com). > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)

View File

@ -99,7 +99,7 @@ class Compiler extends Infusion
$this->repoPath = $this->params->get('git_folder_path', null); $this->repoPath = $this->params->get('git_folder_path', null);
} }
// remove site folder if not needed (TODO add check if custom script was moved to site folder then we must do a more complex cleanup here) // remove site folder if not needed (TODO add check if custom script was moved to site folder then we must do a more complex cleanup here)
if ($this->removeSiteFolder && $this->removeSiteEditFolder) if (CFactory::_('Config')->remove_site_folder && CFactory::_('Config')->remove_site_edit_folder)
{ {
// first remove the files and folders // first remove the files and folders
$this->removeFolder($this->componentPath . '/site'); $this->removeFolder($this->componentPath . '/site');
@ -397,9 +397,9 @@ class Compiler extends Infusion
// now we do the dynamic files // now we do the dynamic files
foreach ($this->newFiles['dynamic'] as $view => $files) foreach ($this->newFiles['dynamic'] as $view => $files)
{ {
if (isset($this->fileContentDynamic[$view]) if (CFactory::_('Content')->exist_($view)
&& ArrayHelper::check( && ArrayHelper::check(
$this->fileContentDynamic[$view] CFactory::_('Content')->get_($view)
)) ))
{ {
foreach ($files as $file) foreach ($files as $file)
@ -417,7 +417,7 @@ class Compiler extends Infusion
} }
} }
// free up some memory // free up some memory
unset($this->fileContentDynamic[$view]); CFactory::_('Content')->remove_($view);
} }
// free up some memory // free up some memory
unset($this->newFiles['dynamic']); unset($this->newFiles['dynamic']);
@ -498,7 +498,7 @@ class Compiler extends Infusion
} }
// free up some memory // free up some memory
unset($this->newFiles[$module->key]); unset($this->newFiles[$module->key]);
unset($this->fileContentDynamic[$module->key]); CFactory::_('Content')->remove_($module->key);
} }
} }
} }
@ -579,7 +579,7 @@ class Compiler extends Infusion
} }
// free up some memory // free up some memory
unset($this->newFiles[$plugin->key]); unset($this->newFiles[$plugin->key]);
unset($this->fileContentDynamic[$plugin->key]); CFactory::_('Content')->remove_($plugin->key);
} }
} }
} }
@ -607,7 +607,7 @@ class Compiler extends Infusion
} }
// free up some memory // free up some memory
unset($this->newFiles[$power->key]); unset($this->newFiles[$power->key]);
unset($this->fileContentDynamic[$power->key]); CFactory::_('Content')->remove_($power->key);
} }
} }
} }
@ -661,7 +661,7 @@ class Compiler extends Infusion
if ($view) if ($view)
{ {
$answer = CFactory::_('Placeholder')->update( $answer = CFactory::_('Placeholder')->update(
$answer, $this->fileContentDynamic[$view], 3 $answer, CFactory::_('Content')->get_($view), 3
); );
} }
// check if this file needs extra care :) // check if this file needs extra care :)
@ -1421,8 +1421,8 @@ class Compiler extends Infusion
$target['id'] $target['id']
); );
$data = $placeholder['start'] . PHP_EOL $data = $placeholder['start'] . PHP_EOL
. CFactory::_('Placeholder')->update( . CFactory::_('Placeholder')->update_(
$target['code'], CFactory::_('Placeholder')->active $target['code']
) . $placeholder['end'] . PHP_EOL; ) . $placeholder['end'] . PHP_EOL;
if ($target['type'] == 2) if ($target['type'] == 2)
{ {

View File

@ -2275,49 +2275,31 @@ class Get
CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_single_code] CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_single_code]
= false; = false;
CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_list_code] = false; CFactory::_('Customcode.Dispenser')->hub['token'][$view->name_list_code] = false;
// set some placeholders // set some placeholders
CFactory::_('Placeholder')->active[Placefix::_h('view')] CFactory::_('Placeholder')->set('view', $view->name_single_code);
= $view->name_single_code; CFactory::_('Placeholder')->set('views', $view->name_list_code);
CFactory::_('Placeholder')->active[Placefix::_h('views')] CFactory::_('Placeholder')->set('View', StringHelper::safe(
= $view->name_list_code;
CFactory::_('Placeholder')->active[Placefix::_h('View')]
= StringHelper::safe(
$view->name_single, 'F' $view->name_single, 'F'
); ));
CFactory::_('Placeholder')->active[Placefix::_h('Views')] CFactory::_('Placeholder')->set('Views', StringHelper::safe(
= StringHelper::safe(
$view->name_list, 'F' $view->name_list, 'F'
); ));
CFactory::_('Placeholder')->active[Placefix::_h('VIEW')] CFactory::_('Placeholder')->set('VIEW', StringHelper::safe(
= StringHelper::safe(
$view->name_single, 'U' $view->name_single, 'U'
); ));
CFactory::_('Placeholder')->active[Placefix::_h('VIEWS')] CFactory::_('Placeholder')->set('VIEWS', StringHelper::safe(
= StringHelper::safe(
$view->name_list, 'U' $view->name_list, 'U'
); ));
CFactory::_('Placeholder')->active[Placefix::_('view')]
= CFactory::_('Placeholder')->active[Placefix::_h('view')];
CFactory::_('Placeholder')->active[Placefix::_('views')]
= CFactory::_('Placeholder')->active[Placefix::_h('views')];
CFactory::_('Placeholder')->active[Placefix::_('View')]
= CFactory::_('Placeholder')->active[Placefix::_h('View')];
CFactory::_('Placeholder')->active[Placefix::_('Views')]
= CFactory::_('Placeholder')->active[Placefix::_h('Views')];
CFactory::_('Placeholder')->active[Placefix::_('VIEW')]
= CFactory::_('Placeholder')->active[Placefix::_h('VIEW')];
CFactory::_('Placeholder')->active[Placefix::_('VIEWS')]
= CFactory::_('Placeholder')->active[Placefix::_h('VIEWS')];
// for plugin event TODO change event api signatures // for plugin event TODO change event api signatures
$this->placeholders = CFactory::_('Placeholder')->active; $placeholders = CFactory::_('Placeholder')->active;
// Trigger Event: jcb_ce_onBeforeModelViewData // Trigger Event: jcb_ce_onBeforeModelViewData
CFactory::_('Event')->trigger( CFactory::_('Event')->trigger(
'jcb_ce_onBeforeModelViewData', 'jcb_ce_onBeforeModelViewData',
array(&$this->componentContext, &$view, &$this->placeholders) array(&$this->componentContext, &$view, &$placeholders)
); );
// for plugin event TODO change event api signatures unset($placeholders);
CFactory::_('Placeholder')->active = $this->placeholders;
// add the tables // add the tables
$view->addtables = (isset($view->addtables) $view->addtables = (isset($view->addtables)
@ -2343,9 +2325,8 @@ class Get
// set the view name // set the view name
$tab['view'] = $view->name_single_code; $tab['view'] = $view->name_single_code;
// load the dynamic data // load the dynamic data
$tab['html'] = CFactory::_('Placeholder')->update( $tab['html'] = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update($tab['html']), CFactory::_('Customcode')->update($tab['html'])
CFactory::_('Placeholder')->active
); );
// set the tab name // set the tab name
$tab['name'] = (isset($tab['name']) $tab['name'] = (isset($tab['name'])
@ -2425,7 +2406,7 @@ class Get
$tab['lang_permission_desc'] = $tab['lang'] $tab['lang_permission_desc'] = $tab['lang']
. '_TAB_PERMISSION_DESC'; . '_TAB_PERMISSION_DESC';
$tab['lang_permission_title'] $tab['lang_permission_title']
= CFactory::_('Placeholder')->active[Placefix::_h('Views')] . ' View ' = CFactory::_('Placeholder')->get('Views') . ' View '
. $tab['name'] . ' Tab'; . $tab['name'] . ' Tab';
CFactory::_('Language')->set( CFactory::_('Language')->set(
'both', $tab['lang_permission'], 'both', $tab['lang_permission'],
@ -2435,7 +2416,7 @@ class Get
'both', $tab['lang_permission_desc'], 'both', $tab['lang_permission_desc'],
'Allow the users in this group to view ' 'Allow the users in this group to view '
. $tab['name'] . ' Tab of ' . $tab['name'] . ' Tab of '
. CFactory::_('Placeholder')->active[Placefix::_h('views')] . CFactory::_('Placeholder')->get('views')
); );
// set the sort key // set the sort key
$tab['sortKey'] $tab['sortKey']
@ -3261,28 +3242,21 @@ class Get
} }
// for plugin event TODO change event api signatures // for plugin event TODO change event api signatures
$this->placeholders = CFactory::_('Placeholder')->active; $placeholders = CFactory::_('Placeholder')->active;
// Trigger Event: jcb_ce_onAfterModelViewData // Trigger Event: jcb_ce_onAfterModelViewData
CFactory::_('Event')->trigger( CFactory::_('Event')->trigger(
'jcb_ce_onAfterModelViewData', 'jcb_ce_onAfterModelViewData',
array(&$this->componentContext, &$view, &$this->placeholders) array(&$this->componentContext, &$view, &$placeholders)
); );
// for plugin event TODO change event api signatures unset($placeholders);
CFactory::_('Placeholder')->active = $this->placeholders;
// clear placeholders // clear placeholders
unset(CFactory::_('Placeholder')->active[Placefix::_h('view')]); CFactory::_('Placeholder')->remove('view');
unset(CFactory::_('Placeholder')->active[Placefix::_h('views')]); CFactory::_('Placeholder')->remove('views');
unset(CFactory::_('Placeholder')->active[Placefix::_h('View')]); CFactory::_('Placeholder')->remove('View');
unset(CFactory::_('Placeholder')->active[Placefix::_h('Views')]); CFactory::_('Placeholder')->remove('Views');
unset(CFactory::_('Placeholder')->active[Placefix::_h('VIEW')]); CFactory::_('Placeholder')->remove('VIEW');
unset(CFactory::_('Placeholder')->active[Placefix::_h('VIEWS')]); CFactory::_('Placeholder')->remove('VIEWS');
unset(CFactory::_('Placeholder')->active[Placefix::_('view')]);
unset(CFactory::_('Placeholder')->active[Placefix::_('views')]);
unset(CFactory::_('Placeholder')->active[Placefix::_('View')]);
unset(CFactory::_('Placeholder')->active[Placefix::_('Views')]);
unset(CFactory::_('Placeholder')->active[Placefix::_('VIEW')]);
unset(CFactory::_('Placeholder')->active[Placefix::_('VIEWS')]);
// store this view to class object // store this view to class object
$this->_adminViewData[$id] = $view; $this->_adminViewData[$id] = $view;
@ -4272,10 +4246,10 @@ class Get
$option2['operator'] $option2['operator']
= $operatorArray[$option2['operator']]; = $operatorArray[$option2['operator']];
$option2['state_key'] $option2['state_key']
= CFactory::_('Placeholder')->update( = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
$option2['state_key'] $option2['state_key']
), CFactory::_('Placeholder')->active )
); );
$option2['key'] = $result->key; $option2['key'] = $result->key;
} }
@ -6884,8 +6858,8 @@ class Get
$guiMapper = array('table' => 'joomla_module', $guiMapper = array('table' => 'joomla_module',
'id' => (int) $id, 'type' => 'php'); 'id' => (int) $id, 'type' => 'php');
// update the name if it has dynamic values // update the name if it has dynamic values
$module->name = CFactory::_('Placeholder')->update( $module->name = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update($module->name), CFactory::_('Placeholder')->active CFactory::_('Customcode')->update($module->name)
); );
// set safe class function name // set safe class function name
$module->code_name $module->code_name
@ -6927,22 +6901,17 @@ class Get
$module->key, CFactory::_('Config')->lang_prefix, $module->official_name $module->key, CFactory::_('Config')->lang_prefix, $module->official_name
); );
// set some placeholder for this module // set some placeholder for this module
CFactory::_('Placeholder')->active[Placefix::_('Module_name')] CFactory::_('Placeholder')->set('Module_name', $module->official_name);
= $module->official_name; CFactory::_('Placeholder')->set('Module', ucfirst(
CFactory::_('Placeholder')->active[Placefix::_('Module')]
= ucfirst(
$module->code_name $module->code_name
); ));
CFactory::_('Placeholder')->active[Placefix::_('module')] CFactory::_('Placeholder')->set('module', strtolower(
= strtolower(
$module->code_name $module->code_name
); ));
CFactory::_('Placeholder')->active[Placefix::_('module.version')] CFactory::_('Placeholder')->set('module.version', $module->module_version);
= $module->module_version; CFactory::_('Placeholder')->set('module_version', str_replace(
CFactory::_('Placeholder')->active[Placefix::_('module_version')]
= str_replace(
'.', '_', $module->module_version '.', '_', $module->module_version
); ));
// set description (TODO) add description field to module // set description (TODO) add description field to module
if (!isset($module->description) if (!isset($module->description)
|| !StringHelper::check( || !StringHelper::check(
@ -6953,9 +6922,8 @@ class Get
} }
else else
{ {
$module->description = CFactory::_('Placeholder')->update( $module->description = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update($module->description), CFactory::_('Customcode')->update($module->description)
CFactory::_('Placeholder')->active
); );
CFactory::_('Language')->set( CFactory::_('Language')->set(
$module->key, $module->lang_prefix . '_DESCRIPTION', $module->key, $module->lang_prefix . '_DESCRIPTION',
@ -6982,9 +6950,8 @@ class Get
// update the readme if set // update the readme if set
if ($module->addreadme == 1 && !empty($module->readme)) if ($module->addreadme == 1 && !empty($module->readme))
{ {
$module->readme = CFactory::_('Placeholder')->update( $module->readme = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update(base64_decode($module->readme)), CFactory::_('Customcode')->update(base64_decode($module->readme))
CFactory::_('Placeholder')->active
); );
} }
else else
@ -7022,12 +6989,12 @@ class Get
// base64 Decode code // base64 Decode code
$module->class_helper_header = PHP_EOL $module->class_helper_header = PHP_EOL
. CFactory::_('Customcode.Gui')->set( . CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode( base64_decode(
$module->class_helper_header $module->class_helper_header
) )
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
) . PHP_EOL; ) . PHP_EOL;
@ -7041,10 +7008,10 @@ class Get
$guiMapper['field'] = 'class_helper_code'; $guiMapper['field'] = 'class_helper_code';
// base64 Decode code // base64 Decode code
$module->class_helper_code = CFactory::_('Customcode.Gui')->set( $module->class_helper_code = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($module->class_helper_code) base64_decode($module->class_helper_code)
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
); );
@ -7071,10 +7038,10 @@ class Get
// set GUI mapper field // set GUI mapper field
$guiMapper['field'] = 'mod_code'; $guiMapper['field'] = 'mod_code';
$module->mod_code = CFactory::_('Customcode.Gui')->set( $module->mod_code = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($module->mod_code) base64_decode($module->mod_code)
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
); );
@ -7099,10 +7066,10 @@ class Get
// set GUI mapper field // set GUI mapper field
$guiMapper['field'] = 'default_header'; $guiMapper['field'] = 'default_header';
$module->default_header = CFactory::_('Customcode.Gui')->set( $module->default_header = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($module->default_header) base64_decode($module->default_header)
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
); );
@ -7119,10 +7086,10 @@ class Get
$guiMapper['field'] = 'default'; $guiMapper['field'] = 'default';
$guiMapper['type'] = 'html'; $guiMapper['type'] = 'html';
$module->default = CFactory::_('Customcode.Gui')->set( $module->default = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($module->default) base64_decode($module->default)
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
); );
@ -7464,15 +7431,14 @@ class Get
// set GUI mapper field // set GUI mapper field
$guiMapper['field'] = $scriptMethod . '_' $guiMapper['field'] = $scriptMethod . '_'
. $scriptType; . $scriptType;
$module->{$scriptMethod . '_' . $scriptType} $module->{$scriptMethod . '_' . $scriptType} = CFactory::_('Customcode.Gui')->set(
= CFactory::_('Customcode.Gui')->set( CFactory::_('Placeholder')->update_(
CFactory::_('Placeholder')->update(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode( base64_decode(
$module->{$scriptMethod . '_' $module->{$scriptMethod . '_'
. $scriptType} . $scriptType}
) )
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
); );
@ -7491,9 +7457,8 @@ class Get
if ($module->add_sql == 1 if ($module->add_sql == 1
&& StringHelper::check($module->sql)) && StringHelper::check($module->sql))
{ {
$module->sql = CFactory::_('Placeholder')->update( $module->sql = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update(base64_decode($module->sql)), CFactory::_('Customcode')->update(base64_decode($module->sql))
CFactory::_('Placeholder')->active
); );
} }
else else
@ -7507,10 +7472,10 @@ class Get
$module->sql_uninstall $module->sql_uninstall
)) ))
{ {
$module->sql_uninstall = CFactory::_('Placeholder')->update( $module->sql_uninstall = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($module->sql_uninstall) base64_decode($module->sql_uninstall)
), CFactory::_('Placeholder')->active )
); );
} }
else else
@ -7524,9 +7489,8 @@ class Get
$module->update_server_url $module->update_server_url
)) ))
{ {
$module->update_server_url = CFactory::_('Placeholder')->update( $module->update_server_url = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update($module->update_server_url), CFactory::_('Customcode')->update($module->update_server_url)
CFactory::_('Placeholder')->active
); );
} }
// add the update/sales server FTP details if that is the expected protocol // add the update/sales server FTP details if that is the expected protocol
@ -7566,17 +7530,11 @@ class Get
$this->langPrefix = $_backup_langPrefix; $this->langPrefix = $_backup_langPrefix;
CFactory::_('Config')->lang_prefix = $_backup_langPrefix; CFactory::_('Config')->lang_prefix = $_backup_langPrefix;
unset( CFactory::_('Placeholder')->remove('Module_name');
CFactory::_('Placeholder')->active[Placefix::_('Module_name')] CFactory::_('Placeholder')->remove('Module');
); CFactory::_('Placeholder')->remove('module');
unset(CFactory::_('Placeholder')->active[Placefix::_('Module')]); CFactory::_('Placeholder')->remove('module.version');
unset(CFactory::_('Placeholder')->active[Placefix::_('module')]); CFactory::_('Placeholder')->remove('module_version');
unset(
CFactory::_('Placeholder')->active[Placefix::_('module.version')]
);
unset(
CFactory::_('Placeholder')->active[Placefix::_('module_version')]
);
$this->joomlaModules[$id] = $module; $this->joomlaModules[$id] = $module;
@ -7801,8 +7759,8 @@ class Get
$guiMapper = array('table' => 'joomla_plugin', $guiMapper = array('table' => 'joomla_plugin',
'id' => (int) $id, 'type' => 'php'); 'id' => (int) $id, 'type' => 'php');
// update the name if it has dynamic values // update the name if it has dynamic values
$plugin->name = CFactory::_('Placeholder')->update( $plugin->name = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update($plugin->name), CFactory::_('Placeholder')->active CFactory::_('Customcode')->update($plugin->name)
); );
// update the name if it has dynamic values // update the name if it has dynamic values
$plugin->code_name $plugin->code_name
@ -7852,37 +7810,19 @@ class Get
$plugin->key, CFactory::_('Config')->lang_prefix, $plugin->official_name $plugin->key, CFactory::_('Config')->lang_prefix, $plugin->official_name
); );
// set some placeholder for this plugin // set some placeholder for this plugin
CFactory::_('Placeholder')->active[Placefix::_('Plugin_name')] CFactory::_('Placeholder')->set('Plugin_name', $plugin->official_name);
= $plugin->official_name; CFactory::_('Placeholder')->set('PLUGIN_NAME', $plugin->official_name);
CFactory::_('Placeholder')->active[Placefix::_h('PLUGIN_NAME')] CFactory::_('Placeholder')->set('Plugin', ucfirst($plugin->code_name));
= $plugin->official_name; CFactory::_('Placeholder')->set('plugin', strtolower($plugin->code_name));
CFactory::_('Placeholder')->active[Placefix::_('Plugin')] CFactory::_('Placeholder')->set('Plugin_group', ucfirst($plugin->group));
= ucfirst( CFactory::_('Placeholder')->set('plugin_group', strtolower($plugin->group));
$plugin->code_name CFactory::_('Placeholder')->set('plugin.version', $plugin->plugin_version);
); CFactory::_('Placeholder')->set('VERSION', $plugin->plugin_version);
CFactory::_('Placeholder')->active[Placefix::_('plugin')] CFactory::_('Placeholder')->set('plugin_version', str_replace(
= strtolower(
$plugin->code_name
);
CFactory::_('Placeholder')->active[Placefix::_('Plugin_group')]
= ucfirst(
$plugin->group
);
CFactory::_('Placeholder')->active[Placefix::_('plugin_group')]
= strtolower(
$plugin->group
);
CFactory::_('Placeholder')->active[Placefix::_('plugin.version')]
= $plugin->plugin_version;
CFactory::_('Placeholder')->active[Placefix::_h('VERSION')]
= $plugin->plugin_version;
CFactory::_('Placeholder')->active[Placefix::_('plugin_version')]
= str_replace(
'.', '_', $plugin->plugin_version '.', '_', $plugin->plugin_version
); ));
// set description // set description
CFactory::_('Placeholder')->active[Placefix::_h('DESCRIPTION')] CFactory::_('Placeholder')->set('DESCRIPTION', '');
= '';
if (!isset($plugin->description) if (!isset($plugin->description)
|| !StringHelper::check( || !StringHelper::check(
$plugin->description $plugin->description
@ -7892,19 +7832,16 @@ class Get
} }
else else
{ {
$plugin->description = CFactory::_('Placeholder')->update( $plugin->description = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update($plugin->description), CFactory::_('Customcode')->update($plugin->description)
CFactory::_('Placeholder')->active
); );
CFactory::_('Language')->set( CFactory::_('Language')->set(
$plugin->key, $plugin->lang_prefix . '_DESCRIPTION', $plugin->key, $plugin->lang_prefix . '_DESCRIPTION',
$plugin->description $plugin->description
); );
// set description // set description
CFactory::_('Placeholder')->active[Placefix::_h('DESCRIPTION')] CFactory::_('Placeholder')->set('DESCRIPTION', $plugin->description);
= $plugin->description; $plugin->description = '<p>' . $plugin->description . '</p>';
$plugin->description = '<p>' . $plugin->description
. '</p>';
} }
$plugin->xml_description = "<h1>" . $plugin->official_name $plugin->xml_description = "<h1>" . $plugin->official_name
. " (v." . $plugin->plugin_version . " (v." . $plugin->plugin_version
@ -7924,9 +7861,8 @@ class Get
// update the readme if set // update the readme if set
if ($plugin->addreadme == 1 && !empty($plugin->readme)) if ($plugin->addreadme == 1 && !empty($plugin->readme))
{ {
$plugin->readme = CFactory::_('Placeholder')->update( $plugin->readme = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update(base64_decode($plugin->readme)), CFactory::_('Customcode')->update(base64_decode($plugin->readme))
CFactory::_('Placeholder')->active
); );
} }
else else
@ -7941,10 +7877,10 @@ class Get
$guiMapper['field'] = 'main_class_code'; $guiMapper['field'] = 'main_class_code';
// base64 Decode main_class_code. // base64 Decode main_class_code.
$plugin->main_class_code = CFactory::_('Customcode.Gui')->set( $plugin->main_class_code = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($plugin->main_class_code) base64_decode($plugin->main_class_code)
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
); );
@ -7956,10 +7892,10 @@ class Get
$guiMapper['field'] = 'head'; $guiMapper['field'] = 'head';
// base64 Decode head. // base64 Decode head.
$plugin->head = CFactory::_('Customcode.Gui')->set( $plugin->head = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($plugin->head) base64_decode($plugin->head)
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
); );
@ -7968,10 +7904,10 @@ class Get
{ {
// base64 Decode head. // base64 Decode head.
$plugin->head = CFactory::_('Customcode.Gui')->set( $plugin->head = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($plugin->class_head) base64_decode($plugin->class_head)
), CFactory::_('Placeholder')->active )
), ),
array( array(
'table' => 'class_extends', 'table' => 'class_extends',
@ -7986,10 +7922,10 @@ class Get
{ {
// base64 Decode comment. // base64 Decode comment.
$plugin->comment = CFactory::_('Customcode.Gui')->set( $plugin->comment = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($plugin->comment) base64_decode($plugin->comment)
), CFactory::_('Placeholder')->active )
), ),
array( array(
'table' => 'class_extends', 'table' => 'class_extends',
@ -8292,13 +8228,13 @@ class Get
. $scriptType; . $scriptType;
$plugin->{$scriptMethod . '_' . $scriptType} $plugin->{$scriptMethod . '_' . $scriptType}
= CFactory::_('Customcode.Gui')->set( = CFactory::_('Customcode.Gui')->set(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode( base64_decode(
$plugin->{$scriptMethod . '_' $plugin->{$scriptMethod . '_'
. $scriptType} . $scriptType}
) )
), CFactory::_('Placeholder')->active )
), ),
$guiMapper $guiMapper
); );
@ -8317,9 +8253,8 @@ class Get
if ($plugin->add_sql == 1 if ($plugin->add_sql == 1
&& StringHelper::check($plugin->sql)) && StringHelper::check($plugin->sql))
{ {
$plugin->sql = CFactory::_('Placeholder')->update( $plugin->sql = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update(base64_decode($plugin->sql)), CFactory::_('Customcode')->update(base64_decode($plugin->sql))
CFactory::_('Placeholder')->active
); );
} }
else else
@ -8333,10 +8268,10 @@ class Get
$plugin->sql_uninstall $plugin->sql_uninstall
)) ))
{ {
$plugin->sql_uninstall = CFactory::_('Placeholder')->update( $plugin->sql_uninstall = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update( CFactory::_('Customcode')->update(
base64_decode($plugin->sql_uninstall) base64_decode($plugin->sql_uninstall)
), CFactory::_('Placeholder')->active )
); );
} }
else else
@ -8350,9 +8285,8 @@ class Get
$plugin->update_server_url $plugin->update_server_url
)) ))
{ {
$plugin->update_server_url = CFactory::_('Placeholder')->update( $plugin->update_server_url = CFactory::_('Placeholder')->update_(
CFactory::_('Customcode')->update($plugin->update_server_url), CFactory::_('Customcode')->update($plugin->update_server_url)
CFactory::_('Placeholder')->active
); );
} }
// add the update/sales server FTP details if that is the expected protocol // add the update/sales server FTP details if that is the expected protocol
@ -8392,32 +8326,16 @@ class Get
$this->langPrefix = $_backup_langPrefix; $this->langPrefix = $_backup_langPrefix;
CFactory::_('Config')->set('lang_prefix', $_backup_langPrefix); CFactory::_('Config')->set('lang_prefix', $_backup_langPrefix);
unset( CFactory::_('Placeholder')->remove('Plugin_name');
CFactory::_('Placeholder')->active[Placefix::_('Plugin_name')] CFactory::_('Placeholder')->remove('Plugin');
); CFactory::_('Placeholder')->remove('plugin');
unset(CFactory::_('Placeholder')->active[Placefix::_('Plugin')]); CFactory::_('Placeholder')->remove('Plugin_group');
unset(CFactory::_('Placeholder')->active[Placefix::_('plugin')]); CFactory::_('Placeholder')->remove('plugin_group');
unset( CFactory::_('Placeholder')->remove('plugin.version');
CFactory::_('Placeholder')->active[Placefix::_('Plugin_group')] CFactory::_('Placeholder')->remove('plugin_version');
); CFactory::_('Placeholder')->remove('VERSION');
unset( CFactory::_('Placeholder')->remove('DESCRIPTION');
CFactory::_('Placeholder')->active[Placefix::_('plugin_group')] CFactory::_('Placeholder')->remove('PLUGIN_NAME');
);
unset(
CFactory::_('Placeholder')->active[Placefix::_('plugin.version')]
);
unset(
CFactory::_('Placeholder')->active[Placefix::_('plugin_version')]
);
unset(
CFactory::_('Placeholder')->active[Placefix::_h('VERSION')]
);
unset(
CFactory::_('Placeholder')->active[Placefix::_h('DESCRIPTION')]
);
unset(
CFactory::_('Placeholder')->active[Placefix::_h('PLUGIN_NAME')]
);
$this->joomlaPlugins[$id] = $plugin; $this->joomlaPlugins[$id] = $plugin;

View File

@ -3087,8 +3087,8 @@ class Structure extends Get
'//', '/', $custom['file'] '//', '/', $custom['file']
); );
// update the dynamic component name placholders in file names // update the dynamic component name placholders in file names
$custom['path'] = CFactory::_('Placeholder')->update( $custom['path'] = CFactory::_('Placeholder')->update_(
$custom['path'], CFactory::_('Placeholder')->active $custom['path']
); );
// get the path info // get the path info
$pathInfo = pathinfo($custom['path']); $pathInfo = pathinfo($custom['path']);
@ -3227,10 +3227,10 @@ class Structure extends Get
*/ */
protected function updateDynamicPath($path) protected function updateDynamicPath($path)
{ {
return CFactory::_('Placeholder')->update( return CFactory::_('Placeholder')->update_(
CFactory::_('Placeholder')->update( CFactory::_('Placeholder')->update(
$path, ComponentbuilderHelper::$constantPaths $path, ComponentbuilderHelper::$constantPaths
), CFactory::_('Placeholder')->active )
); );
} }

View File

@ -403,9 +403,9 @@ class Fields extends Structure
} }
// main lang prefix // main lang prefix
$langView = CFactory::_('Config')->lang_prefix . '_' $langView = CFactory::_('Config')->lang_prefix . '_'
. CFactory::_('Placeholder')->active[Placefix::_h('VIEW')]; . CFactory::_('Placeholder')->get('VIEW');
$langViews = CFactory::_('Config')->lang_prefix . '_' $langViews = CFactory::_('Config')->lang_prefix . '_'
. CFactory::_('Placeholder')->active[Placefix::_h('VIEWS')]; . CFactory::_('Placeholder')->get('VIEWS');
// set default lang // set default lang
CFactory::_('Language')->set( CFactory::_('Language')->set(
CFactory::_('Config')->lang_target, $langView, $view['settings']->name_single CFactory::_('Config')->lang_target, $langView, $view['settings']->name_single
@ -607,17 +607,16 @@ class Fields extends Structure
// set the custom table key // set the custom table key
$dbkey = 'g'; $dbkey = 'g';
// for plugin event TODO change event api signatures // for plugin event TODO change event api signatures
$this->placeholders = CFactory::_('Placeholder')->active; $placeholders = CFactory::_('Placeholder')->active;
// Trigger Event: jcb_ce_onBeforeBuildFields // Trigger Event: jcb_ce_onBeforeBuildFields
CFactory::_('Event')->trigger( CFactory::_('Event')->trigger(
'jcb_ce_onBeforeBuildFields', 'jcb_ce_onBeforeBuildFields',
array(&$this->componentContext, &$dynamicFields, &$readOnly, array(&$this->componentContext, &$dynamicFields, &$readOnly,
&$dbkey, &$view, &$component, &$nameSingleCode, &$dbkey, &$view, &$component, &$nameSingleCode,
&$nameListCode, &$this->placeholders, &$langView, &$nameListCode, &$placeholders, &$langView,
&$langViews) &$langViews)
); );
// for plugin event TODO change event api signatures unset($placeholders);
CFactory::_('Placeholder')->active = $this->placeholders;
// TODO we should add the global and local view switch if field for front end // TODO we should add the global and local view switch if field for front end
foreach ($view['settings']->fields as $field) foreach ($view['settings']->fields as $field)
{ {
@ -628,17 +627,16 @@ class Fields extends Structure
); );
} }
// for plugin event TODO change event api signatures // for plugin event TODO change event api signatures
$this->placeholders = CFactory::_('Placeholder')->active; $placeholders = CFactory::_('Placeholder')->active;
// Trigger Event: jcb_ce_onAfterBuildFields // Trigger Event: jcb_ce_onAfterBuildFields
CFactory::_('Event')->trigger( CFactory::_('Event')->trigger(
'jcb_ce_onAfterBuildFields', 'jcb_ce_onAfterBuildFields',
array(&$this->componentContext, &$dynamicFields, &$readOnly, array(&$this->componentContext, &$dynamicFields, &$readOnly,
&$dbkey, &$view, &$component, &$nameSingleCode, &$dbkey, &$view, &$component, &$nameSingleCode,
&$nameListCode, &$this->placeholders, &$langView, &$nameListCode, &$placeholders, &$langView,
&$langViews) &$langViews)
); );
// for plugin event TODO change event api signatures unset($placeholders);
CFactory::_('Placeholder')->active = $this->placeholders;
// set the default fields // set the default fields
$fieldSet = array(); $fieldSet = array();
$fieldSet[] = '<fieldset name="details">'; $fieldSet[] = '<fieldset name="details">';
@ -1026,17 +1024,16 @@ class Fields extends Structure
// set the custom table key // set the custom table key
$dbkey = 'g'; $dbkey = 'g';
// for plugin event TODO change event api signatures // for plugin event TODO change event api signatures
$this->placeholders = CFactory::_('Placeholder')->active; $placeholders = CFactory::_('Placeholder')->active;
// Trigger Event: jcb_ce_onBeforeBuildFields // Trigger Event: jcb_ce_onBeforeBuildFields
CFactory::_('Event')->trigger( CFactory::_('Event')->trigger(
'jcb_ce_onBeforeBuildFields', 'jcb_ce_onBeforeBuildFields',
array(&$this->componentContext, &$dynamicFieldsXML, &$readOnlyXML, array(&$this->componentContext, &$dynamicFieldsXML, &$readOnlyXML,
&$dbkey, &$view, &$component, &$nameSingleCode, &$dbkey, &$view, &$component, &$nameSingleCode,
&$nameListCode, &$this->placeholders, &$langView, &$nameListCode, &$placeholders, &$langView,
&$langViews) &$langViews)
); );
// for plugin event TODO change event api signatures unset($placeholders);
CFactory::_('Placeholder')->active = $this->placeholders;
// TODO we should add the global and local view switch if field for front end // TODO we should add the global and local view switch if field for front end
foreach ($view['settings']->fields as $field) foreach ($view['settings']->fields as $field)
{ {
@ -1047,17 +1044,16 @@ class Fields extends Structure
); );
} }
// for plugin event TODO change event api signatures // for plugin event TODO change event api signatures
$this->placeholders = CFactory::_('Placeholder')->active; $placeholders = CFactory::_('Placeholder')->active;
// Trigger Event: jcb_ce_onAfterBuildFields // Trigger Event: jcb_ce_onAfterBuildFields
CFactory::_('Event')->trigger( CFactory::_('Event')->trigger(
'jcb_ce_onAfterBuildFields', 'jcb_ce_onAfterBuildFields',
array(&$this->componentContext, &$dynamicFieldsXML, &$readOnlyXML, array(&$this->componentContext, &$dynamicFieldsXML, &$readOnlyXML,
&$dbkey, &$view, &$component, &$nameSingleCode, &$dbkey, &$view, &$component, &$nameSingleCode,
&$nameListCode, &$this->placeholders, &$langView, &$nameListCode, &$placeholders, &$langView,
&$langViews) &$langViews)
); );
// for plugin event TODO change event api signatures unset($placeholders);
CFactory::_('Placeholder')->active = $this->placeholders;
// set the default fields // set the default fields
$XML = new simpleXMLElement('<a/>'); $XML = new simpleXMLElement('<a/>');
$fieldSetXML = $XML->addChild('fieldset'); $fieldSetXML = $XML->addChild('fieldset');
@ -4752,11 +4748,11 @@ class Fields extends Structure
else else
{ {
// get it from the field xml string // get it from the field xml string
$listFieldName = (string) CFactory::_('Placeholder')->update( $listFieldName = (string) CFactory::_('Placeholder')->update_(
GetHelper::between( GetHelper::between(
$field['settings']->xml, 'label="', $field['settings']->xml, 'label="',
'"' '"'
), CFactory::_('Placeholder')->active )
); );
} }
// make sure there is no html in the list field name // make sure there is no html in the list field name
@ -4954,10 +4950,10 @@ class Fields extends Structure
$otherView = $nameSingleCode; $otherView = $nameSingleCode;
} }
// get the xml extension name // get the xml extension name
$_extension = CFactory::_('Placeholder')->update( $_extension = CFactory::_('Placeholder')->update_(
GetHelper::between( GetHelper::between(
$field['settings']->xml, 'extension="', '"' $field['settings']->xml, 'extension="', '"'
), CFactory::_('Placeholder')->active )
); );
// if they left out the extension for some reason // if they left out the extension for some reason
if (!StringHelper::check($_extension)) if (!StringHelper::check($_extension))
@ -5332,12 +5328,11 @@ class Fields extends Structure
if (isset($data['custom']) && isset($data['custom']['extends']) if (isset($data['custom']) && isset($data['custom']['extends'])
&& ((isset($data['custom']['prime_php']) && ((isset($data['custom']['prime_php'])
&& $data['custom']['prime_php'] == 1) && $data['custom']['prime_php'] == 1)
|| !isset( || !CFactory::_('Content')->exist_('customfield_' . $data['type'])
$this->fileContentDynamic['customfield_' . $data['type']]
)
|| !ArrayHelper::check( || !ArrayHelper::check(
$this->fileContentDynamic['customfield_' . $data['type']] CFactory::_('Content')->get_('customfield_' . $data['type'])
))) )
))
{ {
// set J prefix // set J prefix
$jprefix = 'J'; $jprefix = 'J';
@ -5416,18 +5411,17 @@ class Fields extends Structure
$replace[$globalPlaceholder] = $gloabalValue; $replace[$globalPlaceholder] = $gloabalValue;
} }
// start loading the field type // start loading the field type
$this->fileContentDynamic['customfield_' . $data['type']] = array(); // $this->fileContentDynamic['customfield_' . $data['type']] = array();
// JPREFIX <<<DYNAMIC>>> // JPREFIX <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' . $data['type']][Placefix::_h('JPREFIX')] CFactory::_('Content')->set_('customfield_' . $data['type'], 'JPREFIX', $jprefix);
= $jprefix;
// Type <<<DYNAMIC>>> // Type <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' . $data['type']][Placefix::_h('Type')] CFactory::_('Content')->set_('customfield_' . $data['type'], 'Type',
= StringHelper::safe( StringHelper::safe(
$data['custom']['type'], 'F' $data['custom']['type'], 'F'
)
); );
// type <<<DYNAMIC>>> // type <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' . $data['type']][Placefix::_h('type')] CFactory::_('Content')->set_('customfield_' . $data['type'], 'type', StringHelper::safe($data['custom']['type']));
= StringHelper::safe($data['custom']['type']);
// is this a own custom field // is this a own custom field
if (isset($data['custom']['own_custom'])) if (isset($data['custom']['own_custom']))
{ {
@ -5457,28 +5451,28 @@ class Fields extends Structure
); );
// JFORM_TYPE_HEADER <<<DYNAMIC>>> // JFORM_TYPE_HEADER <<<DYNAMIC>>>
$add_default_header = true; $add_default_header = true;
$this->fileContentDynamic['customfield_' CFactory::_('Content')->set_('customfield_' . $data['type'], 'JFORM_TYPE_HEADER',
. $data['type']][Placefix::_h('JFORM_TYPE_HEADER')] "//" . Line::_(
= "//" . Line::_(
__LINE__,__CLASS__ __LINE__,__CLASS__
) . " Import the " . $JFORM_extends ) . " Import the " . $JFORM_extends
. " field type classes needed"; . " field type classes needed"
);
// JFORM_extens <<<DYNAMIC>>> // JFORM_extens <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' CFactory::_('Content')->set_('customfield_' . $data['type'],
. $data['type']][Placefix::_h('JFORM_extends')] 'JFORM_extends', $JFORM_extends
= $JFORM_extends; );
// JFORM_EXTENDS <<<DYNAMIC>>> // JFORM_EXTENDS <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' CFactory::_('Content')->set_('customfield_' . $data['type'], 'JFORM_EXTENDS',
. $data['type']][Placefix::_h('JFORM_EXTENDS')] StringHelper::safe(
= StringHelper::safe(
$data['custom']['extends'], 'F' $data['custom']['extends'], 'F'
)
); );
// JFORM_TYPE_PHP <<<DYNAMIC>>> // JFORM_TYPE_PHP <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' CFactory::_('Content')->set_('customfield_' . $data['type'], 'JFORM_TYPE_PHP',
. $data['type']][Placefix::_h('JFORM_TYPE_PHP')] PHP_EOL . PHP_EOL . Indent::_(1) . "//" . Line::_(
= PHP_EOL . PHP_EOL . Indent::_(1) . "//" . Line::_(
__LINE__,__CLASS__ __LINE__,__CLASS__
) . " A " . $data['custom']['own_custom'] . " Field"; ) . " A " . $data['custom']['own_custom'] . " Field"
);
// load the other PHP options // load the other PHP options
foreach (ComponentbuilderHelper::$phpFieldArray as $x) foreach (ComponentbuilderHelper::$phpFieldArray as $x)
{ {
@ -5502,10 +5496,10 @@ class Fields extends Structure
// check if this is header text // check if this is header text
if ('HEADER' === $x) if ('HEADER' === $x)
{ {
$this->fileContentDynamic['customfield_' CFactory::_('Content')->add_('customfield_' . $data['type'], 'JFORM_TYPE_HEADER',
. $data['type']][Placefix::_h('JFORM_TYPE_HEADER')] PHP_EOL . CFactory::_('Placeholder')->update(
.= PHP_EOL . CFactory::_('Placeholder')->update(
$phpBucket, $replace $phpBucket, $replace
)
); );
// stop default headers from loading // stop default headers from loading
$add_default_header = false; $add_default_header = false;
@ -5513,10 +5507,10 @@ class Fields extends Structure
else else
{ {
// JFORM_TYPE_PHP <<<DYNAMIC>>> // JFORM_TYPE_PHP <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' CFactory::_('Content')->add_('customfield_' . $data['type'], 'JFORM_TYPE_PHP',
. $data['type']][Placefix::_h('JFORM_TYPE_PHP')] PHP_EOL . CFactory::_('Placeholder')->update(
.= PHP_EOL . CFactory::_('Placeholder')->update(
$phpBucket, $replace $phpBucket, $replace
)
); );
} }
} }
@ -5524,24 +5518,21 @@ class Fields extends Structure
// check if we should add default header // check if we should add default header
if ($add_default_header) if ($add_default_header)
{ {
$this->fileContentDynamic['customfield_' CFactory::_('Content')->add_('customfield_' . $data['type'], 'JFORM_TYPE_HEADER',
. $data['type']][Placefix::_h('JFORM_TYPE_HEADER')] PHP_EOL . "jimport('joomla.form.helper');"
.= PHP_EOL . "jimport('joomla.form.helper');"; );
$this->fileContentDynamic['customfield_' CFactory::_('Content')->add_('customfield_' . $data['type'], 'JFORM_TYPE_HEADER',
. $data['type']][Placefix::_h('JFORM_TYPE_HEADER')] PHP_EOL . "JFormHelper::loadFieldClass('" . $JFORM_extends . "');"
.= PHP_EOL . "JFormHelper::loadFieldClass('" );
. $JFORM_extends . "');";
} }
// check the the JFormHelper::loadFieldClass(..) was set // check the the JFormHelper::loadFieldClass(..) was set
elseif (strpos( elseif (strpos(CFactory::_('Content')->get_('customfield_' . $data['type'], 'JFORM_TYPE_HEADER'),
$this->fileContentDynamic['customfield_' 'JFormHelper::loadFieldClass(') === false)
. $data['type']][Placefix::_h('JFORM_TYPE_HEADER')], 'JFormHelper::loadFieldClass('
) === false)
{ {
$this->fileContentDynamic['customfield_' CFactory::_('Content')->add_('customfield_' . $data['type'], 'JFORM_TYPE_HEADER',
. $data['type']][Placefix::_h('JFORM_TYPE_HEADER')] PHP_EOL . "JFormHelper::loadFieldClass('"
.= PHP_EOL . "JFormHelper::loadFieldClass('" . $JFORM_extends . "');"
. $JFORM_extends . "');"; );
} }
} }
else else
@ -5637,25 +5628,25 @@ class Fields extends Structure
// build the Group Control // build the Group Control
$this->setGroupControl[$data['type']] = $groupLangName; $this->setGroupControl[$data['type']] = $groupLangName;
// JFORM_GETGROUPS_PHP <<<DYNAMIC>>> // JFORM_GETGROUPS_PHP <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' CFactory::_('Content')->set_('customfield_' . $data['type'], 'JFORM_GETGROUPS_PHP',
. $data['type']][Placefix::_h('JFORM_GETGROUPS_PHP')] $phpCode
= $phpCode; );
// JFORM_GETEXCLUDED_PHP <<<DYNAMIC>>> // JFORM_GETEXCLUDED_PHP <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' CFactory::_('Content')->set_('customfield_' . $data['type'], 'JFORM_GETEXCLUDED_PHP',
. $data['type']][Placefix::_h('JFORM_GETEXCLUDED_PHP')] $phpxCode
= $phpxCode; );
} }
else else
{ {
// JFORM_GETOPTIONS_PHP <<<DYNAMIC>>> // JFORM_GETOPTIONS_PHP <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' CFactory::_('Content')->set_('customfield_' . $data['type'], 'JFORM_GETOPTIONS_PHP',
. $data['type']][Placefix::_h('JFORM_GETOPTIONS_PHP')] $phpCode
= $phpCode; );
} }
// type <<<DYNAMIC>>> // type <<<DYNAMIC>>>
$this->fileContentDynamic['customfield_' CFactory::_('Content')->set_('customfield_' . $data['type'], 'ADD_BUTTON',
. $data['type']][Placefix::_h('ADD_BUTTON')] $this->setAddButtonToListField($data['custom'])
= $this->setAddButtonToListField($data['custom']); );
} }
} }
// if this field gets used in plugin or module we should track it so if needed we can copy it over // if this field gets used in plugin or module we should track it so if needed we can copy it over
@ -6065,42 +6056,34 @@ class Fields extends Structure
public function setFilterFieldFile($getOptions, $filter) public function setFilterFieldFile($getOptions, $filter)
{ {
// make sure it is not already been build // make sure it is not already been build
if (!isset( if (!CFactory::_('Content')->exist_('customfilterfield_' . $filter['filter_type'])
$this->fileContentDynamic['customfilterfield_'
. $filter['filter_type']]
)
|| !ArrayHelper::check( || !ArrayHelper::check(
$this->fileContentDynamic['customfilterfield_' CFactory::_('Content')->get_('customfilterfield_' . $filter['filter_type'])
. $filter['filter_type']]
) )
) )
{ {
// start loading the field type // start loading the field type
$this->fileContentDynamic['customfilterfield_' // $this->fileContentDynamic['customfilterfield_'
. $filter['filter_type']] // . $filter['filter_type']]
= array(); // = array();
// JPREFIX <<DYNAMIC>>> // JPREFIX <<DYNAMIC>>>
$this->fileContentDynamic['customfilterfield_' CFactory::_('Content')->set_('customfilterfield_' . $filter['filter_type'], 'JPREFIX', 'J');
. $filter['filter_type']][Placefix::_h('JPREFIX')]
= 'J';
// Type <<<DYNAMIC>>> // Type <<<DYNAMIC>>>
$this->fileContentDynamic['customfilterfield_' CFactory::_('Content')->set_('customfilterfield_' . $filter['filter_type'], 'Type',
. $filter['filter_type']][Placefix::_h('Type')] StringHelper::safe(
= StringHelper::safe(
$filter['filter_type'], 'F' $filter['filter_type'], 'F'
)
); );
// type <<<DYNAMIC>>> // type <<<DYNAMIC>>>
$this->fileContentDynamic['customfilterfield_' CFactory::_('Content')->set_('customfilterfield_' . $filter['filter_type'], 'type',
. $filter['filter_type']][Placefix::_h('type')] StringHelper::safe($filter['filter_type'])
= StringHelper::safe($filter['filter_type']); );
// JFORM_GETOPTIONS_PHP <<<DYNAMIC>>> // JFORM_GETOPTIONS_PHP <<<DYNAMIC>>>
$this->fileContentDynamic['customfilterfield_' CFactory::_('Content')->set_('customfilterfield_' . $filter['filter_type'], 'JFORM_GETOPTIONS_PHP',
. $filter['filter_type']][Placefix::_h('JFORM_GETOPTIONS_PHP')] $getOptions
= $getOptions; );
// ADD_BUTTON <<<DYNAMIC>>> // ADD_BUTTON <<<DYNAMIC>>>
$this->fileContentDynamic['customfilterfield_' CFactory::_('Content')->set_('customfilterfield_' . $filter['filter_type'], 'ADD_BUTTON', '');
. $filter['filter_type']][Placefix::_h('ADD_BUTTON')]
= '';
// now build the custom filter field type file // now build the custom filter field type file
$target = array('admin' => 'customfilterfield'); $target = array('admin' => 'customfilterfield');
$this->buildDynamique( $this->buildDynamique(
@ -6153,8 +6136,8 @@ class Fields extends Structure
$fieldData['component'], Placefix::b() $fieldData['component'], Placefix::b()
) !== false) // should not be needed... but ) !== false) // should not be needed... but
{ {
$fieldData['component'] = CFactory::_('Placeholder')->update( $fieldData['component'] = CFactory::_('Placeholder')->update_(
$fieldData['component'], CFactory::_('Placeholder')->active $fieldData['component']
); );
} }
// get core permissions // get core permissions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="4" method="upgrade"> <extension type="component" version="4" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>4th December, 2022</creationDate> <creationDate>11th December, 2022</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>joomla@vdm.io</authorEmail> <authorEmail>joomla@vdm.io</authorEmail>
<authorUrl>https://dev.vdm.io</authorUrl> <authorUrl>https://dev.vdm.io</authorUrl>

View File

@ -417,5 +417,27 @@ class Config extends BaseConfig
return false; return false;
} }
/**
* Should we remove the site folder
*
* @return bool Switch to control the removal
* @since 3.2.0
*/
protected function getRemovesitefolder(): bool
{
return false;
}
/**
* Should we remove the site edit folder
*
* @return bool Switch to control the removal
* @since 3.2.0
*/
protected function getRemovesiteeditfolder(): bool
{
return true;
}
} }

View File

@ -104,6 +104,19 @@ class Content
} }
} }
/**
* Remove content
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove(string $key)
{
unset($this->active[Placefix::_h($key)]);
}
/** /**
* Set dynamic content * Set dynamic content
* *
@ -123,14 +136,14 @@ class Content
* Get dynamic content * Get dynamic content
* *
* @param string $view The view key * @param string $view The view key
* @param string $key The main string key * @param string|null $key The main string key
* *
* @return mixed * @return mixed
* @since 3.2.0 * @since 3.2.0
*/ */
public function get_(string $view, string $key = null) public function get_(string $view, ?string $key = null)
{ {
if (!is_null($key)) if (is_string($key))
{ {
return $this->_active[$view][Placefix::_h($key)] ?? null; return $this->_active[$view][Placefix::_h($key)] ?? null;
} }
@ -141,18 +154,22 @@ class Content
* Does view key exist * Does view key exist
* *
* @param string $view The view key * @param string $view The view key
* @param string $key The main string key * @param string|null $key The main string key
* *
* @return bool * @return bool
* @since 3.2.0 * @since 3.2.0
*/ */
public function exist_(string $view, string $key): bool public function exist_(string $view, ?string $key = null): bool
{ {
if (isset($this->_active[$view]) && if (is_string($key) && isset($this->_active[$view]) &&
isset($this->_active[$view][Placefix::_h($key)])) isset($this->_active[$view][Placefix::_h($key)]))
{ {
return true; return true;
} }
elseif (is_null($key) && isset($this->_active[$view]))
{
return true;
}
return false; return false;
} }
@ -179,5 +196,26 @@ class Content
} }
} }
/**
* Remove dynamic content
*
* @param string $view The view key
* @param string|null $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove_(string $view, ?string $key = null)
{
if (is_string($key))
{
unset($this->_active[$view][Placefix::_h($key)]);
}
else
{
unset($this->_active[$view]);
}
}
} }

View File

@ -19,6 +19,164 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces;
*/ */
interface PlaceholderInterface interface PlaceholderInterface
{ {
/**
* Set content
*
* @param string $key The main string key
* @param mixed $value The values to set
* @param bool $hash Add the hash around the key
*
* @return void
* @since 3.2.0
*/
public function set(string $key, $value, bool $hash = true);
/**
* Get content by key
*
* @param string $key The main string key
*
* @return mixed
* @since 3.2.0
*/
public function get(string $key);
/**
* Does key exist at all in any variation
*
* @param string $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist(string $key): bool;
/**
* Add content
*
* @param string $key The main string key
* @param mixed $value The values to set
* @param bool $hash Add the hash around the key
*
* @return void
* @since 3.2.0
*/
public function add(string $key, $value, bool $hash = true);
/**
* Remove content
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove(string $key);
/**
* Set content with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set_(string $key, $value);
/**
* Get content with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
*
* @return mixed
* @since 3.2.0
*/
public function get_(string $key);
/**
* Does key exist with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist_(string $key): bool;
/**
* Add content with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add_(string $key, $value);
/**
* Remove content with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove_(string $key);
/**
* Set content with # # # hash
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set_h(string $key, $value);
/**
* Get content with # # # hash
*
* @param string $key The main string key
*
* @return mixed
* @since 3.2.0
*/
public function get_h(string $key);
/**
* Does key exist with # # # hash
*
* @param string $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist_h(string $key): bool;
/**
* Add content with # # # hash
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add_h(string $key, $value);
/**
* Remove content with # # # hash
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove_h(string $key);
/** /**
* Set a type of placeholder with set of values * Set a type of placeholder with set of values
* *
@ -57,6 +215,16 @@ interface PlaceholderInterface
*/ */
public function update(string $data, array &$placeholder, int $action = 1): string; public function update(string $data, array &$placeholder, int $action = 1): string;
/**
* Update the data with the active placeholders
*
* @param string $data The actual data
*
* @return string
* @since 3.2.0
*/
public function update_(string $data): string;
/** /**
* return the placeholders for inserted and replaced code * return the placeholders for inserted and replaced code
* *

View File

@ -13,8 +13,6 @@ namespace VDM\Joomla\Componentbuilder\Compiler;
use VDM\Joomla\Utilities\ArrayHelper; use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler; use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use VDM\Joomla\Componentbuilder\Compiler\Config; use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix; use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
@ -56,6 +54,270 @@ class Placeholder implements PlaceholderInterface
$this->config = $config ?: Compiler::_('Config'); $this->config = $config ?: Compiler::_('Config');
} }
/**
* Set content
*
* @param string $key The main string key
* @param mixed $value The values to set
* @param bool $hash Add the hash around the key
*
* @return void
* @since 3.2.0
*/
public function set(string $key, $value, bool $hash = true)
{
if ($hash)
{
$this->set_($key, $value);
$this->set_h($key, $value);
}
else
{
$this->active[$key] = $value;
}
}
/**
* Get content by key
*
* @param string $key The main string key
*
* @return mixed
* @since 3.2.0
*/
public function get(string $key)
{
return $this->active[$key] ?? $this->get_($key) ?? $this->get_h($key) ?? null;
}
/**
* Does key exist at all in any variation
*
* @param string $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist(string $key): bool
{
if (isset($this->active[$key]) || $this->exist_($key) || $this->exist_h($key))
{
return true;
}
return false;
}
/**
* Add content
*
* @param string $key The main string key
* @param mixed $value The values to set
* @param bool $hash Add the hash around the key
*
* @return void
* @since 3.2.0
*/
public function add(string $key, $value, bool $hash = true)
{
if ($hash)
{
$this->add_($key, $value);
$this->add_h($key, $value);
}
elseif (isset($this->active[$key]))
{
$this->active[$key] .= $value;
}
else
{
$this->active[$key] = $value;
}
}
/**
* Remove content
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove(string $key)
{
if (isset($this->active[$key]))
{
unset($this->active[$key]);
}
else
{
$this->remove_($key);
$this->remove_h($key);
}
}
/**
* Set content with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set_(string $key, $value)
{
$this->active[Placefix::_($key)] = $value;
}
/**
* Get content with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
*
* @return mixed
* @since 3.2.0
*/
public function get_(string $key)
{
return $this->active[Placefix::_($key)] ?? null;
}
/**
* Does key exist with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist_(string $key): bool
{
if (isset($this->active[Placefix::_($key)]))
{
return true;
}
return false;
}
/**
* Add content with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add_(string $key, $value)
{
if (isset($this->active[Placefix::_($key)]))
{
$this->active[Placefix::_($key)] .= $value;
}
else
{
$this->active[Placefix::_($key)] = $value;
}
}
/**
* Remove content with [ [ [ ... ] ] ] hash
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove_(string $key)
{
if ($this->exist_($key))
{
unset($this->active[Placefix::_($key)]);
}
}
/**
* Set content with # # # hash
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set_h(string $key, $value)
{
$this->active[Placefix::_h($key)] = $value;
}
/**
* Get content with # # # hash
*
* @param string $key The main string key
*
* @return mixed
* @since 3.2.0
*/
public function get_h(string $key)
{
return $this->active[Placefix::_h($key)] ?? null;
}
/**
* Does key exist with # # # hash
*
* @param string $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist_h(string $key): bool
{
if (isset($this->active[Placefix::_h($key)]))
{
return true;
}
return false;
}
/**
* Add content with # # # hash
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add_h(string $key, $value)
{
if ($this->exist_h($key))
{
$this->active[Placefix::_h($key)] .= $value;
}
else
{
$this->active[Placefix::_h($key)] = $value;
}
}
/**
* Remove content with # # # hash
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove_h(string $key)
{
if ($this->exist_h($key))
{
unset($this->active[Placefix::_h($key)]);
}
}
/** /**
* Set a type of placeholder with set of values * Set a type of placeholder with set of values
* *
@ -76,8 +338,7 @@ class Placeholder implements PlaceholderInterface
$number = 0; $number = 0;
foreach ($values as $value) foreach ($values as $value)
{ {
$this->active[Placefix::_($key . $number)] $this->set($key . $number, $value);
= $value;
$number++; $number++;
} }
} }
@ -93,16 +354,19 @@ class Placeholder implements PlaceholderInterface
*/ */
public function clearType(string $key) public function clearType(string $key)
{ {
$key = Placefix::_($key); $keys = [Placefix::_($key), Placefix::_h($key), $key];
foreach ($keys as $_key)
{
$this->active = array_filter( $this->active = array_filter(
$this->active, $this->active,
function(string $k) use($key){ function (string $k) use ($_key) {
return preg_replace('/\d/', '', $k) !== $key; return preg_replace('/\d/', '', $k) !== $_key;
}, },
ARRAY_FILTER_USE_KEY ARRAY_FILTER_USE_KEY
); );
} }
}
/** /**
* Update the data with the placeholders * Update the data with the placeholders
@ -124,9 +388,9 @@ class Placeholder implements PlaceholderInterface
// make sure the placeholders is an array // make sure the placeholders is an array
if (!ArrayHelper::check($placeholder)) if (!ArrayHelper::check($placeholder))
{ {
// This is an error, TODO actually we need to add a kind of log here to know that this happened
return $data; return $data;
} }
// continue with the work of replacement // continue with the work of replacement
if (1 == $action) // <-- just replace (default) if (1 == $action) // <-- just replace (default)
{ {
@ -148,7 +412,6 @@ class Placeholder implements PlaceholderInterface
// only replace if the data has these placeholder values // only replace if the data has these placeholder values
if ($replace === true) if ($replace === true)
{ {
return str_replace( return str_replace(
array_keys($placeholder), array_values($placeholder), $data array_keys($placeholder), array_values($placeholder), $data
); );
@ -176,6 +439,22 @@ class Placeholder implements PlaceholderInterface
return $data; return $data;
} }
/**
* Update the data with the active placeholders
*
* @param string $data The actual data
*
* @return string
* @since 3.2.0
*/
public function update_(string $data): string
{
// just replace the placeholders in data
return str_replace(
array_keys($this->active), array_values($this->active), $data
);
}
/** /**
* return the placeholders for inserted and replaced code * return the placeholders for inserted and replaced code
* *
@ -240,6 +519,5 @@ class Placeholder implements PlaceholderInterface
return [ 'start' => "", 'end' => ""]; return [ 'start' => "", 'end' => ""];
} }
} }

View File

@ -44,6 +44,22 @@ class Power implements PowerInterface
**/ **/
public array $active = []; public array $active = [];
/**
* All power namespaces
*
* @var array
* @since 3.2.0
**/
public array $namespace = [];
/**
* All composer namespaces
*
* @var array
* @since 3.2.0
**/
public array $composer = [];
/** /**
* The url to the power, if there is an error. * The url to the power, if there is an error.
* *
@ -475,10 +491,13 @@ class Power implements PowerInterface
$namespace_array = array_map(function ($val) { $namespace_array = array_map(function ($val) {
return $this->getCleanNamespace($val); return $this->getCleanNamespace($val);
}, $namespace_array); }, $namespace_array);
// set the actual class namespace // set the actual class namespace
$this->active[$guid]->_namespace = implode('\\', $namespace_array); $this->active[$guid]->_namespace = implode('\\', $namespace_array);
// prefix values
$this->active[$guid]->_namespace_prefix = $path_array; // set global namespaces for autoloader
$this->namespace[implode('.', $path_array)] = $path_array;
// get the parent folder (the first value in array) // get the parent folder (the first value in array)
$prefix_folder = implode('.', $path_array); $prefix_folder = implode('.', $path_array);
@ -579,10 +598,10 @@ class Power implements PowerInterface
$this->active[$guid]->composer $this->active[$guid]->composer
)) ? json_decode($this->active[$guid]->composer, true) : null; )) ? json_decode($this->active[$guid]->composer, true) : null;
unset($this->active[$guid]->composer);
if (ArrayHelper::check($_composer)) if (ArrayHelper::check($_composer))
{ {
$this->active[$guid]->composer = [];
foreach ($_composer as $composer) foreach ($_composer as $composer)
{ {
if (isset($composer['access_point']) && StringHelper::check($composer['access_point'])) if (isset($composer['access_point']) && StringHelper::check($composer['access_point']))
@ -612,17 +631,15 @@ class Power implements PowerInterface
{ {
$namespace = $this->getCleanNamespace(explode(' as ', $namespace)[0]); $namespace = $this->getCleanNamespace(explode(' as ', $namespace)[0]);
} }
$this->active[$guid]->composer[$namespace] = $composer['access_point'];
// add composer namespaces for autoloader
$this->composer[$namespace] = $composer['access_point'];
} }
} }
} }
} }
} }
} }
else
{
$this->active[$guid]->composer = null;
}
} }
/** /**

View File

@ -0,0 +1,214 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/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\Power;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use VDM\Joomla\Componentbuilder\Compiler\Power;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Content;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Utilities\ArrayHelper;
/**
* Compiler Autoloader
*
* @since 3.2.0
*/
class Autoloader
{
/**
* Power Objects
*
* @var Power
* @since 3.2.0
**/
protected Power $power;
/**
* Compiler Config
*
* @var Config
* @since 3.2.0
**/
protected Config $config;
/**
* Compiler Content
*
* @var Content
* @since 3.2.0
**/
protected Content $content;
/**
* Constructor.
*
* @param Power|null $power The power object.
* @param Config|null $config The compiler config object.
* @param Content|null $content The compiler content object.
*
* @since 3.2.0
*/
public function __construct(?Power $power = null, ?Config $config = null, ?Content $content = null)
{
$this->power = $power ?: Compiler::_('Power');
$this->config = $config ?: Compiler::_('Config');
$this->content = $content ?: Compiler::_('Content');
// reset all autoloaders power placeholders
$this->content->set('ADMIN_POWER_HELPER', '');
$this->content->set('SITE_POWER_HELPER', '');
$this->content->set('CUSTOM_POWER_AUTOLOADER', '');
}
/**
* Set the autoloader into the active content array
*
* @return void
* @since 3.2.0
*/
public function set()
{
if (($size = ArrayHelper::check($this->power->namespace)) > 0)
{
// set if we should load the autoloader on the site area
$loadSite = true;
// check if we are using a plugin
$use_plugin = $this->content->exist('PLUGIN_POWER_AUTOLOADER');
// build the methods
$autoloadNotSiteMethod = array();
$autoloadMethod = array();
// add only if we are not using a plugin
$tab_space = 2;
if (!$use_plugin)
{
$autoloadNotSiteMethod[] = PHP_EOL . PHP_EOL;
$tab_space = 0;
}
elseif (!$loadSite)
{
// we add code to prevent this plugin from triggering on the site area
$autoloadNotSiteMethod[] = PHP_EOL . Indent::_(2) . '//'
. Line::_(__Line__, __Class__) . ' do not run the autoloader in the site area';
$autoloadNotSiteMethod[] = Indent::_(2) . 'if ($this->app->isClient(\'site\'))';
$autoloadNotSiteMethod[] = Indent::_(2) . '{';
$autoloadNotSiteMethod[] = Indent::_(3) . 'return;';
$autoloadNotSiteMethod[] = Indent::_(2) . '}' . PHP_EOL;
}
// we start building the spl_autoload_register function call
$autoloadMethod[] = Indent::_($tab_space) . '//'
. Line::_(__Line__, __Class__) . ' register this component namespace';
$autoloadMethod[] = Indent::_($tab_space) . 'spl_autoload_register(function ($class) {';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
. Line::_(__Line__, __Class__) . ' project-specific base directories and namespace prefix';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$search = array(';
// ==== IMPORTANT NOTICE =====
// make sure the name space values are sorted from the longest string to the shortest
// so that the search do not mistakenly match a shorter namespace before a longer one
// that has the same short namespace for example:
// NameSpace\SubName\Sub <- will always match first
// NameSpace\SubName\SubSubName
// Should the shorter namespace be listed [first] it will match both of these:
// NameSpace\SubName\Sub\ClassName
// ^^^^^^^^^^^^^^^^^^^^^
// NameSpace\SubName\SubSubName\ClassName
// ^^^^^^^^^^^^^^^^^^^^^
uksort($this->power->namespace, function ($a, $b) {
return strlen($b) - strlen($a);
});
// counter to manage the comma in the actual array
$counter = 1;
foreach ($this->power->namespace as $base_dir => $prefix)
{
// don't add the ending comma on last value
if ($size == $counter)
{
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . "'" . $this->config->get('jcb_powers_path', 'libraries/jcb_powers') . "/$base_dir' => '" . implode('\\\\', $prefix) . "'";
}
else
{
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . "'" . $this->config->get('jcb_powers_path', 'libraries/jcb_powers') . "/$base_dir' => '" . implode('\\\\', $prefix) . "',";
}
$counter++;
}
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . ');';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '// Start the search and load if found';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$found = false;';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$found_base_dir = "";';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$found_len = 0;';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . 'foreach ($search as $base_dir => $prefix)';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '{';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '//'
. Line::_(__Line__, __Class__) . ' does the class use the namespace prefix?';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '$len = strlen($prefix);';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . 'if (strncmp($prefix, $class, $len) === 0)';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '{';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '//'
. Line::_(__Line__, __Class__) . ' we have a match so load the values';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '$found = true;';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '$found_base_dir = $base_dir;';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '$found_len = $len;';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '//'
. Line::_(__Line__, __Class__) . ' done here';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . 'break;';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '}';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '}';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
. Line::_(__Line__, __Class__) . ' check if we found a match';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . 'if (!$found)';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '{';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '//'
. Line::_(__Line__, __Class__) . ' no, move to the next registered autoloader';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . 'return;';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '}';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
. Line::_(__Line__, __Class__) . ' get the relative class name';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$relative_class = substr($class, $found_len);';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
. Line::_(__Line__, __Class__) . ' replace the namespace prefix with the base directory, replace namespace';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '// separators with directory separators in the relative class name, append';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '// with .php';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . "\$file = JPATH_ROOT . '/' . \$found_base_dir . '/src' . str_replace('\\\\', '/', \$relative_class) . '.php';";
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
. Line::_(__Line__, __Class__) . ' if the file exists, require it';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . 'if (file_exists($file))';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '{';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . 'require $file;';
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '}';
$autoloadMethod[] = Indent::_($tab_space) . '});';
// create the method string
$autoloader = implode(PHP_EOL, $autoloadNotSiteMethod) . implode(PHP_EOL, $autoloadMethod);
// check if we are using a plugin
if ($use_plugin)
{
$this->content->set('PLUGIN_POWER_AUTOLOADER', PHP_EOL . $autoloader);
}
else
{
// load to events placeholders
$this->content->add('ADMIN_POWER_HELPER', $autoloader);
// load to site if needed
if ($loadSite)
{
$this->content->add('SITE_POWER_HELPER', $autoloader);
}
}
// to add to custom files
$this->content->add('CUSTOM_POWER_AUTOLOADER', PHP_EOL . implode(PHP_EOL, $autoloadMethod));
}
}
}

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -14,7 +14,8 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service;
use Joomla\DI\Container; use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface; use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Compiler\Power as CompilerPower; use VDM\Joomla\Componentbuilder\Compiler\Power as Powers;
use VDM\Joomla\Componentbuilder\Compiler\Power\Autoloader;
/** /**
@ -34,26 +35,47 @@ class Power implements ServiceProviderInterface
*/ */
public function register(Container $container) public function register(Container $container)
{ {
$container->alias(CompilerPower::class, 'Power') $container->alias(Powers::class, 'Power')
->share('Power', [$this, 'getPower'], true); ->share('Power', [$this, 'getPowers'], true);
$container->alias(Autoloader::class, 'Power.Autoloader')
->share('Power.Autoloader', [$this, 'getAutoloader'], true);
} }
/** /**
* Get the Compiler Power * Get the Powers
* *
* @param Container $container The DI container. * @param Container $container The DI container.
* *
* @return CompilerPower * @return Powers
* @since 3.2.0 * @since 3.2.0
*/ */
public function getPower(Container $container): CompilerPower public function getPowers(Container $container): Powers
{ {
return new CompilerPower( return new Powers(
$container->get('Config'), $container->get('Config'),
$container->get('Placeholder'), $container->get('Placeholder'),
$container->get('Customcode'), $container->get('Customcode'),
$container->get('Customcode.Gui') $container->get('Customcode.Gui')
); );
} }
/**
* Get the Compiler Autoloader
*
* @param Container $container The DI container.
*
* @return Autoloader
* @since 3.2.0
*/
public function getAutoloader(Container $container): Autoloader
{
return new Autoloader(
$container->get('Power'),
$container->get('Config'),
$container->get('Content')
);
}
} }