Release of v4.0.1-alpha5

Add repositories for better integration with gitea. Refactored the Data classes. Add new Data classes.
This commit is contained in:
2024-06-21 01:37:13 +02:00
parent f36922f9a1
commit 5a2e137f31
120 changed files with 8945 additions and 3699 deletions

View File

@ -67,7 +67,7 @@ class ComponentbuilderModel extends ListModel
$icons = [];
// view groups array
$viewGroups = array(
'main' => array('png.compiler', 'png.joomla_components', 'png.joomla_modules', 'png.joomla_plugins', 'png.powers', 'png.search', 'png.admin_views', 'png.custom_admin_views', 'png.site_views', 'png.template.add', 'png.templates', 'png.layouts', 'png.dynamic_get.add', 'png.dynamic_gets', 'png.custom_codes', 'png.placeholders', 'png.libraries', 'png.snippets', 'png.validation_rules', 'png.field.add', 'png.fields', 'png.fields.catid_qpo0O0oqp_com_componentbuilder_po0O0oq_field', 'png.fieldtypes', 'png.fieldtypes.catid_qpo0O0oqp_com_componentbuilder_po0O0oq_fieldtype', 'png.language_translations', 'png.languages', 'png.servers', 'png.help_documents')
'main' => array('png.compiler', 'png.joomla_components', 'png.joomla_modules', 'png.joomla_plugins', 'png.powers', 'png.search', 'png.admin_views', 'png.custom_admin_views', 'png.site_views', 'png.template.add', 'png.templates', 'png.layouts', 'png.dynamic_get.add', 'png.dynamic_gets', 'png.custom_codes', 'png.placeholders', 'png.libraries', 'png.snippets', 'png.validation_rules', 'png.field.add', 'png.fields', 'png.fields.catid_qpo0O0oqp_com_componentbuilder_po0O0oq_field', 'png.fieldtypes', 'png.fieldtypes.catid_qpo0O0oqp_com_componentbuilder_po0O0oq_fieldtype', 'png.language_translations', 'png.languages', 'png.servers', 'png.repositories', 'png.help_documents')
);
// view access array
$viewAccess = [
@ -184,6 +184,11 @@ class ComponentbuilderModel extends ListModel
'server.access' => 'server.access',
'servers.submenu' => 'server.submenu',
'servers.dashboard_list' => 'server.dashboard_list',
'repository.create' => 'repository.create',
'repositories.access' => 'repository.access',
'repository.access' => 'repository.access',
'repositories.submenu' => 'repository.submenu',
'repositories.dashboard_list' => 'repository.dashboard_list',
'help_document.create' => 'help_document.create',
'help_documents.access' => 'help_document.access',
'help_document.access' => 'help_document.access',

View File

@ -84,7 +84,6 @@ class FieldModel extends AdminModel
'store',
'medium_encryption_note',
'basic_encryption_note',
'note_whmcs_encryption',
'note_expert_field_save_mode',
'initiator_on_save_model',
'initiator_on_get_model',
@ -247,6 +246,12 @@ class FieldModel extends AdminModel
$item->metadata = $registry->toArray();
}
if (!empty($item->on_get_model_field))
{
// base64 Decode on_get_model_field.
$item->on_get_model_field = base64_decode($item->on_get_model_field);
}
if (!empty($item->on_save_model_field))
{
// base64 Decode on_save_model_field.
@ -259,10 +264,10 @@ class FieldModel extends AdminModel
$item->initiator_on_get_model = base64_decode($item->initiator_on_get_model);
}
if (!empty($item->initiator_on_save_model))
if (!empty($item->javascript_view_footer))
{
// base64 Decode initiator_on_save_model.
$item->initiator_on_save_model = base64_decode($item->initiator_on_save_model);
// base64 Decode javascript_view_footer.
$item->javascript_view_footer = base64_decode($item->javascript_view_footer);
}
if (!empty($item->css_views))
@ -277,24 +282,18 @@ class FieldModel extends AdminModel
$item->css_view = base64_decode($item->css_view);
}
if (!empty($item->on_get_model_field))
{
// base64 Decode on_get_model_field.
$item->on_get_model_field = base64_decode($item->on_get_model_field);
}
if (!empty($item->javascript_view_footer))
{
// base64 Decode javascript_view_footer.
$item->javascript_view_footer = base64_decode($item->javascript_view_footer);
}
if (!empty($item->javascript_views_footer))
{
// base64 Decode javascript_views_footer.
$item->javascript_views_footer = base64_decode($item->javascript_views_footer);
}
if (!empty($item->initiator_on_save_model))
{
// base64 Decode initiator_on_save_model.
$item->initiator_on_save_model = base64_decode($item->initiator_on_save_model);
}
if (!empty($item->xml))
{
// JSON Decode xml.
@ -1225,6 +1224,12 @@ class FieldModel extends AdminModel
$data['xml'] = (string) json_encode($data['xml']);
}
// Set the on_get_model_field string to base64 string.
if (isset($data['on_get_model_field']))
{
$data['on_get_model_field'] = base64_encode($data['on_get_model_field']);
}
// Set the on_save_model_field string to base64 string.
if (isset($data['on_save_model_field']))
{
@ -1237,10 +1242,10 @@ class FieldModel extends AdminModel
$data['initiator_on_get_model'] = base64_encode($data['initiator_on_get_model']);
}
// Set the initiator_on_save_model string to base64 string.
if (isset($data['initiator_on_save_model']))
// Set the javascript_view_footer string to base64 string.
if (isset($data['javascript_view_footer']))
{
$data['initiator_on_save_model'] = base64_encode($data['initiator_on_save_model']);
$data['javascript_view_footer'] = base64_encode($data['javascript_view_footer']);
}
// Set the css_views string to base64 string.
@ -1255,24 +1260,18 @@ class FieldModel extends AdminModel
$data['css_view'] = base64_encode($data['css_view']);
}
// Set the on_get_model_field string to base64 string.
if (isset($data['on_get_model_field']))
{
$data['on_get_model_field'] = base64_encode($data['on_get_model_field']);
}
// Set the javascript_view_footer string to base64 string.
if (isset($data['javascript_view_footer']))
{
$data['javascript_view_footer'] = base64_encode($data['javascript_view_footer']);
}
// Set the javascript_views_footer string to base64 string.
if (isset($data['javascript_views_footer']))
{
$data['javascript_views_footer'] = base64_encode($data['javascript_views_footer']);
}
// Set the initiator_on_save_model string to base64 string.
if (isset($data['initiator_on_save_model']))
{
$data['initiator_on_save_model'] = base64_encode($data['initiator_on_save_model']);
}
// Set the Params Items to data
if (isset($data['params']) && is_array($data['params']))
{

View File

@ -396,7 +396,6 @@ class FieldsModel extends ListModel
2 => 'COM_COMPONENTBUILDER_FIELD_BASE64',
3 => 'COM_COMPONENTBUILDER_FIELD_BASIC_ENCRYPTION_LOCALDBKEY',
5 => 'COM_COMPONENTBUILDER_FIELD_MEDIUM_ENCRYPTION_LOCALFILEKEY',
4 => 'COM_COMPONENTBUILDER_FIELD_WHMCSKEY_ENCRYPTION',
6 => 'COM_COMPONENTBUILDER_FIELD_EXPERT_MODE_CUSTOM'
);
// Now check if value is found in this array

View File

