dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
generate_mod_placeholders.php
Go to the documentation of this file.
1<?php
8
9if (PHP_SAPI !== 'cli') {
10 http_response_code(404);
11 exit;
12}
13
14$modulesDir = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR;
15
16function mod_class_files($modulesDir, $modul) {
17 $base = $modulesDir . $modul . DIRECTORY_SEPARATOR;
18 $files = array();
19 $main = $base . $modul . '.class.php';
20 if (is_file($main)) $files[] = $main;
21 $inc = $base . 'include' . DIRECTORY_SEPARATOR;
22 if (is_dir($inc)) {
23 foreach (glob($inc . '*.class.php') ?: array() as $path) {
24 if (is_file($path)) $files[] = $path;
25 }
26 }
27 return $files;
28}
29
30function mod_scan_runs($modulesDir, $modul) {
31 $run1 = array();
32 $run2 = array();
33 $uses_run2 = false;
34 foreach (mod_class_files($modulesDir, $modul) as $file) {
35 $src = @file_get_contents($file);
36 if (!is_string($src) || $src === '') continue;
37 if (preg_match("/get_modul_var\s*\‍(\s*['\"]dbx_run2['\"]/", $src)) {
38 $uses_run2 = true;
39 }
40 if (preg_match_all("/case\s+['\"]([^'\"]+)['\"]\s*:/", $src, $matches)) {
41 foreach ($matches[1] as $case) {
42 $case = trim((string)$case);
43 if ($case === '' || $case === 'default') continue;
44 $run1[$case] = true;
45 }
46 }
47 if (preg_match_all('/\$(?:run|action|work)\s*===?\s*[\'"]([^\'"]+)[\'"]/', $src, $ifs)) {
48 foreach ($ifs[1] as $case) {
49 $case = trim((string)$case);
50 if ($case === '') continue;
51 $run1[$case] = true;
52 }
53 }
54 if (preg_match_all("/get_modul_var\s*\‍(\s*['\"]dbx_run1['\"][^)]*['\"]([a-zA-Z0-9_]+)['\"]/", $src, $defaults)) {
55 foreach ($defaults[1] as $case) {
56 $case = trim((string)$case);
57 if ($case === '' || $case === 'parameter') continue;
58 $run1[$case] = true;
59 }
60 }
61 }
62 return array(
63 'run1' => array_keys($run1),
64 'uses_run2' => $uses_run2,
65 );
66}
67
68function mod_is_api_action($run1) {
69 if (preg_match('/^cms_(tree|page|save|new|delete|move|media|upload|external|remove|edit|set|assign|sort|mod_)/', $run1)) {
70 return true;
71 }
72 return false;
73}
74
75function mod_run2_variants($modul, $run1) {
76 $map = array(
77 'dbxContent' => array(
78 'cms' => array('show', 'tree', 'page'),
79 'content' => array('edit'),
80 ),
81 'dbxUser' => array(
82 'user' => array('profil', 'avatar', 'avatar_upload', 'edit_profil', 'edit_avatar'),
83 ),
84 'dbxLogin' => array(
85 'register' => array('confirm', 'resend_confirm'),
86 ),
87 'dbxHelp' => array(
88 'dbx' => array('show'),
89 ),
90 );
91 if (!isset($map[$modul][$run1])) return array();
92 return $map[$modul][$run1];
93}
94
95function mod_specs_for_module($modulesDir, $modul, $scan) {
96 $specs = array();
97 $uses_run2 = !empty($scan['uses_run2']);
98 $run1_list = $scan['run1'];
99
100 if ($uses_run2 && $modul === 'dbxHelp') {
101 return array(array('dbx', 'show'));
102 }
103
104 $has_run1 = false;
105 foreach ($run1_list as $run1) {
106 if (mod_is_api_action($run1)) continue;
107 $has_run1 = true;
108 $specs[] = array($run1, '');
109 foreach (mod_run2_variants($modul, $run1) as $run2) {
110 $specs[] = array($run1, $run2);
111 }
112 }
113
114 if (!$has_run1) {
115 $specs[] = array('show', '');
116 }
117
118 $uniq = array();
119 $out = array();
120 foreach ($specs as $spec) {
121 $key = $spec[0] . '|' . $spec[1];
122 if (isset($uniq[$key])) continue;
123 $uniq[$key] = true;
124 $out[] = $spec;
125 }
126 return $out;
127}
128
129function mod_visual_type($run1, $run2) {
130 $key = strtolower($run2 !== '' ? $run2 : $run1);
131 if (preg_match('/(form|contact|edit|profil|register|login)/', $key)) return 'form';
132 if (preg_match('/(list|tree|flat|overview|folder|files|grid)/', $key)) return 'list';
133 if (preg_match('/(menu|load|nav)/', $key)) return 'menu';
134 if (preg_match('/(cms|content|show|view|page|dashboard|run)/', $key)) return 'content';
135 if (preg_match('/(media|image|upload|avatar)/', $key)) return 'media';
136 if (preg_match('/(api|web|json|html)/', $key)) return 'api';
137 return 'default';
138}
139
140function mod_palette($type) {
141 $palettes = array(
142 'form' => array('#f8f6f2', '#8a6d3b', '#d8cfc0'),
143 'list' => array('#f2f6fa', '#2a5a8a', '#c8d8ea'),
144 'menu' => array('#f2faf4', '#2a6a3a', '#c8e8d0'),
145 'content' => array('#f4f6fa', '#3a4a7a', '#d0d8ea'),
146 'media' => array('#faf4f8', '#7a3a6a', '#e8d0e0'),
147 'api' => array('#f6f4fa', '#5a3a8a', '#ddd0ea'),
148 'default' => array('#f5f5f5', '#555555', '#dddddd'),
149 );
150 return $palettes[$type] ?? $palettes['default'];
151}
152
153function mod_svg_content($modul, $run1, $run2, $params) {
154 $type = mod_visual_type($run1, $run2);
155 list($bg, $accent, $border) = mod_palette($type);
156 $marker = '[modul=' . $modul . ']' . $params . '[/modul]';
157 $title = $modul;
158 $paramLine = $params !== '' ? $params : '(Standard-Aufruf)';
159 $run2Line = $run2 !== '' ? ('dbx_run2=' . $run2) : '';
160
161 $shapes = '';
162 if ($type === 'form') {
163 $shapes = '
164 <rect x="40" y="50" width="280" height="14" fill="' . $accent . '" rx="3" opacity="0.35"/>
165 <rect x="40" y="78" width="280" height="28" fill="#fff" stroke="' . $border . '" rx="4"/>
166 <rect x="40" y="118" width="280" height="28" fill="#fff" stroke="' . $border . '" rx="4"/>
167 <rect x="40" y="158" width="100" height="26" fill="' . $accent . '" rx="4"/>';
168 } elseif ($type === 'list') {
169 $shapes = '
170 <rect x="40" y="52" width="300" height="22" fill="#fff" stroke="' . $border . '" rx="3"/>
171 <rect x="40" y="82" width="300" height="22" fill="#fff" stroke="' . $border . '" rx="3"/>
172 <rect x="40" y="112" width="300" height="22" fill="#fff" stroke="' . $border . '" rx="3"/>
173 <rect x="40" y="142" width="300" height="22" fill="#fff" stroke="' . $border . '" rx="3"/>';
174 } elseif ($type === 'menu') {
175 $shapes = '
176 <rect x="40" y="60" width="70" height="24" fill="' . $accent . '" rx="4" opacity="0.8"/>
177 <rect x="120" y="60" width="70" height="24" fill="' . $accent . '" rx="4" opacity="0.55"/>
178 <rect x="200" y="60" width="70" height="24" fill="' . $accent . '" rx="4" opacity="0.35"/>
179 <rect x="40" y="110" width="320" height="60" fill="#fff" stroke="' . $border . '" rx="6"/>';
180 } elseif ($type === 'media') {
181 $shapes = '
182 <rect x="60" y="55" width="120" height="90" fill="#fff" stroke="' . $border . '" rx="6"/>
183 <circle cx="110" cy="90" r="18" fill="' . $accent . '" opacity="0.4"/>
184 <polygon points="180,130 220,70 260,130" fill="' . $accent . '" opacity="0.35"/>';
185 } else {
186 $shapes = '
187 <rect x="40" y="55" width="320" height="110" fill="#fff" stroke="' . $border . '" rx="6"/>
188 <rect x="56" y="72" width="180" height="12" fill="' . $accent . '" rx="2" opacity="0.5"/>
189 <rect x="56" y="94" width="260" height="10" fill="' . $accent . '" rx="2" opacity="0.25"/>
190 <rect x="56" y="112" width="220" height="10" fill="' . $accent . '" rx="2" opacity="0.25"/>';
191 }
192
193 $esc = function ($s) {
194 return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8');
195 };
196
197 return '<?xml version="1.0" encoding="UTF-8"?>
198<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 200" role="img" aria-label="' . $esc($modul . ' ' . $run1) . '">
199 <rect width="800" height="200" fill="' . $bg . '" stroke="' . $border . '" stroke-width="2" rx="8"/>
200 ' . $shapes . '
201 <text x="420" y="58" font-family="Segoe UI,Arial,sans-serif" font-size="22" font-weight="700" fill="' . $accent . '">' . $esc($title) . '</text>
202 <text x="420" y="88" font-family="Consolas,monospace" font-size="14" fill="#333">dbx_run1=' . $esc($run1) . '</text>
203 ' . ($run2Line !== '' ? '<text x="420" y="112" font-family="Consolas,monospace" font-size="14" fill="#333">' . $esc($run2Line) . '</text>' : '') . '
204 <text x="420" y="150" font-family="Consolas,monospace" font-size="11" fill="#666">' . $esc($paramLine) . '</text>
205 <text x="400" y="182" text-anchor="middle" font-family="Consolas,monospace" font-size="10" fill="#888">' . $esc($marker) . '</text>
206</svg>
207';
208}
209
210function mod_filename($modul, $run1, $run2) {
211 $name = $modul . '_' . $run1;
212 if ($run2 !== '') $name .= '_' . $run2;
213 return $name . '.svg';
214}
215
216function mod_build_params($run1, $run2) {
217 $params = array();
218 if ($run1 !== '') $params[] = 'dbx_run1=' . rawurlencode($run1);
219 if ($run2 !== '') $params[] = 'dbx_run2=' . rawurlencode($run2);
220 return implode('&', $params);
221}
222
225
226foreach (glob($modulesDir . '*', GLOB_ONLYDIR) ?: array() as $path) {
227 $modul = basename(str_replace('\\', '/', $path));
228 if (!preg_match('/^[A-Za-z][A-Za-z0-9_]*$/', $modul)) continue;
229 if (!is_file($path . DIRECTORY_SEPARATOR . $modul . '.class.php')) continue;
230
231 $scan = mod_scan_runs($modulesDir, $modul);
232 $specs = mod_specs_for_module($modulesDir, $modul, $scan);
233 $outDir = $path . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . 'mod' . DIRECTORY_SEPARATOR;
234 if (!is_dir($outDir) && !mkdir($outDir, 0775, true) && !is_dir($outDir)) {
235 fwrite(STDERR, "Cannot create dir: $outDir\n");
236 continue;
237 }
238
239 foreach ($specs as $spec) {
240 list($run1, $run2) = $spec;
241 $file = $outDir . mod_filename($modul, $run1, $run2);
242 if (is_file($file)) {
243 $skipped++;
244 continue;
245 }
246 $params = mod_build_params($run1, $run2);
247 $svg = mod_svg_content($modul, $run1, $run2, $params);
248 file_put_contents($file, $svg);
249 $created++;
250 echo "created: $modul / " . basename($file) . "\n";
251 }
252}
253
254echo "Done. Created: $created, skipped (exists): $skipped\n";
mod_class_files($modulesDir, $modul)
mod_specs_for_module($modulesDir, $modul, $scan)
mod_svg_content($modul, $run1, $run2, $params)
mod_run2_variants($modul, $run1)
mod_is_api_action($run1)
mod_scan_runs($modulesDir, $modul)
if(PHP_SAPI !=='cli') $modulesDir
Erzeugt Platzhalter-SVGs in dbx/modules/{modul}/tpl/mod/ Dateiname: {Modul}_{dbx_run1}...
mod_visual_type($run1, $run2)
mod_filename($modul, $run1, $run2)
mod_build_params($run1, $run2)
exit
Definition index.php:532