1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flextype\Plugin\Admin\Controllers; |
4
|
|
|
|
5
|
|
|
use Flextype\Component\Filesystem\Filesystem; |
|
|
|
|
6
|
|
|
use Flextype\Component\Session\Session; |
|
|
|
|
7
|
|
|
use Flextype\Component\Arrays\Arrays; |
|
|
|
|
8
|
|
|
use function Flextype\Component\I18n\__; |
|
|
|
|
9
|
|
|
use Respect\Validation\Validator as v; |
|
|
|
|
10
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
|
|
|
11
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
|
|
|
|
12
|
|
|
use Ramsey\Uuid\Uuid; |
|
|
|
|
13
|
|
|
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; |
|
|
|
|
14
|
|
|
use Flextype\App\Foundation\Container; |
|
|
|
|
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @property View $view |
19
|
|
|
* @property Router $router |
20
|
|
|
* @property Registry $registry |
21
|
|
|
* @property Entries $entries |
22
|
|
|
* @property Fieldsets $fieldsets |
23
|
|
|
* @property Flash $flash |
24
|
|
|
* @property Csrf $csrf |
25
|
|
|
* @property Themes $themes |
26
|
|
|
* @property Slugify $slugify |
27
|
|
|
* @property Forms $forms |
28
|
|
|
*/ |
29
|
|
|
class EntriesController extends Container |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get Entry ID |
34
|
|
|
* |
35
|
|
|
* @param array Query |
|
|
|
|
36
|
|
|
*/ |
37
|
|
|
protected function getEntryID($query) |
38
|
|
|
{ |
39
|
|
|
if (isset($query['id'])) { |
40
|
|
|
$_id = $query['id']; |
41
|
|
|
} else { |
42
|
|
|
$_id = ''; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $_id; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Index page |
50
|
|
|
* |
51
|
|
|
* @param Request $request PSR7 request |
52
|
|
|
* @param Response $response PSR7 response |
53
|
|
|
* |
54
|
|
|
* @return Response |
55
|
|
|
*/ |
56
|
|
|
public function index(Request $request, Response $response) : Response |
57
|
|
|
{ |
58
|
|
|
// Get Query Params |
59
|
|
|
$query = $request->getQueryParams(); |
60
|
|
|
|
61
|
|
|
// Set Entries ID in parts |
62
|
|
|
if (isset($query['id'])) { |
63
|
|
|
$parts = explode("/", $query['id']); |
64
|
|
|
} else { |
65
|
|
|
$parts = [0 => '']; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// Init Fieldsets |
69
|
|
|
$fieldsets = []; |
70
|
|
|
|
71
|
|
|
// Get fieldsets files |
72
|
|
|
$fieldsets_list = Filesystem::listContents(PATH['project'] . '/fieldsets/'); |
|
|
|
|
73
|
|
|
|
74
|
|
|
// If there is any fieldset file then go... |
75
|
|
|
if (count($fieldsets_list) > 0) { |
76
|
|
|
foreach ($fieldsets_list as $fieldset) { |
77
|
|
|
if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'yaml') { |
78
|
|
|
$fieldset_content = $this->yaml->decode(Filesystem::read($fieldset['path'])); |
79
|
|
|
if (isset($fieldset_content['form']) && |
80
|
|
|
isset($fieldset_content['form']['tabs']) && |
81
|
|
|
isset($fieldset_content['form']['tabs']['main']['fields']) && |
82
|
|
|
isset($fieldset_content['form']['tabs']['main']['fields']['title'])) { |
83
|
|
|
if (isset($fieldset_content['hide']) && $fieldset_content['hide'] == true) { |
84
|
|
|
continue; |
85
|
|
|
} |
86
|
|
|
$fieldsets[$fieldset['basename']] = $fieldset_content; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$entry_current = $this->entries->fetch($this->getEntryID($query)); |
93
|
|
|
|
94
|
|
|
if (isset($entry_current['items_view'])) { |
95
|
|
|
$items_view = $entry_current['items_view']; |
96
|
|
|
} else { |
97
|
|
|
$items_view = $this->registry->get('plugins.admin.settings.entries.items_view_default'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $this->twig->render( |
101
|
|
|
$response, |
102
|
|
|
'plugins/admin/templates/content/entries/index.html', |
103
|
|
|
[ |
104
|
|
|
'entries_list' => collect($this->entries->fetchCollection($this->getEntryID($query)))->orderBy('published_at', 'DESC')->all(), |
|
|
|
|
105
|
|
|
'id_current' => $this->getEntryID($query), |
106
|
|
|
'entry_current' => $entry_current, |
107
|
|
|
'items_view' => $items_view, |
108
|
|
|
'menu_item' => 'entries', |
109
|
|
|
'fieldsets' => $fieldsets, |
110
|
|
|
'parts' => $parts, |
111
|
|
|
'i' => count($parts), |
112
|
|
|
'last' => array_pop($parts), |
113
|
|
|
'links' => [ |
114
|
|
|
'entries' => [ |
115
|
|
|
'link' => $this->router->pathFor('admin.entries.index'), |
116
|
|
|
'title' => __('admin_entries'), |
|
|
|
|
117
|
|
|
'active' => true |
118
|
|
|
] |
119
|
|
|
], |
120
|
|
|
'buttons' => [ |
121
|
|
|
'create' => [ |
122
|
|
|
'link' => 'javascript:;', |
123
|
|
|
'title' => __('admin_create_new_entry'), |
124
|
|
|
'onclick' => 'event.preventDefault(); selectEntryType("'.$this->getEntryID($query).'", 0);' |
125
|
|
|
] |
126
|
|
|
] |
127
|
|
|
] |
128
|
|
|
); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Create new entry page |
133
|
|
|
* |
134
|
|
|
* @param Request $request PSR7 request |
135
|
|
|
* @param Response $response PSR7 response |
136
|
|
|
* |
137
|
|
|
* @return Response |
138
|
|
|
*/ |
139
|
|
|
public function add(Request $request, Response $response) : Response |
140
|
|
|
{ |
141
|
|
|
// Get Query Params |
142
|
|
|
$query = $request->getQueryParams(); |
143
|
|
|
|
144
|
|
|
// Set Entries ID in parts |
145
|
|
|
if (isset($query['id'])) { |
146
|
|
|
$parts = explode("/", $query['id']); |
147
|
|
|
} else { |
148
|
|
|
$parts = [0 => '']; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
$type = isset($query['type']) ? $query['type']: ''; |
152
|
|
|
|
153
|
|
|
return $this->twig->render( |
154
|
|
|
$response, |
155
|
|
|
'plugins/admin/templates/content/entries/add.html', |
156
|
|
|
[ |
157
|
|
|
'entries_list' => collect($this->entries->fetchCollection($this->getEntryID($query)))->orderBy('order_by', 'ASC')->all(), |
|
|
|
|
158
|
|
|
'menu_item' => 'entries', |
159
|
|
|
'current_id' => $this->getEntryID($query), |
160
|
|
|
'parts' => $parts, |
161
|
|
|
'i' => count($parts), |
162
|
|
|
'last' => array_pop($parts), |
163
|
|
|
'type' => $type, |
164
|
|
|
'links' => [ |
165
|
|
|
'entries' => [ |
166
|
|
|
'link' => $this->router->pathFor('admin.entries.index'), |
167
|
|
|
'title' => __('admin_entries'), |
|
|
|
|
168
|
|
|
|
169
|
|
|
], |
170
|
|
|
'entries_add' => [ |
171
|
|
|
'link' => $this->router->pathFor('admin.entries.add') . '?id=' . $this->getEntryID($query), |
172
|
|
|
'title' => __('admin_create_new_entry'), |
173
|
|
|
'active' => true |
174
|
|
|
] |
175
|
|
|
] |
176
|
|
|
] |
177
|
|
|
); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Select Entry Type - process |
182
|
|
|
* |
183
|
|
|
* @param Request $request PSR7 request |
184
|
|
|
* @param Response $response PSR7 response |
185
|
|
|
* |
186
|
|
|
* @return Response |
187
|
|
|
*/ |
188
|
|
|
public function selectEntryTypeProcess(Request $request, Response $response) : Response |
189
|
|
|
{ |
190
|
|
|
// Get data from POST |
191
|
|
|
$data = $request->getParsedBody(); |
192
|
|
|
|
193
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.add') . '?id=' . $data['id'] . '&type=' . $data['type']); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Create new entry - process |
198
|
|
|
* |
199
|
|
|
* @param Request $request PSR7 request |
200
|
|
|
* @param Response $response PSR7 response |
201
|
|
|
* |
202
|
|
|
* @return Response |
203
|
|
|
*/ |
204
|
|
|
public function addProcess(Request $request, Response $response) : Response |
205
|
|
|
{ |
206
|
|
|
// Get data from POST |
207
|
|
|
$data = $request->getParsedBody(); |
208
|
|
|
|
209
|
|
|
// Set parent Entry ID |
210
|
|
|
if ($data['current_id']) { |
211
|
|
|
$parent_entry_id = $data['current_id']; |
212
|
|
|
} else { |
213
|
|
|
$parent_entry_id = ''; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
// Set new Entry ID using slugify or without it |
217
|
|
|
if ($this->registry->get('plugins.admin.settings.entries.slugify') == true) { |
218
|
|
|
$id = ltrim($parent_entry_id . '/' . $this->slugify->slugify($data['id']), '/'); |
219
|
|
|
} else { |
220
|
|
|
$id = ltrim($parent_entry_id . '/' . $data['id'], '/'); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
// Check if entry exists then try to create it |
224
|
|
|
if (!$this->entries->has($id)) { |
225
|
|
|
|
226
|
|
|
// Check if we have fieldset for this entry |
227
|
|
|
if ($this->fieldsets->has($data['fieldset'])) { |
228
|
|
|
|
229
|
|
|
// Get fieldset |
230
|
|
|
$fieldset = $this->fieldsets->fetch($data['fieldset']); |
231
|
|
|
|
232
|
|
|
// Init entry data |
233
|
|
|
$data_from_post = []; |
234
|
|
|
$data_from_post_override = []; |
235
|
|
|
$data_result = []; |
236
|
|
|
|
237
|
|
|
// Define data values based on POST data |
238
|
|
|
$data_from_post['title'] = $data['title']; |
239
|
|
|
$data_from_post['fieldset'] = $data['fieldset']; |
240
|
|
|
$data_from_post['visibility'] = $data['visibility']; |
241
|
|
|
$data_from_post['routable'] = isset($data['routable']) ? (bool) $data['routable'] : false; |
242
|
|
|
|
243
|
|
|
// Themes/Templates support for Site Plugin |
244
|
|
|
// We need to check if template for current fieldset is exists |
245
|
|
|
// if template is not exist then `default` template will be used! |
246
|
|
|
if ($this->registry->has('plugins.site')) { |
247
|
|
|
$template_path = PATH['project'] . '/themes/' . $this->registry->get('plugins.site.settings.theme') . '/templates/' . $data['fieldset'] . '.html'; |
|
|
|
|
248
|
|
|
$template = (Filesystem::has($template_path)) ? $data['fieldset'] : 'default'; |
249
|
|
|
$data_from_post['template'] = $template; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
//foreach ($fieldset['sections'] as $section_name => $section_body) { |
253
|
|
|
// foreach ($section_body['form']['fields'] as $field => $properties) { |
254
|
|
|
|
255
|
|
|
// Predefine data values based on fieldset default values |
256
|
|
|
foreach ($fieldset['form']['tabs'] as $form_tab => $form_tab_body) { |
257
|
|
|
foreach ($form_tab_body['fields'] as $field => $properties) { |
258
|
|
|
|
259
|
|
|
// Ingnore fields where property: heading |
260
|
|
|
if ($properties['type'] == 'heading') { |
261
|
|
|
continue; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
// Get values from $data_from_post |
265
|
|
|
if (isset($data_from_post[$field])) { |
266
|
|
|
$value = $data_from_post[$field]; |
267
|
|
|
|
268
|
|
|
// Get values from fieldsets predefined field values |
269
|
|
|
} elseif (isset($properties['value'])) { |
270
|
|
|
$value = $properties['value']; |
271
|
|
|
|
272
|
|
|
// or set empty value |
273
|
|
|
} else { |
274
|
|
|
$value = ''; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
$data_from_post_override[$field] = $value; |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
// Merge data |
282
|
|
|
if (count($data_from_post_override) > 0) { |
283
|
|
|
$data_result = array_replace_recursive($data_from_post_override, $data_from_post); |
284
|
|
|
} else { |
285
|
|
|
$data_result = $data_from_post; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
if ($this->entries->create($id, $data_result)) { |
289
|
|
|
$this->media_folders->create('entries/' . $id); |
290
|
|
|
$this->clearEntryCounter($parent_entry_id); |
291
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_created')); |
|
|
|
|
292
|
|
|
} else { |
293
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_was_not_created')); |
294
|
|
|
} |
295
|
|
|
} else { |
296
|
|
|
$this->flash->addMessage('error', __('admin_message_fieldset_not_found')); |
297
|
|
|
} |
298
|
|
|
} else { |
299
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_was_not_created')); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
if (isset($data['create-and-edit'])) { |
303
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=editor'); |
304
|
|
|
} else { |
305
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $parent_entry_id); |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Change entry type |
311
|
|
|
* |
312
|
|
|
* @param Request $request PSR7 request |
313
|
|
|
* @param Response $response PSR7 response |
314
|
|
|
* |
315
|
|
|
* @return Response |
316
|
|
|
*/ |
317
|
|
|
public function type(Request $request, Response $response) : Response |
318
|
|
|
{ |
319
|
|
|
// Get Query Params |
320
|
|
|
$query = $request->getQueryParams(); |
321
|
|
|
|
322
|
|
|
// Set Entries ID in parts |
323
|
|
|
if (isset($query['id'])) { |
324
|
|
|
$parts = explode("/", $query['id']); |
325
|
|
|
} else { |
326
|
|
|
$parts = [0 => '']; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
$entry = $this->entries->fetch($this->getEntryID($query)); |
330
|
|
|
|
331
|
|
|
$fieldsets = []; |
332
|
|
|
|
333
|
|
|
// Get fieldsets files |
334
|
|
|
$_fieldsets = Filesystem::listContents(PATH['project'] . '/fieldsets/'); |
|
|
|
|
335
|
|
|
|
336
|
|
|
// If there is any fieldsets file then go... |
337
|
|
|
if (count($_fieldsets) > 0) { |
338
|
|
|
foreach ($_fieldsets as $fieldset) { |
339
|
|
|
if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'yaml') { |
340
|
|
|
$fieldset_content = $this->yaml->decode(Filesystem::read($fieldset['path'])); |
341
|
|
|
if (isset($fieldset_content['form']) && |
342
|
|
|
isset($fieldset_content['form']['tabs']['main']) && |
343
|
|
|
isset($fieldset_content['form']['tabs']['main']['fields']) && |
344
|
|
|
isset($fieldset_content['form']['tabs']['main']['fields']['title'])) { |
345
|
|
|
if (isset($fieldset_content['hide']) && $fieldset_content['hide'] == true) { |
346
|
|
|
continue; |
347
|
|
|
} |
348
|
|
|
$fieldsets[$fieldset['basename']] = $fieldset_content['title']; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
return $this->twig->render( |
355
|
|
|
$response, |
356
|
|
|
'plugins/admin/templates/content/entries/type.html', |
357
|
|
|
[ |
358
|
|
|
'fieldset' => $entry['fieldset'], |
359
|
|
|
'fieldsets' => $fieldsets, |
360
|
|
|
'id' => $this->getEntryID($query), |
361
|
|
|
'menu_item' => 'entries', |
362
|
|
|
'parts' => $parts, |
363
|
|
|
'i' => count($parts), |
364
|
|
|
'last' => array_pop($parts), |
365
|
|
|
'links' => [ |
366
|
|
|
'entries' => [ |
367
|
|
|
'link' => $this->router->pathFor('admin.entries.index'), |
368
|
|
|
'title' => __('admin_entries'), |
|
|
|
|
369
|
|
|
|
370
|
|
|
], |
371
|
|
|
'entries_type' => [ |
372
|
|
|
'link' => $this->router->pathFor('admin.entries.type') . '?id=' . $this->getEntryID($query), |
373
|
|
|
'title' => __('admin_type'), |
374
|
|
|
'active' => true |
375
|
|
|
] |
376
|
|
|
] |
377
|
|
|
] |
378
|
|
|
); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Change entry type - process |
383
|
|
|
* |
384
|
|
|
* @param Request $request PSR7 request |
385
|
|
|
* @param Response $response PSR7 response |
386
|
|
|
* |
387
|
|
|
* @return Response |
388
|
|
|
*/ |
389
|
|
|
public function typeProcess(Request $request, Response $response) : Response |
390
|
|
|
{ |
391
|
|
|
$post_data = $request->getParsedBody(); |
392
|
|
|
|
393
|
|
|
$id = $post_data['id']; |
394
|
|
|
|
395
|
|
|
$entry = $this->entries->fetch($id); |
396
|
|
|
|
397
|
|
|
Arrays::delete($entry, 'slug'); |
398
|
|
|
Arrays::delete($entry, 'modified_at'); |
399
|
|
|
Arrays::delete($entry, 'created_at'); |
400
|
|
|
Arrays::delete($entry, 'published_at'); |
401
|
|
|
|
402
|
|
|
Arrays::delete($post_data, 'csrf_name'); |
403
|
|
|
Arrays::delete($post_data, 'csrf_value'); |
404
|
|
|
Arrays::delete($post_data, 'save_entry'); |
405
|
|
|
Arrays::delete($post_data, 'id'); |
406
|
|
|
|
407
|
|
|
$post_data['published_by'] = Session::get('uuid'); |
408
|
|
|
|
409
|
|
|
$data = array_merge($entry, $post_data); |
410
|
|
|
|
411
|
|
|
if ($this->entries->update( |
412
|
|
|
$id, |
413
|
|
|
$data |
414
|
|
|
)) { |
415
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_changes_saved')); |
|
|
|
|
416
|
|
|
} else { |
417
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_was_not_moved')); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . implode('/', array_slice(explode("/", $id), 0, -1))); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* Move entry |
425
|
|
|
* |
426
|
|
|
* @param Request $request PSR7 request |
427
|
|
|
* @param Response $response PSR7 response |
428
|
|
|
* |
429
|
|
|
* @return Response |
430
|
|
|
*/ |
431
|
|
|
public function move(Request $request, Response $response) : Response |
432
|
|
|
{ |
433
|
|
|
// Get Query Params |
434
|
|
|
$query = $request->getQueryParams(); |
435
|
|
|
|
436
|
|
|
// Get Entry from Query Params |
437
|
|
|
$entry_id = $this->getEntryID($query); |
438
|
|
|
|
439
|
|
|
// Get current Entry ID |
440
|
|
|
$entry_id_current = array_pop(explode("/", $entry_id)); |
|
|
|
|
441
|
|
|
|
442
|
|
|
// Fetch entry |
443
|
|
|
$entry = $this->entries->fetch($this->getEntryID($query)); |
|
|
|
|
444
|
|
|
|
445
|
|
|
// Set Entries IDs in parts |
446
|
|
|
if (isset($query['id'])) { |
447
|
|
|
$parts = explode("/", $query['id']); |
448
|
|
|
} else { |
449
|
|
|
$parts = [0 => '']; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
// Get entries list |
453
|
|
|
$entries_list['/'] = '/'; |
|
|
|
|
454
|
|
|
foreach ($this->entries->fetch('', ['order_by' => ['field' => ['slug']], 'recursive' => true]) as $_entry) { |
455
|
|
|
if ($_entry['slug'] != '') { |
456
|
|
|
$entries_list[$_entry['slug']] = $_entry['slug']; |
457
|
|
|
} else { |
458
|
|
|
$entries_list[$this->registry->get('flextype.entries.main')] = $this->registry->get('flextype.entries.main'); |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
return $this->twig->render( |
463
|
|
|
$response, |
464
|
|
|
'plugins/admin/templates/content/entries/move.html', |
465
|
|
|
[ |
466
|
|
|
'menu_item' => 'entries', |
467
|
|
|
'entries_list' => $entries_list, |
468
|
|
|
'entry_id_current' => $entry_id_current, |
469
|
|
|
'entry_id_path_current' => $entry_id, |
470
|
|
|
'entry_id_path_parent' => implode('/', array_slice(explode("/", $entry_id), 0, -1)), |
471
|
|
|
'parts' => $parts, |
472
|
|
|
'i' => count($parts), |
473
|
|
|
'last' => array_pop($parts), |
474
|
|
|
'links' => [ |
475
|
|
|
'entries' => [ |
476
|
|
|
'link' => $this->router->pathFor('admin.entries.index'), |
477
|
|
|
'title' => __('admin_entries'), |
|
|
|
|
478
|
|
|
|
479
|
|
|
], |
480
|
|
|
'entries_move' => [ |
481
|
|
|
'link' => $this->router->pathFor('admin.entries.move'), |
482
|
|
|
'title' => __('admin_move'), |
483
|
|
|
'active' => true |
484
|
|
|
] |
485
|
|
|
] |
486
|
|
|
] |
487
|
|
|
); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Move entry - process |
492
|
|
|
* |
493
|
|
|
* @param Request $request PSR7 request |
494
|
|
|
* @param Response $response PSR7 response |
495
|
|
|
* |
496
|
|
|
* @return Response |
497
|
|
|
*/ |
498
|
|
|
public function moveProcess(Request $request, Response $response) |
499
|
|
|
{ |
500
|
|
|
// Get data from POST |
501
|
|
|
$data = $request->getParsedBody(); |
502
|
|
|
|
503
|
|
|
// Set entry id current |
504
|
|
|
$entry_id_current = $data['entry_id_current']; |
505
|
|
|
|
506
|
|
|
if (!$this->entries->has($data['parent_entry'] . '/' . $entry_id_current)) { |
507
|
|
|
if ($this->entries->rename( |
508
|
|
|
$data['entry_id_path_current'], |
509
|
|
|
$data['parent_entry'] . '/' . $entry_id_current |
510
|
|
|
)) { |
511
|
|
|
$this->media_folders->rename('entries/' . $data['entry_id_path_current'], 'entries/' . $data['parent_entry'] . '/' . $entry_id_current); |
512
|
|
|
$this->clearEntryCounter($data['parent_entry']); |
513
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_moved')); |
|
|
|
|
514
|
|
|
} else { |
515
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_was_not_moved')); |
516
|
|
|
} |
517
|
|
|
} else { |
518
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_was_not_moved')); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . (($data['parent_entry'] == '/') ? '' : $data['parent_entry'])); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* Rename entry |
526
|
|
|
* |
527
|
|
|
* @param Request $request PSR7 request |
528
|
|
|
* @param Response $response PSR7 response |
529
|
|
|
* |
530
|
|
|
* @return Response |
531
|
|
|
*/ |
532
|
|
|
public function rename(Request $request, Response $response) : Response |
533
|
|
|
{ |
534
|
|
|
// Get Query Params |
535
|
|
|
$query = $request->getQueryParams(); |
536
|
|
|
|
537
|
|
|
// Set Entries ID in parts |
538
|
|
|
if (isset($query['id'])) { |
539
|
|
|
$parts = explode("/", $query['id']); |
540
|
|
|
} else { |
541
|
|
|
$parts = [0 => '']; |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
return $this->twig->render( |
545
|
|
|
$response, |
546
|
|
|
'plugins/admin/templates/content/entries/rename.html', |
547
|
|
|
[ |
548
|
|
|
'name_current' => array_pop(explode("/", $this->getEntryID($query))), |
|
|
|
|
549
|
|
|
'entry_path_current' => $this->getEntryID($query), |
550
|
|
|
'entry_parent' => implode('/', array_slice(explode("/", $this->getEntryID($query)), 0, -1)), |
551
|
|
|
'menu_item' => 'entries', |
552
|
|
|
'parts' => $parts, |
553
|
|
|
'i' => count($parts), |
554
|
|
|
'last' => array_pop($parts), |
555
|
|
|
'links' => [ |
556
|
|
|
'entries' => [ |
557
|
|
|
'link' => $this->router->pathFor('admin.entries.index'), |
558
|
|
|
'title' => __('admin_entries'), |
|
|
|
|
559
|
|
|
|
560
|
|
|
], |
561
|
|
|
'entries_type' => [ |
562
|
|
|
'link' => $this->router->pathFor('admin.entries.rename') . '?id=' . $this->getEntryID($query), |
563
|
|
|
'title' => __('admin_rename'), |
564
|
|
|
'active' => true |
565
|
|
|
] |
566
|
|
|
] |
567
|
|
|
] |
568
|
|
|
); |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* Rename entry - process |
573
|
|
|
* |
574
|
|
|
* @param Request $request PSR7 request |
575
|
|
|
* @param Response $response PSR7 response |
576
|
|
|
* |
577
|
|
|
* @return Response |
578
|
|
|
*/ |
579
|
|
|
public function renameProcess(Request $request, Response $response) : Response |
580
|
|
|
{ |
581
|
|
|
$data = $request->getParsedBody(); |
582
|
|
|
|
583
|
|
|
// Set name |
584
|
|
|
if ($this->registry->get('plugins.admin.settings.entries.slugify') == true) { |
585
|
|
|
$name = $this->slugify->slugify($data['name']); |
586
|
|
|
} else { |
587
|
|
|
$name = $data['name']; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
if ($this->entries->rename( |
591
|
|
|
$data['entry_path_current'], |
592
|
|
|
$data['entry_parent'] . '/' . $name) |
593
|
|
|
) { |
594
|
|
|
$this->media_folders->rename('entries/' . $data['entry_path_current'], 'entries/' . $data['entry_parent'] . '/' . $this->slugify->slugify($data['name'])); |
595
|
|
|
$this->clearEntryCounter($data['entry_path_current']); |
596
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_renamed')); |
|
|
|
|
597
|
|
|
} else { |
598
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_was_not_renamed')); |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $data['entry_parent']); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* Delete entry - process |
606
|
|
|
* |
607
|
|
|
* @param Request $request PSR7 request |
608
|
|
|
* @param Response $response PSR7 response |
609
|
|
|
* |
610
|
|
|
* @return Response |
611
|
|
|
*/ |
612
|
|
|
public function deleteProcess(Request $request, Response $response) : Response |
613
|
|
|
{ |
614
|
|
|
$data = $request->getParsedBody(); |
615
|
|
|
|
616
|
|
|
$id = $data['id']; |
617
|
|
|
$id_current = $data['id-current']; |
618
|
|
|
|
619
|
|
|
if ($this->entries->delete($id)) { |
620
|
|
|
|
621
|
|
|
$this->media_folders->delete('entries/' . $id); |
622
|
|
|
|
623
|
|
|
$this->clearEntryCounter($id_current); |
624
|
|
|
|
625
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_deleted')); |
|
|
|
|
626
|
|
|
} else { |
627
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_was_not_deleted')); |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $id_current); |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
/** |
634
|
|
|
* Duplicate entry - process |
635
|
|
|
* |
636
|
|
|
* @param Request $request PSR7 request |
637
|
|
|
* @param Response $response PSR7 response |
638
|
|
|
* |
639
|
|
|
* @return Response |
640
|
|
|
*/ |
641
|
|
|
public function duplicateProcess(Request $request, Response $response) : Response |
642
|
|
|
{ |
643
|
|
|
$data = $request->getParsedBody(); |
644
|
|
|
|
645
|
|
|
$id = $data['id']; |
646
|
|
|
$parent_id = implode('/', array_slice(explode("/", $id), 0, -1)); |
647
|
|
|
|
648
|
|
|
$random_date = date("Ymd_His"); |
649
|
|
|
|
650
|
|
|
$this->entries->copy($id, $id . '-duplicate-' . $random_date, true); |
651
|
|
|
|
652
|
|
|
if (Filesystem::has(PATH['project'] . '/uploads' . '/entries/' . $id)) { |
|
|
|
|
653
|
|
|
Filesystem::copy(PATH['project'] . '/uploads' . '/entries/' . $id, PATH['project'] . '/uploads' . '/entries/' . $id . '-duplicate-' . $random_date, true); |
654
|
|
|
} else { |
655
|
|
|
Filesystem::createDir(PATH['project'] . '/uploads' . '/entries/' . $id . '-duplicate-' . $random_date); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
$this->clearEntryCounter($parent_id); |
659
|
|
|
|
660
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_duplicated')); |
|
|
|
|
661
|
|
|
|
662
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $parent_id); |
663
|
|
|
} |
664
|
|
|
|
665
|
|
|
/** |
666
|
|
|
* Edit entry |
667
|
|
|
* |
668
|
|
|
* @param Request $request PSR7 request |
669
|
|
|
* @param Response $response PSR7 response |
670
|
|
|
* |
671
|
|
|
* @return Response |
672
|
|
|
*/ |
673
|
|
|
public function edit(Request $request, Response $response) : Response |
674
|
|
|
{ |
675
|
|
|
// Get Query Params |
676
|
|
|
$query = $request->getQueryParams(); |
677
|
|
|
|
678
|
|
|
// Set Entries ID in parts |
679
|
|
|
if (isset($query['id'])) { |
680
|
|
|
$parts = explode("/", $query['id']); |
681
|
|
|
} else { |
682
|
|
|
$parts = [0 => '']; |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
// Get Entry type |
686
|
|
|
$type = $request->getQueryParams()['type']; |
687
|
|
|
|
688
|
|
|
// Get Entry |
689
|
|
|
$entry = $this->entries->fetch($this->getEntryID($query)); |
690
|
|
|
Arrays::delete($entry, 'slug'); |
691
|
|
|
Arrays::delete($entry, 'modified_at'); |
692
|
|
|
|
693
|
|
|
// Fieldsets for current entry template |
694
|
|
|
$fieldsets_path = PATH['project'] . '/fieldsets/' . (isset($entry['fieldset']) ? $entry['fieldset'] : 'default') . '.yaml'; |
|
|
|
|
695
|
|
|
$fieldsets = $this->yaml->decode(Filesystem::read($fieldsets_path)); |
696
|
|
|
is_null($fieldsets) and $fieldsets = []; |
697
|
|
|
|
698
|
|
|
if ($type == 'source') { |
699
|
|
|
$entry['published_at'] = date($this->registry->get('flextype.settings.date_format'), $entry['published_at']); |
700
|
|
|
$entry['created_at'] = date($this->registry->get('flextype.settings.date_format'), $entry['created_at']); |
701
|
|
|
|
702
|
|
|
return $this->twig->render( |
703
|
|
|
$response, |
704
|
|
|
'plugins/admin/templates/content/entries/source.html', |
705
|
|
|
[ |
706
|
|
|
'parts' => $parts, |
707
|
|
|
'i' => count($parts), |
708
|
|
|
'last' => array_pop($parts), |
709
|
|
|
'id' => $this->getEntryID($query), |
710
|
|
|
'data' => $this->frontmatter->encode($entry), |
711
|
|
|
'type' => $type, |
712
|
|
|
'menu_item' => 'entries', |
713
|
|
|
'links' => [ |
714
|
|
|
'entries' => [ |
715
|
|
|
'link' => $this->router->pathFor('admin.entries.index'), |
716
|
|
|
'title' => __('admin_entries'), |
|
|
|
|
717
|
|
|
|
718
|
|
|
], |
719
|
|
|
'edit_entry' => [ |
720
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query). '&type=editor', |
721
|
|
|
'title' => __('admin_editor'), |
722
|
|
|
|
723
|
|
|
], |
724
|
|
|
'edit_entry_media' => [ |
725
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=media', |
726
|
|
|
'title' => __('admin_media'), |
727
|
|
|
|
728
|
|
|
], |
729
|
|
|
'edit_entry_source' => [ |
730
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=source', |
731
|
|
|
'title' => __('admin_source'), |
732
|
|
|
'active' => true |
733
|
|
|
], |
734
|
|
|
], |
735
|
|
|
'buttons' => [ |
736
|
|
|
'save_entry' => [ |
737
|
|
|
'id' => 'form', |
738
|
|
|
'link' => 'javascript:;', |
739
|
|
|
'title' => __('admin_save'), |
740
|
|
|
'type' => 'action' |
741
|
|
|
], |
742
|
|
|
] |
743
|
|
|
] |
744
|
|
|
); |
745
|
|
|
} elseif ($type == 'media') { |
746
|
|
|
return $this->twig->render( |
747
|
|
|
$response, |
748
|
|
|
'plugins/admin/templates/content/entries/media.html', |
749
|
|
|
[ |
750
|
|
|
'parts' => $parts, |
751
|
|
|
'i' => count($parts), |
752
|
|
|
'last' => array_pop($parts), |
753
|
|
|
'id' => $this->getEntryID($query), |
754
|
|
|
'files' => $this->getMediaList($this->getEntryID($query), true), |
755
|
|
|
'menu_item' => 'entries', |
756
|
|
|
'links' => [ |
757
|
|
|
'entries' => [ |
758
|
|
|
'link' => $this->router->pathFor('admin.entries.index') . '?id=' . implode('/', array_slice(explode("/", $this->getEntryID($query)), 0, -1)), |
759
|
|
|
'title' => __('admin_entries'), |
760
|
|
|
|
761
|
|
|
], |
762
|
|
|
'edit_entry' => [ |
763
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=editor', |
764
|
|
|
'title' => __('admin_editor'), |
765
|
|
|
|
766
|
|
|
], |
767
|
|
|
'edit_entry_media' => [ |
768
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=media', |
769
|
|
|
'title' => __('admin_media'), |
770
|
|
|
'active' => true |
771
|
|
|
], |
772
|
|
|
'edit_entry_source' => [ |
773
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=source', |
774
|
|
|
'title' => __('admin_source'), |
775
|
|
|
], |
776
|
|
|
] |
777
|
|
|
] |
778
|
|
|
); |
779
|
|
|
} else { |
780
|
|
|
|
781
|
|
|
// Merge current entry fieldset with global fildset |
782
|
|
|
if (isset($entry['entry_fieldset'])) { |
783
|
|
|
$form = $this->form->render(array_replace_recursive($fieldsets, $entry['entry_fieldset']), $entry); |
784
|
|
|
} else { |
785
|
|
|
$form = $this->form->render($fieldsets, $entry); |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
return $this->twig->render( |
789
|
|
|
$response, |
790
|
|
|
'plugins/admin/templates/content/entries/edit.html', |
791
|
|
|
[ |
792
|
|
|
'parts' => $parts, |
793
|
|
|
'i' => count($parts), |
794
|
|
|
'last' => array_pop($parts), |
795
|
|
|
'form' => $form, |
796
|
|
|
'menu_item' => 'entries', |
797
|
|
|
'links' => [ |
798
|
|
|
'entries' => [ |
799
|
|
|
'link' => $this->router->pathFor('admin.entries.index') . '?id=' . implode('/', array_slice(explode("/", $this->getEntryID($query)), 0, -1)), |
800
|
|
|
'title' => __('admin_entries') |
801
|
|
|
], |
802
|
|
|
'edit_entry' => [ |
803
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=editor', |
804
|
|
|
'title' => __('admin_editor'), |
805
|
|
|
'active' => true |
806
|
|
|
], |
807
|
|
|
'edit_entry_media' => [ |
808
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=media', |
809
|
|
|
'title' => __('admin_media') |
810
|
|
|
], |
811
|
|
|
'edit_entry_source' => [ |
812
|
|
|
'link' => $this->router->pathFor('admin.entries.edit') . '?id=' . $this->getEntryID($query) . '&type=source', |
813
|
|
|
'title' => __('admin_source') |
814
|
|
|
], |
815
|
|
|
], |
816
|
|
|
'buttons' => [ |
817
|
|
|
'save_entry' => [ |
818
|
|
|
'id' => 'form', |
819
|
|
|
'link' => 'javascript:;', |
820
|
|
|
'title' => __('admin_save'), |
821
|
|
|
'type' => 'action' |
822
|
|
|
], |
823
|
|
|
] |
824
|
|
|
] |
825
|
|
|
); |
826
|
|
|
} |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
/** |
830
|
|
|
* Edit entry process |
831
|
|
|
* |
832
|
|
|
* @param Request $request PSR7 request |
833
|
|
|
* @param Response $response PSR7 response |
834
|
|
|
* |
835
|
|
|
* @return Response |
836
|
|
|
*/ |
837
|
|
|
public function editProcess(Request $request, Response $response) : Response |
838
|
|
|
{ |
839
|
|
|
$query = $request->getQueryParams(); |
840
|
|
|
|
841
|
|
|
// Get Entry ID and TYPE from GET param |
842
|
|
|
$id = $query['id']; |
843
|
|
|
$type = $query['type']; |
844
|
|
|
|
845
|
|
|
if ($type == 'source') { |
846
|
|
|
|
847
|
|
|
// Data from POST |
848
|
|
|
$data = $request->getParsedBody(); |
849
|
|
|
|
850
|
|
|
$entry = $this->frontmatter->decode($data['data']); |
851
|
|
|
|
852
|
|
|
$entry['published_by'] = Session::get('uuid'); |
853
|
|
|
|
854
|
|
|
Arrays::delete($entry, 'slug'); |
855
|
|
|
Arrays::delete($entry, 'modified_at'); |
856
|
|
|
|
857
|
|
|
// Update entry |
858
|
|
|
if (Filesystem::write(PATH['project'] . '/entries' . '/' . $id . '/entry.md', $this->frontmatter->encode($entry))) { |
|
|
|
|
859
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_changes_saved')); |
|
|
|
|
860
|
|
|
} else { |
861
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_changes_not_saved')); |
862
|
|
|
} |
863
|
|
|
} else { |
864
|
|
|
// Result data to save |
865
|
|
|
$result_data = []; |
|
|
|
|
866
|
|
|
|
867
|
|
|
// Data from POST |
868
|
|
|
$data = $request->getParsedBody(); |
869
|
|
|
|
870
|
|
|
// Delete system fields |
871
|
|
|
isset($data['slug']) and Arrays::delete($data, 'slug'); |
872
|
|
|
isset($data['csrf_value']) and Arrays::delete($data, 'csrf_value'); |
873
|
|
|
isset($data['csrf_name']) and Arrays::delete($data, 'csrf_name'); |
874
|
|
|
isset($data['form-save-action']) and Arrays::delete($data, 'form-save-action'); |
875
|
|
|
isset($data['trumbowyg-icons-path']) and Arrays::delete($data, 'trumbowyg-icons-path'); |
876
|
|
|
isset($data['trumbowyg-locale']) and Arrays::delete($data, 'trumbowyg-locale'); |
877
|
|
|
isset($data['flatpickr-date-format']) and Arrays::delete($data, 'flatpickr-date-format'); |
878
|
|
|
isset($data['flatpickr-locale']) and Arrays::delete($data, 'flatpickr-locale'); |
879
|
|
|
|
880
|
|
|
|
881
|
|
|
$data['published_by'] = Session::get('uuid'); |
882
|
|
|
|
883
|
|
|
// Fetch entry |
884
|
|
|
$entry = $this->entries->fetch($id); |
885
|
|
|
Arrays::delete($entry, 'slug'); |
886
|
|
|
Arrays::delete($entry, 'modified_at'); |
887
|
|
|
|
888
|
|
|
if (isset($data['created_at'])) { |
889
|
|
|
$data['created_at'] = date($this->registry->get('flextype.settings.date_format'), strtotime($data['created_at'])); |
890
|
|
|
} else { |
891
|
|
|
$data['created_at'] = date($this->registry->get('flextype.settings.date_format'), $entry['created_at']); |
892
|
|
|
} |
893
|
|
|
|
894
|
|
|
if (isset($data['published_at'])) { |
895
|
|
|
$data['published_at'] = (string) date($this->registry->get('flextype.settings.date_format'), strtotime($data['published_at'])); |
896
|
|
|
} else { |
897
|
|
|
$data['published_at'] = (string) date($this->registry->get('flextype.settings.date_format'), $entry['published_at']); |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
if (isset($data['routable'])) { |
901
|
|
|
$data['routable'] = (bool) $data['routable']; |
902
|
|
|
} elseif(isset($entry['routable'])) { |
903
|
|
|
$data['routable'] = (bool) $entry['routable']; |
904
|
|
|
} else { |
905
|
|
|
$data['routable'] = true; |
906
|
|
|
} |
907
|
|
|
|
908
|
|
|
// Merge entry data with $data |
909
|
|
|
$result_data = array_merge($entry, $data); |
910
|
|
|
|
911
|
|
|
// Update entry |
912
|
|
|
if ($this->entries->update($id, $result_data)) { |
913
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_changes_saved')); |
914
|
|
|
} else { |
915
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_changes_not_saved')); |
916
|
|
|
} |
917
|
|
|
} |
918
|
|
|
|
919
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=' . $type); |
920
|
|
|
} |
921
|
|
|
|
922
|
|
|
/** |
923
|
|
|
* Delete media file - process |
924
|
|
|
* |
925
|
|
|
* @param Request $request PSR7 request |
926
|
|
|
* @param Response $response PSR7 response |
927
|
|
|
* |
928
|
|
|
* @return Response |
929
|
|
|
*/ |
930
|
|
|
public function deleteMediaFileProcess(Request $request, Response $response) : Response |
931
|
|
|
{ |
932
|
|
|
$data = $request->getParsedBody(); |
933
|
|
|
|
934
|
|
|
$entry_id = $data['entry-id']; |
935
|
|
|
$media_id = $data['media-id']; |
936
|
|
|
|
937
|
|
|
$this->media_files->delete('entries/' . $entry_id . '/' . $media_id); |
938
|
|
|
|
939
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_file_deleted')); |
|
|
|
|
940
|
|
|
|
941
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.edit') . '?id=' . $entry_id . '&type=media'); |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
/** |
945
|
|
|
* Upload media file - process |
946
|
|
|
* |
947
|
|
|
* @param Request $request PSR7 request |
948
|
|
|
* @param Response $response PSR7 response |
949
|
|
|
* |
950
|
|
|
* @return Response |
951
|
|
|
*/ |
952
|
|
|
public function uploadMediaFileProcess(Request $request, Response $response) : Response |
953
|
|
|
{ |
954
|
|
|
$data = $request->getParsedBody(); |
955
|
|
|
|
956
|
|
|
if ($this->media_files->upload($_FILES['file'], '/entries/' . $data['entry-id'] . '/')) { |
957
|
|
|
$this->flash->addMessage('success', __('admin_message_entry_file_uploaded')); |
|
|
|
|
958
|
|
|
} else { |
959
|
|
|
$this->flash->addMessage('error', __('admin_message_entry_file_not_uploaded')); |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.edit') . '?id=' . $data['entry-id'] . '&type=media'); |
963
|
|
|
} |
964
|
|
|
|
965
|
|
|
/** |
966
|
|
|
* Get media list |
967
|
|
|
* |
968
|
|
|
* @param string $id Entry ID |
969
|
|
|
* @param bool $path if true returns with url paths |
970
|
|
|
* |
971
|
|
|
* @return array |
972
|
|
|
*/ |
973
|
|
|
public function getMediaList(string $id, bool $path = false) : array |
974
|
|
|
{ |
975
|
|
|
$base_url = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER))->getBaseUrl(); |
|
|
|
|
976
|
|
|
$files = []; |
977
|
|
|
|
978
|
|
|
if (!Filesystem::has(PATH['project'] . '/uploads' . '/entries/' . $id)) { |
|
|
|
|
979
|
|
|
Filesystem::createDir(PATH['project'] . '/uploads' . '/entries/' . $id); |
980
|
|
|
} |
981
|
|
|
|
982
|
|
|
foreach (array_diff(scandir(PATH['project'] . '/uploads' . '/entries/' . $id), ['..', '.']) as $file) { |
|
|
|
|
983
|
|
|
if (strpos($this->registry->get('plugins.admin.settings.entries.media.accept_file_types'), $file_ext = substr(strrchr($file, '.'), 1)) !== false) { |
984
|
|
|
if (strpos($file, strtolower($file_ext), 1)) { |
985
|
|
|
if ($file !== 'entry.md') { |
986
|
|
|
if ($path) { |
987
|
|
|
$files[$base_url . '/' . $id . '/' . $file] = $base_url . '/' . $id . '/' . $file; |
988
|
|
|
} else { |
989
|
|
|
$files[$file] = $file; |
990
|
|
|
} |
991
|
|
|
} |
992
|
|
|
} |
993
|
|
|
} |
994
|
|
|
} |
995
|
|
|
return $files; |
996
|
|
|
} |
997
|
|
|
|
998
|
|
|
/** |
999
|
|
|
* Display view - process |
1000
|
|
|
* |
1001
|
|
|
* @param Request $request PSR7 request |
1002
|
|
|
* @param Response $response PSR7 response |
1003
|
|
|
*/ |
1004
|
|
|
public function displayViewProcess(Request $request, Response $response) : Response |
1005
|
|
|
{ |
1006
|
|
|
// Get POST data |
1007
|
|
|
$post_data = $request->getParsedBody(); |
1008
|
|
|
|
1009
|
|
|
if ($post_data['id'] == '') { |
1010
|
|
|
$data = []; |
|
|
|
|
1011
|
|
|
$admin_plugin_settings = $this->yaml->decode(Filesystem::read(PATH['project'] . '/config/' . '/plugins/admin/settings.yaml')); |
|
|
|
|
1012
|
|
|
$admin_plugin_settings['entries']['items_view_default'] = $post_data['items_view']; |
1013
|
|
|
Filesystem::write(PATH['project'] . '/config/' . '/plugins/admin/settings.yaml', $this->yaml->encode($admin_plugin_settings)); |
1014
|
|
|
} else { |
1015
|
|
|
$this->entries->update($post_data['id'], ['items_view' => $post_data['items_view']]); |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $post_data['id']); |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
/** |
1022
|
|
|
* Clear entry counter |
1023
|
|
|
* |
1024
|
|
|
* @param string $id Entry ID |
1025
|
|
|
*/ |
1026
|
|
|
public function clearEntryCounter($id) : void |
1027
|
|
|
{ |
1028
|
|
|
if ($this->cache->contains($id . '_counter')) { |
1029
|
|
|
$this->cache->delete($id . '_counter'); |
1030
|
|
|
} |
1031
|
|
|
} |
1032
|
|
|
} |
1033
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths