dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxConfig_dbx.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxAdmin;
3
5 private const CONFIG_FD = 'cfg:dbx';
6 private const SERVER_FD = 'fd:dbxAdmin|server';
7 private const NESTED_SECTIONS = array('ftp', 'mail');
8 private const SQL_DB_SECTION = 'db';
9 private const SERVER_FIELD_NAMES = array('activ', 'type', 'host', 'dbname', 'user', 'pass', 'port');
10
11 private array $config = array();
12 private string $activeTab = 'config';
13 private string $activeSubTab = '';
14 private array $sectionMessages = array();
15 private array $groupMessages = array();
16
17 public function run() {
18 $this->config = dbx()->get_config('dbx');
19 if (!is_array($this->config)) {
20 $this->config = array();
21 }
22
23 $this->read_active_state();
24 $arraySections = $this->array_sections();
25
26 if ($this->activeTab !== 'config'
27 && $this->activeTab !== self::SQL_DB_SECTION
28 && !in_array($this->activeTab, $arraySections, true)) {
29 $this->activeTab = 'config';
30 }
31
32 $tabs = array(
33 array(
34 'id' => 'config',
35 'label' => 'Config',
36 'content' => $this->render_config_form(),
37 ),
38 array(
39 'id' => self::SQL_DB_SECTION,
40 'label' => $this->section_label(self::SQL_DB_SECTION),
41 'content' => $this->render_array_section(self::SQL_DB_SECTION),
42 ),
43 );
44
45 foreach ($arraySections as $section) {
46 $tabs[] = array(
47 'id' => $section,
48 'label' => $this->section_label($section),
49 'content' => $this->render_array_section($section),
50 );
51 }
52
53 $tabsHtml = $this->render_tabs($tabs, 'dbx_config', $this->activeTab);
54 $help = dbx()->get_include_obj('dbxAdminHelp', 'dbxAdmin');
55
56 return $this->get_tpl('config-dbx-shell', array_merge(
57 $help->moduleBarTemplateData('config', '', '', '', 'Modul: dbx'),
58 array(
59 'frame_id' => 'dbx_target_config_dbx',
60 'frame_panel_class' => 'dbx-config-dbx',
61 'frame_form_open' => '',
62 'frame_form_close' => '',
63 'frame_subbar' => '',
64 'frame_body_class' => '',
65 'frame_body_head' => '',
66 'frame_body_tail' => '',
67 'frame_panel_attrs' => '',
68 'content' => $tabsHtml,
69 )
70 ));
71 }
72
73 private function tpl() {
74 return dbx()->get_system_obj('dbxTPL');
75 }
76
77 private function get_tpl(string $tpl, array $data = array()): string {
78 return $this->tpl()->get_tpl('dbxAdmin|' . $tpl, $data);
79 }
80
81 private function get_dbx_tpl(string $tpl, array $data = array()): string {
82 return $this->tpl()->get_tpl('dbx|' . $tpl, $data);
83 }
84
85 private function base_action(): string {
86 return '?dbx_modul=dbxAdmin&dbx_run1=config&dbx_run2=edit&xmodul=dbx';
87 }
88
89 private function read_active_state(): void {
90 $tab = (string)($_POST['activeTab'] ?? dbx()->get_modul_var('activeTab', 'config', 'parameter'));
91 $subTab = (string)($_POST['activeSubTab'] ?? dbx()->get_modul_var('activeSubTab', '', 'parameter'));
92
93 if ($tab === '') {
94 $tab = 'config';
95 }
96
97 $this->activeTab = $tab;
98 $this->activeSubTab = $subTab;
99 }
100
101 private function array_sections(): array {
102 $sections = array();
103
104 foreach (self::NESTED_SECTIONS as $section) {
105 if (isset($this->config[$section]) && is_array($this->config[$section])) {
106 $sections[] = $section;
107 }
108 }
109
110 return $sections;
111 }
112
113 private function render_tabs(array $tabs, string $idPrefix, string $activeId): string {
114 $tabHtml = '';
115 $paneHtml = '';
116
117 foreach ($tabs as $tab) {
118 $tabId = (string)($tab['id'] ?? 'tab');
119 $id = $this->safe_id($idPrefix . '_' . $tabId);
120 $label = (string)($tab['label'] ?? '');
121 $content = (string)($tab['content'] ?? '');
122 $active = ($tabId === $activeId);
123
124 $tabHtml .= $this->get_tpl('config-dbx-tab', array(
125 'id' => $id,
126 'label' => $this->h($label),
127 'active' => $active ? 'active' : '',
128 'selected' => $active ? 'true' : 'false',
129 ));
130
131 $paneHtml .= $this->get_tpl('config-dbx-pane', array(
132 'id' => $id,
133 'content' => $content,
134 'active' => $active ? 'show active' : '',
135 ));
136 }
137
138 return $this->get_tpl('config-dbx-tabs', array(
139 'tabs' => $tabHtml,
140 'panes' => $paneHtml,
141 ));
142 }
143
144 private function render_config_form(): string {
145 $data = $this->config_form_data();
146 $form = $this->new_form('config_dbx_general', $data, 'dbx System-Konfiguration bearbeiten.');
147 $this->add_state_fields($form);
148 $form->_fd = self::CONFIG_FD;
149 $form->add_flds(self::CONFIG_FD);
150 $form->add_fld('default_server', options: $this->sql_server_options());
151 $form->add_obj('actions', 'dbxAdmin|config-dbx-save-actions', array('label' => 'Config speichern'));
152
153 if ($form->submit() && !$form->errors()) {
154 $this->apply_config_form_post($form);
155 $this->set_form_save_message($form);
156 }
157
158 return $form->run();
159 }
160
161 private function config_form_data(): array {
162 $data = array(
163 'activeTab' => 'config',
164 'activeSubTab' => '',
165 );
166
167 foreach ($this->config_fd_names() as $name) {
168 $value = $this->config[$name] ?? '';
169 if ($name === 'groups' || $name === 'accessible_lng') {
170 $data[$name] = is_array($value) ? implode(',', $value) : (string) $value;
171 continue;
172 }
173 $data[$name] = $this->value_to_field($value);
174 }
175
176 return $data;
177 }
178
179 private function config_fd_names(): array {
180 $names = array();
181 $fields = array();
182 $file = dbx_os_path_file(dbx_get_base_dir() . 'dbx/modules/dbx/cfg/config.dd.php');
183 if (is_file($file)) {
184 include $file;
185 }
186 if (!is_array($fields)) {
187 return $names;
188 }
189 foreach ($fields as $field) {
190 if (!is_array($field) || empty($field['name'])) {
191 continue;
192 }
193 $names[] = (string) $field['name'];
194 }
195 return $names;
196 }
197
198 private function apply_config_form_post($form): void {
199 foreach ($this->config_fd_names() as $name) {
200 if (!array_key_exists($name, $form->_post)) {
201 continue;
202 }
203 $raw = $form->_post[$name];
204 $oldValue = $this->config[$name] ?? '';
205 if ($name === 'groups' || $name === 'accessible_lng') {
206 $this->config[$name] = $this->multiselect_to_array($raw);
207 continue;
208 }
209 $this->config[$name] = $this->field_to_top_value($oldValue, (string) $raw);
210 }
211 }
212
213 private function multiselect_to_array($raw): array {
214 if (is_array($raw)) {
215 return array_values(array_filter(array_map('trim', $raw), static function ($item) {
216 return $item !== '';
217 }));
218 }
219 $parts = preg_split('/\s*,\s*/', (string) $raw, -1, PREG_SPLIT_NO_EMPTY);
220 return is_array($parts) ? array_values($parts) : array();
221 }
222
223 private function sql_server_options(): string {
224 $options = array();
225 foreach ($this->sql_db_servers() as $name => $entry) {
226 $options[] = rawurlencode((string) $name) . '=' . rawurlencode((string) $name);
227 }
228 return implode('&', $options);
229 }
230
231 private function sql_db_servers(): array {
232 $db = $this->config['db'] ?? array();
233 if (!is_array($db)) {
234 return array();
235 }
236 $servers = array();
237 foreach ($db as $name => $entry) {
238 if (!is_array($entry) || $this->is_module_db_entry((string) $name, $entry)) {
239 continue;
240 }
241 $servers[(string) $name] = $entry;
242 }
243 return $servers;
244 }
245
246 private function is_module_db_entry(string $name, array $entry): bool {
247 return function_exists('dbx_config_is_module_db_entry')
248 && dbx_config_is_module_db_entry($name, $entry);
249 }
250
251 private function strip_module_db_from_config(): void {
252 if (!isset($this->config['db']) || !is_array($this->config['db'])) {
253 return;
254 }
255 foreach ($this->config['db'] as $name => $entry) {
256 if (is_array($entry) && $this->is_module_db_entry((string) $name, $entry)) {
257 unset($this->config['db'][$name]);
258 }
259 }
260 }
261
262 private function render_array_section(string $section): string {
263 $value = $this->config[$section] ?? array();
264 if (!is_array($value)) {
265 return $this->get_dbx_tpl('alert-info', array('msg' => 'Keine Eintraege vorhanden.'));
266 }
267
268 if ($this->is_grouped_section($value)) {
269 return $this->render_grouped_section($section, $value);
270 }
271
272 return $this->render_section_form($section, $value);
273 }
274
275 private function render_grouped_section(string $section, array $groups): string {
276 $this->process_group_add($section);
277 $this->process_group_action($section);
278
279 $groups = $section === self::SQL_DB_SECTION
280 ? $this->sql_db_servers()
281 : ($this->config[$section] ?? array());
282 if (!is_array($groups)) {
283 $groups = array();
284 }
285
286 $addForm = $this->render_group_add_form($section, $groups);
287
288 if (!$groups) {
289 $emptyMsg = $section === self::SQL_DB_SECTION
290 ? 'Keine SQL-Server in der Config. Modul-SQLite (*.db3) wird von dbxDB automatisch unter dbx/modules/*/db/ aufgeloest.'
291 : 'Keine Eintraege vorhanden.';
292 return $this->get_tpl('config-dbx-section', array(
293 'add_form' => $addForm,
294 'tabs' => $this->get_dbx_tpl('alert-info', array('msg' => $emptyMsg)),
295 ));
296 }
297
298 $activeGroup = ($this->activeTab === $section) ? $this->activeSubTab : '';
299 if ($activeGroup === '' || !isset($groups[$activeGroup])) {
300 $keys = array_keys($groups);
301 $activeGroup = (string)reset($keys);
302 }
303
304 $tabs = array();
305 foreach ($groups as $group => $values) {
306 if (!is_array($values)) {
307 $values = array();
308 }
309
310 $tabs[] = array(
311 'id' => (string)$group,
312 'label' => (string)$group,
313 'content' => $this->render_group_form($section, (string)$group, $values),
314 );
315 }
316
317 return $this->get_tpl('config-dbx-section', array(
318 'add_form' => $addForm,
319 'tabs' => $this->render_tabs($tabs, 'dbx_config_' . $section, $activeGroup),
320 ));
321 }
322
323 private function render_section_form(string $section, array $values): string {
324 $used = array();
325 $fields = $this->collect_fields('cfg_' . $section, $values, array(), $used);
326 $data = array(
327 'activeTab' => $section,
328 'activeSubTab' => '',
329 );
330
331 foreach ($fields as $field) {
332 $data[$field['name']] = $this->value_to_field($field['value']);
333 }
334
335 $label = $this->section_label($section);
336 $form = $this->new_form('config_dbx_' . $this->safe_token($section), $data, $label . ' bearbeiten.');
337 $this->add_state_fields($form);
338 $this->add_fields($form, $fields, $label);
339 $form->add_obj('actions', 'dbxAdmin|config-dbx-save-actions', array('label' => $label . ' speichern'));
340
341 if ($form->submit() && !$form->errors()) {
342 foreach ($fields as $name => $field) {
343 $oldValue = $field['value'];
344 $newValue = (string)($form->_post[$name] ?? '');
345 $this->set_path($this->config[$section], $field['path'], $this->field_to_value($oldValue, $newValue));
346 }
347
348 $this->set_form_save_message($form);
349 }
350
351 return $form->run();
352 }
353
354 private function render_group_form(string $section, string $group, array $values): string {
355 $form = $this->build_group_form($section, $group, $values);
356 $this->apply_group_message($form, $section, $group);
357
358 return $form->run();
359 }
360
361 private function process_group_add(string $section): void {
362 $form = $this->build_group_add_form($section, $this->config[$section] ?? array());
363
364 if (!$form->submit()) {
365 return;
366 }
367
368 if ($form->errors()) {
369 $this->sectionMessages[$section] = array('error', 'Bitte den neuen Namen pruefen.');
370 return;
371 }
372
373 $entry = trim((string)($form->_post['configEntry'] ?? ''));
374 if ($entry === '') {
375 $this->sectionMessages[$section] = array('error', 'Bitte den neuen Namen eingeben.');
376 return;
377 }
378
379 if (!isset($this->config[$section]) || !is_array($this->config[$section])) {
380 $this->config[$section] = array();
381 }
382
383 if (isset($this->config[$section][$entry])) {
384 $this->sectionMessages[$section] = array('error', 'Eintrag "' . $entry . '" ist bereits vorhanden.');
385 return;
386 }
387
388 $this->config[$section][$entry] = $section === self::SQL_DB_SECTION
389 ? array(
390 'activ' => '1',
391 'type' => 'mysql',
392 'host' => '127.0.0.1',
393 'dbname' => '',
394 'user' => '',
395 'pass' => '',
396 'port' => '3306',
397 )
398 : $this->empty_group_template($this->config[$section]);
399
400 if (!$this->save_config()) {
401 $this->sectionMessages[$section] = array('error', 'Eintrag konnte nicht angelegt werden.');
402 return;
403 }
404
405 $this->activeTab = $section;
406 $this->activeSubTab = $entry;
407 $this->sectionMessages[$section] = array('success', 'Eintrag "' . $entry . '" wurde angelegt.');
408 }
409
410 private function process_group_action(string $section): void {
411 if (($this->activeTab !== $section) || $this->activeSubTab === '') {
412 return;
413 }
414
415 $group = $this->activeSubTab;
416 if (!isset($this->config[$section][$group]) || !is_array($this->config[$section][$group])) {
417 return;
418 }
419
420 $values = $this->config[$section][$group];
421 $form = $this->build_group_form($section, $group, $values);
422
423 if (!$form->submit()) {
424 return;
425 }
426
427 if (!empty($_POST['deleteAction'])) {
428 unset($this->config[$section][$group]);
429
430 if (!$this->save_config()) {
431 $this->sectionMessages[$section] = array('error', 'Eintrag "' . $group . '" konnte nicht geloescht werden.');
432 return;
433 }
434
435 $keys = array_keys((array)$this->config[$section]);
436 $this->activeSubTab = $keys ? (string)reset($keys) : '';
437 $this->sectionMessages[$section] = array('success', 'Eintrag "' . $group . '" wurde geloescht.');
438 return;
439 }
440
441 if ($form->errors()) {
442 $this->groupMessages[$section][$group] = array('error', 'Bitte Eingaben pruefen.');
443 return;
444 }
445
446 if ($section === self::SQL_DB_SECTION) {
447 $record = $this->server_record_from_post($form->_post);
448 if (strtolower((string) ($record['type'] ?? '')) === 'sqlite') {
449 $this->groupMessages[$section][$group] = array('error', 'Modul-SQLite (*.db3) gehoert nicht in die System-Config.');
450 return;
451 }
452 $this->config[$section][$group] = $record;
453 } else {
454 foreach ($this->group_fields($section, $group, $values) as $name => $field) {
455 $oldValue = $field['value'];
456 $newValue = (string)($form->_post[$name] ?? '');
457 $this->set_path($this->config[$section][$group], $field['path'], $this->field_to_value($oldValue, $newValue));
458 }
459 }
460
461 if (!$this->save_config()) {
462 $this->groupMessages[$section][$group] = array('error', 'Eintrag konnte nicht gespeichert werden.');
463 return;
464 }
465
466 $this->groupMessages[$section][$group] = array('success', 'Eintrag wurde gespeichert.');
467 }
468
469 private function render_group_add_form(string $section, array $groups): string {
470 $form = $this->build_group_add_form($section, $groups);
471 $this->apply_section_message($form, $section);
472 return $form->run();
473 }
474
475 private function build_group_add_form(string $section, array $groups) {
476 $label = $this->section_label($section);
477 $form = $this->new_form('config_dbx_' . $this->safe_token($section) . '_add', array(
478 'activeTab' => $section,
479 'activeSubTab' => '',
480 'configAction' => 'add',
481 'configEntry' => '',
482 ), 'Neuen ' . $label . '-Eintrag anlegen.');
483
484 $this->add_state_fields($form);
485 $form->add_fld('configAction', 'dbx|hidden', rules: 'parameter', dd: '');
486 $form->add_fld('configEntry', 'text-label', label: 'Neuer Eintrag', rules: 'parameter|min=1', tooltip: 'Name fuer den neuen Eintrag', dd: '');
487 $form->add_obj('actions', 'dbxAdmin|config-dbx-save-actions', array('label' => $label . ' anlegen'));
488
489 return $form;
490 }
491
492 private function build_group_form(string $section, string $group, array $values) {
493 $fields = $this->group_fields($section, $group, $values);
494 $data = array(
495 'activeTab' => $section,
496 'activeSubTab' => $group,
497 'configAction' => 'save',
498 );
499
500 if ($section === self::SQL_DB_SECTION) {
501 foreach (self::SERVER_FIELD_NAMES as $name) {
502 $data[$name] = (string) ($values[$name] ?? ($name === 'activ' ? '1' : ''));
503 }
504 } else {
505 foreach ($fields as $field) {
506 $data[$field['name']] = $this->value_to_field($field['value']);
507 }
508 }
509
510 $label = $this->section_label($section);
511 $form = $this->new_form(
512 'config_dbx_' . $this->safe_token($section) . '_' . $this->safe_token($group),
513 $data,
514 $label . ' "' . $group . '" bearbeiten.'
515 );
516 $this->add_state_fields($form);
517 $form->add_fld('configAction', 'dbx|hidden', rules: 'parameter', dd: '');
518 if ($section === self::SQL_DB_SECTION) {
519 $this->add_server_fields($form);
520 } else {
521 $this->add_fields($form, $fields, $label . ' ' . $group);
522 }
523 $form->add_obj('actions', 'dbxAdmin|config-dbx-group-actions', array(
524 'save_label' => $label . ' speichern',
525 'delete_label' => $label . ' loeschen',
526 'confirm' => $label . ' "' . $group . '" wirklich loeschen?',
527 ));
528
529 return $form;
530 }
531
532 private function group_fields(string $section, string $group, array $values): array {
533 $used = array();
534 return $this->collect_fields('cfg_' . $section . '_' . $group, $values, array(), $used);
535 }
536
537 private function new_form(string $fid, array $data, string $info) {
538 $form = dbx()->get_system_obj('dbxForm');
539 $form->init($fid, 'form-config-dbx');
540 $form->_action = $this->base_action();
541 $form->_data = array_merge($form->_data, $data);
542 $form->_msg_info = $info;
543 $form->_fld_change_state = '*';
544
545 return $form;
546 }
547
548 private function add_state_fields($form): void {
549 $form->add_fld('activeTab', 'dbx|hidden', rules: 'parameter', dd: '');
550 $form->add_fld('activeSubTab', 'dbx|hidden', rules: 'parameter', dd: '');
551 }
552
553 private function add_fields($form, array $fields, string $tooltipPrefix): void {
554 foreach ($fields as $field) {
555 $form->add_fld(
556 $field['name'],
557 $this->field_template($field),
558 label: $field['label'],
559 rules: '*',
560 tooltip: $tooltipPrefix . ': ' . $field['label'],
561 dd: ''
562 );
563 }
564 }
565
566 private function field_template(array $field): string {
567 $path = (array)($field['path'] ?? array());
568 $last = strtolower((string)end($path));
569 $sensitive = array('pass', 'password', 'pwd', 'secret', 'token', 'api_key', 'apikey', 'private_key');
570
571 foreach ($sensitive as $needle) {
572 if ($last === $needle || str_ends_with($last, '_' . $needle) || str_contains($last, $needle)) {
573 return 'password-label';
574 }
575 }
576
577 return 'text-label';
578 }
579
580 private function add_server_fields($form): void {
581 foreach (self::SERVER_FIELD_NAMES as $name) {
582 $form->add_fld($name, dd: self::SERVER_FD);
583 }
584 }
585
586 private function server_record_from_post(array $post): array {
587 $record = array();
588 foreach (self::SERVER_FIELD_NAMES as $name) {
589 $record[$name] = trim((string) ($post[$name] ?? ($name === 'activ' ? '1' : '')));
590 }
591 return $record;
592 }
593
594 private function set_form_save_message($form): void {
595 if ($this->save_config()) {
596 $form->_msg_success = 'Die Konfiguration wurde erfolgreich gespeichert.';
597 return;
598 }
599
600 $form->_msg_error = 'Fehler beim Speichern der Konfiguration.';
601 }
602
603 private function save_config(): bool {
604 $this->strip_module_db_from_config();
605 return (bool)dbx()->set_config('dbx', $this->config);
606 }
607
608 private function apply_section_message($form, string $section): void {
609 if (empty($this->sectionMessages[$section])) {
610 return;
611 }
612
613 $this->apply_message($form, $this->sectionMessages[$section]);
614 }
615
616 private function apply_group_message($form, string $section, string $group): void {
617 if (empty($this->groupMessages[$section][$group])) {
618 return;
619 }
620
621 $this->apply_message($form, $this->groupMessages[$section][$group]);
622 }
623
624 private function apply_message($form, array $message): void {
625 $mode = (string)($message[0] ?? 'info');
626 $text = (string)($message[1] ?? '');
627
628 if ($mode === 'success') {
629 $form->_msg_success = $text;
630 return;
631 }
632
633 if ($mode === 'error') {
634 $form->_msg_error = $text;
635 return;
636 }
637
638 if ($mode === 'warning') {
639 $form->_msg_warning = $text;
640 return;
641 }
642
643 $form->_msg_info = $text;
644 }
645
646 private function empty_group_template(array $groups): array {
647 foreach ($groups as $group) {
648 if (is_array($group)) {
649 return $this->empty_like($group);
650 }
651 }
652
653 return array('name' => '');
654 }
655
656 private function empty_like($value) {
657 if (is_array($value)) {
658 $empty = array();
659 foreach ($value as $key => $item) {
660 $empty[$key] = $this->empty_like($item);
661 }
662
663 return $empty;
664 }
665
666 return '';
667 }
668
669 private function collect_fields(string $prefix, array $value, array $path, array &$used): array {
670 $fields = array();
671
672 foreach ($value as $key => $item) {
673 $nextPath = array_merge($path, array((string)$key));
674
675 if (is_array($item)) {
676 $fields = array_merge($fields, $this->collect_fields($prefix, $item, $nextPath, $used));
677 continue;
678 }
679
680 $field = $this->field_definition($prefix, $nextPath, $item, $used);
681 $fields[$field['name']] = $field;
682 }
683
684 return $fields;
685 }
686
687 private function field_definition(string $prefix, array $path, $value, array &$used): array {
688 $name = $this->field_name($prefix, $path);
689 $baseName = $name;
690 $counter = 2;
691
692 while (isset($used[$name])) {
693 $name = $baseName . '_' . $counter;
694 $counter++;
695 }
696
697 $used[$name] = 1;
698
699 return array(
700 'name' => $name,
701 'path' => $path,
702 'label' => implode(' / ', $path),
703 'value' => $value,
704 );
705 }
706
707 private function set_path(array &$target, array $path, $value): void {
708 if (!$path) {
709 return;
710 }
711
712 $key = array_shift($path);
713
714 if (!$path) {
715 $target[$key] = $value;
716 return;
717 }
718
719 if (!isset($target[$key]) || !is_array($target[$key])) {
720 $target[$key] = array();
721 }
722
723 $this->set_path($target[$key], $path, $value);
724 }
725
726 private function value_to_field($value): string {
727 if (is_array($value)) {
728 if ($this->is_list_array($value)) {
729 return implode(',', array_map('strval', $value));
730 }
731
732 return http_build_query($value);
733 }
734
735 return (string)$value;
736 }
737
738 private function field_to_top_value($oldValue, string $value) {
739 if (is_array($oldValue)) {
740 if ($this->is_list_array($oldValue)) {
741 return $value;
742 }
743
744 if (strpos($value, '&') !== false) {
745 $parsed = array();
746 parse_str($value, $parsed);
747 return $parsed;
748 }
749
750 return $value;
751 }
752
753 return $this->field_to_value($oldValue, $value);
754 }
755
756 private function field_to_value($oldValue, string $value) {
757 if (is_int($oldValue)) {
758 return (int)$value;
759 }
760
761 if (is_float($oldValue)) {
762 return (float)$value;
763 }
764
765 if (is_bool($oldValue)) {
766 return in_array(strtolower($value), array('1', 'true', 'yes', 'on'), true);
767 }
768
769 return $value;
770 }
771
772 private function is_list_array(array $value): bool {
773 if ($value === array()) {
774 return true;
775 }
776
777 return array_keys($value) === range(0, count($value) - 1);
778 }
779
780 private function is_grouped_section(array $value): bool {
781 if (!$value) {
782 return false;
783 }
784
785 foreach ($value as $item) {
786 if (!is_array($item)) {
787 return false;
788 }
789 }
790
791 return true;
792 }
793
794 private function section_label(string $section): string {
795 $labels = array(
796 'db' => 'SQL-Server',
797 'ftp' => 'FTP',
798 'mail' => 'Mail',
799 );
800
801 return $labels[$section] ?? $section;
802 }
803
804 private function field_name(string $prefix, array $parts): string {
805 $tokens = array($this->safe_token($prefix));
806 foreach ($parts as $part) {
807 $tokens[] = $this->safe_token((string)$part);
808 }
809
810 return implode('_', $tokens);
811 }
812
813 private function safe_token(string $value): string {
814 $value = preg_replace('/[^a-zA-Z0-9_]+/', '_', $value);
815 $value = trim((string)$value, '_');
816
817 if ($value === '') {
818 return 'x';
819 }
820
821 return $value;
822 }
823
824 private function safe_id(string $value): string {
825 return 'dbx_' . strtolower($this->safe_token($value));
826 }
827
828 private function h($value): string {
829 return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
830 }
831}
$fields[]
Definition config.dd.php:16
$field
Definition config.dd.php:4
dbx_os_path_file($path_file)
Definition index.php:164
dbx_config_is_module_db_entry(string $key, array $entry)
Definition index.php:231
if( $syncRequest)
Definition index.php:520
dbx_get_base_dir($cut_Data=0)
Definition index.php:157
DBX schema administration.
foreach( $topics as $file=> $html)