Passed
Push — dev ( 143846...68bc13 )
by Sergey
11:44
created

EntriesController::clearEntryCounter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Flextype\Plugin\Admin\Controllers;
4
5
use Flextype\Component\Filesystem\Filesystem;
0 ignored issues
show
Bug introduced by
The type Flextype\Component\Filesystem\Filesystem was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Flextype\Component\Session\Session;
0 ignored issues
show
Bug introduced by
The type Flextype\Component\Session\Session was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Flextype\Component\Arrays\Arrays;
0 ignored issues
show
Bug introduced by
The type Flextype\Component\Arrays\Arrays was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use function Flextype\Component\I18n\__;
0 ignored issues
show
introduced by
The function Flextype\Component\I18n\__ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
9
use Respect\Validation\Validator as v;
0 ignored issues
show
Bug introduced by
The type Respect\Validation\Validator was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Psr\Http\Message\ResponseInterface as Response;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Psr\Http\Message\ServerRequestInterface as Request;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ServerRequestInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Ramsey\Uuid\Uuid;
0 ignored issues
show
Bug introduced by
The type Ramsey\Uuid\Uuid was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
0 ignored issues
show
Bug introduced by
The type Ramsey\Uuid\Exception\Un...fiedDependencyException was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Flextype\App\Foundation\Container;
0 ignored issues
show
Bug introduced by
The type Flextype\App\Foundation\Container was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
0 ignored issues
show
Bug introduced by
The type Flextype\Plugin\Admin\Controllers\Query was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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/');
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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 = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $entries_collection is dead and can be removed.
Loading history...
102
        $entries_collection = collect($this->entries->fetchCollection($this->getEntryID($query), ['depth' => ['1']]))->orderBy('published_at', 'DESC')->all();
0 ignored issues
show
Bug introduced by
The function collect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
        $entries_collection = /** @scrutinizer ignore-call */ collect($this->entries->fetchCollection($this->getEntryID($query), ['depth' => ['1']]))->orderBy('published_at', 'DESC')->all();