@ -519,7 +519,6 @@ class FieldtypeModel extends AdminModel
2 => 'COM_COMPONENTBUILDER_FIELD_BASE64',
3 => 'COM_COMPONENTBUILDER_FIELD_BASIC_ENCRYPTION_LOCALDBKEY',
5 => 'COM_COMPONENTBUILDER_FIELD_MEDIUM_ENCRYPTION_LOCALFILEKEY',
4 => 'COM_COMPONENTBUILDER_FIELD_WHMCSKEY_ENCRYPTION',
6 => 'COM_COMPONENTBUILDER_FIELD_EXPERT_MODE_CUSTOM'
);
// Now check if value is found in this array

View File

@ -77,12 +77,6 @@ class Joomla_componentModel extends AdminModel
'author',
'email',
'website',
'add_license',
'license_type',
'note_whmcs_lisencing_note',
'whmcs_key',
'whmcs_url',
'whmcs_buy_link',
'license',
'bom',
'image',
@ -97,30 +91,6 @@ class Joomla_componentModel extends AdminModel
'not_required'
)
),
'libs_helpers' => array(
'fullwidth' => array(
'creatuserhelper',
'adduikit',
'addfootable',
'add_email_helper',
'add_php_helper_both',
'php_helper_both',
'add_php_helper_admin',
'php_helper_admin',
'add_admin_event',
'php_admin_event',
'add_php_helper_site',
'php_helper_site',
'add_site_event',
'php_site_event',
'add_javascript',
'javascript',
'add_css_admin',
'css_admin',
'add_css_site',
'css_site'
)
),
'dynamic_integration' => array(
'left' => array(
'add_update_server',
@ -150,6 +120,15 @@ class Joomla_componentModel extends AdminModel
'crowdin_account_api_key'
)
),
'mysql' => array(
'fullwidth' => array(
'add_sql',
'sql',
'add_sql_uninstall',
'sql_uninstall',
'assets_table_fix'
)
),
'dash_install' => array(
'left' => array(
'dashboard_type'
@ -174,6 +153,30 @@ class Joomla_componentModel extends AdminModel
'php_method_install'
)
),
'libs_helpers' => array(
'fullwidth' => array(
'creatuserhelper',
'adduikit',
'addfootable',
'add_email_helper',
'add_php_helper_both',
'php_helper_both',
'add_php_helper_admin',
'php_helper_admin',
'add_admin_event',
'php_admin_event',
'add_php_helper_site',
'php_helper_site',
'add_site_event',
'php_site_event',
'add_javascript',
'javascript',
'add_css_admin',
'css_admin',
'add_css_site',
'css_site'
)
),
'readme' => array(
'left' => array(
'addreadme',
@ -183,15 +186,6 @@ class Joomla_componentModel extends AdminModel
'note_readme'
)
),
'mysql' => array(
'fullwidth' => array(
'add_sql',
'sql',
'add_sql_uninstall',
'sql_uninstall',
'assets_table_fix'
)
),
'dynamic_build' => array(
'fullwidth' => array(
'note_buildcomp_dynamic_mysql',
@ -403,58 +397,22 @@ class Joomla_componentModel extends AdminModel
$item->metadata = $registry->toArray();
}
if (!empty($item->php_site_event))
if (!empty($item->sql_uninstall))
{
// base64 Decode php_site_event.
$item->php_site_event = base64_decode($item->php_site_event);
// base64 Decode sql_uninstall.
$item->sql_uninstall = base64_decode($item->sql_uninstall);
}
if (!empty($item->php_admin_event))
if (!empty($item->php_postflight_update))
{
// base64 Decode php_admin_event.
$item->php_admin_event = base64_decode($item->php_admin_event);
// base64 Decode php_postflight_update.
$item->php_postflight_update = base64_decode($item->php_postflight_update);
}
if (!empty($item->php_preflight_install))
if (!empty($item->css_site))
{
// base64 Decode php_preflight_install.
$item->php_preflight_install = base64_decode($item->php_preflight_install);
}
if (!empty($item->php_method_uninstall))
{
// base64 Decode php_method_uninstall.
$item->php_method_uninstall = base64_decode($item->php_method_uninstall);
}
if (!empty($item->css_admin))
{
// base64 Decode css_admin.
$item->css_admin = base64_decode($item->css_admin);
}
if (!empty($item->php_postflight_install))
{
// base64 Decode php_postflight_install.
$item->php_postflight_install = base64_decode($item->php_postflight_install);
}
if (!empty($item->sql))
{
// base64 Decode sql.
$item->sql = base64_decode($item->sql);
}
if (!empty($item->buildcompsql))
{
// base64 Decode buildcompsql.
$item->buildcompsql = base64_decode($item->buildcompsql);
}
if (!empty($item->php_helper_admin))
{
// base64 Decode php_helper_admin.
$item->php_helper_admin = base64_decode($item->php_helper_admin);
// base64 Decode css_site.
$item->css_site = base64_decode($item->css_site);
}
if (!empty($item->php_helper_site))
@ -469,10 +427,28 @@ class Joomla_componentModel extends AdminModel
$item->javascript = base64_decode($item->javascript);
}
if (!empty($item->css_site))
if (!empty($item->php_method_install))
{
// base64 Decode css_site.
$item->css_site = base64_decode($item->css_site);
// base64 Decode php_method_install.
$item->php_method_install = base64_decode($item->php_method_install);
}
if (!empty($item->php_admin_event))
{
// base64 Decode php_admin_event.
$item->php_admin_event = base64_decode($item->php_admin_event);
}
if (!empty($item->php_site_event))
{
// base64 Decode php_site_event.
$item->php_site_event = base64_decode($item->php_site_event);
}
if (!empty($item->css_admin))
{
// base64 Decode css_admin.
$item->css_admin = base64_decode($item->css_admin);
}
if (!empty($item->php_preflight_update))
@ -481,22 +457,34 @@ class Joomla_componentModel extends AdminModel
$item->php_preflight_update = base64_decode($item->php_preflight_update);
}
if (!empty($item->php_postflight_update))
if (!empty($item->php_preflight_install))
{
// base64 Decode php_postflight_update.
$item->php_postflight_update = base64_decode($item->php_postflight_update);
// base64 Decode php_preflight_install.
$item->php_preflight_install = base64_decode($item->php_preflight_install);
}
if (!empty($item->php_method_install))
if (!empty($item->php_postflight_install))
{
// base64 Decode php_method_install.
$item->php_method_install = base64_decode($item->php_method_install);
// base64 Decode php_postflight_install.
$item->php_postflight_install = base64_decode($item->php_postflight_install);
}
if (!empty($item->sql_uninstall))
if (!empty($item->php_method_uninstall))
{
// base64 Decode sql_uninstall.
$item->sql_uninstall = base64_decode($item->sql_uninstall);
// base64 Decode php_method_uninstall.
$item->php_method_uninstall = base64_decode($item->php_method_uninstall);
}
if (!empty($item->sql))
{
// base64 Decode sql.
$item->sql = base64_decode($item->sql);
}
if (!empty($item->buildcompsql))
{
// base64 Decode buildcompsql.
$item->buildcompsql = base64_decode($item->buildcompsql);
}
if (!empty($item->readme))
@ -511,6 +499,12 @@ class Joomla_componentModel extends AdminModel
$item->php_helper_both = base64_decode($item->php_helper_both);
}
if (!empty($item->php_helper_admin))
{
// base64 Decode php_helper_admin.
$item->php_helper_admin = base64_decode($item->php_helper_admin);
}
// Get the basic encryption.
$basickey = ComponentbuilderHelper::getCryptKey('basic');
// Get the encryption object.
@ -522,12 +516,6 @@ class Joomla_componentModel extends AdminModel
$item->crowdin_username = rtrim($basic->decryptString($item->crowdin_username), "\0");
}
if (!empty($item->whmcs_key) && $basickey && !is_numeric($item->whmcs_key) && $item->whmcs_key === base64_encode(base64_decode($item->whmcs_key, true)))
{
// basic decrypt data whmcs_key.
$item->whmcs_key = rtrim($basic->decryptString($item->whmcs_key), "\0");
}
if (!empty($item->export_key) && $basickey && !is_numeric($item->export_key) && $item->export_key === base64_encode(base64_decode($item->export_key, true)))
{
// basic decrypt data export_key.
@ -1500,58 +1488,22 @@ class Joomla_componentModel extends AdminModel
$data['addcontributors'] = '';
}
// Set the php_site_event string to base64 string.
if (isset($data['php_site_event']))
// Set the sql_uninstall string to base64 string.
if (isset($data['sql_uninstall']))
{
$data['php_site_event'] = base64_encode($data['php_site_event']);
$data['sql_uninstall'] = base64_encode($data['sql_uninstall']);
}
// Set the php_admin_event string to base64 string.
if (isset($data['php_admin_event']))
// Set the php_postflight_update string to base64 string.
if (isset($data['php_postflight_update']))
{
$data['php_admin_event'] = base64_encode($data['php_admin_event']);
$data['php_postflight_update'] = base64_encode($data['php_postflight_update']);
}
// Set the php_preflight_install string to base64 string.
if (isset($data['php_preflight_install']))
// Set the css_site string to base64 string.
if (isset($data['css_site']))
{
$data['php_preflight_install'] = base64_encode($data['php_preflight_install']);
}
// Set the php_method_uninstall string to base64 string.
if (isset($data['php_method_uninstall']))
{
$data['php_method_uninstall'] = base64_encode($data['php_method_uninstall']);
}
// Set the css_admin string to base64 string.
if (isset($data['css_admin']))
{
$data['css_admin'] = base64_encode($data['css_admin']);
}
// Set the php_postflight_install string to base64 string.
if (isset($data['php_postflight_install']))
{
$data['php_postflight_install'] = base64_encode($data['php_postflight_install']);
}
// Set the sql string to base64 string.
if (isset($data['sql']))
{
$data['sql'] = base64_encode($data['sql']);
}
// Set the buildcompsql string to base64 string.
if (isset($data['buildcompsql']))
{
$data['buildcompsql'] = base64_encode($data['buildcompsql']);
}
// Set the php_helper_admin string to base64 string.
if (isset($data['php_helper_admin']))
{
$data['php_helper_admin'] = base64_encode($data['php_helper_admin']);
$data['css_site'] = base64_encode($data['css_site']);
}
// Set the php_helper_site string to base64 string.
@ -1566,10 +1518,28 @@ class Joomla_componentModel extends AdminModel
$data['javascript'] = base64_encode($data['javascript']);
}
// Set the css_site string to base64 string.
if (isset($data['css_site']))
// Set the php_method_install string to base64 string.
if (isset($data['php_method_install']))
{
$data['css_site'] = base64_encode($data['css_site']);
$data['php_method_install'] = base64_encode($data['php_method_install']);
}
// Set the php_admin_event string to base64 string.
if (isset($data['php_admin_event']))
{
$data['php_admin_event'] = base64_encode($data['php_admin_event']);
}
// Set the php_site_event string to base64 string.
if (isset($data['php_site_event']))
{
$data['php_site_event'] = base64_encode($data['php_site_event']);
}
// Set the css_admin string to base64 string.
if (isset($data['css_admin']))
{
$data['css_admin'] = base64_encode($data['css_admin']);
}
// Set the php_preflight_update string to base64 string.
@ -1578,22 +1548,34 @@ class Joomla_componentModel extends AdminModel
$data['php_preflight_update'] = base64_encode($data['php_preflight_update']);
}
// Set the php_postflight_update string to base64 string.
if (isset($data['php_postflight_update']))
// Set the php_preflight_install string to base64 string.
if (isset($data['php_preflight_install']))
{
$data['php_postflight_update'] = base64_encode($data['php_postflight_update']);
$data['php_preflight_install'] = base64_encode($data['php_preflight_install']);
}
// Set the php_method_install string to base64 string.
if (isset($data['php_method_install']))
// Set the php_postflight_install string to base64 string.
if (isset($data['php_postflight_install']))
{
$data['php_method_install'] = base64_encode($data['php_method_install']);
$data['php_postflight_install'] = base64_encode($data['php_postflight_install']);
}
// Set the sql_uninstall string to base64 string.
if (isset($data['sql_uninstall']))
// Set the php_method_uninstall string to base64 string.
if (isset($data['php_method_uninstall']))
{
$data['sql_uninstall'] = base64_encode($data['sql_uninstall']);
$data['php_method_uninstall'] = base64_encode($data['php_method_uninstall']);
}
// Set the sql string to base64 string.
if (isset($data['sql']))
{
$data['sql'] = base64_encode($data['sql']);
}
// Set the buildcompsql string to base64 string.
if (isset($data['buildcompsql']))
{
$data['buildcompsql'] = base64_encode($data['buildcompsql']);
}
// Set the readme string to base64 string.
@ -1608,6 +1590,12 @@ class Joomla_componentModel extends AdminModel
$data['php_helper_both'] = base64_encode($data['php_helper_both']);
}
// Set the php_helper_admin string to base64 string.
if (isset($data['php_helper_admin']))
{
$data['php_helper_admin'] = base64_encode($data['php_helper_admin']);
}
// Get the basic encryption key.
$basickey = ComponentbuilderHelper::getCryptKey('basic');
// Get the encryption object
@ -1619,12 +1607,6 @@ class Joomla_componentModel extends AdminModel
$data['crowdin_username'] = $basic->encryptString($data['crowdin_username']);
}
// Encrypt data whmcs_key.
if (isset($data['whmcs_key']) && $basickey)
{
$data['whmcs_key'] = $basic->encryptString($data['whmcs_key']);
}
// Encrypt data export_key.
if (isset($data['export_key']) && $basickey)
{

View File

@ -2745,48 +2745,41 @@ class Joomla_componentsModel extends ListModel
continue;
}
// decode php_site_event
$item->php_site_event = base64_decode($item->php_site_event);
// decode sql_uninstall
$item->sql_uninstall = base64_decode($item->sql_uninstall);
// decode php_postflight_update
$item->php_postflight_update = base64_decode($item->php_postflight_update);
// decode css_site
$item->css_site = base64_decode($item->css_site);
// decode php_helper_site
$item->php_helper_site = base64_decode($item->php_helper_site);
// decode javascript
$item->javascript = base64_decode($item->javascript);
// decode php_method_install
$item->php_method_install = base64_decode($item->php_method_install);
// decode php_admin_event
$item->php_admin_event = base64_decode($item->php_admin_event);
// decode php_site_event
$item->php_site_event = base64_decode($item->php_site_event);
// decode css_admin
$item->css_admin = base64_decode($item->css_admin);
// decode php_preflight_update
$item->php_preflight_update = base64_decode($item->php_preflight_update);
// decode php_preflight_install
$item->php_preflight_install = base64_decode($item->php_preflight_install);
// decode php_postflight_install
$item->php_postflight_install = base64_decode($item->php_postflight_install);
// decode php_method_uninstall
$item->php_method_uninstall = base64_decode($item->php_method_uninstall);
// decode sql
$item->sql = base64_decode($item->sql);
if ($basickey && !is_numeric($item->crowdin_username) && $item->crowdin_username === base64_encode(base64_decode($item->crowdin_username, true)))
{
// decrypt crowdin_username
$item->crowdin_username = $basic->decryptString($item->crowdin_username);
}
// decode php_preflight_install
$item->php_preflight_install = base64_decode($item->php_preflight_install);
// decode php_method_uninstall
$item->php_method_uninstall = base64_decode($item->php_method_uninstall);
// decode css_admin
$item->css_admin = base64_decode($item->css_admin);
// decode php_postflight_install
$item->php_postflight_install = base64_decode($item->php_postflight_install);
// decode sql
$item->sql = base64_decode($item->sql);
// decode buildcompsql
$item->buildcompsql = base64_decode($item->buildcompsql);
// decode php_helper_admin
$item->php_helper_admin = base64_decode($item->php_helper_admin);
// decode php_helper_site
$item->php_helper_site = base64_decode($item->php_helper_site);
if ($basickey && !is_numeric($item->whmcs_key) && $item->whmcs_key === base64_encode(base64_decode($item->whmcs_key, true)))
{
// decrypt whmcs_key
$item->whmcs_key = $basic->decryptString($item->whmcs_key);
}
// decode javascript
$item->javascript = base64_decode($item->javascript);
// decode css_site
$item->css_site = base64_decode($item->css_site);
// decode php_preflight_update
$item->php_preflight_update = base64_decode($item->php_preflight_update);
// decode php_postflight_update
$item->php_postflight_update = base64_decode($item->php_postflight_update);
// decode php_method_install
$item->php_method_install = base64_decode($item->php_method_install);
// decode sql_uninstall
$item->sql_uninstall = base64_decode($item->sql_uninstall);
if ($basickey && !is_numeric($item->export_key) && $item->export_key === base64_encode(base64_decode($item->export_key, true)))
{
// decrypt export_key
@ -2799,13 +2792,15 @@ class Joomla_componentsModel extends ListModel
// decrypt crowdin_project_api_key
$item->crowdin_project_api_key = $basic->decryptString($item->crowdin_project_api_key);
}
// decode php_helper_both
$item->php_helper_both = base64_decode($item->php_helper_both);
if ($basickey && !is_numeric($item->crowdin_account_api_key) && $item->crowdin_account_api_key === base64_encode(base64_decode($item->crowdin_account_api_key, true)))
{
// decrypt crowdin_account_api_key
$item->crowdin_account_api_key = $basic->decryptString($item->crowdin_account_api_key);
}
// decode php_helper_both
$item->php_helper_both = base64_decode($item->php_helper_both);
// decode php_helper_admin
$item->php_helper_admin = base64_decode($item->php_helper_admin);
// unset the values we don't want exported.
unset($item->asset_id);
unset($item->checked_out);

