dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxInterpreter.class.php
Go to the documentation of this file.
1<?php
6
23
28 private function is_template_editor_context() {
29 if ((int)dbx()->get_system_var('dbx_editor', 0, 'int') > 0) {
30 return true;
31 }
32
33 if ((string)dbx()->get_system_var('dbx_page', '') === '_tpledit') {
34 return true;
35 }
36
37 $modul = (string)dbx()->get_system_var('dbx_modul', '');
38 $run1 = (string)dbx()->get_system_var('dbx_run1', '');
39
40 return $modul === 'dbxAdmin' && in_array($run1, array('_edittpl', '_edittpl_file'), true);
41 }
42
49 public function run($content) {
50 //return $content;
51
52 if ($this->is_template_editor_context()) {
53 return $content;
54 }
55
56 //dbx_debug("#RUN-INTERPRETER#");
57
58 $f1=''; $f2=''; $modul=''; $parameter='';
59
60
61
62 for ($a=1; $a< 512; $a++) { // break 4
63 $do=false;
64
65
66
67 // preg_match_all("'[html](.*?)[/html]'si", $content, $match);
68 // preg_match_all("'<p class=\"review\">(.*?)</p>'si", $source, $match);
69 // foreach($match[1] as $norep) {
70 // $key=dbx()->norep($norep);
71 // $rep="[html]".$norep."[/html]";
72 // $content=(str_replace($rep,$key,$content));
73 // }
74 // // - - - - -
75
76 $patterns = "/\‍[modul=([^\‍[]*)\‍]([^\‍[]*)\‍[\/modul\‍]/i";
77 preg_match ($patterns, $content, $matches);
78 $count=count($matches);
79
80 if ($count) {
81 $funki = ($matches[1]);
82 $f1=$matches[1];
83 $f2=$matches[2];
84
85 if ($f1 > "" && $f2 > "") {
86 $modul = $f1;
87 $parameter= $f2;
88
89 $replacements = "ersetzt";
90
91 $replacements = $this->get_modul_content($modul,$parameter);
92 $inc_patterns = "[modul=".$f1."]".$f2."[/modul]";
93
94
95 $pos1 = strpos ($content, $inc_patterns );
96 $lang1 = strlen ($inc_patterns);
97 $lang2 = strlen ($content);
98 $vor = substr ( $content, 0 , $pos1);
99 $nach = substr ( $content, ($pos1+$lang1) , $lang2);
100 $content = $vor.$replacements.$nach;
101
102 $do=true;
103 }
104 }
105 // - - - - -
106 if (!$do) break; // Kill if Dubbel Break needed
107 //echo "<br>Loops=$a";
108 } // Loop a
109
110 //dbx_debug("RETURN",$content);
111 return $content;
112
113 }
114
123 public function run_selected_modules($content, array $modules) {
124 $content = (string)$content;
125 if ($this->is_template_editor_context()) {
126 return $content;
127 }
128
129 if ($content === '' || stripos($content, '[modul=') === false) {
130 return $content;
131 }
132
133 $allowed = array();
134 foreach ($modules as $module) {
135 $module = trim((string)$module);
136 if ($module !== '') {
137 $allowed[strtolower($module)] = 1;
138 }
139 }
140 if (!$allowed) {
141 return $content;
142 }
143
144 $patterns = "/\‍[modul=([^\‍[]*)\‍]([^\‍[]*)\‍[\/modul\‍]/i";
145 for ($a = 1; $a < 512; $a++) {
146 if (!preg_match_all($patterns, $content, $matches, PREG_OFFSET_CAPTURE)) {
147 break;
148 }
149
150 $done = false;
151 foreach ($matches[0] as $idx => $match) {
152 $modul = (string)($matches[1][$idx][0] ?? '');
153 if (!isset($allowed[strtolower($modul)])) {
154 continue;
155 }
156
157 $parameter = (string)($matches[2][$idx][0] ?? '');
158 $replacement = $this->run($this->get_modul_content($modul, $parameter));
159 $pos = (int)$match[1];
160 $len = strlen((string)$match[0]);
161 $content = substr($content, 0, $pos) . $replacement . substr($content, $pos + $len);
162 $done = true;
163 break;
164 }
165
166 if (!$done) {
167 break;
168 }
169 }
170
171 return $content;
172 }
173
174
175
187 private function get_modul_content($modul,$parameter='') {
188 dbx()->timer('run-'.$modul,'P='.$parameter);
189
190 $modul_content=''; $xparameter=''; $action='undef'; $modul_id=0;
191 $protected_modulvars = array();
192
193 $access=dbx()->can_modul($modul);
194 //dbx_debug("###DBX-Interpreter### M=($modul) Param=($parameter) Access=($access)");
195 if ($access) {
196 $oModul = dbx()->get_modul_obj($modul);
197 $modul_id = dbx()->get_system_var('dbx_activ_modul_id');
198 $parameter= trim($parameter);
199 $uid = dbx()->user('id');
200 $part_select = explode ("&", $parameter); // Parameter vom Aufruf
201 if (is_array($part_select)) { // Zur Sicherheit
202 foreach ($part_select as $id => $value) {
203 $pos = strpos($value,"=");
204 $pos2=($pos+1);
205 $paramn = substr($value,0,$pos); //
206 $paramv = substr($value,$pos2);
207 if ($paramv=='?') $paramv=dbx()->get_request_var($paramn,'','parameter+|');
208 if ($paramn=='dbx_run1') $action=$paramv;
209 //$xparameter.= "Parameter($paramn)=($paramv) ";
210 dbx()->set_modul_var($paramn,$paramv);
211
212 if ($paramn > '') {
213 $protected_modulvars[$paramn] = 1;
214 }
215
216 //dbx()->debug("##############Modul=($modul) Par=($paramn) Val=($paramv)");
217 //dbx()->set_system_var($paramn,$paramv);
218 }
219 }
220
221 if (count($protected_modulvars)) {
222 dbx()->set_modul_var('dbx_protected_modulvars',$protected_modulvars);
223 }
224
225 if ($modul) {
226 dbx()->set_system_var('dbx_modul' ,$modul);
227 dbx()->set_system_var('dbx_run1' ,$action);
228 dbx()->set_system_var('dbx_activ_modul' ,$modul);
229 dbx()->set_system_var('dbx_activ_action',$action);
230
231
232 $modul_content=dbx()->run_owner($oModul, 'run', $action);
233
234
235
236 } else {
237 $modul_content="<p class='red'>#undef# Modul=($modul) Action=($action)</p>";
238 }
239 //dbx_debug("Interpreter $modul $action",$modul_content);
240 } else { // no access
241 $uid=dbx()->user();
242 if ($uid > 1) {
243 $oTPL=dbx()->get_system_obj('dbxTPL');
244 $modul_content=$oTPL->get_tpl('dbx|alert-warning',"msg=Sie haben keinen Zugriff auf ($modul)." );
245 }
246 if ($uid == 1) {
247 $master=dbx()->get_system_var('dbx_master_modul',$modul);
248 $perma =dbx()->get_system_var('dbx_permalink','');
249
250 $modul_content='[modul=dbxLogin]dbx_run1=login[/modul]';
251
252 //dbx_debug("#Redir after login=($perma)");
253
254 if ($perma) {
255 dbx()->set_remember_var('dbx_redir_after_login',$perma,'dbx');
256 } else {
257 dbx()->set_remember_var('dbx_redir_after_login',"?dbx_modul=$modul&$parameter",'dbx');
258 }
259 }
260 }
261 $redir=dbx()->get_remember_var('dbx_redir_after_login','','dbx');
262 //dbx_debug("#DBX# Modul=($modul) Param=($parameter) Access=($access) M-id=($modul_id) redirect=($redir)");
263 dbx()->timer('run-'.$modul);
264 return $modul_content;
265 }
266
267
268
269} // Class
Fuehrt eingebettete Modulaufrufe aus und ersetzt sie durch Modul-HTML.
run_selected_modules($content, array $modules)
Ersetzt nur ausgewaehlte Modulmarker.
run($content)
Ersetzt alle Modulmarker im uebergebenen Inhalt.
DBX schema administration.