52 public function run() {
54 $modul =
dbx()->get_system_var(
'dbx_modul');
55 $run1 =
dbx()->get_modul_var(
'dbx_run1',
'dbx');
56 $file =
dbx()->get_modul_var(
'file',
'none',
'*');
58 $ajax =
dbx()->get_system_var(
'dbx_ajax',0,
'int');
59 $xedit =
dbx()->get_system_var(
'dbx_edit',0,
'int');
60 dbx()->set_system_var(
'dbx_edit',0);
65 if (in_array($run1, array(
'save',
'delete',
'rename',
'copy'),
true)) {
66 $mutation = $this->mutation_state();
67 if (!$mutation[
'submitted']) {
72 'Editor-Mutation ohne gueltigen dbxForm-Token abgewiesen',
73 'ip=' . (
string)(
$_SERVER[
'REMOTE_ADDR'] ??
'')
75 $this->json_result(
false,
'security_check_failed', $mutation[
'security']);
88 if (!$this->is_valid_file(
$file)) {
89 return "invalid file";
94 if (!file_exists($full)) {
95 return "file not found ($file)";
98 $txt = file_get_contents($full);
100 $data[
'txt'] =
dbx()->norep(htmlspecialchars($txt, ENT_QUOTES | ENT_SUBSTITUTE,
'UTF-8'));
101 $security = $this->editor_form()->get_security_data();
102 $data[
'security_name'] = htmlspecialchars($security[
'name'], ENT_QUOTES,
'UTF-8');
103 $data[
'security_value'] = htmlspecialchars($security[
'value'], ENT_QUOTES,
'UTF-8');
105 $oTPL =
dbx()->get_system_obj(
'dbxTPL');
106 $content = $oTPL->get_tpl(
'dbxEditor|editor', $data);
113 if (!$this->is_valid_file(
$file)) {
114 $this->json_result(
false,
'invalid_file', $mutation[
'security']);
120 $data =
$_POST[
'content'] ??
'';
122 if (file_put_contents($full, $data) ===
false) {
123 $this->json_result(
false,
'save_failed', $mutation[
'security']);
125 $this->clear_dd_file_cache(
$file);
126 $this->json_result(
true,
'saved', $mutation[
'security']);
129 $content=
"delete ($base) ($file) ajax=($ajax)";
132 if (!$this->is_valid_file(
$file)) {
133 $this->json_result(
false,
'invalid file', $mutation[
'security']);
138 if (!file_exists($full)) {
139 $this->json_result(
false,
'file not found', $mutation[
'security']);
142 if (!unlink($full)) {
143 $this->json_result(
false,
'delete failed', $mutation[
'security']);
146 $this->clear_dd_file_cache(
$file);
147 $this->json_result(
true,
'deleted', $mutation[
'security']);
154 $old =
dbx()->get_modul_var(
'old',
'',
'alphanum+/');
155 $new =
dbx()->get_modul_var(
'new',
'',
'alphanum+/');
157 if (!$this->is_valid_file($old) || !$this->is_valid_file($new)) {
158 $this->json_result(
false,
'invalid file', $mutation[
'security']);
161 $fullOld =
$base.$old;
162 $fullNew =
$base.$new;
164 if (!file_exists($fullOld)) {
165 $this->json_result(
false,
'source not found', $mutation[
'security']);
168 if (file_exists($fullNew)) {
169 $this->json_result(
false,
'target exists', $mutation[
'security']);
172 if (!rename($fullOld, $fullNew)) {
173 $this->json_result(
false,
'rename failed', $mutation[
'security']);
175 $this->clear_dd_file_cache($old);
176 $this->clear_dd_file_cache($new);
177 $this->json_result(
true,
'renamed', $mutation[
'security']);
183 $old =
dbx()->get_modul_var(
'old',
'',
'alphanum+/.');
184 $new =
dbx()->get_modul_var(
'new',
'',
'alphanum+/.');
186 if (!$this->is_valid_file($old) || !$this->is_valid_file($new)) {
187 $this->json_result(
false,
'invalid file', $mutation[
'security']);
190 $fullOld =
$base . $old;
191 $fullNew =
$base . $new;
193 if (!file_exists($fullOld)) {
194 $this->json_result(
false,
'source not found', $mutation[
'security']);
197 if (file_exists($fullNew)) {
198 $this->json_result(
false,
'target exists', $mutation[
'security']);
201 if (!copy($fullOld, $fullNew)) {
202 $this->json_result(
false,
'copy failed', $mutation[
'security']);
205 $this->clear_dd_file_cache($new);
206 $this->json_result(
true,
'copied', $mutation[
'security']);
212 $oTPL=
dbx()->get_system_obj(
'dbxTPL');
213 $msg[
'msg']=
"Modul=($modul) Action=($run1) is undef.";
214 $content=$oTPL->get_tpl(
'dbx|alert-warning',$msg);
216 dbx()->set_system_var(
'dbx_edit',$xedit);