View File

@ -23,7 +23,6 @@ use Joomla\Utilities\ArrayHelper;
use Joomla\Input\Input;
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
use Joomla\CMS\Helper\TagsHelper;
use VDM\Joomla\Utilities\Component\Helper as JCBHelper;
use VDM\Joomla\Componentbuilder\Utilities\FilterHelper as JCBFilterHelper;
use VDM\Joomla\Utilities\FormHelper as JCBFormHelper;
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
@ -117,7 +116,7 @@ class PowersModel extends ListModel
// load form from the parent class
$form = parent::getFilterForm($data, $loadData);
// Create the "admin_view" filter
// Create the "namegroup" filter
$attributes = array(
'name' => 'namegroup',
'type' => 'list',
@ -126,7 +125,7 @@ class PowersModel extends ListModel
$options = array(
'' => '- ' . Text::_('COM_COMPONENTBUILDER_NO_NAMESPACE_FOUND') . ' -'
);
// check if we have namespace (and limit to an extension if it is set)
// check if we have namespace
if (($namespaces = JCBFilterHelper::namespaces()) !== null)
{
$options = array(
@ -144,54 +143,33 @@ class PowersModel extends ListModel
);
array_push($this->filter_fields, 'namegroup');
// get the component params
$params = JCBHelper::getParams();
$activate = $params->get('super_powers_repositories', 0);
if ($activate == 1)
// Create the "approved_paths" filter
$attributes = array(
'name' => 'approved_paths',
'type' => 'list',
'onchange' => 'this.form.submit();',
);
$options = array(
'' => '- ' . Text::_('COM_COMPONENTBUILDER_NO_PATHS_FOUND') . ' -'
);
// check if we have approved_paths = 1
if (($approvedpaths = JCBFilterHelper::repositories(1)) !== null)
{
$subform = $params->get('approved_paths', null);
// create approved paths filter
$attributes = array(
'name' => 'approved_paths',
'type' => 'list',
'onchange' => 'this.form.submit();',
);
$options = array(
'' => '- ' . Text::_('COM_COMPONENTBUILDER_NO_PATHS_FOUND') . ' -'
'' => '- ' . Text::_('COM_COMPONENTBUILDER_SELECT_APPROVED_PATH') . ' -'
);
// add the paths found in global settings
if (is_object($subform))
{
$core = $params->get('super_powers_core', 'joomla/super-powers');
$options = array(
'' => '- ' . Text::_('COM_COMPONENTBUILDER_SELECT_APPROVED_PATH') . ' -',
$core => $core
);
foreach ($subform as $value)
{
if (isset($value->owner) && strlen($value->owner) > 1 &&
isset($value->repo) && strlen($value->repo) > 1)
{
$value = trim($value->owner) . '/' . trim($value->repo);
$options[$value] = $value;
}
}
}
$form->setField(JCBFormHelper::xml($attributes, $options), 'filter');
$form->setValue(
'approved_paths',
'filter',
$this->state->get("filter.approved_paths")
);
array_push($this->filter_fields, 'approved_paths');
// make sure we do not lose the key values in normal merge
$options = $options + $approvedpaths;
}
$form->setField(JCBFormHelper::xml($attributes, $options),'filter');
$form->setValue(
'approved_paths',
'filter',
$this->state->get("filter.approved_paths")
);
array_push($this->filter_fields, 'approved_paths');
return $form;
}

View File

@ -0,0 +1,559 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Component\Componentbuilder\Administrator\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\User\User;
use Joomla\Utilities\ArrayHelper;
use Joomla\Input\Input;
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
use Joomla\CMS\Helper\TagsHelper;
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\StringHelper;
// No direct access to this file
\defined('_JEXEC') or die;
/**
* Repositories List Model
*
* @since 1.6
*/
class RepositoriesModel extends ListModel
{
/**
* The application object.
*
* @var CMSApplicationInterface The application instance.
* @since 3.2.0
*/
protected CMSApplicationInterface $app;
/**
* The styles array.
*
* @var array
* @since 4.3
*/
protected array $styles = [
'administrator/components/com_componentbuilder/assets/css/admin.css',
'administrator/components/com_componentbuilder/assets/css/repositories.css'
];
/**
* The scripts array.
*
* @var array
* @since 4.3
*/
protected array $scripts = [
'administrator/components/com_componentbuilder/assets/js/admin.js'
];
/**
* Constructor
*
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
* @param ?MVCFactoryInterface $factory The factory.
*
* @since 1.6
* @throws \Exception
*/
public function __construct($config = [], MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'a.id','id',
'a.published','published',
'a.access','access',
'a.ordering','ordering',
'a.created_by','created_by',
'a.modified_by','modified_by',
'a.organisation','organisation',
'a.repository','repository',
'a.target','target',
'a.base','base',
'a.type','type'
);
}
parent::__construct($config, $factory);
$this->app ??= Factory::getApplication();
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
* @since 1.7.0
*/
protected function populateState($ordering = null, $direction = null)
{
$app = $this->app;
// Adjust the context to support modal layouts.
if ($layout = $app->input->get('layout'))
{
$this->context .= '.' . $layout;
}
// Check if the form was submitted
$formSubmited = $app->input->post->get('form_submited');
$access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', 0, 'int');
if ($formSubmited)
{
$access = $app->input->post->get('access');
$this->setState('filter.access', $access);
}
$published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '');
$this->setState('filter.published', $published);
$created_by = $this->getUserStateFromRequest($this->context . '.filter.created_by', 'filter_created_by', '');
$this->setState('filter.created_by', $created_by);
$created = $this->getUserStateFromRequest($this->context . '.filter.created', 'filter_created');
$this->setState('filter.created', $created);
$sorting = $this->getUserStateFromRequest($this->context . '.filter.sorting', 'filter_sorting', 0, 'int');
$this->setState('filter.sorting', $sorting);
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$organisation = $this->getUserStateFromRequest($this->context . '.filter.organisation', 'filter_organisation');
if ($formSubmited)
{
$organisation = $app->input->post->get('organisation');
$this->setState('filter.organisation', $organisation);
}
$repository = $this->getUserStateFromRequest($this->context . '.filter.repository', 'filter_repository');
if ($formSubmited)
{
$repository = $app->input->post->get('repository');
$this->setState('filter.repository', $repository);
}
$target = $this->getUserStateFromRequest($this->context . '.filter.target', 'filter_target');
if ($formSubmited)
{
$target = $app->input->post->get('target');
$this->setState('filter.target', $target);
}
$base = $this->getUserStateFromRequest($this->context . '.filter.base', 'filter_base');
if ($formSubmited)
{
$base = $app->input->post->get('base');
$this->setState('filter.base', $base);
}
$type = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type');
if ($formSubmited)
{
$type = $app->input->post->get('type');
$this->setState('filter.type', $type);
}
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Method to get an array of data items.
*
* @return mixed An array of data items on success, false on failure.
* @since 1.6
*/
public function getItems()
{
// Check in items
$this->checkInNow();
// load parent items
$items = parent::getItems();
// Set values to display correctly.
if (UtilitiesArrayHelper::check($items))
{
// Get the user object if not set.
if (!isset($user) || !ObjectHelper::check($user))
{
$user = $this->getCurrentUser();
}
foreach ($items as $nr => &$item)
{
// Remove items the user can't access.
$access = ($user->authorise('repository.access', 'com_componentbuilder.repository.' . (int) $item->id) && $user->authorise('repository.access', 'com_componentbuilder'));
if (!$access)
{
unset($items[$nr]);
continue;
}
}
}
// set selection value to a translatable value
if (UtilitiesArrayHelper::check($items))
{
foreach ($items as $nr => &$item)
{
// convert target
$item->target = $this->selectionTranslation($item->target, 'target');
// convert type
$item->type = $this->selectionTranslation($item->type, 'type');
}
}
// return items
return $items;
}
/**
* Method to convert selection values to translatable string.
*
* @return string The translatable string.
*/
public function selectionTranslation($value,$name)
{
// Array of target language strings
if ($name === 'target')
{
$targetArray = array(
0 => 'COM_COMPONENTBUILDER_REPOSITORY_SELECT_AN_OPTION',
1 => 'COM_COMPONENTBUILDER_REPOSITORY_SUPER_POWER',
2 => 'COM_COMPONENTBUILDER_REPOSITORY_JOOMLA_POWER'
);
// Now check if value is found in this array
if (isset($targetArray[$value]) && StringHelper::check($targetArray[$value]))
{
return $targetArray[$value];
}
}
// Array of type language strings
if ($name === 'type')
{
$typeArray = array(
0 => 'COM_COMPONENTBUILDER_REPOSITORY_SELECT_AN_OPTION',
1 => 'COM_COMPONENTBUILDER_REPOSITORY_GITEA'
);
// Now check if value is found in this array
if (isset($typeArray[$value]) && StringHelper::check($typeArray[$value]))
{
return $typeArray[$value];
}
}
return $value;
}
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
* @since 1.6
*/
protected function getListQuery()
{
// Get the user object.
$user = $this->getCurrentUser();
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
// Select some fields
$query->select('a.*');
// From the componentbuilder_item table
$query->from($db->quoteName('#__componentbuilder_repository', 'a'));
// Filter by published state
$published = $this->getState('filter.published');
if (is_numeric($published))
{
$query->where('a.published = ' . (int) $published);
}
elseif ($published === '')
{
$query->where('(a.published = 0 OR a.published = 1)');
}
// Join over the asset groups.
$query->select('ag.title AS access_level');
$query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
// Filter by access level.
$_access = $this->getState('filter.access');
if ($_access && is_numeric($_access))
{
$query->where('a.access = ' . (int) $_access);
}
elseif (UtilitiesArrayHelper::check($_access))
{
// Secure the array for the query
$_access = ArrayHelper::toInteger($_access);
// Filter by the Access Array.
$query->where('a.access IN (' . implode(',', $_access) . ')');
}
// Implement View Level Access
if (!$user->authorise('core.options', 'com_componentbuilder'))
{
$groups = implode(',', $user->getAuthorisedViewLevels());
$query->where('a.access IN (' . $groups . ')');
}
// Filter by search.
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = ' . (int) substr($search, 3));
}
else
{
$search = $db->quote('%' . $db->escape($search) . '%');
$query->where('(a.organisation LIKE '.$search.' OR a.repository LIKE '.$search.' OR a.target LIKE '.$search.' OR a.type LIKE '.$search.' OR a.base LIKE '.$search.' OR a.guid LIKE '.$search.' OR a.username LIKE '.$search.')');
}
}
// Filter by Organisation.
$_organisation = $this->getState('filter.organisation');
if (is_numeric($_organisation))
{
if (is_float($_organisation))
{
$query->where('a.organisation = ' . (float) $_organisation);
}
else
{
$query->where('a.organisation = ' . (int) $_organisation);
}
}
elseif (StringHelper::check($_organisation))
{
$query->where('a.organisation = ' . $db->quote($db->escape($_organisation)));
}
// Filter by Repository.
$_repository = $this->getState('filter.repository');
if (is_numeric($_repository))
{
if (is_float($_repository))
{
$query->where('a.repository = ' . (float) $_repository);
}
else
{
$query->where('a.repository = ' . (int) $_repository);
}
}
elseif (StringHelper::check($_repository))
{
$query->where('a.repository = ' . $db->quote($db->escape($_repository)));
}
// Filter by Target.
$_target = $this->getState('filter.target');
if (is_numeric($_target))
{
if (is_float($_target))
{
$query->where('a.target = ' . (float) $_target);
}
else
{
$query->where('a.target = ' . (int) $_target);
}
}
elseif (StringHelper::check($_target))
{
$query->where('a.target = ' . $db->quote($db->escape($_target)));
}
// Filter by Base.
$_base = $this->getState('filter.base');
if (is_numeric($_base))
{
if (is_float($_base))
{
$query->where('a.base = ' . (float) $_base);
}
else
{
$query->where('a.base = ' . (int) $_base);
}
}
elseif (StringHelper::check($_base))
{
$query->where('a.base = ' . $db->quote($db->escape($_base)));
}
// Add the list ordering clause.
$orderCol = $this->getState('list.ordering', 'a.id');
$orderDirn = $this->getState('list.direction', 'desc');
if ($orderCol != '')
{
// Check that the order direction is valid encase we have a field called direction as part of filers.
$orderDirn = (is_string($orderDirn) && in_array(strtolower($orderDirn), ['asc', 'desc'])) ? $orderDirn : 'desc';
$query->order($db->escape($orderCol . ' ' . $orderDirn));
}
return $query;
}
/**
* Method to get a store id based on model configuration state.
*
* @return string A store id.
* @since 1.6
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.id');
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.published');
// Check if the value is an array
$_access = $this->getState('filter.access');
if (UtilitiesArrayHelper::check($_access))
{
$id .= ':' . implode(':', $_access);
}
// Check if this is only an number or string
elseif (is_numeric($_access)
|| StringHelper::check($_access))
{
$id .= ':' . $_access;
}
$id .= ':' . $this->getState('filter.ordering');
$id .= ':' . $this->getState('filter.created_by');
$id .= ':' . $this->getState('filter.modified_by');
$id .= ':' . $this->getState('filter.organisation');
$id .= ':' . $this->getState('filter.repository');
$id .= ':' . $this->getState('filter.target');
$id .= ':' . $this->getState('filter.base');
$id .= ':' . $this->getState('filter.type');
return parent::getStoreId($id);
}
/**
* Method to get the styles that have to be included on the view
*
* @return array styles files
* @since 4.3
*/
public function getStyles(): array
{
return $this->styles;
}
/**
* Method to set the styles that have to be included on the view
*
* @return void
* @since 4.3
*/
public function setStyles(string $path): void
{
$this->styles[] = $path;
}
/**
* Method to get the script that have to be included on the view
*
* @return array script files
* @since 4.3
*/
public function getScripts(): array
{
return $this->scripts;
}
/**
* Method to set the script that have to be included on the view
*
* @return void
* @since 4.3
*/
public function setScript(string $path): void
{
$this->scripts[] = $path;
}
/**
* Build an SQL query to checkin all items left checked out longer then a set time.
*
* @return bool
* @since 3.2.0
*/
protected function checkInNow(): bool
{
// Get set check in time
$time = ComponentHelper::getParams('com_componentbuilder')->get('check_in');
if ($time)
{
// Get a db connection.
$db = $this->getDatabase();
// Reset query.
$query = $db->getQuery(true);
$query->select('*');
$query->from($db->quoteName('#__componentbuilder_repository'));
// Only select items that are checked out.
$query->where($db->quoteName('checked_out') . '!=0');
$db->setQuery($query, 0, 1);
$db->execute();
if ($db->getNumRows())
{
// Get Yesterdays date.
$date = Factory::getDate()->modify($time)->toSql();
// Reset query.
$query = $db->getQuery(true);
// Fields to update.
$fields = array(
$db->quoteName('checked_out_time') . '=\'0000-00-00 00:00:00\'',
$db->quoteName('checked_out') . '=0'
);
// Conditions for which records should be updated.
$conditions = array(
$db->quoteName('checked_out') . '!=0',
$db->quoteName('checked_out_time') . '<\''.$date.'\''
);
// Check table.
$query->update($db->quoteName('#__componentbuilder_repository'))->set($fields)->where($conditions);
$db->setQuery($query);
return $db->execute();
}
}
return false;
}
}

