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