Loading history...
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()) {
0 ignored issues
show
Bug introduced by
The function find was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
            if (/** @scrutinizer ignore-call */ find()->in(PATH['project'] . '/entries/' . $slug)->depth('>=1')->depth('<=2')->hasResults()) {
Loading history...
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'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

127
                                                'title' => /** @scrutinizer ignore-call */ __('admin_entries'),
Loading history...
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(),
0 ignored issues
show
Bug introduced by
The function collect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

168
                            'entries_list' => /** @scrutinizer ignore-call */ collect($this->entries->fetchCollection($this->getEntryID($query)))->orderBy('order_by', 'ASC')->all(),
Loading history...
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'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

178
                                            'title' => /** @scrutinizer ignore-call */ __('admin_entries'),
Loading history...
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['created_by'] = $this->acl->getUserLoggedInUuid();
250
                $data_from_post['published_by'] = $this->acl->getUserLoggedInUuid();
251
                $data_from_post['title']      = $data['title'];
252
                $data_from_post['fieldset']   = $data['fieldset'];
253
                $data_from_post['visibility'] = $data['visibility'];
254
                $data_from_post['routable']   = isset($data['routable']) ? (bool) $data['routable'] : false;
255
256
                // Themes/Templates support for Site Plugin
257
                // We need to check if template for current fieldset is exists
258
                // if template is not exist then `default` template will be used!
259
                if ($this->registry->has('plugins.site')) {
260
                    $template_path = PATH['project'] . '/themes/' . $this->registry->get('plugins.site.settings.theme') . '/templates/' . $data['fieldset'] . '.html';
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
261
                    $template = (Filesystem::has($template_path)) ? $data['fieldset'] : 'default';
262
                    $data_from_post['template']   = $template;
263
                }
264
265
                //foreach ($fieldset['sections'] as $section_name => $section_body) {
266
                //    foreach ($section_body['form']['fields'] as $field => $properties) {
267
268
                // Predefine data values based on fieldset default values
269
                foreach ($fieldset['form']['tabs'] as $form_tab => $form_tab_body) {
270
                    foreach ($form_tab_body['fields'] as $field => $properties) {
271
272
                        // Ingnore fields where property: heading
273
                        if ($properties['type'] == 'heading') {
274
                            continue;
275
                        }
276
277
                        // Get values from $data_from_post
278
                        if (isset($data_from_post[$field])) {
279
                            $value = $data_from_post[$field];
280
281
                        // Get values from fieldsets predefined field values
282
                        } elseif (isset($properties['value'])) {
283
                            $value = $properties['value'];
284
285
                        // or set empty value
286
                        } else {
287
                            $value = '';
288
                        }
289
290
                        $data_from_post_override[$field] = $value;
291
                    }
292
                }
293
294
                // Merge data
295
                if (count($data_from_post_override) > 0) {
296
                    $data_result = array_replace_recursive($data_from_post_override, $data_from_post);
297
                } else {
298
                    $data_result = $data_from_post;
299
                }
300
301
                if ($this->entries->create($id, $data_result)) {
302
                    $this->media_folders->create('entries/' . $id);
303
                    $this->flash->addMessage('success', __('admin_message_entry_created'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

303
                    $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_created'));
Loading history...
304
                } else {
305
                    $this->flash->addMessage('error', __('admin_message_entry_was_not_created'));
306
                }
307
            } else {
308
                $this->flash->addMessage('error', __('admin_message_fieldset_not_found'));
309
            }
310
        } else {
311
            $this->flash->addMessage('error', __('admin_message_entry_was_not_created'));
312
        }
313
314
        if (isset($data['create-and-edit'])) {
315
            return $response->withRedirect($this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=editor');
316
        } else {
317
            return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $parent_entry_id);
318
        }
319
    }
320
321
    /**
322
     * Change entry type
323
     *
324
     * @param Request  $request  PSR7 request
325
     * @param Response $response PSR7 response
326
     *
327
     * @return Response
328
     */
329
    public function type(Request $request, Response $response) : Response
330
    {
331
        // Get Query Params
332
        $query = $request->getQueryParams();
333
334
        // Set Entries ID in parts
335
        if (isset($query['id'])) {
336
            $parts = explode("/", $query['id']);
337
        } else {
338
            $parts = [0 => ''];
339
        }
340
341
        $entry = $this->entries->fetch($this->getEntryID($query));
342
343
        $fieldsets = [];
344
345
        // Get fieldsets files
346
        $_fieldsets = Filesystem::listContents(PATH['project'] . '/fieldsets/');
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
347
348
        // If there is any fieldsets file then go...
349
        if (count($_fieldsets) > 0) {
350
            foreach ($_fieldsets as $fieldset) {
351
                if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'yaml') {
352
                    $fieldset_content = $this->yaml->decode(Filesystem::read($fieldset['path']));
353
                    if (isset($fieldset_content['form']) &&
354
                        isset($fieldset_content['form']['tabs']['main']) &&
355
                        isset($fieldset_content['form']['tabs']['main']['fields']) &&
356
                        isset($fieldset_content['form']['tabs']['main']['fields']['title'])) {
357
                        if (isset($fieldset_content['hide']) && $fieldset_content['hide'] == true) {
358
                            continue;
359
                        }
360
                        $fieldsets[$fieldset['basename']] = $fieldset_content['title'];
361
                    }
362
                }
363
            }
364
        }
365
366
        return $this->twig->render(
367
            $response,
368
            'plugins/admin/templates/content/entries/type.html',
369
            [
370
                            'fieldset' => $entry['fieldset'],
371
                            'fieldsets' => $fieldsets,
372
                            'id' => $this->getEntryID($query),
373
                            'menu_item' => 'entries',
374
                            'parts' => $parts,
375
                            'i' => count($parts),
376
                            'last' => array_pop($parts),
377
                            'links' => [
378
                                'entries' => [
379
                                    'link' => $this->router->pathFor('admin.entries.index'),
380
                                    'title' => __('admin_entries'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

380
                                    'title' => /** @scrutinizer ignore-call */ __('admin_entries'),
Loading history...
381
382
                                ],
383
                                'entries_type' => [
384
                                    'link' => $this->router->pathFor('admin.entries.type') . '?id=' . $this->getEntryID($query),
385
                                    'title' => __('admin_type'),
386
                                    'active' => true
387
                                    ]
388
                                ]
389
                        ]
390
        );
391
    }
392
393
    /**
394
     * Change entry type - process
395
     *
396
     * @param Request  $request  PSR7 request
397
     * @param Response $response PSR7 response
398
     *
399
     * @return Response
400
     */
401
    public function typeProcess(Request $request, Response $response) : Response
402
    {
403
        $post_data = $request->getParsedBody();
404
405
        $id = $post_data['id'];
406
407
        $entry = $this->entries->fetch($id);
408
409
        Arrays::delete($entry, 'slug');
410
        Arrays::delete($entry, 'modified_at');
411
        Arrays::delete($entry, 'created_at');
412
        Arrays::delete($entry, 'published_at');
413
414
        Arrays::delete($post_data, 'csrf_name');
415
        Arrays::delete($post_data, 'csrf_value');
416
        Arrays::delete($post_data, 'save_entry');
417
        Arrays::delete($post_data, 'id');
418
419
        $post_data['created_by'] = $this->acl->getUserLoggedInUuid();
420
        $post_data['published_by'] = $this->acl->getUserLoggedInUuid();
421
422
        $data = array_merge($entry, $post_data);
423
424
        if ($this->entries->update(
425
            $id,
426
            $data
427
        )) {
428
            $this->flash->addMessage('success', __('admin_message_entry_changes_saved'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

428
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_changes_saved'));
Loading history...
429
        } else {
430
            $this->flash->addMessage('error', __('admin_message_entry_was_not_moved'));
431
        }
432
433
        return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . implode('/', array_slice(explode("/", $id), 0, -1)));
434
    }
435
436
    /**
437
     * Move entry
438
     *
439
     * @param Request  $request  PSR7 request
440
     * @param Response $response PSR7 response
441
     *
442
     * @return Response
443
     */
444
    public function move(Request $request, Response $response) : Response
445
    {
446
        // Get Query Params
447
        $query = $request->getQueryParams();
448
449
        // Get Entry from Query Params
450
        $entry_id = $this->getEntryID($query);
451
452
        // Get current Entry ID
453
        $entry_id_current = array_pop(explode("/", $entry_id));
0 ignored issues
show
Bug introduced by
explode('/', $entry_id) cannot be passed to array_pop() as the parameter $array expects a reference. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

453
        $entry_id_current = array_pop(/** @scrutinizer ignore-type */ explode("/", $entry_id));
Loading history...
454
455
        // Fetch entry
456
        $entry = $this->entries->fetch($this->getEntryID($query));
0 ignored issues
show
Unused Code introduced by
The assignment to $entry is dead and can be removed.
Loading history...
457
458
        // Set Entries IDs in parts
459
        if (isset($query['id'])) {
460
            $parts = explode("/", $query['id']);
461
        } else {
462
            $parts = [0 => ''];
463
        }
464
465
        // Get entries list
466
        $entries_list['/'] = '/';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$entries_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $entries_list = array(); before regardless.
Loading history...
467
        foreach ($this->entries->fetch('', ['depth' => '>0', 'order_by' => ['field' => ['slug']]]) as $_entry) {
468
            if ($_entry['slug'] != '') {
469
                $entries_list[$_entry['slug']] = $_entry['slug'];
470
            } else {
471
                $entries_list[$this->registry->get('flextype.entries.main')] = $this->registry->get('flextype.entries.main');
472
            }
473
        }
474
475
        return $this->twig->render(
476
            $response,
477
            'plugins/admin/templates/content/entries/move.html',
478
            [
479
                            'menu_item' => 'entries',
480
                            'entries_list' => $entries_list,
481
                            'entry_id_current' => $entry_id_current,
482
                            'entry_id_path_current' => $entry_id,
483
                            'entry_id_path_parent' => implode('/', array_slice(explode("/", $entry_id), 0, -1)),
484
                            'parts' => $parts,
485
                            'i' => count($parts),
486
                            'last' => array_pop($parts),
487
                            'links' => [
488
                                'entries' => [
489
                                    'link' => $this->router->pathFor('admin.entries.index'),
490
                                    'title' => __('admin_entries'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

490
                                    'title' => /** @scrutinizer ignore-call */ __('admin_entries'),
Loading history...
491
492
                                ],
493
                                'entries_move' => [
494
                                    'link' => $this->router->pathFor('admin.entries.move'),
495
                                    'title' => __('admin_move'),
496
                                    'active' => true
497
                                    ]
498
                                ]
499
                        ]
500
        );
501
    }
502
503
    /**
504
     * Move entry - process
505
     *
506
     * @param Request  $request  PSR7 request
507
     * @param Response $response PSR7 response
508
     *
509
     * @return Response
510
     */
511
    public function moveProcess(Request $request, Response $response)
512
    {
513
        // Get data from POST
514
        $data = $request->getParsedBody();
515
516
        // Set entry id current
517
        $entry_id_current = $data['entry_id_current'];
518
519
        if (!$this->entries->has($data['parent_entry'] . '/' . $entry_id_current)) {
520
            if ($this->entries->rename(
521
                $data['entry_id_path_current'],
522
                $data['parent_entry'] . '/' . $entry_id_current
523
            )) {
524
                $this->media_folders->rename('entries/' . $data['entry_id_path_current'], 'entries/' . $data['parent_entry'] . '/' . $entry_id_current);
525
                $this->clearEntryCounter($data['parent_entry']);
526
                $this->flash->addMessage('success', __('admin_message_entry_moved'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

526
                $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_moved'));
Loading history...
527
            } else {
528
                $this->flash->addMessage('error', __('admin_message_entry_was_not_moved'));
529
            }
530
        } else {
531
            $this->flash->addMessage('error', __('admin_message_entry_was_not_moved'));
532
        }
533
534
        return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . (($data['parent_entry'] == '/') ? '' : $data['parent_entry']));
535
    }
536
537
    /**
538
     * Rename entry
539
     *
540
     * @param Request  $request  PSR7 request
541
     * @param Response $response PSR7 response
542
     *
543
     * @return Response
544
     */
545
    public function rename(Request $request, Response $response) : Response
546
    {
547
        // Get Query Params
548
        $query = $request->getQueryParams();
549
550
        // Set Entries ID in parts
551
        if (isset($query['id'])) {
552
            $parts = explode("/", $query['id']);
553
        } else {
554
            $parts = [0 => ''];
555
        }
556
557
        return $this->twig->render(
558
            $response,
559
            'plugins/admin/templates/content/entries/rename.html',
560
            [
561
                            'name_current' => array_pop(explode("/", $this->getEntryID($query))),
0 ignored issues
show
Bug introduced by
explode('/', $this->getEntryID($query)) cannot be passed to array_pop() as the parameter $array expects a reference. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

561
                            'name_current' => array_pop(/** @scrutinizer ignore-type */ explode("/", $this->getEntryID($query))),
Loading history...
562
                            'entry_path_current' => $this->getEntryID($query),
563
                            'entry_parent' => implode('/', array_slice(explode("/", $this->getEntryID($query)), 0, -1)),
564
                            'menu_item' => 'entries',
565
                            'parts' => $parts,
566
                            'i' => count($parts),
567
                            'last' => array_pop($parts),
568
                            'links' => [
569
                                'entries' => [
570
                                    'link' => $this->router->pathFor('admin.entries.index'),
571
                                    'title' => __('admin_entries'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

571
                                    'title' => /** @scrutinizer ignore-call */ __('admin_entries'),
Loading history...
572
573
                                ],
574
                                'entries_type' => [
575
                                    'link' => $this->router->pathFor('admin.entries.rename') . '?id=' . $this->getEntryID($query),
576
                                    'title' => __('admin_rename'),
577
                                    'active' => true
578
                                    ]
579
                                ]
580
                        ]
581
        );
582
    }
583
584
    /**
585
     * Rename entry - process
586
     *
587
     * @param Request  $request  PSR7 request
588
     * @param Response $response PSR7 response
589
     *
590
     * @return Response
591
     */
592
    public function renameProcess(Request $request, Response $response) : Response
593
    {
594
        $data = $request->getParsedBody();
595
596
        // Set name
597
        if ($this->registry->get('plugins.admin.settings.entries.slugify') == true) {
598
            $name = $this->slugify->slugify($data['name']);
599
        } else {
600
            $name = $data['name'];
601
        }
602
603
        if ($this->entries->rename(
604
            $data['entry_path_current'],
605
            $data['entry_parent'] . '/' . $name)
606
        ) {
607
            $this->media_folders->rename('entries/' . $data['entry_path_current'], 'entries/' . $data['entry_parent'] . '/' . $this->slugify->slugify($data['name']));
608
            $this->clearEntryCounter($data['entry_path_current']);
609
            $this->flash->addMessage('success', __('admin_message_entry_renamed'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

609
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_renamed'));
Loading history...
610
        } else {
611
            $this->flash->addMessage('error', __('admin_message_entry_was_not_renamed'));
612
        }
613
614
        return $response->withRedirect($this->router->pathFor('admin.entries.index') . '?id=' . $data['entry_parent']);
615
    }
616
617
    /**
618
     * Delete entry - process
619
     *
620
     * @param Request  $request  PSR7 request
621
     * @param Response $response PSR7 response
622
     *
623
     * @return Response
624
     */
625
    public function deleteProcess(Request $request, Response $response) : Response
626
    {
627
        $data = $request->getParsedBody();
628
629
        $id = $data['id'];
630
        $id_current = $data['id-current'];
631
632
        if ($this->entries->delete($id)) {
633
634
            $this->media_folders->delete('entries/' . $id);
635
636
            $this->flash->addMessage('success', __('admin_message_entry_deleted'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

636
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_deleted'));
Loading history...
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)) {
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

671
        $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_duplicated'));
Loading history...
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';
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

729
                                'title' => /** @scrutinizer ignore-call */ __('admin_entries'),
Loading history...
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['created_by'] = $this->acl->getUserLoggedInUuid();
866
            $entry['published_by'] = $this->acl->getUserLoggedInUuid();
867
868
            Arrays::delete($entry, 'slug');
869
            Arrays::delete($entry, 'modified_at');
870
871
            // Update entry
872
            if (Filesystem::write(PATH['project'] . '/entries' . '/' . $id . '/entry.md', $this->frontmatter->encode($entry))) {
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
873
                $this->flash->addMessage('success', __('admin_message_entry_changes_saved'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

873
                $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_changes_saved'));
Loading history...
874
            } else {
875
                $this->flash->addMessage('error', __('admin_message_entry_changes_not_saved'));
876
            }
877
        } else {
878
            // Result data to save
879
            $result_data = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $result_data is dead and can be removed.
Loading history...
880
881
            // Data from POST
882
            $data = $request->getParsedBody();
883
884
            // Delete system fields
885
            isset($data['slug'])                  and Arrays::delete($data, 'slug');
886
            isset($data['csrf_value'])            and Arrays::delete($data, 'csrf_value');
887
            isset($data['csrf_name'])             and Arrays::delete($data, 'csrf_name');
888
            isset($data['form-save-action'])      and Arrays::delete($data, 'form-save-action');
889
            isset($data['trumbowyg-icons-path'])  and Arrays::delete($data, 'trumbowyg-icons-path');
890
            isset($data['trumbowyg-locale'])      and Arrays::delete($data, 'trumbowyg-locale');
891
            isset($data['flatpickr-date-format']) and Arrays::delete($data, 'flatpickr-date-format');
892
            isset($data['flatpickr-locale'])      and Arrays::delete($data, 'flatpickr-locale');
893
894
895
            $data['published_by'] = Session::get('uuid');
896
897
            // Fetch entry
898
            $entry = $this->entries->fetch($id);
899
            Arrays::delete($entry, 'slug');
900
            Arrays::delete($entry, 'modified_at');
901
902
            if (isset($data['created_at'])) {
903
                $data['created_at'] = date($this->registry->get('flextype.settings.date_format'), strtotime($data['created_at']));
904
            } else {
905
                $data['created_at'] = date($this->registry->get('flextype.settings.date_format'), $entry['created_at']);
906
            }
907
908
            if (isset($data['published_at'])) {
909
                $data['published_at'] = (string) date($this->registry->get('flextype.settings.date_format'), strtotime($data['published_at']));
910
            } else {
911
                $data['published_at'] = (string) date($this->registry->get('flextype.settings.date_format'), $entry['published_at']);
912
            }
913
914
            if (isset($data['routable'])) {
915
                $data['routable'] = (bool) $data['routable'];
916
            } elseif(isset($entry['routable'])) {
917
                $data['routable'] = (bool) $entry['routable'];
918
            } else {
919
                $data['routable'] = true;
920
            }
921
922
            // Merge entry data with $data
923
            $result_data = array_merge($entry, $data);
924
925
            // Update entry
926
            if ($this->entries->update($id, $result_data)) {
927
                $this->flash->addMessage('success', __('admin_message_entry_changes_saved'));
928
            } else {
929
                $this->flash->addMessage('error', __('admin_message_entry_changes_not_saved'));
930
            }
931
        }
932
933
        return $response->withRedirect($this->router->pathFor('admin.entries.edit') . '?id=' . $id . '&type=' . $type);
934
    }
935
936
    /**
937
     * Delete media file - process
938
     *
939
     * @param Request  $request  PSR7 request
940
     * @param Response $response PSR7 response
941
     *
942
     * @return Response
943
     */
944
    public function deleteMediaFileProcess(Request $request, Response $response) : Response
945
    {
946
        $data = $request->getParsedBody();
947
948
        $entry_id = $data['entry-id'];
949
        $media_id = $data['media-id'];
950
951
        $this->media_files->delete('entries/' . $entry_id . '/' . $media_id);
952
953
        $this->flash->addMessage('success', __('admin_message_entry_file_deleted'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

953
        $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_file_deleted'));
Loading history...
954
955
        return $response->withRedirect($this->router->pathFor('admin.entries.edit') . '?id=' . $entry_id . '&type=media');
956
    }
957
958
    /**
959
     * Upload media file - process
960
     *
961
     * @param Request  $request  PSR7 request
962
     * @param Response $response PSR7 response
963
     *
964
     * @return Response
965
     */
966
    public function uploadMediaFileProcess(Request $request, Response $response) : Response
967
    {
968
        $data = $request->getParsedBody();
969
970
        if ($this->media_files->upload($_FILES['file'], '/entries/' . $data['entry-id'] . '/')) {
971
            $this->flash->addMessage('success', __('admin_message_entry_file_uploaded'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

971
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('admin_message_entry_file_uploaded'));
Loading history...
972
        } else {
973
            $this->flash->addMessage('error', __('admin_message_entry_file_not_uploaded'));
974
        }
975
976
        return $response->withRedirect($this->router->pathFor('admin.entries.edit') . '?id=' . $data['entry-id'] . '&type=media');
977
    }
978
979
    /**
980
     * Get media list
981
     *
982
     * @param string $id Entry ID
983
     * @param bool   $path if true returns with url paths
984
     *
985
     * @return array
986
     */
987
    public function getMediaList(string $id, bool $path = false) : array
988
    {
989
        $base_url = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER))->getBaseUrl();
0 ignored issues
show
Bug introduced by
The type Slim\Http\Uri was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type Slim\Http\Environment was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
990
        $files = [];
991
992
        if (!Filesystem::has(PATH['project'] . '/uploads/entries/' . $id)) {
0 ignored issues
show
Bug introduced by
The constant Flextype\Plugin\Admin\Controllers\PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
993
            Filesystem::createDir(PATH['project'] . '/uploads/entries/' . $id);
994
        }
995
996
        foreach (array_diff(scandir(PATH['project'] . '/uploads/entries/' . $id), ['..', '.']) as $file) {
0 ignored issues
show
Bug introduced by
It seems like scandir(Flextype\Plugin\...ploads/entries/' . $id) can also be of type false; however, parameter $array1 of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

996
        foreach (array_diff(/** @scrutinizer ignore-type */ scandir(PATH['project'] . '/uploads/entries/' . $id), ['..', '.']) as $file) {
Loading history...
997
            if (strpos($this->registry->get('plugins.admin.settings.entries.media.accept_file_types'), $file_ext = substr(strrchr($file, '.'), 1)) !== false) {
998
                if (strpos($file, strtolower($file_ext), 1)) {
999
                    if ($file !== 'entry.md') {
1000
                        if ($path) {
1001
                            $files[$base_url . '/' . $id . '/' . $file] = $base_url . '/' . $id . '/' . $file;
1002
                        } else {
1003
                            $files[$file] = $file;
1004
                        }
1005
                    }
1006
                }
1007
            }
1008
        }
1009
        return $files;
1010
    }
1011
1012
}
1013