dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxModuleRegistry.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxAdmin;
3
8
9 private $modulesRoot = '';
10 private $groupLabels = null;
11 private $inspectCache = array();
12 private $images = null;
13
14 public function __construct() {
15 $this->modulesRoot = dbx()->os_path(dbx()->get_base_dir() . 'dbx/modules/');
16 }
17
18 public function listModuleNames(): array {
19 $names = array();
20 if (!is_dir($this->modulesRoot)) {
21 return $names;
22 }
23
24 $dh = opendir($this->modulesRoot);
25 if (!$dh) {
26 return $names;
27 }
28
29 while (($file = readdir($dh)) !== false) {
30 if ($file === '.' || $file === '..' || $file === 'tpl') {
31 continue;
32 }
33 $path = $this->modulesRoot . $file;
34 if (!is_dir($path)) {
35 continue;
36 }
37 $names[] = $file;
38 }
39 closedir($dh);
40
41 sort($names, SORT_NATURAL | SORT_FLAG_CASE);
42 if (($key = array_search('dbx', $names, true)) !== false) {
43 array_splice($names, $key, 1);
44 array_unshift($names, 'dbx');
45 }
46
47 return $names;
48 }
49
50 public function inspect(string $modul): array {
51 $modul = trim($modul);
52 if (isset($this->inspectCache[$modul])) {
53 return $this->inspectCache[$modul];
54 }
55
56 $base = $this->modulesRoot . $modul . DIRECTORY_SEPARATOR;
57 $config = dbx()->get_config($modul);
58 if (!is_array($config)) {
59 $config = array();
60 }
61
62 $runs = $this->scanRuns($modul);
63 $defaultRun1 = (string)($runs['default_run1'] ?? 'run');
64 $defaultRun2 = (string)($runs['default_run2'] ?? '');
65 $install = $this->detectInstall($modul);
66 $images = $this->images();
67 $graphic = $images->moduleSymbol($modul);
68 $imageItems = $images->imageItems($modul);
69 $ddList = $this->detectDdUsage($modul);
70 $ddItems = $this->buildDdItems($ddList);
71 $ddCount = count($ddList);
72 $description = $this->detectDescription($modul, $base, $ddList);
73 $groups = $this->normalizeGroups($config['groups'] ?? '*');
74 $active = $this->isActive($config);
75 $version = trim((string)($config['version'] ?? ''));
76
77 $previewModul = $modul;
78 $previewRun1 = $defaultRun1;
79 $previewRun2 = $defaultRun2;
80 if ($modul === 'dbxHome') {
81 $previewRun1 = '';
82 $previewRun2 = '';
83 }
84
85 $previewUrl = $this->buildModulUrl($previewModul, $previewRun1, $previewRun2);
86 $installUrl = $install['url'] ?? '';
87 $configUrl = $this->configEditUrl($modul);
88 $accessUrl = '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_access&dbx_run3=edit&xmodul=' . rawurlencode($modul);
89 $helpUrl = '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_help&xmodul=' . rawurlencode($modul);
90 $avatarUrl = '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_avatar&xmodul=' . rawurlencode($modul);
91
92 $this->inspectCache[$modul] = array(
93 'xmodul' => $modul,
94 'title' => $modul,
95 'description' => $description,
96 'version' => $version !== '' ? $version : '—',
97 'active' => $active ? '1' : '0',
98 'active_label' => $active ? 'Aktiv' : 'Inaktiv',
99 'active_class' => $active ? 'success' : 'secondary',
100 'groups' => $groups,
101 'groups_text' => $this->groupsText($groups),
102 'dd_list' => $ddList,
103 'dd_items' => $ddItems,
104 'dd_count' => $ddCount,
105 'dd_select_id' => 'dbx_mod_dd_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $modul),
106 'dd_select_size' => 6,
107 'default_run1' => $defaultRun1,
108 'default_run2' => $defaultRun2,
109 'default_call' => $this->formatDefaultCall($modul, $defaultRun1, $defaultRun2),
110 'preview_url' => $previewUrl,
111 'install_url' => $installUrl,
112 'has_install' => !empty($install['url']) ? '1' : '0',
113 'install_modul' => (string)($install['modul'] ?? ''),
114 'config_url' => $configUrl,
115 'access_url' => $accessUrl,
116 'help_url' => $helpUrl,
117 'avatar_url' => $avatarUrl,
118 'images_url' => '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_images&xmodul=' . rawurlencode($modul),
119 'images_add_url' => '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_images_add',
120 'images_upload_url' => '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_images_upload',
121 'images_remove_url' => '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_images_remove',
122 'symbol_add_url' => '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_symbol_add',
123 'symbol_media_url' => '?dbx_modul=dbxContent_admin&dbx_run1=cms_media&images=1&media_type=image',
124 'symbol_upload_url' => '?dbx_modul=dbxContent_admin&dbx_run1=cms_upload',
125 'symbol_mediafolders_url' => '?dbx_modul=dbxContent_admin&dbx_run1=cms_media_folders',
126 'symbol_mediafoldercreate_url' => '?dbx_modul=dbxContent_admin&dbx_run1=cms_media_folder_create',
127 'symbol_mediafolderdelete_url' => '?dbx_modul=dbxContent_admin&dbx_run1=cms_media_folder_delete',
128 'symbol_deletemedia_url' => '?dbx_modul=dbxContent_admin&dbx_run1=cms_delete_media',
129 'access_save_url' => '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_access_save',
130 'active_toggle_url' => '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_active_toggle',
131 'delete_url' => '?dbx_modul=dbxAdmin&dbx_run1=modules&dbx_run2=modul_delete',
132 'can_delete' => $this->canDeleteModule($modul) ? '1' : '0',
133 'graphic_url' => (string)($graphic['url'] ?? ''),
134 'graphic_alt' => (string)($graphic['alt'] ?? $modul),
135 'graphic_badge' => (string)($graphic['badge'] ?? ''),
136 'placeholder_url' => $this->moduleImageEmptyPlaceholderUrl(),
137 'placeholder_alt' => $this->moduleImageEmptyPlaceholderAlt(),
138 'module_images' => array_values(array_map(function ($item) {
139 return (string)($item['file'] ?? '');
140 }, $imageItems)),
141 'image_items' => $imageItems,
142 'image_count_cfg' => count($imageItems),
143 'has_class' => is_file($base . $modul . '.class.php') ? '1' : '0',
144 'run_cases' => (array)($runs['run1'] ?? array()),
145 'uses_run2' => !empty($runs['uses_run2']) ? '1' : '0',
146 );
147 return $this->inspectCache[$modul];
148 }
149
150 private function images(): dbxModuleImages {
151 if (!class_exists('dbx\\dbxAdmin\\dbxModuleImages', false)) {
152 require_once __DIR__ . '/dbxModuleImages.class.php';
153 }
154 if (!$this->images instanceof dbxModuleImages) {
155 $this->images = new dbxModuleImages();
156 }
157 return $this->images;
158 }
159
160 public function ddEditUrl(string $modul, string $dd): string {
161 return '?dbx_modul=dbxAdmin&dbx_run1=edit_dd&modul=' . rawurlencode($modul) . '&dd=' . rawurlencode($dd);
162 }
163
164 public function buildDdItems(array $ddList): array {
165 $items = array();
166 foreach ($ddList as $ddRef) {
167 $parts = explode('|', (string)$ddRef, 2);
168 $m = trim((string)($parts[0] ?? ''));
169 $d = trim((string)($parts[1] ?? ''));
170 if ($m === '' || $d === '') {
171 continue;
172 }
173 $items[] = array(
174 'ref' => $ddRef,
175 'modul' => $m,
176 'dd' => $d,
177 'label' => $d,
178 'modul_label' => $m,
179 'edit_url' => $this->ddEditUrl($m, $d),
180 'edit_title' => 'DD bearbeiten: ' . $m . '/' . $d,
181 );
182 }
183 return $items;
184 }
185
186 public function inspectAll(): array {
187 $rows = array();
188 foreach ($this->listModuleNames() as $modul) {
189 $rows[] = $this->inspect($modul);
190 }
191 return $rows;
192 }
193
194 public function groupOptions(): array {
195 if (is_array($this->groupLabels)) {
196 return $this->groupLabels;
197 }
198
199 $options = array(
200 'admin' => 'Admin',
201 'guest' => 'Gast',
202 'member' => 'Mitglied',
203 '*' => 'Alle (*)',
204 );
205
206 $db = dbx()->get_system_obj('dbxDB');
207 $userGroups = $db->select('dbxUser_groups', 'active = 1');
208 if (is_array($userGroups)) {
209 foreach ($userGroups as $record) {
210 $id = trim((string)($record['name'] ?? ''));
211 if ($id === '') {
212 continue;
213 }
214 $options[$id] = trim((string)($record['description'] ?? $id));
215 }
216 }
217
218 $this->groupLabels = $options;
219 return $this->groupLabels;
220 }
221
222 private function groupsText(array $groups): string {
223 if (!$groups) {
224 return '—';
225 }
226
227 $labels = $this->groupOptions();
228 $parts = array();
229 foreach ($groups as $group) {
230 $parts[] = $labels[$group] ?? $group;
231 }
232
233 return implode(', ', $parts);
234 }
235
236 private function normalizeGroups($groups): array {
237 if (is_array($groups)) {
238 $out = array();
239 foreach ($groups as $value) {
240 $value = trim((string)$value);
241 if ($value !== '') {
242 $out[] = $value;
243 }
244 }
245 return array_values(array_unique($out));
246 }
247
248 $text = trim((string)$groups);
249 if ($text === '') {
250 return array('*');
251 }
252
253 $parts = preg_split('/\s*,\s*/', $text, -1, PREG_SPLIT_NO_EMPTY);
254 if (!is_array($parts) || !$parts) {
255 return array($text);
256 }
257
258 return array_values(array_unique($parts));
259 }
260
261 private function isActive(array $config): bool {
262 if (isset($config['activ'])) {
263 return (string)$config['activ'] === '1';
264 }
265 if (isset($config['active'])) {
266 return (string)$config['active'] === '1';
267 }
268 return true;
269 }
270
271 private function configEditUrl(string $modul): string {
272 if ($modul === 'dbx') {
273 return '?dbx_modul=dbxAdmin&dbx_run1=config&dbx_run2=edit&xmodul=dbx';
274 }
275
276 $file = 'dbx/modules/' . $modul . '/cfg/config.php';
277 return '?dbx_modul=dbxEditor&dbx_run1=edit&file=' . rawurlencode($file);
278 }
279
280 private function moduleClassFiles(string $modul): array {
281 $base = $this->modulesRoot . $modul . DIRECTORY_SEPARATOR;
282 $files = array();
283 $main = $base . $modul . '.class.php';
284 if (is_file($main)) {
285 $files[] = $main;
286 }
287 $inc = $base . 'include' . DIRECTORY_SEPARATOR;
288 if (is_dir($inc)) {
289 foreach (glob($inc . '*.class.php') ?: array() as $path) {
290 if (is_file($path)) {
291 $files[] = $path;
292 }
293 }
294 }
295 return $files;
296 }
297
298 public function scanRunsPublic(string $modul): array {
299 return $this->scanRuns($modul);
300 }
301
302 private function scanRuns(string $modul): array {
303 $run1 = array();
304 $defaultRun1 = '';
305 $defaultRun2 = '';
306 $usesRun2 = false;
307
308 foreach ($this->moduleClassFiles($modul) as $file) {
309 $src = @file_get_contents($file);
310 if (!is_string($src) || $src === '') {
311 continue;
312 }
313
314 if (preg_match("/get_modul_var\s*\‍(\s*['\"]dbx_run2['\"]/", $src)) {
315 $usesRun2 = true;
316 }
317
318 if ($defaultRun1 === '' && preg_match("/get_modul_var\s*\‍(\s*['\"]dbx_run1['\"][^,]*,\s*['\"]([^'\"]+)['\"]/", $src, $match)) {
319 $candidate = trim((string)$match[1]);
320 if ($candidate !== '' && $candidate !== 'parameter') {
321 $defaultRun1 = $candidate;
322 }
323 }
324
325 if ($defaultRun2 === '' && preg_match("/get_modul_var\s*\‍(\s*['\"]dbx_run2['\"][^,]*,\s*['\"]([^'\"]+)['\"]/", $src, $match)) {
326 $candidate = trim((string)$match[1]);
327 if ($candidate !== '' && $candidate !== 'parameter') {
328 $defaultRun2 = $candidate;
329 }
330 }
331
332 if (preg_match_all("/case\s+['\"]([^'\"]+)['\"]\s*:/", $src, $matches)) {
333 foreach ($matches[1] as $case) {
334 $case = trim((string)$case);
335 if ($case === '' || $case === 'default') {
336 continue;
337 }
338 $run1[$case] = true;
339 }
340 }
341
342 if (preg_match_all('/\$(?:run|action|work)\s*===?\s*[\'"]([^\'"]+)[\'"]/', $src, $ifs)) {
343 foreach ($ifs[1] as $case) {
344 $case = trim((string)$case);
345 if ($case !== '') {
346 $run1[$case] = true;
347 }
348 }
349 }
350 }
351
352 if ($defaultRun1 === '') {
353 $keys = array_keys($run1);
354 $defaultRun1 = $keys ? (string)$keys[0] : 'run';
355 }
356
357 if ($modul === 'dbxAdmin' && isset($run1['run'])) {
358 $defaultRun1 = 'run';
359 }
360 if ($modul === 'dbxHome') {
361 $defaultRun1 = '';
362 }
363
364 return array(
365 'run1' => array_keys($run1),
366 'default_run1' => $defaultRun1,
367 'default_run2' => $defaultRun2,
368 'uses_run2' => $usesRun2,
369 );
370 }
371
372 private function detectInstall(string $modul): array {
373 $candidates = array($modul);
374 if (substr($modul, -6) !== '_admin') {
375 $candidates[] = $modul . '_admin';
376 }
377
378 foreach ($candidates as $candidate) {
379 foreach ($this->moduleClassFiles($candidate) as $file) {
380 $src = @file_get_contents($file);
381 if (!is_string($src) || $src === '') {
382 continue;
383 }
384 if (!preg_match("/case\s+['\"]install['\"]\s*:/", $src)
385 && !preg_match('/\$(?:run|action|work)\s*===?\s*[\'"]install[\'"]/', $src)) {
386 continue;
387 }
388
389 return array(
390 'modul' => $candidate,
391 'url' => $this->buildModulUrl($candidate, 'install'),
392 );
393 }
394 }
395
396 return array();
397 }
398
399 private function detectDdUsage(string $modul): array {
400 $found = array();
401
402 $ddDir = $this->modulesRoot . $modul . DIRECTORY_SEPARATOR . 'dd' . DIRECTORY_SEPARATOR;
403 if (is_dir($ddDir)) {
404 foreach (glob($ddDir . '*.dd.php') ?: array() as $file) {
405 $name = basename($file, '.dd.php');
406 if ($name === '' || $name === 'new' || str_starts_with($name, '.')) {
407 continue;
408 }
409 $this->registerDdRef($found, $modul, $name);
410 }
411 }
412
413 foreach ($this->moduleClassFiles($modul) as $file) {
414 $src = @file_get_contents($file);
415 if (!is_string($src) || $src === '') {
416 continue;
417 }
418
419 if (preg_match_all("/['\"]" . preg_quote($modul, '/') . "\|([a-zA-Z][a-zA-Z0-9_]*)['\"]/", $src, $matches)) {
420 foreach ($matches[1] as $dd) {
421 $this->registerDdRef($found, $modul, $dd);
422 }
423 }
424
425 if (preg_match_all("/_dd\s*=\s*['\"]([a-zA-Z][a-zA-Z0-9_]*(?:\|[a-zA-Z][a-zA-Z0-9_]*)?)['\"]/", $src, $matches)) {
426 foreach ($matches[1] as $ddRef) {
427 $this->registerDdRefString($found, $modul, $ddRef);
428 }
429 }
430
431 if (preg_match_all("/load_dd\s*\‍(\s*['\"]([a-zA-Z][a-zA-Z0-9_]*(?:\|[a-zA-Z][a-zA-Z0-9_]*)?)['\"]/", $src, $matches)) {
432 foreach ($matches[1] as $ddRef) {
433 $this->registerDdRefString($found, $modul, $ddRef);
434 }
435 }
436 }
437
438 $list = array_keys($found);
439 sort($list, SORT_NATURAL | SORT_FLAG_CASE);
440 return $list;
441 }
442
443 private function isValidIdent(string $name): bool {
444 return (bool)preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $name);
445 }
446
447 private function ddFileExists(string $modul, string $dd): bool {
448 $path = $this->modulesRoot . $modul . DIRECTORY_SEPARATOR . 'dd' . DIRECTORY_SEPARATOR . $dd . '.dd.php';
449 return is_file($path);
450 }
451
452 private function registerDdRef(array &$found, string $modul, string $dd): void {
453 $modul = trim($modul);
454 $dd = trim($dd);
455 if (!$this->isValidIdent($modul) || !$this->isValidIdent($dd)) {
456 return;
457 }
458 if (!$this->ddFileExists($modul, $dd)) {
459 return;
460 }
461 $found[$modul . '|' . $dd] = true;
462 }
463
464 private function registerDdRefString(array &$found, string $modul, string $ddRef): void {
465 $ddRef = trim($ddRef);
466 if ($ddRef === '') {
467 return;
468 }
469 if (strpos($ddRef, '|') !== false) {
470 $parts = explode('|', $ddRef, 2);
471 $this->registerDdRef($found, $parts[0], $parts[1]);
472 return;
473 }
474 $this->registerDdRef($found, $modul, $ddRef);
475 }
476
477 private function detectDescription(string $modul, string $base, array $ddList = array()): string {
478 $candidates = array(
479 $base . 'cfg' . DIRECTORY_SEPARATOR . 'about.txt',
480 $base . 'cfg' . DIRECTORY_SEPARATOR . 'help.txt',
481 $base . $modul . '.class.php',
482 $base . 'cfg' . DIRECTORY_SEPARATOR . 'config.php',
483 );
484
485 foreach ($candidates as $file) {
486 if (!is_file($file)) {
487 continue;
488 }
489 $text = $this->readLeadComment($file);
490 if ($text !== '') {
491 return $this->trimDescription($text);
492 }
493 }
494
495 $runs = $this->scanRuns($modul);
496 $parts = array();
497 $parts[] = 'Standardaufruf: ' . $this->formatDefaultCall($modul, (string)($runs['default_run1'] ?? 'run'), (string)($runs['default_run2'] ?? ''));
498 if ($ddList) {
499 $parts[] = count($ddList) . ' DataDic-Datei(en)';
500 }
501
502 return implode(' · ', $parts);
503 }
504
505 private function readLeadComment(string $file): string {
506 $src = @file_get_contents($file);
507 if (!is_string($src) || $src === '') {
508 return '';
509 }
510
511 if (preg_match('/\A\s*<\?php\s*/', $src)) {
512 $src = preg_replace('/\A\s*<\?php\s*/', '', $src, 1);
513 }
514
515 if (preg_match('/\A\s*\/\*\*(.*?)\*\//s', $src, $match)) {
516 return $this->cleanCommentBlock($match[1]);
517 }
518 if (preg_match('/\A\s*\/\*(.*?)\*\//s', $src, $match)) {
519 return $this->cleanCommentBlock($match[1]);
520 }
521
522 return '';
523 }
524
525 private function cleanCommentBlock(string $text): string {
526 $lines = preg_split('/\R/', $text);
527 $out = array();
528 foreach ($lines as $line) {
529 $line = preg_replace('/^\s*\*\s?/', '', $line);
530 $line = trim((string)$line);
531 if ($line === '' || preg_match('/^@/', $line)) {
532 continue;
533 }
534 $out[] = $line;
535 }
536 return trim(implode(' ', $out));
537 }
538
539 private function trimDescription(string $text): string {
540 $text = preg_replace('/\s+/', ' ', trim($text));
541 if (strlen($text) > 320) {
542 $text = substr($text, 0, 317) . '…';
543 }
544 return $text;
545 }
546
547 public function placeholderGraphic(string $modul, string $run1 = '', string $run2 = ''): array {
548 return $this->resolveModGraphic($modul, $run1, $run2);
549 }
550
551 public function moduleImageEmptyPlaceholderUrl(): string {
552 static $cache = array();
553 $dir = dbx_get_base_dir() . 'dbx/modules/dbxAdmin/tpl/img/';
554 $lng = function_exists('dbx_lng_current')
555 ? dbx_lng_current()
556 : strtolower(trim((string) dbx()->get_system_var('dbx_lng', 'de')));
557 if ($lng === '') {
558 $lng = 'de';
559 }
560 if (isset($cache[$lng])) {
561 return $cache[$lng];
562 }
563
564 $candidates = array(
565 'modul-no-image_' . $lng . '.svg',
566 'modul-no-image.svg',
567 'modul-no-image_de.svg',
568 'modul-no-image_en.svg',
569 );
570
571 $path = '';
572 foreach ($candidates as $file) {
573 $try = $dir . $file;
574 if (is_file($try)) {
575 $path = $try;
576 break;
577 }
578 }
579
580 if ($path === '') {
581 $path = function_exists('dbx_lng_resolve_file')
582 ? dbx_lng_resolve_file($dir, 'modul-no-image', 'svg')
583 : '';
584 }
585
586 if ($path === '' || !is_file($path)) {
587 $cache[$lng] = '';
588 return '';
589 }
590
591 $file = basename(str_replace('\\', '/', $path));
592 $cache[$lng] = dbx()->get_base_url() . 'dbx/modules/dbxAdmin/tpl/img/' . rawurlencode($file);
593 return $cache[$lng];
594 }
595
596 public function moduleImageEmptyPlaceholderAlt(): string {
597 static $cache = array();
598 $lng = function_exists('dbx_lng_current')
599 ? dbx_lng_current()
600 : strtolower(trim((string) dbx()->get_system_var('dbx_lng', 'de')));
601 if (isset($cache[$lng])) {
602 return $cache[$lng];
603 }
604 if ($lng === 'en') {
605 $cache[$lng] = 'No module image selected';
606 return $cache[$lng];
607 }
608 if ($lng === 'es') {
609 $cache[$lng] = 'Sin imagen de módulo seleccionada';
610 return $cache[$lng];
611 }
612 $cache[$lng] = 'Kein Modulbild ausgewählt';
613 return $cache[$lng];
614 }
615
616 private function resolveModGraphic(string $modul, string $run1, string $run2): array {
617 $urlBase = dbx()->get_base_url() . 'dbx/modules/' . rawurlencode($modul) . '/';
618 $modDir = $this->modulesRoot . $modul . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . 'mod' . DIRECTORY_SEPARATOR;
619
620 $candidates = array();
621 if ($run1 !== '' && $run2 !== '') {
622 $candidates[] = $modul . '_' . $run1 . '_' . $run2 . '.svg';
623 }
624 if ($run1 !== '') {
625 $candidates[] = $modul . '_' . $run1 . '.svg';
626 }
627 $candidates[] = $modul . '.svg';
628
629 if (is_dir($modDir)) {
630 foreach ($candidates as $name) {
631 if (is_file($modDir . $name)) {
632 return array(
633 'url' => $urlBase . 'tpl/mod/' . rawurlencode($name),
634 'alt' => $modul . ' ' . $run1,
635 'badge' => $name,
636 );
637 }
638 }
639
640 $any = glob($modDir . '*.svg');
641 if (is_array($any) && isset($any[0]) && is_file($any[0])) {
642 $name = basename($any[0]);
643 return array(
644 'url' => $urlBase . 'tpl/mod/' . rawurlencode($name),
645 'alt' => $modul,
646 'badge' => $name,
647 );
648 }
649 }
650
651 $imgPath = $this->modulesRoot . $modul . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'modul.gif';
652 if (is_file($imgPath)) {
653 return array(
654 'url' => $urlBase . 'tpl/img/modul.gif',
655 'alt' => $modul,
656 'badge' => 'modul.gif',
657 );
658 }
659
660 return array(
661 'url' => dbx()->get_base_url() . 'dbx/modules/dbxAdmin/tpl/mod/dbxAdmin_modul.svg',
662 'alt' => $modul,
663 'badge' => 'placeholder',
664 );
665 }
666
667 public function modulUrl(string $modul, string $run1 = '', string $run2 = ''): string {
668 return $this->buildModulUrl($modul, $run1, $run2);
669 }
670
671 public function canDeleteModule(string $modul): bool {
672 $modul = trim($modul);
673 if ($modul === '' || !preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $modul)) {
674 return false;
675 }
676 $protected = array('dbx', 'dbxAdmin', 'dbxLogin', 'dbxHome');
677 if (in_array($modul, $protected, true)) {
678 return false;
679 }
680 $dir = $this->modulesRoot . $modul;
681 return is_dir($dir);
682 }
683
684 private function buildModulUrl(string $modul, string $run1 = '', string $run2 = ''): string {
685 $url = '?dbx_modul=' . rawurlencode($modul);
686 if ($run1 !== '') {
687 $url .= '&dbx_run1=' . rawurlencode($run1);
688 }
689 if ($run2 !== '') {
690 $url .= '&dbx_run2=' . rawurlencode($run2);
691 }
692 return $url;
693 }
694
695 private function formatDefaultCall(string $modul, string $run1, string $run2): string {
696 $parts = array('dbx_modul=' . $modul);
697 if ($run1 !== '') {
698 $parts[] = 'dbx_run1=' . $run1;
699 }
700 if ($run2 !== '') {
701 $parts[] = 'dbx_run2=' . $run2;
702 }
703 return implode('&', $parts);
704 }
705
706 public function moduleHelpPath(string $modul): string {
707 $modul = trim($modul);
708 if ($modul === '') {
709 return '';
710 }
711 $path = $this->modulesRoot . $modul . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . 'htm' . DIRECTORY_SEPARATOR . 'modul-help.htm';
712 return is_file($path) ? $path : '';
713 }
714
715 public function renderModuleHelp(string $modul, array $data = array()): string {
716 $modul = trim($modul);
717 if ($modul === '') {
718 return '';
719 }
720
721 $tpl = dbx()->get_system_obj('dbxTPL');
722 if ($this->moduleHelpPath($modul) === '') {
723 if (!isset($data['modul'])) {
724 $data['modul'] = dbx()->esc($modul);
725 }
726 return $tpl->get_tpl('dbxAdmin|modul-help-fallback', $data);
727 }
728
729 return $tpl->get_tpl($modul . '|modul-help', $data);
730 }
731}
Erkennt Modul-Metadaten aus Dateisystem und PHP-Quellen (ohne manuelle Registry).
renderModuleHelp(string $modul, array $data=array())
modulUrl(string $modul, string $run1='', string $run2='')
placeholderGraphic(string $modul, string $run1='', string $run2='')
$config['version']
Definition config.php:2
if( $syncRequest)
Definition index.php:520
dbx_get_base_dir($cut_Data=0)
Definition index.php:157
DBX schema administration.