View File

@ -0,0 +1,968 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Component\Componentbuilder\Administrator\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Table\Table;
use Joomla\CMS\UCM\UCMType;
use Joomla\CMS\Versioning\VersionableModelTrait;
use Joomla\CMS\User\User;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;
use Joomla\Input\Input;
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
use Joomla\CMS\Helper\TagsHelper;
use VDM\Joomla\Utilities\GuidHelper;
use VDM\Joomla\Utilities\StringHelper as UtilitiesStringHelper;
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
use VDM\Joomla\Utilities\GetHelper;
// No direct access to this file
\defined('_JEXEC') or die;
/**
* Componentbuilder Repository Admin Model
*
* @since 1.6
*/
class RepositoryModel extends AdminModel
{
use VersionableModelTrait;
/**
* The tab layout fields array.
*
* @var array
* @since 3.0.0
*/
protected $tabLayoutFields = array(
'details' => array(
'left' => array(
'type',
'base',
'username',
'token'
),
'right' => array(
'organisation',
'repository',
'read_branch',
'write_branch'
),
'above' => array(
'system_name',
'target',
'access_repo'
)
)
);
/**
* The styles array.
*
* @var array
* @since 4.3
*/
protected array $styles = [
'administrator/components/com_componentbuilder/assets/css/admin.css',
'administrator/components/com_componentbuilder/assets/css/repository.css'
];
/**
* The scripts array.
*
* @var array
* @since 4.3
*/
protected array $scripts = [
'administrator/components/com_componentbuilder/assets/js/admin.js',
'media/com_componentbuilder/js/repository.js'
];
/**
* @var string The prefix to use with controller messages.
* @since 1.6
*/
protected $text_prefix = 'COM_COMPONENTBUILDER';
/**
* The type alias for this content type.
*
* @var string
* @since 3.2
*/
public $typeAlias = 'com_componentbuilder.repository';
/**
* Returns a Table object, always creating it
*
* @param type $type The table type to instantiate
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return Table A database object
* @since 3.0
* @throws \Exception
*/
public function getTable($type = 'repository', $prefix = 'Administrator', $config = [])
{
// get instance of the table
return parent::getTable($type, $prefix, $config);
}
/**
* Method to get a single record.
*
* @param integer $pk The id of the primary key.
*
* @return mixed Object on success, false on failure.
* @since 1.6
*/
public function getItem($pk = null)
{
if ($item = parent::getItem($pk))
{
if (!empty($item->params) && !is_array($item->params))
{
// Convert the params field to an array.
$registry = new Registry;
$registry->loadString($item->params);
$item->params = $registry->toArray();
}
if (!empty($item->metadata))
{
// Convert the metadata field to an array.
$registry = new Registry;
$registry->loadString($item->metadata);
$item->metadata = $registry->toArray();
}
}
return $item;
}
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @param array $options Optional array of options for the form creation.
*
* @return Form|boolean A Form object on success, false on failure
* @since 1.6
*/
public function getForm($data = [], $loadData = true, $options = ['control' => 'jform'])
{
// set load data option
$options['load_data'] = $loadData;
// check if xpath was set in options
$xpath = false;
if (isset($options['xpath']))
{
$xpath = $options['xpath'];
unset($options['xpath']);
}
// check if clear form was set in options
$clear = false;
if (isset($options['clear']))
{
$clear = $options['clear'];
unset($options['clear']);
}
// Get the form.
$form = $this->loadForm('com_componentbuilder.repository', 'repository', $options, $clear, $xpath);
if (empty($form))
{
return false;
}
$jinput = Factory::getApplication()->input;
// The front end calls this model and uses a_id to avoid id clashes so we need to check for that first.
if ($jinput->get('a_id'))
{
$id = $jinput->get('a_id', 0, 'INT');
}
// The back end uses id so we use that the rest of the time and set it to 0 by default.
else
{
$id = $jinput->get('id', 0, 'INT');
}
$user = Factory::getApplication()->getIdentity();
// Check for existing item.
// Modify the form based on Edit State access controls.
if ($id != 0 && (!$user->authorise('repository.edit.state', 'com_componentbuilder.repository.' . (int) $id))
|| ($id == 0 && !$user->authorise('repository.edit.state', 'com_componentbuilder')))
{
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('published', 'disabled', 'true');
// Disable fields while saving.
$form->setFieldAttribute('ordering', 'filter', 'unset');
$form->setFieldAttribute('published', 'filter', 'unset');
}
// If this is a new item insure the greated by is set.
if (0 == $id)
{
// Set the created_by to this user
$form->setValue('created_by', null, $user->id);
}
// Modify the form based on Edit Creaded By access controls.
if ($id != 0 && (!$user->authorise('repository.edit.created_by', 'com_componentbuilder.repository.' . (int) $id))
|| ($id == 0 && !$user->authorise('repository.edit.created_by', 'com_componentbuilder')))
{
// Disable fields for display.
$form->setFieldAttribute('created_by', 'disabled', 'true');
// Disable fields for display.
$form->setFieldAttribute('created_by', 'readonly', 'true');
// Disable fields while saving.
$form->setFieldAttribute('created_by', 'filter', 'unset');
}
// Modify the form based on Edit Creaded Date access controls.
if ($id != 0 && (!$user->authorise('repository.edit.created', 'com_componentbuilder.repository.' . (int) $id))
|| ($id == 0 && !$user->authorise('repository.edit.created', 'com_componentbuilder')))
{
// Disable fields for display.
$form->setFieldAttribute('created', 'disabled', 'true');
// Disable fields while saving.
$form->setFieldAttribute('created', 'filter', 'unset');
}
// Only load these values if no id is found
if (0 == $id)
{
// Set redirected view name
$redirectedView = $jinput->get('ref', null, 'STRING');
// Set field name (or fall back to view name)
$redirectedField = $jinput->get('field', $redirectedView, 'STRING');
// Set redirected view id
$redirectedId = $jinput->get('refid', 0, 'INT');
// Set field id (or fall back to redirected view id)
$redirectedValue = $jinput->get('field_id', $redirectedId, 'INT');
if (0 != $redirectedValue && $redirectedField)
{
// Now set the local-redirected field default value
$form->setValue($redirectedField, null, $redirectedValue);
}
}
// Only load the GUID if new item (or empty)
if (0 == $id || !($val = $form->getValue('guid')))
{
$form->setValue('guid', null, GuidHelper::get());
}
return $form;
}
/**
* Method to get the styles that have to be included on the view
*
* @return array styles files
* @since 4.3
*/
public function getStyles(): array
{
return $this->styles;
}
/**
* Method to set the styles that have to be included on the view
*
* @return void
* @since 4.3
*/
public function setStyles(string $path): void
{
$this->styles[] = $path;
}
/**
* Method to get the script that have to be included on the view
*
* @return array script files
* @since 4.3
*/
public function getScripts(): array
{
return $this->scripts;
}
/**
* Method to set the script that have to be included on the view
*
* @return void
* @since 4.3
*/
public function setScript(string $path): void
{
$this->scripts[] = $path;
}
/**
* Method to test whether a record can be deleted.
*
* @param object $record A record object.
*
* @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
* @since 1.6
*/
protected function canDelete($record)
{
if (empty($record->id) || ($record->published != -2))
{
return false;
}
// The record has been set. Check the record permissions.
return $this->getCurrentUser()->authorise('repository.delete', 'com_componentbuilder.repository.' . (int) $record->id);
}
/**
* Method to test whether a record can have its state edited.
*
* @param object $record A record object.
*
* @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component.
* @since 1.6
*/
protected function canEditState($record)
{
$user = $this->getCurrentUser();
$recordId = $record->id ?? 0;
if ($recordId)
{
// The record has been set. Check the record permissions.
$permission = $user->authorise('repository.edit.state', 'com_componentbuilder.repository.' . (int) $recordId);
if (!$permission && !is_null($permission))
{
return false;
}
}
// In the absence of better information, revert to the component permissions.
return $user->authorise('repository.edit.state', 'com_componentbuilder');
}
/**
* Method override to check if you can edit an existing record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
* @since 2.5
*/
protected function allowEdit($data = [], $key = 'id')
{
// Check specific edit permission then general edit permission.
$user = Factory::getApplication()->getIdentity();
return $user->authorise('repository.edit', 'com_componentbuilder.repository.'. ((int) isset($data[$key]) ? $data[$key] : 0)) or $user->authorise('repository.edit', 'com_componentbuilder');
}
/**
* Prepare and sanitise the table data prior to saving.
*
* @param Table $table A Table object.
*
* @return void
* @since 1.6
*/
protected function prepareTable($table)
{
$date = Factory::getDate();
$user = $this->getCurrentUser();
if (isset($table->name))
{
$table->name = \htmlspecialchars_decode($table->name, ENT_QUOTES);
}
if (isset($table->alias) && empty($table->alias))
{
$table->generateAlias();
}
if (empty($table->id))
{
$table->created = $date->toSql();
// set the user
if ($table->created_by == 0 || empty($table->created_by))
{
$table->created_by = $user->id;
}
// Set ordering to the last item if not set
if (empty($table->ordering))
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('MAX(ordering)')
->from($db->quoteName('#__componentbuilder_repository'));
$db->setQuery($query);
$max = $db->loadResult();
$table->ordering = $max + 1;
}
}
else
{
$table->modified = $date->toSql();
$table->modified_by = $user->id;
}
if (!empty($table->id))
{
// Increment the items version number.
$table->version++;
}
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
* @since 1.6
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = Factory::getApplication()->getUserState('com_componentbuilder.edit.repository.data', []);
if (empty($data))
{
$data = $this->getItem();
}
// run the perprocess of the data
$this->preprocessData('com_componentbuilder.repository', $data);
return $data;
}
/**
* Method to get the unique fields of this table.
*
* @return mixed An array of field names, boolean false if none is set.
*
* @since 3.0
*/
protected function getUniqueFields()
{
return array('guid');
}
/**
* Method to delete one or more records.
*
* @param array &$pks An array of record primary keys.
*
* @return boolean True if successful, false if an error occurs
* @since 12.2
*/
public function delete(&$pks)
{
if (!parent::delete($pks))
{
return false;
}
return true;
}
/**
* Method to change the published state of one or more records.
*
* @param array &$pks A list of the primary keys to change.
* @param integer $value The value of the published state.
*
* @return boolean True on success.
* @since 12.2
*/
public function publish(&$pks, $value = 1)
{
if (!parent::publish($pks, $value))
{
return false;
}
return true;
}
/**
* Method to perform batch operations on an item or a set of items.
*
* @param array $commands An array of commands to perform.
* @param array $pks An array of item ids.
* @param array $contexts An array of item contexts.
*
* @return boolean Returns true on success, false on failure.
* @since 12.2
*/
public function batch($commands, $pks, $contexts)
{
// Sanitize ids.
$pks = array_unique($pks);
ArrayHelper::toInteger($pks);
// Remove any values of zero.
if (array_search(0, $pks, true))
{
unset($pks[array_search(0, $pks, true)]);
}
if (empty($pks))
{
$this->setError(Text::_('JGLOBAL_NO_ITEM_SELECTED'));
return false;
}
$done = false;
// Set some needed variables.
$this->user ??= $this->getCurrentUser();
$this->table = $this->getTable();
$this->tableClassName = get_class($this->table);
$this->contentType = new UCMType;
$this->type = $this->contentType->getTypeByTable($this->tableClassName);
$this->canDo = ComponentbuilderHelper::getActions('repository');
$this->batchSet = true;
if (!$this->canDo->get('core.batch'))
{
$this->setError(Text::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
return false;
}
if ($this->type == false)
{
$type = new UCMType;
$this->type = $type->getTypeByAlias($this->typeAlias);
}
$this->tagsObserver = $this->table->getObserverOfClass('JTableObserverTags');
if (!empty($commands['move_copy']))
{
$cmd = ArrayHelper::getValue($commands, 'move_copy', 'c');
if ($cmd == 'c')
{
$result = $this->batchCopy($commands, $pks, $contexts);
if (is_array($result))
{
foreach ($result as $old => $new)
{
$contexts[$new] = $contexts[$old];
}
$pks = array_values($result);
}
else
{
return false;
}
}
elseif ($cmd == 'm' && !$this->batchMove($commands, $pks, $contexts))
{
return false;
}
$done = true;
}
if (!$done)
{
$this->setError(Text::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
return false;
}
// Clear the cache
$this->cleanCache();
return true;
}
/**
* Batch copy items to a new category or current.
*
* @param integer $values The new values.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return mixed An array of new IDs on success, boolean false on failure.
*
* @since 12.2
*/
protected function batchCopy($values, $pks, $contexts)
{
if (empty($this->batchSet))
{
// Set some needed variables.
$this->user = Factory::getApplication()->getIdentity();
$this->table = $this->getTable();
$this->tableClassName = get_class($this->table);
$this->canDo = ComponentbuilderHelper::getActions('repository');
}
if (!$this->canDo->get('repository.create') && !$this->canDo->get('repository.batch'))
{
return false;
}
// get list of unique fields
$uniqueFields = $this->getUniqueFields();
// remove move_copy from array
unset($values['move_copy']);
// make sure published is set
if (!isset($values['published']))
{
$values['published'] = 0;
}
elseif (isset($values['published']) && !$this->canDo->get('repository.edit.state'))
{
$values['published'] = 0;
}
$newIds = [];
// Parent exists so let's proceed
while (!empty($pks))
{
// Pop the first ID off the stack
$pk = array_shift($pks);
$this->table->reset();
// only allow copy if user may edit this item.
if (!$this->user->authorise('repository.edit', $contexts[$pk]))
{
// Not fatal error
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
continue;
}
// Check that the row actually exists
if (!$this->table->load($pk))
{
if ($error = $this->table->getError())
{
// Fatal error
$this->setError($error);
return false;
}
else
{
// Not fatal error
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
continue;
}
}
// Only for strings
if (UtilitiesStringHelper::check($this->table->system_name) && !is_numeric($this->table->system_name))
{
$this->table->system_name = $this->generateUnique('system_name',$this->table->system_name);
}
// insert all set values
if (UtilitiesArrayHelper::check($values))
{
foreach ($values as $key => $value)
{
if (strlen($value) > 0 && isset($this->table->$key))
{
$this->table->$key = $value;
}
}
}
// update all unique fields
if (UtilitiesArrayHelper::check($uniqueFields))
{
foreach ($uniqueFields as $uniqueField)
{
$this->table->$uniqueField = $this->generateUnique($uniqueField,$this->table->$uniqueField);
}
}
// Reset the ID because we are making a copy
$this->table->id = 0;
// TODO: Deal with ordering?
// $this->table->ordering = 1;
// Check the row.
if (!$this->table->check())
{
$this->setError($this->table->getError());
return false;
}
if (!empty($this->type))
{
$this->createTagsHelper($this->tagsObserver, $this->type, $pk, $this->typeAlias, $this->table);
}
// Store the row.
if (!$this->table->store())
{
$this->setError($this->table->getError());
return false;
}
// Get the new item ID
$newId = $this->table->get('id');
// Add the new ID to the array
$newIds[$pk] = $newId;
}
// Clean the cache
$this->cleanCache();
return $newIds;
}
/**
* Batch move items to a new category
*
* @param integer $value The new category ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 12.2
*/
protected function batchMove($values, $pks, $contexts)
{
if (empty($this->batchSet))
{
// Set some needed variables.
$this->user = Factory::getApplication()->getIdentity();
$this->table = $this->getTable();
$this->tableClassName = get_class($this->table);
$this->canDo = ComponentbuilderHelper::getActions('repository');
}
if (!$this->canDo->get('repository.edit') && !$this->canDo->get('repository.batch'))
{
$this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
// make sure published only updates if user has the permission.
if (isset($values['published']) && !$this->canDo->get('repository.edit.state'))
{
unset($values['published']);
}
// remove move_copy from array
unset($values['move_copy']);
// Parent exists so we proceed
foreach ($pks as $pk)
{
if (!$this->user->authorise('repository.edit', $contexts[$pk]))
{
$this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
// Check that the row actually exists
if (!$this->table->load($pk))
{
if ($error = $this->table->getError())
{
// Fatal error
$this->setError($error);
return false;
}
else
{
// Not fatal error
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
continue;
}
}
// insert all set values.
if (UtilitiesArrayHelper::check($values))
{
foreach ($values as $key => $value)
{
// Do special action for access.
if ('access' === $key && strlen($value) > 0)
{
$this->table->$key = $value;
}
elseif (strlen($value) > 0 && isset($this->table->$key))
{
$this->table->$key = $value;
}
}
}
// Check the row.
if (!$this->table->check())
{
$this->setError($this->table->getError());
return false;
}
if (!empty($this->type))
{
$this->createTagsHelper($this->tagsObserver, $this->type, $pk, $this->typeAlias, $this->table);
}
// Store the row.
if (!$this->table->store())
{
$this->setError($this->table->getError());
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
* @since 1.6
*/
public function save($data)
{
$input = Factory::getApplication()->getInput();
$filter = InputFilter::getInstance();
// set the metadata to the Item Data
if (isset($data['metadata']) && isset($data['metadata']['author']))
{
$data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
$metadata = new Registry;
$metadata->loadArray($data['metadata']);
$data['metadata'] = (string) $metadata;
}
// Set the GUID if empty or not valid
if (empty($data['guid']) && $data['id'] > 0)
{
// get the existing one
$data['guid'] = (string) GetHelper::var('repository', $data['id'], 'id', 'guid');
}
// Set the GUID if empty or not valid
while (!GuidHelper::valid($data['guid'], "repository", $data['id']))
{
// must always be set
$data['guid'] = (string) GuidHelper::get();
}
// Set the Params Items to data
if (isset($data['params']) && is_array($data['params']))
{
$params = new Registry;
$params->loadArray($data['params']);
$data['params'] = (string) $params;
}
// Alter the unique field for save as copy
if ($input->get('task') === 'save2copy')
{
// Automatic handling of other unique fields
$uniqueFields = $this->getUniqueFields();
if (UtilitiesArrayHelper::check($uniqueFields))
{
foreach ($uniqueFields as $uniqueField)
{
$data[$uniqueField] = $this->generateUnique($uniqueField,$data[$uniqueField]);
}
}
}
if (parent::save($data))
{
return true;
}
return false;
}
/**
* Method to generate a unique value.
*
* @param string $field name.
* @param string $value data.
*
* @return string New value.
* @since 3.0
*/
protected function generateUnique($field, $value)
{
// set field value unique
$table = $this->getTable();
while ($table->load([$field => $value]))
{
$value = StringHelper::increment($value);
}
return $value;
}
/**
* Method to change the title
*
* @param string $title The title.
*
* @return array Contains the modified title and alias.
*
*/
protected function _generateNewTitle($title)
{
// Alter the title
$table = $this->getTable();
while ($table->load(['title' => $title]))
{
$title = StringHelper::increment($title);
}
return $title;
}
}