diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..485dee64b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md index 225f0e156..b8d0abdb2 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.10.11) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.10.13) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -144,14 +144,14 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 17th February, 2020 -+ *Version*: 2.10.11 ++ *Last Build*: 3rd April, 2020 ++ *Version*: 2.10.13 + *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **278479** -+ *Field count*: **1505** -+ *File count*: **1756** -+ *Folder count*: **278** ++ *Line count*: **280662** ++ *Field count*: **1514** ++ *File count*: **1771** ++ *Folder count*: **287** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/README.txt b/admin/README.txt index 225f0e156..b8d0abdb2 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -12,7 +12,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.10.11) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.10.13) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -144,14 +144,14 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 17th February, 2020 -+ *Version*: 2.10.11 ++ *Last Build*: 3rd April, 2020 ++ *Version*: 2.10.13 + *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **278479** -+ *Field count*: **1505** -+ *File count*: **1756** -+ *Folder count*: **278** ++ *Line count*: **280662** ++ *Field count*: **1514** ++ *File count*: **1771** ++ *Folder count*: **287** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) diff --git a/admin/compiler/joomla_3/default.php b/admin/compiler/joomla_3/default.php index 80a0b50b3..b93d04e3f 100644 --- a/admin/compiler/joomla_3/default.php +++ b/admin/compiler/joomla_3/default.php @@ -80,8 +80,8 @@ if ($this->saveOrder) $this->loadTemplate('batch_body') ); ?> - - + + diff --git a/admin/config.xml b/admin/config.xml index ab8e9d975..7cc153967 100644 --- a/admin/config.xml +++ b/admin/config.xml @@ -229,7 +229,7 @@ label="COM_COMPONENTBUILDER_CONFIG_LANGUAGE_LABEL" class="list_class" multiple="false" - default="0" + default="en-GB" required="true" button="true" /> diff --git a/admin/helpers/compiler.php b/admin/helpers/compiler.php index 7928f0e45..f7ac678b2 100644 --- a/admin/helpers/compiler.php +++ b/admin/helpers/compiler.php @@ -5,7 +5,7 @@ * @created 30th April, 2015 * @author Llewellyn van der Merwe * @github Joomla Component Builder - * @copyright Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + * @copyright Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ @@ -25,7 +25,7 @@ class Compiler extends Infusion * * @var string */ - private $tempPath; + public $tempPath; /** * The timer @@ -41,13 +41,14 @@ class Compiler extends Infusion * * @var string */ - public $filepath = array( - 'component' => '', - 'component-folder' => '', - 'package' => '', - 'plugins' => array(), - 'plugins-folders' => array(), - 'modules' => array() + public $filepath + = array( + 'component' => '', + 'component-folder' => '', + 'package' => '', + 'plugins' => array(), + 'plugins-folders' => array(), + 'modules' => array() ); // fixed pathes @@ -67,12 +68,14 @@ class Compiler extends Infusion if (parent::__construct($config)) { // set temp directory - $comConfig = JFactory::getConfig(); + $comConfig = JFactory::getConfig(); $this->tempPath = $comConfig->get('tmp_path'); // set some folder paths in relation to distribution if ($config['backup']) { - $this->backupPath = $this->params->get('backup_folder_path', $this->tempPath); + $this->backupPath = $this->params->get( + 'backup_folder_path', $this->tempPath + ); $this->dynamicIntegration = true; } // set local repos switch @@ -86,60 +89,111 @@ class Compiler extends Infusion // first remove the files and folders $this->removeFolder($this->componentPath . '/site'); // clear form component xml - $xmlPath = $this->componentPath . '/' . $this->fileContentStatic[$this->hhh . 'component' . $this->hhh] . '.xml'; - $componentXML = ComponentbuilderHelper::getFileContents($xmlPath); - $textToSite = ComponentbuilderHelper::getBetween($componentXML, '', ''); - $textToSiteLang = ComponentbuilderHelper::getBetween($componentXML, '', ''); - $componentXML = str_replace(array('' . $textToSite . "", '' . $textToSiteLang . ""), array('', ''), $componentXML); + $xmlPath = $this->componentPath . '/' + . $this->fileContentStatic[$this->hhh . 'component' + . $this->hhh] . '.xml'; + $componentXML = ComponentbuilderHelper::getFileContents( + $xmlPath + ); + $textToSite = ComponentbuilderHelper::getBetween( + $componentXML, '', '' + ); + $textToSiteLang = ComponentbuilderHelper::getBetween( + $componentXML, '', '' + ); + $componentXML = str_replace( + array('' . $textToSite . "", + '' . $textToSiteLang + . ""), array('', ''), $componentXML + ); $this->writeFile($xmlPath, $componentXML); } // Trigger Event: jcb_ce_onBeforeUpdateFiles - $this->triggerEvent('jcb_ce_onBeforeUpdateFiles', array(&$this->componentContext, $this)); + $this->triggerEvent( + 'jcb_ce_onBeforeUpdateFiles', + array(&$this->componentContext, $this) + ); // now update the files if (!$this->updateFiles()) { return false; } // Trigger Event: jcb_ce_onBeforeGetCustomCode - $this->triggerEvent('jcb_ce_onBeforeGetCustomCode', array(&$this->componentContext, $this)); + $this->triggerEvent( + 'jcb_ce_onBeforeGetCustomCode', + array(&$this->componentContext, $this) + ); // now insert into the new files if ($this->getCustomCode()) { // Trigger Event: jcb_ce_onBeforeAddCustomCode - $this->triggerEvent('jcb_ce_onBeforeAddCustomCode', array(&$this->componentContext, $this)); + $this->triggerEvent( + 'jcb_ce_onBeforeAddCustomCode', + array(&$this->componentContext, $this) + ); $this->addCustomCode(); } // Trigger Event: jcb_ce_onBeforeSetLangFileData - $this->triggerEvent('jcb_ce_onBeforeSetLangFileData', array(&$this->componentContext, $this)); + $this->triggerEvent( + 'jcb_ce_onBeforeSetLangFileData', + array(&$this->componentContext, $this) + ); // set the lang data now $this->setLangFileData(); // set the language notice if it was set - if (ComponentbuilderHelper::checkArray($this->langNot) || ComponentbuilderHelper::checkArray($this->langSet)) + if (ComponentbuilderHelper::checkArray($this->langNot) + || ComponentbuilderHelper::checkArray($this->langSet)) { if (ComponentbuilderHelper::checkArray($this->langNot)) { - $this->app->enqueueMessage(JText::_('

Language Warning

'), 'Warning'); + $this->app->enqueueMessage( + JText::_('

Language Warning

'), 'Warning' + ); foreach ($this->langNot as $tag => $percentage) { - $this->app->enqueueMessage(JText::sprintf('The %s language has %s% translated, you will need to translate %s% of the language strings before it will be added.', $tag, $percentage, $this->percentageLanguageAdd), 'Warning'); + $this->app->enqueueMessage( + JText::sprintf( + 'The %s language has %s% translated, you will need to translate %s% of the language strings before it will be added.', + $tag, $percentage, $this->percentageLanguageAdd + ), 'Warning' + ); } - $this->app->enqueueMessage(JText::_('

Language Notice

'), 'Notice'); - $this->app->enqueueMessage(JText::sprintf('You can change this percentage of translated strings required in the global options of JCB.
Please watch this tutorial for more help surrounding the JCB translations manager.', '"https://youtu.be/zzAcVkn_cWU?list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE" target="_blank" title="JCB Tutorial surrounding Translation Manager"'), 'Notice'); + $this->app->enqueueMessage( + JText::_('

Language Notice

'), 'Notice' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'You can change this percentage of translated strings required in the global options of JCB.
Please watch this tutorial for more help surrounding the JCB translations manager.', + '"https://youtu.be/zzAcVkn_cWU?list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE" target="_blank" title="JCB Tutorial surrounding Translation Manager"' + ), 'Notice' + ); } // set why the strings were added - $whyAddedLang = JText::sprintf('because more then %s% of the strings have been translated.', $this->percentageLanguageAdd); + $whyAddedLang = JText::sprintf( + 'because more then %s% of the strings have been translated.', + $this->percentageLanguageAdd + ); if ($this->debugLinenr) { - $whyAddedLang = JText::_('because the debugging mode is on. (debug line numbers)'); + $whyAddedLang = JText::_( + 'because the debugging mode is on. (debug line numbers)' + ); } // show languages that were added if (ComponentbuilderHelper::checkArray($this->langSet)) { - $this->app->enqueueMessage(JText::_('

Language Notice

'), 'Notice'); + $this->app->enqueueMessage( + JText::_('

Language Notice

'), 'Notice' + ); foreach ($this->langSet as $tag => $percentage) { - $this->app->enqueueMessage(JText::sprintf('The %s language has %s% translated. Was addeded %s', $tag, $percentage, $whyAddedLang), 'Notice'); + $this->app->enqueueMessage( + JText::sprintf( + 'The %s language has %s% translated. Was addeded %s', + $tag, $percentage, $whyAddedLang + ), 'Notice' + ); } } } @@ -166,29 +220,51 @@ class Compiler extends Infusion { if (ComponentbuilderHelper::checkArray($this->langMatch)) { - $mismatch = array_diff(array_unique($this->langMismatch), array_unique($this->langMatch)); + $mismatch = array_diff( + array_unique($this->langMismatch), + array_unique($this->langMatch) + ); } else { $mismatch = array_unique($this->langMismatch); } // set a notice if we have a mismatch - if (isset($mismatch) && ComponentbuilderHelper::checkArray($mismatch)) + if (isset($mismatch) + && ComponentbuilderHelper::checkArray( + $mismatch + )) { - $this->app->enqueueMessage(JText::_('

Language Warning

'), 'Warning'); + $this->app->enqueueMessage( + JText::_('

Language Warning

'), 'Warning' + ); if (count((array) $mismatch) > 1) { - $this->app->enqueueMessage(JText::_('

Please check the following mismatching Joomla.JText language constants.

'), 'Warning'); + $this->app->enqueueMessage( + JText::_( + '

Please check the following mismatching Joomla.JText language constants.

' + ), 'Warning' + ); } else { - $this->app->enqueueMessage(JText::_('

Please check the following mismatch Joomla.JText language constant.

'), 'Warning'); + $this->app->enqueueMessage( + JText::_( + '

Please check the following mismatch Joomla.JText language constant.

' + ), 'Warning' + ); } // add the mismatching issues foreach ($mismatch as $string) { - $constant = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($string, 'U'); - $this->app->enqueueMessage(JText::sprintf('The Joomla.JText._('%s') language constant for %s does not have a corresponding JText::script('%s') decalaration, please add it.', $constant, $string, $string), 'Warning'); + $constant = $this->langPrefix . '_' + . ComponentbuilderHelper::safeString($string, 'U'); + $this->app->enqueueMessage( + JText::sprintf( + 'The Joomla.JText._('%s') language constant for %s does not have a corresponding JText::script('%s') decalaration, please add it.', + $constant, $string, $string + ), 'Warning' + ); } } } @@ -198,24 +274,35 @@ class Compiler extends Infusion // number of external code strings $externalCount = count($this->externalCodeString); // the correct string - $externalCodeString = ($externalCount == 1) ? JText::_('code/string') : JText::_('code/strings'); + $externalCodeString = ($externalCount == 1) ? JText::_( + 'code/string' + ) : JText::_('code/strings'); // the notice - $this->app->enqueueMessage(JText::_('

External Code Notice

'), 'Notice'); - $this->app->enqueueMessage(JText::sprintf('There has been %s - %s added to this component as EXTERNALCODE. To avoid shipping your component with malicious %s always make sure that the correct code/string values were used.', $externalCount, $externalCodeString, $externalCodeString), 'Notice'); + $this->app->enqueueMessage( + JText::_('

External Code Notice

'), 'Notice' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'There has been %s - %s added to this component as EXTERNALCODE. To avoid shipping your component with malicious %s always make sure that the correct code/string values were used.', + $externalCount, $externalCodeString, $externalCodeString + ), 'Notice' + ); } // end the timer here - $this->time_end = microtime(true); + $this->time_end = microtime(true); $this->secondsCompiled = $this->time_end - $this->time_start; + // completed the compilation return true; } + return false; } /** * Set the line number in comments * - * @param int $nr The line number + * @param int $nr The line number * * @return void * @@ -226,6 +313,7 @@ class Compiler extends Infusion { return ' [Compiler ' . $nr . ']'; } + return ''; } @@ -237,7 +325,10 @@ class Compiler extends Infusion */ protected function updateFiles() { - if (isset($this->newFiles['static']) && ComponentbuilderHelper::checkArray($this->newFiles['static']) && isset($this->newFiles['dynamic']) && ComponentbuilderHelper::checkArray($this->newFiles['dynamic'])) + if (isset($this->newFiles['static']) + && ComponentbuilderHelper::checkArray($this->newFiles['static']) + && isset($this->newFiles['dynamic']) + && ComponentbuilderHelper::checkArray($this->newFiles['dynamic'])) { // get the bom file $bom = ComponentbuilderHelper::getFileContents($this->bomPath); @@ -246,13 +337,18 @@ class Compiler extends Infusion { if (JFile::exists($static['path'])) { - $this->setFileContent($static['name'], $static['path'], $bom); + $this->setFileContent( + $static['name'], $static['path'], $bom + ); } } // now we do the dynamic files foreach ($this->newFiles['dynamic'] as $view => $files) { - if (isset($this->fileContentDynamic[$view]) && ComponentbuilderHelper::checkArray($this->fileContentDynamic[$view])) + if (isset($this->fileContentDynamic[$view]) + && ComponentbuilderHelper::checkArray( + $this->fileContentDynamic[$view] + )) { foreach ($files as $file) { @@ -260,7 +356,10 @@ class Compiler extends Infusion { if (JFile::exists($file['path'])) { - $this->setFileContent($file['name'], $file['path'], $bom, $file['view']); + $this->setFileContent( + $file['name'], $file['path'], $bom, + $file['view'] + ); } } } @@ -275,37 +374,59 @@ class Compiler extends Infusion { foreach ($this->joomlaModules as $module) { - if (ComponentbuilderHelper::checkObject($module) && isset($this->newFiles[$module->key]) && ComponentbuilderHelper::checkArray($this->newFiles[$module->key])) + if (ComponentbuilderHelper::checkObject($module) + && isset($this->newFiles[$module->key]) + && ComponentbuilderHelper::checkArray( + $this->newFiles[$module->key] + )) { // move field or rule if needed - if (isset($module->fields_rules_paths) && $module->fields_rules_paths == 2) + if (isset($module->fields_rules_paths) + && $module->fields_rules_paths == 2) { // check the config fields - if (isset($module->config_fields) && ComponentbuilderHelper::checkArray($module->config_fields)) + if (isset($module->config_fields) + && ComponentbuilderHelper::checkArray( + $module->config_fields + )) { - foreach ($module->config_fields as $field_name => $fieldsets) + foreach ( + $module->config_fields as $field_name => + $fieldsets + ) { foreach ($fieldsets as $fieldset => $fields) { foreach ($fields as $field) { - $this->moveFieldsRules($field, $module->folder_path); + $this->moveFieldsRules( + $field, $module->folder_path + ); } } } } // check the fieldsets - if (isset($module->form_files) && ComponentbuilderHelper::checkArray($module->form_files)) + if (isset($module->form_files) + && ComponentbuilderHelper::checkArray( + $module->form_files + )) { - foreach($module->form_files as $file => $files) + foreach ($module->form_files as $file => $files) { - foreach ($files as $field_name => $fieldsets) + foreach ( + $files as $field_name => $fieldsets + ) { - foreach ($fieldsets as $fieldset => $fields) + foreach ( + $fieldsets as $fieldset => $fields + ) { foreach ($fields as $field) { - $this->moveFieldsRules($field, $module->folder_path); + $this->moveFieldsRules( + $field, $module->folder_path + ); } } } @@ -317,7 +438,10 @@ class Compiler extends Infusion { if (JFile::exists($module_file['path'])) { - $this->setFileContent($module_file['name'], $module_file['path'], $bom, $module->key); + $this->setFileContent( + $module_file['name'], $module_file['path'], + $bom, $module->key + ); } } // free up some memory @@ -331,37 +455,59 @@ class Compiler extends Infusion { foreach ($this->joomlaPlugins as $plugin) { - if (ComponentbuilderHelper::checkObject($plugin) && isset($this->newFiles[$plugin->key]) && ComponentbuilderHelper::checkArray($this->newFiles[$plugin->key])) + if (ComponentbuilderHelper::checkObject($plugin) + && isset($this->newFiles[$plugin->key]) + && ComponentbuilderHelper::checkArray( + $this->newFiles[$plugin->key] + )) { // move field or rule if needed - if (isset($plugin->fields_rules_paths) && $plugin->fields_rules_paths == 2) + if (isset($plugin->fields_rules_paths) + && $plugin->fields_rules_paths == 2) { // check the config fields - if (isset($plugin->config_fields) && ComponentbuilderHelper::checkArray($plugin->config_fields)) + if (isset($plugin->config_fields) + && ComponentbuilderHelper::checkArray( + $plugin->config_fields + )) { - foreach ($plugin->config_fields as $field_name => $fieldsets) + foreach ( + $plugin->config_fields as $field_name => + $fieldsets + ) { foreach ($fieldsets as $fieldset => $fields) { foreach ($fields as $field) { - $this->moveFieldsRules($field, $plugin->folder_path); + $this->moveFieldsRules( + $field, $plugin->folder_path + ); } } } } // check the fieldsets - if (isset($plugin->form_files) && ComponentbuilderHelper::checkArray($plugin->form_files)) + if (isset($plugin->form_files) + && ComponentbuilderHelper::checkArray( + $plugin->form_files + )) { - foreach($plugin->form_files as $file => $files) + foreach ($plugin->form_files as $file => $files) { - foreach ($files as $field_name => $fieldsets) + foreach ( + $files as $field_name => $fieldsets + ) { - foreach ($fieldsets as $fieldset => $fields) + foreach ( + $fieldsets as $fieldset => $fields + ) { foreach ($fields as $field) { - $this->moveFieldsRules($field, $plugin->folder_path); + $this->moveFieldsRules( + $field, $plugin->folder_path + ); } } } @@ -373,7 +519,10 @@ class Compiler extends Infusion { if (JFile::exists($plugin_file['path'])) { - $this->setFileContent($plugin_file['name'], $plugin_file['path'], $bom, $plugin->key); + $this->setFileContent( + $plugin_file['name'], $plugin_file['path'], + $bom, $plugin->key + ); } } // free up some memory @@ -382,8 +531,10 @@ class Compiler extends Infusion } } } + return true; } + return false; } @@ -396,7 +547,10 @@ class Compiler extends Infusion protected function setFileContent(&$name, &$path, &$bom, $view = null) { // Trigger Event: jcb_ce_onBeforeSetFileContent - $this->triggerEvent('jcb_ce_onBeforeSetFileContent', array(&$this->componentContext, &$name, &$path, &$bom, &$view)); + $this->triggerEvent( + 'jcb_ce_onBeforeSetFileContent', + array(&$this->componentContext, &$name, &$path, &$bom, &$view) + ); // set the file name $this->fileContentStatic[$this->hhh . 'FILENAME' . $this->hhh] = $name; // check if the file should get PHP opening @@ -408,11 +562,17 @@ class Compiler extends Infusion // get content of the file $string = ComponentbuilderHelper::getFileContents($path); // Trigger Event: jcb_ce_onGetFileContents - $this->triggerEvent('jcb_ce_onGetFileContents', array(&$this->componentContext, &$string, &$name, &$path, &$bom, &$view)); + $this->triggerEvent( + 'jcb_ce_onGetFileContents', + array(&$this->componentContext, &$string, &$name, &$path, &$bom, + &$view) + ); // see if we should add a BOM if (strpos($string, $this->hhh . 'BOM' . $this->hhh) !== false) { - list($wast, $code) = explode($this->hhh . 'BOM' . $this->hhh, $string); + list($wast, $code) = explode( + $this->hhh . 'BOM' . $this->hhh, $string + ); $string = $php . $bom . $code; } // set the answer @@ -420,7 +580,9 @@ class Compiler extends Infusion // set the dynamic answer if ($view) { - $answer = $this->setPlaceholders($answer, $this->fileContentDynamic[$view], 3); + $answer = $this->setPlaceholders( + $answer, $this->fileContentDynamic[$view], 3 + ); } // check if this file needs extra care :) if (isset($this->updateFileContent[$path])) @@ -428,7 +590,11 @@ class Compiler extends Infusion $answer = $this->setDynamicValues($answer); } // Trigger Event: jcb_ce_onBeforeSetFileContent - $this->triggerEvent('jcb_ce_onBeforeWriteFileContent', array(&$this->componentContext, &$answer, &$name, &$path, &$bom, &$view)); + $this->triggerEvent( + 'jcb_ce_onBeforeWriteFileContent', + array(&$this->componentContext, &$answer, &$name, &$path, &$bom, + &$view) + ); // add answer back to file $this->writeFile($path, $answer); // count the file lines @@ -444,15 +610,24 @@ class Compiler extends Infusion protected function setUpdateServer() { // move the component update server to host - if ($this->componentData->add_update_server == 1 && $this->componentData->update_server_target == 1 - && isset($this->updateServerFileName) && $this->dynamicIntegration) + if ($this->componentData->add_update_server == 1 + && $this->componentData->update_server_target == 1 + && isset($this->updateServerFileName) + && $this->dynamicIntegration) { - $update_server_xml_path = $this->componentPath . '/' . $this->updateServerFileName . '.xml'; + $update_server_xml_path = $this->componentPath . '/' + . $this->updateServerFileName . '.xml'; // make sure we have the correct file - if (JFile::exists($update_server_xml_path) && isset($this->componentData->update_server)) + if (JFile::exists($update_server_xml_path) + && isset($this->componentData->update_server)) { // move to server - ComponentbuilderHelper::moveToServer($update_server_xml_path, $this->updateServerFileName . '.xml', (int) $this->componentData->update_server, $this->componentData->update_server_protocol); + ComponentbuilderHelper::moveToServer( + $update_server_xml_path, + $this->updateServerFileName . '.xml', + (int) $this->componentData->update_server, + $this->componentData->update_server_protocol + ); // remove the local file JFile::delete($update_server_xml_path); } @@ -463,14 +638,27 @@ class Compiler extends Infusion foreach ($this->joomlaPlugins as $plugin) { if (ComponentbuilderHelper::checkObject($plugin) - && isset($plugin->add_update_server) && $plugin->add_update_server == 1 - && isset($plugin->update_server_target) && $plugin->update_server_target == 1 - && isset($plugin->update_server) && is_numeric($plugin->update_server) && $plugin->update_server > 0 - && isset($plugin->update_server_xml_path) && JFile::exists($plugin->update_server_xml_path) - && isset($plugin->update_server_xml_file_name) && ComponentbuilderHelper::checkString($plugin->update_server_xml_file_name)) + && isset($plugin->add_update_server) + && $plugin->add_update_server == 1 + && isset($plugin->update_server_target) + && $plugin->update_server_target == 1 + && isset($plugin->update_server) + && is_numeric($plugin->update_server) + && $plugin->update_server > 0 + && isset($plugin->update_server_xml_path) + && JFile::exists($plugin->update_server_xml_path) + && isset($plugin->update_server_xml_file_name) + && ComponentbuilderHelper::checkString( + $plugin->update_server_xml_file_name + )) { // move to server - ComponentbuilderHelper::moveToServer($plugin->update_server_xml_path, $plugin->update_server_xml_file_name, (int) $plugin->update_server, $plugin->update_server_protocol); + ComponentbuilderHelper::moveToServer( + $plugin->update_server_xml_path, + $plugin->update_server_xml_file_name, + (int) $plugin->update_server, + $plugin->update_server_protocol + ); // remove the local file JFile::delete($plugin->update_server_xml_path); } @@ -482,7 +670,11 @@ class Compiler extends Infusion protected function fixLicenseValues($data) { // check if these files have its own config data) - if (isset($data['config']) && ComponentbuilderHelper::checkArray($data['config']) && $this->componentData->mvc_versiondate == 1) + if (isset($data['config']) + && ComponentbuilderHelper::checkArray( + $data['config'] + ) + && $this->componentData->mvc_versiondate == 1) { foreach ($data['config'] as $key => $value) { @@ -502,12 +694,19 @@ class Compiler extends Infusion } $this->fileContentStatic[$key] = $value; } + return true; } // else insure to reset to global - $this->fileContentStatic[$this->hhh . 'CREATIONDATE' . $this->hhh] = $this->fileContentStatic[$this->hhh . 'CREATIONDATE' . $this->hhh . 'GLOBAL']; - $this->fileContentStatic[$this->hhh . 'BUILDDATE' . $this->hhh] = $this->fileContentStatic[$this->hhh . 'BUILDDATE' . $this->hhh . 'GLOBAL']; - $this->fileContentStatic[$this->hhh . 'VERSION' . $this->hhh] = $this->fileContentStatic[$this->hhh . 'VERSION' . $this->hhh . 'GLOBAL']; + $this->fileContentStatic[$this->hhh . 'CREATIONDATE' . $this->hhh] + = $this->fileContentStatic[$this->hhh . 'CREATIONDATE' . $this->hhh + . 'GLOBAL']; + $this->fileContentStatic[$this->hhh . 'BUILDDATE' . $this->hhh] + = $this->fileContentStatic[$this->hhh . 'BUILDDATE' . $this->hhh + . 'GLOBAL']; + $this->fileContentStatic[$this->hhh . 'VERSION' . $this->hhh] + = $this->fileContentStatic[$this->hhh . 'VERSION' . $this->hhh + . 'GLOBAL']; } // set all global numbers @@ -517,28 +716,32 @@ class Compiler extends Infusion $this->pageCount = round($this->lineCount / 56); // setup the unrealistic numbers $this->folderSeconds = $this->folderCount * 5; - $this->fileSeconds = $this->fileCount * 5; - $this->lineSeconds = $this->lineCount * 10; - $this->seconds = $this->folderSeconds + $this->fileSeconds + $this->lineSeconds; - $this->totalHours = round($this->seconds / 3600); - $this->totalDays = round($this->totalHours / 8); + $this->fileSeconds = $this->fileCount * 5; + $this->lineSeconds = $this->lineCount * 10; + $this->seconds = $this->folderSeconds + $this->fileSeconds + + $this->lineSeconds; + $this->totalHours = round($this->seconds / 3600); + $this->totalDays = round($this->totalHours / 8); // setup the more realistic numbers $this->secondsDebugging = $this->seconds / 4; - $this->secondsPlanning = $this->seconds / 7; - $this->secondsMapping = $this->seconds / 10; - $this->secondsOffice = $this->seconds / 6; - $this->actualSeconds = $this->folderSeconds + $this->fileSeconds + $this->lineSeconds + $this->secondsDebugging + $this->secondsPlanning + $this->secondsMapping + $this->secondsOffice; + $this->secondsPlanning = $this->seconds / 7; + $this->secondsMapping = $this->seconds / 10; + $this->secondsOffice = $this->seconds / 6; + $this->actualSeconds = $this->folderSeconds + $this->fileSeconds + + $this->lineSeconds + $this->secondsDebugging + + $this->secondsPlanning + $this->secondsMapping + + $this->secondsOffice; $this->actualTotalHours = round($this->actualSeconds / 3600); - $this->actualTotalDays = round($this->actualTotalHours / 8); - $this->debuggingHours = round($this->secondsDebugging / 3600); - $this->planningHours = round($this->secondsPlanning / 3600); - $this->mappingHours = round($this->secondsMapping / 3600); - $this->officeHours = round($this->secondsOffice / 3600); + $this->actualTotalDays = round($this->actualTotalHours / 8); + $this->debuggingHours = round($this->secondsDebugging / 3600); + $this->planningHours = round($this->secondsPlanning / 3600); + $this->mappingHours = round($this->secondsMapping / 3600); + $this->officeHours = round($this->secondsOffice / 3600); // the actual time spent $this->actualHoursSpent = $this->actualTotalHours - $this->totalHours; - $this->actualDaysSpent = $this->actualTotalDays - $this->totalDays; + $this->actualDaysSpent = $this->actualTotalDays - $this->totalDays; // calculate the projects actual time frame of completion - $this->projectWeekTime = round($this->actualTotalDays / 5, 1); + $this->projectWeekTime = round($this->actualTotalDays / 5, 1); $this->projectMonthTime = round($this->actualTotalDays / 24, 1); } @@ -548,7 +751,10 @@ class Compiler extends Infusion $two = 0; foreach ($this->newFiles['static'] as $static) { - if (('README.md' === $static['name'] || 'README.txt' === $static['name']) && $this->componentData->addreadme && JFile::exists($static['path'])) + if (('README.md' === $static['name'] + || 'README.txt' === $static['name']) + && $this->componentData->addreadme + && JFile::exists($static['path'])) { $this->setReadMe($static['path']); $two++; @@ -564,7 +770,11 @@ class Compiler extends Infusion private function setReadMe($path) { // set readme data if not set already - if (!isset($this->fileContentStatic[$this->hhh . 'LINE_COUNT' . $this->hhh]) || $this->fileContentStatic[$this->hhh . 'LINE_COUNT' . $this->hhh] != $this->lineCount) + if (!isset( + $this->fileContentStatic[$this->hhh . 'LINE_COUNT' . $this->hhh] + ) + || $this->fileContentStatic[$this->hhh . 'LINE_COUNT' . $this->hhh] + != $this->lineCount) { $this->buildReadMeData(); } @@ -579,75 +789,137 @@ class Compiler extends Infusion private function buildReadMeData() { // set some defaults - $this->fileContentStatic[$this->hhh . 'LINE_COUNT' . $this->hhh] = $this->lineCount; - $this->fileContentStatic[$this->hhh . 'FIELD_COUNT' . $this->hhh] = $this->fieldCount; - $this->fileContentStatic[$this->hhh . 'FILE_COUNT' . $this->hhh] = $this->fileCount; - $this->fileContentStatic[$this->hhh . 'FOLDER_COUNT' . $this->hhh] = $this->folderCount; - $this->fileContentStatic[$this->hhh . 'PAGE_COUNT' . $this->hhh] = $this->pageCount; - $this->fileContentStatic[$this->hhh . 'folders' . $this->hhh] = $this->folderSeconds; - $this->fileContentStatic[$this->hhh . 'foldersSeconds' . $this->hhh] = $this->folderSeconds; - $this->fileContentStatic[$this->hhh . 'files' . $this->hhh] = $this->fileSeconds; - $this->fileContentStatic[$this->hhh . 'filesSeconds' . $this->hhh] = $this->fileSeconds; - $this->fileContentStatic[$this->hhh . 'lines' . $this->hhh] = $this->lineSeconds; - $this->fileContentStatic[$this->hhh . 'linesSeconds' . $this->hhh] = $this->lineSeconds; - $this->fileContentStatic[$this->hhh . 'seconds' . $this->hhh] = $this->actualSeconds; - $this->fileContentStatic[$this->hhh . 'actualSeconds' . $this->hhh] = $this->actualSeconds; - $this->fileContentStatic[$this->hhh . 'totalHours' . $this->hhh] = $this->totalHours; - $this->fileContentStatic[$this->hhh . 'totalDays' . $this->hhh] = $this->totalDays; - $this->fileContentStatic[$this->hhh . 'debugging' . $this->hhh] = $this->secondsDebugging; - $this->fileContentStatic[$this->hhh . 'secondsDebugging' . $this->hhh] = $this->secondsDebugging; - $this->fileContentStatic[$this->hhh . 'planning' . $this->hhh] = $this->secondsPlanning; - $this->fileContentStatic[$this->hhh . 'secondsPlanning' . $this->hhh] = $this->secondsPlanning; - $this->fileContentStatic[$this->hhh . 'mapping' . $this->hhh] = $this->secondsMapping; - $this->fileContentStatic[$this->hhh . 'secondsMapping' . $this->hhh] = $this->secondsMapping; - $this->fileContentStatic[$this->hhh . 'office' . $this->hhh] = $this->secondsOffice; - $this->fileContentStatic[$this->hhh . 'secondsOffice' . $this->hhh] = $this->secondsOffice; - $this->fileContentStatic[$this->hhh . 'actualTotalHours' . $this->hhh] = $this->actualTotalHours; - $this->fileContentStatic[$this->hhh . 'actualTotalDays' . $this->hhh] = $this->actualTotalDays; - $this->fileContentStatic[$this->hhh . 'debuggingHours' . $this->hhh] = $this->debuggingHours; - $this->fileContentStatic[$this->hhh . 'planningHours' . $this->hhh] = $this->planningHours; - $this->fileContentStatic[$this->hhh . 'mappingHours' . $this->hhh] = $this->mappingHours; - $this->fileContentStatic[$this->hhh . 'officeHours' . $this->hhh] = $this->officeHours; - $this->fileContentStatic[$this->hhh . 'actualHoursSpent' . $this->hhh] = $this->actualHoursSpent; - $this->fileContentStatic[$this->hhh . 'actualDaysSpent' . $this->hhh] = $this->actualDaysSpent; - $this->fileContentStatic[$this->hhh . 'projectWeekTime' . $this->hhh] = $this->projectWeekTime; - $this->fileContentStatic[$this->hhh . 'projectMonthTime' . $this->hhh] = $this->projectMonthTime; + $this->fileContentStatic[$this->hhh . 'LINE_COUNT' . $this->hhh] + = $this->lineCount; + $this->fileContentStatic[$this->hhh . 'FIELD_COUNT' . $this->hhh] + = $this->fieldCount; + $this->fileContentStatic[$this->hhh . 'FILE_COUNT' . $this->hhh] + = $this->fileCount; + $this->fileContentStatic[$this->hhh . 'FOLDER_COUNT' . $this->hhh] + = $this->folderCount; + $this->fileContentStatic[$this->hhh . 'PAGE_COUNT' . $this->hhh] + = $this->pageCount; + $this->fileContentStatic[$this->hhh . 'folders' . $this->hhh] + = $this->folderSeconds; + $this->fileContentStatic[$this->hhh . 'foldersSeconds' . $this->hhh] + = $this->folderSeconds; + $this->fileContentStatic[$this->hhh . 'files' . $this->hhh] + = $this->fileSeconds; + $this->fileContentStatic[$this->hhh . 'filesSeconds' . $this->hhh] + = $this->fileSeconds; + $this->fileContentStatic[$this->hhh . 'lines' . $this->hhh] + = $this->lineSeconds; + $this->fileContentStatic[$this->hhh . 'linesSeconds' . $this->hhh] + = $this->lineSeconds; + $this->fileContentStatic[$this->hhh . 'seconds' . $this->hhh] + = $this->actualSeconds; + $this->fileContentStatic[$this->hhh . 'actualSeconds' . $this->hhh] + = $this->actualSeconds; + $this->fileContentStatic[$this->hhh . 'totalHours' . $this->hhh] + = $this->totalHours; + $this->fileContentStatic[$this->hhh . 'totalDays' . $this->hhh] + = $this->totalDays; + $this->fileContentStatic[$this->hhh . 'debugging' . $this->hhh] + = $this->secondsDebugging; + $this->fileContentStatic[$this->hhh . 'secondsDebugging' . $this->hhh] + = $this->secondsDebugging; + $this->fileContentStatic[$this->hhh . 'planning' . $this->hhh] + = $this->secondsPlanning; + $this->fileContentStatic[$this->hhh . 'secondsPlanning' . $this->hhh] + = $this->secondsPlanning; + $this->fileContentStatic[$this->hhh . 'mapping' . $this->hhh] + = $this->secondsMapping; + $this->fileContentStatic[$this->hhh . 'secondsMapping' . $this->hhh] + = $this->secondsMapping; + $this->fileContentStatic[$this->hhh . 'office' . $this->hhh] + = $this->secondsOffice; + $this->fileContentStatic[$this->hhh . 'secondsOffice' . $this->hhh] + = $this->secondsOffice; + $this->fileContentStatic[$this->hhh . 'actualTotalHours' . $this->hhh] + = $this->actualTotalHours; + $this->fileContentStatic[$this->hhh . 'actualTotalDays' . $this->hhh] + = $this->actualTotalDays; + $this->fileContentStatic[$this->hhh . 'debuggingHours' . $this->hhh] + = $this->debuggingHours; + $this->fileContentStatic[$this->hhh . 'planningHours' . $this->hhh] + = $this->planningHours; + $this->fileContentStatic[$this->hhh . 'mappingHours' . $this->hhh] + = $this->mappingHours; + $this->fileContentStatic[$this->hhh . 'officeHours' . $this->hhh] + = $this->officeHours; + $this->fileContentStatic[$this->hhh . 'actualHoursSpent' . $this->hhh] + = $this->actualHoursSpent; + $this->fileContentStatic[$this->hhh . 'actualDaysSpent' . $this->hhh] + = $this->actualDaysSpent; + $this->fileContentStatic[$this->hhh . 'projectWeekTime' . $this->hhh] + = $this->projectWeekTime; + $this->fileContentStatic[$this->hhh . 'projectMonthTime' . $this->hhh] + = $this->projectMonthTime; } private function setLocalRepos() { // move it to the repo folder if set - if (isset($this->repoPath) && ComponentbuilderHelper::checkString($this->repoPath)) + if (isset($this->repoPath) + && ComponentbuilderHelper::checkString( + $this->repoPath + )) { // set the repo path - $repoFullPath = $this->repoPath . '/com_' . $this->componentData->sales_name . '__joomla_' . $this->joomlaVersion; + $repoFullPath = $this->repoPath . '/com_' + . $this->componentData->sales_name . '__joomla_' + . $this->joomlaVersion; // Trigger Event: jcb_ce_onBeforeUpdateRepo - $this->triggerEvent('jcb_ce_onBeforeUpdateRepo', array(&$this->componentContext, &$this->componentPath, &$repoFullPath, &$this->componentData)); + $this->triggerEvent( + 'jcb_ce_onBeforeUpdateRepo', + array(&$this->componentContext, &$this->componentPath, + &$repoFullPath, &$this->componentData) + ); // remove old data $this->removeFolder($repoFullPath, $this->componentData->toignore); // set the new data JFolder::copy($this->componentPath, $repoFullPath, '', true); // Trigger Event: jcb_ce_onAfterUpdateRepo - $this->triggerEvent('jcb_ce_onAfterUpdateRepo', array(&$this->componentContext, &$this->componentPath, &$repoFullPath, &$this->componentData)); + $this->triggerEvent( + 'jcb_ce_onAfterUpdateRepo', + array(&$this->componentContext, &$this->componentPath, + &$repoFullPath, &$this->componentData) + ); // move the modules to local folder repos if (ComponentbuilderHelper::checkArray($this->joomlaModules)) { foreach ($this->joomlaModules as $module) { - if (ComponentbuilderHelper::checkObject($module) && isset($module->file_name)) + if (ComponentbuilderHelper::checkObject($module) + && isset($module->file_name)) { - $module_context = 'module.' . $module->file_name . '.' . $module->id; + $module_context = 'module.' . $module->file_name . '.' + . $module->id; // set the repo path - $repoFullPath = $this->repoPath . '/' . $module->folder_name . '__joomla_' . $this->joomlaVersion; + $repoFullPath = $this->repoPath . '/' + . $module->folder_name . '__joomla_' + . $this->joomlaVersion; // Trigger Event: jcb_ce_onBeforeUpdateRepo - $this->triggerEvent('jcb_ce_onBeforeUpdateRepo', array(&$module_context, &$module->folder_path, &$repoFullPath, &$module)); + $this->triggerEvent( + 'jcb_ce_onBeforeUpdateRepo', + array(&$module_context, &$module->folder_path, + &$repoFullPath, &$module) + ); // remove old data - $this->removeFolder($repoFullPath, $this->componentData->toignore); + $this->removeFolder( + $repoFullPath, $this->componentData->toignore + ); // set the new data - JFolder::copy($module->folder_path, $repoFullPath, '', true); + JFolder::copy( + $module->folder_path, $repoFullPath, '', true + ); // Trigger Event: jcb_ce_onAfterUpdateRepo - $this->triggerEvent('jcb_ce_onAfterUpdateRepo', array(&$module_context, &$module->folder_path, &$repoFullPath, &$module)); + $this->triggerEvent( + 'jcb_ce_onAfterUpdateRepo', + array(&$module_context, &$module->folder_path, + &$repoFullPath, &$module) + ); } } } @@ -656,19 +928,35 @@ class Compiler extends Infusion { foreach ($this->joomlaPlugins as $plugin) { - if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->file_name)) + if (ComponentbuilderHelper::checkObject($plugin) + && isset($plugin->file_name)) { - $plugin_context = 'plugin.' . $plugin->file_name . '.' . $plugin->id; + $plugin_context = 'plugin.' . $plugin->file_name . '.' + . $plugin->id; // set the repo path - $repoFullPath = $this->repoPath . '/' . $plugin->folder_name . '__joomla_' . $this->joomlaVersion; + $repoFullPath = $this->repoPath . '/' + . $plugin->folder_name . '__joomla_' + . $this->joomlaVersion; // Trigger Event: jcb_ce_onBeforeUpdateRepo - $this->triggerEvent('jcb_ce_onBeforeUpdateRepo', array(&$plugin_context, &$plugin->folder_path, &$repoFullPath, &$plugin)); + $this->triggerEvent( + 'jcb_ce_onBeforeUpdateRepo', + array(&$plugin_context, &$plugin->folder_path, + &$repoFullPath, &$plugin) + ); // remove old data - $this->removeFolder($repoFullPath, $this->componentData->toignore); + $this->removeFolder( + $repoFullPath, $this->componentData->toignore + ); // set the new data - JFolder::copy($plugin->folder_path, $repoFullPath, '', true); + JFolder::copy( + $plugin->folder_path, $repoFullPath, '', true + ); // Trigger Event: jcb_ce_onAfterUpdateRepo - $this->triggerEvent('jcb_ce_onAfterUpdateRepo', array(&$plugin_context, &$plugin->folder_path, &$repoFullPath, &$plugin)); + $this->triggerEvent( + 'jcb_ce_onAfterUpdateRepo', + array(&$plugin_context, &$plugin->folder_path, + &$repoFullPath, &$plugin) + ); } } } @@ -680,41 +968,76 @@ class Compiler extends Infusion // Component Folder Name $this->filepath['component-folder'] = $this->componentFolderName; // the name of the zip file to create - $this->filepath['component'] = $this->tempPath . '/' . $this->filepath['component-folder'] . '.zip'; + $this->filepath['component'] = $this->tempPath . '/' + . $this->filepath['component-folder'] . '.zip'; // Trigger Event: jcb_ce_onBeforeZipComponent - $this->triggerEvent('jcb_ce_onBeforeZipComponent', array(&$this->componentContext, &$this->componentPath, &$this->filepath['component'], &$this->tempPath, &$this->componentFolderName, &$this->componentData)); + $this->triggerEvent( + 'jcb_ce_onBeforeZipComponent', + array(&$this->componentContext, &$this->componentPath, + &$this->filepath['component'], &$this->tempPath, + &$this->componentFolderName, &$this->componentData) + ); //create the zip file - if (ComponentbuilderHelper::zip($this->componentPath, $this->filepath['component'])) + if (ComponentbuilderHelper::zip( + $this->componentPath, $this->filepath['component'] + )) { // now move to backup if zip was made and backup is required if ($this->backupPath && $this->dynamicIntegration) { // Trigger Event: jcb_ce_onBeforeBackupZip - $this->triggerEvent('jcb_ce_onBeforeBackupZip', array(&$this->componentContext, &$this->filepath['component'], &$this->tempPath, &$this->backupPath, &$this->componentData)); + $this->triggerEvent( + 'jcb_ce_onBeforeBackupZip', array(&$this->componentContext, + &$this->filepath['component'], + &$this->tempPath, + &$this->backupPath, + &$this->componentData) + ); // copy the zip to backup path - JFile::copy($this->filepath['component'], $this->backupPath . '/' . $this->componentBackupName . '.zip'); + JFile::copy( + $this->filepath['component'], + $this->backupPath . '/' . $this->componentBackupName + . '.zip' + ); } // move to sales server host - if ($this->componentData->add_sales_server == 1 && $this->dynamicIntegration) + if ($this->componentData->add_sales_server == 1 + && $this->dynamicIntegration) { // make sure we have the correct file if (isset($this->componentData->sales_server)) { // Trigger Event: jcb_ce_onBeforeMoveToServer - $this->triggerEvent('jcb_ce_onBeforeMoveToServer', array(&$this->componentContext, &$this->filepath['component'], &$this->tempPath, &$this->componentSalesName, &$this->componentData)); + $this->triggerEvent( + 'jcb_ce_onBeforeMoveToServer', + array(&$this->componentContext, + &$this->filepath['component'], &$this->tempPath, + &$this->componentSalesName, &$this->componentData) + ); // move to server - ComponentbuilderHelper::moveToServer($this->filepath['component'], $this->componentSalesName . '.zip', (int) $this->componentData->sales_server, $this->componentData->sales_server_protocol); + ComponentbuilderHelper::moveToServer( + $this->filepath['component'], + $this->componentSalesName . '.zip', + (int) $this->componentData->sales_server, + $this->componentData->sales_server_protocol + ); } } // Trigger Event: jcb_ce_onAfterZipComponent - $this->triggerEvent('jcb_ce_onAfterZipComponent', array(&$this->componentContext, &$this->filepath['component'], &$this->tempPath, &$this->componentFolderName, &$this->componentData)); + $this->triggerEvent( + 'jcb_ce_onAfterZipComponent', + array(&$this->componentContext, &$this->filepath['component'], + &$this->tempPath, &$this->componentFolderName, + &$this->componentData) + ); // remove the component folder since we are done if ($this->removeFolder($this->componentPath)) { return true; } } + return false; } @@ -724,30 +1047,53 @@ class Compiler extends Infusion { foreach ($this->joomlaModules as $module) { - if (ComponentbuilderHelper::checkObject($module) && isset($module->zip_name) + if (ComponentbuilderHelper::checkObject($module) + && isset($module->zip_name) && ComponentbuilderHelper::checkString($module->zip_name) && isset($module->folder_path) - && ComponentbuilderHelper::checkString($module->folder_path)) + && ComponentbuilderHelper::checkString( + $module->folder_path + )) { // set module context $module_context = $module->file_name . '.' . $module->id; // Component Folder Name - $this->filepath['modules-folder'][$module->id] = $module->zip_name; + $this->filepath['modules-folder'][$module->id] + = $module->zip_name; // the name of the zip file to create - $this->filepath['modules'][$module->id] = $this->tempPath . '/' . $module->zip_name . '.zip'; + $this->filepath['modules'][$module->id] = $this->tempPath + . '/' . $module->zip_name . '.zip'; // Trigger Event: jcb_ce_onBeforeZipModule - $this->triggerEvent('jcb_ce_onBeforeZipModule', array(&$module_context, &$module->folder_path, &$this->filepath['modules'][$module->id], &$this->tempPath, &$module->zip_name, &$module)); + $this->triggerEvent( + 'jcb_ce_onBeforeZipModule', + array(&$module_context, &$module->folder_path, + &$this->filepath['modules'][$module->id], + &$this->tempPath, &$module->zip_name, &$module) + ); //create the zip file - if (ComponentbuilderHelper::zip($module->folder_path, $this->filepath['modules'][$module->id])) + if (ComponentbuilderHelper::zip( + $module->folder_path, + $this->filepath['modules'][$module->id] + )) { // now move to backup if zip was made and backup is required if ($this->backupPath) { $__module_context = 'module.' . $module_context; // Trigger Event: jcb_ce_onBeforeBackupZip - $this->triggerEvent('jcb_ce_onBeforeBackupZip', array(&$__module_context, &$this->filepath['modules'][$module->id], &$this->tempPath, &$this->backupPath, &$module)); + $this->triggerEvent( + 'jcb_ce_onBeforeBackupZip', + array(&$__module_context, + &$this->filepath['modules'][$module->id], + &$this->tempPath, &$this->backupPath, + &$module) + ); // copy the zip to backup path - JFile::copy($this->filepath['modules'][$module->id], $this->backupPath . '/' . $module->zip_name . '.zip'); + JFile::copy( + $this->filepath['modules'][$module->id], + $this->backupPath . '/' . $module->zip_name + . '.zip' + ); } // move to sales server host @@ -757,13 +1103,30 @@ class Compiler extends Infusion if (isset($module->sales_server)) { // Trigger Event: jcb_ce_onBeforeMoveToServer - $this->triggerEvent('jcb_ce_onBeforeMoveToServer', array(&$__module_context, &$this->filepath['modules'][$module->id], &$this->tempPath, &$module->zip_name, &$module)); + $this->triggerEvent( + 'jcb_ce_onBeforeMoveToServer', + array(&$__module_context, + &$this->filepath['modules'][$module->id], + &$this->tempPath, &$module->zip_name, + &$module) + ); // move to server - ComponentbuilderHelper::moveToServer($this->filepath['modules'][$module->id], $module->zip_name . '.zip', (int) $module->sales_server, $module->sales_server_protocol); + ComponentbuilderHelper::moveToServer( + $this->filepath['modules'][$module->id], + $module->zip_name . '.zip', + (int) $module->sales_server, + $module->sales_server_protocol + ); } } // Trigger Event: jcb_ce_onAfterZipModule - $this->triggerEvent('jcb_ce_onAfterZipModule', array(&$module_context, &$this->filepath['modules'][$module->id], &$this->tempPath, &$module->zip_name, &$module)); + $this->triggerEvent( + 'jcb_ce_onAfterZipModule', array(&$module_context, + &$this->filepath['modules'][$module->id], + &$this->tempPath, + &$module->zip_name, + &$module) + ); // remove the module folder since we are done $this->removeFolder($module->folder_path); } @@ -778,30 +1141,53 @@ class Compiler extends Infusion { foreach ($this->joomlaPlugins as $plugin) { - if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->zip_name) + if (ComponentbuilderHelper::checkObject($plugin) + && isset($plugin->zip_name) && ComponentbuilderHelper::checkString($plugin->zip_name) && isset($plugin->folder_path) - && ComponentbuilderHelper::checkString($plugin->folder_path)) + && ComponentbuilderHelper::checkString( + $plugin->folder_path + )) { // set plugin context $plugin_context = $plugin->file_name . '.' . $plugin->id; // Component Folder Name - $this->filepath['plugins-folder'][$plugin->id] = $plugin->zip_name; + $this->filepath['plugins-folder'][$plugin->id] + = $plugin->zip_name; // the name of the zip file to create - $this->filepath['plugins'][$plugin->id] = $this->tempPath . '/' . $plugin->zip_name . '.zip'; + $this->filepath['plugins'][$plugin->id] = $this->tempPath + . '/' . $plugin->zip_name . '.zip'; // Trigger Event: jcb_ce_onBeforeZipPlugin - $this->triggerEvent('jcb_ce_onBeforeZipPlugin', array(&$plugin_context, &$plugin->folder_path, &$this->filepath['plugins'][$plugin->id], &$this->tempPath, &$plugin->zip_name, &$plugin)); + $this->triggerEvent( + 'jcb_ce_onBeforeZipPlugin', + array(&$plugin_context, &$plugin->folder_path, + &$this->filepath['plugins'][$plugin->id], + &$this->tempPath, &$plugin->zip_name, &$plugin) + ); //create the zip file - if (ComponentbuilderHelper::zip($plugin->folder_path, $this->filepath['plugins'][$plugin->id])) + if (ComponentbuilderHelper::zip( + $plugin->folder_path, + $this->filepath['plugins'][$plugin->id] + )) { // now move to backup if zip was made and backup is required if ($this->backupPath) { $__plugin_context = 'plugin.' . $plugin_context; // Trigger Event: jcb_ce_onBeforeBackupZip - $this->triggerEvent('jcb_ce_onBeforeBackupZip', array(&$__plugin_context, &$this->filepath['plugins'][$plugin->id], &$this->tempPath, &$this->backupPath, &$plugin)); + $this->triggerEvent( + 'jcb_ce_onBeforeBackupZip', + array(&$__plugin_context, + &$this->filepath['plugins'][$plugin->id], + &$this->tempPath, &$this->backupPath, + &$plugin) + ); // copy the zip to backup path - JFile::copy($this->filepath['plugins'][$plugin->id], $this->backupPath . '/' . $plugin->zip_name . '.zip'); + JFile::copy( + $this->filepath['plugins'][$plugin->id], + $this->backupPath . '/' . $plugin->zip_name + . '.zip' + ); } // move to sales server host @@ -811,13 +1197,30 @@ class Compiler extends Infusion if (isset($plugin->sales_server)) { // Trigger Event: jcb_ce_onBeforeMoveToServer - $this->triggerEvent('jcb_ce_onBeforeMoveToServer', array(&$__plugin_context, &$this->filepath['plugins'][$plugin->id], &$this->tempPath, &$plugin->zip_name, &$plugin)); + $this->triggerEvent( + 'jcb_ce_onBeforeMoveToServer', + array(&$__plugin_context, + &$this->filepath['plugins'][$plugin->id], + &$this->tempPath, &$plugin->zip_name, + &$plugin) + ); // move to server - ComponentbuilderHelper::moveToServer($this->filepath['plugins'][$plugin->id], $plugin->zip_name . '.zip', (int) $plugin->sales_server, $plugin->sales_server_protocol); + ComponentbuilderHelper::moveToServer( + $this->filepath['plugins'][$plugin->id], + $plugin->zip_name . '.zip', + (int) $plugin->sales_server, + $plugin->sales_server_protocol + ); } } // Trigger Event: jcb_ce_onAfterZipPlugin - $this->triggerEvent('jcb_ce_onAfterZipPlugin', array(&$plugin_context, &$this->filepath['plugins'][$plugin->id], &$this->tempPath, &$plugin->zip_name, &$plugin)); + $this->triggerEvent( + 'jcb_ce_onAfterZipPlugin', array(&$plugin_context, + &$this->filepath['plugins'][$plugin->id], + &$this->tempPath, + &$plugin->zip_name, + &$plugin) + ); // remove the plugin folder since we are done $this->removeFolder($plugin->folder_path); } @@ -835,22 +1238,29 @@ class Compiler extends Infusion { // reset each time per custom code $fingerPrint = array(); - if (isset($target['hashtarget'][0]) && $target['hashtarget'][0] > 3 && isset($target['path']) && ComponentbuilderHelper::checkString($target['path']) && isset($target['hashtarget'][1]) && ComponentbuilderHelper::checkString($target['hashtarget'][1])) + if (isset($target['hashtarget'][0]) && $target['hashtarget'][0] > 3 + && isset($target['path']) + && ComponentbuilderHelper::checkString($target['path']) + && isset($target['hashtarget'][1]) + && ComponentbuilderHelper::checkString( + $target['hashtarget'][1] + )) { - $file = $this->componentPath . '/' . $target['path']; - $size = (int) $target['hashtarget'][0]; - $hash = $target['hashtarget'][1]; - $cut = $size - 1; - $found = false; - $bites = 0; + $file = $this->componentPath . '/' . $target['path']; + $size = (int) $target['hashtarget'][0]; + $hash = $target['hashtarget'][1]; + $cut = $size - 1; + $found = false; + $bites = 0; $lineBites = array(); - $replace = array(); - if ($target['type'] == 1 && isset($target['hashendtarget'][0]) && $target['hashendtarget'][0] > 0) + $replace = array(); + if ($target['type'] == 1 && isset($target['hashendtarget'][0]) + && $target['hashendtarget'][0] > 0) { $foundEnd = false; - $sizeEnd = (int) $target['hashendtarget'][0]; - $hashEnd = $target['hashendtarget'][1]; - $cutEnd = $sizeEnd - 1; + $sizeEnd = (int) $target['hashendtarget'][0]; + $hashEnd = $target['hashendtarget'][1]; + $cutEnd = $sizeEnd - 1; } else { @@ -861,13 +1271,19 @@ class Compiler extends Infusion // check if file exist if (JFile::exists($file)) { - foreach (new SplFileObject($file) as $lineNumber => $lineContent) + foreach ( + new SplFileObject($file) as $lineNumber => $lineContent + ) { // if not found we need to load line bites per line - $lineBites[$lineNumber] = (int) mb_strlen($lineContent, '8bit'); + $lineBites[$lineNumber] = (int) mb_strlen( + $lineContent, '8bit' + ); if (!$found) { - $bites = (int) ComponentbuilderHelper::bcmath('add', $lineBites[$lineNumber], $bites); + $bites = (int) ComponentbuilderHelper::bcmath( + 'add', $lineBites[$lineNumber], $bites + ); } if ($found && !$foundEnd) { @@ -875,19 +1291,24 @@ class Compiler extends Infusion // we musk keep last three lines to dynamic find target entry $fingerPrint[$lineNumber] = trim($lineContent); // check lines each time if it fits our target - if (count((array) $fingerPrint) === $sizeEnd && !$foundEnd) + if (count((array) $fingerPrint) === $sizeEnd + && !$foundEnd) { $fingerTest = md5(implode('', $fingerPrint)); if ($fingerTest === $hashEnd) { // we are done here $foundEnd = true; - $replace = array_slice($replace, 0, count($replace) - $sizeEnd); + $replace = array_slice( + $replace, 0, count($replace) - $sizeEnd + ); break; } else { - $fingerPrint = array_slice($fingerPrint, -$cutEnd, $cutEnd, true); + $fingerPrint = array_slice( + $fingerPrint, -$cutEnd, $cutEnd, true + ); } } continue; @@ -916,14 +1337,22 @@ class Compiler extends Infusion } else { - $fingerPrint = array_slice($fingerPrint, -$cut, $cut, true); + $fingerPrint = array_slice( + $fingerPrint, -$cut, $cut, true + ); } } } if ($found) { - $placeholder = $this->getPlaceHolder((int) $target['comment_type'] . $target['type'], $target['id']); - $data = $placeholder['start'] . PHP_EOL . $this->setPlaceholders($target['code'], $this->placeholders) . $placeholder['end'] . PHP_EOL; + $placeholder = $this->getPlaceHolder( + (int) $target['comment_type'] . $target['type'], + $target['id'] + ); + $data = $placeholder['start'] . PHP_EOL + . $this->setPlaceholders( + $target['code'], $this->placeholders + ) . $placeholder['end'] . PHP_EOL; if ($target['type'] == 2) { // found it now add code from the next line @@ -932,29 +1361,61 @@ class Compiler extends Infusion elseif ($target['type'] == 1 && $foundEnd) { // found it now add code from the next line - $this->addDataToFile($file, $data, $bites, (int) array_sum($replace)); + $this->addDataToFile( + $file, $data, $bites, (int) array_sum($replace) + ); } else { // Load escaped code since the target endhash has changed $this->loadEscapedCode($file, $target, $lineBites); - $this->app->enqueueMessage(JText::_('

Custom Code Warning

'), 'Warning'); - $this->app->enqueueMessage(JText::sprintf('Custom code %s could not be added to %s please review the file after install at line %s and reposition the code, remove the comments and recompile to fix the issue. The issue could be due to a change to lines below the custom code.', '#' . $target['id'] . '', $target['path'], $target['from_line']), 'Warning'); + $this->app->enqueueMessage( + JText::_('

Custom Code Warning

'), + 'Warning' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'Custom code %s could not be added to %s please review the file after install at line %s and reposition the code, remove the comments and recompile to fix the issue. The issue could be due to a change to lines below the custom code.', + '#' + . $target['id'] . '', $target['path'], + $target['from_line'] + ), 'Warning' + ); } } else { // Load escaped code since the target hash has changed $this->loadEscapedCode($file, $target, $lineBites); - $this->app->enqueueMessage(JText::_('

Custom Code Warning

'), 'Warning'); - $this->app->enqueueMessage(JText::sprintf('Custom code %s could not be added to %s please review the file after install at line %s and reposition the code, remove the comments and recompile to fix the issue. The issue could be due to a change to lines above the custom code.', '#' . $target['id'] . '', $target['path'], $target['from_line']), 'Warning'); + $this->app->enqueueMessage( + JText::_('

Custom Code Warning

'), + 'Warning' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'Custom code %s could not be added to %s please review the file after install at line %s and reposition the code, remove the comments and recompile to fix the issue. The issue could be due to a change to lines above the custom code.', + '#' + . $target['id'] . '', $target['path'], + $target['from_line'] + ), 'Warning' + ); } } else { // Give developer a notice that file is not found. - $this->app->enqueueMessage(JText::_('

Custom Code Warning

'), 'Warning'); - $this->app->enqueueMessage(JText::sprintf('File %s could not be found, so the custom code for this file could not be addded.', $target['path']), 'Warning'); + $this->app->enqueueMessage( + JText::_('

Custom Code Warning

'), + 'Warning' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'File %s could not be found, so the custom code for this file could not be addded.', + $target['path'] + ), 'Warning' + ); } } } @@ -965,19 +1426,23 @@ class Compiler extends Infusion // get comment type if ($target['comment_type'] == 1) { - $commentType = "// "; + $commentType = "// "; $_commentType = ""; } else { - $commentType = ""; } // escape the code $code = explode(PHP_EOL, $target['code']); - $code = PHP_EOL . $commentType . implode($_commentType . PHP_EOL . $commentType, $code) . $_commentType . PHP_EOL; + $code = PHP_EOL . $commentType . implode( + $_commentType . PHP_EOL . $commentType, $code + ) . $_commentType . PHP_EOL; // get place holders - $placeholder = $this->getPlaceHolder((int) $target['comment_type'] . $target['type'], $target['id']); + $placeholder = $this->getPlaceHolder( + (int) $target['comment_type'] . $target['type'], $target['id'] + ); // build the data $data = $placeholder['start'] . $code . $placeholder['end'] . PHP_EOL; // get the bites before insertion @@ -1006,12 +1471,16 @@ class Compiler extends Infusion // Add the data fwrite($fpFile, $data); // truncate file at the end of the data that was added - $remove = ComponentbuilderHelper::bcmath('add', $position, mb_strlen($data, '8bit')); + $remove = ComponentbuilderHelper::bcmath( + 'add', $position, mb_strlen($data, '8bit') + ); ftruncate($fpFile, $remove); // check if this was a replacement of data if ($replace) { - $position = ComponentbuilderHelper::bcmath('add', $position, $replace); + $position = ComponentbuilderHelper::bcmath( + 'add', $position, $replace + ); } // move to the position of the data that should remain below the new data fseek($fpTemp, $position); diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index aeaaddb44..8976c4176 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -5,7 +5,7 @@ * @created 30th April, 2015 * @author Llewellyn van der Merwe * @github Joomla Component Builder - * @copyright Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + * @copyright Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ @@ -20,111 +20,112 @@ class Get /** * The Joomla Version - * + * * @var string */ public $joomlaVersion; /** * The hash placeholder - * + * * @var string */ public $hhh = '#' . '#' . '#'; /** * The open bracket placeholder - * + * * @var string */ public $bbb = '[' . '[' . '['; /** * The close bracket placeholder - * + * * @var string */ public $ddd = ']' . ']' . ']'; /** * The app - * + * * @var object */ public $app; /** * The Params - * + * * @var object */ public $params; /** * Add strict field export permissions - * + * * @var boolean */ public $strictFieldExportPermissions = false; /** * Add text only export options - * + * * @var boolean */ public $exportTextOnly = false; /** * The global placeholders - * + * * @var array */ public $globalPlaceholders = array(); /** * The placeholders - * + * * @var array */ public $placeholders = array(); /** * The Compiler Path - * + * * @var object */ public $compilerPath; /** * Switch to add custom code placeholders - * + * * @var bool */ public $addPlaceholders = false; /** * The placeholders for custom code keys - * + * * @var array */ - protected $customCodeKeyPlacholders = array( - '[' => '[', - ']' => ']', - ',' => ',', - '+' => '+', - '=' => '=' + protected $customCodeKeyPlacholders + = array( + '[' => '[', + ']' => ']', + ',' => ',', + '+' => '+', + '=' => '=' ); /** * The Component data - * + * * @var object */ public $componentData; /** * The Plugins data - * + * * @var array */ public $joomlaPlugins = array(); @@ -137,643 +138,650 @@ class Get public $joomlaModules = array(); /** - * The custom script placeholders - we use the (xxx) to avoid detection it should be (***) - * ##################################---> PHP/JS <---#################################### - * - * New Insert Code = /xxx[INSERT<>$$$$]xxx/ /xxx[/INSERT<>$$$$]xxx/ - * New Replace Code = /xxx[REPLACE<>$$$$]xxx/ /xxx[/REPLACE<>$$$$]xxx/ + * The custom script placeholders - we use the (xxx) to avoid detection it should be (***) + * ##################################---> PHP/JS <---#################################### * - * //////////////////////////////// when JCB adds it back ////////////////////////////////// - * JCB Add Inserted Code = /xxx[INSERTED$$$$]xxx//x23x/ /xxx[/INSERTED$$$$]xxx/ - * JCB Add Replaced Code = /xxx[REPLACED$$$$]xxx//x25x/ /xxx[/REPLACED$$$$]xxx/ + * New Insert Code = /xxx[INSERT<>$$$$]xxx/ /xxx[/INSERT<>$$$$]xxx/ + * New Replace Code = /xxx[REPLACE<>$$$$]xxx/ /xxx[/REPLACE<>$$$$]xxx/ * - * /////////////////////////////// changeing existing custom code ///////////////////////// - * Update Inserted Code = /xxx[INSERTED<>$$$$]xxx//x23x/ /xxx[/INSERTED<>$$$$]xxx/ - * Update Replaced Code = /xxx[REPLACED<>$$$$]xxx//x25x/ /xxx[/REPLACED<>$$$$]xxx/ - * - * The custom script placeholders - we use the (==) to avoid detection it should be (--) - * ###################################---> HTML <---##################################### - * - * New Insert Code = $$$$]==> $$$$]==> - * New Replace Code = $$$$]==> $$$$]==> + * //////////////////////////////// when JCB adds it back ////////////////////////////////// + * JCB Add Inserted Code = /xxx[INSERTED$$$$]xxx//x23x/ /xxx[/INSERTED$$$$]xxx/ + * JCB Add Replaced Code = /xxx[REPLACED$$$$]xxx//x25x/ /xxx[/REPLACED$$$$]xxx/ * - * ///////////////////////////////// when JCB adds it back /////////////////////////////// - * JCB Add Inserted Code = - * JCB Add Replaced Code = + * /////////////////////////////// changeing existing custom code ///////////////////////// + * Update Inserted Code = /xxx[INSERTED<>$$$$]xxx//x23x/ /xxx[/INSERTED<>$$$$]xxx/ + * Update Replaced Code = /xxx[REPLACED<>$$$$]xxx//x25x/ /xxx[/REPLACED<>$$$$]xxx/ * - * //////////////////////////// changeing existing custom code /////////////////////////// - * Update Inserted Code = $$$$]==> $$$$]==> - * Update Replaced Code = $$$$]==> $$$$]==> - * - * ////////23 is the ID of the code in the system don't change it!!!!!!!!!!!!!!!!!!!!!!!!!! - * - * @var array + * The custom script placeholders - we use the (==) to avoid detection it should be (--) + * ###################################---> HTML <---##################################### + * + * New Insert Code = $$$$]==> $$$$]==> + * New Replace Code = $$$$]==> $$$$]==> + * + * ///////////////////////////////// when JCB adds it back /////////////////////////////// + * JCB Add Inserted Code = + * JCB Add Replaced Code = + * + * //////////////////////////// changeing existing custom code /////////////////////////// + * Update Inserted Code = $$$$]==> $$$$]==> + * Update Replaced Code = $$$$]==> $$$$]==> + * + * ////////23 is the ID of the code in the system don't change it!!!!!!!!!!!!!!!!!!!!!!!!!! + * + * @var array */ - protected $customCodePlaceholders = array( - 1 => 'REPLACE<>$$$$]', - 2 => 'INSERT<>$$$$]', - 3 => 'REPLACED<>$$$$]', - 4 => 'INSERTED<>$$$$]' - ); + protected $customCodePlaceholders + = array( + 1 => 'REPLACE<>$$$$]', + 2 => 'INSERT<>$$$$]', + 3 => 'REPLACED<>$$$$]', + 4 => 'INSERTED<>$$$$]' + ); /** * The custom code to be added - * + * * @var array */ public $customCode; /** * The custom code to be added - * + * * @var array */ protected $customCodeData = array(); /** * The function name memory ids - * + * * @var array */ public $functionNameMemory = array(); /** * The custom code for local memory - * + * * @var array */ public $customCodeMemory = array(); /** * The custom code in local files that already exist in system - * + * * @var array */ protected $existingCustomCode = array(); /** * The custom code in local files this are new - * + * * @var array */ protected $newCustomCode = array(); /** * The index of code already loaded - * + * * @var array */ protected $codeAreadyDone = array(); /** * The external code/string to be added - * + * * @var array */ protected $externalCodeString = array(); /* * The line numbers Switch - * + * * @var boolean */ public $debugLinenr = false; /* * The percentage when a language should be added - * + * * @var boolean */ public $percentageLanguageAdd = 0; /** * The Placholder Language prefix - * + * * @var string */ public $langPrefix; /** * The Language content - * + * * @var array */ public $langContent = array(); /** * The Languages bucket - * + * * @var array */ - public $languages = array(); + public $languages + = array('components' => array(), 'modules' => array(), + 'plugins' => array()); /** * The Main Languages - * + * * @var string */ public $langTag = 'en-GB'; /** * The Multi Languages bucket - * + * * @var array */ public $multiLangString = array(); /** * The new lang to add - * + * * @var array */ protected $newLangStrings = array(); /** * The existing lang to update - * + * * @var array */ protected $existingLangStrings = array(); /** * The Language JS matching check - * + * * @var array */ public $langMismatch = array(); /** * The Language SC matching check - * + * * @var array */ public $langMatch = array(); /** * The Language string targets - * + * * @var array */ - public $langStringTargets = array( - 'Joomla' . '.JText._(', - 'JText:' . ':script(', - 'JText:' . ':_(', - 'JText:' . ':sprintf(', - 'JustTEXT:' . ':_(' - ); + public $langStringTargets + = array( + 'Joomla' . '.JText._(', + 'JText:' . ':script(', + 'JText:' . ':_(', + 'JText:' . ':sprintf(', + 'JustTEXT:' . ':_(' + ); /** * The Component Code Name - * + * * @var string */ public $componentCodeName; /** * The Component ID - * + * * @var int */ public $componentID; /** * The current user - * + * * @var array */ public $user; /** * The database object - * + * * @var array */ public $db; /** * The Component version - * + * * @var string */ public $component_version; /** * The UIKIT Switch - * - * @var boolean + * + * @var boolean */ public $uikit = 0; /** * The UIKIT component checker - * + * * @var array */ public $uikitComp = array(); /** * The FOOTABLE Switch - * + * * @var boolean */ public $footable = false; /** * The FOOTABLE Version - * + * * @var int */ public $footableVersion; /** * The Google Chart Switch per view - * + * * @var array */ public $googleChart = array(); /** * The Google Chart Switch - * + * * @var boolean */ public $googlechart = false; /** * The Import & Export Switch - * + * * @var boolean */ public $addEximport = false; /** * The Tag & History Switch - * + * * @var boolean */ public $setTagHistory = false; /** * The Joomla Fields Switch - * + * * @var boolean */ public $setJoomlaFields = false; /** * The site edit views - * + * * @var array */ public $siteEditView = array(); /** * The Language target - * + * * @var string */ public $lang = 'admin'; /** * The lang keys for extentions - * + * * @var array */ public $langKeys = array(); /** * The Build target Switch - * + * * @var string */ public $target; /** * The unique codes - * + * * @var array */ public $uniquecodes = array(); /** * The unique keys - * + * * @var array */ public $uniquekeys = array(); /** * The Ad contributors Switch - * + * * @var boolean */ public $addContributors = false; /** * The Custom Script Builder - * + * * @var array */ public $customScriptBuilder = array(); /** * The Footable Script Builder - * + * * @var array */ public $footableScripts = array(); /** * The pathe to the bom file to be used - * + * * @var string */ public $bomPath; /** * The SQL Tweak of admin views - * + * * @var array */ public $sqlTweak = array(); /** * The validation rules that should be added - * + * * @var array */ public $validationRules = array(); /** * The validation linked to fields - * + * * @var array */ public $validationLinkedFields = array(); /** * The admin views data array - * + * * @var array */ private $_adminViewData = array(); /** * The field data array - * + * * @var array */ private $_fieldData = array(); /** * The custom alias builder - * + * * @var array */ public $customAliasBuilder = array(); /** * The field builder type - * + * * 1 = StringManipulation * 2 = SimpleXMLElement - * + * * @var int */ public $fieldBuilderType; /** * Set unique Names - * + * * @var array */ public $uniqueNames = array(); /** * Set unique Names - * + * * @var array */ protected $uniqueFieldNames = array(); /** * Category other name bucket - * + * * @var array */ public $catOtherName = array(); /** * The field relations values - * + * * @var array */ public $fieldRelations = array(); /** * Default Fields - * + * * @var array */ - public $defaultFields = array('created', 'created_by', 'modified', 'modified_by', 'published', 'ordering', 'access', 'version', 'hits', 'id'); + public $defaultFields + = array('created', 'created_by', 'modified', 'modified_by', 'published', + 'ordering', 'access', 'version', 'hits', 'id'); /** * The list join fields - * + * * @var array */ public $listJoinBuilder = array(); /** * The list head over ride - * + * * @var array */ public $listHeadOverRide = array(); /** * The linked admin view tabs - * + * * @var array */ public $linkedAdminViews = array(); /** * The custom admin view tabs - * + * * @var array */ public $customTabs = array(); /** * The Add Ajax Switch - * + * * @var boolean */ public $addAjax = false; /** * The Add Site Ajax Switch - * + * * @var boolean */ public $addSiteAjax = false; /** * The get Module Script Switch - * + * * @var array */ public $getModule = array(); /** * The template data - * + * * @var array */ public $templateData = array(); /** * The layout data - * + * * @var array */ public $layoutData = array(); /** * The Encryption Types - * + * * @var array */ public $cryptionTypes = array('basic', 'medium', 'whmcs', 'expert'); /** * The WHMCS Encryption Switch - * + * * @var boolean */ public $whmcsEncryption = false; /** * The Basic Encryption Switch - * + * * @var boolean */ public $basicEncryption = false; /** * The Medium Encryption Switch - * + * * @var boolean */ public $mediumEncryption = false; /** * The Custom field Switch per view - * + * * @var array */ public $customFieldScript = array(); /** * The site main get - * + * * @var array */ public $siteMainGet = array(); /** * The site dynamic get - * + * * @var array */ public $siteDynamicGet = array(); /** * The get AS lookup - * + * * @var array */ public $getAsLookup = array(); /** * The site fields - * + * * @var array */ public $siteFields = array(); /** * The add SQL - * + * * @var array */ public $addSQL = array(); /** * The update SQL - * + * * @var array */ public $updateSQL = array(); /** * The Library Manager - * + * * @var array */ public $libManager = array(); /** * The Libraries - * + * * @var array */ public $libraries = array(); /** * Is minify Enabled - * + * * @var int */ public $minify = 0; /** * Is Tidy Enabled - * + * * @var bool */ public $tidy = false; /** * Set Tidy warning once switch - * + * * @var bool */ public $setTidyWarning = false; /** * mysql table setting keys - * + * * @var array */ - public $mysqlTableKeys = array( - 'engine' => array('default' => 'MyISAM'), - 'charset' => array('default' => 'utf8'), - 'collate' => array('default' => 'utf8_general_ci'), - 'row_format' => array('default' => '') + public $mysqlTableKeys + = array( + 'engine' => array('default' => 'MyISAM'), + 'charset' => array('default' => 'utf8'), + 'collate' => array('default' => 'utf8_general_ci'), + 'row_format' => array('default' => '') ); /** * mysql table settings - * + * * @var array */ public $mysqlTableSetting = array(); /** * event plugin trigger switch - * + * * @var boolean */ protected $active_plugins = false; @@ -790,11 +798,12 @@ class Get // Set the params $this->params = JComponentHelper::getParams('com_componentbuilder'); // get active plugins - if (($plugins = $this->params->get('compiler_plugin', false)) !== false) + if (($plugins = $this->params->get('compiler_plugin', false)) + !== false) { foreach ($plugins as $plugin) { - // get posible plugins + // get possible plugins if (\JPluginHelper::isEnabled('extension', $plugin)) { // Import the appropriate plugin group. @@ -809,45 +818,73 @@ class Get // set the Joomla version $this->joomlaVersion = $config['version']; // set the minfy switch of the JavaScript - $this->minify = (isset($config['minify']) && $config['minify'] != 2) ? $config['minify'] : $this->params->get('minify', 0); + $this->minify = (isset($config['minify']) && $config['minify'] != 2) + ? $config['minify'] : $this->params->get('minify', 0); // set the global language $this->langTag = $this->params->get('language', $this->langTag); // also set the helper class langTag (for safeStrings) ComponentbuilderHelper::$langTag = $this->langTag; // setup the main language array - $this->languages[$this->langTag] = array(); + $this->languages['components'][$this->langTag] = array(); // check if we have Tidy enabled $this->tidy = extension_loaded('Tidy'); // set the field type builder - $this->fieldBuilderType = $this->params->get('compiler_field_builder_type', 2); + $this->fieldBuilderType = $this->params->get( + 'compiler_field_builder_type', 2 + ); // check the field builder type logic if (!$this->tidy && $this->fieldBuilderType == 2) { // we do not have the tidy extention set fall back to StringManipulation $this->fieldBuilderType = 1; // load the sugestion to use string manipulation - $this->app->enqueueMessage(JText::_('

Field Notice

'), 'Notice'); - $this->app->enqueueMessage(JText::_('Since you do not have Tidy extentsion setup on your system, we could not use the SimpleXMLElement class. We instead used string manipulation to build all your fields, this is a faster method, you must inspect the xml files in your component package to see if you are satisfied with the result.
You can make this method your default by opening the global options of JCB and under the Global tab set the Field Builder Type to string manipulation.'), 'Notice'); + $this->app->enqueueMessage( + JText::_('

Field Notice

'), 'Notice' + ); + $this->app->enqueueMessage( + JText::_( + 'Since you do not have Tidy extentsion setup on your system, we could not use the SimpleXMLElement class. We instead used string manipulation to build all your fields, this is a faster method, you must inspect the xml files in your component package to see if you are satisfied with the result.
You can make this method your default by opening the global options of JCB and under the Global tab set the Field Builder Type to string manipulation.' + ), 'Notice' + ); } // load the compiler path - $this->compilerPath = $this->params->get('compiler_folder_path', JPATH_COMPONENT_ADMINISTRATOR . '/compiler'); + $this->compilerPath = $this->params->get( + 'compiler_folder_path', + JPATH_COMPONENT_ADMINISTRATOR . '/compiler' + ); // set the component ID $this->componentID = (int) $config['component']; // set this components code name - if ($name_code = ComponentbuilderHelper::getVar('joomla_component', $this->componentID, 'id', 'name_code')) + if ($name_code = ComponentbuilderHelper::getVar( + 'joomla_component', $this->componentID, 'id', 'name_code' + )) { // set lang prefix - $this->langPrefix = 'COM_' . ComponentbuilderHelper::safeString($name_code, 'U'); + $this->langPrefix = 'COM_' . ComponentbuilderHelper::safeString( + $name_code, 'U' + ); // set component code name - $this->componentCodeName = ComponentbuilderHelper::safeString($name_code); + $this->componentCodeName = ComponentbuilderHelper::safeString( + $name_code + ); // set component context - $this->componentContext = $this->componentCodeName . '.' . $this->componentID; + $this->componentContext = $this->componentCodeName . '.' + . $this->componentID; // set if placeholders should be added to customcode - $global = ((int) ComponentbuilderHelper::getVar('joomla_component', $this->componentID, 'id', 'add_placeholders') == 1) ? true : false; - $this->addPlaceholders = ((int) $config['placeholders'] == 0) ? false : (((int) $config['placeholders'] == 1) ? true : $global); + $global = ((int) ComponentbuilderHelper::getVar( + 'joomla_component', $this->componentID, 'id', + 'add_placeholders' + ) == 1) ? true : false; + $this->addPlaceholders = ((int) $config['placeholders'] == 0) + ? false + : (((int) $config['placeholders'] == 1) ? true : $global); // set if line numbers should be added to comments - $global = ((int) ComponentbuilderHelper::getVar('joomla_component', $this->componentID, 'id', 'debug_linenr') == 1) ? true : false; - $this->debugLinenr = ((int) $config['debuglinenr'] == 0) ? false : (((int) $config['debuglinenr'] == 1) ? true : $global); + $global = ((int) ComponentbuilderHelper::getVar( + 'joomla_component', $this->componentID, 'id', + 'debug_linenr' + ) == 1) ? true : false; + $this->debugLinenr = ((int) $config['debuglinenr'] == 0) ? false + : (((int) $config['debuglinenr'] == 1) ? true : $global); // set the current user $this->user = JFactory::getUser(); // Get a db connection. @@ -863,50 +900,71 @@ class Get $this->customCodeFactory($paths, $today); } // Trigger Event: jcb_ce_onBeforeGetComponentData - $this->triggerEvent('jcb_ce_onBeforeGetComponentData', array(&$this->componentContext, $this)); + $this->triggerEvent( + 'jcb_ce_onBeforeGetComponentData', + array(&$this->componentContext, $this) + ); // get the component data $this->componentData = $this->getComponentData(); // Trigger Event: jcb_ce_onAfterGetComponentData - $this->triggerEvent('jcb_ce_onAfterGetComponentData', array(&$this->componentContext, $this)); + $this->triggerEvent( + 'jcb_ce_onAfterGetComponentData', + array(&$this->componentContext, $this) + ); // make sure we have a version - if (strpos($this->componentData->component_version, '.') === FALSE) + if (strpos($this->componentData->component_version, '.') + === false) { $this->componentData->component_version = '1.0.0'; } // update the version - if (!isset($this->componentData->old_component_version) && (ComponentbuilderHelper::checkArray($this->addSQL) || ComponentbuilderHelper::checkArray($this->updateSQL))) + if (!isset($this->componentData->old_component_version) + && (ComponentbuilderHelper::checkArray($this->addSQL) + || ComponentbuilderHelper::checkArray( + $this->updateSQL + ))) { // set the new version - $version = (array) explode('.', $this->componentData->component_version); + $version = (array) explode( + '.', $this->componentData->component_version + ); // get last key end($version); $key = key($version); // just increment the last $version[$key]++; // set the old version - $this->componentData->old_component_version = $this->componentData->component_version; + $this->componentData->old_component_version + = $this->componentData->component_version; // set the new version, and set update switch - $this->componentData->component_version = implode('.', $version); + $this->componentData->component_version = implode( + '.', $version + ); } // set the percentage when a language can be added - $this->percentageLanguageAdd = (int) $this->params->get('percentagelanguageadd', 50); + $this->percentageLanguageAdd = (int) $this->params->get( + 'percentagelanguageadd', 50 + ); // Trigger Event: jcb_ce_onBeforeGet - $this->triggerEvent('jcb_ce_onAfterGet', array(&$this->componentContext, $this)); + $this->triggerEvent( + 'jcb_ce_onAfterGet', array(&$this->componentContext, $this) + ); return true; } } + return false; } /** * Set the tab/space - * - * @param int $nr The number of tag/space - * + * + * @param int $nr The number of tag/space + * * @return string - * + * */ public function _t($nr) { @@ -916,11 +974,11 @@ class Get /** * Set the line number in comments - * - * @param int $nr The line number - * + * + * @param int $nr The line number + * * @return void - * + * */ private function setLine($nr) { @@ -928,17 +986,18 @@ class Get { return ' [Get ' . $nr . ']'; } + return ''; } /** * Trigger events - * - * @param string $event The event to trigger - * @param mix $data The values to pass to the event/plugin - * - * @return string - * + * + * @param string $event The event to trigger + * @param mix $data The values to pass to the event/plugin + * + * @return void + * */ public function triggerEvent($event, $data) { @@ -969,7 +1028,7 @@ class Get * get all System Placeholders * * @return array The global placeholders - * + * */ public function getGlobalPlaceholders() { @@ -977,7 +1036,7 @@ class Get $bucket = array(); // Create a new query object. $query = $this->db->getQuery(true); - $query->select($this->db->quoteName(array('a.target','a.value'))); + $query->select($this->db->quoteName(array('a.target', 'a.value'))); // from these tables $query->from('#__componentbuilder_placeholder AS a'); // Reset the query using our newly populated query object. @@ -994,37 +1053,52 @@ class Get } } // set component place holders - $bucket[$this->hhh . 'component' . $this->hhh] = $this->componentCodeName; - $bucket[$this->hhh . 'Component' . $this->hhh] = ComponentbuilderHelper::safeString($this->componentCodeName, 'F'); - $bucket[$this->hhh . 'COMPONENT' . $this->hhh] = ComponentbuilderHelper::safeString($this->componentCodeName, 'U'); - $bucket[$this->bbb . 'component' . $this->ddd] = $bucket[$this->hhh . 'component' . $this->hhh]; - $bucket[$this->bbb . 'Component' . $this->ddd] = $bucket[$this->hhh . 'Component' . $this->hhh]; - $bucket[$this->bbb . 'COMPONENT' . $this->ddd] = $bucket[$this->hhh . 'COMPONENT' . $this->hhh]; + $bucket[$this->hhh . 'component' . $this->hhh] + = $this->componentCodeName; + $bucket[$this->hhh . 'Component' . $this->hhh] + = ComponentbuilderHelper::safeString( + $this->componentCodeName, 'F' + ); + $bucket[$this->hhh . 'COMPONENT' . $this->hhh] + = ComponentbuilderHelper::safeString( + $this->componentCodeName, 'U' + ); + $bucket[$this->bbb . 'component' . $this->ddd] = $bucket[$this->hhh + . 'component' . $this->hhh]; + $bucket[$this->bbb . 'Component' . $this->ddd] = $bucket[$this->hhh + . 'Component' . $this->hhh]; + $bucket[$this->bbb . 'COMPONENT' . $this->ddd] = $bucket[$this->hhh + . 'COMPONENT' . $this->hhh]; $bucket[$this->hhh . 'LANG_PREFIX' . $this->hhh] = $this->langPrefix; - $bucket[$this->bbb . 'LANG_PREFIX' . $this->ddd] = $bucket[$this->hhh . 'LANG_PREFIX' . $this->hhh]; + $bucket[$this->bbb . 'LANG_PREFIX' . $this->ddd] = $bucket[$this->hhh + . 'LANG_PREFIX' . $this->hhh]; // get the current components overides - if (($_placeholders = ComponentbuilderHelper::getVar('component_placeholders', $this->componentID, 'joomla_component', 'addplaceholders')) !== false - && ComponentbuilderHelper::checkJson($_placeholders)) + if (($_placeholders = ComponentbuilderHelper::getVar( + 'component_placeholders', $this->componentID, + 'joomla_component', 'addplaceholders' + )) !== false + && ComponentbuilderHelper::checkJson($_placeholders)) { $_placeholders = json_decode($_placeholders, true); if (ComponentbuilderHelper::checkArray($_placeholders)) { - foreach($_placeholders as $row) + foreach ($_placeholders as $row) { $bucket[$row['target']] = $row['value']; } } } + return $bucket; } /** * get all Component Data - * - * @param int $id The component ID + * + * @param int $id The component ID * * @return oject The component data - * + * */ public function getComponentData() { @@ -1032,25 +1106,25 @@ class Get $query = $this->db->getQuery(true); // selection $selection = array( - 'b.addadmin_views' => 'addadmin_views', - 'b.id' => 'addadmin_views_id', - 'h.addconfig' => 'addconfig', + 'b.addadmin_views' => 'addadmin_views', + 'b.id' => 'addadmin_views_id', + 'h.addconfig' => 'addconfig', 'd.addcustom_admin_views' => 'addcustom_admin_views', - 'g.addcustommenus' => 'addcustommenus', - 'j.addfiles' => 'addfiles', - 'j.addfolders' => 'addfolders', - 'j.addfilesfullpath' => 'addfilesfullpath', - 'j.addfoldersfullpath' => 'addfoldersfullpath', - 'c.addsite_views' => 'addsite_views', - 'l.addjoomla_plugins' => 'addjoomla_plugins', - 'k.addjoomla_modules' => 'addjoomla_modules', - 'i.dashboard_tab' => 'dashboard_tab', + 'g.addcustommenus' => 'addcustommenus', + 'j.addfiles' => 'addfiles', + 'j.addfolders' => 'addfolders', + 'j.addfilesfullpath' => 'addfilesfullpath', + 'j.addfoldersfullpath' => 'addfoldersfullpath', + 'c.addsite_views' => 'addsite_views', + 'l.addjoomla_plugins' => 'addjoomla_plugins', + 'k.addjoomla_modules' => 'addjoomla_modules', + 'i.dashboard_tab' => 'dashboard_tab', 'i.php_dashboard_methods' => 'php_dashboard_methods', - 'i.id' => 'component_dashboard_id', - 'f.sql_tweak' => 'sql_tweak', - 'e.version_update' => 'version_update', - 'e.id' => 'version_update_id' - ); + 'i.id' => 'component_dashboard_id', + 'f.sql_tweak' => 'sql_tweak', + 'e.version_update' => 'version_update', + 'e.id' => 'version_update_id' + ); $query->select('a.*'); $query->select( $this->db->quoteName( @@ -1074,14 +1148,25 @@ class Get 'k' => 'component_modules' ); // load the joins - foreach($joiners as $as => $join) + foreach ($joiners as $as => $join) { - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_' . $join, $as) . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName($as . '.joomla_component') . ')'); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_' . $join, $as) + . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName($as . '.joomla_component') . ')' + ); } - $query->where($this->db->quoteName('a.id') . ' = ' . (int) $this->componentID); + $query->where( + $this->db->quoteName('a.id') . ' = ' . (int) $this->componentID + ); // Trigger Event: jcb_ce_onBeforeQueryComponentData - $this->triggerEvent('jcb_ce_onBeforeQueryComponentData', array(&$this->componentContext, &$this->componentID, &$query, &$this->db)); + $this->triggerEvent( + 'jcb_ce_onBeforeQueryComponentData', + array(&$this->componentContext, &$this->componentID, &$query, + &$this->db) + ); // Reset the query using our newly populated query object. $this->db->setQuery($query); @@ -1090,43 +1175,68 @@ class Get $component = $this->db->loadObject(); // Trigger Event: jcb_ce_onBeforeModelComponentData - $this->triggerEvent('jcb_ce_onBeforeModelComponentData', array(&$this->componentContext, &$component)); + $this->triggerEvent( + 'jcb_ce_onBeforeModelComponentData', + array(&$this->componentContext, &$component) + ); // set upater $updater = array( 'unique' => array( - 'addadmin_views' => array('table' => 'component_admin_views', 'val' => (int) $component->addadmin_views_id, 'key' => 'id'), - 'addconfig' => array('table' => 'component_config', 'val' => (int) $this->componentID, 'key' => 'joomla_component'), - 'addcustom_admin_views' => array('table' => 'component_custom_admin_views', 'val' => (int) $this->componentID, 'key' => 'joomla_component'), - 'addcustommenus' => array('table' => 'component_custom_admin_menus', 'val' => (int) $this->componentID, 'key' => 'joomla_component'), - 'addfiles' => array('table' => 'component_files_folders', 'val' => (int) $this->componentID, 'key' => 'joomla_component'), - 'addfolders' => array('table' => 'component_files_folders', 'val' => (int) $this->componentID, 'key' => 'joomla_component'), - 'addsite_views' => array('table' => 'component_site_views', 'val' => (int) $this->componentID, 'key' => 'joomla_component'), - 'dashboard_tab' => array('table' => 'component_dashboard', 'val' => (int) $this->componentID, 'key' => 'joomla_component'), - 'sql_tweak' => array('table' => 'component_mysql_tweaks', 'val' => (int) $this->componentID, 'key' => 'joomla_component'), - 'version_update' => array('table' => 'component_updates', 'val' => (int) $this->componentID, 'key' => 'joomla_component') + 'addadmin_views' => array('table' => 'component_admin_views', + 'val' => (int) $component->addadmin_views_id, + 'key' => 'id'), + 'addconfig' => array('table' => 'component_config', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component'), + 'addcustom_admin_views' => array('table' => 'component_custom_admin_views', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component'), + 'addcustommenus' => array('table' => 'component_custom_admin_menus', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component'), + 'addfiles' => array('table' => 'component_files_folders', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component'), + 'addfolders' => array('table' => 'component_files_folders', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component'), + 'addsite_views' => array('table' => 'component_site_views', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component'), + 'dashboard_tab' => array('table' => 'component_dashboard', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component'), + 'sql_tweak' => array('table' => 'component_mysql_tweaks', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component'), + 'version_update' => array('table' => 'component_updates', + 'val' => (int) $this->componentID, + 'key' => 'joomla_component') ), - 'table' => 'joomla_component', - 'key' => 'id', - 'val' => (int) $this->componentID + 'table' => 'joomla_component', + 'key' => 'id', + 'val' => (int) $this->componentID ); // repeatable fields to update $searchRepeatables = array( // repeatablefield => checker - 'addadmin_views' => 'adminview', - 'addconfig' => 'field', - 'addcontributors' => 'name', + 'addadmin_views' => 'adminview', + 'addconfig' => 'field', + 'addcontributors' => 'name', 'addcustom_admin_views' => 'customadminview', - 'addcustommenus' => 'name', - 'addfiles' => 'file', - 'addfolders' => 'folder', - 'addsite_views' => 'siteview', - 'dashboard_tab' => 'name', - 'sql_tweak' => 'adminview', - 'version_update' => 'version' + 'addcustommenus' => 'name', + 'addfiles' => 'file', + 'addfolders' => 'folder', + 'addsite_views' => 'siteview', + 'dashboard_tab' => 'name', + 'sql_tweak' => 'adminview', + 'version_update' => 'version' ); // update the repeatable fields - $component = ComponentbuilderHelper::convertRepeatableFields($component, $searchRepeatables, $updater); + $component = ComponentbuilderHelper::convertRepeatableFields( + $component, $searchRepeatables, $updater + ); // load the global placeholders if (ComponentbuilderHelper::checkArray($this->globalPlaceholders)) @@ -1135,20 +1245,41 @@ class Get } // set component sales name - $component->sales_name = ComponentbuilderHelper::safeString($component->system_name); + $component->sales_name = ComponentbuilderHelper::safeString( + $component->system_name + ); + + // set the component name_code + $component->name_code = ComponentbuilderHelper::safeString( + $component->name_code + ); // ensure version naming is correct - $this->component_version = preg_replace('/[^0-9.]+/', '', $component->component_version); + $this->component_version = preg_replace( + '/[^0-9.]+/', '', $component->component_version + ); // set the add targets - $addArrayF = array('files' => 'files', 'folders' => 'folders', 'filesfullpath' => 'files', 'foldersfullpath' => 'folders'); + $addArrayF = array('files' => 'files', 'folders' => 'folders', + 'filesfullpath' => 'files', + 'foldersfullpath' => 'folders'); foreach ($addArrayF as $addTarget => $targetHere) { // set the add target data - $component->{'add' . $addTarget} = (isset($component->{'add' . $addTarget}) && ComponentbuilderHelper::checkJson($component->{'add' . $addTarget})) ? json_decode($component->{'add' . $addTarget}, true) : null; - if (ComponentbuilderHelper::checkArray($component->{'add' . $addTarget})) + $component->{'add' . $addTarget} = (isset( + $component->{'add' . $addTarget} + ) + && ComponentbuilderHelper::checkJson( + $component->{'add' . $addTarget} + )) ? json_decode($component->{'add' . $addTarget}, true) : null; + if (ComponentbuilderHelper::checkArray( + $component->{'add' . $addTarget} + )) { - if (isset($component->{$targetHere}) && ComponentbuilderHelper::checkArray($component->{$targetHere})) + if (isset($component->{$targetHere}) + && ComponentbuilderHelper::checkArray( + $component->{$targetHere} + )) { foreach ($component->{'add' . $addTarget} as $taget) { @@ -1157,7 +1288,9 @@ class Get } else { - $component->{$targetHere} = array_values($component->{'add' . $addTarget}); + $component->{$targetHere} = array_values( + $component->{'add' . $addTarget} + ); } } unset($component->{'add' . $addTarget}); @@ -1167,32 +1300,39 @@ class Get $this->uikit = $component->adduikit; // set whmcs links if needed - if (1 == $component->add_license && (!isset($component->whmcs_buy_link) || !ComponentbuilderHelper::checkString($component->whmcs_buy_link))) + if (1 == $component->add_license + && (!isset($component->whmcs_buy_link) + || !ComponentbuilderHelper::checkString( + $component->whmcs_buy_link + ))) { // update with the whmcs url - if (isset($component->whmcs_url) && ComponentbuilderHelper::checkString($component->whmcs_url)) + if (isset($component->whmcs_url) + && ComponentbuilderHelper::checkString($component->whmcs_url)) { $component->whmcs_buy_link = $component->whmcs_url; } // use the company website - elseif (isset($component->website) && ComponentbuilderHelper::checkString($component->website)) + elseif (isset($component->website) + && ComponentbuilderHelper::checkString($component->website)) { $component->whmcs_buy_link = $component->website; - $component->whmcs_url = rtrim($component->website, '/').'/whmcs'; + $component->whmcs_url = rtrim($component->website, '/') + . '/whmcs'; } // none set else { $component->whmcs_buy_link = '#'; - $component->whmcs_url = '#'; + $component->whmcs_url = '#'; } } // since the license details are not set clear elseif (0 == $component->add_license) { - $component->whmcs_key = ''; + $component->whmcs_key = ''; $component->whmcs_buy_link = ''; - $component->whmcs_url = ''; + $component->whmcs_url = ''; } // set the footable switch @@ -1200,11 +1340,14 @@ class Get { $this->footable = true; // add the version - $this->footableVersion = (1 == $component->addfootable || 2 == $component->addfootable) ? 2 : $component->addfootable; + $this->footableVersion = (1 == $component->addfootable + || 2 == $component->addfootable) ? 2 : $component->addfootable; } // set the addcustommenus data - $component->addcustommenus = (isset($component->addcustommenus) && ComponentbuilderHelper::checkJson($component->addcustommenus)) ? json_decode($component->addcustommenus, true) : null; + $component->addcustommenus = (isset($component->addcustommenus) + && ComponentbuilderHelper::checkJson($component->addcustommenus)) + ? json_decode($component->addcustommenus, true) : null; if (ComponentbuilderHelper::checkArray($component->addcustommenus)) { $component->custommenus = array_values($component->addcustommenus); @@ -1212,31 +1355,46 @@ class Get unset($component->addcustommenus); // set the sql_tweak data - $component->sql_tweak = (isset($component->sql_tweak) && ComponentbuilderHelper::checkJson($component->sql_tweak)) ? json_decode($component->sql_tweak, true) : null; + $component->sql_tweak = (isset($component->sql_tweak) + && ComponentbuilderHelper::checkJson($component->sql_tweak)) + ? json_decode($component->sql_tweak, true) : null; if (ComponentbuilderHelper::checkArray($component->sql_tweak)) { // build the tweak settings - $this->setSqlTweaking(array_map(function($array) - { - return array_map(function($value) - { - if (!ComponentbuilderHelper::checkArray($value) && !ComponentbuilderHelper::checkObject($value) && strval($value) === strval(intval($value))) - { - return (int) $value; - } - return $value; - }, $array); - }, array_values($component->sql_tweak))); + $this->setSqlTweaking( + array_map( + function ($array) { + return array_map( + function ($value) { + if (!ComponentbuilderHelper::checkArray($value) + && !ComponentbuilderHelper::checkObject( + $value + ) + && strval($value) === strval( + intval($value) + )) + { + return (int) $value; + } + + return $value; + }, $array + ); + }, array_values($component->sql_tweak) + ) + ); } unset($component->sql_tweak); // set the admin_view data - $component->addadmin_views = (isset($component->addadmin_views) && ComponentbuilderHelper::checkJson($component->addadmin_views)) ? json_decode($component->addadmin_views, true) : null; + $component->addadmin_views = (isset($component->addadmin_views) + && ComponentbuilderHelper::checkJson($component->addadmin_views)) + ? json_decode($component->addadmin_views, true) : null; if (ComponentbuilderHelper::checkArray($component->addadmin_views)) { // sort the views acording to order - usort($component->addadmin_views, function($a, $b) - { + usort( + $component->addadmin_views, function ($a, $b) { if ($a['order'] != 0 && $b['order'] != 0) { return $a['order'] - $b['order']; @@ -1249,110 +1407,156 @@ class Get { return 0; } - return 1; - }); - // build the admin_views settings - $component->admin_views = array_map(function($array) - { - $array = array_map(function($value) - { - if (!ComponentbuilderHelper::checkArray($value) && !ComponentbuilderHelper::checkObject($value) && strval($value) === strval(intval($value))) - { - return (int) $value; - } - return $value; - }, $array); - // check if we must add to site - if (isset($array['edit_create_site_view']) && is_numeric($array['edit_create_site_view']) && $array['edit_create_site_view'] > 0) - { - $this->siteEditView[$array['adminview']] = true; - $this->lang = 'both'; - } - if (isset($array['port']) && $array['port'] && !$this->addEximport) - { - $this->addEximport = true; - } - if (isset($array['history']) && $array['history'] && !$this->setTagHistory) - { - $this->setTagHistory = true; - } - if (isset($array['joomla_fields']) && $array['joomla_fields'] && !$this->setJoomlaFields) - { - $this->setJoomlaFields = true; - } - // has become a lacacy issue, can't remove this - $array['view'] = $array['adminview']; - // get the admin settings/data - $array['settings'] = $this->getAdminViewData($array['view']); - return $array; - }, array_values($component->addadmin_views)); + return 1; + } + ); + // build the admin_views settings + $component->admin_views = array_map( + function ($array) { + $array = array_map( + function ($value) { + if (!ComponentbuilderHelper::checkArray($value) + && !ComponentbuilderHelper::checkObject($value) + && strval($value) === strval(intval($value))) + { + return (int) $value; + } + + return $value; + }, $array + ); + // check if we must add to site + if (isset($array['edit_create_site_view']) + && is_numeric( + $array['edit_create_site_view'] + ) + && $array['edit_create_site_view'] > 0) + { + $this->siteEditView[$array['adminview']] = true; + $this->lang = 'both'; + } + if (isset($array['port']) && $array['port'] + && !$this->addEximport) + { + $this->addEximport = true; + } + if (isset($array['history']) && $array['history'] + && !$this->setTagHistory) + { + $this->setTagHistory = true; + } + if (isset($array['joomla_fields']) + && $array['joomla_fields'] + && !$this->setJoomlaFields) + { + $this->setJoomlaFields = true; + } + // has become a legacy issue, can't remove this + $array['view'] = $array['adminview']; + // get the admin settings/data + $array['settings'] = $this->getAdminViewData( + $array['view'] + ); + + return $array; + }, array_values($component->addadmin_views) + ); } // set the site_view data - $component->addsite_views = (isset($component->addsite_views) && ComponentbuilderHelper::checkJson($component->addsite_views)) ? json_decode($component->addsite_views, true) : null; + $component->addsite_views = (isset($component->addsite_views) + && ComponentbuilderHelper::checkJson($component->addsite_views)) + ? json_decode($component->addsite_views, true) : null; if (ComponentbuilderHelper::checkArray($component->addsite_views)) { - $this->lang = 'site'; + $this->lang = 'site'; $this->target = 'site'; // build the site_views settings - $component->site_views = array_map(function($array) - { - // has become a lacacy issue, can't remove this - $array['view'] = $array['siteview']; - $array['settings'] = $this->getCustomViewData($array['view']); - return array_map(function($value) - { - if (!ComponentbuilderHelper::checkArray($value) && !ComponentbuilderHelper::checkObject($value) && strval($value) === strval(intval($value))) - { - return (int) $value; - } - return $value; - }, $array); - }, array_values($component->addsite_views)); + $component->site_views = array_map( + function ($array) { + // has become a lacacy issue, can't remove this + $array['view'] = $array['siteview']; + $array['settings'] = $this->getCustomViewData( + $array['view'] + ); + + return array_map( + function ($value) { + if (!ComponentbuilderHelper::checkArray($value) + && !ComponentbuilderHelper::checkObject($value) + && strval($value) === strval(intval($value))) + { + return (int) $value; + } + + return $value; + }, $array + ); + }, array_values($component->addsite_views) + ); // unset original value unset($component->addsite_views); } // set the custom_admin_views data - $component->addcustom_admin_views = (isset($component->addcustom_admin_views) && ComponentbuilderHelper::checkJson($component->addcustom_admin_views)) ? json_decode($component->addcustom_admin_views, true) : null; - if (ComponentbuilderHelper::checkArray($component->addcustom_admin_views)) + $component->addcustom_admin_views + = (isset($component->addcustom_admin_views) + && ComponentbuilderHelper::checkJson( + $component->addcustom_admin_views + )) ? json_decode($component->addcustom_admin_views, true) : null; + if (ComponentbuilderHelper::checkArray( + $component->addcustom_admin_views + )) { - $this->lang = 'admin'; + $this->lang = 'admin'; $this->target = 'custom_admin'; // build the custom_admin_views settings - $component->custom_admin_views = array_map(function($array) - { - // has become a lacacy issue, can't remove this - $array['view'] = $array['customadminview']; - $array['settings'] = $this->getCustomViewData($array['view'], 'custom_admin_view'); - return array_map(function($value) - { - if (!ComponentbuilderHelper::checkArray($value) && !ComponentbuilderHelper::checkObject($value) && strval($value) === strval(intval($value))) - { - return (int) $value; - } - return $value; - }, $array); - }, array_values($component->addcustom_admin_views)); + $component->custom_admin_views = array_map( + function ($array) { + // has become a lacacy issue, can't remove this + $array['view'] = $array['customadminview']; + $array['settings'] = $this->getCustomViewData( + $array['view'], 'custom_admin_view' + ); + + return array_map( + function ($value) { + if (!ComponentbuilderHelper::checkArray($value) + && !ComponentbuilderHelper::checkObject($value) + && strval($value) === strval(intval($value))) + { + return (int) $value; + } + + return $value; + }, $array + ); + }, array_values($component->addcustom_admin_views) + ); // unset original value unset($component->addcustom_admin_views); } // set the config data - $component->addconfig = (isset($component->addconfig) && ComponentbuilderHelper::checkJson($component->addconfig)) ? json_decode($component->addconfig, true) : null; + $component->addconfig = (isset($component->addconfig) + && ComponentbuilderHelper::checkJson($component->addconfig)) + ? json_decode($component->addconfig, true) : null; if (ComponentbuilderHelper::checkArray($component->addconfig)) { - $component->config = array_map(function($field) { - // make sure the alias and title is 0 - $field['alias'] = 0; - $field['title'] = 0; - // set the field details - $this->setFieldDetails($field); - // set unique name counter - $this->setUniqueNameCounter($field['base_name'], 'configs'); - // return field - return $field; - }, array_values($component->addconfig)); + $component->config = array_map( + function ($field) { + // make sure the alias and title is 0 + $field['alias'] = 0; + $field['title'] = 0; + // set the field details + $this->setFieldDetails($field); + // set unique name counter + $this->setUniqueNameCounter($field['base_name'], 'configs'); + + // return field + return $field; + }, array_values($component->addconfig) + ); // do some house cleaning (for fields) foreach ($component->config as $field) @@ -1365,41 +1569,62 @@ class Get } // set the addcustommenus data - $component->addcontributors = (isset($component->addcontributors) && ComponentbuilderHelper::checkJson($component->addcontributors)) ? json_decode($component->addcontributors, true) : null; + $component->addcontributors = (isset($component->addcontributors) + && ComponentbuilderHelper::checkJson($component->addcontributors)) + ? json_decode($component->addcontributors, true) : null; if (ComponentbuilderHelper::checkArray($component->addcontributors)) { - $this->addContributors = true; - $component->contributors = array_values($component->addcontributors); + $this->addContributors = true; + $component->contributors = array_values( + $component->addcontributors + ); } unset($component->addcontributors); // set the addcustommenus data - $component->version_update = (isset($component->version_update) && ComponentbuilderHelper::checkJson($component->version_update)) ? json_decode($component->version_update, true) : null; + $component->version_update = (isset($component->version_update) + && ComponentbuilderHelper::checkJson($component->version_update)) + ? json_decode($component->version_update, true) : null; if (ComponentbuilderHelper::checkArray($component->version_update)) { - $component->version_update = array_values($component->version_update); + $component->version_update = array_values( + $component->version_update + ); } // build update SQL - $old_admin_views = $this->getHistoryWatch('component_admin_views', $component->addadmin_views_id); - $old_component = $this->getHistoryWatch('joomla_component', $this->componentID); + $old_admin_views = $this->getHistoryWatch( + 'component_admin_views', $component->addadmin_views_id + ); + $old_component = $this->getHistoryWatch( + 'joomla_component', $this->componentID + ); if ($old_component || $old_admin_views) { if (ComponentbuilderHelper::checkObject($old_admin_views)) { // add new views if found - if (isset($old_admin_views->addadmin_views) && ComponentbuilderHelper::checkJson($old_admin_views->addadmin_views)) + if (isset($old_admin_views->addadmin_views) + && ComponentbuilderHelper::checkJson( + $old_admin_views->addadmin_views + )) { - $this->setUpdateSQL(json_decode($old_admin_views->addadmin_views, true), $component->addadmin_views, 'adminview'); + $this->setUpdateSQL( + json_decode($old_admin_views->addadmin_views, true), + $component->addadmin_views, 'adminview' + ); } // check if a new version was manualy set if (ComponentbuilderHelper::checkObject($old_component)) { - $old_component_version = preg_replace('/[^0-9.]+/', '', $old_component->component_version); + $old_component_version = preg_replace( + '/[^0-9.]+/', '', $old_component->component_version + ); if ($old_component_version != $this->component_version) { // yes, this is a new version, this mean there may be manual sql and must be checked and updated - $component->old_component_version = $old_component_version; + $component->old_component_version + = $old_component_version; } // clear this data unset($old_component); @@ -1412,7 +1637,9 @@ class Get unset($component->addadmin_views); // set GUI mapper - $guiMapper = array( 'table' => 'joomla_component', 'id' => (int) $this->componentID, 'field' => 'javascript', 'type' => 'js'); + $guiMapper = array('table' => 'joomla_component', + 'id' => (int) $this->componentID, + 'field' => 'javascript', 'type' => 'js'); // add_javascript if ($component->add_javascript == 1) @@ -1436,7 +1663,12 @@ class Get foreach ($addGlobalCss as $area) { // add_css if found - if (isset($component->{'add_css_' . $area}) && $component->{'add_css_' . $area} == 1 && isset($component->{'css_' . $area}) && ComponentbuilderHelper::checkString($component->{'css_' . $area})) + if (isset($component->{'add_css_' . $area}) + && $component->{'add_css_' . $area} == 1 + && isset($component->{'css_' . $area}) + && ComponentbuilderHelper::checkString( + $component->{'css_' . $area} + )) { $this->setCustomScriptBuilder( $component->{'css_' . $area}, @@ -1452,15 +1684,23 @@ class Get // set the lang target $this->lang = 'admin'; // add PHP in ADMIN - $addScriptMethods = array('php_preflight', 'php_postflight', 'php_method'); - $addScriptTypes = array('install', 'update', 'uninstall'); + $addScriptMethods = array('php_preflight', 'php_postflight', + 'php_method'); + $addScriptTypes = array('install', 'update', 'uninstall'); // update GUI mapper $guiMapper['type'] = 'php'; foreach ($addScriptMethods as $scriptMethod) { foreach ($addScriptTypes as $scriptType) { - if (isset($component->{'add_' . $scriptMethod . '_' . $scriptType}) && $component->{'add_' . $scriptMethod . '_' . $scriptType} == 1 && ComponentbuilderHelper::checkString($component->{$scriptMethod . '_' . $scriptType})) + if (isset( + $component->{'add_' . $scriptMethod . '_' . $scriptType} + ) + && $component->{'add_' . $scriptMethod . '_' . $scriptType} + == 1 + && ComponentbuilderHelper::checkString( + $component->{$scriptMethod . '_' . $scriptType} + )) { // set GUI mapper field $guiMapper['field'] = $scriptMethod . '_' . $scriptType; @@ -1480,11 +1720,14 @@ class Get } } // add_php_helper - if ($component->add_php_helper_admin == 1 && ComponentbuilderHelper::checkString($component->php_helper_admin)) + if ($component->add_php_helper_admin == 1 + && ComponentbuilderHelper::checkString( + $component->php_helper_admin + )) { $this->lang = 'admin'; // update GUI mapper - $guiMapper['field'] = 'php_helper_admin'; + $guiMapper['field'] = 'php_helper_admin'; $guiMapper['prefix'] = PHP_EOL . PHP_EOL; $this->setCustomScriptBuilder( $component->php_helper_admin, @@ -1501,7 +1744,8 @@ class Get } unset($component->php_helper); // add_admin_event - if ($component->add_admin_event == 1 && ComponentbuilderHelper::checkString($component->php_admin_event)) + if ($component->add_admin_event == 1 + && ComponentbuilderHelper::checkString($component->php_admin_event)) { $this->lang = 'admin'; // update GUI mapper field @@ -1520,11 +1764,12 @@ class Get } unset($component->php_admin_event); // add_php_helper_both - if ($component->add_php_helper_both == 1 && ComponentbuilderHelper::checkString($component->php_helper_both)) + if ($component->add_php_helper_both == 1 + && ComponentbuilderHelper::checkString($component->php_helper_both)) { $this->lang = 'both'; // update GUI mapper field - $guiMapper['field'] = 'php_helper_both'; + $guiMapper['field'] = 'php_helper_both'; $guiMapper['prefix'] = PHP_EOL . PHP_EOL; $this->setCustomScriptBuilder( $component->php_helper_both, @@ -1540,11 +1785,12 @@ class Get $this->customScriptBuilder['component_php_helper_both'] = ''; } // add_php_helper_site - if ($component->add_php_helper_site == 1 && ComponentbuilderHelper::checkString($component->php_helper_site)) + if ($component->add_php_helper_site == 1 + && ComponentbuilderHelper::checkString($component->php_helper_site)) { $this->lang = 'site'; // update GUI mapper field - $guiMapper['field'] = 'php_helper_site'; + $guiMapper['field'] = 'php_helper_site'; $guiMapper['prefix'] = PHP_EOL . PHP_EOL; $this->setCustomScriptBuilder( $component->php_helper_site, @@ -1561,7 +1807,8 @@ class Get } unset($component->php_helper); // add_site_event - if ($component->add_site_event == 1 && ComponentbuilderHelper::checkString($component->php_site_event)) + if ($component->add_site_event == 1 + && ComponentbuilderHelper::checkString($component->php_site_event)) { $this->lang = 'site'; // update GUI mapper field @@ -1611,7 +1858,9 @@ class Get // README if ($component->addreadme) { - $component->readme = $this->setDynamicValues(base64_decode($component->readme)); + $component->readme = $this->setDynamicValues( + base64_decode($component->readme) + ); } else { @@ -1619,34 +1868,43 @@ class Get } // set lang now - $nowLang = $this->lang; + $nowLang = $this->lang; $this->lang = 'admin'; // dashboard methods - $component->dashboard_tab = (isset($component->dashboard_tab) && ComponentbuilderHelper::checkJson($component->dashboard_tab)) ? json_decode($component->dashboard_tab, true) : null; + $component->dashboard_tab = (isset($component->dashboard_tab) + && ComponentbuilderHelper::checkJson($component->dashboard_tab)) + ? json_decode($component->dashboard_tab, true) : null; if (ComponentbuilderHelper::checkArray($component->dashboard_tab)) { - $component->dashboard_tab = array_map(function($array) - { - $array['html'] = $this->setDynamicValues($array['html']); - return $array; - }, array_values($component->dashboard_tab)); + $component->dashboard_tab = array_map( + function ($array) { + $array['html'] = $this->setDynamicValues($array['html']); + + return $array; + }, array_values($component->dashboard_tab) + ); } else { $component->dashboard_tab = ''; } // add the php of the dashboard if set - if (isset($component->php_dashboard_methods) && ComponentbuilderHelper::checkString($component->php_dashboard_methods)) + if (isset($component->php_dashboard_methods) + && ComponentbuilderHelper::checkString( + $component->php_dashboard_methods + )) { // load the php for the dashboard model $component->php_dashboard_methods = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($component->php_dashboard_methods)), + $this->setDynamicValues( + base64_decode($component->php_dashboard_methods) + ), array( 'table' => 'component_dashboard', 'field' => 'php_dashboard_methods', - 'id' => (int) $component->component_dashboard_id, - 'type' => 'php') - ); + 'id' => (int) $component->component_dashboard_id, + 'type' => 'php') + ); } else { @@ -1659,10 +1917,17 @@ class Get $serverArray = array('update_server', 'sales_server'); foreach ($serverArray as $server) { - if ($component->{'add_' . $server} == 1 && is_numeric($component->{$server}) && $component->{$server} > 0) + if ($component->{'add_' . $server} == 1 + && is_numeric( + $component->{$server} + ) + && $component->{$server} > 0) { // get the server protocol - $component->{$server . '_protocol'} = ComponentbuilderHelper::getVar('server', (int) $component->{$server}, 'id', 'protocol'); + $component->{$server . '_protocol'} + = ComponentbuilderHelper::getVar( + 'server', (int) $component->{$server}, 'id', 'protocol' + ); } else { @@ -1676,11 +1941,16 @@ class Get } } // set the ignore folders for repo if found - if (isset($component->toignore) && ComponentbuilderHelper::checkString($component->toignore)) + if (isset($component->toignore) + && ComponentbuilderHelper::checkString( + $component->toignore + )) { if (strpos($component->toignore, ',') !== false) { - $component->toignore = array_map('trim', (array) explode(',', $component->toignore)); + $component->toignore = array_map( + 'trim', (array) explode(',', $component->toignore) + ); } else { @@ -1693,36 +1963,53 @@ class Get $component->toignore = array('.git'); } // get all modules - $component->addjoomla_modules = (isset($component->addjoomla_modules) && ComponentbuilderHelper::checkJson($component->addjoomla_modules)) ? json_decode($component->addjoomla_modules, true) : null; + $component->addjoomla_modules = (isset($component->addjoomla_modules) + && ComponentbuilderHelper::checkJson($component->addjoomla_modules)) + ? json_decode($component->addjoomla_modules, true) : null; if (ComponentbuilderHelper::checkArray($component->addjoomla_modules)) { - $joomla_modules = array_map(function($array) use(&$component) { - // only load the modules whose target association calls for it - if (!isset($array['target']) || $array['target'] != 2) - { - return $this->setJoomlaModule($array['module'], $component); - } - return null; - }, array_values($component->addjoomla_modules)); + $joomla_modules = array_map( + function ($array) use (&$component) { + // only load the modules whose target association calls for it + if (!isset($array['target']) || $array['target'] != 2) + { + return $this->setJoomlaModule( + $array['module'], $component + ); + } + + return null; + }, array_values($component->addjoomla_modules) + ); } unset($component->addjoomla_modules); // get all plugins - $component->addjoomla_plugins = (isset($component->addjoomla_plugins) && ComponentbuilderHelper::checkJson($component->addjoomla_plugins)) ? json_decode($component->addjoomla_plugins, true) : null; + $component->addjoomla_plugins = (isset($component->addjoomla_plugins) + && ComponentbuilderHelper::checkJson($component->addjoomla_plugins)) + ? json_decode($component->addjoomla_plugins, true) : null; if (ComponentbuilderHelper::checkArray($component->addjoomla_plugins)) { - $joomla_plugins = array_map(function($array) use(&$component) { - // only load the plugins whose target association calls for it - if (!isset($array['target']) || $array['target'] != 2) - { - return $this->setJoomlaPlugin($array['plugin'], $component); - } - return null; - }, array_values($component->addjoomla_plugins)); + $joomla_plugins = array_map( + function ($array) use (&$component) { + // only load the plugins whose target association calls for it + if (!isset($array['target']) || $array['target'] != 2) + { + return $this->setJoomlaPlugin( + $array['plugin'], $component + ); + } + + return null; + }, array_values($component->addjoomla_plugins) + ); } unset($component->addjoomla_plugins); // Trigger Event: jcb_ce_onAfterModelComponentData - $this->triggerEvent('jcb_ce_onAfterModelComponentData', array(&$this->componentContext, &$component)); + $this->triggerEvent( + 'jcb_ce_onAfterModelComponentData', + array(&$this->componentContext, &$component) + ); // return the found component data return $component; @@ -1730,20 +2017,25 @@ class Get /** * set the language content values to language content array - * - * @param string $target The target area for the language string - * @param string $language The language key string - * @param string $string The language string - * @param boolean $addPrefix The switch to add langPrefix + * + * @param string $target The target area for the language string + * @param string $language The language key string + * @param string $string The language string + * @param boolean $addPrefix The switch to add langPrefix * * @return void - * + * */ - public function setLangContent($target, $language, $string, $addPrefix = false) - { - if ($addPrefix && !isset($this->langContent[$target][$this->langPrefix . '_' . $language])) + public function setLangContent($target, $language, $string, + $addPrefix = false + ) { + if ($addPrefix + && !isset( + $this->langContent[$target][$this->langPrefix . '_' . $language] + )) { - $this->langContent[$target][$this->langPrefix . '_' . $language] = trim($string); + $this->langContent[$target][$this->langPrefix . '_' . $language] + = trim($string); } elseif (!isset($this->langContent[$target][$language])) { @@ -1753,11 +2045,11 @@ class Get /** * Get all Admin View Data - * - * @param int $id The view ID + * + * @param int $id The view ID * * @return oject The view data - * + * */ public function getAdminViewData($id) { @@ -1770,31 +2062,54 @@ class Get $query->select( $this->db->quoteName( array( - 'b.addfields', - 'b.id', - 'c.addconditions', - 'c.id', - 'r.addrelations', - 't.tabs' + 'b.addfields', + 'b.id', + 'c.addconditions', + 'c.id', + 'r.addrelations', + 't.tabs' ), array( - 'addfields', - 'addfields_id', - 'addconditions', - 'addconditions_id', - 'addrelations', - 'customtabs' + 'addfields', + 'addfields_id', + 'addconditions', + 'addconditions_id', + 'addrelations', + 'customtabs' ) ) ); $query->from('#__componentbuilder_admin_view AS a'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields', 'b') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('b.admin_view') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields_conditions', 'c') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('c.admin_view') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_fields_relations', 'r') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('r.admin_view') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_admin_custom_tabs', 't') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('t.admin_view') . ')'); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_admin_fields', 'b') + . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('b.admin_view') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_admin_fields_conditions', 'c' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('c.admin_view') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_admin_fields_relations', 'r' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('r.admin_view') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_admin_custom_tabs', 't' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('t.admin_view') . ')' + ); $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); // Trigger Event: jcb_ce_onBeforeQueryViewData - $this->triggerEvent('jcb_ce_onBeforeQueryViewData', array(&$this->componentContext, &$id, &$query, &$this->db)); + $this->triggerEvent( + 'jcb_ce_onBeforeQueryViewData', + array(&$this->componentContext, &$id, &$query, &$this->db) + ); // Reset the query using our newly populated query object. $this->db->setQuery($query); @@ -1803,33 +2118,41 @@ class Get $view = $this->db->loadObject(); // setup view name to use in storing the data - $name_single = ComponentbuilderHelper::safeString($view->name_single); - $name_list = ComponentbuilderHelper::safeString($view->name_list); + $name_single = ComponentbuilderHelper::safeString( + $view->name_single + ); + $name_list = ComponentbuilderHelper::safeString($view->name_list); // set upater $updater = array( 'unique' => array( - 'addfields' => array('table' => 'admin_fields', 'val' => (int) $view->addfields_id, 'key' => 'id'), - 'addconditions' => array('table' => 'admin_fields_conditions', 'val' => (int) $view->addconditions_id, 'key' => 'id') + 'addfields' => array('table' => 'admin_fields', + 'val' => (int) $view->addfields_id, + 'key' => 'id'), + 'addconditions' => array('table' => 'admin_fields_conditions', + 'val' => (int) $view->addconditions_id, + 'key' => 'id') ), - 'table' => 'admin_view', - 'key' => 'id', - 'val' => (int) $id + 'table' => 'admin_view', + 'key' => 'id', + 'val' => (int) $id ); // repeatable fields to update $searchRepeatables = array( // repeatablefield => checker - 'addfields' => 'field', - 'addconditions' => 'target_field', - 'ajax_input' => 'value_name', - 'custom_button' => 'name', + 'addfields' => 'field', + 'addconditions' => 'target_field', + 'ajax_input' => 'value_name', + 'custom_button' => 'name', 'addlinked_views' => 'adminview', - 'addtables' => 'table', - 'addtabs' => 'name', - 'addpermissions' => 'action' + 'addtables' => 'table', + 'addtabs' => 'name', + 'addpermissions' => 'action' ); // update the repeatable fields - $view = ComponentbuilderHelper::convertRepeatableFields($view, $searchRepeatables, $updater); + $view = ComponentbuilderHelper::convertRepeatableFields( + $view, $searchRepeatables, $updater + ); // setup token check if (!isset($this->customScriptBuilder['token'])) @@ -1837,26 +2160,55 @@ class Get $this->customScriptBuilder['token'] = array(); } $this->customScriptBuilder['token'][$name_single] = false; - $this->customScriptBuilder['token'][$name_list] = false; + $this->customScriptBuilder['token'][$name_list] = false; // set some placeholders - $this->placeholders[$this->hhh . 'view' . $this->hhh] = ComponentbuilderHelper::safeString($name_single); - $this->placeholders[$this->hhh . 'views' . $this->hhh] = ComponentbuilderHelper::safeString($name_list); - $this->placeholders[$this->hhh . 'View' . $this->hhh] = ComponentbuilderHelper::safeString($name_single, 'F'); - $this->placeholders[$this->hhh . 'Views' . $this->hhh] = ComponentbuilderHelper::safeString($name_list, 'F'); - $this->placeholders[$this->hhh . 'VIEW' . $this->hhh] = ComponentbuilderHelper::safeString($name_single, 'U'); - $this->placeholders[$this->hhh . 'VIEWS' . $this->hhh] = ComponentbuilderHelper::safeString($name_list, 'U'); - $this->placeholders[$this->bbb . 'view' . $this->ddd] = $this->placeholders[$this->hhh . 'view' . $this->hhh]; - $this->placeholders[$this->bbb . 'views' . $this->ddd] = $this->placeholders[$this->hhh . 'views' . $this->hhh]; - $this->placeholders[$this->bbb . 'View' . $this->ddd] = $this->placeholders[$this->hhh . 'View' . $this->hhh]; - $this->placeholders[$this->bbb . 'Views' . $this->ddd] = $this->placeholders[$this->hhh . 'Views' . $this->hhh]; - $this->placeholders[$this->bbb . 'VIEW' . $this->ddd] = $this->placeholders[$this->hhh . 'VIEW' . $this->hhh]; - $this->placeholders[$this->bbb . 'VIEWS' . $this->ddd] = $this->placeholders[$this->hhh . 'VIEWS' . $this->hhh]; + $this->placeholders[$this->hhh . 'view' . $this->hhh] + = ComponentbuilderHelper::safeString( + $name_single + ); + $this->placeholders[$this->hhh . 'views' . $this->hhh] + = ComponentbuilderHelper::safeString( + $name_list + ); + $this->placeholders[$this->hhh . 'View' . $this->hhh] + = ComponentbuilderHelper::safeString( + $name_single, 'F' + ); + $this->placeholders[$this->hhh . 'Views' . $this->hhh] + = ComponentbuilderHelper::safeString( + $name_list, 'F' + ); + $this->placeholders[$this->hhh . 'VIEW' . $this->hhh] + = ComponentbuilderHelper::safeString( + $name_single, 'U' + ); + $this->placeholders[$this->hhh . 'VIEWS' . $this->hhh] + = ComponentbuilderHelper::safeString( + $name_list, 'U' + ); + $this->placeholders[$this->bbb . 'view' . $this->ddd] + = $this->placeholders[$this->hhh . 'view' . $this->hhh]; + $this->placeholders[$this->bbb . 'views' . $this->ddd] + = $this->placeholders[$this->hhh . 'views' . $this->hhh]; + $this->placeholders[$this->bbb . 'View' . $this->ddd] + = $this->placeholders[$this->hhh . 'View' . $this->hhh]; + $this->placeholders[$this->bbb . 'Views' . $this->ddd] + = $this->placeholders[$this->hhh . 'Views' . $this->hhh]; + $this->placeholders[$this->bbb . 'VIEW' . $this->ddd] + = $this->placeholders[$this->hhh . 'VIEW' . $this->hhh]; + $this->placeholders[$this->bbb . 'VIEWS' . $this->ddd] + = $this->placeholders[$this->hhh . 'VIEWS' . $this->hhh]; // Trigger Event: jcb_ce_onBeforeModelViewData - $this->triggerEvent('jcb_ce_onBeforeModelViewData', array(&$this->componentContext, &$view, &$this->placeholders)); + $this->triggerEvent( + 'jcb_ce_onBeforeModelViewData', + array(&$this->componentContext, &$view, &$this->placeholders) + ); // add the tables - $view->addtables = (isset($view->addtables) && ComponentbuilderHelper::checkJson($view->addtables)) ? json_decode($view->addtables, true) : null; + $view->addtables = (isset($view->addtables) + && ComponentbuilderHelper::checkJson($view->addtables)) + ? json_decode($view->addtables, true) : null; if (ComponentbuilderHelper::checkArray($view->addtables)) { $view->tables = array_values($view->addtables); @@ -1865,71 +2217,131 @@ class Get // set custom tabs $this->customTabs[$name_single] = null; - $view->customtabs = (isset($view->customtabs) && ComponentbuilderHelper::checkJson($view->customtabs)) ? json_decode($view->customtabs, true) : null; + $view->customtabs = (isset($view->customtabs) + && ComponentbuilderHelper::checkJson($view->customtabs)) + ? json_decode($view->customtabs, true) : null; if (ComponentbuilderHelper::checkArray($view->customtabs)) { // setup custom tabs to global data sets - $this->customTabs[$name_single] = array_map( function ($tab) use($name_single) { - // set the view name - $tab['view'] = $name_single; - // load the dynamic data - $tab['html'] = $this->setPlaceholders($this->setDynamicValues($tab['html']), $this->placeholders); - // set the tab name - $tab['name'] = (isset($tab['name']) && ComponentbuilderHelper::checkString($tab['name'])) ? $tab['name'] : 'Tab'; - // set lang - $tab['lang'] = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($tab['view'], 'U') . '_' . ComponentbuilderHelper::safeString($tab['name'], 'U'); - $this->setLangContent('both', $tab['lang'], $tab['name']); - // set code name - $tab['code'] = ComponentbuilderHelper::safeString($tab['name']); - // check if the permissions for the tab should be added - $_tab = ''; - if (isset($tab['permission']) && $tab['permission'] == 1) - { - $_tab = $this->_t(1); - } - // check if the php of the tab is set, if not load it now - if (strpos($tab['html'], 'bootstrap.addTab') === false && strpos($tab['html'], 'bootstrap.endTab') === false) - { - // add the tab - $tmp = PHP_EOL . $_tab . $this->_t(1) . ""; - $tmp .= PHP_EOL . $_tab . $this->_t(2) . '
'; - $tmp .= PHP_EOL . $_tab . $this->_t(3) . '
'; - $tmp .= PHP_EOL . $_tab . $this->_t(4) . implode(PHP_EOL . $_tab . $this->_t(4), (array) explode(PHP_EOL, trim($tab['html']))); - $tmp .= PHP_EOL . $_tab . $this->_t(3) . '
'; - $tmp .= PHP_EOL . $_tab . $this->_t(2) . '
'; - $tmp .= PHP_EOL . $_tab . $this->_t(1) . ""; - // update html - $tab['html'] = $tmp; - } - else - { - $tab['html'] = PHP_EOL . $_tab. $this->_t(1) . implode(PHP_EOL . $_tab. $this->_t(1), (array) explode(PHP_EOL, trim($tab['html']))); - } - // add the permissions if needed - if (isset($tab['permission']) && $tab['permission'] == 1) - { - $tmp = PHP_EOL . $this->_t(1) . "canDo->get('" . $tab['view'] . "." . $tab['code'] . ".viewtab')) : ?>"; - $tmp .= $tab['html']; - $tmp .= PHP_EOL . $this->_t(1) . ""; - // update html - $tab['html'] = $tmp; - // set lang for permissions - $tab['lang_permission'] = $tab['lang'] . '_TAB_PERMISSION'; - $tab['lang_permission_desc'] = $tab['lang'] . '_TAB_PERMISSION_DESC'; - $tab['lang_permission_title'] = $this->placeholders[$this->hhh . 'Views' . $this->hhh] . ' View ' . $tab['name'] . ' Tab'; - $this->setLangContent('both', $tab['lang_permission'], $tab['lang_permission_title']); - $this->setLangContent('both', $tab['lang_permission_desc'], 'Allow the users in this group to view ' . $tab['name'] . ' Tab of ' . $this->placeholders[$this->hhh . 'views' . $this->hhh]); - // set the sort key - $tab['sortKey'] = ComponentbuilderHelper::safeString($tab['lang_permission_title']); - } - // return tab - return $tab; - }, array_values($view->customtabs)); + $this->customTabs[$name_single] = array_map( + function ($tab) use ($name_single) { + // set the view name + $tab['view'] = $name_single; + // load the dynamic data + $tab['html'] = $this->setPlaceholders( + $this->setDynamicValues($tab['html']), + $this->placeholders + ); + // set the tab name + $tab['name'] = (isset($tab['name']) + && ComponentbuilderHelper::checkString( + $tab['name'] + )) ? $tab['name'] : 'Tab'; + // set lang + $tab['lang'] = $this->langPrefix . '_' + . ComponentbuilderHelper::safeString( + $tab['view'], 'U' + ) . '_' . ComponentbuilderHelper::safeString( + $tab['name'], 'U' + ); + $this->setLangContent( + 'both', $tab['lang'], $tab['name'] + ); + // set code name + $tab['code'] = ComponentbuilderHelper::safeString( + $tab['name'] + ); + // check if the permissions for the tab should be added + $_tab = ''; + if (isset($tab['permission']) + && $tab['permission'] == 1) + { + $_tab = $this->_t(1); + } + // check if the php of the tab is set, if not load it now + if (strpos($tab['html'], 'bootstrap.addTab') === false + && strpos($tab['html'], 'bootstrap.endTab') + === false) + { + // add the tab + $tmp = PHP_EOL . $_tab . $this->_t(1) + . ""; + $tmp .= PHP_EOL . $_tab . $this->_t(2) + . '
'; + $tmp .= PHP_EOL . $_tab . $this->_t(3) + . '
'; + $tmp .= PHP_EOL . $_tab . $this->_t(4) . implode( + PHP_EOL . $_tab . $this->_t(4), + (array) explode(PHP_EOL, trim($tab['html'])) + ); + $tmp .= PHP_EOL . $_tab . $this->_t(3) . '
'; + $tmp .= PHP_EOL . $_tab . $this->_t(2) . '
'; + $tmp .= PHP_EOL . $_tab . $this->_t(1) + . ""; + // update html + $tab['html'] = $tmp; + } + else + { + $tab['html'] = PHP_EOL . $_tab . $this->_t(1) + . implode( + PHP_EOL . $_tab . $this->_t(1), + (array) explode(PHP_EOL, trim($tab['html'])) + ); + } + // add the permissions if needed + if (isset($tab['permission']) + && $tab['permission'] == 1) + { + $tmp = PHP_EOL . $this->_t(1) + . "canDo->get('" + . $tab['view'] . "." . $tab['code'] + . ".viewtab')) : ?>"; + $tmp .= $tab['html']; + $tmp .= PHP_EOL . $this->_t(1) . ""; + // update html + $tab['html'] = $tmp; + // set lang for permissions + $tab['lang_permission'] = $tab['lang'] + . '_TAB_PERMISSION'; + $tab['lang_permission_desc'] = $tab['lang'] + . '_TAB_PERMISSION_DESC'; + $tab['lang_permission_title'] + = $this->placeholders[$this->hhh + . 'Views' . $this->hhh] . ' View ' + . $tab['name'] . ' Tab'; + $this->setLangContent( + 'both', $tab['lang_permission'], + $tab['lang_permission_title'] + ); + $this->setLangContent( + 'both', $tab['lang_permission_desc'], + 'Allow the users in this group to view ' + . $tab['name'] . ' Tab of ' + . $this->placeholders[$this->hhh . 'views' + . $this->hhh] + ); + // set the sort key + $tab['sortKey'] + = ComponentbuilderHelper::safeString( + $tab['lang_permission_title'] + ); + } + + // return tab + return $tab; + }, array_values($view->customtabs) + ); } unset($view->customtabs); // add the local tabs - $view->addtabs = (isset($view->addtabs) && ComponentbuilderHelper::checkJson($view->addtabs)) ? json_decode($view->addtabs, true) : null; + $view->addtabs = (isset($view->addtabs) + && ComponentbuilderHelper::checkJson($view->addtabs)) + ? json_decode($view->addtabs, true) : null; if (ComponentbuilderHelper::checkArray($view->addtabs)) { $nr = 1; @@ -1945,7 +2357,9 @@ class Get $view->tabs[1] = 'Details'; } // always make sure that publishing is lowercase - if (($removeKey = array_search('publishing', array_map('strtolower', $view->tabs))) !== false) + if (($removeKey = array_search( + 'publishing', array_map('strtolower', $view->tabs) + )) !== false) { $view->tabs[$removeKey] = 'publishing'; } @@ -1953,7 +2367,9 @@ class Get $view->tabs[15] = 'publishing'; unset($view->addtabs); // add permissions - $view->addpermissions = (isset($view->addpermissions) && ComponentbuilderHelper::checkJson($view->addpermissions)) ? json_decode($view->addpermissions, true) : null; + $view->addpermissions = (isset($view->addpermissions) + && ComponentbuilderHelper::checkJson($view->addpermissions)) + ? json_decode($view->addpermissions, true) : null; if (ComponentbuilderHelper::checkArray($view->addpermissions)) { $view->permissions = array_values($view->addpermissions); @@ -1962,40 +2378,60 @@ class Get // reset fields $view->fields = array(); // set fields - $view->addfields = (isset($view->addfields) && ComponentbuilderHelper::checkJson($view->addfields)) ? json_decode($view->addfields, true) : null; + $view->addfields = (isset($view->addfields) + && ComponentbuilderHelper::checkJson($view->addfields)) + ? json_decode($view->addfields, true) : null; if (ComponentbuilderHelper::checkArray($view->addfields)) { $ignoreFields = array(); // load the field data - $view->fields = array_map(function($field) use($name_single, $name_list, &$ignoreFields) - { - // set the field details - $this->setFieldDetails($field, $name_single, $name_list); - // check if this field is a default field OR - // check if this is none database related field - if (in_array($field['base_name'], $this->defaultFields) || - ComponentbuilderHelper::fieldCheck($field['type_name'], 'spacer') || - (isset($field['list']) && $field['list'] == 2)) // 2 = none database - { - $ignoreFields[$field['field']] = $field['field']; - } - // return field - return $field; - }, array_values($view->addfields)); + $view->fields = array_map( + function ($field) use ( + $name_single, $name_list, &$ignoreFields + ) { + // set the field details + $this->setFieldDetails( + $field, $name_single, $name_list + ); + // check if this field is a default field OR + // check if this is none database related field + if (in_array($field['base_name'], $this->defaultFields) + || ComponentbuilderHelper::fieldCheck( + $field['type_name'], 'spacer' + ) + || (isset($field['list']) + && $field['list'] == 2)) // 2 = none database + { + $ignoreFields[$field['field']] = $field['field']; + } + + // return field + return $field; + }, array_values($view->addfields) + ); // build update SQL - if ($old_view = $this->getHistoryWatch('admin_fields', $view->addfields_id)) + if ($old_view = $this->getHistoryWatch( + 'admin_fields', $view->addfields_id + )) { // add new fields were added - if (isset($old_view->addfields) && ComponentbuilderHelper::checkJson($old_view->addfields)) + if (isset($old_view->addfields) + && ComponentbuilderHelper::checkJson( + $old_view->addfields + )) { - $this->setUpdateSQL(json_decode($old_view->addfields, true), $view->addfields, 'field', $name_single, $ignoreFields); + $this->setUpdateSQL( + json_decode($old_view->addfields, true), + $view->addfields, 'field', $name_single, + $ignoreFields + ); } // clear this data unset($old_view); } // sort the fields acording to order - usort($view->fields, function($a, $b) - { + usort( + $view->fields, function ($a, $b) { if (isset($a['order_list']) && isset($b['order_list'])) { if ($a['order_list'] != 0 && $b['order_list'] != 0) @@ -2010,59 +2446,103 @@ class Get { return 0; } + return 1; } + return 0; - }); + } + ); // do some house cleaning (for fields) foreach ($view->fields as $field) { // so first we lock the field name in $field_name = $this->getFieldName($field, $name_list); // check if the field changed since the last compilation (default fields never change and are always added) - if (!isset($ignoreFields[$field['field']]) && ComponentbuilderHelper::checkObject($field['settings']->history)) + if (!isset($ignoreFields[$field['field']]) + && ComponentbuilderHelper::checkObject( + $field['settings']->history + )) { // check if the datatype changed if (isset($field['settings']->history->datatype)) { - $this->setUpdateSQL($field['settings']->history->datatype, $field['settings']->datatype, 'field.datatype', $name_single . '.' . $field_name); + $this->setUpdateSQL( + $field['settings']->history->datatype, + $field['settings']->datatype, 'field.datatype', + $name_single . '.' . $field_name + ); } // check if the datatype lenght changed - if (isset($field['settings']->history->datalenght) && isset($field['settings']->history->datalenght_other)) + if (isset($field['settings']->history->datalenght) + && isset($field['settings']->history->datalenght_other)) { - $this->setUpdateSQL($field['settings']->history->datalenght . $field['settings']->history->datalenght_other, $field['settings']->datalenght . $field['settings']->datalenght_other, 'field.lenght', $name_single . '.' . $field_name); + $this->setUpdateSQL( + $field['settings']->history->datalenght + . $field['settings']->history->datalenght_other, + $field['settings']->datalenght + . $field['settings']->datalenght_other, + 'field.lenght', $name_single . '.' . $field_name + ); } // check if the name changed - if (isset($field['settings']->history->xml) && ComponentbuilderHelper::checkJson($field['settings']->history->xml)) + if (isset($field['settings']->history->xml) + && ComponentbuilderHelper::checkJson( + $field['settings']->history->xml + )) { // only run if this is not an alias or a tag - if ((!isset($field['alias']) || !$field['alias']) && 'tag' !== $field['settings']->type_name) + if ((!isset($field['alias']) || !$field['alias']) + && 'tag' !== $field['settings']->type_name) { // build temp field bucket - $tmpfield = array(); + $tmpfield = array(); $tmpfield['settings'] = new stdClass(); // convert the xml json string to normal string - $tmpfield['settings']->xml = $this->setDynamicValues(json_decode($field['settings']->history->xml)); + $tmpfield['settings']->xml + = $this->setDynamicValues( + json_decode( + $field['settings']->history->xml + ) + ); // add properties from current field as it is generic - $tmpfield['settings']->properties = $field['settings']->properties; + $tmpfield['settings']->properties + = $field['settings']->properties; // add the old name - $tmpfield['settings']->name = $field['settings']->history->name; + $tmpfield['settings']->name + = $field['settings']->history->name; // add the field type from current field since it is generic - $tmpfield['settings']->type_name = $field['settings']->type_name; + $tmpfield['settings']->type_name + = $field['settings']->type_name; // get the old name - $old_field_name = $this->getFieldName($tmpfield); + $old_field_name = $this->getFieldName( + $tmpfield + ); // only run this if not a multi field if (!isset($this->uniqueNames[$name_list]['names'][$field_name])) { // this only works when the field is not multiple of the same field - $this->setUpdateSQL($old_field_name, $field_name, 'field.name', $name_single . '.' . $field_name); + $this->setUpdateSQL( + $old_field_name, $field_name, + 'field.name', + $name_single . '.' . $field_name + ); } elseif ($old_field_name !== $field_name) { // give a notice atleast that the multi fields could have changed and no DB update was done - $this->app->enqueueMessage(JText::_('

Field Notice

'), 'Notice'); - $this->app->enqueueMessage(JText::sprintf('You have a field called %s that has been added multiple times to the %s view, the name of that field has changed to %s. Normaly we would automaticly add the update SQL to your component, but with multiple fields this does not work automaticly since it could be that noting changed and it just seems like it did. Therefore you will have to do this manualy if it actualy did change!', $field_name, $name_single, $old_field_name), 'Notice'); + $this->app->enqueueMessage( + JText::_('

Field Notice

'), + 'Notice' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'You have a field called %s that has been added multiple times to the %s view, the name of that field has changed to %s. Normaly we would automaticly add the update SQL to your component, but with multiple fields this does not work automaticly since it could be that noting changed and it just seems like it did. Therefore you will have to do this manualy if it actualy did change!', + $field_name, $name_single, + $old_field_name + ), 'Notice' + ); } // remove tmp unset($tmpfield); @@ -2078,52 +2558,99 @@ class Get // check if the view name changed if (ComponentbuilderHelper::checkString($old_view->name_single)) { - $this->setUpdateSQL(ComponentbuilderHelper::safeString($old_view->name_single), $name_single, 'table_name', $name_single); + $this->setUpdateSQL( + ComponentbuilderHelper::safeString( + $old_view->name_single + ), $name_single, 'table_name', $name_single + ); } // loop the mysql table settings - foreach ($this->mysqlTableKeys as $_mysqlTableKey => $_mysqlTableVal) + foreach ( + $this->mysqlTableKeys as $_mysqlTableKey => $_mysqlTableVal + ) { // check if the table engine changed - if (isset($old_view->{'mysql_table_' . $_mysqlTableKey}) && isset($view->{'mysql_table_' . $_mysqlTableKey})) + if (isset($old_view->{'mysql_table_' . $_mysqlTableKey}) + && isset($view->{'mysql_table_' . $_mysqlTableKey})) { - $this->setUpdateSQL( $old_view->{'mysql_table_' . $_mysqlTableKey}, $view->{'mysql_table_' . $_mysqlTableKey}, 'table_' . $_mysqlTableKey, $name_single); + $this->setUpdateSQL( + $old_view->{'mysql_table_' . $_mysqlTableKey}, + $view->{'mysql_table_' . $_mysqlTableKey}, + 'table_' . $_mysqlTableKey, $name_single + ); } // check if there is no history on table engine, and it changed from the default/global - elseif (isset($view->{'mysql_table_' . $_mysqlTableKey}) && ComponentbuilderHelper::checkString($view->{'mysql_table_' . $_mysqlTableKey}) && !is_numeric($view->{'mysql_table_' . $_mysqlTableKey})) + elseif (isset($view->{'mysql_table_' . $_mysqlTableKey}) + && ComponentbuilderHelper::checkString( + $view->{'mysql_table_' . $_mysqlTableKey} + ) + && !is_numeric( + $view->{'mysql_table_' . $_mysqlTableKey} + )) { - $this->setUpdateSQL($_mysqlTableVal['default'], $view->{'mysql_table_' . $_mysqlTableKey}, 'table_' . $_mysqlTableKey, $name_single); + $this->setUpdateSQL( + $_mysqlTableVal['default'], + $view->{'mysql_table_' . $_mysqlTableKey}, + 'table_' . $_mysqlTableKey, $name_single + ); } } // clear this data unset($old_view); } // set the conditions - $view->addconditions = (isset($view->addconditions) && ComponentbuilderHelper::checkJson($view->addconditions)) ? json_decode($view->addconditions, true) : null; + $view->addconditions = (isset($view->addconditions) + && ComponentbuilderHelper::checkJson($view->addconditions)) + ? json_decode($view->addconditions, true) : null; if (ComponentbuilderHelper::checkArray($view->addconditions)) { $view->conditions = array(); - $ne = 0; + $ne = 0; foreach ($view->addconditions as $nr => $conditionValue) { - if (ComponentbuilderHelper::checkArray($conditionValue['target_field']) && ComponentbuilderHelper::checkArray($view->fields)) + if (ComponentbuilderHelper::checkArray( + $conditionValue['target_field'] + ) + && ComponentbuilderHelper::checkArray($view->fields)) { - foreach ($conditionValue['target_field'] as $fieldKey => $fieldId) + foreach ( + $conditionValue['target_field'] as $fieldKey => + $fieldId + ) { foreach ($view->fields as $fieldValues) { - if ((int) $fieldValues['field'] == (int) $fieldId) + if ((int) $fieldValues['field'] + == (int) $fieldId) { // load the field details - $required = ComponentbuilderHelper::getBetween($fieldValues['settings']->xml, 'required="', '"'); - $required = ($required === 'true' || $required === '1') ? 'yes' : 'no'; - $filter = ComponentbuilderHelper::getBetween($fieldValues['settings']->xml, 'filter="', '"'); - $filter = ComponentbuilderHelper::checkString($filter) ? $filter : 'none'; + $required + = ComponentbuilderHelper::getBetween( + $fieldValues['settings']->xml, + 'required="', '"' + ); + $required = ($required === 'true' + || $required === '1') ? 'yes' : 'no'; + $filter + = ComponentbuilderHelper::getBetween( + $fieldValues['settings']->xml, + 'filter="', '"' + ); + $filter + = ComponentbuilderHelper::checkString( + $filter + ) ? $filter : 'none'; // set the field name - $conditionValue['target_field'][$fieldKey] = array( - 'name' => $this->getFieldName($fieldValues, $name_list), - 'type' => $this->getFieldType($fieldValues), + $conditionValue['target_field'][$fieldKey] + = array( + 'name' => $this->getFieldName( + $fieldValues, $name_list + ), + 'type' => $this->getFieldType( + $fieldValues + ), 'required' => $required, - 'filter' => $filter + 'filter' => $filter ); break; } @@ -2132,22 +2659,32 @@ class Get } // load match field - if (ComponentbuilderHelper::checkArray($view->fields) && isset($conditionValue['match_field'])) + if (ComponentbuilderHelper::checkArray($view->fields) + && isset($conditionValue['match_field'])) { foreach ($view->fields as $fieldValue) { - if ((int) $fieldValue['field'] == (int) $conditionValue['match_field']) + if ((int) $fieldValue['field'] + == (int) $conditionValue['match_field']) { // set the type $type = $this->getFieldType($fieldValue); // set the field details - $conditionValue['match_name'] = $this->getFieldName($fieldValue, $name_list); + $conditionValue['match_name'] + = $this->getFieldName( + $fieldValue, $name_list + ); $conditionValue['match_type'] = $type; - $conditionValue['match_xml'] = $fieldValue['settings']->xml; + $conditionValue['match_xml'] + = $fieldValue['settings']->xml; // if custom field load field being extended if (!ComponentbuilderHelper::fieldCheck($type)) { - $conditionValue['match_extends'] = ComponentbuilderHelper::getBetween($fieldValue['settings']->xml, 'extends="', '"'); + $conditionValue['match_extends'] + = ComponentbuilderHelper::getBetween( + $fieldValue['settings']->xml, + 'extends="', '"' + ); } else { @@ -2165,49 +2702,86 @@ class Get unset($view->addconditions); // prep the buckets - $this->fieldRelations[$name_list] = array(); - $this->listJoinBuilder[$name_list] = array(); + $this->fieldRelations[$name_list] = array(); + $this->listJoinBuilder[$name_list] = array(); $this->listHeadOverRide[$name_list] = array(); // set the relations - $view->addrelations = (isset($view->addrelations) && ComponentbuilderHelper::checkJson($view->addrelations)) ? json_decode($view->addrelations, true) : null; + $view->addrelations = (isset($view->addrelations) + && ComponentbuilderHelper::checkJson($view->addrelations)) + ? json_decode($view->addrelations, true) : null; if (ComponentbuilderHelper::checkArray($view->addrelations)) { foreach ($view->addrelations as $nr => $relationsValue) { // only add if list view field is selected and joind fields are set - if (isset($relationsValue['listfield']) && is_numeric($relationsValue['listfield']) && $relationsValue['listfield'] > 0 && - isset($relationsValue['area']) && is_numeric($relationsValue['area']) && $relationsValue['area'] > 0) + if (isset($relationsValue['listfield']) + && is_numeric( + $relationsValue['listfield'] + ) + && $relationsValue['listfield'] > 0 + && isset($relationsValue['area']) + && is_numeric($relationsValue['area']) + && $relationsValue['area'] > 0) { // do a dynamic update on the set values - if (isset($relationsValue['set']) && ComponentbuilderHelper::checkString($relationsValue['set'])) + if (isset($relationsValue['set']) + && ComponentbuilderHelper::checkString( + $relationsValue['set'] + )) { - $relationsValue['set'] = $this->setDynamicValues($relationsValue['set']); + $relationsValue['set'] = $this->setDynamicValues( + $relationsValue['set'] + ); } // check that the arrays are set - if (!isset($this->fieldRelations[$name_list][(int) $relationsValue['listfield']]) || !ComponentbuilderHelper::checkArray($this->fieldRelations[$name_list][(int) $relationsValue['listfield']])) + if (!isset($this->fieldRelations[$name_list][(int) $relationsValue['listfield']]) + || !ComponentbuilderHelper::checkArray( + $this->fieldRelations[$name_list][(int) $relationsValue['listfield']] + )) { - $this->fieldRelations[$name_list][(int) $relationsValue['listfield']] = array(); + $this->fieldRelations[$name_list][(int) $relationsValue['listfield']] + = array(); } // load the field relations - $this->fieldRelations[$name_list][ (int) $relationsValue['listfield']][ (int) $relationsValue['area']] = $relationsValue; + $this->fieldRelations[$name_list][(int) $relationsValue['listfield']][(int) $relationsValue['area']] + = $relationsValue; // load the list joints - if (isset($relationsValue['joinfields']) && ComponentbuilderHelper::checkArray($relationsValue['joinfields'])) + if (isset($relationsValue['joinfields']) + && ComponentbuilderHelper::checkArray( + $relationsValue['joinfields'] + )) { foreach ($relationsValue['joinfields'] as $join) { - $this->listJoinBuilder[$name_list][(int) $join] = (int) $join; + $this->listJoinBuilder[$name_list][(int) $join] + = (int) $join; } } // set header over-ride - if (isset($relationsValue['column_name']) && ComponentbuilderHelper::checkString($relationsValue['column_name'])) + if (isset($relationsValue['column_name']) + && ComponentbuilderHelper::checkString( + $relationsValue['column_name'] + )) { - $check_column_name = trim(strtolower($relationsValue['column_name'])); + $check_column_name = trim( + strtolower($relationsValue['column_name']) + ); // confirm it should really make the over ride if ('default' !== $check_column_name) { - $column_name_lang = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($name_list, 'U') . '_' . ComponentbuilderHelper::safeString($relationsValue['column_name'], 'U'); - $this->setLangContent('admin', $column_name_lang, $relationsValue['column_name']); - $this->listHeadOverRide[$name_list][(int) $relationsValue['listfield']] = $column_name_lang; + $column_name_lang = $this->langPrefix . '_' + . ComponentbuilderHelper::safeString( + $name_list, 'U' + ) . '_' + . ComponentbuilderHelper::safeString( + $relationsValue['column_name'], 'U' + ); + $this->setLangContent( + 'admin', $column_name_lang, + $relationsValue['column_name'] + ); + $this->listHeadOverRide[$name_list][(int) $relationsValue['listfield']] + = $column_name_lang; } } } @@ -2217,11 +2791,16 @@ class Get // set linked views $this->linkedAdminViews[$name_single] = null; - $view->addlinked_views = (isset($view->addlinked_views) && ComponentbuilderHelper::checkJson($view->addlinked_views)) ? json_decode($view->addlinked_views, true) : null; + $view->addlinked_views + = (isset($view->addlinked_views) + && ComponentbuilderHelper::checkJson($view->addlinked_views)) + ? json_decode($view->addlinked_views, true) : null; if (ComponentbuilderHelper::checkArray($view->addlinked_views)) { // setup linked views to global data sets - $this->linkedAdminViews[$name_single] = array_values($view->addlinked_views); + $this->linkedAdminViews[$name_single] = array_values( + $view->addlinked_views + ); } unset($view->addlinked_views); // set the lang target @@ -2231,16 +2810,23 @@ class Get $this->lang = 'both'; } // set GUI mapper - $guiMapper = array( 'table' => 'admin_view', 'id' => (int) $id, 'type' => 'js'); + $guiMapper = array('table' => 'admin_view', 'id' => (int) $id, + 'type' => 'js'); // add_javascript - $addArrayJ = array('javascript_view_file', 'javascript_view_footer', 'javascript_views_file', 'javascript_views_footer'); + $addArrayJ = array('javascript_view_file', 'javascript_view_footer', + 'javascript_views_file', + 'javascript_views_footer'); // update GUI mapper $guiMapper['prefix'] = PHP_EOL; foreach ($addArrayJ as $scripter) { - if (isset($view->{'add_' . $scripter}) && $view->{'add_' . $scripter} == 1 && ComponentbuilderHelper::checkString($view->$scripter)) + if (isset($view->{'add_' . $scripter}) + && $view->{'add_' . $scripter} == 1 + && ComponentbuilderHelper::checkString($view->$scripter)) { - $scripter_target = str_replace('javascript_', '', $scripter); + $scripter_target = str_replace( + 'javascript_', '', $scripter + ); // update GUI mapper field $guiMapper['field'] = $scripter; $this->setCustomScriptBuilder( @@ -2254,11 +2840,15 @@ class Get true ); // check if a token must be set - if (strpos($view->$scripter, "token") !== false || strpos($view->$scripter, "task=ajax") !== false) + if (strpos($view->$scripter, "token") !== false + || strpos( + $view->$scripter, "task=ajax" + ) !== false) { if (!$this->customScriptBuilder['token'][$name_single]) { - $this->customScriptBuilder['token'][$name_single] = true; + $this->customScriptBuilder['token'][$name_single] + = true; } } unset($view->{$scripter}); @@ -2269,7 +2859,9 @@ class Get $addArrayC = array('css_view', 'css_views'); foreach ($addArrayC as $scripter) { - if (isset($view->{'add_' . $scripter}) && $view->{'add_' . $scripter} == 1 && ComponentbuilderHelper::checkString($view->{$scripter})) + if (isset($view->{'add_' . $scripter}) + && $view->{'add_' . $scripter} == 1 + && ComponentbuilderHelper::checkString($view->{$scripter})) { $this->setCustomScriptBuilder( $view->{$scripter}, @@ -2287,10 +2879,19 @@ class Get // update GUI mapper $guiMapper['type'] = 'php'; // add_php - $addArrayP = array('php_getitem', 'php_before_save', 'php_save', 'php_getform', 'php_postsavehook', 'php_getitems', 'php_getitems_after_all', 'php_getlistquery', 'php_allowadd', 'php_allowedit', 'php_before_cancel', 'php_after_cancel', 'php_before_delete', 'php_after_delete', 'php_before_publish', 'php_after_publish', 'php_batchcopy', 'php_batchmove', 'php_document'); + $addArrayP = array('php_getitem', 'php_before_save', 'php_save', + 'php_getform', 'php_postsavehook', + 'php_getitems', 'php_getitems_after_all', + 'php_getlistquery', 'php_allowadd', + 'php_allowedit', 'php_before_cancel', + 'php_after_cancel', 'php_before_delete', + 'php_after_delete', 'php_before_publish', + 'php_after_publish', 'php_batchcopy', + 'php_batchmove', 'php_document'); foreach ($addArrayP as $scripter) { - if (isset($view->{'add_' . $scripter}) && $view->{'add_' . $scripter} == 1) + if (isset($view->{'add_' . $scripter}) + && $view->{'add_' . $scripter} == 1) { // update GUI mapper field $guiMapper['field'] = $scripter; @@ -2305,7 +2906,8 @@ class Get } } // add the custom buttons - if (isset($view->add_custom_button) && $view->add_custom_button == 1) + if (isset($view->add_custom_button) + && $view->add_custom_button == 1) { $button_code_array = array( 'php_model', @@ -2316,18 +2918,26 @@ class Get // set for the code foreach ($button_code_array as $button_code_field) { - if (isset($view->{$button_code_field}) && ComponentbuilderHelper::checkString($view->{$button_code_field})) + if (isset($view->{$button_code_field}) + && ComponentbuilderHelper::checkString( + $view->{$button_code_field} + )) { // set field $guiMapper['field'] = $button_code_field; - $view->{$button_code_field} = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($view->{$button_code_field})), + $view->{$button_code_field} + = $this->setGuiCodePlaceholder( + $this->setDynamicValues( + base64_decode($view->{$button_code_field}) + ), $guiMapper - ); + ); } } // set the button array - $view->custom_button = (isset($view->custom_button) && ComponentbuilderHelper::checkJson($view->custom_button)) ? json_decode($view->custom_button, true) : null; + $view->custom_button = (isset($view->custom_button) + && ComponentbuilderHelper::checkJson($view->custom_button)) + ? json_decode($view->custom_button, true) : null; if (ComponentbuilderHelper::checkArray($view->custom_button)) { $view->custom_buttons = array_values($view->custom_button); @@ -2335,12 +2945,19 @@ class Get unset($view->custom_button); } // set custom import scripts - if (isset($view->add_custom_import) && $view->add_custom_import == 1) + if (isset($view->add_custom_import) + && $view->add_custom_import == 1) { - $addImportArray = array('php_import_ext', 'php_import_display', 'php_import', 'php_import_setdata', 'php_import_save', 'php_import_headers', 'html_import_view'); + $addImportArray = array('php_import_ext', 'php_import_display', + 'php_import', 'php_import_setdata', + 'php_import_save', 'php_import_headers', + 'html_import_view'); foreach ($addImportArray as $importScripter) { - if (isset($view->$importScripter) && strlen($view->$importScripter) > 0) + if (isset($view->$importScripter) + && strlen( + $view->$importScripter + ) > 0) { // update GUI mapper field $guiMapper['field'] = $importScripter; @@ -2356,7 +2973,11 @@ class Get else { // load the default - $this->customScriptBuilder[$importScripter]['import_' . $name_list] = ComponentbuilderHelper::getDynamicScripts($importScripter, true); + $this->customScriptBuilder[$importScripter]['import_' + . $name_list] + = ComponentbuilderHelper::getDynamicScripts( + $importScripter, true + ); } } } @@ -2366,7 +2987,7 @@ class Get { // insure the token is added to edit view atleast $this->customScriptBuilder['token'][$name_single] = true; - $addAjaxSite = false; + $addAjaxSite = false; if (isset($this->siteEditView[$id]) && $this->siteEditView[$id]) { // we should add this site ajax to front ajax @@ -2377,14 +2998,18 @@ class Get } } // check if controller input as been set - $view->ajax_input = (isset($view->ajax_input) && ComponentbuilderHelper::checkJson($view->ajax_input)) ? json_decode($view->ajax_input, true) : null; + $view->ajax_input = (isset($view->ajax_input) + && ComponentbuilderHelper::checkJson($view->ajax_input)) + ? json_decode($view->ajax_input, true) : null; if (ComponentbuilderHelper::checkArray($view->ajax_input)) { if ($addAjaxSite) { - $this->customScriptBuilder['site']['ajax_controller'][$name_single] = array_values($view->ajax_input); + $this->customScriptBuilder['site']['ajax_controller'][$name_single] + = array_values($view->ajax_input); } - $this->customScriptBuilder['admin']['ajax_controller'][$name_single] = array_values($view->ajax_input); + $this->customScriptBuilder['admin']['ajax_controller'][$name_single] + = array_values($view->ajax_input); $this->addAjax = true; unset($view->ajax_input); } @@ -2417,26 +3042,32 @@ class Get } } // activate alias builder - if (!isset($this->customAliasBuilder[$name_single]) && isset($view->alias_builder_type) && 2 == $view->alias_builder_type && isset($view->alias_builder) && ComponentbuilderHelper::checkJson($view->alias_builder)) + if (!isset($this->customAliasBuilder[$name_single]) + && isset($view->alias_builder_type) + && 2 == $view->alias_builder_type + && isset($view->alias_builder) + && ComponentbuilderHelper::checkJson($view->alias_builder)) { // get the aliasFields $alias_fields = (array) json_decode($view->alias_builder, true); // get the active fields - $alias_fields = (array) array_filter($view->fields, function($field) use($alias_fields) + $alias_fields = (array) array_filter( + $view->fields, function ($field) use ($alias_fields) { + // check if field is in view fields + if (in_array($field['field'], $alias_fields)) { - // check if field is in view fields - if (in_array($field['field'], $alias_fields)) - { - return true; - } - return false; - }); + return true; + } + + return false; + } + ); // check if all is well if (ComponentbuilderHelper::checkArray($alias_fields)) { // load the field names - $this->customAliasBuilder[$name_single] = (array) array_map(function ($field) use($name_list) - { + $this->customAliasBuilder[$name_single] = (array) array_map( + function ($field) use ($name_list) { return $this->getFieldName($field, $name_list); }, $alias_fields ); @@ -2450,7 +3081,8 @@ class Get if ($view->source == 1 && isset($view->tables)) { // build and add the SQL dump - $this->customScriptBuilder['sql'][$name_single] = $this->buildSqlDump($view->tables, $name_single, $id); + $this->customScriptBuilder['sql'][$name_single] + = $this->buildSqlDump($view->tables, $name_single, $id); unset($view->tables); } elseif ($view->source == 2 && isset($view->sql)) @@ -2470,22 +3102,33 @@ class Get $this->mysqlTableSetting[$name_single] = array(); } // set mySql Table Settings - foreach ($this->mysqlTableKeys as $_mysqlTableKey => $_mysqlTableVal) + foreach ( + $this->mysqlTableKeys as $_mysqlTableKey => $_mysqlTableVal + ) { - if (isset($view->{'mysql_table_' . $_mysqlTableKey}) && ComponentbuilderHelper::checkString($view->{'mysql_table_' . $_mysqlTableKey}) && !is_numeric($view->{'mysql_table_' . $_mysqlTableKey})) + if (isset($view->{'mysql_table_' . $_mysqlTableKey}) + && ComponentbuilderHelper::checkString( + $view->{'mysql_table_' . $_mysqlTableKey} + ) + && !is_numeric($view->{'mysql_table_' . $_mysqlTableKey})) { - $this->mysqlTableSetting[$name_single][$_mysqlTableKey] = $view->{'mysql_table_' . $_mysqlTableKey}; + $this->mysqlTableSetting[$name_single][$_mysqlTableKey] + = $view->{'mysql_table_' . $_mysqlTableKey}; } else { - $this->mysqlTableSetting[$name_single][$_mysqlTableKey] = $_mysqlTableVal['default']; + $this->mysqlTableSetting[$name_single][$_mysqlTableKey] + = $_mysqlTableVal['default']; } // remove the table values since we moved to another object unset($view->{'mysql_table_' . $_mysqlTableKey}); } // Trigger Event: jcb_ce_onAfterModelViewData - $this->triggerEvent('jcb_ce_onAfterModelViewData', array(&$this->componentContext, &$view, &$this->placeholders)); + $this->triggerEvent( + 'jcb_ce_onAfterModelViewData', + array(&$this->componentContext, &$view, &$this->placeholders) + ); // clear placeholders unset($this->placeholders[$this->hhh . 'view' . $this->hhh]); @@ -2504,18 +3147,19 @@ class Get // store this view to class object $this->_adminViewData[$id] = $view; } + // return the found view data return $this->_adminViewData[$id]; } /** * Get all Custom View Data - * - * @param int $id The view ID - * @param string $table The view table - * + * + * @param int $id The view ID + * @param string $table The view table + * * @return oject The view data - * + * */ public function getCustomViewData($id, $table = 'site_view') { @@ -2527,7 +3171,10 @@ class Get $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); // Trigger Event: jcb_ce_onBeforeQueryCustomViewData - $this->triggerEvent('jcb_ce_onBeforeQueryCustomViewData', array(&$this->componentContext, &$id, &$table, &$query, &$this->db)); + $this->triggerEvent( + 'jcb_ce_onBeforeQueryCustomViewData', + array(&$this->componentContext, &$id, &$table, &$query, &$this->db) + ); // Reset the query using our newly populated query object. $this->db->setQuery($query); @@ -2536,7 +3183,10 @@ class Get $view = $this->db->loadObject(); // Trigger Event: jcb_ce_onBeforeModelCustomViewData - $this->triggerEvent('jcb_ce_onBeforeModelCustomViewData', array(&$this->componentContext, &$view, &$id, &$table)); + $this->triggerEvent( + 'jcb_ce_onBeforeModelCustomViewData', + array(&$this->componentContext, &$view, &$id, &$table) + ); if ($table === 'site_view') { @@ -2544,7 +3194,7 @@ class Get // repeatable fields to update $searchRepeatables = array( // repeatablefield => checker - 'ajax_input' => 'value_name', + 'ajax_input' => 'value_name', 'custom_button' => 'name' ); } @@ -2560,26 +3210,34 @@ class Get // set upater $updater = array( 'table' => $table, - 'key' => 'id', - 'val' => (int) $id + 'key' => 'id', + 'val' => (int) $id ); // update the repeatable fields - $view = ComponentbuilderHelper::convertRepeatableFields($view, $searchRepeatables, $updater); + $view = ComponentbuilderHelper::convertRepeatableFields( + $view, $searchRepeatables, $updater + ); // set GUI mapper - $guiMapper = array( 'table' => $table, 'id' => (int) $id, 'field' => 'default', 'type' => 'html'); + $guiMapper = array('table' => $table, 'id' => (int) $id, + 'field' => 'default', 'type' => 'html'); // set the default data $view->default = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($view->default)), - $guiMapper - ); + $this->setDynamicValues(base64_decode($view->default)), + $guiMapper + ); // fix alias to use in code - $view->code = $this->uniqueCode(ComponentbuilderHelper::safeString($view->codename)); + $view->code = $this->uniqueCode( + ComponentbuilderHelper::safeString($view->codename) + ); $view->Code = ComponentbuilderHelper::safeString($view->code, 'F'); $view->CODE = ComponentbuilderHelper::safeString($view->code, 'U'); // load context if not set - if (!isset($view->context) || !ComponentbuilderHelper::checkString($view->context)) + if (!isset($view->context) + || !ComponentbuilderHelper::checkString( + $view->context + )) { $view->context = $view->code; } @@ -2611,16 +3269,19 @@ class Get { if ($this->getMediaLibrary((int) $library)) { - $this->libManager[$this->target][$view->code][(int) $library] = true; + $this->libManager[$this->target][$view->code][(int) $library] + = true; } } } } - elseif (is_numeric($view->libraries) && !isset($this->libManager[$this->target][$view->code][(int) $view->libraries])) + elseif (is_numeric($view->libraries) + && !isset($this->libManager[$this->target][$view->code][(int) $view->libraries])) { if ($this->getMediaLibrary((int) $view->libraries)) { - $this->libManager[$this->target][$view->code][(int) $view->libraries] = true; + $this->libManager[$this->target][$view->code][(int) $view->libraries] + = true; } } // setup template array @@ -2634,10 +3295,14 @@ class Get { $this->uikitComp[$view->code] = array(); } - $this->uikitComp[$view->code] = ComponentbuilderHelper::getUikitComp($view->default, $this->uikitComp[$view->code]); + $this->uikitComp[$view->code] + = ComponentbuilderHelper::getUikitComp( + $view->default, $this->uikitComp[$view->code] + ); } // check for footable - if (!isset($this->footableScripts[$this->target][$view->code]) || !$this->footableScripts[$this->target][$view->code]) + if (!isset($this->footableScripts[$this->target][$view->code]) + || !$this->footableScripts[$this->target][$view->code]) { $foundFoo = $this->getFootableScripts($view->default); if ($foundFoo) @@ -2650,7 +3315,8 @@ class Get } } // check for get module - if (!isset($this->getModule[$this->target][$view->code]) || !$this->getModule[$this->target][$view->code]) + if (!isset($this->getModule[$this->target][$view->code]) + || !$this->getModule[$this->target][$view->code]) { $found = $this->getGetModule($view->default); if ($found) @@ -2659,31 +3325,43 @@ class Get } } // set the main get data - $main_get = $this->setGetData(array($view->main_get), $view->code, $view->context); + $main_get = $this->setGetData( + array($view->main_get), $view->code, $view->context + ); $view->main_get = $main_get[0]; // set the custom_get data - $view->custom_get = $this->setGetData(json_decode($view->custom_get, true), $view->code, $view->context); + $view->custom_get = $this->setGetData( + json_decode($view->custom_get, true), $view->code, $view->context + ); // set array adding array of scripts - $addArray = array('php_view', 'php_jview', 'php_jview_display', 'php_document', 'javascript_file', 'js_document', 'css_document', 'css'); + $addArray = array('php_view', 'php_jview', 'php_jview_display', + 'php_document', 'javascript_file', 'js_document', + 'css_document', 'css'); // set GUI mapper $guiMapper['type'] = 'php'; foreach ($addArray as $scripter) { - if (isset($view->{'add_' . $scripter}) && $view->{'add_' . $scripter} == 1 && ComponentbuilderHelper::checkString($view->$scripter)) + if (isset($view->{'add_' . $scripter}) + && $view->{'add_' . $scripter} == 1 + && ComponentbuilderHelper::checkString($view->$scripter)) { // css does not get placholders yet if (strpos($scripter, 'css') === false) { // set field $guiMapper['field'] = $scripter; - $view->$scripter = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($view->$scripter)), - $guiMapper - ); + $view->$scripter = $this->setGuiCodePlaceholder( + $this->setDynamicValues( + base64_decode($view->$scripter) + ), + $guiMapper + ); } else { - $view->$scripter = $this->setDynamicValues(base64_decode($view->$scripter)); + $view->$scripter = $this->setDynamicValues( + base64_decode($view->$scripter) + ); } if (2 == $this->uikit || 1 == $this->uikit) { @@ -2692,18 +3370,23 @@ class Get $this->uikitComp[$view->code] = array(); } // set uikit to views - $this->uikitComp[$view->code] = ComponentbuilderHelper::getUikitComp($view->$scripter, $this->uikitComp[$view->code]); + $this->uikitComp[$view->code] + = ComponentbuilderHelper::getUikitComp( + $view->$scripter, $this->uikitComp[$view->code] + ); } $this->setTemplateAndLayoutData($view->$scripter, $view->code); // check for footable - if (!isset($this->footableScripts[$this->target][$view->code]) || !$this->footableScripts[$this->target][$view->code]) + if (!isset($this->footableScripts[$this->target][$view->code]) + || !$this->footableScripts[$this->target][$view->code]) { $foundFoo = $this->getFootableScripts($view->$scripter); if ($foundFoo) { - $this->footableScripts[$this->target][$view->code] = true; + $this->footableScripts[$this->target][$view->code] + = true; } if ($foundFoo && !$this->footable) { @@ -2711,7 +3394,8 @@ class Get } } // check for google chart - if (!isset($this->googleChart[$this->target][$view->code]) || !$this->googleChart[$this->target][$view->code]) + if (!isset($this->googleChart[$this->target][$view->code]) + || !$this->googleChart[$this->target][$view->code]) { $found = $this->getGoogleChart($view->$scripter); if ($found) @@ -2724,7 +3408,8 @@ class Get } } // check for get module - if (!isset($this->getModule[$this->target][$view->code]) || !$this->getModule[$this->target][$view->code]) + if (!isset($this->getModule[$this->target][$view->code]) + || !$this->getModule[$this->target][$view->code]) { $found = $this->getGetModule($view->$scripter); if ($found) @@ -2748,10 +3433,13 @@ class Get } $setAjax = false; // check if controller input as been set - $view->ajax_input = (isset($view->ajax_input) && ComponentbuilderHelper::checkJson($view->ajax_input)) ? json_decode($view->ajax_input, true) : null; + $view->ajax_input = (isset($view->ajax_input) + && ComponentbuilderHelper::checkJson($view->ajax_input)) + ? json_decode($view->ajax_input, true) : null; if (ComponentbuilderHelper::checkArray($view->ajax_input)) { - $this->customScriptBuilder[$target]['ajax_controller'][$view->code] = array_values($view->ajax_input); + $this->customScriptBuilder[$target]['ajax_controller'][$view->code] + = array_values($view->ajax_input); $setAjax = true; } unset($view->ajax_input); @@ -2795,18 +3483,25 @@ class Get // set for the code foreach ($button_code_array as $button_code_field) { - if (isset($view->{$button_code_field}) && ComponentbuilderHelper::checkString($view->{$button_code_field})) + if (isset($view->{$button_code_field}) + && ComponentbuilderHelper::checkString( + $view->{$button_code_field} + )) { // set field - $guiMapper['field'] = $button_code_field; + $guiMapper['field'] = $button_code_field; $view->{$button_code_field} = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($view->{$button_code_field})), + $this->setDynamicValues( + base64_decode($view->{$button_code_field}) + ), $guiMapper - ); + ); } } // set the button array - $view->custom_button = (isset($view->custom_button) && ComponentbuilderHelper::checkJson($view->custom_button)) ? json_decode($view->custom_button, true) : null; + $view->custom_button = (isset($view->custom_button) + && ComponentbuilderHelper::checkJson($view->custom_button)) + ? json_decode($view->custom_button, true) : null; if (ComponentbuilderHelper::checkArray($view->custom_button)) { $view->custom_buttons = array_values($view->custom_button); @@ -2815,7 +3510,10 @@ class Get } // Trigger Event: jcb_ce_onAfterModelCustomViewData - $this->triggerEvent('jcb_ce_onAfterModelCustomViewData', array(&$this->componentContext, &$view)); + $this->triggerEvent( + 'jcb_ce_onAfterModelCustomViewData', + array(&$this->componentContext, &$view) + ); // return the found view data return $view; @@ -2823,13 +3521,13 @@ class Get /** * Get all Field Data - * - * @param int $id The field ID - * @param string $name_single The view edit or single name - * @param string $name_list The view list name + * + * @param int $id The field ID + * @param string $name_single The view edit or single name + * @param string $name_list The view list name * * @return oject The field data - * + * */ public function getFieldData($id, $name_single = null, $name_list = null) { @@ -2840,13 +3538,28 @@ class Get // Select all the values in the field $query->select('a.*'); - $query->select($this->db->quoteName(array('c.name', 'c.properties'), array('type_name', 'properties'))); + $query->select( + $this->db->quoteName( + array('c.name', 'c.properties'), + array('type_name', 'properties') + ) + ); $query->from('#__componentbuilder_field AS a'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_fieldtype', 'c') . ' ON (' . $this->db->quoteName('a.fieldtype') . ' = ' . $this->db->quoteName('c.id') . ')'); - $query->where($this->db->quoteName('a.id') . ' = ' . $this->db->quote($id)); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_fieldtype', 'c') + . ' ON (' . $this->db->quoteName('a.fieldtype') . ' = ' + . $this->db->quoteName('c.id') . ')' + ); + $query->where( + $this->db->quoteName('a.id') . ' = ' . $this->db->quote($id) + ); // Trigger Event: jcb_ce_onBeforeQueryFieldData - $this->triggerEvent('jcb_ce_onBeforeQueryFieldData', array(&$this->componentContext, &$id, &$query, &$this->db)); + $this->triggerEvent( + 'jcb_ce_onBeforeQueryFieldData', + array(&$this->componentContext, &$id, &$query, &$this->db) + ); // Reset the query using our newly populated query object. $this->db->setQuery($query); @@ -2857,7 +3570,10 @@ class Get $field = $this->db->loadObject(); // Trigger Event: jcb_ce_onBeforeModelFieldData - $this->triggerEvent('jcb_ce_onBeforeModelFieldData', array(&$this->componentContext, &$field)); + $this->triggerEvent( + 'jcb_ce_onBeforeModelFieldData', + array(&$this->componentContext, &$field) + ); // adding a fix for the changed name of type to fieldtype $field->type = $field->fieldtype; @@ -2870,44 +3586,69 @@ class Get // set upater $updater = array( 'table' => 'fieldtype', - 'key' => 'id', - 'val' => (int) $id + 'key' => 'id', + 'val' => (int) $id ); // update the repeatable fields - $field = ComponentbuilderHelper::convertRepeatableFields($field, $searchRepeatables, $updater); + $field = ComponentbuilderHelper::convertRepeatableFields( + $field, $searchRepeatables, $updater + ); // load the values form params $field->xml = $this->setDynamicValues(json_decode($field->xml)); // check if we have validate (validation rule set) - $validationRule = ComponentbuilderHelper::getBetween($field->xml, 'validate="', '"'); + $validationRule = ComponentbuilderHelper::getBetween( + $field->xml, 'validate="', '"' + ); if (ComponentbuilderHelper::checkString($validationRule)) { // make sure it is lowercase - $validationRule = ComponentbuilderHelper::safeString($validationRule); + $validationRule = ComponentbuilderHelper::safeString( + $validationRule + ); // link this field to this validation $this->validationLinkedFields[$id] = $validationRule; // make sure it is not already set if (!isset($this->validationRules[$validationRule])) { // get joomla core validation names - if ($coreValidationRules = ComponentbuilderHelper::getExistingValidationRuleNames(true)) + if ($coreValidationRules + = ComponentbuilderHelper::getExistingValidationRuleNames( + true + )) { // make sure this rule is not a core validation rule - if (!in_array($validationRule, (array) $coreValidationRules)) + if (!in_array( + $validationRule, (array) $coreValidationRules + )) { // get the class methods for this rule if it exists - if ($this->validationRules[$validationRule] = ComponentbuilderHelper::getVar('validation_rule', $validationRule, 'name', 'php')) + if ($this->validationRules[$validationRule] + = ComponentbuilderHelper::getVar( + 'validation_rule', $validationRule, 'name', + 'php' + )) { // open and set the validation rule - $this->validationRules[$validationRule] = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($this->validationRules[$validationRule])), $this->placeholders), + $this->validationRules[$validationRule] + = $this->setGuiCodePlaceholder( + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode( + $this->validationRules[$validationRule] + ) + ), $this->placeholders + ), array( 'table' => 'validation_rule', 'field' => 'php', - 'id' => ComponentbuilderHelper::getVar('validation_rule', $validationRule, 'name', 'id'), - 'type' => 'php') - ); + 'id' => ComponentbuilderHelper::getVar( + 'validation_rule', + $validationRule, 'name', 'id' + ), + 'type' => 'php') + ); } else { @@ -2925,45 +3666,93 @@ class Get } // load the type values form type params - $field->properties = (isset($field->properties) && ComponentbuilderHelper::checkJson($field->properties)) ? json_decode($field->properties, true) : null; + $field->properties = (isset($field->properties) + && ComponentbuilderHelper::checkJson($field->properties)) + ? json_decode($field->properties, true) : null; if (ComponentbuilderHelper::checkArray($field->properties)) { $field->properties = array_values($field->properties); } // check if we have WHMCS encryption - if (4 == $field->store && (!isset($this->whmcsEncryption) || !$this->whmcsEncryption)) + if (4 == $field->store + && (!isset($this->whmcsEncryption) + || !$this->whmcsEncryption)) { $this->whmcsEncryption = true; } // check if we have basic encryption - elseif (3 == $field->store && (!isset($this->basicEncryption) || !$this->basicEncryption)) + elseif (3 == $field->store + && (!isset($this->basicEncryption) + || !$this->basicEncryption)) { $this->basicEncryption = true; } // check if we have better encryption - elseif (5 == $field->store && (!isset($this->mediumEncryption) || !$this->mediumEncryption)) + elseif (5 == $field->store + && (!isset($this->mediumEncryption) + || !$this->mediumEncryption)) { $this->mediumEncryption = true; } // check if we have better encryption elseif (6 == $field->store - && ComponentbuilderHelper::checkString($field->on_get_model_field) - && ComponentbuilderHelper::checkString($field->on_save_model_field)) + && ComponentbuilderHelper::checkString( + $field->on_get_model_field + ) + && ComponentbuilderHelper::checkString( + $field->on_save_model_field + )) { // add only if string lenght found - if (ComponentbuilderHelper::checkString($field->initiator_on_save_model)) + if (ComponentbuilderHelper::checkString( + $field->initiator_on_save_model + )) { - $field->initiator_save_key = md5($field->initiator_on_save_model); - $field->initiator_save = explode(PHP_EOL, $this->setPlaceholders($this->setDynamicValues(base64_decode($field->initiator_on_save_model)), $this->placeholders)); + $field->initiator_save_key = md5( + $field->initiator_on_save_model + ); + $field->initiator_save = explode( + PHP_EOL, $this->setPlaceholders( + $this->setDynamicValues( + base64_decode( + $field->initiator_on_save_model + ) + ), $this->placeholders + ) + ); } - if (ComponentbuilderHelper::checkString($field->initiator_on_save_model)) + if (ComponentbuilderHelper::checkString( + $field->initiator_on_save_model + )) { - $field->initiator_get_key = md5($field->initiator_on_get_model); - $field->initiator_get = explode(PHP_EOL, $this->setPlaceholders($this->setDynamicValues(base64_decode($field->initiator_on_get_model)), $this->placeholders)); + $field->initiator_get_key = md5( + $field->initiator_on_get_model + ); + $field->initiator_get = explode( + PHP_EOL, $this->setPlaceholders( + $this->setDynamicValues( + base64_decode( + $field->initiator_on_get_model + ) + ), $this->placeholders + ) + ); } // set the field modeling - $field->model_field['save'] = explode(PHP_EOL, $this->setPlaceholders($this->setDynamicValues(base64_decode($field->on_save_model_field)), $this->placeholders)); - $field->model_field['get'] = explode(PHP_EOL, $this->setPlaceholders($this->setDynamicValues(base64_decode($field->on_get_model_field)), $this->placeholders)); + $field->model_field['save'] = explode( + PHP_EOL, $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($field->on_save_model_field) + ), $this->placeholders + ) + ); + $field->model_field['get'] = explode( + PHP_EOL, $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($field->on_get_model_field) + ), $this->placeholders + ) + ); // remove the original values unset($field->on_save_model_field, $field->on_get_model_field, $field->initiator_on_save_model, $field->initiator_on_get_model); } @@ -2972,7 +3761,10 @@ class Get $field->history = $this->getHistoryWatch('field', $id); // Trigger Event: jcb_ce_onAfterModelFieldData - $this->triggerEvent('jcb_ce_onAfterModelFieldData', array(&$this->componentContext, &$field)); + $this->triggerEvent( + 'jcb_ce_onAfterModelFieldData', + array(&$this->componentContext, &$field) + ); $this->_fieldData[$id] = $field; } @@ -2985,10 +3777,14 @@ class Get if ($id > 0 && isset($this->_fieldData[$id])) { // check if we should load scripts for single view - if (ComponentbuilderHelper::checkString($name_single) && !isset($this->customFieldScript[$name_single][$id])) + if (ComponentbuilderHelper::checkString($name_single) + && !isset($this->customFieldScript[$name_single][$id])) { // add_javascript_view_footer - if ($this->_fieldData[$id]->add_javascript_view_footer == 1 && ComponentbuilderHelper::checkString($this->_fieldData[$id]->javascript_view_footer)) + if ($this->_fieldData[$id]->add_javascript_view_footer == 1 + && ComponentbuilderHelper::checkString( + $this->_fieldData[$id]->javascript_view_footer + )) { $convert__ = true; if (isset($this->_fieldData[$id]->javascript_view_footer_decoded) @@ -3002,10 +3798,10 @@ class Get $name_single, false, array( - 'table' => 'field', - 'id' => (int) $id, - 'field' => 'javascript_view_footer', - 'type' => 'js', + 'table' => 'field', + 'id' => (int) $id, + 'field' => 'javascript_view_footer', + 'type' => 'js', 'prefix' => PHP_EOL), $convert__, $convert__, @@ -3013,18 +3809,27 @@ class Get ); if (!isset($this->_fieldData[$id]->javascript_view_footer_decoded)) { - $this->_fieldData[$id]->javascript_view_footer_decoded = true; + $this->_fieldData[$id]->javascript_view_footer_decoded + = true; } - if (strpos($this->_fieldData[$id]->javascript_view_footer, "token") !== false || - strpos($this->_fieldData[$id]->javascript_view_footer, "task=ajax") !== false) + if (strpos( + $this->_fieldData[$id]->javascript_view_footer, + "token" + ) !== false + || strpos( + $this->_fieldData[$id]->javascript_view_footer, + "task=ajax" + ) !== false) { if (!isset($this->customScriptBuilder['token'])) { $this->customScriptBuilder['token'] = array(); } - if (!isset($this->customScriptBuilder['token'][$name_single]) || !$this->customScriptBuilder['token'][$name_single]) + if (!isset($this->customScriptBuilder['token'][$name_single]) + || !$this->customScriptBuilder['token'][$name_single]) { - $this->customScriptBuilder['token'][$name_single] = true; + $this->customScriptBuilder['token'][$name_single] + = true; } } } @@ -3057,10 +3862,14 @@ class Get $this->customFieldScript[$name_single][$id] = true; } // check if we should load scripts for list views - if (ComponentbuilderHelper::checkString($name_list) && !isset($this->customFieldScript[$name_list][$id])) + if (ComponentbuilderHelper::checkString($name_list) + && !isset($this->customFieldScript[$name_list][$id])) { // add_javascript_views_footer - if ($this->_fieldData[$id]->add_javascript_views_footer == 1 && ComponentbuilderHelper::checkString($this->_fieldData[$id]->javascript_views_footer)) + if ($this->_fieldData[$id]->add_javascript_views_footer == 1 + && ComponentbuilderHelper::checkString( + $this->_fieldData[$id]->javascript_views_footer + )) { $convert__ = true; if (isset($this->_fieldData[$id]->javascript_views_footer_decoded) @@ -3074,10 +3883,10 @@ class Get $name_single, false, array( - 'table' => 'field', - 'id' => (int) $id, - 'field' => 'javascript_views_footer', - 'type' => 'js', + 'table' => 'field', + 'id' => (int) $id, + 'field' => 'javascript_views_footer', + 'type' => 'js', 'prefix' => PHP_EOL), $convert__, $convert__, @@ -3085,18 +3894,27 @@ class Get ); if (!isset($this->_fieldData[$id]->javascript_views_footer_decoded)) { - $this->_fieldData[$id]->javascript_views_footer_decoded = true; + $this->_fieldData[$id]->javascript_views_footer_decoded + = true; } - if (strpos($this->_fieldData[$id]->javascript_views_footer, "token") !== false || - strpos($this->_fieldData[$id]->javascript_views_footer, "task=ajax") !== false) + if (strpos( + $this->_fieldData[$id]->javascript_views_footer, + "token" + ) !== false + || strpos( + $this->_fieldData[$id]->javascript_views_footer, + "task=ajax" + ) !== false) { if (!isset($this->customScriptBuilder['token'])) { $this->customScriptBuilder['token'] = array(); } - if (!isset($this->customScriptBuilder['token'][$name_list]) || !$this->customScriptBuilder['token'][$name_list]) + if (!isset($this->customScriptBuilder['token'][$name_list]) + || !$this->customScriptBuilder['token'][$name_list]) { - $this->customScriptBuilder['token'][$name_list] = true; + $this->customScriptBuilder['token'][$name_list] + = true; } } } @@ -3134,22 +3952,24 @@ class Get // return the found field data return $this->_fieldData[$id]; } + return false; } /** * set Field details - * - * @param object $field The field object - * @param string $singleViewName The single view name - * @param string $listViewName The list view name - * @param string $amicably The peaceful resolve - * + * + * @param object $field The field object + * @param string $singleViewName The single view name + * @param string $listViewName The list view name + * @param string $amicably The peaceful resolve + * * @return void - * + * */ - public function setFieldDetails(&$field, $singleViewName = null, $listViewName = null, $amicably = '') - { + public function setFieldDetails(&$field, $singleViewName = null, + $listViewName = null, $amicably = '' + ) { // set hash static $hash = 123467890; // load hash if not found @@ -3162,7 +3982,9 @@ class Get // set the settings if (!isset($field['settings'])) { - $field['settings'] = $this->getFieldData($field['field'], $singleViewName, $listViewName); + $field['settings'] = $this->getFieldData( + $field['field'], $singleViewName, $listViewName + ); } // set real field name if (!isset($field['base_name'])) @@ -3175,24 +3997,31 @@ class Get $field['type_name'] = $this->getFieldType($field); } // check if value is array - if (isset($field['permission']) && !ComponentbuilderHelper::checkArray($field['permission']) && is_numeric($field['permission']) && $field['permission'] > 0) + if (isset($field['permission']) + && !ComponentbuilderHelper::checkArray( + $field['permission'] + ) + && is_numeric($field['permission']) + && $field['permission'] > 0) { $field['permission'] = array($field['permission']); } // set unigue name keeper if ($listViewName) { - $this->setUniqueNameCounter($field['base_name'], $listViewName . $amicably); + $this->setUniqueNameCounter( + $field['base_name'], $listViewName . $amicably + ); } } /** * Get the field's actual type - * - * @param object $field The field object - * + * + * @param object $field The field object + * * @return string Success returns field type - * + * */ public function getFieldType(&$field) { @@ -3202,38 +4031,62 @@ class Get return $field['type_name']; } // check that we have the poperties - if (isset($field['settings']) && ComponentbuilderHelper::checkObject($field['settings']) && isset($field['settings']->properties) && ComponentbuilderHelper::checkArray($field['settings']->properties)) + if (isset($field['settings']) + && ComponentbuilderHelper::checkObject( + $field['settings'] + ) + && isset($field['settings']->properties) + && ComponentbuilderHelper::checkArray( + $field['settings']->properties + )) { // search for own custom fields if (strpos($field['settings']->type_name, '@') !== false) { // set own custom field $field['settings']->own_custom = $field['settings']->type_name; - $field['settings']->type_name = 'Custom'; + $field['settings']->type_name = 'Custom'; } // set the type name - $type_name = ComponentbuilderHelper::safeTypeName($field['settings']->type_name); + $type_name = ComponentbuilderHelper::safeTypeName( + $field['settings']->type_name + ); // if custom (we must use the xml value) - if (strtolower($type_name) === 'custom' || strtolower($type_name) === 'customuser') + if (strtolower($type_name) === 'custom' + || strtolower($type_name) === 'customuser') { - $type = ComponentbuilderHelper::safeTypeName(ComponentbuilderHelper::getBetween($field['settings']->xml, 'type="', '"')); + $type = ComponentbuilderHelper::safeTypeName( + ComponentbuilderHelper::getBetween( + $field['settings']->xml, 'type="', '"' + ) + ); } else { // loop over properties looking for the type value foreach ($field['settings']->properties as $property) { - if ($property['name'] === 'type') // type field is never ajustable (unless custom) + if ($property['name'] + === 'type') // type field is never ajustable (unless custom) { // force the default value - if (isset($property['example']) && ComponentbuilderHelper::checkString($property['example'])) + if (isset($property['example']) + && ComponentbuilderHelper::checkString( + $property['example'] + )) { - $type = ComponentbuilderHelper::safeTypeName($property['example']); + $type = ComponentbuilderHelper::safeTypeName( + $property['example'] + ); } // fall back on the xml settings (not ideal) else { - $type = ComponentbuilderHelper::safeTypeName(ComponentbuilderHelper::getBetween($field['settings']->xml, 'type="', '"')); + $type = ComponentbuilderHelper::safeTypeName( + ComponentbuilderHelper::getBetween( + $field['settings']->xml, 'type="', '"' + ) + ); } // exit foreach loop break; @@ -3251,34 +4104,44 @@ class Get return $type_name; } } + // fall back to text return 'text'; } /** * Get the field's actual name - * - * @param object $field The field object - * @param string $listViewName The list view name - * @param string $amicably The peaceful resolve (for fields in subforms in same view :) - * + * + * @param object $field The field object + * @param string $listViewName The list view name + * @param string $amicably The peaceful resolve (for fields in subforms in same view :) + * * @return string Success returns field name - * + * */ public function getFieldName(&$field, $listViewName = null, $amicably = '') { // return the unique name if already set - if (ComponentbuilderHelper::checkString($listViewName) && isset($field['hash']) && isset($this->uniqueFieldNames[$listViewName . $amicably . $field['hash']])) + if (ComponentbuilderHelper::checkString($listViewName) + && isset($field['hash']) + && isset( + $this->uniqueFieldNames[$listViewName . $amicably + . $field['hash']] + )) { - return $this->uniqueFieldNames[$listViewName . $amicably . $field['hash']]; + return $this->uniqueFieldNames[$listViewName . $amicably + . $field['hash']]; } // always make sure we have a field name and type - if (!isset($field['settings']) || !isset($field['settings']->type_name) || !isset($field['settings']->name)) + if (!isset($field['settings']) || !isset($field['settings']->type_name) + || !isset($field['settings']->name)) { return 'error'; } // set the type name - $type_name = ComponentbuilderHelper::safeTypeName($field['settings']->type_name); + $type_name = ComponentbuilderHelper::safeTypeName( + $field['settings']->type_name + ); // set the name of the field $name = ComponentbuilderHelper::safeFieldName($field['settings']->name); // check that we have the poperties @@ -3292,11 +4155,16 @@ class Get if ($type_name === 'category') { // quick check if this is a category linked to view page - $requeSt_id = ComponentbuilderHelper::getBetween($field['settings']->xml, 'name="', '"'); - if (strpos($requeSt_id, '_request_id') !== false || strpos($requeSt_id, '_request_catid') !== false) + $requeSt_id = ComponentbuilderHelper::getBetween( + $field['settings']->xml, 'name="', '"' + ); + if (strpos($requeSt_id, '_request_id') !== false + || strpos($requeSt_id, '_request_catid') !== false) { // keep it then, don't change - $name = $this->setPlaceholders($requeSt_id, $this->placeholders); + $name = $this->setPlaceholders( + $requeSt_id, $this->placeholders + ); } else { @@ -3306,17 +4174,41 @@ class Get if (ComponentbuilderHelper::checkString($listViewName)) { // check if we should use another Text Name as this views name - $otherName = $this->setPlaceholders(ComponentbuilderHelper::getBetween($field['settings']->xml, 'othername="', '"'), $this->placeholders); - $otherViews = $this->setPlaceholders(ComponentbuilderHelper::getBetween($field['settings']->xml, 'views="', '"'), $this->placeholders); - $otherView = $this->setPlaceholders(ComponentbuilderHelper::getBetween($field['settings']->xml, 'view="', '"'), $this->placeholders); + $otherName = $this->setPlaceholders( + ComponentbuilderHelper::getBetween( + $field['settings']->xml, 'othername="', '"' + ), $this->placeholders + ); + $otherViews = $this->setPlaceholders( + ComponentbuilderHelper::getBetween( + $field['settings']->xml, 'views="', '"' + ), $this->placeholders + ); + $otherView = $this->setPlaceholders( + ComponentbuilderHelper::getBetween( + $field['settings']->xml, 'view="', '"' + ), $this->placeholders + ); // This is to link other view category - if (ComponentbuilderHelper::checkString($otherName) && ComponentbuilderHelper::checkString($otherViews) && ComponentbuilderHelper::checkString($otherView)) + if (ComponentbuilderHelper::checkString($otherName) + && ComponentbuilderHelper::checkString( + $otherViews + ) + && ComponentbuilderHelper::checkString( + $otherView + )) { // set other category details $this->catOtherName[$listViewName] = array( - 'name' => ComponentbuilderHelper::safeFieldName($otherName), - 'views' => ComponentbuilderHelper::safeString($otherViews), - 'view' => ComponentbuilderHelper::safeString($otherView) + 'name' => ComponentbuilderHelper::safeFieldName( + $otherName + ), + 'views' => ComponentbuilderHelper::safeString( + $otherViews + ), + 'view' => ComponentbuilderHelper::safeString( + $otherView + ) ); } } @@ -3334,7 +4226,13 @@ class Get else { // get value from xml - $xml = ComponentbuilderHelper::safeFieldName($this->setPlaceholders(ComponentbuilderHelper::getBetween($field['settings']->xml, 'name="', '"'), $this->placeholders)); + $xml = ComponentbuilderHelper::safeFieldName( + $this->setPlaceholders( + ComponentbuilderHelper::getBetween( + $field['settings']->xml, 'name="', '"' + ), $this->placeholders + ) + ); // check if a value was found if (ComponentbuilderHelper::checkString($xml)) { @@ -3347,12 +4245,17 @@ class Get } } // return the value unique - if (ComponentbuilderHelper::checkString($listViewName) && isset($field['hash'])) + if (ComponentbuilderHelper::checkString($listViewName) + && isset($field['hash'])) { - $this->uniqueFieldNames[$listViewName . $amicably . $field['hash']] = $this->uniqueName($name, $listViewName . $amicably); + $this->uniqueFieldNames[$listViewName . $amicably . $field['hash']] + = $this->uniqueName($name, $listViewName . $amicably); + // now return the unique name - return $this->uniqueFieldNames[$listViewName . $amicably . $field['hash']]; + return $this->uniqueFieldNames[$listViewName . $amicably + . $field['hash']]; } + // fall back to global return $name; } @@ -3360,8 +4263,8 @@ class Get /** * Count how many times the same field is used per view * - * @param string $name The name of the field - * @param string $view The name of the view + * @param string $name The name of the field + * @param string $view The name of the view * * @return void * @@ -3370,25 +4273,27 @@ class Get { if (!isset($this->uniqueNames[$view])) { - $this->uniqueNames[$view] = array(); + $this->uniqueNames[$view] = array(); $this->uniqueNames[$view]['counter'] = array(); - $this->uniqueNames[$view]['names'] = array(); + $this->uniqueNames[$view]['names'] = array(); } if (!isset($this->uniqueNames[$view]['counter'][$name])) { $this->uniqueNames[$view]['counter'][$name] = 1; + return; } // count how many times the field is used - $this->uniqueNames[$view]['counter'][$name] ++; + $this->uniqueNames[$view]['counter'][$name]++; + return; } /** * Naming each field with an unique name * - * @param string $name The name of the field - * @param string $view The name of the view + * @param string $name The name of the field + * @param string $view The name of the view * * @return string the name * @@ -3396,35 +4301,42 @@ class Get protected function uniqueName($name, $view) { // only increment if the field name is used multiple times - if (isset($this->uniqueNames[$view]['counter'][$name]) && $this->uniqueNames[$view]['counter'][$name] > 1) + if (isset($this->uniqueNames[$view]['counter'][$name]) + && $this->uniqueNames[$view]['counter'][$name] > 1) { $counter = 1; // set the unique name - $uniqueName = ComponentbuilderHelper::safeFieldName($name . '_' . $counter); + $uniqueName = ComponentbuilderHelper::safeFieldName( + $name . '_' . $counter + ); while (isset($this->uniqueNames[$view]['names'][$uniqueName])) { // increment the number $counter++; // try again - $uniqueName = ComponentbuilderHelper::safeFieldName($name . '_' . $counter); + $uniqueName = ComponentbuilderHelper::safeFieldName( + $name . '_' . $counter + ); } // set the new name number $this->uniqueNames[$view]['names'][$uniqueName] = $counter; + // return the unique name return $uniqueName; } + return $name; } /** * Set get Data - * - * @param array $ids The ids of the dynamic get - * @param string $view_code The view code name - * @param string $context The context for events + * + * @param array $ids The ids of the dynamic get + * @param string $view_code The view code name + * @param string $context The context for events * * @return oject the get dynamicGet data - * + * */ public function setGetData($ids, $view_code, $context) { @@ -3442,54 +4354,80 @@ class Get $this->db->execute(); if ($this->db->getNumRows()) { - $results = $this->db->loadObjectList(); - $typeArray = array(1 => 'LEFT', 2 => 'LEFT OUTER', 3 => 'INNER', 4 => 'RIGHT', 5 => 'RIGHT OUTER'); - $operatorArray = array(1 => '=', 2 => '!=', 3 => '<>', 4 => '>', 5 => '<', 6 => '>=', 7 => '<=', 8 => '!<', 9 => '!>', 10 => 'IN', 11 => 'NOT IN'); - $guiMapper = array( 'table' => 'dynamic_get', 'type' => 'php'); + $results = $this->db->loadObjectList(); + $typeArray = array(1 => 'LEFT', 2 => 'LEFT OUTER', + 3 => 'INNER', 4 => 'RIGHT', + 5 => 'RIGHT OUTER'); + $operatorArray = array(1 => '=', 2 => '!=', 3 => '<>', + 4 => '>', 5 => '<', 6 => '>=', + 7 => '<=', 8 => '!<', 9 => '!>', + 10 => 'IN', 11 => 'NOT IN'); + $guiMapper = array('table' => 'dynamic_get', + 'type' => 'php'); foreach ($results as $_nr => &$result) { // set GUI mapper id $guiMapper['id'] = (int) $result->id; // add calculations if set - if ($result->addcalculation == 1 && ComponentbuilderHelper::checkString($result->php_calculation)) + if ($result->addcalculation == 1 + && ComponentbuilderHelper::checkString( + $result->php_calculation + )) { // set GUI mapper field $guiMapper['field'] = 'php_calculation'; - $result->php_calculation = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($result->php_calculation)), + $result->php_calculation + = $this->setGuiCodePlaceholder( + $this->setDynamicValues( + base64_decode($result->php_calculation) + ), $guiMapper - ); + ); } // setup the router parse if (isset($result->add_php_router_parse) && $result->add_php_router_parse == 1 && isset($result->php_router_parse) - && ComponentbuilderHelper::checkString($result->php_router_parse)) + && ComponentbuilderHelper::checkString( + $result->php_router_parse + )) { // set GUI mapper field $guiMapper['field'] = 'php_router_parse'; - $result->php_router_parse = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($result->php_router_parse)), + $result->php_router_parse + = $this->setGuiCodePlaceholder( + $this->setDynamicValues( + base64_decode($result->php_router_parse) + ), $guiMapper - ); + ); } else { $result->add_php_router_parse = 0; } // The array of the php scripts that should be added to the script builder - $phpSripts = array('php_before_getitem', 'php_after_getitem', 'php_before_getitems', 'php_after_getitems', 'php_getlistquery'); + $phpSripts = array('php_before_getitem', + 'php_after_getitem', + 'php_before_getitems', + 'php_after_getitems', + 'php_getlistquery'); // load the php scripts foreach ($phpSripts as $script) { // add php script to the script builder - if (isset($result->{'add_' . $script}) && $result->{'add_' . $script} == 1 && isset($result->{$script}) && ComponentbuilderHelper::checkString($result->{$script})) + if (isset($result->{'add_' . $script}) + && $result->{'add_' . $script} == 1 + && isset($result->{$script}) + && ComponentbuilderHelper::checkString( + $result->{$script} + )) { // move all main gets out to the customscript builder if ($result->gettype <= 2) { // set GUI mapper field - $guiMapper['field'] = $script; + $guiMapper['field'] = $script; $guiMapper['prefix'] = PHP_EOL . PHP_EOL; $this->setCustomScriptBuilder( $result->{$script}, @@ -3509,11 +4447,14 @@ class Get else { // set GUI mapper field - $guiMapper['field'] = $script; + $guiMapper['field'] = $script; $guiMapper['prefix'] = PHP_EOL; // only for custom gets - $result->{$script} = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($result->{$script})), + $result->{$script} + = $this->setGuiCodePlaceholder( + $this->setDynamicValues( + base64_decode($result->{$script}) + ), $guiMapper ); unset($guiMapper['prefix']); @@ -3527,9 +4468,11 @@ class Get } } // set the getmethod code name - $result->key = ComponentbuilderHelper::safeString($view_code . ' ' . $result->name . ' ' . $result->id); + $result->key = ComponentbuilderHelper::safeString( + $view_code . ' ' . $result->name . ' ' . $result->id + ); // reset buckets - $result->main_get = array(); + $result->main_get = array(); $result->custom_get = array(); // should joineds and other weaks be added $addDynamicTweaksJoints = true; @@ -3543,9 +4486,14 @@ class Get $result->view_selection = '*'; } // set the view data - $result->main_get[0]['selection'] = $this->setDataSelection($result->key, $view_code, $result->view_selection, $result->view_table_main, 'a', null, 'view'); - $result->main_get[0]['as'] = 'a'; - $result->main_get[0]['key'] = $result->key; + $result->main_get[0]['selection'] + = $this->setDataSelection( + $result->key, $view_code, + $result->view_selection, + $result->view_table_main, 'a', null, 'view' + ); + $result->main_get[0]['as'] = 'a'; + $result->main_get[0]['key'] = $result->key; $result->main_get[0]['context'] = $context; unset($result->view_selection); break; @@ -3556,9 +4504,14 @@ class Get $result->db_selection = '*'; } // set the database data - $result->main_get[0]['selection'] = $this->setDataSelection($result->key, $view_code, $result->db_selection, $result->db_table_main, 'a', null, 'db'); - $result->main_get[0]['as'] = 'a'; - $result->main_get[0]['key'] = $result->key; + $result->main_get[0]['selection'] + = $this->setDataSelection( + $result->key, $view_code, + $result->db_selection, + $result->db_table_main, 'a', null, 'db' + ); + $result->main_get[0]['as'] = 'a'; + $result->main_get[0]['key'] = $result->key; $result->main_get[0]['context'] = $context; unset($result->db_selection); break; @@ -3566,32 +4519,54 @@ class Get // set GUI mapper field $guiMapper['field'] = 'php_custom_get'; // get the custom query - $customQueryString = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($result->php_custom_get)), + $customQueryString + = $this->setGuiCodePlaceholder( + $this->setDynamicValues( + base64_decode($result->php_custom_get) + ), $guiMapper - ); + ); // get the table name - $_searchQuery = ComponentbuilderHelper::getBetween($customQueryString, '$query->from(', ')'); - if (ComponentbuilderHelper::checkString($_searchQuery) && strpos($_searchQuery, '#__') !== false) + $_searchQuery + = ComponentbuilderHelper::getBetween( + $customQueryString, '$query->from(', ')' + ); + if (ComponentbuilderHelper::checkString( + $_searchQuery + ) + && strpos($_searchQuery, '#__') !== false) { - $_queryName = ComponentbuilderHelper::getBetween($_searchQuery, '#__', "'"); - if (!ComponentbuilderHelper::checkString($_queryName)) + $_queryName + = ComponentbuilderHelper::getBetween( + $_searchQuery, '#__', "'" + ); + if (!ComponentbuilderHelper::checkString( + $_queryName + )) { - $_queryName = ComponentbuilderHelper::getBetween($_searchQuery, '#__', '"'); + $_queryName + = ComponentbuilderHelper::getBetween( + $_searchQuery, '#__', '"' + ); } } // set to blank if not found - if (!isset($_queryName) || !ComponentbuilderHelper::checkString($_queryName)) + if (!isset($_queryName) + || !ComponentbuilderHelper::checkString( + $_queryName + )) { $_queryName = ''; } // set custom script $result->main_get[0]['selection'] = array( 'select' => $customQueryString, - 'from' => '', 'table' => '', 'type' => '', 'name' => $_queryName); - $result->main_get[0]['as'] = 'a'; - $result->main_get[0]['key'] = $result->key; - $result->main_get[0]['context'] = $context; + 'from' => '', 'table' => '', 'type' => '', + 'name' => $_queryName); + $result->main_get[0]['as'] = 'a'; + $result->main_get[0]['key'] + = $result->key; + $result->main_get[0]['context'] = $context; // do not add $addDynamicTweaksJoints = false; break; @@ -3600,55 +4575,88 @@ class Get if ($addDynamicTweaksJoints) { // set join_view_table details - $result->join_view_table = json_decode($result->join_view_table, true); - if (ComponentbuilderHelper::checkArray($result->join_view_table)) + $result->join_view_table = json_decode( + $result->join_view_table, true + ); + if (ComponentbuilderHelper::checkArray( + $result->join_view_table + )) { // start the part of a table bucket $_part_of_a = array(); // build relationship - $_relationship = array_map(function($op) use(&$_part_of_a){ - $bucket = array(); - // array(on_field_as, on_field) - $bucket['on_field'] = array_map('trim', explode('.', $op['on_field'])); - // array(join_field_as, join_field) - $bucket['join_field'] = array_map('trim', explode('.', $op['join_field'])); - // triget filed that has table a relationship - if ($op['row_type'] == 1 && ($bucket['on_field'][0] === 'a' || - isset($_part_of_a[$bucket['on_field'][0]]) || - isset($_part_of_a[$bucket['join_field'][0]]))) - { - $_part_of_a[$op['as']] = $op['as']; - } - return $bucket; - }, $result->join_view_table); + $_relationship = array_map( + function ($op) use (&$_part_of_a) { + $bucket = array(); + // array(on_field_as, on_field) + $bucket['on_field'] = array_map( + 'trim', + explode('.', $op['on_field']) + ); + // array(join_field_as, join_field) + $bucket['join_field'] = array_map( + 'trim', + explode('.', $op['join_field']) + ); + // triget filed that has table a relationship + if ($op['row_type'] == 1 + && ($bucket['on_field'][0] === 'a' + || isset($_part_of_a[$bucket['on_field'][0]]) + || isset($_part_of_a[$bucket['join_field'][0]]))) + { + $_part_of_a[$op['as']] = $op['as']; + } + + return $bucket; + }, $result->join_view_table + ); // loop joints - foreach ($result->join_view_table as $nr => &$option) + foreach ( + $result->join_view_table as $nr => &$option + ) { - if (ComponentbuilderHelper::checkString($option['selection'])) + if (ComponentbuilderHelper::checkString( + $option['selection'] + )) { // convert the type - $option['type'] = $typeArray[$option['type']]; + $option['type'] + = $typeArray[$option['type']]; // convert the operator - $option['operator'] = $operatorArray[$option['operator']]; + $option['operator'] + = $operatorArray[$option['operator']]; // get the on field values - $on_field = $_relationship[$nr]['on_field']; + $on_field + = $_relationship[$nr]['on_field']; // get the join field values - $join_field = $_relationship[$nr]['join_field']; + $join_field + = $_relationship[$nr]['join_field']; // set selection - $option['selection'] = $this->setDataSelection($result->key, $view_code, $option['selection'], $option['view_table'], $option['as'], $option['row_type'], 'view'); - $option['key'] = $result->key; + $option['selection'] + = $this->setDataSelection( + $result->key, $view_code, + $option['selection'], + $option['view_table'], + $option['as'], $option['row_type'], + 'view' + ); + $option['key'] = $result->key; $option['context'] = $context; // load to the getters if ($option['row_type'] == 1) { $result->main_get[] = $option; - if ($on_field[0] === 'a' || isset($_part_of_a[$join_field[0]]) || isset($_part_of_a[$on_field[0]])) + if ($on_field[0] === 'a' + || isset($_part_of_a[$join_field[0]]) + || isset($_part_of_a[$on_field[0]])) { - $this->siteMainGet[$this->target][$view_code][$option['as']] = $option['as']; + $this->siteMainGet[$this->target][$view_code][$option['as']] + = $option['as']; } else { - $this->siteDynamicGet[$this->target][$view_code][$option['as']][$join_field[1]] = $on_field[0]; + $this->siteDynamicGet[$this->target][$view_code][$option['as']][$join_field[1]] + = $on_field[0]; } } elseif ($option['row_type'] == 2) @@ -3656,7 +4664,8 @@ class Get $result->custom_get[] = $option; if ($on_field[0] != 'a') { - $this->siteDynamicGet[$this->target][$view_code][$option['as']][$join_field[1]] = $on_field[0]; + $this->siteDynamicGet[$this->target][$view_code][$option['as']][$join_field[1]] + = $on_field[0]; } } } @@ -3665,56 +4674,89 @@ class Get } unset($result->join_view_table); // set join_db_table details - $result->join_db_table = json_decode($result->join_db_table, true); - if (ComponentbuilderHelper::checkArray($result->join_db_table)) + $result->join_db_table = json_decode( + $result->join_db_table, true + ); + if (ComponentbuilderHelper::checkArray( + $result->join_db_table + )) { // start the part of a table bucket $_part_of_a = array(); // build relationship - $_relationship = array_map(function($op) use(&$_part_of_a){ - $bucket = array(); - // array(on_field_as, on_field) - $bucket['on_field'] = array_map('trim', explode('.', $op['on_field'])); - // array(join_field_as, join_field) - $bucket['join_field'] = array_map('trim', explode('.', $op['join_field'])); - // triget filed that has table a relationship - if ($op['row_type'] == 1 && ($bucket['on_field'][0] === 'a' || - isset($_part_of_a[$bucket['on_field'][0]]) || - isset($_part_of_a[$bucket['join_field'][0]]))) - { - $_part_of_a[$op['as']] = $op['as']; - } - return $bucket; - }, $result->join_db_table); + $_relationship = array_map( + function ($op) use (&$_part_of_a) { + $bucket = array(); + // array(on_field_as, on_field) + $bucket['on_field'] = array_map( + 'trim', + explode('.', $op['on_field']) + ); + // array(join_field_as, join_field) + $bucket['join_field'] = array_map( + 'trim', + explode('.', $op['join_field']) + ); + // triget filed that has table a relationship + if ($op['row_type'] == 1 + && ($bucket['on_field'][0] === 'a' + || isset($_part_of_a[$bucket['on_field'][0]]) + || isset($_part_of_a[$bucket['join_field'][0]]))) + { + $_part_of_a[$op['as']] = $op['as']; + } + + return $bucket; + }, $result->join_db_table + ); // loop joints - foreach ($result->join_db_table as $nr => &$option1) + foreach ( + $result->join_db_table as $nr => &$option1 + ) { - if (ComponentbuilderHelper::checkString($option1['selection'])) + if (ComponentbuilderHelper::checkString( + $option1['selection'] + )) { // convert the type - $option1['type'] = $typeArray[$option1['type']]; + $option1['type'] + = $typeArray[$option1['type']]; // convert the operator - $option1['operator'] = $operatorArray[$option1['operator']]; + $option1['operator'] + = $operatorArray[$option1['operator']]; // get the on field values - $on_field = $_relationship[$nr]['on_field']; + $on_field + = $_relationship[$nr]['on_field']; // get the join field values - $join_field = $_relationship[$nr]['join_field']; + $join_field + = $_relationship[$nr]['join_field']; // set selection - $option1['selection'] = $this->setDataSelection($result->key, $view_code, $option1['selection'], $option1['db_table'], $option1['as'], $option1['row_type'], 'db'); - $option1['key'] = $result->key; + $option1['selection'] + = $this->setDataSelection( + $result->key, $view_code, + $option1['selection'], + $option1['db_table'], + $option1['as'], + $option1['row_type'], 'db' + ); + $option1['key'] = $result->key; $option1['context'] = $context; // load to the getters if ($option1['row_type'] == 1) { $result->main_get[] = $option1; - if ($on_field[0] === 'a' || isset($_part_of_a[$join_field[0]]) || isset($_part_of_a[$on_field[0]])) + if ($on_field[0] === 'a' + || isset($_part_of_a[$join_field[0]]) + || isset($_part_of_a[$on_field[0]])) { - $this->siteMainGet[$this->target][$view_code][$option1['as']] = $option1['as']; + $this->siteMainGet[$this->target][$view_code][$option1['as']] + = $option1['as']; } else { - $this->siteDynamicGet[$this->target][$view_code][$option1['as']][$join_field[1]] = $on_field[0]; + $this->siteDynamicGet[$this->target][$view_code][$option1['as']][$join_field[1]] + = $on_field[0]; } } elseif ($option1['row_type'] == 2) @@ -3722,7 +4764,8 @@ class Get $result->custom_get[] = $option1; if ($on_field[0] != 'a') { - $this->siteDynamicGet[$this->target][$view_code][$option1['as']][$join_field[1]] = $on_field[0]; + $this->siteDynamicGet[$this->target][$view_code][$option1['as']][$join_field[1]] + = $on_field[0]; } } } @@ -3731,15 +4774,25 @@ class Get } unset($result->join_db_table); // set filter details - $result->filter = json_decode($result->filter, true); - if (ComponentbuilderHelper::checkArray($result->filter)) + $result->filter = json_decode( + $result->filter, true + ); + if (ComponentbuilderHelper::checkArray( + $result->filter + )) { foreach ($result->filter as $nr => &$option2) { if (isset($option2['operator'])) { - $option2['operator'] = $operatorArray[$option2['operator']]; - $option2['state_key'] = $this->setPlaceholders($this->setDynamicValues($option2['state_key']), $this->placeholders); + $option2['operator'] + = $operatorArray[$option2['operator']]; + $option2['state_key'] + = $this->setPlaceholders( + $this->setDynamicValues( + $option2['state_key'] + ), $this->placeholders + ); $option2['key'] = $result->key; } else @@ -3750,13 +4803,16 @@ class Get } // set where details $result->where = json_decode($result->where, true); - if (ComponentbuilderHelper::checkArray($result->where)) + if (ComponentbuilderHelper::checkArray( + $result->where + )) { foreach ($result->where as $nr => &$option3) { if (isset($option3['operator'])) { - $option3['operator'] = $operatorArray[$option3['operator']]; + $option3['operator'] + = $operatorArray[$option3['operator']]; } else { @@ -3770,19 +4826,27 @@ class Get } // set order details $result->order = json_decode($result->order, true); - if (!ComponentbuilderHelper::checkArray($result->order)) + if (!ComponentbuilderHelper::checkArray( + $result->order + )) { unset($result->order); } // set grouping $result->group = json_decode($result->group, true); - if (!ComponentbuilderHelper::checkArray($result->group)) + if (!ComponentbuilderHelper::checkArray( + $result->group + )) { unset($result->group); } // set global details - $result->global = json_decode($result->global, true); - if (!ComponentbuilderHelper::checkArray($result->global)) + $result->global = json_decode( + $result->global, true + ); + if (!ComponentbuilderHelper::checkArray( + $result->global + )) { unset($result->global); } @@ -3799,70 +4863,85 @@ class Get unset($result->global); } // load the events if any is set - if ($result->gettype == 1 && ComponentbuilderHelper::checkJson($result->plugin_events)) + if ($result->gettype == 1 + && ComponentbuilderHelper::checkJson( + $result->plugin_events + )) { - $result->plugin_events = json_decode($result->plugin_events, true); + $result->plugin_events = json_decode( + $result->plugin_events, true + ); } else { $result->plugin_events = ''; } } + return $results; } } } + return false; } /** * set the script for the custom script builder * - * @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 + * @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 * */ - public function setCustomScriptBuilder(&$script, $first, $second = false, $third = false, $config = array(), $base64 = true, $dynamic = true, $add = false) - { + public function setCustomScriptBuilder(&$script, $first, $second = false, + $third = false, $config = array(), $base64 = true, $dynamic = true, + $add = false + ) { // only load if we have a string if (!ComponentbuilderHelper::checkString($script)) { return false; } // this needs refactoring (TODO) - if (!isset($this->customScriptBuilder[$first]) || ($second && !isset($this->customScriptBuilder[$first][$second]))) + 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])) + 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])) + if ($second && $third + && !isset($this->customScriptBuilder[$first][$second])) { $this->customScriptBuilder[$first][$second] = array(); } - elseif ($add && $second && !$third && !isset($this->customScriptBuilder[$first][$second])) + 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])) + if ($add && $second && $third + && !isset($this->customScriptBuilder[$first][$second][$third])) { $this->customScriptBuilder[$first][$second][$third] = ''; } @@ -3880,7 +4959,7 @@ class Get { $script = $this->setDynamicValues($script); } - // check if we still hava a string + // check if we still have a string if (ComponentbuilderHelper::checkString($script)) { // now load the placeholder snippet if needed @@ -3894,11 +4973,13 @@ class Get // now act on loading option if ($add) { - $this->customScriptBuilder[$first][$second][$third] .= $script; + $this->customScriptBuilder[$first][$second][$third] + .= $script; } else { - $this->customScriptBuilder[$first][$second][$third] = $script; + $this->customScriptBuilder[$first][$second][$third] + = $script; } } elseif ($first && $second) @@ -3925,18 +5006,20 @@ class Get $this->customScriptBuilder[$first] = $script; } } + return true; } + return false; } /** * To limit the SQL Demo date build in the views - * - * @param array $settings Tweaking array. + * + * @param array $settings Tweaking array. * * @return void - * + * */ public function setSqlTweaking($settings) { @@ -3950,14 +5033,16 @@ class Get // add sql (by option) if (2 == $setting['add_sql_options']) { - // rest always + // rest always $id_array = array(); // by id (first remove backups) $ids = $setting['ids']; // now get the ids if (strpos($ids, ',') !== false) { - $id_array = (array) array_map('trim', explode(',', $ids)); + $id_array = (array) array_map( + 'trim', explode(',', $ids) + ); } else { @@ -3969,13 +5054,19 @@ class Get { if (strpos($id, '=>') !== false) { - $id_range = (array) array_map('trim', explode('=>', $id)); + $id_range = (array) array_map( + 'trim', explode('=>', $id) + ); unset($id_array[$key]); // build range if (count((array) $id_range) == 2) { - $range = range($id_range[0], $id_range[1]); - $id_array_new = array_merge($id_array_new, $range); + $range = range( + $id_range[0], $id_range[1] + ); + $id_array_new = array_merge( + $id_array_new, $range + ); } } } @@ -3991,14 +5082,16 @@ class Get // sort sort($id_array, SORT_NUMERIC); // now set it to global - $this->sqlTweak[(int) $setting['adminview']]['where'] = implode(',', $id_array); + $this->sqlTweak[(int) $setting['adminview']]['where'] + = implode(',', $id_array); } } } else { // remove all sql dump options - $this->sqlTweak[(int) $setting['adminview']]['remove'] = true; + $this->sqlTweak[(int) $setting['adminview']]['remove'] + = true; } } } @@ -4006,20 +5099,22 @@ class Get /** * check if an update SQL is needed - * - * @param mix $old The old values - * @param mix $new The new values - * @param string $type The type of values - * @param int $key The id/key where values changed - * @param array $ignore The ids to ignore + * + * @param mix $old The old values + * @param mix $new The new values + * @param string $type The type of values + * @param int $key The id/key where values changed + * @param array $ignore The ids to ignore * * @return void - * + * */ - protected function setUpdateSQL($old, $new, $type, $key = null, $ignore = null) - { + protected function setUpdateSQL($old, $new, $type, $key = null, + $ignore = null + ) { // check if there were new items added - if (ComponentbuilderHelper::checkArray($new) && ComponentbuilderHelper::checkArray($old)) + if (ComponentbuilderHelper::checkArray($new) + && ComponentbuilderHelper::checkArray($old)) { // check if this is old repeatable field if (isset($new[$type])) @@ -4028,13 +5123,17 @@ class Get { $newItem = true; // check if this is an id to ignore - if (ComponentbuilderHelper::checkArray($ignore) && in_array($item, $ignore)) + if (ComponentbuilderHelper::checkArray($ignore) + && in_array( + $item, $ignore + )) { // don't add ignored ids $newItem = false; } // check if this is old repeatable field - elseif (isset($old[$type]) && ComponentbuilderHelper::checkArray($old[$type])) + elseif (isset($old[$type]) + && ComponentbuilderHelper::checkArray($old[$type])) { if (!in_array($item, $old[$type])) { @@ -4085,13 +5184,15 @@ class Get // search to see if this is a new value $newItem = true; // check if this is an id to ignore - if (ComponentbuilderHelper::checkArray($ignore) && in_array($item[$type], $ignore)) + if (ComponentbuilderHelper::checkArray($ignore) + && in_array($item[$type], $ignore)) { // don't add ignored ids $newItem = false; } // check if this is old repeatable field - elseif (isset($old[$type]) && ComponentbuilderHelper::checkArray($old[$type])) + elseif (isset($old[$type]) + && ComponentbuilderHelper::checkArray($old[$type])) { if (in_array($item[$type], $old[$type])) { @@ -4132,10 +5233,15 @@ class Get } } } - elseif ($key && ((ComponentbuilderHelper::checkString($new) && ComponentbuilderHelper::checkString($old)) || (is_numeric($new) && is_numeric($old))) && $new !== $old) + elseif ($key + && ((ComponentbuilderHelper::checkString($new) + && ComponentbuilderHelper::checkString($old)) + || (is_numeric($new) && is_numeric($old))) + && $new !== $old) { // the string changed, lets add to SQL update - if (!isset($this->updateSQL[$type]) || !ComponentbuilderHelper::checkArray($this->updateSQL[$type])) + if (!isset($this->updateSQL[$type]) + || !ComponentbuilderHelper::checkArray($this->updateSQL[$type])) { $this->updateSQL[$type] = array(); } @@ -4146,24 +5252,30 @@ class Get /** * Set the add sql - * - * @param string $type The type of values - * @param int $item The item id to add - * @param int $key The id/key where values changed - * + * + * @param string $type The type of values + * @param int $item The item id to add + * @param int $key The id/key where values changed + * * @return void */ protected function setAddSQL($type, $item, $key) { // we have a new item, lets add to SQL - if (!isset($this->addSQL[$type]) || !ComponentbuilderHelper::checkArray($this->addSQL[$type])) + if (!isset($this->addSQL[$type]) + || !ComponentbuilderHelper::checkArray( + $this->addSQL[$type] + )) { $this->addSQL[$type] = array(); } // add key if found if ($key) { - if (!isset($this->addSQL[$type][$key]) || !ComponentbuilderHelper::checkArray($this->addSQL[$type][$key])) + if (!isset($this->addSQL[$type][$key]) + || !ComponentbuilderHelper::checkArray( + $this->addSQL[$type][$key] + )) { $this->addSQL[$type][$key] = array(); } @@ -4174,7 +5286,9 @@ class Get // convert adminview id to name if ('adminview' === $type) { - $this->addSQL[$type][] = ComponentbuilderHelper::safeString($this->getAdminViewData($item)->name_single); + $this->addSQL[$type][] = ComponentbuilderHelper::safeString( + $this->getAdminViewData($item)->name_single + ); } else { @@ -4185,12 +5299,12 @@ class Get /** * Get Item History values - * - * @param string $type The type of item - * @param int $id The item ID + * + * @param string $type The type of item + * @param int $id The item ID * * @return oject The history - * + * */ protected function getHistoryWatch($type, $id) { @@ -4201,10 +5315,18 @@ class Get $query->select('h.*'); $query->from('#__ucm_history AS h'); - $query->where($this->db->quoteName('h.ucm_item_id') . ' = ' . (int) $id); + $query->where( + $this->db->quoteName('h.ucm_item_id') . ' = ' . (int) $id + ); // Join over the content type for the type id - $query->join('LEFT', '#__content_types AS ct ON ct.type_id = h.ucm_type_id'); - $query->where('ct.type_alias = ' . $this->db->quote('com_componentbuilder.' . $type)); + $query->join( + 'LEFT', '#__content_types AS ct ON ct.type_id = h.ucm_type_id' + ); + $query->where( + 'ct.type_alias = ' . $this->db->quote( + 'com_componentbuilder.' . $type + ) + ); $query->order('h.save_date DESC'); $this->db->setQuery($query, 0, 1); $this->db->execute(); @@ -4221,7 +5343,9 @@ class Get $query->select('h.*'); $query->from('#__ucm_history AS h'); - $query->where($this->db->quoteName('h.ucm_item_id') . ' = ' . (int) $id); + $query->where( + $this->db->quoteName('h.ucm_item_id') . ' = ' . (int) $id + ); $query->where('h.keep_forever = 1'); $query->where('h.version_note LIKE ' . $this->db->quote('%component%')); // make sure it does not return the active version @@ -4230,8 +5354,14 @@ class Get $query->where('h.version_id != ' . (int) $newActive->version_id); } // Join over the content type for the type id - $query->join('LEFT', '#__content_types AS ct ON ct.type_id = h.ucm_type_id'); - $query->where('ct.type_alias = ' . $this->db->quote('com_componentbuilder.' . $type)); + $query->join( + 'LEFT', '#__content_types AS ct ON ct.type_id = h.ucm_type_id' + ); + $query->where( + 'ct.type_alias = ' . $this->db->quote( + 'com_componentbuilder.' . $type + ) + ); $query->order('h.save_date DESC'); $this->db->setQuery($query); $this->db->execute(); @@ -4247,21 +5377,22 @@ class Get $this->setHistoryWatch($oldActive, 0); } } + // return the last used history record or null. return $this->tmpHistory; } /** * Set Item History Watch - * - * @param Object $object The history object - * @param int $action The action to take - * 0 = remove watch - * 1 = add watch - * @param string $type The type of item + * + * @param Object $object The history object + * @param int $action The action to take + * 0 = remove watch + * 1 = add watch + * @param string $type The type of item * * @return bool - * + * */ protected function setHistoryWatch($object, $action) { @@ -4279,11 +5410,14 @@ class Get { case 0: // remove watch - if (isset($version_note['component']) && ($key = array_search($this->componentID, $version_note['component'])) !== false) + if (isset($version_note['component']) + && ($key = array_search( + $this->componentID, $version_note['component'] + )) !== false) { // last version that was used to build/compile $this->tmpHistory = json_decode($object->version_data); - // remove it from this component + // remove it from this component unset($version_note['component'][$key]); } else @@ -4306,10 +5440,13 @@ class Get break; } // check if we need to still keep this locked - if (isset($version_note['component']) && ComponentbuilderHelper::checkArray($version_note['component'])) + if (isset($version_note['component']) + && ComponentbuilderHelper::checkArray($version_note['component'])) { // insure component ids are only added once per item - $version_note['component'] = array_unique($version_note['component']); + $version_note['component'] = array_unique( + $version_note['component'] + ); // we may change this, little risky (but since JCB does not have history notes it should be okay for now) $object->version_note = json_encode($version_note); $object->keep_forever = '1'; @@ -4319,27 +5456,33 @@ class Get $object->version_note = ''; $object->keep_forever = '0'; } + // run the update return $this->db->updateObject('#__ucm_history', $object, 'version_id'); } /** * Set Template and Layout Data - * - * @param string $default The content to check - * @param string $view The view code name + * + * @param string $default The content to check + * @param string $view The view code name * * @return void - * + * */ public function setTemplateAndLayoutData($default, $view) { // set the Tempale date - $temp1 = ComponentbuilderHelper::getAllBetween($default, "\$this->loadTemplate('", "')"); - $temp2 = ComponentbuilderHelper::getAllBetween($default, '$this->loadTemplate("', '")'); + $temp1 = ComponentbuilderHelper::getAllBetween( + $default, "\$this->loadTemplate('", "')" + ); + $temp2 = ComponentbuilderHelper::getAllBetween( + $default, '$this->loadTemplate("', '")' + ); $templates = array(); - $again = array(); - if (ComponentbuilderHelper::checkArray($temp1) && ComponentbuilderHelper::checkArray($temp2)) + $again = array(); + if (ComponentbuilderHelper::checkArray($temp1) + && ComponentbuilderHelper::checkArray($temp2)) { $templates = array_merge($temp1, $temp2); } @@ -4358,12 +5501,18 @@ class Get { foreach ($templates as $template) { - if (!isset($this->templateData[$this->target][$view]) || !array_key_exists($template, $this->templateData[$this->target][$view])) + if (!isset($this->templateData[$this->target][$view]) + || !array_key_exists( + $template, $this->templateData[$this->target][$view] + )) { - $data = $this->getDataWithAlias($template, 'template', $view); + $data = $this->getDataWithAlias( + $template, 'template', $view + ); if (ComponentbuilderHelper::checkArray($data)) { - $this->templateData[$this->target][$view][$template] = $data; + $this->templateData[$this->target][$view][$template] + = $data; // call self to get child data $again[] = array($data['html'], $view); $again[] = array($data['php_view'], $view); @@ -4372,10 +5521,14 @@ class Get } } // set the layout data - $lay1 = ComponentbuilderHelper::getAllBetween($default, "JLayoutHelper::render('", "',"); - $lay2 = ComponentbuilderHelper::getAllBetween($default, 'JLayoutHelper::render("', '",'); - ; - if (ComponentbuilderHelper::checkArray($lay1) && ComponentbuilderHelper::checkArray($lay2)) + $lay1 = ComponentbuilderHelper::getAllBetween( + $default, "JLayoutHelper::render('", "'," + ); + $lay2 = ComponentbuilderHelper::getAllBetween( + $default, 'JLayoutHelper::render("', '",' + );; + if (ComponentbuilderHelper::checkArray($lay1) + && ComponentbuilderHelper::checkArray($lay2)) { $layouts = array_merge($lay1, $lay2); } @@ -4394,7 +5547,13 @@ class Get { foreach ($layouts as $layout) { - if (!isset($this->layoutData[$this->target]) || !ComponentbuilderHelper::checkArray($this->layoutData[$this->target]) || !array_key_exists($layout, $this->layoutData[$this->target])) + if (!isset($this->layoutData[$this->target]) + || !ComponentbuilderHelper::checkArray( + $this->layoutData[$this->target] + ) + || !array_key_exists( + $layout, $this->layoutData[$this->target] + )) { $data = $this->getDataWithAlias($layout, 'layout', $view); if (ComponentbuilderHelper::checkArray($data)) @@ -4418,13 +5577,13 @@ class Get /** * Get Data With Alias - * - * @param string $n_ame The alias name - * @param string $table The table where to find the alias - * @param string $view The view code name + * + * @param string $n_ame The alias name + * @param string $table The table where to find the alias + * @param string $view The view code name * * @return array The data found with the alias - * + * */ public function getDataWithAlias($n_ame, $table, $view) { @@ -4437,30 +5596,31 @@ class Get foreach ($rows as $row) { $k_ey = ComponentbuilderHelper::safeString($row->alias); - $key = preg_replace("/[^A-Za-z]/", '', $k_ey); + $key = preg_replace("/[^A-Za-z]/", '', $k_ey); $name = preg_replace("/[^A-Za-z]/", '', $n_ame); if ($k_ey == $n_ame || $key == $name) { $php_view = ''; - if ($row->add_php_view == 1 && ComponentbuilderHelper::checkString($row->php_view)) + if ($row->add_php_view == 1 + && ComponentbuilderHelper::checkString($row->php_view)) { $php_view = $this->setGuiCodePlaceholder( $this->setDynamicValues(base64_decode($row->php_view)), array( 'table' => $table, 'field' => 'php_view', - 'id' => (int) $row->id, - 'type' => 'php') - ); + 'id' => (int) $row->id, + 'type' => 'php') + ); } $contnent = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($row->{$table})), - array( - 'table' => $table, - 'field' => $table, - 'id' => (int) $row->id, - 'type' => 'html') - ); + $this->setDynamicValues(base64_decode($row->{$table})), + array( + 'table' => $table, + 'field' => $table, + 'id' => (int) $row->id, + 'type' => 'html') + ); // load the library if (!isset($this->libManager[$this->target])) { @@ -4484,16 +5644,19 @@ class Get { if ($this->getMediaLibrary((int) $library)) { - $this->libManager[$this->target][$view][(int) $library] = true; + $this->libManager[$this->target][$view][(int) $library] + = true; } } } } - elseif (is_numeric($row->libraries) && !isset($this->libManager[$this->target][$view][(int) $row->libraries])) + elseif (is_numeric($row->libraries) + && !isset($this->libManager[$this->target][$view][(int) $row->libraries])) { if ($this->getMediaLibrary((int) $row->libraries)) { - $this->libManager[$this->target][$view][(int) $row->libraries] = true; + $this->libManager[$this->target][$view][(int) $row->libraries] + = true; } } // load UIKIT if needed @@ -4504,10 +5667,14 @@ class Get $this->uikitComp[$view] = array(); } // set uikit to views - $this->uikitComp[$view] = ComponentbuilderHelper::getUikitComp($contnent, $this->uikitComp[$view]); + $this->uikitComp[$view] + = ComponentbuilderHelper::getUikitComp( + $contnent, $this->uikitComp[$view] + ); } // set footable to views and turn it on - if (!isset($this->footableScripts[$this->target][$view]) || !$this->footableScripts[$this->target][$view]) + if (!isset($this->footableScripts[$this->target][$view]) + || !$this->footableScripts[$this->target][$view]) { $foundFoo = $this->getFootableScripts($contnent); if ($foundFoo) @@ -4520,7 +5687,8 @@ class Get } } // set google charts to views and turn it on - if (!isset($this->googleChart[$this->target][$view]) || !$this->googleChart[$this->target][$view]) + if (!isset($this->googleChart[$this->target][$view]) + || !$this->googleChart[$this->target][$view]) { $foundA = $this->getGoogleChart($php_view); $foundB = $this->getGoogleChart($contnent); @@ -4534,7 +5702,8 @@ class Get } } // check for get module - if (!isset($this->getModule[$this->target][$view]) || !$this->getModule[$this->target][$view]) + if (!isset($this->getModule[$this->target][$view]) + || !$this->getModule[$this->target][$view]) { $foundA = $this->getGetModule($php_view); $foundB = $this->getGetModule($contnent); @@ -4543,39 +5712,41 @@ class Get $this->getModule[$this->target][$view] = true; } } + return array( - 'id' => $row->id, - 'html' => $this->setGuiCodePlaceholder( + 'id' => $row->id, + 'html' => $this->setGuiCodePlaceholder( $contnent, array( 'table' => $table, 'field' => $table, - 'id' => $row->id, - 'type' => 'html' - ) - ), + 'id' => $row->id, + 'type' => 'html' + ) + ), 'php_view' => $this->setGuiCodePlaceholder( $php_view, array( 'table' => $table, 'field' => 'php_view', - 'id' => $row->id, - 'type' => 'php' - ) + 'id' => $row->id, + 'type' => 'php' ) - ); + ) + ); } } + return false; } /** * Get Media Library Data and store globally - * - * @param string $id the library id + * + * @param string $id the library id * * @return bool true on success - * + * */ protected function getMediaLibrary($id) { @@ -4604,7 +5775,8 @@ class Get } break; case 5: // FooTable v2 - if (!isset($this->footableVersion) || 2 == $this->footableVersion) + if (!isset($this->footableVersion) + || 2 == $this->footableVersion) { // already being loaded $this->libraries[$id] = false; @@ -4628,38 +5800,48 @@ class Get $query->select( $this->db->quoteName( array( - 'a.id', - 'a.name', - 'a.how', - 'a.type', - 'a.addconditions', - 'b.addconfig', - 'c.addfiles', - 'c.addfolders', - 'c.addfilesfullpath', - 'c.addfoldersfullpath', - 'c.addurls', - 'a.php_setdocument' + 'a.id', + 'a.name', + 'a.how', + 'a.type', + 'a.addconditions', + 'b.addconfig', + 'c.addfiles', + 'c.addfolders', + 'c.addfilesfullpath', + 'c.addfoldersfullpath', + 'c.addurls', + 'a.php_setdocument' ), array( - 'id', - 'name', - 'how', - 'type', - 'addconditions', - 'addconfig', - 'addfiles', - 'addfolders', - 'addfilesfullpath', - 'addfoldersfullpath', - 'addurls', - 'php_setdocument' + 'id', + 'name', + 'how', + 'type', + 'addconditions', + 'addconfig', + 'addfiles', + 'addfolders', + 'addfilesfullpath', + 'addfoldersfullpath', + 'addurls', + 'php_setdocument' ) ) ); // from these tables $query->from('#__componentbuilder_library AS a'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_library_config', 'b') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('b.library') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_library_files_folders_urls', 'c') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('c.library') . ')'); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_library_config', 'b') + . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('b.library') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_library_files_folders_urls', 'c' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('c.library') . ')' + ); $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); $query->where($this->db->quoteName('a.target') . ' = 1'); @@ -4673,8 +5855,16 @@ class Get if ($library->how == 4) { // fall back on build-in features - $buildin = array(3 => array('uikit' => 3), 4 => array('uikit' => 1), 5 => array('footableVersion' => 2, 'footable' => true), 6 => array('footableVersion' => 3, 'footable' => true)); - if (isset($buildin[$library->id]) && ComponentbuilderHelper::checkArray($buildin[$library->id])) + $buildin = array(3 => array('uikit' => 3), + 4 => array('uikit' => 1), + 5 => array('footableVersion' => 2, + 'footable' => true), + 6 => array('footableVersion' => 3, + 'footable' => true)); + if (isset($buildin[$library->id]) + && ComponentbuilderHelper::checkArray( + $buildin[$library->id] + )) { // set the lib switch foreach ($buildin[$library->id] as $lib => $val) @@ -4694,14 +5884,29 @@ class Get if ($library->how > 0) { // set the add targets - $addArray = array('files' => 'files', 'folders' => 'folders', 'urls' => 'urls', 'filesfullpath' => 'files', 'foldersfullpath' => 'folders'); + $addArray = array('files' => 'files', + 'folders' => 'folders', + 'urls' => 'urls', + 'filesfullpath' => 'files', + 'foldersfullpath' => 'folders'); foreach ($addArray as $addTarget => $targetHere) { // set the add target data - $library->{'add' . $addTarget} = (isset($library->{'add' . $addTarget}) && ComponentbuilderHelper::checkJson($library->{'add' . $addTarget})) ? json_decode($library->{'add' . $addTarget}, true) : null; - if (ComponentbuilderHelper::checkArray($library->{'add' . $addTarget})) + $library->{'add' . $addTarget} = (isset( + $library->{'add' . $addTarget} + ) + && ComponentbuilderHelper::checkJson( + $library->{'add' . $addTarget} + )) ? json_decode($library->{'add' . $addTarget}, true) + : null; + if (ComponentbuilderHelper::checkArray( + $library->{'add' . $addTarget} + )) { - if (isset($library->{$targetHere}) && ComponentbuilderHelper::checkArray($library->{$targetHere})) + if (isset($library->{$targetHere}) + && ComponentbuilderHelper::checkArray( + $library->{$targetHere} + )) { foreach ($library->{'add' . $addTarget} as $taget) { @@ -4710,7 +5915,9 @@ class Get } else { - $library->{$targetHere} = array_values($library->{'add' . $addTarget}); + $library->{$targetHere} = array_values( + $library->{'add' . $addTarget} + ); } } unset($library->{'add' . $addTarget}); @@ -4719,42 +5926,61 @@ class Get if ($library->how > 1) { // set the config data - $library->addconfig = (isset($library->addconfig) && ComponentbuilderHelper::checkJson($library->addconfig)) ? json_decode($library->addconfig, true) : null; + $library->addconfig = (isset($library->addconfig) + && ComponentbuilderHelper::checkJson( + $library->addconfig + )) ? json_decode($library->addconfig, true) : null; if (ComponentbuilderHelper::checkArray($library->addconfig)) { - $library->config = array_map(function($array) - { - $array['alias'] = 0; - $array['title'] = 0; - $array['settings'] = $this->getFieldData($array['field']); - return $array; - }, array_values($library->addconfig)); + $library->config = array_map( + function ($array) { + $array['alias'] = 0; + $array['title'] = 0; + $array['settings'] = $this->getFieldData( + $array['field'] + ); + + return $array; + }, array_values($library->addconfig) + ); } } // if this lib is controlled by custom script if (3 == $library->how) { // set Needed PHP - if (isset($library->php_setdocument) && ComponentbuilderHelper::checkString($library->php_setdocument)) + if (isset($library->php_setdocument) + && ComponentbuilderHelper::checkString( + $library->php_setdocument + )) { $library->document = $this->setGuiCodePlaceholder( - $this->setDynamicValues(base64_decode($library->php_setdocument)), + $this->setDynamicValues( + base64_decode($library->php_setdocument) + ), array( 'table' => 'library', 'field' => 'php_setdocument', - 'id' => (int) $id, - 'type' => 'php') - ); + 'id' => (int) $id, + 'type' => 'php') + ); } } // if this lib is controlled by conditions elseif (2 == $library->how) { // set the addconditions data - $library->addconditions = (isset($library->addconditions) && ComponentbuilderHelper::checkJson($library->addconditions)) ? json_decode($library->addconditions, true) : null; - if (ComponentbuilderHelper::checkArray($library->addconditions)) + $library->addconditions = (isset($library->addconditions) + && ComponentbuilderHelper::checkJson( + $library->addconditions + )) ? json_decode($library->addconditions, true) : null; + if (ComponentbuilderHelper::checkArray( + $library->addconditions + )) { - $library->conditions = array_values($library->addconditions); + $library->conditions = array_values( + $library->addconditions + ); } } unset($library->php_setdocument); @@ -4773,13 +5999,14 @@ class Get { return $this->libraries[$id]; } + return false; } /** * Set Language Place Holders * - * @param string $content The content + * @param string $content The content * * @return string The content with the updated Language place holder * @@ -4788,14 +6015,15 @@ class Get { // get targets to search for $langStringTargets = array_filter( - $this->langStringTargets, function($get) use($content) - { + $this->langStringTargets, function ($get) use ($content) { if (strpos($content, $get) !== false) { return true; } + return false; - }); + } + ); // check if we should continue if (ComponentbuilderHelper::checkArray($langStringTargets)) { @@ -4803,45 +6031,63 @@ class Get $content = $this->setPlaceholders($content, $this->placeholders); // reset some buckets $langHolders = array(); - $langCheck = array(); - $langOnly = array(); - $jsTEXT = array(); - $scTEXT = array(); + $langCheck = array(); + $langOnly = array(); + $jsTEXT = array(); + $scTEXT = array(); // first get the Joomla .JText._() if (in_array('Joomla' . '.JText._(', $langStringTargets)) { - $jsTEXT[] = ComponentbuilderHelper::getAllBetween($content, "Joomla" . ".JText._('", "'"); - $jsTEXT[] = ComponentbuilderHelper::getAllBetween($content, 'Joomla' . '.JText._("', '"'); + $jsTEXT[] = ComponentbuilderHelper::getAllBetween( + $content, "Joomla" . ".JText._('", "'" + ); + $jsTEXT[] = ComponentbuilderHelper::getAllBetween( + $content, 'Joomla' . '.JText._("', '"' + ); // combine into one array $jsTEXT = ComponentbuilderHelper::mergeArrays($jsTEXT); // we need to add a check to insure these JavaScript lang matchup - if (ComponentbuilderHelper::checkArray($jsTEXT)) //<-- not really needed hmmm + if (ComponentbuilderHelper::checkArray( + $jsTEXT + )) //<-- not really needed hmmm { // load the JS text to mismatch array - $langCheck[] = $jsTEXT; - $this->langMismatch = ComponentbuilderHelper::mergeArrays(array($jsTEXT, $this->langMismatch)); + $langCheck[] = $jsTEXT; + $this->langMismatch = ComponentbuilderHelper::mergeArrays( + array($jsTEXT, $this->langMismatch) + ); } } // now get the JText: :script() if (in_array('JText:' . ':script(', $langStringTargets)) { - $scTEXT[] = ComponentbuilderHelper::getAllBetween($content, "JText:" . ":script('", "'"); - $scTEXT[] = ComponentbuilderHelper::getAllBetween($content, 'JText:' . ':script("', '"'); + $scTEXT[] = ComponentbuilderHelper::getAllBetween( + $content, "JText:" . ":script('", "'" + ); + $scTEXT[] = ComponentbuilderHelper::getAllBetween( + $content, 'JText:' . ':script("', '"' + ); // combine into one array $scTEXT = ComponentbuilderHelper::mergeArrays($scTEXT); // we need to add a check to insure these JavaScript lang matchup if (ComponentbuilderHelper::checkArray($scTEXT)) { // load the Script text to match array - $langCheck[] = $scTEXT; - $this->langMatch = ComponentbuilderHelper::mergeArrays(array($scTEXT, $this->langMatch)); + $langCheck[] = $scTEXT; + $this->langMatch = ComponentbuilderHelper::mergeArrays( + array($scTEXT, $this->langMatch) + ); } } // now do the little trick for JustTEXT: :_('Just uppercase text'); if (in_array('JustTEXT:' . ':_(', $langStringTargets)) { - $langOnly[] = ComponentbuilderHelper::getAllBetween($content, "JustTEXT:" . ":_('", "')"); - $langOnly[] = ComponentbuilderHelper::getAllBetween($content, 'JustTEXT:' . ':_("', '")'); + $langOnly[] = ComponentbuilderHelper::getAllBetween( + $content, "JustTEXT:" . ":_('", "')" + ); + $langOnly[] = ComponentbuilderHelper::getAllBetween( + $content, 'JustTEXT:' . ':_("', '")' + ); // merge lang only $langOnly = ComponentbuilderHelper::mergeArrays($langOnly); } @@ -4849,18 +6095,24 @@ class Get foreach ($langStringTargets as $langStringTarget) { // need some special treatment here - if ($langStringTarget === 'Joomla' . '.JText._(' || - $langStringTarget === 'JText:' . ':script(' || - $langStringTarget === 'JustTEXT:' . ':_(') + if ($langStringTarget === 'Joomla' . '.JText._(' + || $langStringTarget === 'JText:' . ':script(' + || $langStringTarget === 'JustTEXT:' . ':_(') { continue; } - $langCheck[] = ComponentbuilderHelper::getAllBetween($content, $langStringTarget . "'", "'"); - $langCheck[] = ComponentbuilderHelper::getAllBetween($content, $langStringTarget . '"', '"'); + $langCheck[] = ComponentbuilderHelper::getAllBetween( + $content, $langStringTarget . "'", "'" + ); + $langCheck[] = ComponentbuilderHelper::getAllBetween( + $content, $langStringTarget . '"', '"' + ); } // the normal loading of the language strings $langCheck = ComponentbuilderHelper::mergeArrays($langCheck); - if (ComponentbuilderHelper::checkArray($langCheck)) //<-- not really needed hmmm + if (ComponentbuilderHelper::checkArray( + $langCheck + )) //<-- not really needed hmmm { foreach ($langCheck as $string) { @@ -4874,8 +6126,12 @@ class Get { continue; } - $langHolders[$langStringTarget . "'" . $string . "'"] = $langStringTarget . "'" . $keyLang . "'"; - $langHolders[$langStringTarget . '"' . $string . '"'] = $langStringTarget . '"' . $keyLang . '"'; + $langHolders[$langStringTarget . "'" . $string + . "'"] + = $langStringTarget . "'" . $keyLang . "'"; + $langHolders[$langStringTarget . '"' . $string + . '"'] + = $langStringTarget . '"' . $keyLang . '"'; } } } @@ -4888,8 +6144,10 @@ class Get if ($keyLang = $this->setLang($string)) { // load the language targets - $langHolders["JustTEXT:" . ":_('" . $string . "')"] = "'" . $keyLang . "'"; - $langHolders['JustTEXT:' . ':_("' . $string . '")'] = '"' . $keyLang . '"'; + $langHolders["JustTEXT:" . ":_('" . $string . "')"] + = "'" . $keyLang . "'"; + $langHolders['JustTEXT:' . ':_("' . $string . '")'] + = '"' . $keyLang . '"'; } } } @@ -4899,16 +6157,17 @@ class Get $content = $this->setPlaceholders($content, $langHolders); } } + return $content; } /** * Set the language String - * - * @param string $string The plan text string (English) + * + * @param string $string The plan text string (English) * * @return string The key language string (all uppercase) - * + * */ public function setLang($string) { @@ -4918,7 +6177,9 @@ class Get return false; } // build lang key - $keyLang = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($string, 'U'); + $keyLang = $this->langPrefix . '_' . ComponentbuilderHelper::safeString( + $string, 'U' + ); // set the language string $this->setLangContent($this->lang, $keyLang, $string); @@ -4927,32 +6188,33 @@ class Get /** * Set Data Selection of the dynamic get - * - * @param string $method_key The method unique key - * @param string $view_code The code name of the view - * @param string $string The data string - * @param string $asset The asset in question - * @param string $as The as string - * @param int $row_type The row type - * @param string $type The target type (db||view) + * + * @param string $method_key The method unique key + * @param string $view_code The code name of the view + * @param string $string The data string + * @param string $asset The asset in question + * @param string $as The as string + * @param int $row_type The row type + * @param string $type The target type (db||view) * * @return array the select query - * + * */ - public function setDataSelection($method_key, $view_code, $string, $asset, $as, $row_type, $type) - { + public function setDataSelection($method_key, $view_code, $string, $asset, + $as, $row_type, $type + ) { if (ComponentbuilderHelper::checkString($string)) { if ('db' === $type) { - $table = '#__' . $asset; + $table = '#__' . $asset; $queryName = $asset; - $view = ''; + $view = ''; } elseif ('view' === $type) { - $view = $this->getViewTableName($asset); - $table = '#__' . $this->componentCodeName . '_' . $view; + $view = $this->getViewTableName($asset); + $table = '#__' . $this->componentCodeName . '_' . $view; $queryName = $view; } // just get all values from table if * is found @@ -4960,11 +6222,15 @@ class Get { if ($type == 'view') { - $_string = ComponentbuilderHelper::getViewTableColumns($asset, $as, $row_type); + $_string = ComponentbuilderHelper::getViewTableColumns( + $asset, $as, $row_type + ); } else { - $_string = ComponentbuilderHelper::getDbTableColumns($asset, $as, $row_type); + $_string = ComponentbuilderHelper::getDbTableColumns( + $asset, $as, $row_type + ); } // get only selected values $lines = explode(PHP_EOL, $_string); @@ -5000,7 +6266,11 @@ class Get $get = trim($lineArray[0]); $key = trim($lineArray[1]); // only add the view (we must adapt this) - if (isset($this->getAsLookup[$method_key][$get]) && 'a' != $as && 1 == $row_type && 'view' === $type && strpos('#' . $key, '#' . $view . '_') === false) + if (isset($this->getAsLookup[$method_key][$get]) + && 'a' != $as + && 1 == $row_type + && 'view' === $type + && strpos('#' . $key, '#' . $view . '_') === false) { // this is a problem (TODO) since we may want to not add the view name. $key = $view . '_' . trim($key); @@ -5012,13 +6282,21 @@ class Get if (ComponentbuilderHelper::checkString($key)) { $this->getAsLookup[$method_key][$get] = $key; - $keys[] = $this->db->quote($key); + $keys[] + = $this->db->quote( + $key + ); } else { - $key = str_replace($as . '.', '', $get); + $key = str_replace( + $as . '.', '', $get + ); $this->getAsLookup[$method_key][$get] = $key; - $keys[] = $this->db->quote($key); + $keys[] + = $this->db->quote( + $key + ); } // make sure we have the view name if (ComponentbuilderHelper::checkString($view)) @@ -5031,11 +6309,15 @@ class Get $this->siteFields[$view][$field] = array(); } // load to the site fields memory bucket - $this->siteFields[$view][$field][$method_key . '___' . $as] = array('site' => $view_code, 'get' => $get, 'as' => $as, 'key' => $key); + $this->siteFields[$view][$field][$method_key . '___' + . $as] + = array('site' => $view_code, 'get' => $get, + 'as' => $as, 'key' => $key); } } } - if (ComponentbuilderHelper::checkArray($gets) && ComponentbuilderHelper::checkArray($keys)) + if (ComponentbuilderHelper::checkArray($gets) + && ComponentbuilderHelper::checkArray($keys)) { // single joined selection needs the prefix to the values to avoid conflict in the names // so we must still add then AS @@ -5045,50 +6327,66 @@ class Get } else { - $querySelect = '$query->select($db->quoteName(' . PHP_EOL . $this->_t(3) . 'array(' . implode(',', $gets) . '),' . PHP_EOL . $this->_t(3) . 'array(' . implode(',', $keys) . ')));'; + $querySelect = '$query->select($db->quoteName(' + . PHP_EOL . $this->_t(3) . 'array(' . implode( + ',', $gets + ) . '),' . PHP_EOL . $this->_t(3) . 'array(' + . implode(',', $keys) . ')));'; } - $queryFrom = '$db->quoteName(' . $this->db->quote($table) . ', ' . $this->db->quote($as) . ')'; + $queryFrom = '$db->quoteName(' . $this->db->quote($table) + . ', ' . $this->db->quote($as) . ')'; + // return the select query - return array('select' => $querySelect, 'from' => $queryFrom, 'name' => $queryName, 'table' => $table, 'type' => $type, 'select_gets' => $gets, 'select_keys' => $keys); + return array('select' => $querySelect, + 'from' => $queryFrom, + 'name' => $queryName, 'table' => $table, + 'type' => $type, 'select_gets' => $gets, + 'select_keys' => $keys); } } } + return false; } /** * Get the View Table Name - * - * @param int $id The admin view in + * + * @param int $id The admin view in * * @return string view code name - * + * */ public function getViewTableName($id) { // Create a new query object. $query = $this->db->getQuery(true); $query->select($this->db->quoteName(array('a.name_single'))); - $query->from($this->db->quoteName('#__componentbuilder_admin_view', 'a')); + $query->from( + $this->db->quoteName('#__componentbuilder_admin_view', 'a') + ); $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); $this->db->setQuery($query); + return ComponentbuilderHelper::safeString($this->db->loadResult()); } /** * Build the SQL dump String for a view - * - * @param string $tables The tables to use in build - * @param string $view The target view/table to dump in - * @param int $view_id The id of the target view + * + * @param string $tables The tables to use in build + * @param string $view The target view/table to dump in + * @param int $view_id The id of the target view * * @return string on success with the Dump SQL - * + * */ public function buildSqlDump($tables, $view, $view_id) { // first build a query statment to get all the data (insure it must be added - check the tweaking) - if (ComponentbuilderHelper::checkArray($tables) && (!isset($this->sqlTweak[$view_id]['remove']) || !$this->sqlTweak[$view_id]['remove'])) + if (ComponentbuilderHelper::checkArray($tables) + && (!isset($this->sqlTweak[$view_id]['remove']) + || !$this->sqlTweak[$view_id]['remove'])) { $counter = 'a'; // Create a new query object. @@ -5114,23 +6412,42 @@ class Get { if (strpos($field, "=>") !== false) { - list($source, $target) = explode("=>", $field); - $sourceArray[] = $counter . '.' . trim($source); + list($source, $target) = explode( + "=>", $field + ); + $sourceArray[] = $counter . '.' . trim( + $source + ); $targetArray[] = trim($target); } } - if (ComponentbuilderHelper::checkArray($sourceArray) && ComponentbuilderHelper::checkArray($targetArray)) + if (ComponentbuilderHelper::checkArray( + $sourceArray + ) + && ComponentbuilderHelper::checkArray( + $targetArray + )) { // add to query - $query->select($this->db->quoteName($sourceArray, $targetArray)); - $query->from('#__' . $table['table'] . ' AS a'); + $query->select( + $this->db->quoteName( + $sourceArray, $targetArray + ) + ); + $query->from( + '#__' . $table['table'] . ' AS a' + ); $runQuery = true; } // we may need to filter the selection if (isset($this->sqlTweak[$view_id]['where'])) { // add to query the where filter - $query->where('a.id IN (' . $this->sqlTweak[$view_id]['where'] . ')'); + $query->where( + 'a.id IN (' + . $this->sqlTweak[$view_id]['where'] + . ')' + ); } } } @@ -5150,21 +6467,45 @@ class Get { if (strpos($field, "=>") !== false) { - list($source, $target) = explode("=>", $field); - $sourceArray[] = $counter . '.' . trim($source); + list($source, $target) = explode( + "=>", $field + ); + $sourceArray[] = $counter . '.' . trim( + $source + ); $targetArray[] = trim($target); } if (strpos($field, "==") !== false) { - list($aKey, $bKey) = explode("==", $field); + list($aKey, $bKey) = explode( + "==", $field + ); // add to query - $query->join('LEFT', $this->db->quoteName('#__' . $table['table'], $counter) . ' ON (' . $this->db->quoteName('a.' . trim($aKey)) . ' = ' . $this->db->quoteName($counter . '.' . trim($bKey)) . ')'); + $query->join( + 'LEFT', $this->db->quoteName( + '#__' . $table['table'], + $counter + ) . ' ON (' . $this->db->quoteName( + 'a.' . trim($aKey) + ) . ' = ' . $this->db->quoteName( + $counter . '.' . trim($bKey) + ) . ')' + ); } } - if (ComponentbuilderHelper::checkArray($sourceArray) && ComponentbuilderHelper::checkArray($targetArray)) + if (ComponentbuilderHelper::checkArray( + $sourceArray + ) + && ComponentbuilderHelper::checkArray( + $targetArray + )) { // add to query - $query->select($this->db->quoteName($sourceArray, $targetArray)); + $query->select( + $this->db->quoteName( + $sourceArray, $targetArray + ) + ); } } } @@ -5190,9 +6531,12 @@ class Get $data = $this->db->loadObjectList(); // start building the MySql dump $dump = "--"; - $dump .= PHP_EOL . "-- Dumping data for table `#__" . $this->bbb . "component" . $this->ddd . "_" . $view . "`"; + $dump .= PHP_EOL . "-- Dumping data for table `#__" + . $this->bbb . "component" . $this->ddd . "_" . $view + . "`"; $dump .= PHP_EOL . "--"; - $dump .= PHP_EOL . PHP_EOL . "INSERT INTO `#__" . $this->bbb . "component" . $this->ddd . "_" . $view . "` ("; + $dump .= PHP_EOL . PHP_EOL . "INSERT INTO `#__" . $this->bbb + . "component" . $this->ddd . "_" . $view . "` ("; foreach ($data as $line) { $comaSet = 0; @@ -5204,7 +6548,9 @@ class Get } else { - $dump .= ", " . $this->db->quoteName($fieldName); + $dump .= ", " . $this->db->quoteName( + $fieldName + ); } $comaSet++; } @@ -5231,7 +6577,9 @@ class Get } else { - $dump .= ", " . $this->mysql_escape($fieldValue); + $dump .= ", " . $this->mysql_escape( + $fieldValue + ); } $comaSet++; } @@ -5239,21 +6587,23 @@ class Get $coma++; } $dump .= ";"; + // return build dump query return $dump; } } } + return false; } /** * Escape the values for a SQL dump - * - * @param string $value the value to escape + * + * @param string $value the value to escape * * @return string on success with escaped string - * + * */ public function mysql_escape($value) { @@ -5272,52 +6622,60 @@ class Get { return "''"; } + // if not array or string then return number return $value; } /** * Creating an uniqueCode - * - * @param string $code The planed code + * + * @param string $code The planed code * * @return string The unique code - * + * */ public function uniqueCode($code) { - if (!isset($this->uniquecodes[$this->target]) || !in_array($code, $this->uniquecodes[$this->target])) + if (!isset($this->uniquecodes[$this->target]) + || !in_array( + $code, $this->uniquecodes[$this->target] + )) { $this->uniquecodes[$this->target][] = $code; + return $code; } + // make sure it is unique return $this->uniqueCode($code . $this->uniquekey(1)); } /** * Creating an unique local key - * - * @param int $size The key size + * + * @param int $size The key size * * @return string The unique localkey - * + * */ - public function uniquekey($size, $random = false, $newBag = "vvvvvvvvvvvvvvvvvvv") - { + public function uniquekey($size, $random = false, + $newBag = "vvvvvvvvvvvvvvvvvvv" + ) { if ($random) { - $bag = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ"; + $bag + = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ"; } else { $bag = $newBag; } - $key = array(); + $key = array(); $bagsize = strlen($bag) - 1; for ($i = 0; $i < $size; $i++) { - $get = rand(0, $bagsize); + $get = rand(0, $bagsize); $key[] = $bag[$get]; } $key = implode($key); @@ -5326,16 +6684,17 @@ class Get $key++; } $this->uniquekeys[] = $key; + return $key; } /** * Check for footable scripts - * - * @param string $content The content to check + * + * @param string $content The content to check * * @return boolean True if found - * + * */ public function getFootableScripts($content) { @@ -5343,16 +6702,17 @@ class Get { return true; } + return false; } /** * Check for getModules script - * - * @param string $content The content to check + * + * @param string $content The content to check * * @return boolean True if found - * + * */ public function getGetModule($content) { @@ -5360,16 +6720,17 @@ class Get { return true; } + return false; } /** * Check for get Google Chart script - * - * @param string $content The content to check + * + * @param string $content The content to check * * @return boolean True if found - * + * */ public function getGoogleChart($content) { @@ -5377,42 +6738,48 @@ class Get { return true; } + return false; } /** * Set the dynamic values in strings here - * - * @param string $string The content to check - * @param int $debug The switch to debug the update - * We can now at any time debug the - * dynamic build values if it gets broken + * + * @param string $string The content to check + * @param int $debug The switch to debug the update + * We can now at any time debug the + * dynamic build values if it gets broken * * @return string - * + * */ public function setDynamicValues($string, $debug = 0) { if (ComponentbuilderHelper::checkString($string)) { - $string = $this->setLangStrings($this->setCustomCodeData($this->setExternalCodeString($string, $debug), $debug)); + $string = $this->setLangStrings( + $this->setCustomCodeData( + $this->setExternalCodeString($string, $debug), $debug + ) + ); } // if debug if ($debug) { jexit(); } + return $string; } /** * Set the external code string & load it in to string - * - * @param string $string The content to check - * @param int $debug The switch to debug the update + * + * @param string $string The content to check + * @param int $debug The switch to debug the update * * @return string - * + * */ public function setExternalCodeString($string, $debug = 0) { @@ -5427,17 +6794,24 @@ class Get } // target content $bucket = array(); - $found = ComponentbuilderHelper::getAllBetween($string, '[EXTERNA' . 'LCODE=', ']'); + $found = ComponentbuilderHelper::getAllBetween( + $string, '[EXTERNA' . 'LCODE=', ']' + ); if (ComponentbuilderHelper::checkArray($found)) { // build local bucket foreach ($found as $target) { // check if user has permission to use EXTERNAL code (we may add a custom access switch - use ADMIN for now) - if ($this->user->authorise('core.admin', 'com_componentbuilder')) + if ($this->user->authorise( + 'core.admin', 'com_componentbuilder' + )) { // check if the target is valid URL or path - if ((!filter_var($target, FILTER_VALIDATE_URL) === false && ComponentbuilderHelper::urlExists($target)) || (JPath::clean($target) === $target && JFile::exists($target))) + if ((!filter_var($target, FILTER_VALIDATE_URL) === false + && ComponentbuilderHelper::urlExists($target)) + || (JPath::clean($target) === $target + && JFile::exists($target))) { $this->getExternalCodeString($target, $bucket); } @@ -5447,8 +6821,17 @@ class Get // set key $key = '[EXTERNA' . 'LCODE=' . $target . ']'; // set the notice - $this->app->enqueueMessage(JText::_('

External Code Warning

'), 'Warning'); - $this->app->enqueueMessage(JText::sprintf('The %s is not a valid url/path!', $key), 'Warning'); + $this->app->enqueueMessage( + JText::_( + '

External Code Warning

' + ), 'Warning' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The %s is not a valid url/path!', + $key + ), 'Warning' + ); // remove the placeholder $bucket[$key] = ''; } @@ -5458,8 +6841,16 @@ class Get // set key $key = '[EXTERNA' . 'LCODE=' . $target . ']'; // set the notice - $this->app->enqueueMessage(JText::_('

External Code Error

'), 'Error'); - $this->app->enqueueMessage(JText::sprintf('%s, you do not have permission to use EXTERNALCODE feature (so %s was removed from the compilation), please contact you system administrator for more info!
(admin access required)', $this->user->get('name'), $key), 'Error'); + $this->app->enqueueMessage( + JText::_('

External Code Error

'), + 'Error' + ); + $this->app->enqueueMessage( + JText::sprintf( + '%s, you do not have permission to use EXTERNALCODE feature (so %s was removed from the compilation), please contact you system administrator for more info!
(admin access required)', + $this->user->get('name'), $key + ), 'Error' + ); // remove the placeholder $bucket[$key] = ''; } @@ -5477,17 +6868,18 @@ class Get var_dump($string); } } + return $string; } /** * Get the External Code/String - * - * @param string $string The content to check - * @param array $bucket The Placeholders bucket + * + * @param string $string The content to check + * @param array $bucket The Placeholders bucket * * @return void - * + * */ protected function getExternalCodeString($target, &$bucket) { @@ -5499,46 +6891,78 @@ class Get if (!isset($this->externalCodeString[$targetKey])) { // get the data string (code) - $this->externalCodeString[$targetKey] = ComponentbuilderHelper::getFileContents($targetKey); + $this->externalCodeString[$targetKey] + = ComponentbuilderHelper::getFileContents($targetKey); // did we get any value - if (ComponentbuilderHelper::checkString($this->externalCodeString[$targetKey])) + if (ComponentbuilderHelper::checkString( + $this->externalCodeString[$targetKey] + )) { // check for changes $liveHash = md5($this->externalCodeString[$targetKey]); // check if it exist local - if ($hash = ComponentbuilderHelper::getVar('external_code', $targetKey, 'target', 'hash')) + if ($hash = ComponentbuilderHelper::getVar( + 'external_code', $targetKey, 'target', 'hash' + )) { if ($hash !== $liveHash) { // update the hash since it changed - $object = new stdClass(); + $object = new stdClass(); $object->target = $targetKey; - $object->hash = $liveHash; + $object->hash = $liveHash; // update local hash - $this->db->updateObject('#__componentbuilder_external_code', $object, 'target'); + $this->db->updateObject( + '#__componentbuilder_external_code', $object, + 'target' + ); // give notice of the change - $this->app->enqueueMessage(JText::_('

External Code Warning

'), 'Warning'); - $this->app->enqueueMessage(JText::sprintf('The code/string from %s has been changed since the last compilation, please investigate to insure the changes are safe!', $key), 'Warning'); + $this->app->enqueueMessage( + JText::_('

External Code Warning

'), + 'Warning' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The code/string from %s has been changed since the last compilation, please investigate to insure the changes are safe!', + $key + ), 'Warning' + ); } } else { // add the hash to track changes - $object = new stdClass(); + $object = new stdClass(); $object->target = $targetKey; - $object->hash = $liveHash; + $object->hash = $liveHash; // insert local hash - $this->db->insertObject('#__componentbuilder_external_code', $object); + $this->db->insertObject( + '#__componentbuilder_external_code', $object + ); // give notice the first time this is added - $this->app->enqueueMessage(JText::_('

External Code Notice

'), 'Notice'); - $this->app->enqueueMessage(JText::sprintf('The code/string from %s has been added for the first time, please investigate to insure the correct code/string was used!', $key), 'Notice'); + $this->app->enqueueMessage( + JText::_('

External Code Notice

'), + 'Notice' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The code/string from %s has been added for the first time, please investigate to insure the correct code/string was used!', + $key + ), 'Notice' + ); } } else { // set notice that we could not get a valid string from the target - $this->app->enqueueMessage(JText::_('

External Code Warning

'), 'Warning'); - $this->app->enqueueMessage(JText::sprintf('The %s returned an invalid string!', $key), 'Warning'); + $this->app->enqueueMessage( + JText::_('

External Code Warning

'), 'Warning' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The %s returned an invalid string!', $key + ), 'Warning' + ); } } // add to local bucket @@ -5550,12 +6974,12 @@ class Get /** * We start set the custom code data & can load it in to string - * - * @param string $string The content to check - * @param int $debug The switch to debug the update + * + * @param string $string The content to check + * @param int $debug The switch to debug the update * * @return string - * + * */ public function setCustomCodeData($string, $debug = 0, $not = null) { @@ -5572,7 +6996,9 @@ class Get } // the ids found in this content $bucket = array(); - $found = ComponentbuilderHelper::getAllBetween($string, '[CUSTO' . 'MCODE=', ']'); + $found = ComponentbuilderHelper::getAllBetween( + $string, '[CUSTO' . 'MCODE=', ']' + ); if (ComponentbuilderHelper::checkArray($found)) { foreach ($found as $key) @@ -5588,20 +7014,30 @@ class Get { $id = (int) $key; } - elseif (ComponentbuilderHelper::checkString($key) && strpos($key, '+') === false) + elseif (ComponentbuilderHelper::checkString($key) + && strpos( + $key, '+' + ) === false) { $getFuncName = trim($key); if (!isset($this->functionNameMemory[$getFuncName])) { - if (!$found_local = ComponentbuilderHelper::getVar('custom_code', $getFuncName, 'function_name', 'id')) + if (!$found_local = ComponentbuilderHelper::getVar( + 'custom_code', $getFuncName, 'function_name', + 'id' + )) { continue; } - $this->functionNameMemory[$getFuncName] = $found_local; + $this->functionNameMemory[$getFuncName] + = $found_local; } $id = (int) $this->functionNameMemory[$getFuncName]; } - elseif (ComponentbuilderHelper::checkString($key) && strpos($key, '+') !== false) + elseif (ComponentbuilderHelper::checkString($key) + && strpos( + $key, '+' + ) !== false) { $array = explode('+', $key); // set ID @@ -5614,11 +7050,16 @@ class Get $getFuncName = trim($array[0]); if (!isset($this->functionNameMemory[$getFuncName])) { - if (!$found_local = ComponentbuilderHelper::getVar('custom_code', $getFuncName, 'function_name', 'id')) + if (!$found_local + = ComponentbuilderHelper::getVar( + 'custom_code', $getFuncName, + 'function_name', 'id' + )) { continue; } - $this->functionNameMemory[$getFuncName] = $found_local; + $this->functionNameMemory[$getFuncName] + = $found_local; } $id = (int) $this->functionNameMemory[$getFuncName]; } @@ -5639,15 +7080,28 @@ class Get if (strpos($array[1], ',') !== false) { // update the function values with the custom code key placholdres (this allow the use of [] + and , in the values) - $this->customCodeData[$id]['args'][$key] = array_map(function($_key) { - return $this->setPlaceholders($_key, $this->customCodeKeyPlacholders); - }, (array) explode(',', $array[1])); + $this->customCodeData[$id]['args'][$key] + = array_map( + function ($_key) { + return $this->setPlaceholders( + $_key, + $this->customCodeKeyPlacholders + ); + }, (array) explode(',', $array[1]) + ); } - elseif (ComponentbuilderHelper::checkString($array[1])) + elseif (ComponentbuilderHelper::checkString( + $array[1] + )) { - $this->customCodeData[$id]['args'][$key] = array(); + $this->customCodeData[$id]['args'][$key] + = array(); // update the function values with the custom code key placholdres (this allow the use of [] + and , in the values) - $this->customCodeData[$id]['args'][$key][] = $this->setPlaceholders($array[1], $this->customCodeKeyPlacholders); + $this->customCodeData[$id]['args'][$key][] + = $this->setPlaceholders( + $array[1], + $this->customCodeKeyPlacholders + ); } } } @@ -5699,17 +7153,18 @@ class Get var_dump($string); } } + return $string; } /** * Insert the custom code into the string - * - * @param string $string The content to check - * @param int $debug The switch to debug the update + * + * @param string $string The content to check + * @param int $debug The switch to debug the update * * @return string on success - * + * */ protected function insertCustomCode($ids, $string, $debug = 0) { @@ -5717,7 +7172,9 @@ class Get // load the code foreach ($ids as $id) { - $this->buildCustomCodePlaceholders($this->customCodeMemory[$id], $code, $debug); + $this->buildCustomCodePlaceholders( + $this->customCodeMemory[$id], $code, $debug + ); } // if debug if ($debug) @@ -5727,23 +7184,27 @@ class Get echo 'Custom Code String Before Update:'; var_dump($string); } + // now update the string return $this->setPlaceholders($string, $code); } /** * Insert the custom code into the string - * - * @param string $string The content to check - * @param int $debug The switch to debug the update + * + * @param string $string The content to check + * @param int $debug The switch to debug the update * * @return string on success - * + * */ protected function buildCustomCodePlaceholders($item, &$code, $debug = 0) { // check if there is args for this code - if (isset($this->customCodeData[$item['id']]['args']) && ComponentbuilderHelper::checkArray($this->customCodeData[$item['id']]['args'])) + if (isset($this->customCodeData[$item['id']]['args']) + && ComponentbuilderHelper::checkArray( + $this->customCodeData[$item['id']]['args'] + )) { // since we have args we cant update this code via IDE (TODO) $placeholder = $this->getPlaceHolder(3, null); @@ -5754,7 +7215,9 @@ class Get var_dump($placeholder); } // we have args and so need to load each - foreach ($this->customCodeData[$item['id']]['args'] as $key => $args) + foreach ( + $this->customCodeData[$item['id']]['args'] as $key => $args + ) { $this->setThesePlaceHolders('arg', $args); // if debug @@ -5763,20 +7226,27 @@ class Get echo 'Custom Code Global Placholders:'; var_dump($this->placeholders); } - $code['[CUSTOM' . 'CODE=' . $key . ']'] = $placeholder['start'] . PHP_EOL . $this->setPlaceholders($item['code'], $this->placeholders) . $placeholder['end']; + $code['[CUSTOM' . 'CODE=' . $key . ']'] = $placeholder['start'] + . PHP_EOL . $this->setPlaceholders( + $item['code'], $this->placeholders + ) . $placeholder['end']; } // always clear the args $this->clearFromPlaceHolders('arg'); } else { - if (($keyPlaceholder = array_search($item['id'], $this->functionNameMemory)) === false) + if (($keyPlaceholder = array_search( + $item['id'], $this->functionNameMemory + )) === false) { $keyPlaceholder = $item['id']; } // check what type of place holders we should load here $placeholderType = (int) $item['comment_type'] . '2'; - if (stripos($item['code'], $this->bbb . 'view') !== false || stripos($item['code'], $this->bbb . 'sview') !== false || stripos($item['code'], $this->bbb . 'arg') !== false) + if (stripos($item['code'], $this->bbb . 'view') !== false + || stripos($item['code'], $this->bbb . 'sview') !== false + || stripos($item['code'], $this->bbb . 'arg') !== false) { // if view is being set dynamicly then we can't update this code via IDE (TODO) $placeholderType = 3; @@ -5784,16 +7254,22 @@ class Get // if now ars were found, clear it $this->clearFromPlaceHolders('arg'); // load args for this code - $placeholder = $this->getPlaceHolder($placeholderType, $item['id']); - $code['[CUSTOM' . 'CODE=' . $keyPlaceholder . ']'] = $placeholder['start'] . PHP_EOL . $this->setPlaceholders($item['code'], $this->placeholders) . $placeholder['end']; + $placeholder = $this->getPlaceHolder( + $placeholderType, $item['id'] + ); + $code['[CUSTOM' . 'CODE=' . $keyPlaceholder . ']'] + = $placeholder['start'] . PHP_EOL + . $this->setPlaceholders( + $item['code'], $this->placeholders + ) . $placeholder['end']; } } /** * Set a type of placeholder with set of values - * - * @param string $key The main string for placeholder key - * @param array $values The values to add + * + * @param string $key The main string for placeholder key + * @param array $values The values to add * * @return void */ @@ -5806,7 +7282,8 @@ class Get $number = 0; foreach ($values as $value) { - $this->placeholders[$this->bbb . $key . $number . $this->ddd] = $value; + $this->placeholders[$this->bbb . $key . $number . $this->ddd] + = $value; $number++; } } @@ -5814,8 +7291,8 @@ class Get /** * Remove a type of placeholder by main string - * - * @param string $like The main string for placeholder key + * + * @param string $like The main string for placeholder key * * @return void */ @@ -5832,7 +7309,7 @@ class Get /** * to unset stuff that are private or protected - * + * */ public function unsetNow($remove) { @@ -5841,25 +7318,39 @@ class Get /** * Get the other languages - * - * @param array $values The lang strings to get - * + * + * @param array $values The lang strings to get + * * * @return void - * + * */ public function getMultiLangStrings($values) { // Create a new query object. $query = $this->db->getQuery(true); - $query->from($this->db->quoteName('#__componentbuilder_language_translation', 'a')); + $query->from( + $this->db->quoteName( + '#__componentbuilder_language_translation', 'a' + ) + ); if (ComponentbuilderHelper::checkArray($values)) { - $query->select($this->db->quoteName(array('a.id', 'a.translation', 'a.source', 'a.components', 'a.published'))); - $query->where($this->db->quoteName('a.source') . ' IN (' . implode(',', array_map(function($a) - { - return $this->db->quote($a); - }, $values)) . ')'); + $query->select( + $this->db->quoteName( + array('a.id', 'a.translation', 'a.source', 'a.components', + 'a.modules', 'a.plugins', 'a.published') + ) + ); + $query->where( + $this->db->quoteName('a.source') . ' IN (' . implode( + ',', array_map( + function ($a) { + return $this->db->quote($a); + }, $values + ) + ) . ')' + ); $this->db->setQuery($query); $this->db->execute(); if ($this->db->getNumRows()) @@ -5867,53 +7358,74 @@ class Get return $this->db->loadAssocList('source'); } } + return false; } /** * Set the Current language values to DB - * + * * * @return void - * + * */ - public function setLangPlaceholders($strings) - { + public function setLangPlaceholders($strings, int $target_id, + $target = 'components' + ) { $counterInsert = 0; $counterUpdate = 0; - $today = JFactory::getDate()->toSql(); - foreach ($this->languages[$this->langTag] as $area => $placeholders) + $today = JFactory::getDate()->toSql(); + foreach ( + $this->languages[$target][$this->langTag] as $area => $placeholders + ) { foreach ($placeholders as $placeholder => $string) { // to keep or remove $remove = false; - // build the tranlations - if (ComponentbuilderHelper::checkString($string) && isset($this->multiLangString[$string])) + // build the translations + if (ComponentbuilderHelper::checkString($string) + && isset($this->multiLangString[$string])) { // make sure we have converted the string to array - if (isset($this->multiLangString[$string]['translation']) && ComponentbuilderHelper::checkJson($this->multiLangString[$string]['translation'])) + if (isset($this->multiLangString[$string]['translation']) + && ComponentbuilderHelper::checkJson( + $this->multiLangString[$string]['translation'] + )) { - $this->multiLangString[$string]['translation'] = json_decode($this->multiLangString[$string]['translation'], true); + $this->multiLangString[$string]['translation'] + = json_decode( + $this->multiLangString[$string]['translation'], true + ); } // if we have an array continue - if (isset($this->multiLangString[$string]['translation']) && ComponentbuilderHelper::checkArray($this->multiLangString[$string]['translation'])) + if (isset($this->multiLangString[$string]['translation']) + && ComponentbuilderHelper::checkArray( + $this->multiLangString[$string]['translation'] + )) { // great lets build the multi languages strings - foreach ($this->multiLangString[$string]['translation'] as $translations) + foreach ( + $this->multiLangString[$string]['translation'] as + $translations + ) { - if (isset($translations['language']) && isset($translations['translation'])) + if (isset($translations['language']) + && isset($translations['translation'])) { // build arrays - if (!isset($this->languages[$translations['language']])) + if (!isset($this->languages[$target][$translations['language']])) { - $this->languages[$translations['language']] = array(); + $this->languages[$target][$translations['language']] + = array(); } - if (!isset($this->languages[$translations['language']][$area])) + if (!isset($this->languages[$target][$translations['language']][$area])) { - $this->languages[$translations['language']][$area] = array(); + $this->languages[$target][$translations['language']][$area] + = array(); } - $this->languages[$translations['language']][$area][$placeholder] = $translations['translation']; + $this->languages[$target][$translations['language']][$area][$placeholder] + = $translations['translation']; } } } @@ -5923,40 +7435,48 @@ class Get $remove = true; } } - // do the database managment - if (ComponentbuilderHelper::checkString($string) && ($key = array_search($string, $strings)) !== false) + // do the database management + if (ComponentbuilderHelper::checkString($string) + && ($key = array_search($string, $strings)) !== false) { if (isset($this->multiLangString[$string])) { // update the existing placeholder in db $id = $this->multiLangString[$string]['id']; - if (ComponentbuilderHelper::checkJson($this->multiLangString[$string]['components'])) + if (ComponentbuilderHelper::checkJson( + $this->multiLangString[$string][$target] + )) { - $components = (array) json_decode($this->multiLangString[$string]['components'], true); - // check if we should add the component ID - if (in_array($this->componentID, $components)) + $targets = (array) json_decode( + $this->multiLangString[$string][$target], true + ); + // check if we should add the target ID + if (in_array($target_id, $targets)) { - // only skip the update if the string is published and has the component ID - if ($this->multiLangString[$string]['published'] == 1) + // only skip the update if the string is published and has the target ID + if ($this->multiLangString[$string]['published'] + == 1) { continue; } } else { - $components[] = $this->componentID; + $targets[] = $target_id; } } else { - $components = array($this->componentID); + $targets = array($target_id); } // start the bucket for this lang - $this->setUpdateExistingLangStrings($id, $components, 1, $today, $counterUpdate); + $this->setUpdateExistingLangStrings( + $id, $target, $targets, 1, $today, $counterUpdate + ); $counterUpdate++; - // load to db + // load to db $this->setExistingLangStrings(50); // remove string if needed if ($remove) @@ -5967,19 +7487,45 @@ class Get else { // add the new lang placeholder to the db - $this->newLangStrings[$counterInsert] = array(); - $this->newLangStrings[$counterInsert][] = $this->db->quote(json_encode(array($this->componentID))); // 'components' - $this->newLangStrings[$counterInsert][] = $this->db->quote($string); // 'source' - $this->newLangStrings[$counterInsert][] = $this->db->quote(1); // 'published' - $this->newLangStrings[$counterInsert][] = $this->db->quote($today); // 'created' - $this->newLangStrings[$counterInsert][] = $this->db->quote((int) $this->user->id); // 'created_by' - $this->newLangStrings[$counterInsert][] = $this->db->quote(1); // 'version' - $this->newLangStrings[$counterInsert][] = $this->db->quote(1); // 'access' + if (!isset($this->newLangStrings[$target])) + { + $this->newLangStrings[$target] = array(); + } + $this->newLangStrings[$target][$counterInsert] + = array(); + $this->newLangStrings[$target][$counterInsert][] + = $this->db->quote( + json_encode(array($target_id)) + ); // 'target' + $this->newLangStrings[$target][$counterInsert][] + = $this->db->quote( + $string + ); // 'source' + $this->newLangStrings[$target][$counterInsert][] + = $this->db->quote( + 1 + ); // 'published' + $this->newLangStrings[$target][$counterInsert][] + = $this->db->quote( + $today + ); // 'created' + $this->newLangStrings[$target][$counterInsert][] + = $this->db->quote( + (int) $this->user->id + ); // 'created_by' + $this->newLangStrings[$target][$counterInsert][] + = $this->db->quote( + 1 + ); // 'version' + $this->newLangStrings[$target][$counterInsert][] + = $this->db->quote( + 1 + ); // 'access' $counterInsert++; - // load to db - $this->setNewLangStrings(100); + // load to db + $this->setNewLangStrings($target, 100); } // only set the string once unset($strings[$key]); @@ -5988,30 +7534,37 @@ class Get } // just to make sure all is done $this->setExistingLangStrings(); - $this->setNewLangStrings(); + $this->setNewLangStrings($target); } /** * store the language placeholders - * - * @param int $when To set when to update + * + * @param string $target The target extention type + * @param int $when To set when to update * * @return void - * + * */ - protected function setNewLangStrings($when = 1) + protected function setNewLangStrings($target, $when = 1) { - if (count((array) $this->newLangStrings) >= $when) + if (isset($this->newLangStrings[$target]) + && count( + (array) $this->newLangStrings[$target] + ) >= $when) { // Create a new query object. - $query = $this->db->getQuery(true); + $query = $this->db->getQuery(true); $continue = false; // Insert columns. - $columns = array('components', 'source', 'published', 'created', 'created_by', 'version', 'access'); + $columns = array($target, 'source', 'published', 'created', + 'created_by', 'version', 'access'); // Prepare the insert query. - $query->insert($this->db->quoteName('#__componentbuilder_language_translation')); + $query->insert( + $this->db->quoteName('#__componentbuilder_language_translation') + ); $query->columns($this->db->quoteName($columns)); - foreach ($this->newLangStrings as $values) + foreach ($this->newLangStrings[$target] as $values) { if (count((array) $values) == 7) { @@ -6024,7 +7577,7 @@ class Get } } // clear the values array - $this->newLangStrings = array(); + $this->newLangStrings[$target] = array(); if (!$continue) { return false; // insure we dont continue if no values were loaded @@ -6037,11 +7590,11 @@ class Get /** * update the language placeholders - * - * @param int $when To set when to update + * + * @param int $when To set when to update * * @return void - * + * */ protected function setExistingLangStrings($when = 1) { @@ -6052,7 +7605,11 @@ class Get // Create a new query object. $query = $this->db->getQuery(true); // Prepare the update query. - $query->update($this->db->quoteName('#__componentbuilder_language_translation'))->set($values['fields'])->where($values['conditions']); + $query->update( + $this->db->quoteName( + '#__componentbuilder_language_translation' + ) + )->set($values['fields'])->where($values['conditions']); // Set the query using our newly populated query object and execute it. $this->db->setQuery($query); $this->db->execute(); @@ -6064,11 +7621,11 @@ class Get /** * Remove exiting language translation stings - * - * @param int $id To string ID to remove + * + * @param int $id To string ID to remove * * @return void - * + * */ protected function removeExitingLangString($id) { @@ -6080,7 +7637,9 @@ class Get $this->db->quoteName('id') . ' = ' . (int) $id ); - $query->delete($this->db->quoteName('#__componentbuilder_language_translation')); + $query->delete( + $this->db->quoteName('#__componentbuilder_language_translation') + ); $query->where($conditions); $this->db->setQuery($query); @@ -6089,110 +7648,191 @@ class Get /** * Function to purge the unused languge strings - * - * @param string $values the active strings + * + * @param string $values the active strings * * @return void - * + * */ - public function purgeLanuageStrings($values) - { - // Create a new query object. - $query = $this->db->getQuery(true); - $query->from($this->db->quoteName('#__componentbuilder_language_translation', 'a')); - $query->select($this->db->quoteName(array('a.id', 'a.translation', 'a.components'))); - // get all string that are not linked to this component - $query->where($this->db->quoteName('a.source') . ' NOT IN (' . implode(',', array_map(function($a) - { - return $this->db->quote($a); - }, $values)) . ')'); - $query->where($this->db->quoteName('a.published') . ' = 1'); - $this->db->setQuery($query); - $this->db->execute(); - if ($this->db->getNumRows()) + public function purgeLanuageStrings($values, $target_id, + $target = 'components' + ) { + // the target types are + $target_types = array('components' => 'components', + 'modules' => 'modules', + 'plugins' => 'plugins'); + // make sure we only work with preset targets + if (isset($target_types[$target])) { - $counterUpdate = 0; - $otherStrings = $this->db->loadAssocList(); - $today = JFactory::getDate()->toSql(); - foreach ($otherStrings as $item) + // remove the current target + unset($target_types[$target]); + // Create a new query object. + $query = $this->db->getQuery(true); + $query->from( + $this->db->quoteName( + '#__componentbuilder_language_translation', 'a' + ) + ); + $query->select( + $this->db->quoteName( + array('a.id', 'a.translation', 'a.components', 'a.modules', + 'a.plugins') + ) + ); + // get all string that are not linked to this component + $query->where( + $this->db->quoteName('a.source') . ' NOT IN (' . implode( + ',', array_map( + function ($a) { + return $this->db->quote($a); + }, $values + ) + ) . ')' + ); + $query->where($this->db->quoteName('a.published') . ' = 1'); + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) { - if (ComponentbuilderHelper::checkJson($item['components'])) + $counterUpdate = 0; + $otherStrings = $this->db->loadAssocList(); + $today = JFactory::getDate()->toSql(); + foreach ($otherStrings as $item) { - $components = (array) json_decode($item['components'], true); - // if component is not found ignore this string, and do nothing - if (($key = array_search($this->componentID, $components)) !== false) + if (ComponentbuilderHelper::checkJson($item[$target])) { - // first remove the component from the string - unset($components[$key]); - // check if there are more components - if (ComponentbuilderHelper::checkArray($components)) + $targets = (array) json_decode($item[$target], true); + // if component is not found ignore this string, and do nothing + if (($key = array_search($target_id, $targets)) + !== false) { - // just update the string to unlink the current component - $this->setUpdateExistingLangStrings($item['id'], $components, 1, $today, $counterUpdate); - - $counterUpdate++; - - // load to db - $this->setExistingLangStrings(50); - } - // check if this string has been worked on - elseif (ComponentbuilderHelper::checkJson($item['translation'])) - { - $translation = json_decode($item['translation'], true); - if (ComponentbuilderHelper::checkArray($translation)) + // first remove the component from the string + unset($targets[$key]); + // check if there are more components + if (ComponentbuilderHelper::checkArray($targets)) { - // only archive the item and update the string to unlink the current component - $this->setUpdateExistingLangStrings($item['id'], $components, 2, $today, $counterUpdate); + // just update the string to unlink the current component + $this->setUpdateExistingLangStrings( + $item['id'], $target, $targets, 1, $today, + $counterUpdate + ); $counterUpdate++; - // load to db + // load to db $this->setExistingLangStrings(50); } + // check if this string has been worked on or is linked to other extensions else { - // remove the string since no translation found and not linked to any other component - $this->removeExitingLangString($item['id']); + // the action (1 = remove, 2 = archive, 0 = do nothing) + $action_with_string = 1; + // now check if it is linked to other extensions + foreach ($target_types as $other_target) + { + // just one linked extension type is enough to stop the search + if ($action_with_string + && ComponentbuilderHelper::checkJson( + $item[$other_target] + )) + { + $other_targets = (array) json_decode( + $item[$other_target], true + ); + // check if linked to other extensions + if (ComponentbuilderHelper::checkArray( + $other_targets + )) + { + $action_with_string + = 0; // do nothing + } + } + } + // check we should just archive or remove string + if ($action_with_string + && ComponentbuilderHelper::checkJson( + $item['translation'] + )) + { + $translation = json_decode( + $item['translation'], true + ); + if (ComponentbuilderHelper::checkArray( + $translation + )) + { + // only archive the item and update the string to unlink the current component + $this->setUpdateExistingLangStrings( + $item['id'], $target, $targets, 2, + $today, $counterUpdate + ); + + $counterUpdate++; + + // load to db + $this->setExistingLangStrings(50); + + $action_with_string + = 2; // we archived it + } + } + // remove the string since no translation found and not linked to any other extensions + if ($action_with_string == 1) + { + $this->removeExitingLangString($item['id']); + } } } - else - { - // remove the string since no translation found and not linked to any other component - $this->removeExitingLangString($item['id']); - } } } + // load to db + $this->setExistingLangStrings(); } - // load to db - $this->setExistingLangStrings(); } } /** * just to add lang string to the existing Lang Strings array - * + * * @return void - * + * */ - protected function setUpdateExistingLangStrings($id, $components, $published, $today, $counterUpdate) - { + protected function setUpdateExistingLangStrings($id, $target, $targets, + $published, $today, $counterUpdate + ) { // start the bucket for this lang - $this->existingLangStrings[$counterUpdate] = array(); - $this->existingLangStrings[$counterUpdate]['id'] = (int) $id; + $this->existingLangStrings[$counterUpdate] = array(); + $this->existingLangStrings[$counterUpdate]['id'] = (int) $id; $this->existingLangStrings[$counterUpdate]['conditions'] = array(); - $this->existingLangStrings[$counterUpdate]['conditions'][] = $this->db->quoteName('id') . ' = ' . $this->db->quote($id); - $this->existingLangStrings[$counterUpdate]['fields'] = array(); - $this->existingLangStrings[$counterUpdate]['fields'][] = $this->db->quoteName('components') . ' = ' . $this->db->quote(json_encode($components)); - $this->existingLangStrings[$counterUpdate]['fields'][] = $this->db->quoteName('published') . ' = ' . $this->db->quote($published); - $this->existingLangStrings[$counterUpdate]['fields'][] = $this->db->quoteName('modified') . ' = ' . $this->db->quote($today); - $this->existingLangStrings[$counterUpdate]['fields'][] = $this->db->quoteName('modified_by') . ' = ' . $this->db->quote((int) $this->user->id); + $this->existingLangStrings[$counterUpdate]['conditions'][] + = $this->db->quoteName( + 'id' + ) . ' = ' . $this->db->quote($id); + $this->existingLangStrings[$counterUpdate]['fields'] = array(); + $this->existingLangStrings[$counterUpdate]['fields'][] + = $this->db->quoteName( + $target + ) . ' = ' . $this->db->quote(json_encode($targets)); + $this->existingLangStrings[$counterUpdate]['fields'][] + = $this->db->quoteName( + 'published' + ) . ' = ' . $this->db->quote($published); + $this->existingLangStrings[$counterUpdate]['fields'][] + = $this->db->quoteName( + 'modified' + ) . ' = ' . $this->db->quote($today); + $this->existingLangStrings[$counterUpdate]['fields'][] + = $this->db->quoteName( + 'modified_by' + ) . ' = ' . $this->db->quote((int) $this->user->id); } /** * get the custom code from the system - * + * * @return void - * + * */ public function getCustomCode($ids = null, $setLang = true, $debug = 0) { @@ -6200,14 +7840,26 @@ class Get $loadInMemory = false; // Create a new query object. $query = $this->db->getQuery(true); - $query->from($this->db->quoteName('#__componentbuilder_custom_code', 'a')); + $query->from( + $this->db->quoteName('#__componentbuilder_custom_code', 'a') + ); if (ComponentbuilderHelper::checkArray($ids)) { if ($idArray = $this->checkCustomCodeMemory($ids)) { - $query->select($this->db->quoteName(array('a.id', 'a.code', 'a.comment_type'))); - $query->where($this->db->quoteName('a.id') . ' IN (' . implode(',', $idArray) . ')'); - $query->where($this->db->quoteName('a.target') . ' = 2'); // <--- to load the correct target + $query->select( + $this->db->quoteName( + array('a.id', 'a.code', 'a.comment_type') + ) + ); + $query->where( + $this->db->quoteName('a.id') . ' IN (' . implode( + ',', $idArray + ) . ')' + ); + $query->where( + $this->db->quoteName('a.target') . ' = 2' + ); // <--- to load the correct target $loadInMemory = true; } else @@ -6218,10 +7870,23 @@ class Get } else { - $query->select($this->db->quoteName(array('a.id', 'a.code', 'a.comment_type', 'a.component', 'a.from_line', 'a.hashtarget', 'a.hashendtarget', 'a.path', 'a.to_line', 'a.type'))); - $query->where($this->db->quoteName('a.component') . ' = ' . (int) $this->componentData->id); - $query->where($this->db->quoteName('a.target') . ' = 1'); // <--- to load the correct target - $query->order($this->db->quoteName('a.from_line') . ' ASC'); // <--- insrue we always add code from top of file + $query->select( + $this->db->quoteName( + array('a.id', 'a.code', 'a.comment_type', 'a.component', + 'a.from_line', 'a.hashtarget', 'a.hashendtarget', + 'a.path', 'a.to_line', 'a.type') + ) + ); + $query->where( + $this->db->quoteName('a.component') . ' = ' + . (int) $this->componentData->id + ); + $query->where( + $this->db->quoteName('a.target') . ' = 1' + ); // <--- to load the correct target + $query->order( + $this->db->quoteName('a.from_line') . ' ASC' + ); // <--- insure we always add code from top of file // reset custom code $this->customCode = array(); } @@ -6236,30 +7901,45 @@ class Get { $customCode['code'] = base64_decode($customCode['code']); // always insure that the external code is loaded - $customCode['code'] = $this->setExternalCodeString($customCode['code']); + $customCode['code'] = $this->setExternalCodeString( + $customCode['code'] + ); // set the lang only if needed if ($setLang) { - $customCode['code'] = $this->setLangStrings($customCode['code']); + $customCode['code'] = $this->setLangStrings( + $customCode['code'] + ); } // check for more custom code (since this is a custom code placeholder) else { - $customCode['code'] = $this->setCustomCodeData($customCode['code'], $debug, $nr); + $customCode['code'] = $this->setCustomCodeData( + $customCode['code'], $debug, $nr + ); } // build the hash array if (isset($customCode['hashtarget'])) { - $customCode['hashtarget'] = explode("__", $customCode['hashtarget']); + $customCode['hashtarget'] = explode( + "__", $customCode['hashtarget'] + ); // is this a replace code, set end has array - if ($customCode['type'] == 1 && strpos($customCode['hashendtarget'], '__') !== false) + if ($customCode['type'] == 1 + && strpos( + $customCode['hashendtarget'], '__' + ) !== false) { - $customCode['hashendtarget'] = explode("__", $customCode['hashendtarget']); + $customCode['hashendtarget'] = explode( + "__", $customCode['hashendtarget'] + ); // NOW see if this is an end of page target (TODO not sure if the string is always d41d8cd98f00b204e9800998ecf8427e) // I know this fix is not air-tight, but it should work as the value of an empty line when md5'ed is ^^^^ // Then if the line number is only >>>one<<< it is almost always end of the page. // So I am using those two values to detect end of page replace ending, to avoid mismatching the ending target hash. - if ($customCode['hashendtarget'][0] == 1 && 'd41d8cd98f00b204e9800998ecf8427e' === $customCode['hashendtarget'][1]) + if ($customCode['hashendtarget'][0] == 1 + && 'd41d8cd98f00b204e9800998ecf8427e' + === $customCode['hashendtarget'][1]) { // unset since this will force the replacement unto end of page. unset($customCode['hashendtarget']); @@ -6273,8 +7953,77 @@ class Get $this->customCodeMemory = $this->customCodeMemory + $bucket; } $this->customCode = array_merge($this->customCode, $bucket); + return true; } + + return false; + } + + /** + * get the Joomla module path + * + * @return array of module path and target site area on success + * + */ + protected function getModulePath($id) + { + if (is_numeric($id) && $id > 0) + { + // Create a new query object. + $query = $this->db->getQuery(true); + + $query->select('a.*'); + $query->select( + $this->db->quoteName( + array( + 'a.name', + 'a.target' + ), array( + 'name', + 'target' + ) + ) + ); + // from these tables + $query->from('#__componentbuilder_joomla_module AS a'); + $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); + $this->db->setQuery($query); + $this->db->execute(); + if ($this->db->getNumRows()) + { + // get the module data + $module = $this->db->loadObject(); + // update the name if it has dynamic values + $module->name = $this->setPlaceholders( + $this->setDynamicValues($module->name), + $this->globalPlaceholders + ); + // set safe class function name + $module->code_name + = ComponentbuilderHelper::safeClassFunctionName( + $module->name + ); + // set module folder name + $module->folder_name = 'mod_' . strtolower($module->code_name); + // set the lang key + $this->langKeys[strtoupper($module->folder_name)] = $module->id + . '_M0dU|3'; + // return the path + if ($module->target == 2) + { + // administrator client area + return JPATH_ADMINISTRATOR . '/modules/' + . $module->folder_name; + } + else + { + // default is the site client area + return JPATH_ROOT . '/modules/' . $module->folder_name; + } + } + } + return false; } @@ -6286,30 +8035,40 @@ class Get */ protected function getModuleIDs() { - if (($addjoomla_modules = ComponentbuilderHelper::getVar('component_modules', $this->componentID, 'joomla_component', 'addjoomla_modules')) !== false) + if (($addjoomla_modules = ComponentbuilderHelper::getVar( + 'component_modules', $this->componentID, 'joomla_component', + 'addjoomla_modules' + )) !== false) { - $addjoomla_modules = (ComponentbuilderHelper::checkJson($addjoomla_modules)) ? json_decode($addjoomla_modules, true) : null; + $addjoomla_modules = (ComponentbuilderHelper::checkJson( + $addjoomla_modules + )) ? json_decode($addjoomla_modules, true) : null; if (ComponentbuilderHelper::checkArray($addjoomla_modules)) { $joomla_modules = array_filter( array_values($addjoomla_modules), - function($array){ + function ($array) { // only load the modules whose target association call for it if (!isset($array['target']) || $array['target'] != 2) { return true; } + return false; - }); + } + ); // if we have values we return IDs if (ComponentbuilderHelper::checkArray($joomla_modules)) { - return array_map(function($array){ - return (int) $array['module']; - }, $joomla_modules); + return array_map( + function ($array) { + return (int) $array['module']; + }, $joomla_modules + ); } } } + return false; } @@ -6354,8 +8113,18 @@ class Get ); // from these tables $query->from('#__componentbuilder_joomla_module AS a'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_module_updates', 'u') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('u.joomla_module') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_module_files_folders_urls', 'f') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('f.joomla_module') . ')'); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_module_updates', 'u' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('u.joomla_module') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_module_files_folders_urls', 'f' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('f.joomla_module') . ')' + ); $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); $query->where($this->db->quoteName('a.published') . ' >= 1'); $this->db->setQuery($query); @@ -6365,69 +8134,134 @@ class Get // get the module data $module = $this->db->loadObject(); // tweak system to set stuff to the module domain - $_backup_target = $this->target; - $_backup_lang = $this->lang; + $_backup_target = $this->target; + $_backup_lang = $this->lang; $_backup_langPrefix = $this->langPrefix; // set some keys $module->target_type = 'M0dU|3'; - $module->key = $module->id . '_' . $module->target_type; + $module->key = $module->id . '_' . $module->target_type; // update to point to module $this->target = $module->key; - $this->lang = $module->key; + $this->lang = $module->key; // set version if not set if (empty($module->module_version)) { $module->module_version = '1.0.0'; } + // set target client + if ($module->target == 2) + { + $module->target_client = 'admin'; + } + else + { + // default is site area + $module->target_client = 'site'; + } + unset($module->target); // set GUI mapper - $guiMapper = array( 'table' => 'joomla_module', 'id' => (int) $id, 'type' => 'php'); + $guiMapper = array('table' => 'joomla_module', + 'id' => (int) $id, 'type' => 'php'); // update the name if it has dynamic values - $module->name = $this->setPlaceholders($this->setDynamicValues($module->name), $this->placeholders); - // update the name if it has dynamic values - $module->code_name = ComponentbuilderHelper::safeClassFunctionName($module->name); + $module->name = $this->setPlaceholders( + $this->setDynamicValues($module->name), $this->placeholders + ); + // set safe class function name + $module->code_name + = ComponentbuilderHelper::safeClassFunctionName( + $module->name + ); // set official name - $module->official_name = ComponentbuilderHelper::safeString($module->name, 'W'); + $module->official_name = ComponentbuilderHelper::safeString( + $module->name, 'W' + ); // set langPrefix $this->langPrefix = 'MOD_' . strtoupper($module->code_name); // set lang prefix $module->lang_prefix = $this->langPrefix; // set module class name - $module->class_helper_name = 'Mod' . ucfirst($module->code_name) . 'Helper'; - $module->class_data_name = 'Mod' . ucfirst($module->code_name) . 'Data'; - // set module install class name - $module->installer_class_name = 'mod_' . ucfirst($module->code_name) . 'InstallerScript'; + $module->class_helper_name = 'Mod' . ucfirst($module->code_name) + . 'Helper'; + $module->class_data_name = 'Mod' . ucfirst($module->code_name) + . 'Data'; + // set module install class name + $module->installer_class_name = 'mod_' . ucfirst( + $module->code_name + ) . 'InstallerScript'; // set module folder name $module->folder_name = 'mod_' . strtolower($module->code_name); // set the zip name - $module->zip_name = $module->folder_name . '_v' . str_replace('.', '_', $module->module_version). '__J' . $this->joomlaVersion; + $module->zip_name = $module->folder_name . '_v' . str_replace( + '.', '_', $module->module_version + ) . '__J' . $this->joomlaVersion; // set module file name $module->file_name = $module->folder_name; + // set module context + $module->context = $module->file_name . '.' . $module->id; // set official_name lang strings - $this->setLangContent($module->key, $this->langPrefix, $module->official_name); + $this->setLangContent( + $module->key, $this->langPrefix, $module->official_name + ); // set some placeholder for this module - $this->placeholders[$this->bbb . 'Module_name' . $this->ddd] = $module->official_name; - $this->placeholders[$this->bbb . 'Module' . $this->ddd] = ucfirst($module->code_name); - $this->placeholders[$this->bbb . 'module' . $this->ddd] = strtolower($module->code_name); - $this->placeholders[$this->bbb . 'module.version' . $this->ddd] = $module->module_version; - $this->placeholders[$this->bbb . 'module_version' . $this->ddd] = str_replace('.', '_', $module->module_version); + $this->placeholders[$this->bbb . 'Module_name' . $this->ddd] + = $module->official_name; + $this->placeholders[$this->bbb . 'Module' . $this->ddd] + = ucfirst( + $module->code_name + ); + $this->placeholders[$this->bbb . 'module' . $this->ddd] + = strtolower( + $module->code_name + ); + $this->placeholders[$this->bbb . 'module.version' . $this->ddd] + = $module->module_version; + $this->placeholders[$this->bbb . 'module_version' . $this->ddd] + = str_replace( + '.', '_', $module->module_version + ); // set description (TODO) add description field to module - if (!isset($module->description) || !ComponentbuilderHelper::checkString($module->description)) + if (!isset($module->description) + || !ComponentbuilderHelper::checkString( + $module->description + )) { $module->description = ''; } else { - $module->description = $this->setPlaceholders($this->setDynamicValues($module->description), $this->placeholders); - $this->setLangContent($module->key, $module->lang_prefix . '_DESCRIPTION', $module->description); - $module->description = '

' . $module->description . '

'; + $module->description = $this->setPlaceholders( + $this->setDynamicValues($module->description), + $this->placeholders + ); + $this->setLangContent( + $module->key, $module->lang_prefix . '_DESCRIPTION', + $module->description + ); + $module->description = '

' . $module->description + . '

'; } - $module->xml_description = "

" . $module->official_name . " (v." . $module->module_version . ")

" . $module->description . "

Created by " . trim(JFilterOutput::cleanText($component->author)) . "
Development started " . JFactory::getDate($module->created)->format("jS F, Y") . "

"; + $module->xml_description = "

" . $module->official_name + . " (v." . $module->module_version + . ")

" + . $module->description . "

Created by " . trim( + JFilterOutput::cleanText($component->author) + ) . "
Development started " + . JFactory::getDate($module->created)->format("jS F, Y") + . "

"; // set xml description - $this->setLangContent($module->key, $module->lang_prefix . '_XML_DESCRIPTION', $module->xml_description); + $this->setLangContent( + $module->key, $module->lang_prefix . '_XML_DESCRIPTION', + $module->xml_description + ); // update the readme if set if ($module->addreadme == 1 && !empty($module->readme)) { - $module->readme = $this->setPlaceholders($this->setDynamicValues(base64_decode($module->readme)), $this->placeholders); + $module->readme = $this->setPlaceholders( + $this->setDynamicValues(base64_decode($module->readme)), + $this->placeholders + ); } else { @@ -6435,38 +8269,59 @@ class Get unset($module->readme); } // get the custom_get - $module->custom_get = (isset($module->custom_get) && ComponentbuilderHelper::checkJson($module->custom_get)) ? json_decode($module->custom_get, true) : null; + $module->custom_get = (isset($module->custom_get) + && ComponentbuilderHelper::checkJson($module->custom_get)) + ? json_decode($module->custom_get, true) : null; if (ComponentbuilderHelper::checkArray($module->custom_get)) { - $module->custom_get = $this->setGetData($module->custom_get, $module->key, $module->key); + $module->custom_get = $this->setGetData( + $module->custom_get, $module->key, $module->key + ); } else { $module->custom_get = false; } // set helper class details - if ($module->add_class_helper >= 1 && ComponentbuilderHelper::checkString($module->class_helper_code)) + if ($module->add_class_helper >= 1 + && ComponentbuilderHelper::checkString( + $module->class_helper_code + )) { - if ($module->add_class_helper_header == 1 && ComponentbuilderHelper::checkString($module->class_helper_header)) + if ($module->add_class_helper_header == 1 + && ComponentbuilderHelper::checkString( + $module->class_helper_header + )) { // set GUI mapper field $guiMapper['field'] = 'class_helper_header'; // base64 Decode code - $module->class_helper_header = PHP_EOL . $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($module->class_helper_header)), $this->placeholders), - $guiMapper - ) . PHP_EOL; + $module->class_helper_header = PHP_EOL + . $this->setGuiCodePlaceholder( + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode( + $module->class_helper_header + ) + ), $this->placeholders + ), + $guiMapper + ) . PHP_EOL; } else { $module->add_class_helper_header = 0; - $module->class_helper_header = ''; + $module->class_helper_header = ''; } // set GUI mapper field $guiMapper['field'] = 'class_helper_code'; // base64 Decode code $module->class_helper_code = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($module->class_helper_code)), $this->placeholders), + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($module->class_helper_code) + ), $this->placeholders + ), $guiMapper ); // set class type @@ -6481,34 +8336,50 @@ class Get } else { - $module->add_class_helper = 0; - $module->class_helper_code = ''; + $module->add_class_helper = 0; + $module->class_helper_code = ''; $module->class_helper_header = ''; } // base64 Decode mod_code - if (isset($module->mod_code) && ComponentbuilderHelper::checkString($module->mod_code)) + if (isset($module->mod_code) + && ComponentbuilderHelper::checkString($module->mod_code)) { // set GUI mapper field $guiMapper['field'] = 'mod_code'; - $module->mod_code = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($module->mod_code)), $this->placeholders), + $module->mod_code = $this->setGuiCodePlaceholder( + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($module->mod_code) + ), $this->placeholders + ), $guiMapper ); } else { $module->mod_code = "// get the module class sfx"; - $module->mod_code .= PHP_EOL . "\$moduleclass_sfx = htmlspecialchars(\$params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8');"; + $module->mod_code .= PHP_EOL + . "\$moduleclass_sfx = htmlspecialchars(\$params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8');"; $module->mod_code .= PHP_EOL . "// load the default Tmpl"; - $module->mod_code .= PHP_EOL . "require JModuleHelper::getLayoutPath('mod_" . strtolower($module->code_name) . "', \$params->get('layout', 'default'));"; + $module->mod_code .= PHP_EOL + . "require JModuleHelper::getLayoutPath('mod_" + . strtolower($module->code_name) + . "', \$params->get('layout', 'default'));"; } // base64 Decode default header - if (isset($module->default_header) && ComponentbuilderHelper::checkString($module->default_header)) + if (isset($module->default_header) + && ComponentbuilderHelper::checkString( + $module->default_header + )) { // set GUI mapper field - $guiMapper['field'] = 'default_header'; + $guiMapper['field'] = 'default_header'; $module->default_header = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($module->default_header)), $this->placeholders), + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($module->default_header) + ), $this->placeholders + ), $guiMapper ); } @@ -6517,12 +8388,18 @@ class Get $module->default_header = ''; } // base64 Decode default - if (isset($module->default) && ComponentbuilderHelper::checkString($module->default)) + if (isset($module->default) + && ComponentbuilderHelper::checkString($module->default)) { // set GUI mapper field $guiMapper['field'] = 'default'; - $module->default = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($module->default)), $this->placeholders), + $guiMapper['type'] = 'html'; + $module->default = $this->setGuiCodePlaceholder( + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($module->default) + ), $this->placeholders + ), $guiMapper ); } @@ -6533,38 +8410,57 @@ class Get // start the config array $module->config_fields = array(); // create the form arrays - $module->form_files = array(); + $module->form_files = array(); $module->fieldsets_label = array(); $module->fieldsets_paths = array(); // set global fields rule to default component path $module->fields_rules_paths = 1; // set the fields data - $module->fields = (isset($module->fields) && ComponentbuilderHelper::checkJson($module->fields)) ? json_decode($module->fields, true) : null; + $module->fields = (isset($module->fields) + && ComponentbuilderHelper::checkJson($module->fields)) + ? json_decode($module->fields, true) : null; if (ComponentbuilderHelper::checkArray($module->fields)) { // ket global key - $key = $module->key; - $dynamic_fields = array('fieldset' => 'basic', 'fields_name' => 'params', 'file' => 'config'); + $key = $module->key; + $dynamic_fields = array('fieldset' => 'basic', + 'fields_name' => 'params', + 'file' => 'config'); foreach ($module->fields as $n => &$form) { - if (isset($form['fields']) && ComponentbuilderHelper::checkArray($form['fields'])) + if (isset($form['fields']) + && ComponentbuilderHelper::checkArray( + $form['fields'] + )) { // make sure the dynamic_field is set to dynamic_value by default - foreach ($dynamic_fields as $dynamic_field => $dynamic_value) + foreach ( + $dynamic_fields as $dynamic_field => + $dynamic_value + ) { - if (!isset($form[$dynamic_field]) || !ComponentbuilderHelper::checkString($form[$dynamic_field])) + if (!isset($form[$dynamic_field]) + || !ComponentbuilderHelper::checkString( + $form[$dynamic_field] + )) { $form[$dynamic_field] = $dynamic_value; } else { - if ('fields_name' === $dynamic_field && strpos($form[$dynamic_field], '.') !== false) + if ('fields_name' === $dynamic_field + && strpos($form[$dynamic_field], '.') + !== false) { - $form[$dynamic_field] = $form[$dynamic_field]; + $form[$dynamic_field] + = $form[$dynamic_field]; } else { - $form[$dynamic_field] = ComponentbuilderHelper::safeString($form[$dynamic_field]); + $form[$dynamic_field] + = ComponentbuilderHelper::safeString( + $form[$dynamic_field] + ); } } } @@ -6572,73 +8468,109 @@ class Get if (!isset($form['module']) || $form['module'] != 1) { // now build the form key - $unique = $form['file'] . $form['fields_name'] . $form['fieldset']; + $unique = $form['file'] . $form['fields_name'] + . $form['fieldset']; } else { // now build the form key - $unique = $form['fields_name'] . $form['fieldset']; + $unique = $form['fields_name'] + . $form['fieldset']; } // set global fields rule path switchs - if ($module->fields_rules_paths == 1 && isset($form['fields_rules_paths']) && $form['fields_rules_paths'] == 2) + if ($module->fields_rules_paths == 1 + && isset($form['fields_rules_paths']) + && $form['fields_rules_paths'] == 2) { $module->fields_rules_paths = 2; } // set where to path is pointing - $module->fieldsets_paths[$unique] = $form['fields_rules_paths']; + $module->fieldsets_paths[$unique] + = $form['fields_rules_paths']; // add the label if set to lang - if (isset($form['label']) && ComponentbuilderHelper::checkString($form['label'])) + if (isset($form['label']) + && ComponentbuilderHelper::checkString( + $form['label'] + )) { - $module->fieldsets_label[$unique] = $this->setLang($form['label']); + $module->fieldsets_label[$unique] + = $this->setLang($form['label']); } // build the fields - $form['fields'] = array_map(function($field) use ($key, $unique){ - // make sure the alias and title is 0 - $field['alias'] = 0; - $field['title'] = 0; - // set the field details - $this->setFieldDetails($field, $key, $key, $unique); - // update the default if set - if (ComponentbuilderHelper::checkString($field['custom_value']) && isset($field['settings'])) - { - if (($old_default = ComponentbuilderHelper::getBetween($field['settings']->xml, 'default="', '"', false)) !== false) + $form['fields'] = array_map( + function ($field) use ($key, $unique) { + // make sure the alias and title is 0 + $field['alias'] = 0; + $field['title'] = 0; + // set the field details + $this->setFieldDetails( + $field, $key, $key, $unique + ); + // update the default if set + if (ComponentbuilderHelper::checkString( + $field['custom_value'] + ) + && isset($field['settings'])) { - // replace old default - $field['settings']->xml = str_replace('default="' . $old_default . '"', 'default="' . $field['custom_value'] . '"', $field['settings']->xml); + if (($old_default + = ComponentbuilderHelper::getBetween( + $field['settings']->xml, + 'default="', '"', false + )) !== false) + { + // replace old default + $field['settings']->xml + = str_replace( + 'default="' . $old_default + . '"', 'default="' + . $field['custom_value'] . '"', + $field['settings']->xml + ); + } + else + { + // add the default (hmmm not ideal but okay it should work) + $field['settings']->xml + = 'default="' + . $field['custom_value'] . '" ' + . $field['settings']->xml; + } } - else - { - // add the default (hmmm not ideal but okay it should work) - $field['settings']->xml = 'default="' . $field['custom_value'] . '" ' . $field['settings']->xml; - } - } - unset($field['custom_value']); - // return field - return $field; - }, array_values($form['fields'])); + unset($field['custom_value']); + + // return field + return $field; + }, array_values($form['fields']) + ); // check if field is external form file if (!isset($form['module']) || $form['module'] != 1) { // load the form file if (!isset($module->form_files[$form['file']])) { - $module->form_files[$form['file']] = array(); + $module->form_files[$form['file']] + = array(); } if (!isset($module->form_files[$form['file']][$form['fields_name']])) { - $module->form_files[$form['file']][$form['fields_name']] = array(); + $module->form_files[$form['file']][$form['fields_name']] + = array(); } if (!isset($module->form_files[$form['file']][$form['fields_name']][$form['fieldset']])) { - $module->form_files[$form['file']][$form['fields_name']][$form['fieldset']] = array(); + $module->form_files[$form['file']][$form['fields_name']][$form['fieldset']] + = array(); } // do some house cleaning (for fields) foreach ($form['fields'] as $field) { // so first we lock the field name in - $this->getFieldName($field, $module->key, $unique); + $this->getFieldName( + $field, $module->key, $unique + ); // add the fields to the global form file builder - $module->form_files[$form['file']][$form['fields_name']][$form['fieldset']][] = $field; + $module->form_files[$form['file']][$form['fields_name']][$form['fieldset']][] + = $field; } // remove form unset($module->fields[$n]); @@ -6648,19 +8580,24 @@ class Get // load the config form if (!isset($module->config_fields[$form['fields_name']])) { - $module->config_fields[$form['fields_name']] = array(); + $module->config_fields[$form['fields_name']] + = array(); } if (!isset($module->config_fields[$form['fields_name']][$form['fieldset']])) { - $module->config_fields[$form['fields_name']][$form['fieldset']] = array(); + $module->config_fields[$form['fields_name']][$form['fieldset']] + = array(); } // do some house cleaning (for fields) foreach ($form['fields'] as $field) { // so first we lock the field name in - $this->getFieldName($field, $module->key, $unique); + $this->getFieldName( + $field, $module->key, $unique + ); // add the fields to the config builder - $module->config_fields[$form['fields_name']][$form['fieldset']][] = $field; + $module->config_fields[$form['fields_name']][$form['fieldset']][] + = $field; } // remove form unset($module->fields[$n]); @@ -6674,14 +8611,29 @@ class Get } unset($module->fields); // set the add targets - $addArray = array('files' => 'files', 'folders' => 'folders', 'urls' => 'urls', 'filesfullpath' => 'files', 'foldersfullpath' => 'folders'); + $addArray = array('files' => 'files', + 'folders' => 'folders', + 'urls' => 'urls', + 'filesfullpath' => 'files', + 'foldersfullpath' => 'folders'); foreach ($addArray as $addTarget => $targetHere) { // set the add target data - $module->{'add' . $addTarget} = (isset($module->{'add' . $addTarget}) && ComponentbuilderHelper::checkJson($module->{'add' . $addTarget})) ? json_decode($module->{'add' . $addTarget}, true) : null; - if (ComponentbuilderHelper::checkArray($module->{'add' . $addTarget})) + $module->{'add' . $addTarget} = (isset( + $module->{'add' . $addTarget} + ) + && ComponentbuilderHelper::checkJson( + $module->{'add' . $addTarget} + )) ? json_decode($module->{'add' . $addTarget}, true) + : null; + if (ComponentbuilderHelper::checkArray( + $module->{'add' . $addTarget} + )) { - if (isset($module->{$targetHere}) && ComponentbuilderHelper::checkArray($module->{$targetHere})) + if (isset($module->{$targetHere}) + && ComponentbuilderHelper::checkArray( + $module->{$targetHere} + )) { foreach ($module->{'add' . $addTarget} as $taget) { @@ -6690,7 +8642,9 @@ class Get } else { - $module->{$targetHere} = array_values($module->{'add' . $addTarget}); + $module->{$targetHere} = array_values( + $module->{'add' . $addTarget} + ); } } unset($module->{'add' . $addTarget}); @@ -6702,7 +8656,8 @@ class Get } if (!isset($this->libManager[$this->target][$module->code_name])) { - $this->libManager[$this->target][$module->code_name] = array(); + $this->libManager[$this->target][$module->code_name] + = array(); } // make sure json become array if (ComponentbuilderHelper::checkJson($module->libraries)) @@ -6718,32 +8673,55 @@ class Get { if ($this->getMediaLibrary((int) $library)) { - $this->libManager[$this->target][$module->code_name][(int) $library] = true; + $this->libManager[$this->target][$module->code_name][(int) $library] + = true; } } } } - elseif (is_numeric($module->libraries) && !isset($this->libManager[$this->target][$module->code_name][(int) $module->libraries])) + elseif (is_numeric($module->libraries) + && !isset($this->libManager[$this->target][$module->code_name][(int) $module->libraries])) { if ($this->getMediaLibrary((int) $module->libraries)) { - $this->libManager[$this->target][$module->code_name][(int) $module->libraries] = true; + $this->libManager[$this->target][$module->code_name][(int) $module->libraries] + = true; } } // add PHP in module install $module->add_install_script = false; - $addScriptMethods = array('php_preflight', 'php_postflight', 'php_method'); - $addScriptTypes = array('install', 'update', 'uninstall'); + $addScriptMethods = array('php_preflight', + 'php_postflight', + 'php_method'); + $addScriptTypes = array('install', 'update', + 'uninstall'); foreach ($addScriptMethods as $scriptMethod) { foreach ($addScriptTypes as $scriptType) { - if (isset($module->{'add_' . $scriptMethod . '_' . $scriptType}) && $module->{'add_' . $scriptMethod . '_' . $scriptType} == 1 && ComponentbuilderHelper::checkString($module->{$scriptMethod . '_' . $scriptType})) + if (isset( + $module->{'add_' . $scriptMethod . '_' + . $scriptType} + ) + && $module->{'add_' . $scriptMethod . '_' + . $scriptType} == 1 + && ComponentbuilderHelper::checkString( + $module->{$scriptMethod . '_' . $scriptType} + )) { // set GUI mapper field - $guiMapper['field'] = $scriptMethod . '_' . $scriptType; - $module->{$scriptMethod . '_' . $scriptType} = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($module->{$scriptMethod . '_' . $scriptType})), $this->placeholders), + $guiMapper['field'] = $scriptMethod . '_' + . $scriptType; + $module->{$scriptMethod . '_' . $scriptType} + = $this->setGuiCodePlaceholder( + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode( + $module->{$scriptMethod . '_' + . $scriptType} + ) + ), $this->placeholders + ), $guiMapper ); $module->add_install_script = true; @@ -6751,14 +8729,20 @@ class Get else { unset($module->{$scriptMethod . '_' . $scriptType}); - $module->{'add_' . $scriptMethod . '_' . $scriptType} = 0; + $module->{'add_' . $scriptMethod . '_' + . $scriptType} + = 0; } } } // add_sql - if ($module->add_sql == 1 && ComponentbuilderHelper::checkString($module->sql)) + if ($module->add_sql == 1 + && ComponentbuilderHelper::checkString($module->sql)) { - $module->sql = $this->setPlaceholders($this->setDynamicValues(base64_decode($module->sql)), $this->placeholders); + $module->sql = $this->setPlaceholders( + $this->setDynamicValues(base64_decode($module->sql)), + $this->placeholders + ); } else { @@ -6766,9 +8750,16 @@ class Get $module->add_sql = 0; } // add_sql_uninstall - if ($module->add_sql_uninstall == 1 && ComponentbuilderHelper::checkString($module->sql_uninstall)) + if ($module->add_sql_uninstall == 1 + && ComponentbuilderHelper::checkString( + $module->sql_uninstall + )) { - $module->sql_uninstall = $this->setPlaceholders($this->setDynamicValues(base64_decode($module->sql_uninstall)), $this->placeholders); + $module->sql_uninstall = $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($module->sql_uninstall) + ), $this->placeholders + ); } else { @@ -6776,18 +8767,31 @@ class Get $module->add_sql_uninstall = 0; } // update the URL of the update_server if set - if ($module->add_update_server == 1 && ComponentbuilderHelper::checkString($module->update_server_url)) + if ($module->add_update_server == 1 + && ComponentbuilderHelper::checkString( + $module->update_server_url + )) { - $module->update_server_url = $this->setPlaceholders($this->setDynamicValues($module->update_server_url), $this->placeholders); + $module->update_server_url = $this->setPlaceholders( + $this->setDynamicValues($module->update_server_url), + $this->placeholders + ); } // add the update/sales server FTP details if that is the expected protocol $serverArray = array('update_server', 'sales_server'); foreach ($serverArray as $server) { - if ($module->{'add_' . $server} == 1 && is_numeric($module->{$server}) && $module->{$server} > 0) + if ($module->{'add_' . $server} == 1 + && is_numeric( + $module->{$server} + ) + && $module->{$server} > 0) { // get the server protocol - $module->{$server . '_protocol'} = ComponentbuilderHelper::getVar('server', (int) $module->{$server}, 'id', 'protocol'); + $module->{$server . '_protocol'} + = ComponentbuilderHelper::getVar( + 'server', (int) $module->{$server}, 'id', 'protocol' + ); } else { @@ -6805,21 +8809,30 @@ class Get // update_server_xml_file_name // rest globals - $this->target = $_backup_target; - $this->lang = $_backup_lang; + $this->target = $_backup_target; + $this->lang = $_backup_lang; $this->langPrefix = $_backup_langPrefix; - unset($this->placeholders[$this->bbb . 'Module_name' . $this->ddd]); + unset( + $this->placeholders[$this->bbb . 'Module_name' . $this->ddd] + ); unset($this->placeholders[$this->bbb . 'Module' . $this->ddd]); unset($this->placeholders[$this->bbb . 'module' . $this->ddd]); - unset($this->placeholders[$this->bbb . 'module.version' . $this->ddd]); - unset($this->placeholders[$this->bbb . 'module_version' . $this->ddd]); + unset( + $this->placeholders[$this->bbb . 'module.version' + . $this->ddd] + ); + unset( + $this->placeholders[$this->bbb . 'module_version' + . $this->ddd] + ); $this->joomlaModules[$id] = $module; return true; } } + return false; } @@ -6832,16 +8845,26 @@ class Get public function getModuleXMLTemplate(&$module) { $xml = ''; - $xml .= PHP_EOL . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $module->lang_prefix . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'BUILDDATE' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'AUTHOR' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'AUTHOREMAIL' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'AUTHORWEBSITE' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'COPYRIGHT' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'LICENSE' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $module->module_version . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $module->lang_prefix . '_XML_DESCRIPTION'; + $xml .= PHP_EOL . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $module->lang_prefix + . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh + . 'BUILDDATE' . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'AUTHOR' + . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh + . 'AUTHOREMAIL' . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh + . 'AUTHORWEBSITE' . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh + . 'COPYRIGHT' . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'LICENSE' + . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $module->module_version + . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $module->lang_prefix + . '_XML_DESCRIPTION'; $xml .= $this->hhh . 'MAINXML' . $this->hhh; $xml .= PHP_EOL . ''; @@ -6850,44 +8873,54 @@ class Get /** * get the Joomla plugins IDs - * + * * @return array of IDs on success - * + * */ protected function getPluginIDs() { - if (($addjoomla_plugins = ComponentbuilderHelper::getVar('component_plugins', $this->componentID, 'joomla_component', 'addjoomla_plugins')) !== false) + if (($addjoomla_plugins = ComponentbuilderHelper::getVar( + 'component_plugins', $this->componentID, 'joomla_component', + 'addjoomla_plugins' + )) !== false) { - $addjoomla_plugins = (ComponentbuilderHelper::checkJson($addjoomla_plugins)) ? json_decode($addjoomla_plugins, true) : null; + $addjoomla_plugins = (ComponentbuilderHelper::checkJson( + $addjoomla_plugins + )) ? json_decode($addjoomla_plugins, true) : null; if (ComponentbuilderHelper::checkArray($addjoomla_plugins)) { $joomla_plugins = array_filter( array_values($addjoomla_plugins), - function($array){ - // only load the plugins whose target association call for it - if (!isset($array['target']) || $array['target'] != 2) - { - return true; + function ($array) { + // only load the plugins whose target association call for it + if (!isset($array['target']) || $array['target'] != 2) + { + return true; + } + + return false; } - return false; - }); + ); // if we have values we return IDs if (ComponentbuilderHelper::checkArray($joomla_plugins)) { - return array_map(function($array){ - return (int) $array['plugin']; - }, $joomla_plugins); + return array_map( + function ($array) { + return (int) $array['plugin']; + }, $joomla_plugins + ); } } } + return false; } /** * get the Joomla plugin path - * + * * @return string of plugin path on success - * + * */ protected function getPluginPath($id) { @@ -6910,9 +8943,13 @@ class Get ); // from these tables $query->from('#__componentbuilder_joomla_plugin AS a'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_group', 'g') . ' ON (' . $this->db->quoteName('a.joomla_plugin_group') . ' = ' . $this->db->quoteName('g.id') . ')'); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_plugin_group', 'g' + ) . ' ON (' . $this->db->quoteName('a.joomla_plugin_group') + . ' = ' . $this->db->quoteName('g.id') . ')' + ); $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); - $query->where($this->db->quoteName('a.published') . ' >= 1'); $this->db->setQuery($query); $this->db->execute(); if ($this->db->getNumRows()) @@ -6920,27 +8957,38 @@ class Get // get the plugin data $plugin = $this->db->loadObject(); // update the name if it has dynamic values - $plugin->name = $this->setPlaceholders($this->setDynamicValues($plugin->name), $this->globalPlaceholders); + $plugin->name = $this->setPlaceholders( + $this->setDynamicValues($plugin->name), + $this->globalPlaceholders + ); // update the name if it has dynamic values - $plugin->code_name = ComponentbuilderHelper::safeClassFunctionName($plugin->name); + $plugin->code_name + = ComponentbuilderHelper::safeClassFunctionName( + $plugin->name + ); // set plugin folder name $plugin->group = strtolower($plugin->group); // set plugin file name $plugin->file_name = strtolower($plugin->code_name); // set the lang key - $this->langKeys['PLG_' . strtoupper($plugin->group . '_' . $plugin->file_name)] = $plugin->id . '_P|uG!n'; + $this->langKeys['PLG_' . strtoupper( + $plugin->group . '_' . $plugin->file_name + )] + = $plugin->id . '_P|uG!n'; + // return the path return $plugin->group . '/' . $plugin->file_name; } } + return false; } /** * set the Joomla plugins - * + * * @return true - * + * */ public function setJoomlaPlugin($id, &$component) { @@ -6987,10 +9035,30 @@ class Get ); // from these tables $query->from('#__componentbuilder_joomla_plugin AS a'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_group', 'g') . ' ON (' . $this->db->quoteName('a.joomla_plugin_group') . ' = ' . $this->db->quoteName('g.id') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_class_extends', 'e') . ' ON (' . $this->db->quoteName('a.class_extends') . ' = ' . $this->db->quoteName('e.id') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_updates', 'u') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('u.joomla_plugin') . ')'); - $query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_files_folders_urls', 'f') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('f.joomla_plugin') . ')'); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_plugin_group', 'g' + ) . ' ON (' . $this->db->quoteName('a.joomla_plugin_group') + . ' = ' . $this->db->quoteName('g.id') . ')' + ); + $query->join( + 'LEFT', + $this->db->quoteName('#__componentbuilder_class_extends', 'e') + . ' ON (' . $this->db->quoteName('a.class_extends') . ' = ' + . $this->db->quoteName('e.id') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_plugin_updates', 'u' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('u.joomla_plugin') . ')' + ); + $query->join( + 'LEFT', $this->db->quoteName( + '#__componentbuilder_joomla_plugin_files_folders_urls', 'f' + ) . ' ON (' . $this->db->quoteName('a.id') . ' = ' + . $this->db->quoteName('f.joomla_plugin') . ')' + ); $query->where($this->db->quoteName('a.id') . ' = ' . (int) $id); $query->where($this->db->quoteName('a.published') . ' >= 1'); $this->db->setQuery($query); @@ -7000,70 +9068,131 @@ class Get // get the plugin data $plugin = $this->db->loadObject(); // tweak system to set stuff to the plugin domain - $_backup_target = $this->target; - $_backup_lang = $this->lang; + $_backup_target = $this->target; + $_backup_lang = $this->lang; $_backup_langPrefix = $this->langPrefix; // set some keys $plugin->target_type = 'P|uG!n'; - $plugin->key = $plugin->id . '_' . $plugin->target_type; + $plugin->key = $plugin->id . '_' . $plugin->target_type; // update to point to plugin $this->target = $plugin->key; - $this->lang = $plugin->key; + $this->lang = $plugin->key; // set version if not set if (empty($plugin->plugin_version)) { $plugin->plugin_version = '1.0.0'; } // set GUI mapper - $guiMapper = array( 'table' => 'joomla_plugin', 'id' => (int) $id, 'type' => 'php'); + $guiMapper = array('table' => 'joomla_plugin', + 'id' => (int) $id, 'type' => 'php'); // update the name if it has dynamic values - $plugin->name = $this->setPlaceholders($this->setDynamicValues($plugin->name), $this->placeholders); + $plugin->name = $this->setPlaceholders( + $this->setDynamicValues($plugin->name), $this->placeholders + ); // update the name if it has dynamic values - $plugin->code_name = ComponentbuilderHelper::safeClassFunctionName($plugin->name); + $plugin->code_name + = ComponentbuilderHelper::safeClassFunctionName( + $plugin->name + ); // set official name - $plugin->official_name = ucwords($plugin->group . ' - ' . $plugin->name); + $plugin->official_name = ucwords( + $plugin->group . ' - ' . $plugin->name + ); // set langPrefix - $this->langPrefix = 'PLG_' . strtoupper($plugin->group) . '_' . strtoupper($plugin->code_name); + $this->langPrefix = 'PLG_' . strtoupper($plugin->group) . '_' + . strtoupper($plugin->code_name); // set lang prefix $plugin->lang_prefix = $this->langPrefix; // set plugin class name - $plugin->class_name = 'Plg' . ucfirst($plugin->group) . ucfirst($plugin->code_name); + $plugin->class_name = 'Plg' . ucfirst($plugin->group) . ucfirst( + $plugin->code_name + ); // set plugin install class name - $plugin->installer_class_name = 'plg' . ucfirst($plugin->group) . ucfirst($plugin->code_name) . 'InstallerScript'; + $plugin->installer_class_name = 'plg' . ucfirst($plugin->group) + . ucfirst($plugin->code_name) . 'InstallerScript'; // set plugin folder name - $plugin->folder_name = 'plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->code_name); + $plugin->folder_name = 'plg_' . strtolower($plugin->group) . '_' + . strtolower($plugin->code_name); // set the zip name - $plugin->zip_name = $plugin->folder_name . '_v' . str_replace('.', '_', $plugin->plugin_version). '__J' . $this->joomlaVersion; + $plugin->zip_name = $plugin->folder_name . '_v' . str_replace( + '.', '_', $plugin->plugin_version + ) . '__J' . $this->joomlaVersion; // set plugin file name $plugin->file_name = strtolower($plugin->code_name); + // set plugin context + $plugin->context = $plugin->folder_name . '.' . $plugin->id; // set official_name lang strings - $this->setLangContent($plugin->key, $this->langPrefix, $plugin->official_name); + $this->setLangContent( + $plugin->key, $this->langPrefix, $plugin->official_name + ); // set some placeholder for this plugin - $this->placeholders[$this->bbb . 'Plugin_name' . $this->ddd] = $plugin->official_name; - $this->placeholders[$this->bbb . 'Plugin' . $this->ddd] = ucfirst($plugin->code_name); - $this->placeholders[$this->bbb . 'plugin' . $this->ddd] = strtolower($plugin->code_name); - $this->placeholders[$this->bbb . 'Plugin_group' . $this->ddd] = ucfirst($plugin->group); - $this->placeholders[$this->bbb . 'plugin_group' . $this->ddd] = strtolower($plugin->group); - $this->placeholders[$this->bbb . 'plugin.version' . $this->ddd] = $plugin->plugin_version; - $this->placeholders[$this->bbb . 'plugin_version' . $this->ddd] = str_replace('.', '_', $plugin->plugin_version); + $this->placeholders[$this->bbb . 'Plugin_name' . $this->ddd] + = $plugin->official_name; + $this->placeholders[$this->bbb . 'Plugin' . $this->ddd] + = ucfirst( + $plugin->code_name + ); + $this->placeholders[$this->bbb . 'plugin' . $this->ddd] + = strtolower( + $plugin->code_name + ); + $this->placeholders[$this->bbb . 'Plugin_group' . $this->ddd] + = ucfirst( + $plugin->group + ); + $this->placeholders[$this->bbb . 'plugin_group' . $this->ddd] + = strtolower( + $plugin->group + ); + $this->placeholders[$this->bbb . 'plugin.version' . $this->ddd] + = $plugin->plugin_version; + $this->placeholders[$this->bbb . 'plugin_version' . $this->ddd] + = str_replace( + '.', '_', $plugin->plugin_version + ); // set description (TODO) add description field to plugin - if (!isset($plugin->description) || !ComponentbuilderHelper::checkString($plugin->description)) + if (!isset($plugin->description) + || !ComponentbuilderHelper::checkString( + $plugin->description + )) { $plugin->description = ''; } else { - $plugin->description = $this->setPlaceholders($this->setDynamicValues($plugin->description), $this->placeholders); - $this->setLangContent($plugin->key, $plugin->lang_prefix . '_DESCRIPTION', $plugin->description); - $plugin->description = '

' . $plugin->description . '

'; + $plugin->description = $this->setPlaceholders( + $this->setDynamicValues($plugin->description), + $this->placeholders + ); + $this->setLangContent( + $plugin->key, $plugin->lang_prefix . '_DESCRIPTION', + $plugin->description + ); + $plugin->description = '

' . $plugin->description + . '

'; } - $plugin->xml_description = "

" . $plugin->official_name . " (v." . $plugin->plugin_version . ")

" . $plugin->description . "

Created by " . trim(JFilterOutput::cleanText($component->author)) . "
Development started " . JFactory::getDate($plugin->created)->format("jS F, Y") . "

"; + $plugin->xml_description = "

" . $plugin->official_name + . " (v." . $plugin->plugin_version + . ")

" + . $plugin->description . "

Created by " . trim( + JFilterOutput::cleanText($component->author) + ) . "
Development started " + . JFactory::getDate($plugin->created)->format("jS F, Y") + . "

"; // set xml discription - $this->setLangContent($plugin->key, $plugin->lang_prefix . '_XML_DESCRIPTION', $plugin->xml_description); + $this->setLangContent( + $plugin->key, $plugin->lang_prefix . '_XML_DESCRIPTION', + $plugin->xml_description + ); // update the readme if set if ($plugin->addreadme == 1 && !empty($plugin->readme)) { - $plugin->readme = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->readme)), $this->placeholders); + $plugin->readme = $this->setPlaceholders( + $this->setDynamicValues(base64_decode($plugin->readme)), + $this->placeholders + ); } else { @@ -7077,9 +9206,13 @@ class Get $guiMapper['field'] = 'main_class_code'; // base64 Decode main_class_code. $plugin->main_class_code = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->main_class_code)), $this->placeholders), + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($plugin->main_class_code) + ), $this->placeholders + ), $guiMapper - ); + ); } // set the head :) if ($plugin->add_head == 1 && !empty($plugin->head)) @@ -7088,21 +9221,29 @@ class Get $guiMapper['field'] = 'head'; // base64 Decode head. $plugin->head = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->head)), $this->placeholders), + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($plugin->head) + ), $this->placeholders + ), $guiMapper - ); + ); } elseif (!empty($plugin->class_head)) { // base64 Decode head. $plugin->head = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->class_head)), $this->placeholders), + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($plugin->class_head) + ), $this->placeholders + ), array( 'table' => 'class_extends', 'field' => 'head', - 'id' => (int) $plugin->class_id, - 'type' => 'php') - ); + 'id' => (int) $plugin->class_id, + 'type' => 'php') + ); } unset($plugin->class_head); // set the comment @@ -7110,49 +9251,72 @@ class Get { // base64 Decode comment. $plugin->comment = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->comment)), $this->placeholders), + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($plugin->comment) + ), $this->placeholders + ), array( 'table' => 'class_extends', 'field' => 'comment', - 'id' => (int) $plugin->class_id, - 'type' => 'php') - ); + 'id' => (int) $plugin->class_id, + 'type' => 'php') + ); } // start the config array $plugin->config_fields = array(); // create the form arrays - $plugin->form_files = array(); + $plugin->form_files = array(); $plugin->fieldsets_label = array(); $plugin->fieldsets_paths = array(); // set global fields rule to default component path $plugin->fields_rules_paths = 1; // set the fields data - $plugin->fields = (isset($plugin->fields) && ComponentbuilderHelper::checkJson($plugin->fields)) ? json_decode($plugin->fields, true) : null; + $plugin->fields = (isset($plugin->fields) + && ComponentbuilderHelper::checkJson($plugin->fields)) + ? json_decode($plugin->fields, true) : null; if (ComponentbuilderHelper::checkArray($plugin->fields)) { // ket global key - $key = $plugin->key; - $dynamic_fields = array('fieldset' => 'basic', 'fields_name' => 'params', 'file' => 'config'); + $key = $plugin->key; + $dynamic_fields = array('fieldset' => 'basic', + 'fields_name' => 'params', + 'file' => 'config'); foreach ($plugin->fields as $n => &$form) { - if (isset($form['fields']) && ComponentbuilderHelper::checkArray($form['fields'])) + if (isset($form['fields']) + && ComponentbuilderHelper::checkArray( + $form['fields'] + )) { // make sure the dynamic_field is set to dynamic_value by default - foreach ($dynamic_fields as $dynamic_field => $dynamic_value) + foreach ( + $dynamic_fields as $dynamic_field => + $dynamic_value + ) { - if (!isset($form[$dynamic_field]) || !ComponentbuilderHelper::checkString($form[$dynamic_field])) + if (!isset($form[$dynamic_field]) + || !ComponentbuilderHelper::checkString( + $form[$dynamic_field] + )) { $form[$dynamic_field] = $dynamic_value; } else { - if ('fields_name' === $dynamic_field && strpos($form[$dynamic_field], '.') !== false) + if ('fields_name' === $dynamic_field + && strpos($form[$dynamic_field], '.') + !== false) { - $form[$dynamic_field] = $form[$dynamic_field]; + $form[$dynamic_field] + = $form[$dynamic_field]; } else { - $form[$dynamic_field] = ComponentbuilderHelper::safeString($form[$dynamic_field]); + $form[$dynamic_field] + = ComponentbuilderHelper::safeString( + $form[$dynamic_field] + ); } } } @@ -7160,73 +9324,109 @@ class Get if (!isset($form['plugin']) || $form['plugin'] != 1) { // now build the form key - $unique = $form['file'] . $form['fields_name'] . $form['fieldset']; + $unique = $form['file'] . $form['fields_name'] + . $form['fieldset']; } else { // now build the form key - $unique = $form['fields_name'] . $form['fieldset']; + $unique = $form['fields_name'] + . $form['fieldset']; } // set global fields rule path switchs - if ($plugin->fields_rules_paths == 1 && isset($form['fields_rules_paths']) && $form['fields_rules_paths'] == 2) + if ($plugin->fields_rules_paths == 1 + && isset($form['fields_rules_paths']) + && $form['fields_rules_paths'] == 2) { $plugin->fields_rules_paths = 2; } // set where to path is pointing - $plugin->fieldsets_paths[$unique] = $form['fields_rules_paths']; + $plugin->fieldsets_paths[$unique] + = $form['fields_rules_paths']; // add the label if set to lang - if (isset($form['label']) && ComponentbuilderHelper::checkString($form['label'])) + if (isset($form['label']) + && ComponentbuilderHelper::checkString( + $form['label'] + )) { - $plugin->fieldsets_label[$unique] = $this->setLang($form['label']); + $plugin->fieldsets_label[$unique] + = $this->setLang($form['label']); } // build the fields - $form['fields'] = array_map(function($field) use ($key, $unique){ - // make sure the alias and title is 0 - $field['alias'] = 0; - $field['title'] = 0; - // set the field details - $this->setFieldDetails($field, $key, $key, $unique); - // update the default if set - if (ComponentbuilderHelper::checkString($field['custom_value']) && isset($field['settings'])) - { - if (($old_default = ComponentbuilderHelper::getBetween($field['settings']->xml, 'default="', '"', false)) !== false) + $form['fields'] = array_map( + function ($field) use ($key, $unique) { + // make sure the alias and title is 0 + $field['alias'] = 0; + $field['title'] = 0; + // set the field details + $this->setFieldDetails( + $field, $key, $key, $unique + ); + // update the default if set + if (ComponentbuilderHelper::checkString( + $field['custom_value'] + ) + && isset($field['settings'])) { - // replace old default - $field['settings']->xml = str_replace('default="' . $old_default . '"', 'default="' . $field['custom_value'] . '"', $field['settings']->xml); + if (($old_default + = ComponentbuilderHelper::getBetween( + $field['settings']->xml, + 'default="', '"', false + )) !== false) + { + // replace old default + $field['settings']->xml + = str_replace( + 'default="' . $old_default + . '"', 'default="' + . $field['custom_value'] . '"', + $field['settings']->xml + ); + } + else + { + // add the default (hmmm not ideal but okay it should work) + $field['settings']->xml + = 'default="' + . $field['custom_value'] . '" ' + . $field['settings']->xml; + } } - else - { - // add the default (hmmm not ideal but okay it should work) - $field['settings']->xml = 'default="' . $field['custom_value'] . '" ' . $field['settings']->xml; - } - } - unset($field['custom_value']); - // return field - return $field; - }, array_values($form['fields'])); + unset($field['custom_value']); + + // return field + return $field; + }, array_values($form['fields']) + ); // check if field is external form file if (!isset($form['plugin']) || $form['plugin'] != 1) { // load the form file if (!isset($plugin->form_files[$form['file']])) { - $plugin->form_files[$form['file']] = array(); + $plugin->form_files[$form['file']] + = array(); } if (!isset($plugin->form_files[$form['file']][$form['fields_name']])) { - $plugin->form_files[$form['file']][$form['fields_name']] = array(); + $plugin->form_files[$form['file']][$form['fields_name']] + = array(); } if (!isset($plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']])) { - $plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']] = array(); + $plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']] + = array(); } // do some house cleaning (for fields) foreach ($form['fields'] as $field) { // so first we lock the field name in - $this->getFieldName($field, $plugin->key, $unique); + $this->getFieldName( + $field, $plugin->key, $unique + ); // add the fields to the global form file builder - $plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']][] = $field; + $plugin->form_files[$form['file']][$form['fields_name']][$form['fieldset']][] + = $field; } // remove form unset($plugin->fields[$n]); @@ -7236,19 +9436,24 @@ class Get // load the config form if (!isset($plugin->config_fields[$form['fields_name']])) { - $plugin->config_fields[$form['fields_name']] = array(); + $plugin->config_fields[$form['fields_name']] + = array(); } if (!isset($plugin->config_fields[$form['fields_name']][$form['fieldset']])) { - $plugin->config_fields[$form['fields_name']][$form['fieldset']] = array(); + $plugin->config_fields[$form['fields_name']][$form['fieldset']] + = array(); } // do some house cleaning (for fields) foreach ($form['fields'] as $field) { // so first we lock the field name in - $this->getFieldName($field, $plugin->key, $unique); + $this->getFieldName( + $field, $plugin->key, $unique + ); // add the fields to the config builder - $plugin->config_fields[$form['fields_name']][$form['fieldset']][] = $field; + $plugin->config_fields[$form['fields_name']][$form['fieldset']][] + = $field; } // remove form unset($plugin->fields[$n]); @@ -7262,14 +9467,29 @@ class Get } unset($plugin->fields); // set the add targets - $addArray = array('files' => 'files', 'folders' => 'folders', 'urls' => 'urls', 'filesfullpath' => 'files', 'foldersfullpath' => 'folders'); + $addArray = array('files' => 'files', + 'folders' => 'folders', + 'urls' => 'urls', + 'filesfullpath' => 'files', + 'foldersfullpath' => 'folders'); foreach ($addArray as $addTarget => $targetHere) { // set the add target data - $plugin->{'add' . $addTarget} = (isset($plugin->{'add' . $addTarget}) && ComponentbuilderHelper::checkJson($plugin->{'add' . $addTarget})) ? json_decode($plugin->{'add' . $addTarget}, true) : null; - if (ComponentbuilderHelper::checkArray($plugin->{'add' . $addTarget})) + $plugin->{'add' . $addTarget} = (isset( + $plugin->{'add' . $addTarget} + ) + && ComponentbuilderHelper::checkJson( + $plugin->{'add' . $addTarget} + )) ? json_decode($plugin->{'add' . $addTarget}, true) + : null; + if (ComponentbuilderHelper::checkArray( + $plugin->{'add' . $addTarget} + )) { - if (isset($plugin->{$targetHere}) && ComponentbuilderHelper::checkArray($plugin->{$targetHere})) + if (isset($plugin->{$targetHere}) + && ComponentbuilderHelper::checkArray( + $plugin->{$targetHere} + )) { foreach ($plugin->{'add' . $addTarget} as $taget) { @@ -7278,25 +9498,47 @@ class Get } else { - $plugin->{$targetHere} = array_values($plugin->{'add' . $addTarget}); + $plugin->{$targetHere} = array_values( + $plugin->{'add' . $addTarget} + ); } } unset($plugin->{'add' . $addTarget}); } // add PHP in plugin install $plugin->add_install_script = false; - $addScriptMethods = array('php_preflight', 'php_postflight', 'php_method'); - $addScriptTypes = array('install', 'update', 'uninstall'); + $addScriptMethods = array('php_preflight', + 'php_postflight', + 'php_method'); + $addScriptTypes = array('install', 'update', + 'uninstall'); foreach ($addScriptMethods as $scriptMethod) { foreach ($addScriptTypes as $scriptType) { - if (isset($plugin->{'add_' . $scriptMethod . '_' . $scriptType}) && $plugin->{'add_' . $scriptMethod . '_' . $scriptType} == 1 && ComponentbuilderHelper::checkString($plugin->{$scriptMethod . '_' . $scriptType})) + if (isset( + $plugin->{'add_' . $scriptMethod . '_' + . $scriptType} + ) + && $plugin->{'add_' . $scriptMethod . '_' + . $scriptType} == 1 + && ComponentbuilderHelper::checkString( + $plugin->{$scriptMethod . '_' . $scriptType} + )) { // set GUI mapper field - $guiMapper['field'] = $scriptMethod . '_' . $scriptType; - $plugin->{$scriptMethod . '_' . $scriptType} = $this->setGuiCodePlaceholder( - $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->{$scriptMethod . '_' . $scriptType})), $this->placeholders), + $guiMapper['field'] = $scriptMethod . '_' + . $scriptType; + $plugin->{$scriptMethod . '_' . $scriptType} + = $this->setGuiCodePlaceholder( + $this->setPlaceholders( + $this->setDynamicValues( + base64_decode( + $plugin->{$scriptMethod . '_' + . $scriptType} + ) + ), $this->placeholders + ), $guiMapper ); $plugin->add_install_script = true; @@ -7304,14 +9546,20 @@ class Get else { unset($plugin->{$scriptMethod . '_' . $scriptType}); - $plugin->{'add_' . $scriptMethod . '_' . $scriptType} = 0; + $plugin->{'add_' . $scriptMethod . '_' + . $scriptType} + = 0; } } } // add_sql - if ($plugin->add_sql == 1 && ComponentbuilderHelper::checkString($plugin->sql)) + if ($plugin->add_sql == 1 + && ComponentbuilderHelper::checkString($plugin->sql)) { - $plugin->sql = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->sql)), $this->placeholders); + $plugin->sql = $this->setPlaceholders( + $this->setDynamicValues(base64_decode($plugin->sql)), + $this->placeholders + ); } else { @@ -7319,9 +9567,16 @@ class Get $plugin->add_sql = 0; } // add_sql_uninstall - if ($plugin->add_sql_uninstall == 1 && ComponentbuilderHelper::checkString($plugin->sql_uninstall)) - { - $plugin->sql_uninstall = $this->setPlaceholders($this->setDynamicValues(base64_decode($plugin->sql_uninstall)), $this->placeholders); + if ($plugin->add_sql_uninstall == 1 + && ComponentbuilderHelper::checkString( + $plugin->sql_uninstall + )) + { + $plugin->sql_uninstall = $this->setPlaceholders( + $this->setDynamicValues( + base64_decode($plugin->sql_uninstall) + ), $this->placeholders + ); } else { @@ -7329,18 +9584,31 @@ class Get $plugin->add_sql_uninstall = 0; } // update the URL of the update_server if set - if ($plugin->add_update_server == 1 && ComponentbuilderHelper::checkString($plugin->update_server_url)) + if ($plugin->add_update_server == 1 + && ComponentbuilderHelper::checkString( + $plugin->update_server_url + )) { - $plugin->update_server_url = $this->setPlaceholders($this->setDynamicValues($plugin->update_server_url), $this->placeholders); + $plugin->update_server_url = $this->setPlaceholders( + $this->setDynamicValues($plugin->update_server_url), + $this->placeholders + ); } // add the update/sales server FTP details if that is the expected protocol $serverArray = array('update_server', 'sales_server'); foreach ($serverArray as $server) { - if ($plugin->{'add_' . $server} == 1 && is_numeric($plugin->{$server}) && $plugin->{$server} > 0) + if ($plugin->{'add_' . $server} == 1 + && is_numeric( + $plugin->{$server} + ) + && $plugin->{$server} > 0) { // get the server protocol - $plugin->{$server . '_protocol'} = ComponentbuilderHelper::getVar('server', (int) $plugin->{$server}, 'id', 'protocol'); + $plugin->{$server . '_protocol'} + = ComponentbuilderHelper::getVar( + 'server', (int) $plugin->{$server}, 'id', 'protocol' + ); } else { @@ -7358,45 +9626,70 @@ class Get // update_server_xml_file_name // rest globals - $this->target = $_backup_target; - $this->lang = $_backup_lang; + $this->target = $_backup_target; + $this->lang = $_backup_lang; $this->langPrefix = $_backup_langPrefix; - unset($this->placeholders[$this->bbb . 'Plugin_name' . $this->ddd]); + unset( + $this->placeholders[$this->bbb . 'Plugin_name' . $this->ddd] + ); unset($this->placeholders[$this->bbb . 'Plugin' . $this->ddd]); unset($this->placeholders[$this->bbb . 'plugin' . $this->ddd]); - unset($this->placeholders[$this->bbb . 'Plugin_group' . $this->ddd]); - unset($this->placeholders[$this->bbb . 'plugin_group' . $this->ddd]); - unset($this->placeholders[$this->bbb . 'plugin.version' . $this->ddd]); - unset($this->placeholders[$this->bbb . 'plugin_version' . $this->ddd]); + unset( + $this->placeholders[$this->bbb . 'Plugin_group' + . $this->ddd] + ); + unset( + $this->placeholders[$this->bbb . 'plugin_group' + . $this->ddd] + ); + unset( + $this->placeholders[$this->bbb . 'plugin.version' + . $this->ddd] + ); + unset( + $this->placeholders[$this->bbb . 'plugin_version' + . $this->ddd] + ); $this->joomlaPlugins[$id] = $plugin; return true; } } + return false; } /** * get the plugin xml template - * + * * @return string - * + * */ public function getPluginXMLTemplate(&$plugin) { $xml = ''; - $xml .= PHP_EOL . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $plugin->lang_prefix . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'BUILDDATE' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'AUTHOR' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'AUTHOREMAIL' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'AUTHORWEBSITE' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'COPYRIGHT' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'LICENSE' . $this->hhh . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $plugin->plugin_version . ''; - $xml .= PHP_EOL . $this->_t(1) . '' . $plugin->lang_prefix . '_XML_DESCRIPTION'; + $xml .= PHP_EOL . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $plugin->lang_prefix + . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh + . 'BUILDDATE' . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'AUTHOR' + . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh + . 'AUTHOREMAIL' . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh + . 'AUTHORWEBSITE' . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh + . 'COPYRIGHT' . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $this->hhh . 'LICENSE' + . $this->hhh . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $plugin->plugin_version + . ''; + $xml .= PHP_EOL . $this->_t(1) . '' . $plugin->lang_prefix + . '_XML_DESCRIPTION'; $xml .= $this->hhh . 'MAINXML' . $this->hhh; $xml .= PHP_EOL . ''; @@ -7405,9 +9698,9 @@ class Get /** * check if we already have these ids in local memory - * + * * @return void - * + * */ protected function checkCustomCodeMemory($ids) { @@ -7426,28 +9719,34 @@ class Get { return $ids; } + return false; } /** * store the code - * - * @param int $when To set when to update + * + * @param int $when To set when to update * * @return void - * + * */ protected function setNewCustomCode($when = 1) { if (count((array) $this->newCustomCode) >= $when) { // Create a new query object. - $query = $this->db->getQuery(true); + $query = $this->db->getQuery(true); $continue = false; // Insert columns. - $columns = array('path', 'type', 'target', 'comment_type', 'component', 'published', 'created', 'created_by', 'version', 'access', 'hashtarget', 'from_line', 'to_line', 'code', 'hashendtarget'); + $columns = array('path', 'type', 'target', 'comment_type', + 'component', 'published', 'created', 'created_by', + 'version', 'access', 'hashtarget', 'from_line', + 'to_line', 'code', 'hashendtarget'); // Prepare the insert query. - $query->insert($this->db->quoteName('#__componentbuilder_custom_code')); + $query->insert( + $this->db->quoteName('#__componentbuilder_custom_code') + ); $query->columns($this->db->quoteName($columns)); foreach ($this->newCustomCode as $values) { @@ -7475,11 +9774,11 @@ class Get /** * store the code - * - * @param int $when To set when to update + * + * @param int $when To set when to update * * @return void - * + * */ protected function setExistingCustomCode($when = 1) { @@ -7490,7 +9789,9 @@ class Get // Create a new query object. $query = $this->db->getQuery(true); // Prepare the update query. - $query->update($this->db->quoteName('#__componentbuilder_custom_code'))->set($code['fields'])->where($code['conditions']); + $query->update( + $this->db->quoteName('#__componentbuilder_custom_code') + )->set($code['fields'])->where($code['conditions']); // Set the query using our newly populated query object and execute it. $this->db->setQuery($query); $this->db->execute(); @@ -7502,26 +9803,37 @@ class Get /** * get the custom code from the local files - * + * * @param array $paths The local paths to parse * @param string $today The date for today * * @return void - * + * */ protected function customCodeFactory(&$paths, &$today) { // we must first store the current woking directory - $joomla = getcwd(); + $joomla = getcwd(); $counter = array(1 => 0, 2 => 0); // file types to get $fileTypes = array('\.php', '\.js', '\.xml'); // set some local placeholders - $placeholders = array_flip($this->globalPlaceholders); - $placeholders[ComponentbuilderHelper::safeString($this->componentCodeName, 'F') . 'Helper::'] = $this->bbb . 'Component' . $this->ddd . 'Helper::'; - $placeholders['COM_' . ComponentbuilderHelper::safeString($this->componentCodeName, 'U')] = 'COM_' . $this->bbb . 'COMPONENT' . $this->ddd; - $placeholders['com_' . $this->componentCodeName] = 'com_' . $this->bbb . 'component' . $this->ddd; + $placeholders = array_flip( + $this->globalPlaceholders + ); + $placeholders[ComponentbuilderHelper::safeString( + $this->componentCodeName, 'F' + ) . 'Helper::'] + = $this->bbb + . 'Component' . $this->ddd . 'Helper::'; + $placeholders['COM_' . ComponentbuilderHelper::safeString( + $this->componentCodeName, 'U' + )] + = 'COM_' . $this->bbb + . 'COMPONENT' . $this->ddd; + $placeholders['com_' . $this->componentCodeName] = 'com_' . $this->bbb + . 'component' . $this->ddd; // putt the last first $placeholders = array_reverse($placeholders, true); @@ -7538,14 +9850,21 @@ class Get { foreach ($files as $file) { - $this->searchFileContent($counter, $file, $target, $this->customCodePlaceholders, $placeholders, $today); + $this->searchFileContent( + $counter, $file, $target, + $this->customCodePlaceholders, $placeholders, $today + ); // insert new code - if (ComponentbuilderHelper::checkArray($this->newCustomCode)) + if (ComponentbuilderHelper::checkArray( + $this->newCustomCode + )) { $this->setNewCustomCode(100); } // update existing custom code - if (ComponentbuilderHelper::checkArray($this->existingCustomCode)) + if (ComponentbuilderHelper::checkArray( + $this->existingCustomCode + )) { $this->setExistingCustomCode(30); } @@ -7569,33 +9888,34 @@ class Get /** * search a file for placeholders and store result - * - * @param array $counter The counter for the arrays - * @param string $file The file path to search - * @param array $searchArray The values to search for - * @param array $placeholders The values to replace in the code being stored - * @param string $today The date for today + * + * @param array $counter The counter for the arrays + * @param string $file The file path to search + * @param array $searchArray The values to search for + * @param array $placeholders The values to replace in the code being stored + * @param string $today The date for today * * @return array on success - * + * */ - protected function searchFileContent(&$counter, &$file, &$target, &$searchArray, &$placeholders, &$today) - { + protected function searchFileContent(&$counter, &$file, &$target, + &$searchArray, &$placeholders, &$today + ) { // we add a new search for the GUI CODE Blocks $this->guiCodeSearch($file, $placeholders, $today, $target); // reset each time per file $loadEndFingerPrint = false; - $endFingerPrint = array(); - $fingerPrint = array(); - $codeBucket = array(); - $pointer = array(); - $reading = array(); - $reader = 0; + $endFingerPrint = array(); + $fingerPrint = array(); + $codeBucket = array(); + $pointer = array(); + $reading = array(); + $reader = 0; // reset found Start type $commentType = 0; // make sure we have the path correct (the script file is not in admin path for example) // there may be more... will nead to keep our eye on this... since files could be moved during install - $file = str_replace( './', '', $file); # TODO (windows path issues) + $file = str_replace('./', '', $file); # TODO (windows path issues) if ($file !== 'script.php') { $path = $target . '/' . $file; @@ -7616,22 +9936,32 @@ class Get } foreach ($searchArray as $type => $search) { - $i = (int) ($type == 3 || $type == 4) ? 2 : 1; + $i = (int) ($type == 3 || $type == 4) ? 2 : 1; $_type = (int) ($type == 1 || $type == 3) ? 1 : 2; if ($reader === 0 || $reader === $i) { $targetKey = $type; - $start = '/***[' . $search . '***/'; - $end = '/***[/' . $search . '***/'; + $start = '/***[' . $search . '***/'; + $end = '/***[/' . $search . '***/'; $startHTML = ''; - $endHTML = ''; + $endHTML = ''; // check if the ending place holder was found - if (isset($reading[$targetKey]) && $reading[$targetKey] && - ((trim($lineContent) === $end || strpos($lineContent, $end) !== false) || - (trim($lineContent) === $endHTML || strpos($lineContent, $endHTML) !== false))) + if (isset($reading[$targetKey]) && $reading[$targetKey] + && ((trim($lineContent) === $end + || strpos( + $lineContent, $end + ) !== false) + || (trim($lineContent) === $endHTML + || strpos( + $lineContent, $endHTML + ) !== false))) { // trim the placeholder and if there is still data then load it - if (isset($endReplace) && ($_line = $this->addLineChecker($endReplace, 2, $lineContent)) !== false) + if (isset($endReplace) + && ($_line + = $this->addLineChecker( + $endReplace, 2, $lineContent + )) !== false) { $codeBucket[$pointer[$targetKey]][] = $_line; } @@ -7646,55 +9976,82 @@ class Get { // activate fingerPrint for replacement end target $loadEndFingerPrint = true; - $backupTargetKey = $targetKey; - $backupI = $i; + $backupTargetKey = $targetKey; + $backupI = $i; } // all new records we can do a bulk insert if ($i === 1) { // end the bucket info for this code block - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote((int) $lineNumber); // 'toline' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + (int) $lineNumber + ); // 'toline' // first reverse engineer this code block - $c0de = $this->reversePlaceholders(implode('', $codeBucket[$pointer[$targetKey]]), $placeholders, $target); - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote(base64_encode($c0de)); // 'code' + $c0de = $this->reversePlaceholders( + implode('', $codeBucket[$pointer[$targetKey]]), + $placeholders, $target + ); + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + base64_encode($c0de) + ); // 'code' if ($_type == 2) { // load the last value - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote(0); // 'hashendtarget' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote(0); // 'hashendtarget' } } // the record already exist so we must update instead elseif ($i === 2) { // end the bucket info for this code block - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('to_line') . ' = ' . $this->db->quote($lineNumber); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('to_line') . ' = ' + . $this->db->quote($lineNumber); // first reverse engineer this code block - $c0de = $this->reversePlaceholders(implode('', $codeBucket[$pointer[$targetKey]]), $placeholders, $target, $this->existingCustomCode[$pointer[$targetKey]]['id']); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('code') . ' = ' . $this->db->quote(base64_encode($c0de)); + $c0de = $this->reversePlaceholders( + implode('', $codeBucket[$pointer[$targetKey]]), + $placeholders, $target, + $this->existingCustomCode[$pointer[$targetKey]]['id'] + ); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('code') . ' = ' + . $this->db->quote(base64_encode($c0de)); if ($_type == 2) { // load the last value - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('hashendtarget') . ' = ' . $this->db->quote(0); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('hashendtarget') + . ' = ' . $this->db->quote(0); } } } // check if the endfingerprint is ready to save if (count((array) $endFingerPrint) === 3) { - $hashendtarget = '3__' . md5(implode('', $endFingerPrint)); + $hashendtarget = '3__' . md5( + implode('', $endFingerPrint) + ); // all new records we can do a bulk insert if ($i === 1) { // load the last value - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote($hashendtarget); // 'hashendtarget' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + $hashendtarget + ); // 'hashendtarget' } // the record already exist so we must use module to update elseif ($i === 2) { - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('hashendtarget') . ' = ' . $this->db->quote($hashendtarget); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('hashendtarget') . ' = ' + . $this->db->quote($hashendtarget); } // reset the needed values - $endFingerPrint = array(); + $endFingerPrint = array(); $loadEndFingerPrint = false; // deactivate reader (to allow other search) $reader = 0; @@ -7705,18 +10062,23 @@ class Get $codeBucket[$pointer[$targetKey]][] = $lineContent; } // see if the custom code line starts now with PHP/JS comment type - if ((!isset($reading[$targetKey]) || !$reading[$targetKey]) && (($i === 1 && trim($lineContent) === $start) || strpos($lineContent, $start) !== false)) + if ((!isset($reading[$targetKey]) || !$reading[$targetKey]) + && (($i === 1 && trim($lineContent) === $start) + || strpos($lineContent, $start) !== false)) { - $commentType = 1; // PHP/JS type + $commentType = 1; // PHP/JS type $startReplace = $start; - $endReplace = $end; + $endReplace = $end; } // see if the custom code line starts now with HTML comment type - elseif ((!isset($reading[$targetKey]) || !$reading[$targetKey]) && (($i === 1 && trim($lineContent) === $startHTML) || strpos($lineContent, $startHTML) !== false)) + elseif ((!isset($reading[$targetKey]) + || !$reading[$targetKey]) + && (($i === 1 && trim($lineContent) === $startHTML) + || strpos($lineContent, $startHTML) !== false)) { - $commentType = 2; // HTML type + $commentType = 2; // HTML type $startReplace = $startHTML; - $endReplace = $endHTML; + $endReplace = $endHTML; } // check if the starting place holder was found if ($commentType > 0) @@ -7726,15 +10088,27 @@ class Get { // reset found comment type $commentType = 0; - $this->app->enqueueMessage(JText::_('

Custom Codes Warning

'), 'Warning'); - $this->app->enqueueMessage(JText::sprintf('We found dynamic code all in one line, and ignored it! Please review (%s) for more details!', $path), 'Warning'); + $this->app->enqueueMessage( + JText::_('

Custom Codes Warning

'), + 'Warning' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'We found dynamic code all in one line, and ignored it! Please review (%s) for more details!', + $path + ), 'Warning' + ); continue; } // do a quick check to insure we have an id $id = false; if ($i === 2) { - $id = $this->getSystemID($lineContent, array(1 => $start, 2 => $startHTML), $commentType); + $id = $this->getSystemID( + $lineContent, + array(1 => $start, 2 => $startHTML), + $commentType + ); } if ($i === 2 && $id > 0) { @@ -7749,7 +10123,9 @@ class Get $this->codeAreadyDone[$id] = (int) $id; } // start replace - $startReplace = $this->setStartReplace($id, $commentType, $startReplace); + $startReplace = $this->setStartReplace( + $id, $commentType, $startReplace + ); // set active reader (to lock out other search) $reader = $i; // set pointer @@ -7759,64 +10135,129 @@ class Get // start code bucket $codeBucket[$pointer[$targetKey]] = array(); // trim the placeholder and if there is still data then load it - if ($_line = $this->addLineChecker($startReplace, 1, $lineContent)) + if ($_line = $this->addLineChecker( + $startReplace, 1, $lineContent + )) { $codeBucket[$pointer[$targetKey]][] = $_line; } // get the finger print around the custom code - $inFinger = count($fingerPrint); - $getFinger = $inFinger - 1; - $hasharray = array_slice($fingerPrint, -$inFinger, $getFinger, true); - $hasleng = count($hasharray); - $hashtarget = $hasleng . '__' . md5(implode('', $hasharray)); + $inFinger = count($fingerPrint); + $getFinger = $inFinger - 1; + $hasharray = array_slice( + $fingerPrint, -$inFinger, $getFinger, true + ); + $hasleng = count($hasharray); + $hashtarget = $hasleng . '__' . md5( + implode('', $hasharray) + ); // for good practice ComponentbuilderHelper::fixPath($path); // all new records we can do a bulk insert if ($i === 1 || !$id) { // start the bucket for this code - $this->newCustomCode[$pointer[$targetKey]] = array(); - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote($path); // 'path' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote((int) $_type); // 'type' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote(1); // 'target' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote($commentType); // 'comment_type' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote((int) $this->componentID); // 'component' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote(1); // 'published' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote($today); // 'created' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote((int) $this->user->id); // 'created_by' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote(1); // 'version' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote(1); // 'access' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote($hashtarget); // 'hashtarget' - $this->newCustomCode[$pointer[$targetKey]][] = $this->db->quote((int) $lineNumber); // 'fromline' + $this->newCustomCode[$pointer[$targetKey]] + = array(); + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + $path + ); // 'path' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + (int) $_type + ); // 'type' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + 1 + ); // 'target' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + $commentType + ); // 'comment_type' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + (int) $this->componentID + ); // 'component' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + 1 + ); // 'published' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + $today + ); // 'created' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + (int) $this->user->id + ); // 'created_by' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + 1 + ); // 'version' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + 1 + ); // 'access' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + $hashtarget + ); // 'hashtarget' + $this->newCustomCode[$pointer[$targetKey]][] + = $this->db->quote( + (int) $lineNumber + ); // 'fromline' } // the record already exist so we must update instead elseif ($i === 2 && $id > 0) { // start the bucket for this code - $this->existingCustomCode[$pointer[$targetKey]] = array(); - $this->existingCustomCode[$pointer[$targetKey]]['id'] = (int) $id; - $this->existingCustomCode[$pointer[$targetKey]]['conditions'] = array(); - $this->existingCustomCode[$pointer[$targetKey]]['conditions'][] = $this->db->quoteName('id') . ' = ' . $this->db->quote($id); - $this->existingCustomCode[$pointer[$targetKey]]['fields'] = array(); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('path') . ' = ' . $this->db->quote($path); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('type') . ' = ' . $this->db->quote($_type); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('comment_type') . ' = ' . $this->db->quote($commentType); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('component') . ' = ' . $this->db->quote($this->componentID); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('from_line') . ' = ' . $this->db->quote($lineNumber); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('modified') . ' = ' . $this->db->quote($today); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('modified_by') . ' = ' . $this->db->quote($this->user->id); - $this->existingCustomCode[$pointer[$targetKey]]['fields'][] = $this->db->quoteName('hashtarget') . ' = ' . $this->db->quote($hashtarget); + $this->existingCustomCode[$pointer[$targetKey]] + = array(); + $this->existingCustomCode[$pointer[$targetKey]]['id'] + = (int) $id; + $this->existingCustomCode[$pointer[$targetKey]]['conditions'] + = array(); + $this->existingCustomCode[$pointer[$targetKey]]['conditions'][] + = $this->db->quoteName('id') . ' = ' + . $this->db->quote($id); + $this->existingCustomCode[$pointer[$targetKey]]['fields'] + = array(); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('path') . ' = ' + . $this->db->quote($path); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('type') . ' = ' + . $this->db->quote($_type); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('comment_type') . ' = ' + . $this->db->quote($commentType); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('component') . ' = ' + . $this->db->quote($this->componentID); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('from_line') . ' = ' + . $this->db->quote($lineNumber); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('modified') . ' = ' + . $this->db->quote($today); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('modified_by') . ' = ' + . $this->db->quote($this->user->id); + $this->existingCustomCode[$pointer[$targetKey]]['fields'][] + = $this->db->quoteName('hashtarget') . ' = ' + . $this->db->quote($hashtarget); } else // this should actualy never happen { // de activate the reader $reading[$targetKey] = false; - $reader = 0; + $reader = 0; } // reset found comment type $commentType = 0; // update the counter - $counter[$i] ++; + $counter[$i]++; } } } @@ -7831,8 +10272,10 @@ class Get { if (count((array) $endFingerPrint) > 0) { - $leng = count($endFingerPrint); - $hashendtarget = $leng . '__' . md5(implode('', $endFingerPrint)); + $leng = count($endFingerPrint); + $hashendtarget = $leng . '__' . md5( + implode('', $endFingerPrint) + ); } else { @@ -7842,52 +10285,75 @@ class Get if ($backupI === 1) { // load the last value - $this->newCustomCode[$pointer[$backupTargetKey]][] = $this->db->quote($hashendtarget); // 'hashendtarget' + $this->newCustomCode[$pointer[$backupTargetKey]][] + = $this->db->quote($hashendtarget); // 'hashendtarget' } // the record already exist so we must use module to update elseif ($backupI === 2) { - $this->existingCustomCode[$pointer[$backupTargetKey]]['fields'][] = $this->db->quoteName('hashendtarget') . ' = ' . $this->db->quote($hashendtarget); + $this->existingCustomCode[$pointer[$backupTargetKey]]['fields'][] + = $this->db->quoteName('hashendtarget') . ' = ' + . $this->db->quote($hashendtarget); } } } /** * Set the JCB GUI code placeholder - * - * @param string $string The code string - * @param array $config The placeholder config values + * + * @param string $string The code string + * @param array $config The placeholder config values * * @return string - * + * */ public function setGuiCodePlaceholder($string, $config) { if (ComponentbuilderHelper::checkString($string)) { - if ($this->addPlaceholders && $this->canAddGuiCodePlaceholder($string) + if ($this->addPlaceholders + && $this->canAddGuiCodePlaceholder( + $string + ) && ComponentbuilderHelper::checkArray($config) - && isset($config['table']) && ComponentbuilderHelper::checkString($config['table']) - && isset($config['field']) && ComponentbuilderHelper::checkString($config['field']) - && isset($config['type']) && ComponentbuilderHelper::checkString($config['type']) - && isset($config['id']) && is_numeric($config['id'])) + && isset($config['table']) + && ComponentbuilderHelper::checkString($config['table']) + && isset($config['field']) + && ComponentbuilderHelper::checkString($config['field']) + && isset($config['type']) + && ComponentbuilderHelper::checkString($config['type']) + && isset($config['id']) + && is_numeric($config['id'])) { // if we have a key we must get the ID - if (isset($config['key']) && ComponentbuilderHelper::checkString($config['key']) && $config['key'] !== 'id') + if (isset($config['key']) + && ComponentbuilderHelper::checkString($config['key']) + && $config['key'] !== 'id') { - if (($id = ComponentbuilderHelper::getVar($config['table'], $config['id'], $config['key'], 'id')) !== false && is_numeric($id)) + if (($id = ComponentbuilderHelper::getVar( + $config['table'], $config['id'], $config['key'], + 'id' + )) !== false + && is_numeric($id)) { $config['id'] = $id; } else { // we must give a error message to inform the user of this issue. (should never happen) - $this->app->enqueueMessage(JText::sprintf('ID mismatch was detected with the %s.%s.%s.%s GUI code field. So the placeholder was not set.', $config['table'], $config['field'], $config['key'], $config['id']), 'Error'); + $this->app->enqueueMessage( + JText::sprintf( + 'ID mismatch was detected with the %s.%s.%s.%s GUI code field. So the placeholder was not set.', + $config['table'], $config['field'], + $config['key'], $config['id'] + ), 'Error' + ); // check some config if (!isset($config['prefix'])) { $config['prefix'] = ''; } + return $config['prefix'] . $string; } } @@ -7903,35 +10369,39 @@ class Get case 'html': $front = $config['prefix'] . '' . PHP_EOL; - $back = ''); + $guiCode[] = ComponentbuilderHelper::getAllBetween( + $file_conent, '/***[JCB' . 'GUI<>', '/***[/JCBGUI' . '$$$$]***/' + ); + $guiCode[] = ComponentbuilderHelper::getAllBetween( + $file_conent, '' + ); - if (($guiCode = ComponentbuilderHelper::mergeArrays($guiCode)) !== false && ComponentbuilderHelper::checkArray($guiCode, true)) + if (($guiCode = ComponentbuilderHelper::mergeArrays($guiCode)) !== false + && ComponentbuilderHelper::checkArray($guiCode, true)) { foreach ($guiCode as $code) { @@ -7977,7 +10453,8 @@ class Get if (is_array($query) && count($query) >= 3) { // cleanup the newlines around the code - $code = trim(str_replace($first_line, '', $code), PHP_EOL) . PHP_EOL; + $code = trim(str_replace($first_line, '', $code), PHP_EOL) + . PHP_EOL; // set the ID $id = (int) $query[2]; // make the field name save @@ -7985,13 +10462,19 @@ class Get // make the table name save $table = ComponentbuilderHelper::safeString($query[0]); // reverse placeholder as much as we can - $code = $this->reversePlaceholders($code, $placeholders, $target, $id, $field, $table); + $code = $this->reversePlaceholders( + $code, $placeholders, $target, $id, $field, $table + ); // update the GUI/Tables/Database $object = new stdClass(); $object->id = $id; - $object->{$field} = base64_encode($code); // (TODO) this may not always work... + $object->{$field} = base64_encode( + $code + ); // (TODO) this may not always work... // update the value in GUI - $this->db->updateObject('#__componentbuilder_' . (string) $table, $object, 'id'); + $this->db->updateObject( + '#__componentbuilder_' . (string) $table, $object, 'id' + ); } } } @@ -7999,13 +10482,13 @@ class Get /** * Check if this line should be added - * - * @param string $replaceKey The key to remove from line - * @param int $type The line type - * @param string $lineContent The line to check + * + * @param string $replaceKey The key to remove from line + * @param int $type The line type + * @param string $lineContent The line to check * * @return bool true on success - * + * */ protected function addLineChecker($replaceKey, $type, $lineContent) { @@ -8029,18 +10512,19 @@ class Get } break; } + return false; } /** * set the start replace placeholder - * - * @param int $id The comment id - * @param int $commentType The comment type - * @param string $startReplace The main replace string + * + * @param int $id The comment id + * @param int $commentType The comment type + * @param string $startReplace The main replace string * * @return array on success - * + * */ protected function setStartReplace($id, $commentType, $startReplace) { @@ -8056,18 +10540,19 @@ class Get break; } } + return $startReplace; } /** * search for the system id in the line given - * - * @param string $lineContent The file path to search - * @param string $placeholders The values to search for - * @param int $commentType The comment type + * + * @param string $lineContent The file path to search + * @param string $placeholders The values to search for + * @param int $commentType The comment type * * @return array on success - * + * */ protected function getSystemID(&$lineContent, $placeholders, $commentType) { @@ -8077,63 +10562,78 @@ class Get $trim = '', - 'end' => ''); + 'end' => ''); } else { return array( 'start' => "", - 'end' => ""); + 'end' => ""); } break; case 22: @@ -8351,21 +10873,22 @@ class Get { return array( 'start' => '', - 'end' => ''); + 'end' => ''); } else { return array( 'start' => "", - 'end' => " "); + 'end' => " "); } break; case 3: return array( 'start' => "", - 'end' => ""); + 'end' => ""); break; } + return false; } @@ -8373,29 +10896,34 @@ class Get * get the local installed path of this component * * @return array of paths on success - * + * */ protected function getLocalInstallPaths() { // set the local paths to search $localPaths = array(); // admin path - $localPaths['admin'] = JPATH_ADMINISTRATOR . '/components/com_' . $this->componentCodeName; + $localPaths['admin'] = JPATH_ADMINISTRATOR . '/components/com_' + . $this->componentCodeName; // site path - $localPaths['site'] = JPATH_ROOT . '/components/com_' . $this->componentCodeName; - // TODO later to include the JS and CSS - $localPaths['media'] = JPATH_ROOT . '/media/com_' . $this->componentCodeName; + $localPaths['site'] = JPATH_ROOT . '/components/com_' + . $this->componentCodeName; + // media path + $localPaths['media'] = JPATH_ROOT . '/media/com_' + . $this->componentCodeName; + // lets also go over the REPOS (TODO) // Painfull but we need to folder paths for the linked modules if (($module_ids = $this->getModuleIDs()) !== false) { foreach ($module_ids as $module_id) { - // get the module group and folder name -// if (($path = $this->getModulePath($module_id)) !== false) -// { -// // set the path -// $localPaths['module_' . str_replace('/', '_', $path)] = JPATH_ROOT . '/modules/' . $path; -// } + // get the module folder path + if (($path = $this->getModulePath($module_id)) !== false) + { + // set the path + $localPaths['module_' . str_replace('/', '_', $path)] + = $path; + } } } // Painfull but we need to folder paths for the linked plugins @@ -8407,7 +10935,8 @@ class Get if (($path = $this->getPluginPath($plugin_id)) !== false) { // set the path - $localPaths['plugin_' . str_replace('/', '_', $path)] = JPATH_ROOT . '/plugins/' . $path; + $localPaths['plugin_' . str_replace('/', '_', $path)] + = JPATH_ROOT . '/plugins/' . $path; } } } @@ -8423,6 +10952,7 @@ class Get { return $localPaths; } + return false; } diff --git a/admin/helpers/compiler/b_Structure.php b/admin/helpers/compiler/b_Structure.php index 5f3d3bf93..c0e44be97 100644 --- a/admin/helpers/compiler/b_Structure.php +++ b/admin/helpers/compiler/b_Structure.php @@ -5,7 +5,7 @@ * @created 30th April, 2015 * @author Llewellyn van der Merwe * @github Joomla Component Builder - * @copyright Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + * @copyright Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ @@ -20,210 +20,210 @@ class Structure extends Get /** * The folder counter - * + * * @var int */ public $folderCount = 0; /** * The file counter - * + * * @var int */ public $fileCount = 0; /** * The page counter - * + * * @var int */ public $pageCount = 0; /** * The line counter - * + * * @var int */ public $lineCount = 0; /** * The field counter - * + * * @var int */ public $fieldCount = 0; /** * The seconds counter - * + * * @var int */ public $seconds = 0; /** * The actual seconds counter - * + * * @var int */ public $actualSeconds = 0; /** * The folder seconds counter - * + * * @var int */ public $folderSeconds = 0; /** * The file seconds counter - * + * * @var int */ public $fileSeconds = 0; /** * The line seconds counter - * + * * @var int */ public $lineSeconds = 0; /** * The seconds debugging counter - * + * * @var int */ public $secondsDebugging = 0; /** * The seconds planning counter - * + * * @var int */ public $secondsPlanning = 0; /** * The seconds mapping counter - * + * * @var int */ public $secondsMapping = 0; /** * The seconds office counter - * + * * @var int */ public $secondsOffice = 0; /** * The total hours counter - * + * * @var int */ public $totalHours = 0; /** * The debugging hours counter - * + * * @var int */ public $debuggingHours = 0; /** * The planning hours counter - * + * * @var int */ public $planningHours = 0; /** * The mapping hours counter - * + * * @var int */ public $mappingHours = 0; /** * The office hours counter - * + * * @var int */ public $officeHours = 0; /** * The actual Total Hours counter - * + * * @var int */ public $actualTotalHours = 0; /** * The actual hours spent counter - * + * * @var int */ public $actualHoursSpent = 0; /** * The actual days spent counter - * + * * @var int */ public $actualDaysSpent = 0; /** * The total days counter - * + * * @var int */ public $totalDays = 0; /** * The actual Total Days counter - * + * * @var int */ public $actualTotalDays = 0; /** * The project week time counter - * + * * @var int */ public $projectWeekTime = 0; /** * The project month time counter - * + * * @var int */ public $projectMonthTime = 0; /** * The template path - * + * * @var string */ public $templatePath; /** * The custom template path - * + * * @var string */ public $templatePathCustom; /** * The Joomla Version Data - * + * * @var object */ public $joomlaVersionData; /** * Static File Content - * + * * @var array */ public $fileContentStatic = array(); @@ -244,105 +244,107 @@ class Structure extends Get /** * The standard folders - * + * * @var array */ public $stdFolders = array('site', 'admin', 'media'); /** * The standard root files - * + * * @var array */ - public $stdRootFiles = array('access.xml', 'config.xml', 'controller.php', 'index.html', 'README.txt'); + public $stdRootFiles + = array('access.xml', 'config.xml', 'controller.php', 'index.html', + 'README.txt'); /** * Dynamic File Content - * + * * @var array */ public $fileContentDynamic = array(); /** * The Component Sales name - * + * * @var string */ public $componentSalesName; /** * The Component Backup name - * + * * @var string */ public $componentBackupName; /** * The Component Folder name - * + * * @var string */ public $componentFolderName; /** * The Component path - * + * * @var string */ public $componentPath; /** * The Dynamic paths - * + * * @var array */ public $dynamicPaths = array(); /** * The not new static items - * + * * @var array */ public $notNew = array(); /** * Update the file content - * + * * @var array */ public $updateFileContent = array(); /** * The new files - * + * * @var array */ public $newFiles = array(); /** * The Checkin Switch - * + * * @var boolean */ public $addCheckin = false; /** * The Move Folders Switch - * + * * @var boolean */ public $setMoveFolders = false; /** * The array of last modified dates - * + * * @var array */ protected $lastModifiedDate = array(); /** * The default view switch - * + * * @var bool/string */ public $dynamicDashboard = false; @@ -358,29 +360,53 @@ class Structure extends Get // set the standard admin file $this->stdRootFiles[] = $this->componentData->name_code . '.php'; // set incase no extra admin folder are loaded - $this->fileContentStatic[$this->hhh . 'EXSTRA_ADMIN_FOLDERS' . $this->hhh] = ''; + $this->fileContentStatic[$this->hhh . 'EXSTRA_ADMIN_FOLDERS' + . $this->hhh] + = ''; // set incase no extra site folder are loaded - $this->fileContentStatic[$this->hhh . 'EXSTRA_SITE_FOLDERS' . $this->hhh] = ''; + $this->fileContentStatic[$this->hhh . 'EXSTRA_SITE_FOLDERS' + . $this->hhh] + = ''; // set incase no extra media folder are loaded - $this->fileContentStatic[$this->hhh . 'EXSTRA_MEDIA_FOLDERS' . $this->hhh] = ''; + $this->fileContentStatic[$this->hhh . 'EXSTRA_MEDIA_FOLDERS' + . $this->hhh] + = ''; // set incase no extra admin files are loaded - $this->fileContentStatic[$this->hhh . 'EXSTRA_ADMIN_FILES' . $this->hhh] = ''; + $this->fileContentStatic[$this->hhh . 'EXSTRA_ADMIN_FILES' + . $this->hhh] + = ''; // set incase no extra site files are loaded - $this->fileContentStatic[$this->hhh . 'EXSTRA_SITE_FILES' . $this->hhh] = ''; + $this->fileContentStatic[$this->hhh . 'EXSTRA_SITE_FILES' + . $this->hhh] + = ''; // set incase no extra media files are loaded - $this->fileContentStatic[$this->hhh . 'EXSTRA_MEDIA_FILES' . $this->hhh] = ''; + $this->fileContentStatic[$this->hhh . 'EXSTRA_MEDIA_FILES' + . $this->hhh] + = ''; // run global updater ComponentbuilderHelper::runGlobalUpdater(); // set the template path - $this->templatePath = $this->compilerPath . '/joomla_' . $config['version']; + $this->templatePath = $this->compilerPath . '/joomla_' + . $config['version']; // set some default names - $this->componentSalesName = 'com_' . $this->componentData->sales_name . '__J' . $this->joomlaVersion; - $this->componentBackupName = 'com_' . $this->componentData->sales_name . '_v' . str_replace('.', '_', $this->componentData->component_version) . '__J' . $this->joomlaVersion; - $this->componentFolderName = 'com_' . $this->componentData->name_code . '_v' . str_replace('.', '_', $this->componentData->component_version) . '__J' . $this->joomlaVersion; + $this->componentSalesName = 'com_' + . $this->componentData->sales_name . '__J' + . $this->joomlaVersion; + $this->componentBackupName = 'com_' + . $this->componentData->sales_name . '_v' . str_replace( + '.', '_', $this->componentData->component_version + ) . '__J' . $this->joomlaVersion; + $this->componentFolderName = 'com_' + . $this->componentData->name_code . '_v' . str_replace( + '.', '_', $this->componentData->component_version + ) . '__J' . $this->joomlaVersion; // set component folder path - $this->componentPath = $this->compilerPath . '/' . $this->componentFolderName; + $this->componentPath = $this->compilerPath . '/' + . $this->componentFolderName; // set the template path for custom - $this->templatePathCustom = $this->params->get('custom_folder_path', JPATH_COMPONENT_ADMINISTRATOR . '/custom'); + $this->templatePathCustom = $this->params->get( + 'custom_folder_path', JPATH_COMPONENT_ADMINISTRATOR . '/custom' + ); // make sure there is no old build $this->removeFolder($this->componentPath); // load the libraries files/folders and url's @@ -392,7 +418,10 @@ class Structure extends Get // set the Joomla Version Data $this->joomlaVersionData = $this->setJoomlaVersionData(); // Trigger Event: jcb_ce_onAfterSetJoomlaVersionData - $this->triggerEvent('jcb_ce_onAfterSetJoomlaVersionData', array(&$this->componentContext, &$this->joomlaVersionData)); + $this->triggerEvent( + 'jcb_ce_onAfterSetJoomlaVersionData', + array(&$this->componentContext, &$this->joomlaVersionData) + ); // set the dashboard $this->setDynamicDashboard(); // set the new folders @@ -410,18 +439,20 @@ class Structure extends Get { return false; } + return true; } + return false; } /** * Set the line number in comments - * - * @param int $nr The line number - * + * + * @param int $nr The line number + * * @return string - * + * */ private function setLine($nr) { @@ -429,6 +460,7 @@ class Structure extends Get { return ' [Structure ' . $nr . ']'; } + return ''; } @@ -443,14 +475,21 @@ class Structure extends Get if (ComponentbuilderHelper::checkArray($this->joomlaModules)) { // Trigger Event: jcb_ce_onBeforeSetModules - $this->triggerEvent('jcb_ce_onBeforeBuildModules', array(&$this->componentContext, &$this->joomlaModules)); + $this->triggerEvent( + 'jcb_ce_onBeforeBuildModules', + array(&$this->componentContext, &$this->joomlaModules) + ); foreach ($this->joomlaModules as $module) { - if (ComponentbuilderHelper::checkObject($module) && isset($module->folder_name) - && ComponentbuilderHelper::checkString($module->folder_name)) + if (ComponentbuilderHelper::checkObject($module) + && isset($module->folder_name) + && ComponentbuilderHelper::checkString( + $module->folder_name + )) { // module path - $module->folder_path = $this->compilerPath . '/' . $module->folder_name; + $module->folder_path = $this->compilerPath . '/' + . $module->folder_name; // set the module paths $this->dynamicPaths[$module->key] = $module->folder_path; // make sure there is no old build @@ -461,35 +500,52 @@ class Structure extends Get JFolder::create($module->folder_path); // count the folder created $this->folderCount++; - $this->indexHTML($module->folder_name, $this->compilerPath); + $this->indexHTML( + $module->folder_name, $this->compilerPath + ); } // set main mod file - $fileDetails = array('path' => $module->folder_path . '/' . $module->file_name . '.php', - 'name' => $module->file_name . '.php', 'zip' => $module->file_name . '.php'); - $this->writeFile($fileDetails['path'], + $fileDetails = array('path' => $module->folder_path . '/' + . $module->file_name . '.php', + 'name' => $module->file_name . '.php', + 'zip' => $module->file_name . '.php'); + $this->writeFile( + $fileDetails['path'], 'hhh . 'BOM' . $this->hhh . PHP_EOL . PHP_EOL . '// No direct access to this file' . PHP_EOL . - "defined('_JEXEC') or die('Restricted access');" . PHP_EOL . - $this->hhh . 'MODCODE' . $this->hhh); + "defined('_JEXEC') or die('Restricted access');" + . PHP_EOL . + $this->hhh . 'MODCODE' . $this->hhh + ); $this->newFiles[$module->key][] = $fileDetails; // count the file created $this->fileCount++; // set custom_get if ($module->custom_get) { - $fileDetails = array('path' => $module->folder_path . '/data.php', - 'name' => 'data.php', 'zip' => 'data.php'); - $this->writeFile($fileDetails['path'], + $fileDetails = array('path' => $module->folder_path + . '/data.php', + 'name' => 'data.php', + 'zip' => 'data.php'); + $this->writeFile( + $fileDetails['path'], 'hhh . 'BOM' . $this->hhh . PHP_EOL . - PHP_EOL . '// No direct access to this file' . PHP_EOL . - "defined('_JEXEC') or die('Restricted access');" . PHP_EOL . PHP_EOL . + PHP_EOL . $this->hhh . 'BOM' . $this->hhh . PHP_EOL + . + PHP_EOL . '// No direct access to this file' + . PHP_EOL . + "defined('_JEXEC') or die('Restricted access');" + . PHP_EOL . PHP_EOL . '/**' . PHP_EOL . - ' * Module ' . $module->official_name . ' Data' . PHP_EOL . + ' * Module ' . $module->official_name . ' Data' + . PHP_EOL . ' */' . PHP_EOL . - "class " . $module->class_data_name . ' extends \JObject' . PHP_EOL . - "{" . $this->hhh . 'DYNAMICGETS' . $this->hhh . "}" . PHP_EOL); + "class " . $module->class_data_name + . ' extends \JObject' . PHP_EOL . + "{" . $this->hhh . 'DYNAMICGETS' . $this->hhh . "}" + . PHP_EOL + ); $this->newFiles[$module->key][] = $fileDetails; // count the file created $this->fileCount++; @@ -497,22 +553,34 @@ class Structure extends Get // set helper file if ($module->add_class_helper >= 1) { - $fileDetails = array('path' => $module->folder_path . '/helper.php', - 'name' => 'helper.php', 'zip' => 'helper.php'); - $this->writeFile($fileDetails['path'], + $fileDetails = array('path' => $module->folder_path + . '/helper.php', + 'name' => 'helper.php', + 'zip' => 'helper.php'); + $this->writeFile( + $fileDetails['path'], 'hhh . 'BOM' . $this->hhh . PHP_EOL . - PHP_EOL . '// No direct access to this file' . PHP_EOL . - "defined('_JEXEC') or die('Restricted access');" . PHP_EOL . - $this->hhh . 'HELPERCODE' . $this->hhh); + PHP_EOL . $this->hhh . 'BOM' . $this->hhh . PHP_EOL + . + PHP_EOL . '// No direct access to this file' + . PHP_EOL . + "defined('_JEXEC') or die('Restricted access');" + . PHP_EOL . + $this->hhh . 'HELPERCODE' . $this->hhh + ); $this->newFiles[$module->key][] = $fileDetails; // count the file created $this->fileCount++; } // set main xml file - $fileDetails = array('path' => $module->folder_path . '/' . $module->file_name . '.xml', - 'name' => $module->file_name . '.xml', 'zip' => $module->file_name . '.xml'); - $this->writeFile($fileDetails['path'], $this->getModuleXMLTemplate($module)); + $fileDetails = array('path' => $module->folder_path . '/' + . $module->file_name . '.xml', + 'name' => $module->file_name . '.xml', + 'zip' => $module->file_name . '.xml'); + $this->writeFile( + $fileDetails['path'], + $this->getModuleXMLTemplate($module) + ); $this->newFiles[$module->key][] = $fileDetails; // count the file created $this->fileCount++; @@ -522,31 +590,45 @@ class Structure extends Get JFolder::create($module->folder_path . '/tmpl'); // count the folder created $this->folderCount++; - $this->indexHTML($module->folder_name . '/tmpl', $this->compilerPath); + $this->indexHTML( + $module->folder_name . '/tmpl', $this->compilerPath + ); } // set default file - $fileDetails = array('path' => $module->folder_path . '/tmpl/default.php', - 'name' => 'default.php', 'zip' => 'tmpl/default.php'); - $this->writeFile($fileDetails['path'], + $fileDetails = array('path' => $module->folder_path + . '/tmpl/default.php', + 'name' => 'default.php', + 'zip' => 'tmpl/default.php'); + $this->writeFile( + $fileDetails['path'], 'hhh . 'BOM' . $this->hhh . PHP_EOL . PHP_EOL . '// No direct access to this file' . PHP_EOL . - "defined('_JEXEC') or die('Restricted access');" . PHP_EOL . - $this->hhh . 'MODDEFAULT' . $this->hhh); + "defined('_JEXEC') or die('Restricted access');" + . PHP_EOL . + $this->hhh . 'MODDEFAULT' . $this->hhh + ); $this->newFiles[$module->key][] = $fileDetails; // count the file created $this->fileCount++; // set install script if needed if ($module->add_install_script) { - $fileDetails = array('path' => $module->folder_path . '/script.php', - 'name' => 'script.php', 'zip' => 'script.php'); - $this->writeFile($fileDetails['path'], + $fileDetails = array('path' => $module->folder_path + . '/script.php', + 'name' => 'script.php', + 'zip' => 'script.php'); + $this->writeFile( + $fileDetails['path'], 'hhh . 'BOM' . $this->hhh . PHP_EOL . - PHP_EOL . '// No direct access to this file' . PHP_EOL . - "defined('_JEXEC') or die('Restricted access');" . PHP_EOL . - $this->hhh . 'INSTALLCLASS' . $this->hhh); + PHP_EOL . $this->hhh . 'BOM' . $this->hhh . PHP_EOL + . + PHP_EOL . '// No direct access to this file' + . PHP_EOL . + "defined('_JEXEC') or die('Restricted access');" + . PHP_EOL . + $this->hhh . 'INSTALLCLASS' . $this->hhh + ); $this->newFiles[$module->key][] = $fileDetails; // count the file created $this->fileCount++; @@ -554,15 +636,18 @@ class Structure extends Get // set readme if found if ($module->addreadme) { - $fileDetails = array('path' => $module->folder_path . '/README.md', - 'name' => 'README.md', 'zip' => 'README.md'); + $fileDetails = array('path' => $module->folder_path + . '/README.md', + 'name' => 'README.md', + 'zip' => 'README.md'); $this->writeFile($fileDetails['path'], $module->readme); $this->newFiles[$module->key][] = $fileDetails; // count the file created $this->fileCount++; } // set fields & rules folders if needed - if (isset($module->fields_rules_paths) && $module->fields_rules_paths == 2) + if (isset($module->fields_rules_paths) + && $module->fields_rules_paths == 2) { // create fields folder if (!JFolder::exists($module->folder_path . '/fields')) @@ -570,7 +655,10 @@ class Structure extends Get JFolder::create($module->folder_path . '/fields'); // count the folder created $this->folderCount++; - $this->indexHTML($module->folder_name . '/fields', $this->compilerPath); + $this->indexHTML( + $module->folder_name . '/fields', + $this->compilerPath + ); } // create rules folder if (!JFolder::exists($module->folder_path . '/rules')) @@ -578,11 +666,17 @@ class Structure extends Get JFolder::create($module->folder_path . '/rules'); // count the folder created $this->folderCount++; - $this->indexHTML($module->folder_name . '/rules', $this->compilerPath); + $this->indexHTML( + $module->folder_name . '/rules', + $this->compilerPath + ); } } // set forms folder if needed - if (isset($module->form_files) && ComponentbuilderHelper::checkArray($module->form_files)) + if (isset($module->form_files) + && ComponentbuilderHelper::checkArray( + $module->form_files + )) { // create forms folder if (!JFolder::exists($module->folder_path . '/forms')) @@ -590,17 +684,26 @@ class Structure extends Get JFolder::create($module->folder_path . '/forms'); // count the folder created $this->folderCount++; - $this->indexHTML($module->folder_name . '/forms', $this->compilerPath); + $this->indexHTML( + $module->folder_name . '/forms', + $this->compilerPath + ); } // set the template files - foreach($module->form_files as $file => $fields) + foreach ($module->form_files as $file => $fields) { // set file details - $fileDetails = array('path' => $module->folder_path . '/forms/' . $file . '.xml', - 'name' => $file . '.xml', 'zip' => 'forms/' . $file . '.xml'); + $fileDetails = array('path' => $module->folder_path + . '/forms/' . $file . '.xml', + 'name' => $file . '.xml', + 'zip' => 'forms/' . $file + . '.xml'); // biuld basic XML $xml = ''; - $xml .= PHP_EOL . ''; + $xml .= PHP_EOL . ''; // search if we must add the component path $add_component_path = false; foreach ($fields as $field_name => $fieldsets) @@ -609,7 +712,13 @@ class Structure extends Get { foreach ($fieldsets as $fieldset => $field) { - if (!$add_component_path && isset($module->fieldsets_paths[$file . $field_name . $fieldset]) && $module->fieldsets_paths[$file . $field_name . $fieldset] == 1) + if (!$add_component_path + && isset( + $module->fieldsets_paths[$file + . $field_name . $fieldset] + ) + && $module->fieldsets_paths[$file + . $field_name . $fieldset] == 1) { $add_component_path = true; } @@ -620,8 +729,14 @@ class Structure extends Get if ($add_component_path) { $xml .= PHP_EOL . '_t(1) . 'addrulepath="/administrator/components/com_' . $this->componentCodeName . '/models/rules"'; - $xml .= PHP_EOL . $this->_t(1) . 'addfieldpath="/administrator/components/com_' . $this->componentCodeName . '/models/fields"'; + $xml .= PHP_EOL . $this->_t(1) + . 'addrulepath="/administrator/components/com_' + . $this->componentCodeName + . '/models/rules"'; + $xml .= PHP_EOL . $this->_t(1) + . 'addfieldpath="/administrator/components/com_' + . $this->componentCodeName + . '/models/fields"'; $xml .= PHP_EOL . '>'; } else @@ -643,41 +758,74 @@ class Structure extends Get $field_name_inner = $field_names[1]; } } - $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) + . ''; foreach ($fieldsets as $fieldset => $field) { // default to the field set name $label = $fieldset; - if (isset($module->fieldsets_label[$file.$field_name.$fieldset])) + if (isset( + $module->fieldsets_label[$file + . $field_name . $fieldset] + )) { - $label = $module->fieldsets_label[$file.$field_name.$fieldset]; + $label = $module->fieldsets_label[$file + . $field_name . $fieldset]; } // add path to module rules and custom fields - if (isset($module->fieldsets_paths[$file.$field_name.$fieldset]) && $module->fieldsets_paths[$file.$field_name.$fieldset] == 2) + if (isset( + $module->fieldsets_paths[$file + . $field_name . $fieldset] + ) + && $module->fieldsets_paths[$file + . $field_name . $fieldset] == 2) { - $xml .= PHP_EOL . $this->_t(1) . ''; - $xml .= PHP_EOL . $this->_t(1) . '
_t(2) . 'addrulepath="/modules/' . strtolower($module->code_name) . '/rules"'; - $xml .= PHP_EOL . $this->_t(2) . 'addfieldpath="/modules/' . strtolower($module->code_name) . '/fields"'; + $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) + . '
_t(2) + . 'addrulepath="/modules/' + . strtolower($module->code_name) + . '/rules"'; + $xml .= PHP_EOL . $this->_t(2) + . 'addfieldpath="/modules/' + . strtolower($module->code_name) + . '/fields"'; $xml .= PHP_EOL . $this->_t(1) . '>'; } else { - $xml .= PHP_EOL . $this->_t(1) . '
'; + $xml .= PHP_EOL . $this->_t(1) + . '
'; } // check if we have an inner field set - if (ComponentbuilderHelper::checkString($field_name_inner)) + if (ComponentbuilderHelper::checkString( + $field_name_inner + )) { - $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) + . ''; } // add the placeholder of the fields - $xml .= $this->hhh . 'FIELDSET_' . $file.$field_name.$fieldset . $this->hhh; + $xml .= $this->hhh . 'FIELDSET_' . $file + . $field_name . $fieldset . $this->hhh; // check if we have an inner field set - if (ComponentbuilderHelper::checkString($field_name_inner)) + if (ComponentbuilderHelper::checkString( + $field_name_inner + )) { - $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) + . ''; } - $xml .= PHP_EOL . $this->_t(1) . '
'; + $xml .= PHP_EOL . $this->_t(1) + . '
'; } $xml .= PHP_EOL . $this->_t(1) . ''; } @@ -698,27 +846,44 @@ class Structure extends Get JFolder::create($module->folder_path . '/sql'); // count the folder created $this->folderCount++; - $this->indexHTML($module->folder_name . '/sql', $this->compilerPath); + $this->indexHTML( + $module->folder_name . '/sql', + $this->compilerPath + ); } // create mysql folder - if (!JFolder::exists($module->folder_path . '/sql/mysql')) + if (!JFolder::exists( + $module->folder_path . '/sql/mysql' + )) { - JFolder::create($module->folder_path . '/sql/mysql'); + JFolder::create( + $module->folder_path . '/sql/mysql' + ); // count the folder created $this->folderCount++; - $this->indexHTML($module->folder_name . '/sql/mysql', $this->compilerPath); + $this->indexHTML( + $module->folder_name . '/sql/mysql', + $this->compilerPath + ); } // now set the install file if ($module->add_sql) { - $this->writeFile($module->folder_path . '/sql/mysql/install.sql', $module->sql); + $this->writeFile( + $module->folder_path . '/sql/mysql/install.sql', + $module->sql + ); // count the file created $this->fileCount++; } // now set the uninstall file if ($module->add_sql_uninstall) { - $this->writeFile($module->folder_path . '/sql/mysql/uninstall.sql', $module->sql_uninstall); + $this->writeFile( + $module->folder_path + . '/sql/mysql/uninstall.sql', + $module->sql_uninstall + ); // count the file created $this->fileCount++; } @@ -730,51 +895,64 @@ class Structure extends Get // count the folder created $this->folderCount++; // also the lang tag - if (!JFolder::exists($module->folder_path . '/language/' . $this->langTag)) + if (!JFolder::exists( + $module->folder_path . '/language/' . $this->langTag + )) { - JFolder::create($module->folder_path . '/language/' . $this->langTag); + JFolder::create( + $module->folder_path . '/language/' + . $this->langTag + ); // count the folder created $this->folderCount++; } } // check if this lib has files - if (isset($module->files) && ComponentbuilderHelper::checkArray($module->files)) + if (isset($module->files) + && ComponentbuilderHelper::checkArray($module->files)) { // add to component files foreach ($module->files as $file) { // set the path finder - $file['target_type'] = $module->target_type; - $file['target_id'] = $module->id; + $file['target_type'] = $module->target_type; + $file['target_id'] = $module->id; $this->componentData->files[] = $file; } } // check if this lib has folders - if (isset($module->folders) && ComponentbuilderHelper::checkArray($module->folders)) + if (isset($module->folders) + && ComponentbuilderHelper::checkArray($module->folders)) { // add to component folders foreach ($module->folders as $folder) { // set the path finder - $folder['target_type'] = $module->target_type; - $folder['target_id'] = $module->id; + $folder['target_type'] = $module->target_type; + $folder['target_id'] = $module->id; $this->componentData->folders[] = $folder; } } // check if this module has urls - if (isset($module->urls) && ComponentbuilderHelper::checkArray($module->urls)) + if (isset($module->urls) + && ComponentbuilderHelper::checkArray($module->urls)) { // add to component urls foreach ($module->urls as $n => &$url) { // should we add the local folder - if (isset($url['type']) && $url['type'] > 1 && isset($url['url']) - && ComponentbuilderHelper::checkString($url['url'])) + if (isset($url['type']) && $url['type'] > 1 + && isset($url['url']) + && ComponentbuilderHelper::checkString( + $url['url'] + )) { // set file name $fileName = basename($url['url']); // get the file contents - $data = ComponentbuilderHelper::getFileContents($url['url']); + $data = ComponentbuilderHelper::getFileContents( + $url['url'] + ); // build sub path if (strpos($fileName, '.js') !== false) { @@ -789,15 +967,23 @@ class Structure extends Get $path = ''; } // create sub media path if not set - if (!JFolder::exists($module->folder_path .$path)) + if (!JFolder::exists( + $module->folder_path . $path + )) { - JFolder::create($module->folder_path . $path); + JFolder::create( + $module->folder_path . $path + ); // count the folder created $this->folderCount++; - $this->indexHTML($module->folder_name . $path, $this->compilerPath); + $this->indexHTML( + $module->folder_name . $path, + $this->compilerPath + ); } // set the path to module file - $url['path'] = $module->folder_path . $path . '/' . $fileName; // we need this for later + $url['path'] = $module->folder_path . $path + . '/' . $fileName; // we need this for later // write data to path $this->writeFile($url['path'], $data); // count the file created @@ -812,23 +998,30 @@ class Structure extends Get /** * Build the Plugins files, folders, url's and config - * + * * @return void - * + * */ private function buildPlugins() { if (ComponentbuilderHelper::checkArray($this->joomlaPlugins)) { // Trigger Event: jcb_ce_onBeforeSetPlugins - $this->triggerEvent('jcb_ce_onBeforeBuildPlugins', array(&$this->componentContext, &$this->joomlaPlugins)); + $this->triggerEvent( + 'jcb_ce_onBeforeBuildPlugins', + array(&$this->componentContext, &$this->joomlaPlugins) + ); foreach ($this->joomlaPlugins as $plugin) { - if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->folder_name) - && ComponentbuilderHelper::checkString($plugin->folder_name)) + if (ComponentbuilderHelper::checkObject($plugin) + && isset($plugin->folder_name) + && ComponentbuilderHelper::checkString( + $plugin->folder_name + )) { // plugin path - $plugin->folder_path = $this->compilerPath . '/' . $plugin->folder_name; + $plugin->folder_path = $this->compilerPath . '/' + . $plugin->folder_name; // set the plugin paths $this->dynamicPaths[$plugin->key] = $plugin->folder_path; // make sure there is no old build @@ -839,38 +1032,57 @@ class Structure extends Get JFolder::create($plugin->folder_path); // count the folder created $this->folderCount++; - $this->indexHTML($plugin->folder_name, $this->compilerPath); + $this->indexHTML( + $plugin->folder_name, $this->compilerPath + ); } // set main class file - $fileDetails = array('path' => $plugin->folder_path . '/' . $plugin->file_name . '.php', - 'name' => $plugin->file_name . '.php', 'zip' => $plugin->file_name . '.php'); - $this->writeFile($fileDetails['path'], + $fileDetails = array('path' => $plugin->folder_path . '/' + . $plugin->file_name . '.php', + 'name' => $plugin->file_name . '.php', + 'zip' => $plugin->file_name . '.php'); + $this->writeFile( + $fileDetails['path'], 'hhh . 'BOM' . $this->hhh . PHP_EOL . PHP_EOL . '// No direct access to this file' . PHP_EOL . - "defined('_JEXEC') or die('Restricted access');" . PHP_EOL . - $this->hhh . 'MAINCLASS' . $this->hhh); + "defined('_JEXEC') or die('Restricted access');" + . PHP_EOL . + $this->hhh . 'MAINCLASS' . $this->hhh + ); $this->newFiles[$plugin->key][] = $fileDetails; // count the file created $this->fileCount++; // set main xml file - $fileDetails = array('path' => $plugin->folder_path . '/' . $plugin->file_name . '.xml', - 'name' => $plugin->file_name . '.xml', 'zip' => $plugin->file_name . '.xml'); - $this->writeFile($fileDetails['path'], $this->getPluginXMLTemplate($plugin)); + $fileDetails = array('path' => $plugin->folder_path . '/' + . $plugin->file_name . '.xml', + 'name' => $plugin->file_name . '.xml', + 'zip' => $plugin->file_name . '.xml'); + $this->writeFile( + $fileDetails['path'], + $this->getPluginXMLTemplate($plugin) + ); $this->newFiles[$plugin->key][] = $fileDetails; // count the file created $this->fileCount++; // set install script if needed if ($plugin->add_install_script) { - $fileDetails = array('path' => $plugin->folder_path . '/script.php', - 'name' => 'script.php', 'zip' => 'script.php'); - $this->writeFile($fileDetails['path'], + $fileDetails = array('path' => $plugin->folder_path + . '/script.php', + 'name' => 'script.php', + 'zip' => 'script.php'); + $this->writeFile( + $fileDetails['path'], 'hhh . 'BOM' . $this->hhh . PHP_EOL . - PHP_EOL . '// No direct access to this file' . PHP_EOL . - "defined('_JEXEC') or die('Restricted access');" . PHP_EOL . - $this->hhh . 'INSTALLCLASS' . $this->hhh); + PHP_EOL . $this->hhh . 'BOM' . $this->hhh . PHP_EOL + . + PHP_EOL . '// No direct access to this file' + . PHP_EOL . + "defined('_JEXEC') or die('Restricted access');" + . PHP_EOL . + $this->hhh . 'INSTALLCLASS' . $this->hhh + ); $this->newFiles[$plugin->key][] = $fileDetails; // count the file created $this->fileCount++; @@ -878,15 +1090,18 @@ class Structure extends Get // set readme if found if ($plugin->addreadme) { - $fileDetails = array('path' => $plugin->folder_path . '/README.md', - 'name' => 'README.md', 'zip' => 'README.md'); + $fileDetails = array('path' => $plugin->folder_path + . '/README.md', + 'name' => 'README.md', + 'zip' => 'README.md'); $this->writeFile($fileDetails['path'], $plugin->readme); $this->newFiles[$plugin->key][] = $fileDetails; // count the file created $this->fileCount++; } // set fields & rules folders if needed - if (isset($plugin->fields_rules_paths) && $plugin->fields_rules_paths == 2) + if (isset($plugin->fields_rules_paths) + && $plugin->fields_rules_paths == 2) { // create fields folder if (!JFolder::exists($plugin->folder_path . '/fields')) @@ -894,7 +1109,10 @@ class Structure extends Get JFolder::create($plugin->folder_path . '/fields'); // count the folder created $this->folderCount++; - $this->indexHTML($plugin->folder_name . '/fields', $this->compilerPath); + $this->indexHTML( + $plugin->folder_name . '/fields', + $this->compilerPath + ); } // create rules folder if (!JFolder::exists($plugin->folder_path . '/rules')) @@ -902,11 +1120,17 @@ class Structure extends Get JFolder::create($plugin->folder_path . '/rules'); // count the folder created $this->folderCount++; - $this->indexHTML($plugin->folder_name . '/rules', $this->compilerPath); + $this->indexHTML( + $plugin->folder_name . '/rules', + $this->compilerPath + ); } } // set forms folder if needed - if (isset($plugin->form_files) && ComponentbuilderHelper::checkArray($plugin->form_files)) + if (isset($plugin->form_files) + && ComponentbuilderHelper::checkArray( + $plugin->form_files + )) { // create forms folder if (!JFolder::exists($plugin->folder_path . '/forms')) @@ -914,17 +1138,26 @@ class Structure extends Get JFolder::create($plugin->folder_path . '/forms'); // count the folder created $this->folderCount++; - $this->indexHTML($plugin->folder_name . '/forms', $this->compilerPath); + $this->indexHTML( + $plugin->folder_name . '/forms', + $this->compilerPath + ); } // set the template files - foreach($plugin->form_files as $file => $fields) + foreach ($plugin->form_files as $file => $fields) { // set file details - $fileDetails = array('path' => $plugin->folder_path . '/forms/' . $file . '.xml', - 'name' => $file . '.xml', 'zip' => 'forms/' . $file . '.xml'); + $fileDetails = array('path' => $plugin->folder_path + . '/forms/' . $file . '.xml', + 'name' => $file . '.xml', + 'zip' => 'forms/' . $file + . '.xml'); // biuld basic XML $xml = ''; - $xml .= PHP_EOL . ''; + $xml .= PHP_EOL . ''; // search if we must add the component path $add_component_path = false; foreach ($fields as $field_name => $fieldsets) @@ -933,7 +1166,13 @@ class Structure extends Get { foreach ($fieldsets as $fieldset => $field) { - if (!$add_component_path && isset($plugin->fieldsets_paths[$file . $field_name . $fieldset]) && $plugin->fieldsets_paths[$file . $field_name . $fieldset] == 1) + if (!$add_component_path + && isset( + $plugin->fieldsets_paths[$file + . $field_name . $fieldset] + ) + && $plugin->fieldsets_paths[$file + . $field_name . $fieldset] == 1) { $add_component_path = true; } @@ -944,8 +1183,14 @@ class Structure extends Get if ($add_component_path) { $xml .= PHP_EOL . '_t(1) . 'addrulepath="/administrator/components/com_' . $this->componentCodeName . '/models/rules"'; - $xml .= PHP_EOL . $this->_t(1) . 'addfieldpath="/administrator/components/com_' . $this->componentCodeName . '/models/fields"'; + $xml .= PHP_EOL . $this->_t(1) + . 'addrulepath="/administrator/components/com_' + . $this->componentCodeName + . '/models/rules"'; + $xml .= PHP_EOL . $this->_t(1) + . 'addfieldpath="/administrator/components/com_' + . $this->componentCodeName + . '/models/fields"'; $xml .= PHP_EOL . '>'; } else @@ -967,41 +1212,76 @@ class Structure extends Get $field_name_inner = $field_names[1]; } } - $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) + . ''; foreach ($fieldsets as $fieldset => $field) { // default to the field set name $label = $fieldset; - if (isset($plugin->fieldsets_label[$file.$field_name.$fieldset])) + if (isset( + $plugin->fieldsets_label[$file + . $field_name . $fieldset] + )) { - $label = $plugin->fieldsets_label[$file.$field_name.$fieldset]; + $label = $plugin->fieldsets_label[$file + . $field_name . $fieldset]; } // add path to plugin rules and custom fields - if (isset($plugin->fieldsets_paths[$file.$field_name.$fieldset]) && $plugin->fieldsets_paths[$file.$field_name.$fieldset] == 2) + if (isset( + $plugin->fieldsets_paths[$file + . $field_name . $fieldset] + ) + && $plugin->fieldsets_paths[$file + . $field_name . $fieldset] == 2) { - $xml .= PHP_EOL . $this->_t(1) . ''; - $xml .= PHP_EOL . $this->_t(1) . '
_t(2) . 'addrulepath="/plugins/' . strtolower($plugin->group) . '/' . strtolower($plugin->code_name) . '/rules"'; - $xml .= PHP_EOL . $this->_t(2) . 'addfieldpath="/plugins/' . strtolower($plugin->group) . '/' . strtolower($plugin->code_name) . '/fields"'; + $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) + . '
_t(2) + . 'addrulepath="/plugins/' + . strtolower($plugin->group) . '/' + . strtolower($plugin->code_name) + . '/rules"'; + $xml .= PHP_EOL . $this->_t(2) + . 'addfieldpath="/plugins/' + . strtolower($plugin->group) . '/' + . strtolower($plugin->code_name) + . '/fields"'; $xml .= PHP_EOL . $this->_t(1) . '>'; } else { - $xml .= PHP_EOL . $this->_t(1) . '
'; + $xml .= PHP_EOL . $this->_t(1) + . '
'; } // check if we have an inner field set - if (ComponentbuilderHelper::checkString($field_name_inner)) + if (ComponentbuilderHelper::checkString( + $field_name_inner + )) { - $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) + . ''; } // add the placeholder of the fields - $xml .= $this->hhh . 'FIELDSET_' . $file.$field_name.$fieldset . $this->hhh; + $xml .= $this->hhh . 'FIELDSET_' . $file + . $field_name . $fieldset . $this->hhh; // check if we have an inner field set - if (ComponentbuilderHelper::checkString($field_name_inner)) + if (ComponentbuilderHelper::checkString( + $field_name_inner + )) { - $xml .= PHP_EOL . $this->_t(1) . ''; + $xml .= PHP_EOL . $this->_t(1) + . ''; } - $xml .= PHP_EOL . $this->_t(1) . '
'; + $xml .= PHP_EOL . $this->_t(1) + . '
'; } $xml .= PHP_EOL . $this->_t(1) . ''; } @@ -1022,27 +1302,44 @@ class Structure extends Get JFolder::create($plugin->folder_path . '/sql'); // count the folder created $this->folderCount++; - $this->indexHTML($plugin->folder_name . '/sql', $this->compilerPath); + $this->indexHTML( + $plugin->folder_name . '/sql', + $this->compilerPath + ); } // create mysql folder - if (!JFolder::exists($plugin->folder_path . '/sql/mysql')) + if (!JFolder::exists( + $plugin->folder_path . '/sql/mysql' + )) { - JFolder::create($plugin->folder_path . '/sql/mysql'); + JFolder::create( + $plugin->folder_path . '/sql/mysql' + ); // count the folder created $this->folderCount++; - $this->indexHTML($plugin->folder_name . '/sql/mysql', $this->compilerPath); + $this->indexHTML( + $plugin->folder_name . '/sql/mysql', + $this->compilerPath + ); } // now set the install file if ($plugin->add_sql) { - $this->writeFile($plugin->folder_path . '/sql/mysql/install.sql', $plugin->sql); + $this->writeFile( + $plugin->folder_path . '/sql/mysql/install.sql', + $plugin->sql + ); // count the file created $this->fileCount++; } // now set the uninstall file if ($plugin->add_sql_uninstall) { - $this->writeFile($plugin->folder_path . '/sql/mysql/uninstall.sql', $plugin->sql_uninstall); + $this->writeFile( + $plugin->folder_path + . '/sql/mysql/uninstall.sql', + $plugin->sql_uninstall + ); // count the file created $this->fileCount++; } @@ -1054,51 +1351,64 @@ class Structure extends Get // count the folder created $this->folderCount++; // also the lang tag - if (!JFolder::exists($plugin->folder_path . '/language/' . $this->langTag)) + if (!JFolder::exists( + $plugin->folder_path . '/language/' . $this->langTag + )) { - JFolder::create($plugin->folder_path . '/language/' . $this->langTag); + JFolder::create( + $plugin->folder_path . '/language/' + . $this->langTag + ); // count the folder created $this->folderCount++; } } // check if this lib has files - if (isset($plugin->files) && ComponentbuilderHelper::checkArray($plugin->files)) + if (isset($plugin->files) + && ComponentbuilderHelper::checkArray($plugin->files)) { // add to component files foreach ($plugin->files as $file) { // set the path finder - $file['target_type'] = $plugin->target_type; - $file['target_id'] = $plugin->id; + $file['target_type'] = $plugin->target_type; + $file['target_id'] = $plugin->id; $this->componentData->files[] = $file; } } // check if this lib has folders - if (isset($plugin->folders) && ComponentbuilderHelper::checkArray($plugin->folders)) + if (isset($plugin->folders) + && ComponentbuilderHelper::checkArray($plugin->folders)) { // add to component folders foreach ($plugin->folders as $folder) { // set the path finder - $folder['target_type'] = $plugin->target_type; - $folder['target_id'] = $plugin->id; + $folder['target_type'] = $plugin->target_type; + $folder['target_id'] = $plugin->id; $this->componentData->folders[] = $folder; } } // check if this plugin has urls - if (isset($plugin->urls) && ComponentbuilderHelper::checkArray($plugin->urls)) + if (isset($plugin->urls) + && ComponentbuilderHelper::checkArray($plugin->urls)) { // add to component urls foreach ($plugin->urls as $n => &$url) { // should we add the local folder - if (isset($url['type']) && $url['type'] > 1 && isset($url['url']) - && ComponentbuilderHelper::checkString($url['url'])) + if (isset($url['type']) && $url['type'] > 1 + && isset($url['url']) + && ComponentbuilderHelper::checkString( + $url['url'] + )) { // set file name $fileName = basename($url['url']); // get the file contents - $data = ComponentbuilderHelper::getFileContents($url['url']); + $data = ComponentbuilderHelper::getFileContents( + $url['url'] + ); // build sub path if (strpos($fileName, '.js') !== false) { @@ -1113,15 +1423,23 @@ class Structure extends Get $path = ''; } // create sub media path if not set - if (!JFolder::exists($plugin->folder_path .$path)) + if (!JFolder::exists( + $plugin->folder_path . $path + )) { - JFolder::create($plugin->folder_path . $path); + JFolder::create( + $plugin->folder_path . $path + ); // count the folder created $this->folderCount++; - $this->indexHTML($plugin->folder_name . $path, $this->compilerPath); + $this->indexHTML( + $plugin->folder_name . $path, + $this->compilerPath + ); } // set the path to plugin file - $url['path'] = $plugin->folder_path . $path . '/' . $fileName; // we need this for later + $url['path'] = $plugin->folder_path . $path + . '/' . $fileName; // we need this for later // write data to path $this->writeFile($url['path'], $data); // count the file created @@ -1136,16 +1454,19 @@ class Structure extends Get /** * Build the Libraries files, folders, url's and config - * + * * @return void - * + * */ private function setLibraries() { if (ComponentbuilderHelper::checkArray($this->libraries)) { // Trigger Event: jcb_ce_onBeforeSetLibraries - $this->triggerEvent('jcb_ce_onBeforeSetLibraries', array(&$this->componentContext, &$this->libraries)); + $this->triggerEvent( + 'jcb_ce_onBeforeSetLibraries', + array(&$this->componentContext, &$this->libraries) + ); // creat the main component folder if (!JFolder::exists($this->componentPath)) { @@ -1167,7 +1488,8 @@ class Structure extends Get if (ComponentbuilderHelper::checkObject($library)) { // check if this lib has files - if (isset($library->files) && ComponentbuilderHelper::checkArray($library->files)) + if (isset($library->files) + && ComponentbuilderHelper::checkArray($library->files)) { // add to component files foreach ($library->files as $file) @@ -1176,7 +1498,10 @@ class Structure extends Get } } // check if this lib has folders - if (isset($library->folders) && ComponentbuilderHelper::checkArray($library->folders)) + if (isset($library->folders) + && ComponentbuilderHelper::checkArray( + $library->folders + )) { // add to component folders foreach ($library->folders as $folder) @@ -1185,22 +1510,38 @@ class Structure extends Get } } // check if this lib has urls - if (isset($library->urls) && ComponentbuilderHelper::checkArray($library->urls)) + if (isset($library->urls) + && ComponentbuilderHelper::checkArray($library->urls)) { // build media folder path - $libFolder = strtolower(preg_replace('/\s+/', '-', ComponentbuilderHelper::safeString($library->name, 'filename', ' ', false))); + $libFolder = strtolower( + preg_replace( + '/\s+/', '-', + ComponentbuilderHelper::safeString( + $library->name, 'filename', ' ', false + ) + ) + ); $mediaPath = '/media/' . $libFolder; // should we add the local folder $addLocalFolder = false; // add to component urls foreach ($library->urls as $n => &$url) { - if (isset($url['type']) && $url['type'] > 1 && isset($url['url']) && ComponentbuilderHelper::checkString($url['url'])) + if (isset($url['type']) && $url['type'] > 1 + && isset($url['url']) + && ComponentbuilderHelper::checkString( + $url['url'] + )) { // create media/lib path if not set - if (!JFolder::exists($this->componentPath . $mediaPath)) + if (!JFolder::exists( + $this->componentPath . $mediaPath + )) { - JFolder::create($this->componentPath . $mediaPath); + JFolder::create( + $this->componentPath . $mediaPath + ); // count the folder created $this->folderCount++; $this->indexHTML($mediaPath); @@ -1210,7 +1551,9 @@ class Structure extends Get // set file name $fileName = basename($url['url']); // get the file contents - $data = ComponentbuilderHelper::getFileContents($url['url']); + $data = ComponentbuilderHelper::getFileContents( + $url['url'] + ); // build sub path if (strpos($fileName, '.js') !== false) { @@ -1225,15 +1568,21 @@ class Structure extends Get $path = ''; } // create sub media path if not set - if (!JFolder::exists($this->componentPath . $mediaPath . $path)) + if (!JFolder::exists( + $this->componentPath . $mediaPath . $path + )) { - JFolder::create($this->componentPath . $mediaPath . $path); + JFolder::create( + $this->componentPath . $mediaPath + . $path + ); // count the folder created $this->folderCount++; $this->indexHTML($mediaPath . $path); } // set the path to library file - $url['path'] = $mediaPath . $path . '/' . $fileName; // we need this for later + $url['path'] = $mediaPath . $path . '/' + . $fileName; // we need this for later // set full path $path = $this->componentPath . $url['path']; // write data to path @@ -1246,18 +1595,25 @@ class Structure extends Get if ($addLocalFolder) { // add folder to xml of media folders - $this->fileContentStatic[$this->hhh . 'EXSTRA_MEDIA_FOLDERS' . $this->hhh] .= PHP_EOL . $this->_t(2) . "" . $libFolder . ""; + $this->fileContentStatic[$this->hhh + . 'EXSTRA_MEDIA_FOLDERS' . $this->hhh] + .= PHP_EOL . $this->_t(2) . "" + . $libFolder . ""; } } // if config fields are found load into component config (avoiding dublicates) - if (isset($library->how) && $library->how > 1 && isset($library->config) && ComponentbuilderHelper::checkArray($library->config)) + if (isset($library->how) && $library->how > 1 + && isset($library->config) + && ComponentbuilderHelper::checkArray($library->config)) { foreach ($library->config as $cofig) { - $found = array_filter($this->componentData->config, function($item) use($cofig) - { - return $item['field'] == $cofig['field']; - }); + $found = array_filter( + $this->componentData->config, + function ($item) use ($cofig) { + return $item['field'] == $cofig['field']; + } + ); // set the config data if not found if (!ComponentbuilderHelper::checkArray($found)) { @@ -1272,86 +1628,138 @@ class Structure extends Get /** * set the dynamic dashboard if set - * + * * @return void - * + * */ private function setDynamicDashboard() { // only add the dynamic dashboard if all checks out - if (isset($this->componentData->dashboard_type) && 2 == $this->componentData->dashboard_type && isset($this->componentData->dashboard) && ComponentbuilderHelper::checkString($this->componentData->dashboard) && strpos($this->componentData->dashboard, '_') !== false) + if (isset($this->componentData->dashboard_type) + && 2 == $this->componentData->dashboard_type + && isset($this->componentData->dashboard) + && ComponentbuilderHelper::checkString( + $this->componentData->dashboard + ) + && strpos($this->componentData->dashboard, '_') !== false) { // set the default view $getter = explode('_', $this->componentData->dashboard); if (count((array) $getter) == 2 && is_numeric($getter[1])) { // the pointers - $t = ComponentbuilderHelper::safeString($getter[0], 'U'); + $t = ComponentbuilderHelper::safeString($getter[0], 'U'); $id = (int) $getter[1]; // the dynamic stuff - $targets = array('A' => 'admin_views', 'C' => 'custom_admin_views'); - $names = array('A' => 'admin view', 'C' => 'custom admin view'); - $types = array('A' => 'adminview', 'C' => 'customadminview'); - $keys = array('A' => 'name_list', 'C' => 'code'); + $targets = array('A' => 'admin_views', + 'C' => 'custom_admin_views'); + $names = array('A' => 'admin view', + 'C' => 'custom admin view'); + $types = array('A' => 'adminview', 'C' => 'customadminview'); + $keys = array('A' => 'name_list', 'C' => 'code'); // check the target values if (isset($targets[$t]) && $id > 0) { // set the type name - $type_names = ComponentbuilderHelper::safeString($targets[$t], 'w'); + $type_names = ComponentbuilderHelper::safeString( + $targets[$t], 'w' + ); // set the dynamic dash - if (isset($this->componentData->{$targets[$t]}) && ComponentbuilderHelper::checkArray($this->componentData->{$targets[$t]})) + if (isset($this->componentData->{$targets[$t]}) + && ComponentbuilderHelper::checkArray( + $this->componentData->{$targets[$t]} + )) { // search the target views - $dashboard = (array) array_filter($this->componentData->{$targets[$t]}, function($view) use($id, $t, $types) - { - if (isset($view[$types[$t]]) && $id == $view[$types[$t]]) + $dashboard = (array) array_filter( + $this->componentData->{$targets[$t]}, + function ($view) use ($id, $t, $types) { + if (isset($view[$types[$t]]) + && $id == $view[$types[$t]]) { return true; } + return false; - }); + } + ); // set dashboard if (ComponentbuilderHelper::checkArray($dashboard)) { $dashboard = array_values($dashboard)[0]; } // check if view was found (this should be true) - if (isset($dashboard['settings']) && isset($dashboard['settings']->{$keys[$t]})) + if (isset($dashboard['settings']) + && isset($dashboard['settings']->{$keys[$t]})) { - $this->dynamicDashboard = ComponentbuilderHelper::safeString($dashboard['settings']->{$keys[$t]}); + $this->dynamicDashboard + = ComponentbuilderHelper::safeString( + $dashboard['settings']->{$keys[$t]} + ); } else { // set massage that something is wrong - $this->app->enqueueMessage(JText::_('

Dashboard Error

'), 'Error'); - $this->app->enqueueMessage(JText::sprintf('The %s (%s) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', $names[$t], $this->componentData->dashboard, $type_names), 'Error'); + $this->app->enqueueMessage( + JText::_('

Dashboard Error

'), + 'Error' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The %s (%s) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', + $names[$t], $this->componentData->dashboard, + $type_names + ), 'Error' + ); } } else { // set massage that something is wrong - $this->app->enqueueMessage(JText::_('

Dashboard Error

'), 'Error'); - $this->app->enqueueMessage(JText::sprintf('The %s (%s) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', $names[$t], $this->componentData->dashboard, $type_names), 'Error'); + $this->app->enqueueMessage( + JText::_('

Dashboard Error

'), 'Error' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The %s (%s) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.', + $names[$t], $this->componentData->dashboard, + $type_names + ), 'Error' + ); } } else { // the target value is wrong - $this->app->enqueueMessage(JText::_('

Dashboard Error

'), 'Error'); - $this->app->enqueueMessage(JText::sprintf('The %s value for the dynamic dashboard is invalid.', $this->componentData->dashboard), 'Error'); + $this->app->enqueueMessage( + JText::_('

Dashboard Error

'), 'Error' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The %s value for the dynamic dashboard is invalid.', + $this->componentData->dashboard + ), 'Error' + ); } } else { // the target value is wrong - $this->app->enqueueMessage(JText::_('

Dashboard Error

'), 'Error'); - $this->app->enqueueMessage(JText::sprintf('The %s value for the dynamic dashboard is invalid.', $this->componentData->dashboard), 'Error'); + $this->app->enqueueMessage( + JText::_('

Dashboard Error

'), 'Error' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The %s value for the dynamic dashboard is invalid.', + $this->componentData->dashboard + ), 'Error' + ); } // if default was changed to dynamic dashboard the remove default tab and methods if (ComponentbuilderHelper::checkString($this->dynamicDashboard)) { // dynamic dashboard is used - $this->componentData->dashboard_tab = ''; + $this->componentData->dashboard_tab = ''; $this->componentData->php_dashboard_methods = ''; } } @@ -1359,9 +1767,9 @@ class Structure extends Get /** * Write data to file - * + * * @return bool true on success - * + * */ public function writeFile($path, $data) { @@ -1370,13 +1778,15 @@ class Structure extends Get /** * Build the Initial Folders - * + * * @return void - * + * */ private function setFolders() { - if (ComponentbuilderHelper::checkObject($this->joomlaVersionData->create)) + if (ComponentbuilderHelper::checkObject( + $this->joomlaVersionData->create + )) { // creat the main component folder if (!JFolder::exists($this->componentPath)) @@ -1400,9 +1810,13 @@ class Structure extends Get { foreach ($folders as $sub => $subFolders) { - if (!JFolder::exists($this->componentPath . '/' . $main . '/' . $sub)) + if (!JFolder::exists( + $this->componentPath . '/' . $main . '/' . $sub + )) { - JFolder::create($this->componentPath . '/' . $main . '/' . $sub); + JFolder::create( + $this->componentPath . '/' . $main . '/' . $sub + ); // count the folder created $this->folderCount++; $this->indexHTML($main . '/' . $sub); @@ -1411,68 +1825,250 @@ class Structure extends Get { foreach ($subFolders as $sub_2 => $subFolders_2) { - if (!JFolder::exists($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2)) + if (!JFolder::exists( + $this->componentPath . '/' . $main . '/' + . $sub . '/' . $sub_2 + )) { - JFolder::create($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2); + JFolder::create( + $this->componentPath . '/' . $main . '/' + . $sub . '/' . $sub_2 + ); // count the folder created $this->folderCount++; - $this->indexHTML($main . '/' . $sub . '/' . $sub_2); + $this->indexHTML( + $main . '/' . $sub . '/' . $sub_2 + ); } - if (ComponentbuilderHelper::checkObject($subFolders_2)) + if (ComponentbuilderHelper::checkObject( + $subFolders_2 + )) { - foreach ($subFolders_2 as $sub_3 => $subFolders_3) + foreach ( + $subFolders_2 as $sub_3 => $subFolders_3 + ) { - if (!JFolder::exists($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3)) + if (!JFolder::exists( + $this->componentPath . '/' . $main + . '/' . $sub . '/' . $sub_2 . '/' + . $sub_3 + )) { - JFolder::create($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3); + JFolder::create( + $this->componentPath . '/' + . $main . '/' . $sub . '/' + . $sub_2 . '/' . $sub_3 + ); // count the folder created $this->folderCount++; - $this->indexHTML($main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3); + $this->indexHTML( + $main . '/' . $sub . '/' + . $sub_2 . '/' . $sub_3 + ); } - if (ComponentbuilderHelper::checkObject($subFolders_3)) + if (ComponentbuilderHelper::checkObject( + $subFolders_3 + )) { - foreach ($subFolders_3 as $sub_4 => $subFolders_4) + foreach ( + $subFolders_3 as $sub_4 => + $subFolders_4 + ) { - if (!JFolder::exists($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4)) + if (!JFolder::exists( + $this->componentPath . '/' + . $main . '/' . $sub . '/' + . $sub_2 . '/' . $sub_3 + . '/' . $sub_4 + )) { - JFolder::create($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4); + JFolder::create( + $this->componentPath + . '/' . $main . '/' + . $sub . '/' . $sub_2 + . '/' . $sub_3 . '/' + . $sub_4 + ); // count the folder created $this->folderCount++; - $this->indexHTML($main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4); + $this->indexHTML( + $main . '/' . $sub . '/' + . $sub_2 . '/' . $sub_3 + . '/' . $sub_4 + ); } - if (ComponentbuilderHelper::checkObject($subFolders_4)) + if (ComponentbuilderHelper::checkObject( + $subFolders_4 + )) { - foreach ($subFolders_4 as $sub_5 => $subFolders_5) + foreach ( + $subFolders_4 as $sub_5 + => $subFolders_5 + ) { - if (!JFolder::exists($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5)) + if (!JFolder::exists( + $this->componentPath + . '/' . $main . '/' + . $sub . '/' + . $sub_2 . '/' + . $sub_3 . '/' + . $sub_4 . '/' + . $sub_5 + )) { - JFolder::create($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5); + JFolder::create( + $this->componentPath + . '/' . $main + . '/' . $sub + . '/' . $sub_2 + . '/' . $sub_3 + . '/' . $sub_4 + . '/' . $sub_5 + ); // count the folder created $this->folderCount++; - $this->indexHTML($main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5); + $this->indexHTML( + $main . '/' + . $sub . '/' + . $sub_2 . '/' + . $sub_3 . '/' + . $sub_4 . '/' + . $sub_5 + ); } - if (ComponentbuilderHelper::checkObject($subFolders_5)) + if (ComponentbuilderHelper::checkObject( + $subFolders_5 + )) { - foreach ($subFolders_5 as $sub_6 => $subFolders_6) + foreach ( + $subFolders_5 as + $sub_6 => + $subFolders_6 + ) { - if (!JFolder::exists($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5 . '/' . $sub_6)) + if (!JFolder::exists( + $this->componentPath + . '/' + . $main + . '/' . $sub + . '/' + . $sub_2 + . '/' + . $sub_3 + . '/' + . $sub_4 + . '/' + . $sub_5 + . '/' + . $sub_6 + )) { - JFolder::create($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5 . '/' . $sub_6); + JFolder::create( + $this->componentPath + . '/' + . $main + . '/' + . $sub + . '/' + . $sub_2 + . '/' + . $sub_3 + . '/' + . $sub_4 + . '/' + . $sub_5 + . '/' + . $sub_6 + ); // count the folder created $this->folderCount++; - $this->indexHTML($main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5 . '/' . $sub_6); + $this->indexHTML( + $main + . '/' + . $sub + . '/' + . $sub_2 + . '/' + . $sub_3 + . '/' + . $sub_4 + . '/' + . $sub_5 + . '/' + . $sub_6 + ); } - if (ComponentbuilderHelper::checkObject($subFolders_6)) + if (ComponentbuilderHelper::checkObject( + $subFolders_6 + )) { - foreach ($subFolders_6 as $sub_7 => $subFolders_7) + foreach ( + $subFolders_6 + as + $sub_7 + => + $subFolders_7 + ) { - if (!JFolder::exists($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5 . '/' . $sub_6 . '/' . $sub_7)) + if (!JFolder::exists( + $this->componentPath + . '/' + . $main + . '/' + . $sub + . '/' + . $sub_2 + . '/' + . $sub_3 + . '/' + . $sub_4 + . '/' + . $sub_5 + . '/' + . $sub_6 + . '/' + . $sub_7 + )) { - JFolder::create($this->componentPath . '/' . $main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5 . '/' . $sub_6 . '/' . $sub_7); + JFolder::create( + $this->componentPath + . '/' + . $main + . '/' + . $sub + . '/' + . $sub_2 + . '/' + . $sub_3 + . '/' + . $sub_4 + . '/' + . $sub_5 + . '/' + . $sub_6 + . '/' + . $sub_7 + ); // count the folder created $this->folderCount++; - $this->indexHTML($main . '/' . $sub . '/' . $sub_2 . '/' . $sub_3 . '/' . $sub_4 . '/' . $sub_5 . '/' . $sub_6 . '/' . $sub_7); + $this->indexHTML( + $main + . '/' + . $sub + . '/' + . $sub_2 + . '/' + . $sub_3 + . '/' + . $sub_4 + . '/' + . $sub_5 + . '/' + . $sub_6 + . '/' + . $sub_7 + ); } } } @@ -1489,32 +2085,43 @@ class Structure extends Get } } } + return true; } + return false; } /** * Set the Static File & Folder - * + * * @return boolean - * + * */ private function setStatic() { - if (ComponentbuilderHelper::checkObject($this->joomlaVersionData->move->static)) + if (ComponentbuilderHelper::checkObject( + $this->joomlaVersionData->move->static + )) { $codeName = $this->componentCodeName; // TODO needs more looking at this must be dynamic actualy $this->notNew[] = 'PHPExcel.php'; $this->notNew[] = 'LICENSE.txt'; // do license check - $LICENSE = false; + $LICENSE = false; $licenseChecker = strtolower($this->componentData->license); - if (strpos($licenseChecker, 'gnu') !== false && strpos($licenseChecker, '2') !== false && - (strpos($licenseChecker, 'gpl') !== false || strpos($licenseChecker, 'general public license') !== false)) + if (strpos($licenseChecker, 'gnu') !== false + && strpos( + $licenseChecker, '2' + ) !== false + && (strpos($licenseChecker, 'gpl') !== false + || strpos( + $licenseChecker, 'general public license' + ) !== false)) { - $LICENSE = true; // we only add version 2 auto at this time (TODO) + $LICENSE + = true; // we only add version 2 auto at this time (TODO) } // do README check $README = false; @@ -1524,7 +2131,9 @@ class Structure extends Get $README = true; } // start moving - foreach ($this->joomlaVersionData->move->static as $ftem => $details) + foreach ( + $this->joomlaVersionData->move->static as $ftem => $details + ) { // set item $item = $details->naam; @@ -1550,7 +2159,8 @@ class Structure extends Get continue; } // if not needed do not add - if (($item === 'README.md' || $item === 'README.txt') && !$README) + if (($item === 'README.md' || $item === 'README.txt') + && !$README) { continue; } @@ -1558,34 +2168,56 @@ class Structure extends Get if (isset($details->_target)) { // set destination path - $zipPath = str_replace($details->_target['type'] . '/', '', $details->path); - $path = str_replace($details->_target['type'] . '/', $this->dynamicPaths[$details->_target['key']] . '/', $details->path); + $zipPath = str_replace( + $details->_target['type'] . '/', '', $details->path + ); + $path = str_replace( + $details->_target['type'] . '/', + $this->dynamicPaths[$details->_target['key']] . '/', + $details->path + ); } else { // set destination path $zipPath = str_replace('c0mp0n3nt/', '', $details->path); - $path = str_replace('c0mp0n3nt/', $this->componentPath . '/', $details->path); + $path = str_replace( + 'c0mp0n3nt/', $this->componentPath . '/', $details->path + ); } // set the template folder path - $templatePath = (isset($details->custom) && $details->custom) ? (($details->custom !== 'full') ? $this->templatePathCustom . '/' : '') : $this->templatePath . '/'; + $templatePath = (isset($details->custom) && $details->custom) + ? (($details->custom !== 'full') ? $this->templatePathCustom + . '/' : '') : $this->templatePath . '/'; // set the final paths - $currentFullPath = (preg_match('/^[a-z]:/i', $item)) ? $item : $templatePath . '/' . $item; + $currentFullPath = (preg_match('/^[a-z]:/i', $item)) ? $item + : $templatePath . '/' . $item; $currentFullPath = str_replace('//', '/', $currentFullPath); $packageFullPath = str_replace('//', '/', $path . '/' . $new); - $zipFullPath = str_replace('//', '/', $zipPath . '/' . $new); + $zipFullPath = str_replace( + '//', '/', $zipPath . '/' . $new + ); // now move the file if ($details->type === 'file') { if (!JFile::exists($currentFullPath)) { - $this->app->enqueueMessage(JText::_('

File Path Error

'), 'Error'); - $this->app->enqueueMessage(JText::sprintf('The file path: %s does not exist, and was not added!', $currentFullPath), 'Error'); + $this->app->enqueueMessage( + JText::_('

File Path Error

'), 'Error' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The file path: %s does not exist, and was not added!', + $currentFullPath + ), 'Error' + ); } else { // get base name && get the path only - $packageFullPath0nly = str_replace(basename($packageFullPath), '', $packageFullPath); + $packageFullPath0nly = str_replace( + basename($packageFullPath), '', $packageFullPath + ); // check if path exist, if not creat it if (!JFolder::exists($packageFullPath0nly)) { @@ -1600,20 +2232,28 @@ class Structure extends Get { if (isset($details->_target)) { - $this->newFiles[$details->_target['key']][] = array('path' => $packageFullPath, 'name' => $new, 'zip' => $zipFullPath); + $this->newFiles[$details->_target['key']][] + = array('path' => $packageFullPath, + 'name' => $new, + 'zip' => $zipFullPath); } else { - $this->newFiles['static'][] = array('path' => $packageFullPath, 'name' => $new, 'zip' => $zipFullPath); + $this->newFiles['static'][] + = array('path' => $packageFullPath, + 'name' => $new, + 'zip' => $zipFullPath); } } // ensure we update this file if needed - if (isset($this->updateFileContent[$ftem]) && $this->updateFileContent[$ftem]) + if (isset($this->updateFileContent[$ftem]) + && $this->updateFileContent[$ftem]) { // remove the pointer unset($this->updateFileContent[$ftem]); // set the full path - $this->updateFileContent[$packageFullPath] = $packageFullPath; + $this->updateFileContent[$packageFullPath] + = $packageFullPath; } } } @@ -1621,13 +2261,23 @@ class Structure extends Get { if (!JFolder::exists($currentFullPath)) { - $this->app->enqueueMessage(JText::_('

Folder Path Error

'), 'Error'); - $this->app->enqueueMessage(JText::sprintf('The folder path: %s does not exist, and was not added!', $currentFullPath), 'Error'); + $this->app->enqueueMessage( + JText::_('

Folder Path Error

'), + 'Error' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'The folder path: %s does not exist, and was not added!', + $currentFullPath + ), 'Error' + ); } else { // move the folder to its place - JFolder::copy($currentFullPath, $packageFullPath, '', true); + JFolder::copy( + $currentFullPath, $packageFullPath, '', true + ); // count the folder created $this->folderCount++; } @@ -1639,7 +2289,8 @@ class Structure extends Get $checker = array_values((array) explode('/', $zipFullPath)); // TODO <-- this may not be the best way, will keep an eye on this. // We basicly only want to check if a folder is added that is not in the stdFolders array - if (isset($checker[0]) && ComponentbuilderHelper::checkString($checker[0]) + if (isset($checker[0]) + && ComponentbuilderHelper::checkString($checker[0]) && !in_array($checker[0], $this->stdFolders)) { // check if we should add the dynamic folder moving script to the installer script @@ -1648,11 +2299,20 @@ class Structure extends Get // add the setDynamicF0ld3rs() method to the install scipt.php file $this->setMoveFolders = true; // set message that this was done (will still add a tutorial link later) - $this->app->enqueueMessage(JText::_('

Dynamic folder/s were detected.

'), 'Notice'); - $this->app->enqueueMessage(JText::sprintf('A method (setDynamicF0ld3rs) was added to the install script.php of this package to insure that the folder/s are copied into the correct place when this componet is installed!'), 'Notice'); + $this->app->enqueueMessage( + JText::_( + '

Dynamic folder/s were detected.

' + ), 'Notice' + ); + $this->app->enqueueMessage( + JText::sprintf( + 'A method (setDynamicF0ld3rs) was added to the install script.php of this package to insure that the folder/s are copied into the correct place when this componet is installed!' + ), 'Notice' + ); } } - elseif (count((array) $checker) == 2 && ComponentbuilderHelper::checkString($checker[0])) + elseif (count((array) $checker) == 2 + && ComponentbuilderHelper::checkString($checker[0])) { $add_to_extra = false; // set the target @@ -1662,13 +2322,14 @@ class Structure extends Get if ($details->type === 'folder') { // only folders outside the standard folder are added - $eNAME = 'FOLDERS'; - $ename = 'folder'; + $eNAME = 'FOLDERS'; + $ename = 'folder'; $add_to_extra = true; } // if this is a file, it can only be added to the admin/site/media folders // all other folders are moved as a whole so their files do not need to be declared - elseif (in_array($checker[0], $this->stdFolders) && !in_array($checker[1], $this->stdRootFiles)) + elseif (in_array($checker[0], $this->stdFolders) + && !in_array($checker[1], $this->stdRootFiles)) { $add_to_extra = true; } @@ -1682,27 +2343,41 @@ class Structure extends Get $eTab = $this->_t(3); } // set the xml file - $this->fileContentStatic[$this->hhh . 'EXSTRA_' . ComponentbuilderHelper::safeString($checker[0], 'U') . '_' . $eNAME . $this->hhh] .= PHP_EOL . $eTab . "<" . $ename . ">" . $checker[1] . ""; + $this->fileContentStatic[$this->hhh . 'EXSTRA_' + . ComponentbuilderHelper::safeString( + $checker[0], 'U' + ) . '_' . $eNAME . $this->hhh] + .= PHP_EOL . $eTab . "<" . $ename . ">" + . $checker[1] . ""; } } } } + return true; } + return false; } /** * Set the Dynamic File & Folder - * + * * @return boolean - * + * */ private function setDynamique() { - $back = false; + $back = false; $front = false; - if ((isset($this->joomlaVersionData->move->dynamic) && ComponentbuilderHelper::checkObject($this->joomlaVersionData->move->dynamic)) && (isset($this->componentData->admin_views) && ComponentbuilderHelper::checkArray($this->componentData->admin_views))) + if ((isset($this->joomlaVersionData->move->dynamic) + && ComponentbuilderHelper::checkObject( + $this->joomlaVersionData->move->dynamic + )) + && (isset($this->componentData->admin_views) + && ComponentbuilderHelper::checkArray( + $this->componentData->admin_views + ))) { if (!ComponentbuilderHelper::checkString($this->dynamicDashboard)) { @@ -1715,30 +2390,55 @@ class Structure extends Get { if (ComponentbuilderHelper::checkObject($view['settings'])) { - $created = $this->getCreatedDate($view); + $created = $this->getCreatedDate($view); $modified = $this->getLastModifiedDate($view); if ($view['settings']->name_list != 'null') { - $target = array('admin' => $view['settings']->name_list); - $config = array($this->hhh . 'CREATIONDATE' . $this->hhh => $created, $this->hhh . 'BUILDDATE' . $this->hhh => $modified, $this->hhh . 'VERSION' . $this->hhh => $view['settings']->version); + $target + = array('admin' => $view['settings']->name_list); + $config = array($this->hhh . 'CREATIONDATE' + . $this->hhh => $created, + $this->hhh . 'BUILDDATE' + . $this->hhh => $modified, + $this->hhh . 'VERSION' + . $this->hhh => $view['settings']->version); $this->buildDynamique($target, 'list', false, $config); } if ($view['settings']->name_single != 'null') { - $target = array('admin' => $view['settings']->name_single); - $config = array($this->hhh . 'CREATIONDATE' . $this->hhh => $created, $this->hhh . 'BUILDDATE' . $this->hhh => $modified, $this->hhh . 'VERSION' . $this->hhh => $view['settings']->version); - $this->buildDynamique($target, 'single', false, $config); + $target + = array('admin' => $view['settings']->name_single); + $config = array($this->hhh . 'CREATIONDATE' + . $this->hhh => $created, + $this->hhh . 'BUILDDATE' + . $this->hhh => $modified, + $this->hhh . 'VERSION' + . $this->hhh => $view['settings']->version); + $this->buildDynamique( + $target, 'single', false, $config + ); } - if (isset($view['edit_create_site_view']) && is_numeric($view['edit_create_site_view']) && $view['edit_create_site_view'] > 0) + if (isset($view['edit_create_site_view']) + && is_numeric( + $view['edit_create_site_view'] + ) + && $view['edit_create_site_view'] > 0) { // setup the front site edit-view files - $target = array('site' => $view['settings']->name_single); - $config = array($this->hhh . 'CREATIONDATE' . $this->hhh => $created, $this->hhh . 'BUILDDATE' . $this->hhh => $modified, $this->hhh . 'VERSION' . $this->hhh => $view['settings']->version); + $target + = array('site' => $view['settings']->name_single); + $config = array($this->hhh . 'CREATIONDATE' + . $this->hhh => $created, + $this->hhh . 'BUILDDATE' + . $this->hhh => $modified, + $this->hhh . 'VERSION' + . $this->hhh => $view['settings']->version); $this->buildDynamique($target, 'edit', false, $config); } } // quick set of checkin once - if (isset($view['checkin']) && $view['checkin'] == 1 && !$this->addCheckin) + if (isset($view['checkin']) && $view['checkin'] == 1 + && !$this->addCheckin) { // switch to add checking to config $this->addCheckin = true; @@ -1746,48 +2446,82 @@ class Structure extends Get } $back = true; } - if ((isset($this->joomlaVersionData->move->dynamic) && ComponentbuilderHelper::checkObject($this->joomlaVersionData->move->dynamic)) && (isset($this->componentData->site_views) && ComponentbuilderHelper::checkArray($this->componentData->site_views))) + if ((isset($this->joomlaVersionData->move->dynamic) + && ComponentbuilderHelper::checkObject( + $this->joomlaVersionData->move->dynamic + )) + && (isset($this->componentData->site_views) + && ComponentbuilderHelper::checkArray( + $this->componentData->site_views + ))) { foreach ($this->componentData->site_views as $nr => $view) { - $created = $this->getCreatedDate($view); + $created = $this->getCreatedDate($view); $modified = $this->getLastModifiedDate($view); if ($view['settings']->main_get->gettype == 2) { // set list view $target = array('site' => $view['settings']->code); - $config = array($this->hhh . 'CREATIONDATE' . $this->hhh => $created, $this->hhh . 'BUILDDATE' . $this->hhh => $modified, $this->hhh . 'VERSION' . $this->hhh => $view['settings']->version); + $config = array($this->hhh . 'CREATIONDATE' + . $this->hhh => $created, + $this->hhh . 'BUILDDATE' + . $this->hhh => $modified, + $this->hhh . 'VERSION' + . $this->hhh => $view['settings']->version); $this->buildDynamique($target, 'list', false, $config); } elseif ($view['settings']->main_get->gettype == 1) { // set single view $target = array('site' => $view['settings']->code); - $config = array($this->hhh . 'CREATIONDATE' . $this->hhh => $created, $this->hhh . 'BUILDDATE' . $this->hhh => $modified, $this->hhh . 'VERSION' . $this->hhh => $view['settings']->version); + $config = array($this->hhh . 'CREATIONDATE' + . $this->hhh => $created, + $this->hhh . 'BUILDDATE' + . $this->hhh => $modified, + $this->hhh . 'VERSION' + . $this->hhh => $view['settings']->version); $this->buildDynamique($target, 'single', false, $config); } } $front = true; } - if ((isset($this->joomlaVersionData->move->dynamic) && ComponentbuilderHelper::checkObject($this->joomlaVersionData->move->dynamic)) && (isset($this->componentData->custom_admin_views) && ComponentbuilderHelper::checkArray($this->componentData->custom_admin_views))) + if ((isset($this->joomlaVersionData->move->dynamic) + && ComponentbuilderHelper::checkObject( + $this->joomlaVersionData->move->dynamic + )) + && (isset($this->componentData->custom_admin_views) + && ComponentbuilderHelper::checkArray( + $this->componentData->custom_admin_views + ))) { foreach ($this->componentData->custom_admin_views as $nr => $view) { - $created = $this->getCreatedDate($view); + $created = $this->getCreatedDate($view); $modified = $this->getLastModifiedDate($view); if ($view['settings']->main_get->gettype == 2) { // set list view$view $target = array('custom_admin' => $view['settings']->code); - $config = array($this->hhh . 'CREATIONDATE' . $this->hhh => $created, $this->hhh . 'BUILDDATE' . $this->hhh => $modified, $this->hhh . 'VERSION' . $this->hhh => $view['settings']->version); + $config = array($this->hhh . 'CREATIONDATE' + . $this->hhh => $created, + $this->hhh . 'BUILDDATE' + . $this->hhh => $modified, + $this->hhh . 'VERSION' + . $this->hhh => $view['settings']->version); $this->buildDynamique($target, 'list', false, $config); } elseif ($view['settings']->main_get->gettype == 1) { // set single view $target = array('custom_admin' => $view['settings']->code); - $config = array($this->hhh . 'CREATIONDATE' . $this->hhh => $created, $this->hhh . 'BUILDDATE' . $this->hhh => $modified, $this->hhh . 'VERSION' . $this->hhh => $view['settings']->version); + $config = array($this->hhh . 'CREATIONDATE' + . $this->hhh => $created, + $this->hhh . 'BUILDDATE' + . $this->hhh => $modified, + $this->hhh . 'VERSION' + . $this->hhh => $view['settings']->version); $this->buildDynamique($target, 'single', false, $config); } } @@ -1798,6 +2532,7 @@ class Structure extends Get { return true; } + return false; } @@ -1816,32 +2551,58 @@ class Structure extends Get if (isset($this->extentionCustomfields[$field['type_name']])) { // lets check if we already moved this - if (!isset($this->extentionTrackingFilesMoved[$path . 'type' . $field['type_name']])) + if (!isset( + $this->extentionTrackingFilesMoved[$path . 'type' + . $field['type_name']] + )) { // check files exist - if (JFile::exists($this->componentPath . '/admin/models/fields/' . $field['type_name'] . '.php')) + if (JFile::exists( + $this->componentPath . '/admin/models/fields/' + . $field['type_name'] . '.php' + )) { // copy the custom field - JFile::copy($this->componentPath . '/admin/models/fields/' . $field['type_name'] . '.php', $path . '/fields/' . $field['type_name'] . '.php'); + JFile::copy( + $this->componentPath . '/admin/models/fields/' + . $field['type_name'] . '.php', + $path . '/fields/' . $field['type_name'] . '.php' + ); } // stop from doing this again. - $this->extentionTrackingFilesMoved[$path . 'type' . $field['type_name']] = true; + $this->extentionTrackingFilesMoved[$path . 'type' + . $field['type_name']] + = true; } } // check if this has validation that should be moved if (isset($this->validationLinkedFields[$field['field']])) { // lets check if we already moved this - if (!isset($this->extentionTrackingFilesMoved[$path . 'rule' . $this->validationLinkedFields[$field['field']]])) + if (!isset( + $this->extentionTrackingFilesMoved[$path . 'rule' + . $this->validationLinkedFields[$field['field']]] + )) { // check files exist - if (JFile::exists($this->componentPath . '/admin/models/rules/' . $this->validationLinkedFields[$field['field']] . '.php')) + if (JFile::exists( + $this->componentPath . '/admin/models/rules/' + . $this->validationLinkedFields[$field['field']] . '.php' + )) { // copy the custom field - JFile::copy($this->componentPath . '/admin/models/rules/' . $this->validationLinkedFields[$field['field']] . '.php', $path . '/rules/' . $this->validationLinkedFields[$field['field']] . '.php'); + JFile::copy( + $this->componentPath . '/admin/models/rules/' + . $this->validationLinkedFields[$field['field']] + . '.php', $path . '/rules/' + . $this->validationLinkedFields[$field['field']] + . '.php' + ); } // stop from doing this again. - $this->extentionTrackingFilesMoved[$path . 'rule' . $this->validationLinkedFields[$field['field']]] = true; + $this->extentionTrackingFilesMoved[$path . 'rule' + . $this->validationLinkedFields[$field['field']]] + = true; } } } @@ -1849,14 +2610,15 @@ class Structure extends Get /** * get the created date of the (view) * - * @param array $view The view values + * @param array $view The view values * * @return string Last Modified Date * */ public function getCreatedDate($view) { - if (isset($view['settings']->created) && ComponentbuilderHelper::checkString($view['settings']->created)) + if (isset($view['settings']->created) + && ComponentbuilderHelper::checkString($view['settings']->created)) { // first set the main date $date = strtotime($view['settings']->created); @@ -1866,13 +2628,14 @@ class Structure extends Get // first set the main date $date = strtotime("now"); } + return JFactory::getDate($date)->format('jS F, Y'); } /** * get the last modified date of a MVC (view) * - * @param array $view The view values + * @param array $view The view values * * @return string Last Modified Date * @@ -1880,7 +2643,9 @@ class Structure extends Get public function getLastModifiedDate($view) { // first set the main date - if (isset($view['settings']->modified) && ComponentbuilderHelper::checkString($view['settings']->modified) && '0000-00-00 00:00:00' !== $view['settings']->modified) + if (isset($view['settings']->modified) + && ComponentbuilderHelper::checkString($view['settings']->modified) + && '0000-00-00 00:00:00' !== $view['settings']->modified) { $date = strtotime($view['settings']->modified); } @@ -1896,13 +2661,27 @@ class Structure extends Get // now check if value has been set if (!isset($this->lastModifiedDate[$id])) { - if (isset($view['settings']->fields) && ComponentbuilderHelper::checkArray($view['settings']->fields)) + if (isset($view['settings']->fields) + && ComponentbuilderHelper::checkArray( + $view['settings']->fields + )) { foreach ($view['settings']->fields as $field) { - if (isset($field['settings']) && ComponentbuilderHelper::checkObject($field['settings']) && isset($field['settings']->modified) && ComponentbuilderHelper::checkString($field['settings']->modified) && '0000-00-00 00:00:00' !== $field['settings']->modified) + if (isset($field['settings']) + && ComponentbuilderHelper::checkObject( + $field['settings'] + ) + && isset($field['settings']->modified) + && ComponentbuilderHelper::checkString( + $field['settings']->modified + ) + && '0000-00-00 00:00:00' + !== $field['settings']->modified) { - $anotherDate = strtotime($field['settings']->modified); + $anotherDate = strtotime( + $field['settings']->modified + ); if ($anotherDate > $date) { $date = $anotherDate; @@ -1918,9 +2697,16 @@ class Structure extends Get // now check if value has been set if (!isset($this->lastModifiedDate[$id])) { - if (isset($view['settings']->main_get->modified) && ComponentbuilderHelper::checkString($view['settings']->main_get->modified) && '0000-00-00 00:00:00' !== $view['settings']->main_get->modified) + if (isset($view['settings']->main_get->modified) + && ComponentbuilderHelper::checkString( + $view['settings']->main_get->modified + ) + && '0000-00-00 00:00:00' + !== $view['settings']->main_get->modified) { - $anotherDate = strtotime($view['settings']->main_get->modified); + $anotherDate = strtotime( + $view['settings']->main_get->modified + ); if ($anotherDate > $date) { $date = $anotherDate; @@ -1934,9 +2720,16 @@ class Structure extends Get // now check if value has been set if (!isset($this->lastModifiedDate[$id])) { - if (isset($view['settings']->main_get->modified) && ComponentbuilderHelper::checkString($view['settings']->main_get->modified) && '0000-00-00 00:00:00' !== $view['settings']->main_get->modified) + if (isset($view['settings']->main_get->modified) + && ComponentbuilderHelper::checkString( + $view['settings']->main_get->modified + ) + && '0000-00-00 00:00:00' + !== $view['settings']->main_get->modified) { - $anotherDate = strtotime($view['settings']->main_get->modified); + $anotherDate = strtotime( + $view['settings']->main_get->modified + ); if ($anotherDate > $date) { $date = $anotherDate; @@ -1955,22 +2748,25 @@ class Structure extends Get $this->lastModifiedDate[$id] = $date; } - return JFactory::getDate($this->lastModifiedDate[$id])->format('jS F, Y'); + return JFactory::getDate($this->lastModifiedDate[$id])->format( + 'jS F, Y' + ); } /** * Set the Static File & Folder * - * @param array $target The main target and name - * @param string $type The type in the target - * @param string $fileName The custom file name - * @param array $cofig to add more data to the files info + * @param array $target The main target and name + * @param string $type The type in the target + * @param string $fileName The custom file name + * @param array $cofig to add more data to the files info * * @return boolean * */ - public function buildDynamique($target, $type, $fileName = false, $config = false) - { + public function buildDynamique($target, $type, $fileName = false, + $config = false + ) { // did we build the files (any number) $build_status = false; // check that we have the target values @@ -1982,7 +2778,10 @@ class Structure extends Get // make sure it is lower case $name = ComponentbuilderHelper::safeString($name); // setup the files - foreach ($this->joomlaVersionData->move->dynamic->{$main} as $item => $details) + foreach ( + $this->joomlaVersionData->move->dynamic->{$main} as $item => + $details + ) { if ($details->type === $type) { @@ -1997,7 +2796,9 @@ class Structure extends Get $path = $details->path; } $zipPath = str_replace('c0mp0n3nt/', '', $path); - $path = str_replace('c0mp0n3nt/', $this->componentPath . '/', $path); + $path = str_replace( + 'c0mp0n3nt/', $this->componentPath . '/', $path + ); // setup the folder if (!JFolder::exists($path)) @@ -2012,7 +2813,9 @@ class Structure extends Get { if ($fileName) { - $new = str_replace($details->rename, $fileName, $item); + $new = str_replace( + $details->rename, $fileName, $item + ); $name = $name . '_' . $fileName; } elseif ($details->rename === 'new') @@ -2021,7 +2824,9 @@ class Structure extends Get } else { - $new = str_replace($details->rename, $name, $item); + $new = str_replace( + $details->rename, $name, $item + ); } } else @@ -2031,12 +2836,17 @@ class Structure extends Get if (!JFile::exists($path . '/' . $new)) { // move the file to its place - JFile::copy($this->templatePath . '/' . $item, $path . '/' . $new, '', true); + JFile::copy( + $this->templatePath . '/' . $item, + $path . '/' . $new, '', true + ); // count the file created $this->fileCount++; } // setup array for new file - $newFIle = array('path' => $path . '/' . $new, 'name' => $new, 'view' => $name, 'zip' => $zipPath . '/' . $new); + $newFIle = array('path' => $path . '/' . $new, + 'name' => $new, 'view' => $name, + 'zip' => $zipPath . '/' . $new); if (ComponentbuilderHelper::checkArray($config)) { $newFIle['config'] = $config; @@ -2049,6 +2859,7 @@ class Structure extends Get } } } + return $build_status; } @@ -2061,41 +2872,65 @@ class Structure extends Get private function setJoomlaVersionData() { // set the version data - $versionData = json_decode(ComponentbuilderHelper::getFileContents($this->templatePath . '/settings.json')); + $versionData = json_decode( + ComponentbuilderHelper::getFileContents( + $this->templatePath . '/settings.json' + ) + ); // add custom folders - if ((isset($this->componentData->folders) && ComponentbuilderHelper::checkArray($this->componentData->folders)) || $this->addEximport || $this->uikit || $this->footable) + if ((isset($this->componentData->folders) + && ComponentbuilderHelper::checkArray( + $this->componentData->folders + )) + || $this->addEximport + || $this->uikit + || $this->footable) { if ($this->addEximport) { // move the import view folder in place - $importView = array('folder' => 'importViews', 'path' => 'admin/views/import', 'rename' => 1); + $importView = array('folder' => 'importViews', + 'path' => 'admin/views/import', + 'rename' => 1); $this->componentData->folders[] = $importView; // move the PHPExel Folder - $PHPExcel = array('folder' => 'PHPExcel', 'path' => 'admin/helpers', 'rename' => 0); + $PHPExcel = array('folder' => 'PHPExcel', + 'path' => 'admin/helpers', + 'rename' => 0); $this->componentData->folders[] = $PHPExcel; } if (2 == $this->uikit || 1 == $this->uikit) { // move the UIKIT Folder into place - $uikit = array('folder' => 'uikit-v2', 'path' => 'media', 'rename' => 0); + $uikit = array('folder' => 'uikit-v2', + 'path' => 'media', + 'rename' => 0); $this->componentData->folders[] = $uikit; } if (2 == $this->uikit || 3 == $this->uikit) { // move the UIKIT-3 Folder into place - $uikit = array('folder' => 'uikit-v3', 'path' => 'media', 'rename' => 0); + $uikit = array('folder' => 'uikit-v3', + 'path' => 'media', + 'rename' => 0); $this->componentData->folders[] = $uikit; } - if ($this->footable && (!isset($this->footableVersion) || 2 == $this->footableVersion)) + if ($this->footable + && (!isset($this->footableVersion) + || 2 == $this->footableVersion)) { // move the footable folder into place - $footable = array('folder' => 'footable-v2', 'path' => 'media', 'rename' => 0); + $footable = array('folder' => 'footable-v2', + 'path' => 'media', + 'rename' => 0); $this->componentData->folders[] = $footable; } elseif ($this->footable && 3 == $this->footableVersion) { // move the footable folder into place - $footable = array('folder' => 'footable-v3', 'path' => 'media', 'rename' => 0); + $footable = array('folder' => 'footable-v3', + 'path' => 'media', + 'rename' => 0); $this->componentData->folders[] = $footable; } @@ -2110,9 +2945,12 @@ class Structure extends Get $_target_type = $custom['target_type']; } // for good practice - ComponentbuilderHelper::fixPath($custom, array('path', 'folder', 'folderpath')); + ComponentbuilderHelper::fixPath( + $custom, array('path', 'folder', 'folderpath') + ); // fix custom path - if (isset($custom['path']) && ComponentbuilderHelper::checkString($custom['path'])) + if (isset($custom['path']) + && ComponentbuilderHelper::checkString($custom['path'])) { $custom['path'] = trim($custom['path'], '/'); } @@ -2122,9 +2960,13 @@ class Structure extends Get if (!isset($custom['folder']) && isset($custom['folderpath'])) { // update the dynamic path - $custom['folderpath'] = $this->updateDynamicPath($custom['folderpath']); + $custom['folderpath'] = $this->updateDynamicPath( + $custom['folderpath'] + ); // set the folder path with / if does not have a drive/windows full path - $custom['folder'] = (preg_match('/^[a-z]:/i', $custom['folderpath'])) + $custom['folder'] = (preg_match( + '/^[a-z]:/i', $custom['folderpath'] + )) ? trim($custom['folderpath'], '/') : '/' . trim($custom['folderpath'], '/'); // remove the file path @@ -2133,67 +2975,94 @@ class Structure extends Get $customPath = 'full'; } // make sure we use the correct name - $pathArray = (array) explode('/', $custom['path']); + $pathArray = (array) explode('/', $custom['path']); $firstFolder = array_values($pathArray)[0]; - $lastFolder = end($pathArray); + $lastFolder = end($pathArray); // only rename folder if last has folder name if (isset($custom['rename']) && $custom['rename'] == 1) { - $custom['path'] = str_replace('/' . $lastFolder, '', $custom['path']); - $rename = 'new'; - $newname = $lastFolder; + $custom['path'] = str_replace( + '/' . $lastFolder, '', $custom['path'] + ); + $rename = 'new'; + $newname = $lastFolder; } elseif ('full' === $customPath) { // make sure we use the correct name $folderArray = (array) explode('/', $custom['folder']); - $lastFolder = end($folderArray); - $rename = 'new'; - $newname = $lastFolder; + $lastFolder = end($folderArray); + $rename = 'new'; + $newname = $lastFolder; } else { $lastFolder = $custom['folder']; - $rename = false; - $newname = ''; + $rename = false; + $newname = ''; } // insure we have no duplicates - $key_pointer = ComponentbuilderHelper::safeString($custom['folder']) . '_f' . $pointer_tracker; + $key_pointer = ComponentbuilderHelper::safeString( + $custom['folder'] + ) . '_f' . $pointer_tracker; $pointer_tracker++; // fix custom path $custom['path'] = ltrim($custom['path'], '/'); // set new folder to object - $versionData->move->static->{$key_pointer} = new stdClass(); - $versionData->move->static->{$key_pointer}->naam = str_replace('//','/', $custom['folder']); - $versionData->move->static->{$key_pointer}->path = $_target_type. '/' . $custom['path']; - $versionData->move->static->{$key_pointer}->rename = $rename; + $versionData->move->static->{$key_pointer} = new stdClass( + ); + $versionData->move->static->{$key_pointer}->naam + = str_replace( + '//', '/', $custom['folder'] + ); + $versionData->move->static->{$key_pointer}->path + = $_target_type + . '/' . $custom['path']; + $versionData->move->static->{$key_pointer}->rename = $rename; $versionData->move->static->{$key_pointer}->newName = $newname; - $versionData->move->static->{$key_pointer}->type = 'folder'; - $versionData->move->static->{$key_pointer}->custom = $customPath; + $versionData->move->static->{$key_pointer}->type = 'folder'; + $versionData->move->static->{$key_pointer}->custom + = $customPath; // set the target if type and id is found - if (isset($custom['target_id']) && isset($custom['target_type'])) + if (isset($custom['target_id']) + && isset($custom['target_type'])) { - $versionData->move->static->{$key_pointer}->_target = array('key' => $custom['target_id'] . '_' . $custom['target_type'], 'type' => $custom['target_type']); + $versionData->move->static->{$key_pointer}->_target + = array('key' => $custom['target_id'] . '_' + . $custom['target_type'], + 'type' => $custom['target_type']); } } unset($this->componentData->folders); unset($custom); } // add custom files - if ((isset($this->componentData->files) && ComponentbuilderHelper::checkArray($this->componentData->files)) || $this->addEximport || $this->googlechart) + if ((isset($this->componentData->files) + && ComponentbuilderHelper::checkArray( + $this->componentData->files + )) + || $this->addEximport + || $this->googlechart) { if ($this->addEximport) { // move the PHPExel main file - $PHPExcel = array('file' => 'PHPExcel.php', 'path' => 'admin/helpers', 'rename' => 0); + $PHPExcel = array('file' => 'PHPExcel.php', + 'path' => 'admin/helpers', + 'rename' => 0); $this->componentData->files[] = $PHPExcel; } if ($this->googlechart) { // move the google chart files - $googleChart = array('file' => 'google.jsapi.js', 'path' => 'media/js', 'rename' => 0); + $googleChart = array('file' => 'google.jsapi.js', + 'path' => 'media/js', + 'rename' => 0); $this->componentData->files[] = $googleChart; - $googleChart = array('file' => 'chartbuilder.php', 'path' => 'admin/helpers', 'rename' => 0); + $googleChart + = array('file' => 'chartbuilder.php', + 'path' => 'admin/helpers', + 'rename' => 0); $this->componentData->files[] = $googleChart; } @@ -2208,16 +3077,22 @@ class Structure extends Get $_target_type = $custom['target_type']; } // for good practice - ComponentbuilderHelper::fixPath($custom, array('path', 'file', 'filepath')); + ComponentbuilderHelper::fixPath( + $custom, array('path', 'file', 'filepath') + ); // by default custom path is true $customPath = 'custom'; // set full path if this is a full path file if (!isset($custom['file']) && isset($custom['filepath'])) { // update the dynamic path - $custom['filepath'] = $this->updateDynamicPath($custom['filepath']); + $custom['filepath'] = $this->updateDynamicPath( + $custom['filepath'] + ); // set the file path with / if does not have a drive/windows full path - $custom['file'] = (preg_match('/^[a-z]:/i', $custom['filepath'])) + $custom['file'] = (preg_match( + '/^[a-z]:/i', $custom['filepath'] + )) ? trim($custom['filepath'], '/') : '/' . trim($custom['filepath'], '/'); // remove the file path @@ -2226,22 +3101,32 @@ class Structure extends Get $customPath = 'full'; } // make sure we have not duplicates - $key_pointer = ComponentbuilderHelper::safeString($custom['file']) . '_g' . $pointer_tracker; + $key_pointer = ComponentbuilderHelper::safeString( + $custom['file'] + ) . '_g' . $pointer_tracker; $pointer_tracker++; // set new file to object - $versionData->move->static->{$key_pointer} = new stdClass(); - $versionData->move->static->{$key_pointer}->naam = str_replace('//','/',$custom['file']); + $versionData->move->static->{$key_pointer} = new stdClass( + ); + $versionData->move->static->{$key_pointer}->naam = str_replace( + '//', '/', $custom['file'] + ); // update the dynamic component name placholders in file names - $custom['path'] = $this->setPlaceholders($custom['path'], $this->placeholders); + $custom['path'] = $this->setPlaceholders( + $custom['path'], $this->placeholders + ); // get the path info $pathInfo = pathinfo($custom['path']); if (isset($pathInfo['extension']) && $pathInfo['extension']) { $pathInfo['dirname'] = trim($pathInfo['dirname'], '/'); // set the info - $versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $pathInfo['dirname']; + $versionData->move->static->{$key_pointer}->path + = $_target_type + . '/' . $pathInfo['dirname']; $versionData->move->static->{$key_pointer}->rename = 'new'; - $versionData->move->static->{$key_pointer}->newName = $pathInfo['basename']; + $versionData->move->static->{$key_pointer}->newName + = $pathInfo['basename']; } elseif ('full' === $customPath) { @@ -2250,27 +3135,39 @@ class Structure extends Get // get file array $fileArray = (array) explode('/', $custom['file']); // set the info - $versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $custom['path']; - $versionData->move->static->{$key_pointer}->rename = 'new'; - $versionData->move->static->{$key_pointer}->newName = end($fileArray); + $versionData->move->static->{$key_pointer}->path + = $_target_type + . '/' . $custom['path']; + $versionData->move->static->{$key_pointer}->rename = 'new'; + $versionData->move->static->{$key_pointer}->newName = end( + $fileArray + ); } else { // fix custom path $custom['path'] = ltrim($custom['path'], '/'); // set the info - $versionData->move->static->{$key_pointer}->path = $_target_type . '/' . $custom['path']; + $versionData->move->static->{$key_pointer}->path + = $_target_type + . '/' . $custom['path']; $versionData->move->static->{$key_pointer}->rename = false; } $versionData->move->static->{$key_pointer}->type = 'file'; - $versionData->move->static->{$key_pointer}->custom = $customPath; + $versionData->move->static->{$key_pointer}->custom + = $customPath; // set the target if type and id is found - if (isset($custom['target_id']) && isset($custom['target_type'])) + if (isset($custom['target_id']) + && isset($custom['target_type'])) { - $versionData->move->static->{$key_pointer}->_target = array('key' => $custom['target_id'] . '_' . $custom['target_type'], 'type' => $custom['target_type']); + $versionData->move->static->{$key_pointer}->_target + = array('key' => $custom['target_id'] . '_' + . $custom['target_type'], + 'type' => $custom['target_type']); } // check if file should be updated - if (!isset($custom['notnew']) || $custom['notnew'] == 0 || $custom['notnew'] != 1) + if (!isset($custom['notnew']) || $custom['notnew'] == 0 + || $custom['notnew'] != 1) { $this->notNew[] = $key_pointer; } @@ -2283,13 +3180,14 @@ class Structure extends Get unset($this->componentData->files); unset($custom); } + return $versionData; } /** * set the index.html file in a folder path * - * @param string $path The path to place the index.html file in + * @param string $path The path to place the index.html file in * * @return void * @@ -2303,13 +3201,18 @@ class Structure extends Get // use path if exist if (strlen($path) > 0) { - JFile::copy($this->templatePath . '/index.html', $root . '/' . $path . '/index.html'); + JFile::copy( + $this->templatePath . '/index.html', + $root . '/' . $path . '/index.html' + ); // count the file created $this->fileCount++; } else { - JFile::copy($this->templatePath . '/index.html', $root . '/index.html'); + JFile::copy( + $this->templatePath . '/index.html', $root . '/index.html' + ); // count the file created $this->fileCount++; } @@ -2317,25 +3220,29 @@ class Structure extends Get /** * Update paths with real value - * - * @param string $path The full path + * + * @param string $path The full path * * @return string The updated path - * + * */ protected function updateDynamicPath($path) { - return $this->setPlaceholders($this->setPlaceholders($path, ComponentbuilderHelper::$constantPaths), $this->placeholders); + return $this->setPlaceholders( + $this->setPlaceholders( + $path, ComponentbuilderHelper::$constantPaths + ), $this->placeholders + ); } /** * Remove folders with files - * + * * @param string $dir The path to folder to remove * @param boolean $ignore The files and folders to ignore * * @return boolean True if all is removed - * + * */ protected function removeFolder($dir, $ignore = false) { diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php index 9754adf52..1dc6f27d2 100644 --- a/admin/helpers/compiler/c_Fields.php +++ b/admin/helpers/compiler/c_Fields.php @@ -5,7 +5,7 @@ * @created 30th April, 2015 * @author Llewellyn van der Merwe * @github Joomla Component Builder - * @copyright Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + * @copyright Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ @@ -286,74 +286,74 @@ class Fields extends Structure /** * Get Items Method Eximport String Fix Builder - * + * * @var array */ public $getItemsMethodEximportStringFixBuilder = array(); /** * Selection Translation Fix Builder - * + * * @var array */ public $selectionTranslationFixBuilder = array(); /** * Sort Builder - * + * * @var array */ public $sortBuilder = array(); /** * Search Builder - * + * * @var array */ public $searchBuilder = array(); /** * Filter Builder - * + * * @var array */ public $filterBuilder = array(); /** * Set Group Control - * + * * @var array */ public $setGroupControl = array(); /** * Set Field Names - * + * * @var array */ public $fieldsNames = array(); /** * Default Fields set to publishing - * + * * @var array */ public $newPublishingFields = array(); /** * Default Fields set to publishing - * + * * @var array */ public $movedPublishingFields = array(); /** * Set the line number in comments - * - * @param int $nr The line number - * + * + * @param int $nr The line number + * * @return void - * + * */ private function setLine($nr) { @@ -361,24 +361,27 @@ class Fields extends Structure { return ' [Fields ' . $nr . ']'; } + return ''; } /** * set the Field set of a view - * - * @param array $view The view data - * @param string $component The component name - * @param string $view_name_single The single view name - * @param string $view_name_list The list view name + * + * @param array $view The view data + * @param string $component The component name + * @param string $view_name_single The single view name + * @param string $view_name_list The list view name * * @return string The fields set in xml - * + * */ - public function setFieldSet($view, $component, $view_name_single, $view_name_list) - { + public function setFieldSet($view, $component, $view_name_single, + $view_name_list + ) { // setup the fieldset of this view - if (isset($view['settings']->fields) && ComponentbuilderHelper::checkArray($view['settings']->fields)) + if (isset($view['settings']->fields) + && ComponentbuilderHelper::checkArray($view['settings']->fields)) { // add metadata to the view if (isset($view['metadata']) && $view['metadata']) @@ -391,106 +394,243 @@ class Fields extends Structure $this->accessBuilder[$view_name_single] = $view_name_single; } // main lang prefix - $langView = $this->langPrefix . '_' . $this->placeholders[$this->hhh . 'VIEW' . $this->hhh]; - $langViews = $this->langPrefix . '_' . $this->placeholders[$this->hhh . 'VIEWS' . $this->hhh]; + $langView = $this->langPrefix . '_' + . $this->placeholders[$this->hhh . 'VIEW' . $this->hhh]; + $langViews = $this->langPrefix . '_' + . $this->placeholders[$this->hhh . 'VIEWS' . $this->hhh]; // set default lang - $this->setLangContent($this->lang, $langView, $view['settings']->name_single); - $this->setLangContent($this->lang, $langViews, $view['settings']->name_list); + $this->setLangContent( + $this->lang, $langView, $view['settings']->name_single + ); + $this->setLangContent( + $this->lang, $langViews, $view['settings']->name_list + ); // set global item strings - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_ARCHIVED', "%s " . $view['settings']->name_list . " archived."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_ARCHIVED_1', "%s " . $view['settings']->name_single . " archived."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_CHECKED_IN_0', "No " . $view['settings']->name_single . " successfully checked in."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_CHECKED_IN_1', "%d " . $view['settings']->name_single . " successfully checked in."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_CHECKED_IN_MORE', "%d " . $view['settings']->name_list . " successfully checked in."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_DELETED', "%s " . $view['settings']->name_list . " deleted."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_DELETED_1', "%s " . $view['settings']->name_single . " deleted."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_FEATURED', "%s " . $view['settings']->name_list . " featured."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_FEATURED_1', "%s " . $view['settings']->name_single . " featured."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_PUBLISHED', "%s " . $view['settings']->name_list . " published."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_PUBLISHED_1', "%s " . $view['settings']->name_single . " published."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_TRASHED', "%s " . $view['settings']->name_list . " trashed."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_TRASHED_1', "%s " . $view['settings']->name_single . " trashed."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_UNFEATURED', "%s " . $view['settings']->name_list . " unfeatured."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_UNFEATURED_1', "%s " . $view['settings']->name_single . " unfeatured."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_UNPUBLISHED', "%s " . $view['settings']->name_list . " unpublished."); - $this->setLangContent($this->lang, $langViews . '_N_ITEMS_UNPUBLISHED_1', "%s " . $view['settings']->name_single . " unpublished."); - $this->setLangContent($this->lang, $langViews . '_BATCH_OPTIONS', "Batch process the selected " . $view['settings']->name_list); - $this->setLangContent($this->lang, $langViews . '_BATCH_TIP', "All changes will be applied to all selected " . $view['settings']->name_list); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_ARCHIVED', + "%s " . $view['settings']->name_list . " archived." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_ARCHIVED_1', + "%s " . $view['settings']->name_single . " archived." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_CHECKED_IN_0', + "No " . $view['settings']->name_single + . " successfully checked in." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_CHECKED_IN_1', + "%d " . $view['settings']->name_single + . " successfully checked in." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_CHECKED_IN_MORE', + "%d " . $view['settings']->name_list + . " successfully checked in." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_DELETED', + "%s " . $view['settings']->name_list . " deleted." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_DELETED_1', + "%s " . $view['settings']->name_single . " deleted." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_FEATURED', + "%s " . $view['settings']->name_list . " featured." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_FEATURED_1', + "%s " . $view['settings']->name_single . " featured." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_PUBLISHED', + "%s " . $view['settings']->name_list . " published." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_PUBLISHED_1', + "%s " . $view['settings']->name_single . " published." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_TRASHED', + "%s " . $view['settings']->name_list . " trashed." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_TRASHED_1', + "%s " . $view['settings']->name_single . " trashed." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_UNFEATURED', + "%s " . $view['settings']->name_list . " unfeatured." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_UNFEATURED_1', + "%s " . $view['settings']->name_single . " unfeatured." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_UNPUBLISHED', + "%s " . $view['settings']->name_list . " unpublished." + ); + $this->setLangContent( + $this->lang, $langViews . '_N_ITEMS_UNPUBLISHED_1', + "%s " . $view['settings']->name_single . " unpublished." + ); + $this->setLangContent( + $this->lang, $langViews . '_BATCH_OPTIONS', + "Batch process the selected " . $view['settings']->name_list + ); + $this->setLangContent( + $this->lang, $langViews . '_BATCH_TIP', + "All changes will be applied to all selected " + . $view['settings']->name_list + ); // set some basic defaults - $this->setLangContent($this->lang, $langView . '_ERROR_UNIQUE_ALIAS', "Another " . $view['settings']->name_single . " has the same alias."); - $this->setLangContent($this->lang, $langView . '_CREATED_DATE_LABEL', "Created Date"); - $this->setLangContent($this->lang, $langView . '_CREATED_DATE_DESC', "The date this " . $view['settings']->name_single . " was created."); - $this->setLangContent($this->lang, $langView . '_MODIFIED_DATE_LABEL', "Modified Date"); - $this->setLangContent($this->lang, $langView . '_MODIFIED_DATE_DESC', "The date this " . $view['settings']->name_single . " was modified."); - $this->setLangContent($this->lang, $langView . '_CREATED_BY_LABEL', "Created By"); - $this->setLangContent($this->lang, $langView . '_CREATED_BY_DESC', "The user that created this " . $view['settings']->name_single . "."); - $this->setLangContent($this->lang, $langView . '_MODIFIED_BY_LABEL', "Modified By"); - $this->setLangContent($this->lang, $langView . '_MODIFIED_BY_DESC', "The last user that modified this " . $view['settings']->name_single . "."); - $this->setLangContent($this->lang, $langView . '_ORDERING_LABEL', "Ordering"); - $this->setLangContent($this->lang, $langView . '_VERSION_LABEL', "Version"); - $this->setLangContent($this->lang, $langView . '_VERSION_DESC', "A count of the number of times this " . $view['settings']->name_single . " has been revised."); - $this->setLangContent($this->lang, $langView . '_SAVE_WARNING', "Alias already existed so a number was added at the end. You can re-edit the " . $view['settings']->name_single . " to customise the alias."); + $this->setLangContent( + $this->lang, $langView . '_ERROR_UNIQUE_ALIAS', + "Another " . $view['settings']->name_single + . " has the same alias." + ); + $this->setLangContent( + $this->lang, $langView . '_CREATED_DATE_LABEL', "Created Date" + ); + $this->setLangContent( + $this->lang, $langView . '_CREATED_DATE_DESC', + "The date this " . $view['settings']->name_single + . " was created." + ); + $this->setLangContent( + $this->lang, $langView . '_MODIFIED_DATE_LABEL', "Modified Date" + ); + $this->setLangContent( + $this->lang, $langView . '_MODIFIED_DATE_DESC', + "The date this " . $view['settings']->name_single + . " was modified." + ); + $this->setLangContent( + $this->lang, $langView . '_CREATED_BY_LABEL', "Created By" + ); + $this->setLangContent( + $this->lang, $langView . '_CREATED_BY_DESC', + "The user that created this " . $view['settings']->name_single + . "." + ); + $this->setLangContent( + $this->lang, $langView . '_MODIFIED_BY_LABEL', "Modified By" + ); + $this->setLangContent( + $this->lang, $langView . '_MODIFIED_BY_DESC', + "The last user that modified this " + . $view['settings']->name_single . "." + ); + $this->setLangContent( + $this->lang, $langView . '_ORDERING_LABEL', "Ordering" + ); + $this->setLangContent( + $this->lang, $langView . '_VERSION_LABEL', "Version" + ); + $this->setLangContent( + $this->lang, $langView . '_VERSION_DESC', + "A count of the number of times this " + . $view['settings']->name_single . " has been revised." + ); + $this->setLangContent( + $this->lang, $langView . '_SAVE_WARNING', + "Alias already existed so a number was added at the end. You can re-edit the " + . $view['settings']->name_single . " to customise the alias." + ); // check what type of field builder to use if ($this->fieldBuilderType == 1) { // build field set using string manipulation - return $this->stringFieldSet($view, $component, $view_name_single, $view_name_list, $langView, $langViews); + return $this->stringFieldSet( + $view, $component, $view_name_single, $view_name_list, + $langView, $langViews + ); } else { // build field set with simpleXMLElement class - return $this->simpleXMLFieldSet($view, $component, $view_name_single, $view_name_list, $langView, $langViews); + return $this->simpleXMLFieldSet( + $view, $component, $view_name_single, $view_name_list, + $langView, $langViews + ); } } + return ''; } /** * build field set using string manipulation * - * @param array $view The view data - * @param string $component The component name - * @param string $view_name_single The single view name - * @param string $view_name_list The list view name - * @param string $langView The language string of the view - * @param string $langViews The language string of the views + * @param array $view The view data + * @param string $component The component name + * @param string $view_name_single The single view name + * @param string $view_name_list The list view name + * @param string $langView The language string of the view + * @param string $langViews The language string of the views * * @return string The fields set in xml * */ - protected function stringFieldSet($view, $component, $view_name_single, $view_name_list, $langView, $langViews) - { + protected function stringFieldSet($view, $component, $view_name_single, + $view_name_list, $langView, $langViews + ) { // set the read only $readOnly = false; if ($view['settings']->type == 2) { - $readOnly = $this->_t(3) . 'readonly="true"' . PHP_EOL . $this->_t(3) . 'disabled="true"'; + $readOnly = $this->_t(3) . 'readonly="true"' . PHP_EOL . $this->_t( + 3 + ) . 'disabled="true"'; } // start adding dynamc fields $dynamicFields = ''; // set the custom table key $dbkey = 'g'; // Trigger Event: jcb_ce_onBeforeBuildFields - $this->triggerEvent('jcb_ce_onBeforeBuildFields', array(&$this->componentContext, &$dynamicFields, &$readOnly, &$dbkey, &$view, &$component, &$view_name_single, &$view_name_list, &$this->placeholders, &$langView, &$langViews)); + $this->triggerEvent( + 'jcb_ce_onBeforeBuildFields', + array(&$this->componentContext, &$dynamicFields, &$readOnly, + &$dbkey, &$view, &$component, &$view_name_single, + &$view_name_list, &$this->placeholders, &$langView, + &$langViews) + ); // TODO we should add the global and local view switch if field for front end foreach ($view['settings']->fields as $field) { - $dynamicFields .= $this->setDynamicField($field, $view, $view['settings']->type, $langView, $view_name_single, $view_name_list, $this->placeholders, $dbkey, true); + $dynamicFields .= $this->setDynamicField( + $field, $view, $view['settings']->type, $langView, + $view_name_single, $view_name_list, $this->placeholders, $dbkey, + true + ); } // Trigger Event: jcb_ce_onAfterBuildFields - $this->triggerEvent('jcb_ce_onAfterBuildFields', array(&$this->componentContext, &$dynamicFields, &$readOnly, &$dbkey, &$view, &$component, &$view_name_single, &$view_name_list, &$this->placeholders, &$langView, &$langViews)); + $this->triggerEvent( + 'jcb_ce_onAfterBuildFields', + array(&$this->componentContext, &$dynamicFields, &$readOnly, + &$dbkey, &$view, &$component, &$view_name_single, + &$view_name_list, &$this->placeholders, &$langView, + &$langViews) + ); // set the default fields - $fieldSet = array(); + $fieldSet = array(); $fieldSet[] = '
'; - $fieldSet[] = $this->_t(2) . ""; - $fieldSet[] = $this->_t(2) . ""; + $fieldSet[] = $this->_t(2) . ""; + $fieldSet[] = $this->_t(2) . ""; // if id is not set if (!isset($this->fieldsNames[$view_name_single]['id'])) { $fieldSet[] = $this->_t(2) . "_t(3) . "name=" . '"id"'; - $fieldSet[] = $this->_t(3) . 'type="text" class="readonly" label="JGLOBAL_FIELD_ID_LABEL"'; - $fieldSet[] = $this->_t(3) . 'description ="JGLOBAL_FIELD_ID_DESC" size="10" default="0"'; + $fieldSet[] = $this->_t(3) + . 'type="text" class="readonly" label="JGLOBAL_FIELD_ID_LABEL"'; + $fieldSet[] = $this->_t(3) + . 'description ="JGLOBAL_FIELD_ID_DESC" size="10" default="0"'; $fieldSet[] = $this->_t(3) . 'readonly="true"'; $fieldSet[] = $this->_t(2) . "/>"; // count the static field created @@ -499,12 +639,15 @@ class Fields extends Structure // if created is not set if (!isset($this->fieldsNames[$view_name_single]['created'])) { - $fieldSet[] = $this->_t(2) . ""; + $fieldSet[] = $this->_t(2) . ""; $fieldSet[] = $this->_t(2) . "_t(3) . "name=" . '"created"'; $fieldSet[] = $this->_t(3) . "type=" . '"calendar"'; - $fieldSet[] = $this->_t(3) . "label=" . '"' . $langView . '_CREATED_DATE_LABEL"'; - $fieldSet[] = $this->_t(3) . "description=" . '"' . $langView . '_CREATED_DATE_DESC"'; + $fieldSet[] = $this->_t(3) . "label=" . '"' . $langView + . '_CREATED_DATE_LABEL"'; + $fieldSet[] = $this->_t(3) . "description=" . '"' . $langView + . '_CREATED_DATE_DESC"'; $fieldSet[] = $this->_t(3) . "size=" . '"22"'; if ($readOnly) { @@ -519,16 +662,19 @@ class Fields extends Structure // if created_by is not set if (!isset($this->fieldsNames[$view_name_single]['created_by'])) { - $fieldSet[] = $this->_t(2) . ""; + $fieldSet[] = $this->_t(2) . ""; $fieldSet[] = $this->_t(2) . "_t(3) . "name=" . '"created_by"'; $fieldSet[] = $this->_t(3) . "type=" . '"user"'; - $fieldSet[] = $this->_t(3) . "label=" . '"' . $langView . '_CREATED_BY_LABEL"'; + $fieldSet[] = $this->_t(3) . "label=" . '"' . $langView + . '_CREATED_BY_LABEL"'; if ($readOnly) { $fieldSet[] = $readOnly; } - $fieldSet[] = $this->_t(3) . "description=" . '"' . $langView . '_CREATED_BY_DESC"'; + $fieldSet[] = $this->_t(3) . "description=" . '"' . $langView + . '_CREATED_BY_DESC"'; $fieldSet[] = $this->_t(2) . "/>"; // count the static field created $this->fieldCount++; @@ -536,14 +682,18 @@ class Fields extends Structure // if published is not set if (!isset($this->fieldsNames[$view_name_single]['published'])) { - $fieldSet[] = $this->_t(2) . ""; - $fieldSet[] = $this->_t(2) . "_t(3) . "description=" . '"JFIELD_PUBLISHED_DESC" class="chzn-color-state"'; + $fieldSet[] = $this->_t(2) . ""; + $fieldSet[] = $this->_t(2) . "_t(3) . "description=" + . '"JFIELD_PUBLISHED_DESC" class="chzn-color-state"'; if ($readOnly) { $fieldSet[] = $readOnly; } - $fieldSet[] = $this->_t(3) . "filter=" . '"intval" size="1" default="1" >'; + $fieldSet[] = $this->_t(3) . "filter=" + . '"intval" size="1" default="1" >'; $fieldSet[] = $this->_t(3) . ""; $fieldSet[] = $this->_t(3) . "
"; // check if metadata is added to this view - if (isset($this->metadataBuilder[$view_name_single]) && ComponentbuilderHelper::checkString($this->metadataBuilder[$view_name_single])) + if (isset($this->metadataBuilder[$view_name_single]) + && ComponentbuilderHelper::checkString( + $this->metadataBuilder[$view_name_single] + )) { if (!isset($this->fieldsNames[$view_name_single]['robots']) || !isset($this->fieldsNames[$view_name_single]['rights']) || !isset($this->fieldsNames[$view_name_single]['author'])) { - $fieldSet[] = PHP_EOL . $this->_t(1) . ""; - $fieldSet[] = $this->_t(1) . "'; + $fieldSet[] = PHP_EOL . $this->_t(1) . ""; + $fieldSet[] = $this->_t(1) . "'; $fieldSet[] = $this->_t(2) . '
_t(3) . 'label="JGLOBAL_FIELDSET_METADATA_OPTIONS">'; + $fieldSet[] = $this->_t(3) + . 'label="JGLOBAL_FIELDSET_METADATA_OPTIONS">'; // robots if (!isset($this->fieldsNames[$view_name_single]['robots'])) { - $fieldSet[] = $this->_t(3) . ""; + $fieldSet[] = $this->_t(3) . ""; $fieldSet[] = $this->_t(3) . '_t(4) . 'type="list"'; - $fieldSet[] = $this->_t(4) . 'label="JFIELD_METADATA_ROBOTS_LABEL"'; - $fieldSet[] = $this->_t(4) . 'description="JFIELD_METADATA_ROBOTS_DESC" >'; - $fieldSet[] = $this->_t(4) . ''; - $fieldSet[] = $this->_t(4) . ''; - $fieldSet[] = $this->_t(4) . ''; - $fieldSet[] = $this->_t(4) . ''; - $fieldSet[] = $this->_t(4) . ''; + $fieldSet[] = $this->_t(4) + . 'label="JFIELD_METADATA_ROBOTS_LABEL"'; + $fieldSet[] = $this->_t(4) + . 'description="JFIELD_METADATA_ROBOTS_DESC" >'; + $fieldSet[] = $this->_t(4) + . ''; + $fieldSet[] = $this->_t(4) + . ''; + $fieldSet[] = $this->_t(4) + . ''; + $fieldSet[] = $this->_t(4) + . ''; + $fieldSet[] = $this->_t(4) + . ''; $fieldSet[] = $this->_t(3) . ''; // count the static field created $this->fieldCount++; @@ -708,10 +903,13 @@ class Fields extends Structure // author if (!isset($this->fieldsNames[$view_name_single]['author'])) { - $fieldSet[] = $this->_t(3) . ""; + $fieldSet[] = $this->_t(3) . ""; $fieldSet[] = $this->_t(3) . '_t(4) . 'type="text"'; - $fieldSet[] = $this->_t(4) . 'label="JAUTHOR" description="JFIELD_METADATA_AUTHOR_DESC"'; + $fieldSet[] = $this->_t(4) + . 'label="JAUTHOR" description="JFIELD_METADATA_AUTHOR_DESC"'; $fieldSet[] = $this->_t(4) . 'size="20"'; $fieldSet[] = $this->_t(3) . "/>"; // count the static field created @@ -720,9 +918,13 @@ class Fields extends Structure // rights if (!isset($this->fieldsNames[$view_name_single]['rights'])) { - $fieldSet[] = $this->_t(3) . ""; - $fieldSet[] = $this->_t(3) . '_t(4) . 'description="JFIELD_META_RIGHTS_DESC" required="false" filter="string"'; + $fieldSet[] = $this->_t(3) . ""; + $fieldSet[] = $this->_t(3) + . '_t(4) + . 'description="JFIELD_META_RIGHTS_DESC" required="false" filter="string"'; $fieldSet[] = $this->_t(4) . 'cols="30" rows="2"'; $fieldSet[] = $this->_t(3) . "/>"; // count the static field created @@ -732,6 +934,7 @@ class Fields extends Structure $fieldSet[] = $this->_t(1) . ""; } } + // retunr the set return implode(PHP_EOL, $fieldSet); } @@ -739,18 +942,19 @@ class Fields extends Structure /** * build field set with simpleXMLElement class * - * @param array $view The view data - * @param string $component The component name - * @param string $view_name_single The single view name - * @param string $view_name_list The list view name - * @param string $langView The language string of the view - * @param string $langViews The language string of the views + * @param array $view The view data + * @param string $component The component name + * @param string $view_name_single The single view name + * @param string $view_name_list The list view name + * @param string $langView The language string of the view + * @param string $langViews The language string of the views * * @return string The fields set in xml * */ - protected function simpleXMLFieldSet($view, $component, $view_name_single, $view_name_list, $langView, $langViews) - { + protected function simpleXMLFieldSet($view, $component, $view_name_single, + $view_name_list, $langView, $langViews + ) { // set the read only $readOnlyXML = array(); if ($view['settings']->type == 2) @@ -763,34 +967,55 @@ class Fields extends Structure // set the custom table key $dbkey = 'g'; // Trigger Event: jcb_ce_onBeforeBuildFields - $this->triggerEvent('jcb_ce_onBeforeBuildFields', array(&$this->componentContext, &$dynamicFieldsXML, &$readOnlyXML, &$dbkey, &$view, &$component, &$view_name_single, &$view_name_list, &$this->placeholders, &$langView, &$langViews)); + $this->triggerEvent( + 'jcb_ce_onBeforeBuildFields', + array(&$this->componentContext, &$dynamicFieldsXML, &$readOnlyXML, + &$dbkey, &$view, &$component, &$view_name_single, + &$view_name_list, &$this->placeholders, &$langView, + &$langViews) + ); // TODO we should add the global and local view switch if field for front end foreach ($view['settings']->fields as $field) { - $dynamicFieldsXML[] = $this->setDynamicField($field, $view, $view['settings']->type, $langView, $view_name_single, $view_name_list, $this->placeholders, $dbkey, true); + $dynamicFieldsXML[] = $this->setDynamicField( + $field, $view, $view['settings']->type, $langView, + $view_name_single, $view_name_list, $this->placeholders, $dbkey, + true + ); } // Trigger Event: jcb_ce_onAfterBuildFields - $this->triggerEvent('jcb_ce_onAfterBuildFields', array(&$this->componentContext, &$dynamicFieldsXML, &$readOnlyXML, &$dbkey, &$view, &$component, &$view_name_single, &$view_name_list, &$this->placeholders, &$langView, &$langViews)); + $this->triggerEvent( + 'jcb_ce_onAfterBuildFields', + array(&$this->componentContext, &$dynamicFieldsXML, &$readOnlyXML, + &$dbkey, &$view, &$component, &$view_name_single, + &$view_name_list, &$this->placeholders, &$langView, + &$langViews) + ); // set the default fields - $XML = new simpleXMLElement(''); + $XML = new simpleXMLElement(''); $fieldSetXML = $XML->addChild('fieldset'); $fieldSetXML->addAttribute('name', 'details'); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Default Fields."); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Id Field. Type: Text (joomla)"); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) . " Default Fields." + ); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, + $this->setLine(__LINE__) . " Id Field. Type: Text (joomla)" + ); // if id is not set if (!isset($this->fieldsNames[$view_name_single]['id'])) { $attributes = array( - 'name' => 'id', - 'type' => 'text', - 'class' => 'readonly', - 'readonly' => "true", - 'label' => 'JGLOBAL_FIELD_ID_LABEL', + 'name' => 'id', + 'type' => 'text', + 'class' => 'readonly', + 'readonly' => "true", + 'label' => 'JGLOBAL_FIELD_ID_LABEL', 'description' => 'JGLOBAL_FIELD_ID_DESC', - 'size' => 10, - 'default' => 0 + 'size' => 10, + 'default' => 0 ); - $fieldXML = $fieldSetXML->addChild('field'); + $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created $this->fieldCount++; @@ -799,16 +1024,19 @@ class Fields extends Structure if (!isset($this->fieldsNames[$view_name_single]['created'])) { $attributes = array( - 'name' => 'created', - 'type' => 'calendar', - 'label' => $langView . '_CREATED_DATE_LABEL', + 'name' => 'created', + 'type' => 'calendar', + 'label' => $langView . '_CREATED_DATE_LABEL', 'description' => $langView . '_CREATED_DATE_DESC', - 'size' => 22, - 'format' => '%Y-%m-%d %H:%M:%S', - 'filter' => 'user_utc' + 'size' => 22, + 'format' => '%Y-%m-%d %H:%M:%S', + 'filter' => 'user_utc' ); $attributes = array_merge($attributes, $readOnlyXML); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Date Created Field. Type: Calendar (joomla)"); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " Date Created Field. Type: Calendar (joomla)" + ); $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created @@ -818,13 +1046,16 @@ class Fields extends Structure if (!isset($this->fieldsNames[$view_name_single]['created_by'])) { $attributes = array( - 'name' => 'created_by', - 'type' => 'user', - 'label' => $langView . '_CREATED_BY_LABEL', + 'name' => 'created_by', + 'type' => 'user', + 'label' => $langView . '_CREATED_BY_LABEL', 'description' => $langView . '_CREATED_BY_DESC', ); $attributes = array_merge($attributes, $readOnlyXML); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " User Created Field. Type: User (joomla)"); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " User Created Field. Type: User (joomla)" + ); $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created @@ -834,17 +1065,23 @@ class Fields extends Structure if (!isset($this->fieldsNames[$view_name_single]['published'])) { $attributes = array( - 'name' => 'published', - 'type' => 'list', + 'name' => 'published', + 'type' => 'list', 'label' => 'JSTATUS' ); $attributes = array_merge($attributes, $readOnlyXML); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Published Field. Type: List (joomla)"); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " Published Field. Type: List (joomla)" + ); $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created $this->fieldCount++; - foreach (array('JPUBLISHED' => 1, 'JUNPUBLISHED' => 0, 'JARCHIVED' => 2, 'JTRASHED' => -2) as $text => $value) + foreach ( + array('JPUBLISHED' => 1, 'JUNPUBLISHED' => 0, 'JARCHIVED' => 2, + 'JTRASHED' => -2) as $text => $value + ) { $optionXML = $fieldXML->addChild('option'); $optionXML->addAttribute('value', $value); @@ -855,17 +1092,20 @@ class Fields extends Structure if (!isset($this->fieldsNames[$view_name_single]['modified'])) { $attributes = array( - 'name' => 'modified', - 'type' => 'calendar', - 'class' => 'readonly', - 'label' => $langView . '_MODIFIED_DATE_LABEL', + 'name' => 'modified', + 'type' => 'calendar', + 'class' => 'readonly', + 'label' => $langView . '_MODIFIED_DATE_LABEL', 'description' => $langView . '_MODIFIED_DATE_DESC', - 'size' => 22, - 'readonly' => "true", - 'format' => '%Y-%m-%d %H:%M:%S', - 'filter' => 'user_utc' + 'size' => 22, + 'readonly' => "true", + 'format' => '%Y-%m-%d %H:%M:%S', + 'filter' => 'user_utc' + ); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " Date Modified Field. Type: Calendar (joomla)" ); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Date Modified Field. Type: Calendar (joomla)"); $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created @@ -875,33 +1115,43 @@ class Fields extends Structure if (!isset($this->fieldsNames[$view_name_single]['modified_by'])) { $attributes = array( - 'name' => 'modified_by', - 'type' => 'user', - 'label' => $langView . '_MODIFIED_BY_LABEL', + 'name' => 'modified_by', + 'type' => 'user', + 'label' => $langView . '_MODIFIED_BY_LABEL', 'description' => $langView . '_MODIFIED_BY_DESC', - 'class' => 'readonly', - 'readonly' => 'true', - 'filter' => 'unset' + 'class' => 'readonly', + 'readonly' => 'true', + 'filter' => 'unset' + ); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " User Modified Field. Type: User (joomla)" ); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " User Modified Field. Type: User (joomla)"); $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created $this->fieldCount++; } // check if view has access - if (isset($this->accessBuilder[$view_name_single]) && ComponentbuilderHelper::checkString($this->accessBuilder[$view_name_single]) && !isset($this->fieldsNames[$view_name_single]['access'])) + if (isset($this->accessBuilder[$view_name_single]) + && ComponentbuilderHelper::checkString( + $this->accessBuilder[$view_name_single] + ) + && !isset($this->fieldsNames[$view_name_single]['access'])) { $attributes = array( - 'name' => 'access', - 'type' => 'accesslevel', - 'label' => 'JFIELD_ACCESS_LABEL', + 'name' => 'access', + 'type' => 'accesslevel', + 'label' => 'JFIELD_ACCESS_LABEL', 'description' => 'JFIELD_ACCESS_DESC', - 'default' => 1, - 'required' => "false" + 'default' => 1, + 'required' => "false" ); $attributes = array_merge($attributes, $readOnlyXML); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Access Field. Type: Accesslevel (joomla)"); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " Access Field. Type: Accesslevel (joomla)" + ); $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created @@ -911,17 +1161,20 @@ class Fields extends Structure if (!isset($this->fieldsNames[$view_name_single]['ordering'])) { $attributes = array( - 'name' => 'ordering', - 'type' => 'number', - 'class' => 'inputbox validate-ordering', - 'label' => $langView . '_ORDERING_LABEL', + 'name' => 'ordering', + 'type' => 'number', + 'class' => 'inputbox validate-ordering', + 'label' => $langView . '_ORDERING_LABEL', 'description' => '', - 'default' => 0, - 'size' => 6, - 'required' => "false" + 'default' => 0, + 'size' => 6, + 'required' => "false" ); $attributes = array_merge($attributes, $readOnlyXML); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Ordering Field. Type: Numbers (joomla)"); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " Ordering Field. Type: Numbers (joomla)" + ); $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created @@ -931,50 +1184,66 @@ class Fields extends Structure if (!isset($this->fieldsNames[$view_name_single]['version'])) { $attributes = array( - 'name' => 'version', - 'type' => 'text', - 'class' => 'readonly', - 'label' => $langView . '_VERSION_LABEL', + 'name' => 'version', + 'type' => 'text', + 'class' => 'readonly', + 'label' => $langView . '_VERSION_LABEL', 'description' => $langView . '_VERSION_DESC', - 'size' => 6, - 'readonly' => "true", - 'filter' => 'unset' + 'size' => 6, + 'readonly' => "true", + 'filter' => 'unset' + ); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, + $this->setLine(__LINE__) . " Version Field. Type: Text (joomla)" ); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Version Field. Type: Text (joomla)"); $fieldXML = $fieldSetXML->addChild('field'); ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); // count the static field created $this->fieldCount++; } // check if metadata is added to this view - if (isset($this->metadataBuilder[$view_name_single]) && ComponentbuilderHelper::checkString($this->metadataBuilder[$view_name_single])) + if (isset($this->metadataBuilder[$view_name_single]) + && ComponentbuilderHelper::checkString( + $this->metadataBuilder[$view_name_single] + )) { // metakey if (!isset($this->fieldsNames[$view_name_single]['metakey'])) { $attributes = array( - 'name' => 'metakey', - 'type' => 'textarea', - 'label' => 'JFIELD_META_KEYWORDS_LABEL', + 'name' => 'metakey', + 'type' => 'textarea', + 'label' => 'JFIELD_META_KEYWORDS_LABEL', 'description' => 'JFIELD_META_KEYWORDS_DESC', - 'rows' => 3, - 'cols' => 30 + 'rows' => 3, + 'cols' => 30 + ); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " Metakey Field. Type: Textarea (joomla)" ); - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metakey Field. Type: Textarea (joomla)"); $fieldXML = $fieldSetXML->addChild('field'); - ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); + ComponentbuilderHelper::xmlAddAttributes( + $fieldXML, $attributes + ); // count the static field created $this->fieldCount++; } // metadesc if (!isset($this->fieldsNames[$view_name_single]['metadesc'])) { - $attributes['name'] = 'metadesc'; - $attributes['label'] = 'JFIELD_META_DESCRIPTION_LABEL'; + $attributes['name'] = 'metadesc'; + $attributes['label'] = 'JFIELD_META_DESCRIPTION_LABEL'; $attributes['description'] = 'JFIELD_META_DESCRIPTION_DESC'; - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metadesc Field. Type: Textarea (joomla)"); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) + . " Metadesc Field. Type: Textarea (joomla)" + ); $fieldXML = $fieldSetXML->addChild('field'); - ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes); + ComponentbuilderHelper::xmlAddAttributes( + $fieldXML, $attributes + ); // count the static field created $this->fieldCount++; } @@ -982,45 +1251,61 @@ class Fields extends Structure // load the dynamic fields now if (count((array) $dynamicFieldsXML)) { - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Dynamic Fields."); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) . " Dynamic Fields." + ); foreach ($dynamicFieldsXML as $dynamicfield) { ComponentbuilderHelper::xmlAppend($fieldSetXML, $dynamicfield); } } // check if metadata is added to this view - if (isset($this->metadataBuilder[$view_name_single]) && ComponentbuilderHelper::checkString($this->metadataBuilder[$view_name_single])) + if (isset($this->metadataBuilder[$view_name_single]) + && ComponentbuilderHelper::checkString( + $this->metadataBuilder[$view_name_single] + )) { if (!isset($this->fieldsNames[$view_name_single]['robots']) || !isset($this->fieldsNames[$view_name_single]['author']) || !isset($this->fieldsNames[$view_name_single]['rights'])) { - ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metadata Fields"); + ComponentbuilderHelper::xmlComment( + $fieldSetXML, $this->setLine(__LINE__) . " Metadata Fields" + ); $fieldsXML = $fieldSetXML->addChild('fields'); $fieldsXML->addAttribute('name', 'metadata'); - $fieldsXML->addAttribute('label', 'JGLOBAL_FIELDSET_METADATA_OPTIONS'); + $fieldsXML->addAttribute( + 'label', 'JGLOBAL_FIELDSET_METADATA_OPTIONS' + ); $fieldsFieldSetXML = $fieldsXML->addChild('fieldset'); $fieldsFieldSetXML->addAttribute('name', 'vdmmetadata'); - $fieldsFieldSetXML->addAttribute('label', 'JGLOBAL_FIELDSET_METADATA_OPTIONS'); + $fieldsFieldSetXML->addAttribute( + 'label', 'JGLOBAL_FIELDSET_METADATA_OPTIONS' + ); // robots if (!isset($this->fieldsNames[$view_name_single]['robots'])) { - ComponentbuilderHelper::xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Robots Field. Type: List (joomla)"); - $robots = $fieldsFieldSetXML->addChild('field'); + ComponentbuilderHelper::xmlComment( + $fieldsFieldSetXML, $this->setLine(__LINE__) + . " Robots Field. Type: List (joomla)" + ); + $robots = $fieldsFieldSetXML->addChild('field'); $attributes = array( - 'name' => 'robots', - 'type' => 'list', - 'label' => 'JFIELD_METADATA_ROBOTS_LABEL', + 'name' => 'robots', + 'type' => 'list', + 'label' => 'JFIELD_METADATA_ROBOTS_LABEL', 'description' => 'JFIELD_METADATA_ROBOTS_DESC' ); - ComponentbuilderHelper::xmlAddAttributes($robots, $attributes); + ComponentbuilderHelper::xmlAddAttributes( + $robots, $attributes + ); // count the static field created $this->fieldCount++; $options = array( - 'JGLOBAL_USE_GLOBAL' => '', - 'JGLOBAL_INDEX_FOLLOW' => 'index, follow', - 'JGLOBAL_NOINDEX_FOLLOW' => 'noindex, follow', - 'JGLOBAL_INDEX_NOFOLLOW' => 'index, nofollow', + 'JGLOBAL_USE_GLOBAL' => '', + 'JGLOBAL_INDEX_FOLLOW' => 'index, follow', + 'JGLOBAL_NOINDEX_FOLLOW' => 'noindex, follow', + 'JGLOBAL_INDEX_NOFOLLOW' => 'index, nofollow', 'JGLOBAL_NOINDEX_NOFOLLOW' => 'noindex, nofollow', ); foreach ($options as $text => $value) @@ -1033,40 +1318,51 @@ class Fields extends Structure // author if (!isset($this->fieldsNames[$view_name_single]['author'])) { - ComponentbuilderHelper::xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Author Field. Type: Text (joomla)"); - $author = $fieldsFieldSetXML->addChild('field'); - $attributes = array( - 'name' => 'author', - 'type' => 'text', - 'label' => 'JAUTHOR', - 'description' => 'JFIELD_METADATA_AUTHOR_DESC', - 'size' => 20 + ComponentbuilderHelper::xmlComment( + $fieldsFieldSetXML, $this->setLine(__LINE__) + . " Author Field. Type: Text (joomla)" + ); + $author = $fieldsFieldSetXML->addChild('field'); + $attributes = array( + 'name' => 'author', + 'type' => 'text', + 'label' => 'JAUTHOR', + 'description' => 'JFIELD_METADATA_AUTHOR_DESC', + 'size' => 20 + ); + ComponentbuilderHelper::xmlAddAttributes( + $author, $attributes ); - ComponentbuilderHelper::xmlAddAttributes($author, $attributes); // count the static field created $this->fieldCount++; } // rights if (!isset($this->fieldsNames[$view_name_single]['rights'])) { - ComponentbuilderHelper::xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Rights Field. Type: Textarea (joomla)"); - $rights = $fieldsFieldSetXML->addChild('field'); - $attributes = array( - 'name' => 'rights', - 'type' => 'textarea', - 'label' => 'JFIELD_META_RIGHTS_LABEL', - 'description' => 'JFIELD_META_RIGHTS_DESC', - 'required' => 'false', - 'filter' => 'string', - 'cols' => 30, - 'rows' => 2 + ComponentbuilderHelper::xmlComment( + $fieldsFieldSetXML, $this->setLine(__LINE__) + . " Rights Field. Type: Textarea (joomla)" + ); + $rights = $fieldsFieldSetXML->addChild('field'); + $attributes = array( + 'name' => 'rights', + 'type' => 'textarea', + 'label' => 'JFIELD_META_RIGHTS_LABEL', + 'description' => 'JFIELD_META_RIGHTS_DESC', + 'required' => 'false', + 'filter' => 'string', + 'cols' => 30, + 'rows' => 2 + ); + ComponentbuilderHelper::xmlAddAttributes( + $rights, $attributes ); - ComponentbuilderHelper::xmlAddAttributes($rights, $attributes); // count the static field created $this->fieldCount++; } } } + // return the set return $this->xmlPrettyPrint($XML, 'fieldset'); } @@ -1074,8 +1370,8 @@ class Fields extends Structure /** * set Field Names * - * @param string $view View the field belongs to - * @param string $name The name of the field + * @param string $view View the field belongs to + * @param string $name The name of the field * * */ @@ -1100,8 +1396,9 @@ class Fields extends Structure * @return SimpleXMLElement The complete field in xml * */ - public function setDynamicField(&$field, &$view, &$viewType, &$langView, &$view_name_single, &$view_name_list, &$placeholders, &$dbkey, $build) - { + public function setDynamicField(&$field, &$view, &$viewType, &$langView, + &$view_name_single, &$view_name_list, &$placeholders, &$dbkey, $build + ) { // set default return if ($this->fieldBuilderType == 1) { @@ -1114,33 +1411,49 @@ class Fields extends Structure $dynamicField = false; } // make sure we have settings - if (isset($field['settings']) && ComponentbuilderHelper::checkObject($field['settings'])) + if (isset($field['settings']) + && ComponentbuilderHelper::checkObject( + $field['settings'] + )) { // reset some values - $name = $this->getFieldName($field, $view_name_list); - $typeName = $this->getFieldType($field); - $multiple = false; - $langLabel = ''; - $fieldSet = ''; + $name = $this->getFieldName($field, $view_name_list); + $typeName = $this->getFieldType($field); + $multiple = false; + $langLabel = ''; + $fieldSet = ''; $fieldAttributes = array(); // set field attributes - $fieldAttributes = $this->setFieldAttributes($field, $viewType, $name, $typeName, $multiple, $langLabel, $langView, $view_name_list, $view_name_single, $placeholders); + $fieldAttributes = $this->setFieldAttributes( + $field, $viewType, $name, $typeName, $multiple, $langLabel, + $langView, $view_name_list, $view_name_single, $placeholders + ); // check if values were set if (ComponentbuilderHelper::checkArray($fieldAttributes)) { // set the array of field names - $this->setFieldsNames($view_name_single, $fieldAttributes['name']); + $this->setFieldsNames( + $view_name_single, $fieldAttributes['name'] + ); if (ComponentbuilderHelper::fieldCheck($typeName, 'option')) { //reset options array $optionArray = array(); // now add to the field set - $dynamicField = $this->setField('option', $fieldAttributes, $name, $typeName, $langView, $view_name_single, $view_name_list, $placeholders, $optionArray); + $dynamicField = $this->setField( + 'option', $fieldAttributes, $name, $typeName, $langView, + $view_name_single, $view_name_list, $placeholders, + $optionArray + ); if ($build) { // set builders - $this->setBuilders($langLabel, $langView, $view_name_single, $view_name_list, $name, $view, $field, $typeName, $multiple, false, $optionArray); + $this->setBuilders( + $langLabel, $langView, $view_name_single, + $view_name_list, $name, $view, $field, $typeName, + $multiple, false, $optionArray + ); } } elseif (ComponentbuilderHelper::fieldCheck($typeName, 'spacer')) @@ -1149,21 +1462,31 @@ class Fields extends Structure { // make sure spacers gets loaded to layout $tabName = ''; - if (isset($view['settings']->tabs) && isset($view['settings']->tabs[(int) $field['tab']])) + if (isset($view['settings']->tabs) + && isset($view['settings']->tabs[(int) $field['tab']])) { - $tabName = $view['settings']->tabs[(int) $field['tab']]; + $tabName + = $view['settings']->tabs[(int) $field['tab']]; } elseif ((int) $field['tab'] == 15) { // set to publishing tab $tabName = 'publishing'; } - $this->setLayoutBuilder($view_name_single, $tabName, $name, $field); + $this->setLayoutBuilder( + $view_name_single, $tabName, $name, $field + ); } // now add to the field set - $dynamicField = $this->setField('spacer', $fieldAttributes, $name, $typeName, $langView, $view_name_single, $view_name_list, $placeholders, $optionArray); + $dynamicField = $this->setField( + 'spacer', $fieldAttributes, $name, $typeName, $langView, + $view_name_single, $view_name_list, $placeholders, + $optionArray + ); } - elseif (ComponentbuilderHelper::fieldCheck($typeName, 'special')) + elseif (ComponentbuilderHelper::fieldCheck( + $typeName, 'special' + )) { // set the repeatable field or subform field if ($typeName === 'repeatable' || $typeName === 'subform') @@ -1171,13 +1494,24 @@ class Fields extends Structure if ($build) { // set builders - $this->setBuilders($langLabel, $langView, $view_name_single, $view_name_list, $name, $view, $field, $typeName, $multiple, false); + $this->setBuilders( + $langLabel, $langView, $view_name_single, + $view_name_list, $name, $view, $field, + $typeName, $multiple, false + ); } // now add to the field set - $dynamicField = $this->setField('special', $fieldAttributes, $name, $typeName, $langView, $view_name_single, $view_name_list, $placeholders, $optionArray); + $dynamicField = $this->setField( + 'special', $fieldAttributes, $name, $typeName, + $langView, $view_name_single, $view_name_list, + $placeholders, $optionArray + ); } } - elseif (isset($fieldAttributes['custom']) && ComponentbuilderHelper::checkArray($fieldAttributes['custom'])) + elseif (isset($fieldAttributes['custom']) + && ComponentbuilderHelper::checkArray( + $fieldAttributes['custom'] + )) { // set the custom array $custom = $fieldAttributes['custom']; @@ -1189,103 +1523,143 @@ class Fields extends Structure if ($build) { // set builders - $this->setBuilders($langLabel, $langView, $view_name_single, $view_name_list, $name, $view, $field, $typeName, $multiple, $custom); + $this->setBuilders( + $langLabel, $langView, $view_name_single, + $view_name_list, $name, $view, $field, $typeName, + $multiple, $custom + ); } // now add to the field set - $dynamicField = $this->setField('custom', $fieldAttributes, $name, $typeName, $langView, $view_name_single, $view_name_list, $placeholders, $optionArray, $custom); + $dynamicField = $this->setField( + 'custom', $fieldAttributes, $name, $typeName, $langView, + $view_name_single, $view_name_list, $placeholders, + $optionArray, $custom + ); } else { if ($build) { // set builders - $this->setBuilders($langLabel, $langView, $view_name_single, $view_name_list, $name, $view, $field, $typeName, $multiple); + $this->setBuilders( + $langLabel, $langView, $view_name_single, + $view_name_list, $name, $view, $field, $typeName, + $multiple + ); } // now add to the field set - $dynamicField = $this->setField('plain', $fieldAttributes, $name, $typeName, $langView, $view_name_single, $view_name_list, $placeholders, $optionArray); + $dynamicField = $this->setField( + 'plain', $fieldAttributes, $name, $typeName, $langView, + $view_name_single, $view_name_list, $placeholders, + $optionArray + ); } } } + return $dynamicField; } /** * set a field * - * @param string $setType The set of fields type - * @param array $fieldAttributes The field values - * @param string $name The field name - * @param string $typeName The field type - * @param string $langView The language string of the view - * @param string $view_name_single The single view name - * @param string $view_name_list The list view name - * @param array $placeholders The place holder and replace values - * @param string $optionArray The option bucket array used to set the field options if needed. - * @param array $custom Used when field is from config - * @param string $taber The tabs to add in layout (only in string manipulation) + * @param string $setType The set of fields type + * @param array $fieldAttributes The field values + * @param string $name The field name + * @param string $typeName The field type + * @param string $langView The language string of the view + * @param string $view_name_single The single view name + * @param string $view_name_list The list view name + * @param array $placeholders The place holder and replace values + * @param string $optionArray The option bucket array used to set the field options if needed. + * @param array $custom Used when field is from config + * @param string $taber The tabs to add in layout (only in string manipulation) * * @return SimpleXMLElement The field in xml * */ - private function setField($setType, &$fieldAttributes, &$name, &$typeName, &$langView, &$view_name_single, &$view_name_list, $placeholders, &$optionArray, $custom = null, $taber = '') - { + private function setField($setType, &$fieldAttributes, &$name, &$typeName, + &$langView, &$view_name_single, &$view_name_list, $placeholders, + &$optionArray, $custom = null, $taber = '' + ) { // count the dynamic fields created $this->fieldCount++; // check what type of field builder to use if ($this->fieldBuilderType == 1) { // build field set using string manipulation - return $this->stringSetField($setType, $fieldAttributes, $name, $typeName, $langView, $view_name_single, $view_name_list, $placeholders, $optionArray, $custom, $taber); + return $this->stringSetField( + $setType, $fieldAttributes, $name, $typeName, $langView, + $view_name_single, $view_name_list, $placeholders, $optionArray, + $custom, $taber + ); } else { // build field set with simpleXMLElement class - return $this->simpleXMLSetField($setType, $fieldAttributes, $name, $typeName, $langView, $view_name_single, $view_name_list, $placeholders, $optionArray, $custom); + return $this->simpleXMLSetField( + $setType, $fieldAttributes, $name, $typeName, $langView, + $view_name_single, $view_name_list, $placeholders, $optionArray, + $custom + ); } } /** * set a field using string manipulation * - * @param string $setType The set of fields type - * @param array $fieldAttributes The field values - * @param string $name The field name - * @param string $typeName The field type - * @param string $langView The language string of the view - * @param string $view_name_single The single view name - * @param string $view_name_list The list view name - * @param array $placeholders The place holder and replace values - * @param string $optionArray The option bucket array used to set the field options if needed. - * @param array $custom Used when field is from config - * @param string $taber The tabs to add in layout + * @param string $setType The set of fields type + * @param array $fieldAttributes The field values + * @param string $name The field name + * @param string $typeName The field type + * @param string $langView The language string of the view + * @param string $view_name_single The single view name + * @param string $view_name_list The list view name + * @param array $placeholders The place holder and replace values + * @param string $optionArray The option bucket array used to set the field options if needed. + * @param array $custom Used when field is from config + * @param string $taber The tabs to add in layout * * @return SimpleXMLElement The field in xml * */ - protected function stringSetField($setType, &$fieldAttributes, &$name, &$typeName, &$langView, &$view_name_single, &$view_name_list, $placeholders, &$optionArray, $custom = null, $taber = '') - { + protected function stringSetField($setType, &$fieldAttributes, &$name, + &$typeName, &$langView, &$view_name_single, &$view_name_list, + $placeholders, &$optionArray, $custom = null, $taber = '' + ) { $field = ''; if ($setType === 'option') { // now add to the field set - $field .= PHP_EOL . $this->_t(1) . $taber . $this->_t(1) . ""; - $field .= PHP_EOL . $this->_t(1) . $taber . $this->_t(1) . "_t(1) . $taber . $this->_t(1) + . ""; + $field .= PHP_EOL . $this->_t(1) . $taber . $this->_t(1) + . " $value) { if ($property != 'option') { - $field .= PHP_EOL . $this->_t(2) . $taber . $this->_t(1) . $property . '="' . $value . '"'; + $field .= PHP_EOL . $this->_t(2) . $taber . $this->_t(1) + . $property . '="' . $value . '"'; } elseif ($property === 'option') { $optionSet = ''; - if (strtolower($typeName) === 'groupedlist' && strpos($value, ',') !== false && strpos($value, '@@') !== false) + if (strtolower($typeName) === 'groupedlist' + && strpos( + $value, ',' + ) !== false + && strpos($value, '@@') !== false) { // reset the group temp arrays - $groups_ = array(); - $grouped_ = array('group' => array(), 'option' => array()); - $order_ = array(); + $groups_ = array(); + $grouped_ = array('group' => array(), + 'option' => array()); + $order_ = array(); // mulitpal options $options = explode(',', $value); foreach ($options as $option) @@ -1296,13 +1670,22 @@ class Fields extends Structure $valueKeyArray = explode('@@', $option); if (count((array) $valueKeyArray) == 2) { - $langValue = $langView . '_' . ComponentbuilderHelper::safeFieldName($valueKeyArray[0], true); + $langValue = $langView . '_' + . ComponentbuilderHelper::safeFieldName( + $valueKeyArray[0], true + ); // add to lang array - $this->setLangContent($this->lang, $langValue, $valueKeyArray[0]); + $this->setLangContent( + $this->lang, $langValue, + $valueKeyArray[0] + ); // now add group label - $groups_[$valueKeyArray[1]] = PHP_EOL . $this->_t(1) . $taber . $this->_t(2) . ''; + $groups_[$valueKeyArray[1]] = PHP_EOL + . $this->_t(1) . $taber . $this->_t(2) + . ''; // set order - $order_['group' . $valueKeyArray[1]] = $valueKeyArray[1]; + $order_['group' . $valueKeyArray[1]] + = $valueKeyArray[1]; } } elseif (strpos($option, '|') !== false) @@ -1311,36 +1694,71 @@ class Fields extends Structure $valueKeyArray = explode('|', $option); if (count((array) $valueKeyArray) == 3) { - $langValue = $langView . '_' . ComponentbuilderHelper::safeFieldName($valueKeyArray[1], true); + $langValue = $langView . '_' + . ComponentbuilderHelper::safeFieldName( + $valueKeyArray[1], true + ); // add to lang array - $this->setLangContent($this->lang, $langValue, $valueKeyArray[1]); + $this->setLangContent( + $this->lang, $langValue, + $valueKeyArray[1] + ); // now add to option set - $grouped_['group'][$valueKeyArray[2]][] = PHP_EOL . $this->_t(1) . $taber . $this->_t(3) . ''; - $optionArray[$valueKeyArray[0]] = $langValue; + $grouped_['group'][$valueKeyArray[2]][] + = PHP_EOL . $this->_t(1) . $taber + . $this->_t(3) . ''; + $optionArray[$valueKeyArray[0]] + = $langValue; // set order - $order_['group' . $valueKeyArray[2]] = $valueKeyArray[2]; + $order_['group' . $valueKeyArray[2]] + = $valueKeyArray[2]; } else { - $langValue = $langView . '_' . ComponentbuilderHelper::safeFieldName($valueKeyArray[1], true); + $langValue = $langView . '_' + . ComponentbuilderHelper::safeFieldName( + $valueKeyArray[1], true + ); // add to lang array - $this->setLangContent($this->lang, $langValue, $valueKeyArray[1]); + $this->setLangContent( + $this->lang, $langValue, + $valueKeyArray[1] + ); // now add to option set - $grouped_['option'][$valueKeyArray[0]] = PHP_EOL . $this->_t(1) . $taber . $this->_t(2) . ''; - $optionArray[$valueKeyArray[0]] = $langValue; + $grouped_['option'][$valueKeyArray[0]] + = PHP_EOL . $this->_t(1) . $taber + . $this->_t(2) . ''; + $optionArray[$valueKeyArray[0]] + = $langValue; // set order - $order_['option' . $valueKeyArray[0]] = $valueKeyArray[0]; + $order_['option' . $valueKeyArray[0]] + = $valueKeyArray[0]; } } else { // text is also the value - $langValue = $langView . '_' . ComponentbuilderHelper::safeFieldName($option, true); + $langValue = $langView . '_' + . ComponentbuilderHelper::safeFieldName( + $option, true + ); // add to lang array - $this->setLangContent($this->lang, $langValue, $option); + $this->setLangContent( + $this->lang, $langValue, $option + ); // now add to option set - $grouped_['option'][$option] = PHP_EOL . $this->_t(1) . $taber . $this->_t(2) . ''; - $optionArray[$option] = $langValue; + $grouped_['option'][$option] = PHP_EOL + . $this->_t(1) . $taber . $this->_t(2) + . ''; + $optionArray[$option] = $langValue; // set order $order_['option' . $option] = $option; } @@ -1356,7 +1774,11 @@ class Fields extends Structure $key_ = 'option'; } // check if this is a group loader - if ('group' === $key_ && isset($groups_[$_id]) && isset($grouped_[$key_][$_id]) && ComponentbuilderHelper::checkArray($grouped_[$key_][$_id])) + if ('group' === $key_ && isset($groups_[$_id]) + && isset($grouped_[$key_][$_id]) + && ComponentbuilderHelper::checkArray( + $grouped_[$key_][$_id] + )) { // set group label $optionSet .= $groups_[$_id]; @@ -1367,9 +1789,13 @@ class Fields extends Structure unset($groups_[$_id]); unset($grouped_[$key_][$_id]); // close the group - $optionSet .= PHP_EOL . $this->_t(1) . $taber . $this->_t(2) . ''; + $optionSet .= PHP_EOL . $this->_t(1) . $taber + . $this->_t(2) . ''; } - elseif (isset($grouped_[$key_][$_id]) && ComponentbuilderHelper::checkString($grouped_[$key_][$_id])) + elseif (isset($grouped_[$key_][$_id]) + && ComponentbuilderHelper::checkString( + $grouped_[$key_][$_id] + )) { $optionSet .= $grouped_[$key_][$_id]; } @@ -1385,21 +1811,39 @@ class Fields extends Structure { // has other value then text list($v, $t) = explode('|', $option); - $langValue = $langView . '_' . ComponentbuilderHelper::safeFieldName($t, true); + $langValue = $langView . '_' + . ComponentbuilderHelper::safeFieldName( + $t, true + ); // add to lang array - $this->setLangContent($this->lang, $langValue, $t); + $this->setLangContent( + $this->lang, $langValue, $t + ); // now add to option set - $optionSet .= PHP_EOL . $this->_t(1) . $taber . $this->_t(2) . ''; + $optionSet .= PHP_EOL . $this->_t(1) + . $taber . $this->_t(2) . ''; $optionArray[$v] = $langValue; } else { // text is also the value - $langValue = $langView . '_' . ComponentbuilderHelper::safeFieldName($option, true); + $langValue = $langView . '_' + . ComponentbuilderHelper::safeFieldName( + $option, true + ); // add to lang array - $this->setLangContent($this->lang, $langValue, $option); + $this->setLangContent( + $this->lang, $langValue, $option + ); // now add to option set - $optionSet .= PHP_EOL . $this->_t(2) . $taber . $this->_t(1) . ''; + $optionSet .= PHP_EOL . $this->_t(2) + . $taber . $this->_t(1) . ''; $optionArray[$option] = $langValue; } } @@ -1411,21 +1855,36 @@ class Fields extends Structure { // has other value then text list($v, $t) = explode('|', $value); - $langValue = $langView . '_' . ComponentbuilderHelper::safeFieldName($t, true); + $langValue = $langView . '_' + . ComponentbuilderHelper::safeFieldName( + $t, true + ); // add to lang array $this->setLangContent($this->lang, $langValue, $t); // now add to option set - $optionSet .= PHP_EOL . $this->_t(2) . $taber . $this->_t(1) . ''; + $optionSet .= PHP_EOL . $this->_t(2) . $taber + . $this->_t(1) . ''; $optionArray[$v] = $langValue; } else { // text is also the value - $langValue = $langView . '_' . ComponentbuilderHelper::safeFieldName($value, true); + $langValue = $langView . '_' + . ComponentbuilderHelper::safeFieldName( + $value, true + ); // add to lang array - $this->setLangContent($this->lang, $langValue, $value); + $this->setLangContent( + $this->lang, $langValue, $value + ); // now add to option set - $optionSet .= PHP_EOL . $this->_t(2) . $taber . $this->_t(1) . ''; + $optionSet .= PHP_EOL . $this->_t(2) + . $taber . $this->_t(1) . ''; $optionArray[$value] = $langValue; } } @@ -1435,7 +1894,8 @@ class Fields extends Structure if (ComponentbuilderHelper::checkString($optionSet)) { $field .= '>'; - $field .= PHP_EOL . $this->_t(3) . $taber . ""; + $field .= PHP_EOL . $this->_t(3) . $taber . ""; $field .= $optionSet; $field .= PHP_EOL . $this->_t(2) . $taber . ""; } @@ -1443,25 +1903,33 @@ class Fields extends Structure elseif (ComponentbuilderHelper::fieldCheck($typeName, 'list')) { $optionArray = false; - $field .= PHP_EOL . $this->_t(2) . $taber . "/>"; - $field .= PHP_EOL . $this->_t(2) . $taber . "" . PHP_EOL; + $field .= PHP_EOL . $this->_t(2) . $taber . "/>"; + $field .= PHP_EOL . $this->_t(2) . $taber . "" + . PHP_EOL; } else { $optionArray = false; - $field .= PHP_EOL . $this->_t(2) . $taber . "/>"; + $field .= PHP_EOL . $this->_t(2) . $taber . "/>"; } } elseif ($setType === 'plain') { // now add to the field set - $field .= PHP_EOL . $this->_t(2) . $taber . ""; + $field .= PHP_EOL . $this->_t(2) . $taber . ""; $field .= PHP_EOL . $this->_t(2) . $taber . " $value) { if ($property != 'option') { - $field .= PHP_EOL . $this->_t(2) . $taber . $this->_t(1) . $property . '="' . $value . '"'; + $field .= PHP_EOL . $this->_t(2) . $taber . $this->_t(1) + . $property . '="' . $value . '"'; } } $field .= PHP_EOL . $this->_t(2) . $taber . "/>"; @@ -1469,7 +1937,10 @@ class Fields extends Structure elseif ($setType === 'spacer') { // now add to the field set - $field .= PHP_EOL . $this->_t(2) . ""; + $field .= PHP_EOL . $this->_t(2) . ""; $field .= PHP_EOL . $this->_t(2) . " $value) { @@ -1486,23 +1957,33 @@ class Fields extends Structure if ($typeName === 'repeatable') { // now add to the field set - $field .= PHP_EOL . $this->_t(2) . ""; - $field .= PHP_EOL . $this->_t(2) . "_t(2) . ""; + $field .= PHP_EOL . $this->_t(2) . " $value) { if ($property != 'fields') { - $field .= PHP_EOL . $this->_t(3) . $property . '="' . $value . '"'; + $field .= PHP_EOL . $this->_t(3) . $property . '="' + . $value . '"'; } } $field .= ">"; - $field .= PHP_EOL . $this->_t(3) . ''; - $field .= PHP_EOL . $this->_t(4) . '