Moves all major structre function to container. Adds new Server replacment class for legacy calls. Refactored multiple classes. Add more advanced compiler options, with donation notice.

This commit is contained in:
2023-02-12 21:15:41 +02:00
parent 7fa8964b44
commit 339aec221e
58 changed files with 4552 additions and 1755 deletions

View File

@ -14,6 +14,7 @@ defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Form\Form;
/**
* Componentbuilder Html View class for the Compiler
@ -47,7 +48,7 @@ class ComponentbuilderViewCompiler extends HtmlView
$this->Components = $this->get('Components');
// get the needed form fields
$this->Form = $this->getDynamicForm();
$this->form = $this->getDynamicForm();
// set the compiler artwork from global settings
$this->builder_gif_size = $this->params->get('builder_gif_size', '480-272');
@ -106,119 +107,378 @@ class ComponentbuilderViewCompiler extends HtmlView
/**
* Get the dynamic build form fields needed on the page
*
* @return array|null The array of form fields
* @return Form|null The form fields
*
* @since 3.2.0
*/
public function getDynamicForm(): ?array
public function getDynamicForm(): ?Form
{
if(ComponentbuilderHelper::checkArray($this->Components))
{
// start the form
$form = array();
$form = new Form('Builder');
$form->load('<form
addrulepath="/administrator/components/com_componentbuilder/models/rules"
addfieldpath="/administrator/components/com_componentbuilder/models/fields">
<fieldset name="builder"></fieldset>
<fieldset name="advanced"></fieldset>
</form>');
// sales attributes
$attributes = array(
$attributes = [
'type' => 'radio',
'name' => 'backup',
'label' => 'COM_COMPONENTBUILDER_ADD_TO_BACKUP_FOLDER_AMP_SALES_SERVER_SMALLIF_SETSMALL',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_THE_ZIPPED_PACKAGE_OF_THE_COMPONENT_BE_MOVED_TO_THE_LOCAL_BACKUP_AND_REMOTE_SALES_SERVER_THIS_IS_ONLY_APPLICABLE_IF_THIS_COMPONENT_HAS_THOSE_VALUES_SET',
'default' => '0');
'default' => '0'];
// set the sales options
$options = array(
$options = [
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
'0' => 'COM_COMPONENTBUILDER_NO'];
// add to form
$form[] = ComponentbuilderHelper::getFieldObject($attributes, 0, $options);
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'builder');
}
// repository attributes
$attributes = array(
$attributes = [
'type' => 'radio',
'name' => 'repository',
'label' => 'COM_COMPONENTBUILDER_ADD_TO_REPOSITORY_FOLDER',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_THE_COMPONENT_BE_MOVED_TO_YOUR_LOCAL_REPOSITORY_FOLDER',
'default' => '1');
'default' => '1'];
// start the repository options
$options = array(
$options = [
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
'0' => 'COM_COMPONENTBUILDER_NO'];
// add to form
$form[] = ComponentbuilderHelper::getFieldObject($attributes, 1, $options);
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'builder');
}
// placeholders attributes
$attributes = array(
$attributes = [
'type' => 'radio',
'name' => 'add_placeholders',
'label' => 'COM_COMPONENTBUILDER_ADD_CUSTOM_CODE_PLACEHOLDERS',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_JCB_INSERT_THE_CUSTOM_CODE_PLACEHOLDERS_THIS_IS_ONLY_APPLICABLE_IF_THIS_COMPONENT_HAS_CUSTOM_CODE',
'default' => '2');
'default' => '2'];
// start the placeholders options
$options = array(
$options = [
'2' => 'COM_COMPONENTBUILDER_GLOBAL',
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
'0' => 'COM_COMPONENTBUILDER_NO'];
// add to form
$form[] = ComponentbuilderHelper::getFieldObject($attributes, 2, $options);
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'builder');
}
// debuglinenr attributes
$attributes = array(
$attributes = [
'type' => 'radio',
'name' => 'debug_line_nr',
'label' => 'COM_COMPONENTBUILDER_DEBUG_LINE_NUMBERS',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_ADD_CORRESPONDING_LINE_NUMBERS_TO_THE_DYNAMIC_COMMENTS_SO_TO_SEE_WHERE_IN_THE_COMPILER_THE_LINES_OF_CODE_WAS_BUILD_THIS_WILL_HELP_IF_YOU_NEED_TO_GET_MORE_TECHNICAL_WITH_AN_ISSUE_ON_GITHUB_OR_EVEN_FOR_YOUR_OWN_DEBUGGING',
'default' => '2');
$options = array(
'default' => '2'];
$options = [
'2' => 'COM_COMPONENTBUILDER_GLOBAL',
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
'0' => 'COM_COMPONENTBUILDER_NO'];
// add to form
$form[] = ComponentbuilderHelper::getFieldObject($attributes, 2, $options);
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'builder');
}
// minify attributes
$attributes = array(
$attributes = [
'type' => 'radio',
'name' => 'minify',
'label' => 'COM_COMPONENTBUILDER_MINIFY_JAVASCRIPT',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_THE_JAVASCRIPT_BE_MINIFIED_IN_THE_COMPONENT',
'default' => '2');
$options = array(
'default' => '2'];
$options = [
'2' => 'COM_COMPONENTBUILDER_GLOBAL',
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
'0' => 'COM_COMPONENTBUILDER_NO'];
// add to form
$form[] = ComponentbuilderHelper::getFieldObject($attributes, 2, $options);
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'builder');
}
// powers attributes
$attributes = array(
$attributes = [
'type' => 'radio',
'name' => 'powers',
'label' => 'COM_COMPONENTBUILDER_ADD_POWERS',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_SHOULD_JCB_ADD_ANY_POWERS_THAT_ARE_CONNECTED_TO_THIS_COMPONENT_THIS_MAY_BE_HELPFUL_IF_YOU_ARE_LOADING_POWERS_VIA_ANOTHER_COMPONENT_AND_WOULD_LIKE_TO_AVOID_ADDING_IT_TO_BOTH_JUST_REMEMBER_THAT_IN_THIS_CASE_YOU_NEED_TO_LOAD_THE_POWERS_VIA_A_PLUGIN',
'default' => '2');
$options = array(
'default' => '2'];
$options = [
'2' => 'COM_COMPONENTBUILDER_GLOBAL',
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO');
'0' => 'COM_COMPONENTBUILDER_NO'];
// add to form
$form[] = ComponentbuilderHelper::getFieldObject($attributes, 2, $options);
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'builder');
}
// component attributes
$attributes = array(
$attributes = [
'type' => 'list',
'name' => 'component_id',
'label' => 'COM_COMPONENTBUILDER_COMPONENTS',
'class' => 'list_class',
'description' => 'COM_COMPONENTBUILDER_SELECT_THE_COMPONENT_TO_COMPILE',
'required' => 'true');
'required' => 'true'];
// start the component options
$options = array();
$options = [];
$options[''] = 'COM_COMPONENTBUILDER__SELECT_COMPONENT_';
// load component options from array
foreach($this->Components as $component)
{
$options[(int) $component->id] = $this->escape($component->name);
}
// add to form
$form[] = ComponentbuilderHelper::getFieldObject($attributes, '', $options);
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'builder');
}
// Advanced Options
$attributes = [
'type' => 'radio',
'name' => 'show_advanced_options',
'label' => 'COM_COMPONENTBUILDER_SHOW_ADVANCED_OPTIONS',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_WOULD_YOU_LIKE_TO_SEE_THE_ADVANCED_COMPILER_OPTIONS',
'default' => '0'];
// start the advanced options switch
$options = [
'1' => 'COM_COMPONENTBUILDER_YES',
'0' => 'COM_COMPONENTBUILDER_NO'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'builder');
}
// Advanced Options note attributes
$attributes = [
'type' => 'note',
'name' => 'show_advanced_options_note',
'label' => "COM_COMPONENTBUILDER_ADVANCED_OPTIONS",
'heading' => 'h3',
'showon' => 'show_advanced_options:1'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Joomla Versions attributes
$attributes = [
'type' => 'radio',
'name' => 'joomla_version_donations',
'label' => 'COM_COMPONENTBUILDER_JOOMLA_VERSION',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_WHAT_VERSION_OF_JOOMLA_WOULD_YOU_LIKE_TO_TARGET',
'default' => '3',
'showon' => 'show_advanced_options:1'];
// start the joomla versions options
$options = [
'3' => 'COM_COMPONENTBUILDER_JOOMLA_THREE',
'4' => 'COM_COMPONENTBUILDER_JOOMLA_FOUR'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Joomla Version 3 attributes
$attributes = [
'type' => 'note',
'name' => 'joomla_version_note_three',
'description' => 'COM_COMPONENTBUILDER_YOUR_COMPONENT_WILL_BE_COMPILED_TO_WORK_IN_JOOMLA_THREE',
'class' => 'alert alert-success',
'showon' => 'show_advanced_options:1[AND]joomla_version_donations:3'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Joomla Version 4 attributes
$attributes = [
'type' => 'note',
'name' => 'joomla_version_note_four',
'description' => 'COM_COMPONENTBUILDER_JCB_IS_NOT_YET_FULLY_READY_FOR_JOOMLA_FOUR_BUT_WITH_YOUR_HELP_WE_CAN_MAKE_THE_TRANSITION_FASTER_SHOW_YOUR_SUPPORT_BY_MAKING_A_DONATION_TODAY_AND_HELP_US_BRING_JCB_TO_THE_NEXT_LEVELBR_BR_BYOUR_COMPONENT_WILL_STILL_ONLY_BE_COMPILED_FOR_JOOMLA_THREEB',
'class' => 'alert alert-info',
'showon' => 'show_advanced_options:1[AND]joomla_version_donations:4'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Indentation attributes
$attributes = [
'type' => 'radio',
'name' => 'indentation_value',
'label' => 'COM_COMPONENTBUILDER_INDENTATION_OPTIONS',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_WHICH_TYPE_OF_INDENTATION_WOULD_YOU_LIKE_TO_USE_PLEASE_NOTE_THAT_THIS_DOES_NOT_YET_IMPACT_THE_STATIC_TEMPLATES',
'default' => '1',
'showon' => 'show_advanced_options:1'];
// start the indentation options
$options = [
'1' => 'COM_COMPONENTBUILDER_TAB',
'2' => 'COM_COMPONENTBUILDER_TWO_SPACES',
'4' => 'COM_COMPONENTBUILDER_FOUR_SPACES'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Build date attributes
$attributes = [
'type' => 'radio',
'name' => 'add_build_date',
'label' => 'COM_COMPONENTBUILDER_BUILD_DATE',
'class' => 'btn-group btn-group-yesno',
'description' => 'COM_COMPONENTBUILDER_WOULD_YOU_LIKE_TO_OVERRIDE_THE_BUILD_DATE',
'default' => '1',
'showon' => 'show_advanced_options:1'];
// start the build date options
$options = [
'1' => 'COM_COMPONENTBUILDER_DEFAULT',
'2' => 'COM_COMPONENTBUILDER_MANUAL',
'3' => 'COM_COMPONENTBUILDER_COMPONENT'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes, $options);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Build date note attributes
$attributes = [
'type' => 'note',
'name' => 'add_build_date_note_two',
'description' => 'COM_COMPONENTBUILDER_ALLOWS_YOU_TO_OVERRIDE_THE_BUILD_DATE_BY_SELECTING_A_DATE_MANUALLY_FROM_THE_CALENDER',
'class' => 'alert alert-info',
'showon' => 'show_advanced_options:1[AND]add_build_date:2'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Build date note attributes
$attributes = [
'type' => 'note',
'name' => 'add_build_date_note_three',
'description' => "COM_COMPONENTBUILDER_THE_COMPONENTS_LAST_MODIFIED_DATE_WILL_BE_USED",
'class' => 'alert alert-info',
'showon' => 'show_advanced_options:1[AND]add_build_date:3'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Build date calendar attributes
$attributes = [
'type' => 'calendar',
'name' => 'build_date',
'label' => 'COM_COMPONENTBUILDER_SELECT_BUILD_DATE',
'format' => '%Y-%m-%d',
'filter' => 'user_utc',
'default' => 'now',
'size' => '22',
'showon' => 'show_advanced_options:1[AND]add_build_date:2'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Build date note attributes
$attributes = [
'type' => 'note',
'name' => 'donations_note',
'label' => "COM_COMPONENTBUILDER_DONATIONS",
'description' => $this->getSupportMessage(),
'class' => 'alert alert-success',
'heading' => 'h1',
'showon' => 'show_advanced_options:1'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// Build date note line attributes
$attributes = [
'type' => 'note',
'name' => 'donations_note_line',
'description' => '<hr />',
'showon' => 'show_advanced_options:1'];
// add to form
$xml = ComponentbuilderHelper::getFieldXML($attributes);
if ($xml instanceof SimpleXMLElement)
{
$form->setField($xml, null, true, 'advanced');
}
// return the form array
return $form;
@ -226,6 +486,18 @@ class ComponentbuilderViewCompiler extends HtmlView
return null;
}
/**
* Get the dynamic support request/gratitude message
*
* @return string The support message
*
* @since 3.2.0
*/
protected function getSupportMessage(): string
{
return JLayoutHelper::render('jcbsupportmessage', []);
}
/**