From 13cb06bd889c1ca5e040164406a0363c10b4f310 Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Sat, 7 Sep 2024 22:29:38 +0200 Subject: [PATCH] CS --- pages/email.php | 7 ------ pages/manager.data_export.php | 7 +++--- pages/manager.data_history.php | 22 +++++++++------- pages/manager.data_import.php | 27 ++++++++------------ pages/manager.table_edit.php | 42 +++++++++++++++---------------- pages/manager.table_field.php | 12 +++------ pages/manager.table_migrate.php | 17 ++++++------- pages/manager.tableset_export.php | 15 +++++------ pages/manager.tableset_import.php | 12 +++------ pages/rest.access.php | 12 +++------ pages/rest.token.php | 15 +++++------ pages/setup.php | 9 +++---- 12 files changed, 82 insertions(+), 115 deletions(-) diff --git a/pages/email.php b/pages/email.php index bc374e90..3fc5b846 100644 --- a/pages/email.php +++ b/pages/email.php @@ -3,13 +3,6 @@ use Yakamara\YForm\Email\Template; use Yakamara\YForm\YForm; -/** - * yform. - * - * @author jan.kristinus[at]redaxo[dot]org Jan Kristinus - * @author www.yakamara.de - */ - $_csrf_key = 'yform_email'; echo rex_view::title(rex_i18n::msg('yform_email_templates')); diff --git a/pages/manager.data_export.php b/pages/manager.data_export.php index 3a8eae4b..6e45b850 100644 --- a/pages/manager.data_export.php +++ b/pages/manager.data_export.php @@ -1,9 +1,8 @@ table->getTableName()); + $dataset = Dataset::getRaw($datasetId, $this->table->getTableName()); } else { $filterDataset = false; } @@ -214,9 +218,9 @@ $list->setColumnLabel('action', rex_i18n::msg('yform_history_action')); $list->setColumnFormat('action', 'custom', static function (array $params) { static $classes = [ - \Yakamara\YForm\Manager\Dataset::ACTION_CREATE => 'success', - \Yakamara\YForm\Manager\Dataset::ACTION_UPDATE => 'primary', - \Yakamara\YForm\Manager\Dataset::ACTION_DELETE => 'danger', + Dataset::ACTION_CREATE => 'success', + Dataset::ACTION_UPDATE => 'primary', + Dataset::ACTION_DELETE => 'danger', ]; $class = $classes[$params['subject']] ?? 'default'; return sprintf('%s', $class, rex_i18n::msg('yform_history_action_' . $params['subject'])); @@ -264,7 +268,7 @@ $options = '' . rex_i18n::msg('yform_history_delete') . ': ' . $fragment->parse('core/buttons/button_group.php'); } -$historySearchForm = new \Yakamara\YForm\YForm(); +$historySearchForm = new YForm(); $historySearchForm->setObjectparams('form_action', $list->getUrl()); $historySearchForm->setObjectparams('form_showformafterupdate', true); $historySearchForm->setObjectparams('real_field_names', true); @@ -291,9 +295,9 @@ 'label' => 'Action', 'choices' => [ '' => rex_i18n::msg('yform_manager_actions_all'), - \Yakamara\YForm\Manager\Dataset::ACTION_CREATE => rex_i18n::msg('yform_history_action_' . \Yakamara\YForm\Manager\Dataset::ACTION_CREATE), - \Yakamara\YForm\Manager\Dataset::ACTION_UPDATE => rex_i18n::msg('yform_history_action_' . \Yakamara\YForm\Manager\Dataset::ACTION_UPDATE), - \Yakamara\YForm\Manager\Dataset::ACTION_DELETE => rex_i18n::msg('yform_history_action_' . \Yakamara\YForm\Manager\Dataset::ACTION_DELETE), + Dataset::ACTION_CREATE => rex_i18n::msg('yform_history_action_' . Dataset::ACTION_CREATE), + Dataset::ACTION_UPDATE => rex_i18n::msg('yform_history_action_' . Dataset::ACTION_UPDATE), + Dataset::ACTION_DELETE => rex_i18n::msg('yform_history_action_' . Dataset::ACTION_DELETE), ], ]); diff --git a/pages/manager.data_import.php b/pages/manager.data_import.php index b9cd7f37..cd9c6d7b 100644 --- a/pages/manager.data_import.php +++ b/pages/manager.data_import.php @@ -1,13 +1,11 @@ www.yakamara.de - * - * @var rex_yform_manager $this - */ +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Manager; +use Yakamara\YForm\Manager\Table\Api; +use Yakamara\YForm\Manager\Table\Table; + +/** @var Manager $this */ $_csrf_key ??= ''; @@ -79,7 +77,6 @@ try { $sql_db->transactional(function () use ($filename, $show_importform, $div, $fieldarray, $missing_columns, $debug, &$counter, &$dcounter, &$ecounter, &$rcounter, &$icounter, &$errorcounter, $fields) { - $fp = fopen($filename, 'r'); $firstbytes = fread($fp, 3); $bom = pack('CCC', 0xEF, 0xBB, 0xBF); @@ -131,7 +128,7 @@ foreach ($mc as $mcc) { rex_sql::factory() - ->setTable(\Yakamara\YForm\Manager\Field::table()) + ->setTable(Field::table()) ->setValue('table_name', $this->table->getTablename()) ->setValue('prio', 999) ->setValue('type_id', 'value') @@ -145,10 +142,10 @@ echo rex_view::info(rex_i18n::msg('yform_manager_import_field_added', $mcc)); } - \Yakamara\YForm\Manager\Table\Api::generateTablesAndFields(); + Api::generateTablesAndFields(); $fields = []; - foreach (\Yakamara\YForm\Manager\Table\Table::get($this->table->getTableName())->getFields() as $field) { + foreach (Table::get($this->table->getTableName())->getFields() as $field) { $fields[strtolower($field->getName())] = $field; } } else { @@ -232,10 +229,8 @@ 'data_errors' => $errorcounter, ], )); - }); - - } catch (\Throwable $e) { + } catch (Throwable $e) { $error_message = $e->getMessage(); } @@ -252,7 +247,7 @@ echo rex_view::error(rex_i18n::msg('yform_manager_import_info_data_imported', $dcounter)); } - \Yakamara\YForm\Manager\Table\Table::deleteCache(); + Table::deleteCache(); } } diff --git a/pages/manager.table_edit.php b/pages/manager.table_edit.php index 24fcede3..4ccb34bf 100644 --- a/pages/manager.table_edit.php +++ b/pages/manager.table_edit.php @@ -1,11 +1,9 @@ www.yakamara.de - */ +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Table\Api; +use Yakamara\YForm\Manager\Table\Table; +use Yakamara\YForm\YForm; echo rex_view::title(rex_i18n::msg('yform')); $_csrf_key = 'yform_table_edit'; @@ -19,7 +17,7 @@ $show_list = true; if ('tableset_import' == $func && rex::getUser()->isAdmin()) { - $yform = new \Yakamara\YForm\YForm(); + $yform = new YForm(); $yform->setDebug(true); $yform->setHiddenField('page', $page); $yform->setHiddenField('func', $func); @@ -58,7 +56,7 @@ } else { try { $content = file_get_contents($yform->objparams['value_pool']['email']['importfile']); - \Yakamara\YForm\Manager\Table\Api::importTablesets($content); + Api::importTablesets($content); echo rex_view::info(rex_i18n::msg('yform_manager_table_import_success')); } catch (Exception $e) { echo rex_view::warning(rex_i18n::msg('yform_manager_table_import_failed', '', $e->getMessage())); @@ -67,13 +65,13 @@ } elseif (('add' == $func || 'edit' == $func) && rex::getUser()->isAdmin()) { $table = null; if ('edit' == $func) { - $table = \Yakamara\YForm\Manager\Table\Table::getById($table_id); + $table = Table::getById($table_id); if (!$table) { $func = 'add'; } } - $yform = new \Yakamara\YForm\YForm(); + $yform = new YForm(); // $yform->setDebug(TRUE); $yform->setObjectparams('form_name', $_csrf_key); $yform->setHiddenField('page', $page); @@ -85,7 +83,7 @@ $yform->setHiddenField('start', rex_request('start', 'string')); $yform->setActionField('showtext', ['', rex_i18n::msg('yform_manager_table_entry_saved')]); - $yform->setObjectparams('main_table', \Yakamara\YForm\Manager\Table\Table::table()); + $yform->setObjectparams('main_table', Table::table()); $yform->setValueField('html', ['html' => '
']); $yform->setValueField('html', ['html' => '']); @@ -97,7 +95,7 @@ $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_update_table')); $yform->setValueField('showvalue', ['table_name', rex_i18n::msg('yform_manager_table_name')]); $yform->setHiddenField('table_id', $table->getId()); - $yform->setActionField('db', [\Yakamara\YForm\Manager\Table\Table::table(), 'id=' . $table->getId()]); + $yform->setActionField('db', [Table::table(), 'id=' . $table->getId()]); $yform->setObjectparams('main_id', $table->getId()); $yform->setObjectparams('main_where', 'id=' . $table->getId()); $yform->setObjectparams('getdata', true); @@ -112,9 +110,9 @@ return !count($matches) || current($matches) != $table; }, '', rex_i18n::msg('yform_manager_table_enter_specialchars')]); $yform->setValidateField('customfunction', ['table_name', static function ($label = '', $table = '', $params = '') { - return (bool) \Yakamara\YForm\Manager\Table\Table::get($table); + return (bool) Table::get($table); }, '', rex_i18n::msg('yform_manager_table_exists')]); - $yform->setActionField('db', [\Yakamara\YForm\Manager\Table\Table::table()]); + $yform->setActionField('db', [Table::table()]); break; } @@ -147,7 +145,7 @@ $sortFields = ['id']; if ('edit' === $func) { $sortFieldsSql = rex_sql::factory(); - $sortFieldsSql->setQuery('SELECT f.name FROM `' . \Yakamara\YForm\Manager\Field::table() . '` f LEFT JOIN `' . \Yakamara\YForm\Manager\Table\Table::table() . '` t ON f.table_name = t.table_name WHERE t.id = :id ORDER BY f.prio', [ + $sortFieldsSql->setQuery('SELECT f.name FROM `' . Field::table() . '` f LEFT JOIN `' . Table::table() . '` t ON f.table_name = t.table_name WHERE t.id = :id ORDER BY f.prio', [ 'id' => (int) $table_id, ]); while ($sortFieldsSql->hasNext()) { @@ -223,19 +221,19 @@ switch ($func) { case 'edit': $table_name = $yform->objparams['value_pool']['email']['table_name']; - $table = \Yakamara\YForm\Manager\Table\Table::get($table_name); + $table = Table::get($table_name); if ($table) { - \Yakamara\YForm\Manager\Table\Api::generateTableAndFields($table); + Api::generateTableAndFields($table); } echo rex_view::info(rex_i18n::msg('yform_manager_table_updated')); break; case 'add': default: - \Yakamara\YForm\Manager\Table\Table::deleteCache(); + Table::deleteCache(); $table_name = $yform->objparams['value_pool']['sql']['table_name']; - $table = \Yakamara\YForm\Manager\Table\Table::get($table_name); + $table = Table::get($table_name); if ($table) { - \Yakamara\YForm\Manager\Table\Api::generateTableAndFields($table); + Api::generateTableAndFields($table); echo rex_view::success(rex_i18n::msg('yform_manager_table_added')); } break; @@ -248,7 +246,7 @@ echo rex_view::error(rex_i18n::msg('csrf_token_invalid')); } else { $table_name = rex_request('table_name', 'string'); - \Yakamara\YForm\Manager\Table\Api::removeTable($table_name); + Api::removeTable($table_name); $func = ''; echo rex_view::success(rex_i18n::msg('yform_manager_table_deleted')); @@ -310,7 +308,7 @@ function rex_yform_list_translate($params) $fragment->setVar('size', 'xs', false); $panel_options = $fragment->parse('core/buttons/button_group.php'); - $sql = 'select id, prio, name, table_name, status, hidden, import, export, search, mass_deletion, mass_edit, history from `' . \Yakamara\YForm\Manager\Table\Table::table() . '`'; + $sql = 'select id, prio, name, table_name, status, hidden, import, export, search, mass_deletion, mass_edit, history from `' . Table::table() . '`'; $list = rex_list::factory($sql, 200, defaultSort: [ 'prio' => 'asc', diff --git a/pages/manager.table_field.php b/pages/manager.table_field.php index 7a883ed9..521aaa4a 100644 --- a/pages/manager.table_field.php +++ b/pages/manager.table_field.php @@ -1,20 +1,16 @@ www.yakamara.de - */ +use Yakamara\YForm\Manager\Manager; +use Yakamara\YForm\Manager\Table\Table; echo rex_view::title(rex_i18n::msg('yform')); $table_name = rex_request('table_name', 'string'); -$table = \Yakamara\YForm\Manager\Table\Table::get($table_name); +$table = Table::get($table_name); if ($table) { try { - $page = new rex_yform_manager(); + $page = new Manager(); $page->setTable($table); $page->setLinkVars(['page' => 'yform/manager/table_field']); echo $page->getFieldPage(); diff --git a/pages/manager.table_migrate.php b/pages/manager.table_migrate.php index ab2751cb..679db6fd 100644 --- a/pages/manager.table_migrate.php +++ b/pages/manager.table_migrate.php @@ -1,11 +1,8 @@ www.yakamara.de - */ +use Yakamara\YForm\Manager\Table\Api; +use Yakamara\YForm\Manager\Table\Table; +use Yakamara\YForm\YForm; echo rex_view::title(rex_i18n::msg('yform')); $_csrf_key = 'table_migrate'; @@ -17,7 +14,7 @@ $yform_tables = []; $missing_tables = []; -foreach (\Yakamara\YForm\Manager\Table\Table::getAll() as $g_table) { +foreach (Table::getAll() as $g_table) { $yform_tables[] = $g_table->getTableName(); } @@ -27,7 +24,7 @@ } } -$yform = new \Yakamara\YForm\YForm(); +$yform = new YForm(); $yform->setObjectparams('form_showformafterupdate', 1); $yform->setObjectparams('form_name', $_csrf_key); $yform->setHiddenField('page', $page); @@ -40,12 +37,12 @@ $schema_overwrite = (int) $yform->objparams['value_pool']['sql']['schema_overwrite']; try { - \Yakamara\YForm\Manager\Table\Api::migrateTable($table_name, (0 == $schema_overwrite) ? false : true); // with convert id / auto_increment finder + Api::migrateTable($table_name, (0 == $schema_overwrite) ? false : true); // with convert id / auto_increment finder echo rex_view::success(rex_i18n::msg('yform_manager_table_migrated_success')); unset($missing_tables[$table_name]); - $yform = new \Yakamara\YForm\YForm(); + $yform = new YForm(); $yform->setObjectparams('form_showformafterupdate', 1); $yform->setHiddenField('page', $page); $yform->setValueField('choice', ['name' => 'table_name', 'label' => rex_i18n::msg('yform_table'), 'choices' => $missing_tables]); diff --git a/pages/manager.tableset_export.php b/pages/manager.tableset_export.php index e7b815a5..04dd0cf8 100644 --- a/pages/manager.tableset_export.php +++ b/pages/manager.tableset_export.php @@ -1,11 +1,8 @@ www.yakamara.de - */ +use Yakamara\YForm\Manager\Table\Api; +use Yakamara\YForm\Manager\Table\Table; +use Yakamara\YForm\YForm; echo rex_view::title(rex_i18n::msg('yform')); $_csrf_key = 'tableset_export'; @@ -13,12 +10,12 @@ $page = rex_request('page', 'string', ''); $yform_tables = []; -foreach (\Yakamara\YForm\Manager\Table\Table::getAll() as $g_table) { +foreach (Table::getAll() as $g_table) { $table_name = $g_table->getTableName(); $yform_tables[$table_name] = $g_table->getNameLocalized() . ' [' . $table_name . ']'; } -$yform = new \Yakamara\YForm\YForm(); +$yform = new YForm(); $yform->setHiddenField('page', $page); $yform->setObjectparams('real_field_names', true); $yform->setObjectparams('form_name', $_csrf_key); @@ -29,7 +26,7 @@ if ($yform->objparams['actions_executed']) { try { $table_names = rex_request('table_names'); - $fileContent = \Yakamara\YForm\Manager\Table\Api::exportTablesets($table_names); + $fileContent = Api::exportTablesets($table_names); $tablenames = implode('_', $table_names); if (mb_strlen($tablenames) > 100) { diff --git a/pages/manager.tableset_import.php b/pages/manager.tableset_import.php index b5f6da8d..ddfa2c6d 100644 --- a/pages/manager.tableset_import.php +++ b/pages/manager.tableset_import.php @@ -1,18 +1,14 @@ www.yakamara.de - */ +use Yakamara\YForm\Manager\Table\Api; +use Yakamara\YForm\YForm; echo rex_view::title(rex_i18n::msg('yform')); $_csrf_key = 'tableset_import'; $page = rex_request('page', 'string', ''); -$yform = new \Yakamara\YForm\YForm(); +$yform = new YForm(); $yform->setHiddenField('page', $page); $yform->setObjectparams('real_field_names', true); $yform->setObjectparams('form_name', $_csrf_key); @@ -36,7 +32,7 @@ try { $filder = $yform->objparams['value_pool']['files']['importfile'][2]; $content = file_get_contents($filder); - \Yakamara\YForm\Manager\Table\Api::importTablesets($content); + Api::importTablesets($content); echo rex_view::success(rex_i18n::msg('yform_manager_tableset_import_success')); } catch (Exception $e) { echo rex_view::warning(rex_i18n::msg('yform_manager_tableset_import_failed', $e->getMessage())); diff --git a/pages/rest.access.php b/pages/rest.access.php index c83fdd09..a78deaea 100644 --- a/pages/rest.access.php +++ b/pages/rest.access.php @@ -1,11 +1,7 @@ www.yakamara.de - */ +use Yakamara\YForm\Rest\AuthToken; +use Yakamara\YForm\YForm; $_csrf_key = 'yform_rest_token_access'; @@ -34,7 +30,7 @@ $form_data[] = 'datetime|datetime_created|translate:yform_rest_token_access_datetime_created'; $form_data[] = 'text|url|translate:yform_rest_token_url'; - $yform = \Yakamara\YForm\YForm::factory(); + $yform = YForm::factory(); $yform->setObjectparams('form_action', 'index.php?page=yform/rest/access'); $yform->setFormData(implode("\n", $form_data)); @@ -154,7 +150,7 @@ $list->setColumnParams('token_id', ['page' => 'yform/rest/token', 'func' => 'edit', 'data_id' => '###rest_id###']); $list->setColumnFormat('token_id', 'custom', static function ($params) { - $token = \Yakamara\YForm\Rest\AuthToken::get($params['subject']); + $token = AuthToken::get($params['subject']); if ($token) { return '' . $token['name'] . ''; } diff --git a/pages/rest.token.php b/pages/rest.token.php index 70387150..b54c341e 100644 --- a/pages/rest.token.php +++ b/pages/rest.token.php @@ -1,11 +1,8 @@ www.yakamara.de - */ +use Yakamara\YForm\Rest\AuthToken; +use Yakamara\YForm\Rest\Rest; +use Yakamara\YForm\YForm; $_csrf_key = 'yform_rest_token'; @@ -21,7 +18,7 @@ $show_list = true; $routes = []; -foreach (\Yakamara\YForm\Rest\Rest::getRoutes() as $route) { +foreach (Rest::getRoutes() as $route) { $routes[] = $route->getPath(); } @@ -46,7 +43,7 @@ $form_data[] = 'integer|amount|translate:yform_rest_token_amount'; $form_data[] = 'choice|paths|translate:yform_rest_token_token_paths|' . implode(',', $routes) . '||1'; - $yform = \Yakamara\YForm\YForm::factory(); + $yform = YForm::factory(); $yform->setObjectparams('form_action', 'index.php?page=yform/rest/token'); $yform->setObjectparams('form_name', 'yform-rest-token-form'); @@ -189,7 +186,7 @@ $return = $maxHits; if ('none' != $list->getValue('interval')) { - $currentHits = \Yakamara\YForm\Rest\AuthToken::getCurrentIntervalAmount($list->getValue('interval'), $list->getValue('id')); + $currentHits = AuthToken::getCurrentIntervalAmount($list->getValue('interval'), $list->getValue('id')); $return = $currentHits . ' / ' . $maxHits . ' / ' . $list->getValue('interval') . ''; } diff --git a/pages/setup.php b/pages/setup.php index 6a3c6aff..e6eef9ed 100644 --- a/pages/setup.php +++ b/pages/setup.php @@ -1,9 +1,8 @@ i18n('yform')); @@ -69,5 +68,5 @@ $fragment = new rex_fragment(); $fragment->setVar('title', $this->i18n('description_type_heading'), false); -$fragment->setVar('body', \Yakamara\YForm\YForm::showHelp(), false); +$fragment->setVar('body', YForm::showHelp(), false); echo $fragment->parse('core/page/section.php');