GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

contentBlueprintsPages::__viewEdit()   F
last analyzed

Complexity

Conditions 42
Paths > 20000

Size

Total Lines 319
Code Lines 188

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 42
eloc 188
nc 6912000
nop 0
dl 0
loc 319
rs 0
c 2
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @package content
5
 */
6
7
/**
8
 * Developers can create new Frontend pages from this class. It provides
9
 * an index view of all the pages in this Symphony install as well as the
10
 * forms for the creation/editing of a Page
11
 */
12
13
class contentBlueprintsPages extends AdministrationPage
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
14
{
15
    public $_errors = array();
16
    protected $_hilights = array();
17
18
    public function insertBreadcrumbsUsingPageIdentifier($page_id, $preserve_last = true)
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$preserve_last" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$preserve_last"; expected 0 but found 1
Loading history...
19
    {
20
        if ($page_id == 0) {
21
            return $this->insertBreadcrumbs(
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->insertBreadcrumbs...'/blueprints/pages/'))) targeting AdministrationPage::insertBreadcrumbs() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
22
                array(Widget::Anchor(__('Pages'), SYMPHONY_URL . '/blueprints/pages/'))
0 ignored issues
show
Bug introduced by
The constant SYMPHONY_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
23
            );
24
        }
25
26
        $pages = PageManager::resolvePage($page_id, 'handle');
27
28
        foreach ($pages as &$page) {
29
            // If we are viewing the Page Editor, the Breadcrumbs should link
30
            // to the parent's Page Editor.
31
            if ($this->_context[0] == 'edit') {
32
                $page = Widget::Anchor(
33
                    General::sanitize(PageManager::fetchTitleFromHandle($page)),
34
                    SYMPHONY_URL . '/blueprints/pages/edit/' . PageManager::fetchIDFromHandle($page) . '/'
35
                );
36
37
                // If the pages index is nested, the Breadcrumb should link to the
38
                // Pages Index filtered by parent
39
            } elseif (Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes') {
40
                $page = Widget::Anchor(
41
                    General::sanitize(PageManager::fetchTitleFromHandle($page)),
42
                    SYMPHONY_URL . '/blueprints/pages/?parent=' . PageManager::fetchIDFromHandle($page)
43
                );
44
45
                // If there is no nesting on the Pages Index, the breadcrumb is
46
                // not a link, just plain text
47
            } else {
48
                $page = new XMLElement('span', General::sanitize(PageManager::fetchTitleFromHandle($page)));
49
            }
50
        }
51
52
        if (!$preserve_last) {
53
            array_pop($pages);
54
        }
55
56
        $this->insertBreadcrumbs(array_merge(
57
            array(Widget::Anchor(__('Pages'), SYMPHONY_URL . '/blueprints/pages/')),
58
            $pages
59
        ));
60
    }
61
62
    public function __viewIndex()
63
    {
64
        $this->setPageType('table');
65
        $this->setTitle(__('%1$s &ndash; %2$s', array(__('Pages'), __('Symphony'))));
66
67
        $nesting = Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes';
68
69
        if ($nesting && isset($_GET['parent']) && is_numeric($_GET['parent'])) {
70
            $parent = PageManager::fetchPageByID((int)$_GET['parent'], array('title', 'id'));
71
        }
72
73
        $this->appendSubheading(
74
            isset($parent)
75
                ? General::sanitize($parent['title'])
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement must be declared on a single line
Loading history...
76
                : __('Pages'),
77
            Widget::Anchor(
78
                __('Create New'),
79
                Administration::instance()->getCurrentPageURL() . 'new/' . ($nesting && isset($parent) ? "?parent={$parent['id']}" : null),
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $parent instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
80
                __('Create a new page'),
81
                'create button',
82
                null,
83
                array('accesskey' => 'c')
84
            )
85
        );
86
87
        if (isset($parent)) {
88
            $this->insertBreadcrumbsUsingPageIdentifier($parent['id'], false);
89
        }
90
91
        $aTableHead = array(
92
            array(__('Name'), 'col'),
93
            array(__('Template'), 'col'),
94
            array('<abbr title="' . __('Universal Resource Locator') . '">' . __('URL') . '</abbr>', 'col'),
95
            array(__('Parameters'), 'col'),
96
            array(__('Type'), 'col')
97
        );
98
        $aTableBody = array();
99
100
        if ($nesting) {
101
            $aTableHead[] = array(__('Children'), 'col');
102
            $where = array(
103
                'parent ' . (isset($parent) ? " = {$parent['id']} " : ' IS NULL ')
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $parent instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
104
            );
105
        } else {
106
            $where = array();
107
        }
108
109
        $pages = PageManager::fetch(true, array('*'), $where);
110
111
        if (!is_array($pages) || empty($pages)) {
0 ignored issues
show
introduced by
The condition is_array($pages) is always true.
Loading history...
112
            $aTableBody = array(Widget::TableRow(array(
113
                Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead))
114
            ), 'odd'));
115
        } else {
116
            foreach ($pages as $page) {
117
                $class = array();
118
119
                $page_title = ($nesting ? $page['title'] : PageManager::resolvePageTitle($page['id']));
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
120
                $page_url = URL . '/' . PageManager::resolvePagePath($page['id']) . '/';
0 ignored issues
show
Bug introduced by
The constant URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
121
                $page_edit_url = Administration::instance()->getCurrentPageURL() . 'edit/' . $page['id'] . '/';
122
                $page_template = PageManager::createFilePath($page['path'], $page['handle']);
123
124
                $col_title = Widget::TableData(
125
                    Widget::Anchor(General::sanitize($page_title), $page_edit_url, $page['handle'])
126
                );
127
                $col_title->appendChild(
128
                    Widget::Label(
129
                        __('Select Page %s', [General::sanitize($page_title)]),
130
                        null,
131
                        'accessible',
132
                        null,
133
                        ['for' => 'page-' . $page['id']]
134
                    )
135
                );
136
                $col_title->appendChild(Widget::Input('items['.$page['id'].']', 'on', 'checkbox', array(
137
                    'id' => 'page-' . $page['id']
138
                )));
139
140
                $col_template = Widget::TableData($page_template . '.xsl');
141
142
                $col_url = Widget::TableData(Widget::Anchor($page_url, $page_url));
143
144
                if ($page['params']) {
145
                    $col_params = Widget::TableData(trim(General::sanitize($page['params']), '/'));
146
                } else {
147
                    $col_params = Widget::TableData(__('None'), 'inactive');
148
                }
149
150
                if (!empty($page['type'])) {
151
                    $col_types = Widget::TableData(implode(', ', array_map(['General', 'sanitize'], $page['type'])));
152
                } else {
153
                    $col_types = Widget::TableData(__('None'), 'inactive');
154
                }
155
156
                if (in_array($page['id'], $this->_hilights)) {
157
                    $class[] = 'failed';
158
                }
159
160
                $columns = array($col_title, $col_template, $col_url, $col_params, $col_types);
161
162
                if ($nesting) {
163
                    if (PageManager::hasChildPages($page['id'])) {
164
                        $col_children = Widget::TableData(
165
                            Widget::Anchor(PageManager::getChildPagesCount($page['id']) . ' &rarr;',
166
                            SYMPHONY_URL . '/blueprints/pages/?parent=' . $page['id'])
0 ignored issues
show
Bug introduced by
The constant SYMPHONY_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
167
                        );
168
                    } else {
169
                        $col_children = Widget::TableData(__('None'), 'inactive');
170
                    }
171
172
                    $columns[] = $col_children;
173
                }
174
175
                $aTableBody[] = Widget::TableRow(
176
                    $columns,
177
                    implode(' ', $class)
178
                );
179
            }
180
        }
181
182
        $table = Widget::Table(
183
            Widget::TableHead($aTableHead), null,
184
            Widget::TableBody($aTableBody), 'orderable selectable',
185
            null, array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive')
186
        );
187
188
        $this->Form->appendChild($table);
189
190
        $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array(
191
            'id' => 'version'
192
        ));
193
        $this->Form->appendChild($version);
194
195
        $tableActions = new XMLElement('div');
196
        $tableActions->setAttribute('class', 'actions');
197
198
        $options = array(
199
            array(null, false, __('With Selected...')),
200
            array('delete', false, __('Delete'), 'confirm', null, array(
201
                'data-message' => __('Are you sure you want to delete the selected pages?')
202
            ))
203
        );
204
205
        /**
206
         * Allows an extension to modify the existing options for this page's
207
         * With Selected menu. If the `$options` parameter is an empty array,
208
         * the 'With Selected' menu will not be rendered.
209
         *
210
         * @delegate AddCustomActions
211
         * @since Symphony 2.3.2
212
         * @param string $context
213
         * '/blueprints/pages/'
214
         * @param array $options
215
         *  An array of arrays, where each child array represents an option
216
         *  in the With Selected menu. Options should follow the same format
217
         *  expected by `Widget::__SelectBuildOption`. Passed by reference.
218
         */
219
        Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/blueprints/pages/', array(
220
            'options' => &$options
221
        ));
222
223
        if (!empty($options)) {
224
            $tableActions->appendChild(Widget::Apply($options));
225
            $this->Form->appendChild($tableActions);
226
        }
227
    }
228
229
    public function __viewNew()
230
    {
231
        $this->__viewEdit();
232
    }
233
234
    public function __viewEdit()
235
    {
236
        $this->setPageType('form');
237
        $fields = array("title"=>null, "handle"=>null, "parent"=>null, "params"=>null, "type"=>null, "data_sources"=>null);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal title does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal handle does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal parent does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal params does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal type does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal data_sources does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
238
        $existing = $fields;
239
        $canonical_link = '/blueprints/pages/';
240
        $nesting = (Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes');
241
242
        // Verify page exists:
243
        if ($this->_context[0] === 'edit') {
244
            if (!$page_id = (int)$this->_context[1]) {
245
                redirect(SYMPHONY_URL . '/blueprints/pages/');
0 ignored issues
show
Bug introduced by
The constant SYMPHONY_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
246
            }
247
248
            $existing = PageManager::fetchPageByID($page_id);
249
            $canonical_link .= 'edit/' . $page_id . '/';
250
251
            if (!$existing) {
252
                Administration::instance()->errorPageNotFound();
253
            } else {
254
                $existing['type'] = PageManager::fetchPageTypes($page_id);
255
            }
256
        } else {
257
            $canonical_link .= 'new/';
258
        }
259
260
        // Status message:
261
        if (isset($this->_context[2])) {
262
            $flag = $this->_context[2];
263
            $parent_link_suffix = $message = '';
264
            $time = Widget::Time();
265
266
            if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) {
267
                $parent_link_suffix = "?parent=" . $_REQUEST['parent'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ?parent= does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
268
            } elseif ($nesting && isset($existing) && !is_null($existing['parent'])) {
269
                $parent_link_suffix = '?parent=' . $existing['parent'];
270
            }
271
272
            switch ($flag) {
273
                case 'saved':
274
                    $message = __('Page updated at %s.', array($time->generate()));
275
                    break;
276
                case 'created':
277
                    $message = __('Page created at %s.', array($time->generate()));
278
            }
279
280
            $this->pageAlert(
281
                $message
282
                . ' <a href="' . SYMPHONY_URL . '/blueprints/pages/new/' . $parent_link_suffix . '" accesskey="c">'
283
                . __('Create another?')
284
                . '</a> <a href="' . SYMPHONY_URL . '/blueprints/pages/" accesskey="a">'
285
                . __('View all Pages')
286
                . '</a>',
287
                Alert::SUCCESS
288
            );
289
        }
290
291
        // Find values:
292
        if (isset($_POST['fields'])) {
293
            $fields = $_POST['fields'];
294
        } elseif ($this->_context[0] == 'edit') {
295
            $fields = $existing;
296
297
            if (!is_null($fields['type'])) {
298
                $fields['type'] = implode(', ', $fields['type']);
299
            }
300
301
            $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY);
302
            $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY);
303
        } elseif (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) {
304
            $fields['parent'] = $_REQUEST['parent'];
305
            $canonical_link .= '?parent=' . urlencode($_REQUEST['parent']);
306
        }
307
308
        $title = $fields['title'];
309
310
        if (trim($title) == '') {
311
            $title = $existing['title'];
312
        }
313
314
        $this->setTitle(
315
            __(
316
                $title
317
                    ? '%1$s &ndash; %2$s &ndash; %3$s'
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement must be declared on a single line
Loading history...
318
                    : '%2$s &ndash; %3$s',
319
                array(General::sanitize($title), __('Pages'), __('Symphony'))
320
            )
321
        );
322
        $this->addElementToHead(new XMLElement('link', null, array(
323
            'rel' => 'canonical',
324
            'href' => SYMPHONY_URL . $canonical_link,
325
        )));
326
327
        $page_id = isset($page_id) ? $page_id : null;
328
329
        if (!empty($title)) {
330
            $page_url = URL . '/' . PageManager::resolvePagePath($page_id) . '/';
0 ignored issues
show
Bug introduced by
The constant URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
331
332
            $this->appendSubheading(
333
                General::sanitize($title),
334
                Widget::Anchor(
335
                    __('View Page'),
336
                    $page_url,
337
                    __('View Page on Frontend'),
338
                    'button',
339
                    null,
340
                    array('target' => '_blank', 'accesskey' => 'v')
341
                )
342
            );
343
        } else {
344
            $this->appendSubheading(!empty($title) ? General::sanitize($title) : __('Untitled'));
345
        }
346
347
        if (isset($page_id)) {
348
            $this->insertBreadcrumbsUsingPageIdentifier($page_id, false);
349
        } else {
350
            $_GET['parent'] = isset($_GET['parent']) ? $_GET['parent'] : null;
351
            $this->insertBreadcrumbsUsingPageIdentifier((int)$_GET['parent'], true);
352
        }
353
354
        // Title --------------------------------------------------------------
355
356
        $fieldset = new XMLElement('fieldset');
357
        $fieldset->setAttribute('class', 'settings');
358
        $fieldset->appendChild(new XMLElement('legend', __('Page Settings')));
359
360
        $label = Widget::Label(__('Name'));
361
        $label->appendChild(Widget::Input(
362
            'fields[title]', General::sanitize($fields['title'])
363
        ));
364
365
        if (isset($this->_errors['title'])) {
366
            $label = Widget::Error($label, $this->_errors['title']);
367
        }
368
369
        $fieldset->appendChild($label);
370
371
        // Handle -------------------------------------------------------------
372
373
        $group = new XMLElement('div');
374
        $group->setAttribute('class', 'two columns');
375
        $column = new XMLElement('div');
376
        $column->setAttribute('class', 'column');
377
378
        $label = Widget::Label(__('Handle'));
379
        $label->appendChild(Widget::Input(
380
            'fields[handle]', $fields['handle']
381
        ));
382
383
        if (isset($this->_errors['handle'])) {
384
            $label = Widget::Error($label, $this->_errors['handle']);
385
        }
386
387
        $column->appendChild($label);
388
389
        // Parent ---------------------------------------------------------
390
391
        $label = Widget::Label(__('Parent Page'));
392
393
        $where = array(
394
            sprintf('id != %d', $page_id)
395
        );
396
        $pages = PageManager::fetch(false, array('id'), $where, 'title ASC');
397
398
        $options = array(
399
            array('', false, '/')
400
        );
401
402
        if (!empty($pages)) {
403
            foreach ($pages as $page) {
404
                $options[] = array(
405
                    $page['id'], $fields['parent'] == $page['id'],
406
                    '/' . PageManager::resolvePagePath($page['id'])
407
                );
408
            }
409
410
            usort($options, array($this, '__compare_pages'));
411
        }
412
413
        $label->appendChild(Widget::Select(
414
            'fields[parent]', $options
415
        ));
416
        $column->appendChild($label);
417
        $group->appendChild($column);
418
419
        // Parameters ---------------------------------------------------------
420
421
        $column = new XMLElement('div');
422
        $column->setAttribute('class', 'column');
423
424
        $label = Widget::Label(__('Parameters'));
425
        $label->appendChild(Widget::Input(
426
            'fields[params]', $fields['params'], 'text', array('placeholder' => 'param1/param2')
427
        ));
428
        $column->appendChild($label);
429
430
        // Type -----------------------------------------------------------
431
432
        $label = Widget::Label(__('Type'));
433
        $label->appendChild(Widget::Input('fields[type]', $fields['type']));
434
435
        if (isset($this->_errors['type'])) {
436
            $label = Widget::Error($label, $this->_errors['type']);
437
        }
438
439
        $column->appendChild($label);
440
441
        $tags = new XMLElement('ul');
442
        $tags->setAttribute('class', 'tags');
443
        $tags->setAttribute('data-interactive', 'data-interactive');
444
445
        $types = PageManager::fetchAvailablePageTypes();
446
447
        foreach ($types as $type) {
448
            $tags->appendChild(new XMLElement('li', General::sanitize($type)));
449
        }
450
451
        $column->appendChild($tags);
452
        $group->appendChild($column);
453
        $fieldset->appendChild($group);
454
        $this->Form->appendChild($fieldset);
455
456
        // Events -------------------------------------------------------------
457
458
        $fieldset = new XMLElement('fieldset');
459
        $fieldset->setAttribute('class', 'settings');
460
        $fieldset->appendChild(new XMLElement('legend', __('Page Resources')));
461
462
        $group = new XMLElement('div');
463
        $group->setAttribute('class', 'two columns');
464
465
        $label = Widget::Label(__('Events'));
466
        $label->setAttribute('class', 'column');
467
468
        $events = ResourceManager::fetch(ResourceManager::RESOURCE_TYPE_EVENT, array(), array(), 'name ASC');
469
        $options = array();
470
471
        if (is_array($events) && !empty($events)) {
472
            if (!isset($fields['events'])) {
473
                $fields['events'] = array();
474
            }
475
476
            foreach ($events as $name => $about) {
477
                $options[] = array(
478
                    $name, in_array($name, $fields['events']), $about['name']
479
                );
480
            }
481
        }
482
483
        $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple')));
484
        $group->appendChild($label);
485
486
        // Data Sources -------------------------------------------------------
487
488
        $label = Widget::Label(__('Data Sources'));
489
        $label->setAttribute('class', 'column');
490
491
        $datasources = ResourceManager::fetch(ResourceManager::RESOURCE_TYPE_DS, array(), array(), 'name ASC');
492
        $options = array();
493
494
        if (is_array($datasources) && !empty($datasources)) {
495
            if (!isset($fields['data_sources'])) {
496
                $fields['data_sources'] = array();
497
            }
498
499
            foreach ($datasources as $name => $about) {
500
                $options[] = array(
501
                    $name, in_array($name, $fields['data_sources']), $about['name']
502
                );
503
            }
504
        }
505
506
        $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple')));
507
        $group->appendChild($label);
508
        $fieldset->appendChild($group);
509
        $this->Form->appendChild($fieldset);
510
511
        // Controls -----------------------------------------------------------
512
513
        /**
514
         * After all Page related Fields have been added to the DOM, just before the
515
         * actions.
516
         *
517
         * @delegate AppendPageContent
518
         * @param string $context
519
         *  '/blueprints/pages/'
520
         * @param XMLElement $form
521
         * @param array $fields
522
         * @param array $errors
523
         */
524
        Symphony::ExtensionManager()->notifyMembers(
525
            'AppendPageContent',
526
            '/blueprints/pages/',
527
            array(
528
                'form'        => &$this->Form,
529
                'fields'    => &$fields,
530
                'errors'    => $this->_errors
531
            )
532
        );
533
534
        $div = new XMLElement('div');
535
        $div->setAttribute('class', 'actions');
536
        $div->appendChild(Widget::Input(
537
            'action[save]',
538
            ($this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page')),
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
539
            'submit',
540
            array('accesskey' => 's')
541
        ));
542
543
        if ($this->_context[0] == 'edit') {
544
            $button = new XMLElement('button', __('Delete'));
545
            $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this page'), 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this page?')));
546
            $div->appendChild($button);
547
        }
548
549
        $this->Form->appendChild($div);
550
551
        if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) {
552
            $this->Form->appendChild(new XMLElement('input', null, array('type' => 'hidden', 'name' => 'parent', 'value' => $_REQUEST['parent'])));
553
        }
554
    }
555
556
    public function __compare_pages($a, $b)
557
    {
558
        return strnatcasecmp($a[2], $b[2]);
559
    }
560
561
    public function __actionIndex()
562
    {
563
        $checked = (is_array($_POST['items'])) ? array_keys($_POST['items']) : null;
564
565
        if (is_array($checked) && !empty($checked)) {
566
            /**
567
             * Extensions can listen for any custom actions that were added
568
             * through `AddCustomPreferenceFieldsets` or `AddCustomActions`
569
             * delegates.
570
             *
571
             * @delegate CustomActions
572
             * @since Symphony 2.3.2
573
             * @param string $context
574
             *  '/blueprints/pages/'
575
             * @param array $checked
576
             *  An array of the selected rows. The value is usually the ID of the
577
             *  the associated object.
578
             */
579
            Symphony::ExtensionManager()->notifyMembers('CustomActions', '/blueprints/pages/', array(
580
                'checked' => $checked
581
            ));
582
583
            switch ($_POST['with-selected']) {
584
                case 'delete':
585
                    $this->__actionDelete($checked, SYMPHONY_URL . '/blueprints/pages/');
0 ignored issues
show
Bug introduced by
The constant SYMPHONY_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
586
                    break;
587
            }
588
        }
589
    }
590
591
    public function __actionTemplate()
592
    {
593
        $filename = $this->_context[1] . '.xsl';
594
        $file_abs = PAGES . '/' . $filename;
0 ignored issues
show
Bug introduced by
The constant PAGES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
595
        $fields = $_POST['fields'];
596
        $this->_errors = array();
597
598
        if (!isset($fields['body']) || trim($fields['body']) == '') {
599
            $this->_errors['body'] = __('This is a required field.');
600
        } elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) {
601
            $this->_errors['body'] = __('This document is not well formed.') . ' ' . __('The following error was returned:') . ' <code>' . $errors[0]['message'] . '</code>';
602
        }
603
604
        if (empty($this->_errors)) {
605
            /**
606
             * Just before a Page Template is about to written to disk
607
             *
608
             * @delegate PageTemplatePreEdit
609
             * @since Symphony 2.2.2
610
             * @param string $context
611
             * '/blueprints/pages/template/'
612
             * @param string $file
613
             *  The path to the Page Template file
614
             * @param string $contents
615
             *  The contents of the `$fields['body']`, passed by reference
616
             */
617
            Symphony::ExtensionManager()->notifyMembers('PageTemplatePreEdit', '/blueprints/pages/template/', array('file' => $file_abs, 'contents' => &$fields['body']));
618
619
            if (!PageManager::writePageFiles($file_abs, $fields['body'])) {
620
                $this->pageAlert(
621
                    __('Page Template could not be written to disk.')
622
                    . ' ' . __('Please check permissions on %s.', array('<code>/workspace/pages</code>')),
623
                    Alert::ERROR
624
                );
625
            } else {
626
                /**
627
                 * Just after a Page Template has been edited and written to disk
628
                 *
629
                 * @delegate PageTemplatePostEdit
630
                 * @since Symphony 2.2.2
631
                 * @param string $context
632
                 * '/blueprints/pages/template/'
633
                 * @param string $file
634
                 *  The path to the Page Template file
635
                 */
636
                Symphony::ExtensionManager()->notifyMembers('PageTemplatePostEdit', '/blueprints/pages/template/', array('file' => $file_abs));
637
638
                redirect(SYMPHONY_URL . '/blueprints/pages/template/' . $this->_context[1] . '/saved/');
0 ignored issues
show
Bug introduced by
The constant SYMPHONY_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
639
            }
640
        }
641
    }
642
643
    public function __actionNew()
644
    {
645
        $this->__actionEdit();
646
    }
647
648
    public function __actionEdit()
649
    {
650
        if ($this->_context[0] != 'new' && !$page_id = (integer)$this->_context[1]) {
651
            redirect(SYMPHONY_URL . '/blueprints/pages/');
0 ignored issues
show
Bug introduced by
The constant SYMPHONY_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
652
        }
653
654
        $parent_link_suffix = null;
655
656
        if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) {
657
            $parent_link_suffix = '?parent=' . $_REQUEST['parent'];
658
        }
659
660
        if (@array_key_exists('delete', $_POST['action'])) {
661
            $this->__actionDelete($page_id, SYMPHONY_URL  . '/blueprints/pages/' . $parent_link_suffix);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $page_id does not seem to be defined for all execution paths leading up to this point.
Loading history...
662
        }
663
664
        if (@array_key_exists('save', $_POST['action'])) {
665
            $fields = $_POST['fields'];
666
            $this->_errors = array();
667
668
            if (!isset($fields['title']) || trim($fields['title']) == '') {
669
                $this->_errors['title'] = __('This is a required field');
670
            }
671
672
            if (trim($fields['type']) != '' && preg_match('/(index|404|403)/i', $fields['type'])) {
673
                $types = preg_split('/\s*,\s*/', strtolower($fields['type']), -1, PREG_SPLIT_NO_EMPTY);
674
675
                if (in_array('index', $types) && PageManager::hasPageTypeBeenUsed($page_id, 'index')) {
0 ignored issues
show
Bug introduced by
It seems like $types can also be of type false; however, parameter $haystack of in_array() 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

675
                if (in_array('index', /** @scrutinizer ignore-type */ $types) && PageManager::hasPageTypeBeenUsed($page_id, 'index')) {
Loading history...
676
                    $this->_errors['type'] = __('An index type page already exists.');
677
                } elseif (in_array('404', $types) && PageManager::hasPageTypeBeenUsed($page_id, '404')) {
678
                    $this->_errors['type'] = __('A 404 type page already exists.');
679
                } elseif (in_array('403', $types) && PageManager::hasPageTypeBeenUsed($page_id, '403')) {
680
                    $this->_errors['type'] = __('A 403 type page already exists.');
681
                }
682
            }
683
684
            if (trim($fields['handle']) == '') {
685
                $fields['handle'] = $fields['title'];
686
            }
687
688
            $fields['handle'] = PageManager::createHandle($fields['handle']);
689
690
            if (empty($fields['handle']) && !isset($this->_errors['title'])) {
691
                $this->_errors['handle'] = __('Please ensure handle contains at least one Latin-based character.');
692
            }
693
694
            /**
695
             * Just after the Symphony validation has run, allows Developers
696
             * to run custom validation logic on a Page
697
             *
698
             * @delegate PagePostValidate
699
             * @since Symphony 2.2
700
             * @param string $context
701
             * '/blueprints/pages/'
702
             * @param array $fields
703
             *  The `$_POST['fields']` array. This should be read-only and not changed
704
             *  through this delegate.
705
             * @param array $errors
706
             *  An associative array of errors, with the key matching a key in the
707
             *  `$fields` array, and the value being the string of the error. `$errors`
708
             *  is passed by reference.
709
             */
710
            Symphony::ExtensionManager()->notifyMembers('PagePostValidate', '/blueprints/pages/', array('fields' => $fields, 'errors' => &$errors));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $errors seems to be never defined.
Loading history...
711
712
            if (empty($this->_errors)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
713
714
                if ($fields['params']) {
715
                    $fields['params'] = trim(preg_replace('@\/{2,}@', '/', $fields['params']), '/');
716
                }
717
718
                // Clean up type list
719
                $types = preg_split('/\s*,\s*/', $fields['type'], -1, PREG_SPLIT_NO_EMPTY);
720
                $types = @array_map('trim', $types);
0 ignored issues
show
Bug introduced by
It seems like $types can also be of type false; however, parameter $arr1 of array_map() 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

720
                $types = @array_map('trim', /** @scrutinizer ignore-type */ $types);
Loading history...
721
                unset($fields['type']);
722
723
                $fields['parent'] = ($fields['parent'] != __('None') ? $fields['parent'] : null);
724
                $fields['data_sources'] = is_array($fields['data_sources']) ? implode(',', $fields['data_sources']) : null;
725
                $fields['events'] = is_array($fields['events']) ? implode(',', $fields['events']) : null;
726
                $fields['path'] = null;
727
728
                if ($fields['parent']) {
729
                    $fields['path'] = PageManager::resolvePagePath((integer)$fields['parent']);
730
                }
731
732
                // Check for duplicates:
733
                $current = PageManager::fetchPageByID($page_id);
734
735
                if (empty($current)) {
736
                    $fields['sortorder'] = PageManager::fetchNextSortOrder();
737
                }
738
739
                $where = array();
740
741
                if (!empty($current)) {
742
                    $where[] = "p.id != {$page_id}";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $page_id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
743
                }
744
745
                $where[] = "p.handle = '" . $fields['handle'] . "'";
746
                $where[] = (is_null($fields['path']))
747
                    ? "p.path IS null"
0 ignored issues
show
Coding Style introduced by
Inline shorthand IF statement must be declared on a single line
Loading history...
Coding Style Comprehensibility introduced by
The string literal p.path IS null does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
748
                    : "p.path = '" . $fields['path'] . "'";
749
                $duplicate = PageManager::fetch(false, array('*'), $where);
750
751
                // If duplicate
752
                if (!empty($duplicate)) {
753
                    $this->_errors['handle'] = __('A page with that handle already exists');
754
755
                    // Create or move files:
756
                } else {
757
                    // New page?
758
                    if (empty($current)) {
759
                        $file_created = PageManager::createPageFiles(
760
                            $fields['path'],
761
                            $fields['handle']
762
                        );
763
764
                        // Existing page, potentially rename files
765
                    } else {
766
                        $file_created = PageManager::createPageFiles(
767
                            $fields['path'],
768
                            $fields['handle'],
769
                            $current['path'],
770
                            $current['handle']
771
                        );
772
                    }
773
774
                    // If the file wasn't created, it's usually permissions related
775
                    if (!$file_created) {
776
                        return $this->pageAlert(
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->pageAlert(__('Pag...code>')), Alert::ERROR) targeting AdministrationPage::pageAlert() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
777
                            __('Page Template could not be written to disk.')
778
                            . ' ' . __('Please check permissions on %s.', array('<code>/workspace/pages</code>')),
779
                            Alert::ERROR
780
                        );
781
                    }
782
783
                    // Insert the new data:
784
                    if (empty($current)) {
785
                        /**
786
                         * Just prior to creating a new Page record in `tbl_pages`, provided
787
                         * with the `$fields` associative array. Use with caution, as no
788
                         * duplicate page checks are run after this delegate has fired
789
                         *
790
                         * @delegate PagePreCreate
791
                         * @since Symphony 2.2
792
                         * @param string $context
793
                         * '/blueprints/pages/'
794
                         * @param array $fields
795
                         *  The `$_POST['fields']` array passed by reference
796
                         */
797
                        Symphony::ExtensionManager()->notifyMembers('PagePreCreate', '/blueprints/pages/', array('fields' => &$fields));
798
799
                        if (!$page_id = PageManager::add($fields)) {
800
                            $this->pageAlert(
801
                                __('Unknown errors occurred while attempting to save.')
802
                                . '<a href="' . SYMPHONY_URL . '/system/log/">'
803
                                . __('Check your activity log')
804
                                . '</a>.',
805
                                Alert::ERROR
806
                            );
807
                        } else {
808
                            /**
809
                             * Just after the creation of a new page in `tbl_pages`
810
                             *
811
                             * @delegate PagePostCreate
812
                             * @since Symphony 2.2
813
                             * @param string $context
814
                             * '/blueprints/pages/'
815
                             * @param integer $page_id
816
                             *  The ID of the newly created Page
817
                             * @param array $fields
818
                             *  An associative array of data that was just saved for this page
819
                             */
820
                            Symphony::ExtensionManager()->notifyMembers('PagePostCreate', '/blueprints/pages/', array('page_id' => $page_id, 'fields' => &$fields));
821
822
                            $redirect = "/blueprints/pages/edit/{$page_id}/created/{$parent_link_suffix}";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $page_id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $parent_link_suffix instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
823
                        }
824
825
                        // Update existing:
826
                    } else {
827
                        /**
828
                         * Just prior to updating a Page record in `tbl_pages`, provided
829
                         * with the `$fields` associative array. Use with caution, as no
830
                         * duplicate page checks are run after this delegate has fired
831
                         *
832
                         * @delegate PagePreEdit
833
                         * @since Symphony 2.2
834
                         * @param string $context
835
                         * '/blueprints/pages/'
836
                         * @param integer $page_id
837
                         *  The ID of the Page that is about to be updated
838
                         * @param array $fields
839
                         *  The `$_POST['fields']` array passed by reference
840
                         */
841
                        Symphony::ExtensionManager()->notifyMembers('PagePreEdit', '/blueprints/pages/', array('page_id' => $page_id, 'fields' => &$fields));
842
843
                        if (!PageManager::edit($page_id, $fields, true)) {
844
                            return $this->pageAlert(
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->pageAlert(__('Unk... '</a>.', Alert::ERROR) targeting AdministrationPage::pageAlert() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
845
                                __('Unknown errors occurred while attempting to save.')
846
                                . '<a href="' . SYMPHONY_URL . '/system/log/">'
847
                                . __('Check your activity log')
848
                                . '</a>.',
849
                                Alert::ERROR
850
                            );
851
                        } else {
852
                            /**
853
                             * Just after updating a page in `tbl_pages`
854
                             *
855
                             * @delegate PagePostEdit
856
                             * @since Symphony 2.2
857
                             * @param string $context
858
                             * '/blueprints/pages/'
859
                             * @param integer $page_id
860
                             *  The ID of the Page that was just updated
861
                             * @param array $fields
862
                             *  An associative array of data that was just saved for this page
863
                             */
864
                            Symphony::ExtensionManager()->notifyMembers('PagePostEdit', '/blueprints/pages/', array('page_id' => $page_id, 'fields' => $fields));
865
866
                            $redirect = "/blueprints/pages/edit/{$page_id}/saved/{$parent_link_suffix}";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $page_id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $parent_link_suffix instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
867
                        }
868
                    }
869
                }
870
871
                // Only proceed if there was no errors saving/creating the page
872
                if (empty($this->_errors)) {
873
                    /**
874
                     * Just before the page's types are saved into `tbl_pages_types`.
875
                     * Use with caution as no further processing is done on the `$types`
876
                     * array to prevent duplicate `$types` from occurring (ie. two index
877
                     * page types). Your logic can use the PageManger::hasPageTypeBeenUsed
878
                     * function to perform this logic.
879
                     *
880
                     * @delegate PageTypePreCreate
881
                     * @since Symphony 2.2
882
                     * @see toolkit.PageManager#hasPageTypeBeenUsed
883
                     * @param string $context
884
                     * '/blueprints/pages/'
885
                     * @param integer $page_id
886
                     *  The ID of the Page that was just created or updated
887
                     * @param array $types
888
                     *  An associative array of the types for this page passed by reference.
889
                     */
890
                    Symphony::ExtensionManager()->notifyMembers('PageTypePreCreate', '/blueprints/pages/', array('page_id' => $page_id, 'types' => &$types));
891
892
                    // Assign page types:
893
                    PageManager::addPageTypesToPage($page_id, $types);
894
895
                    // Find and update children:
896
                    if ($this->_context[0] == 'edit') {
897
                        PageManager::editPageChildren($page_id, $fields['path'] . '/' . $fields['handle']);
898
                    }
899
900
                    if ($redirect) {
901
                        redirect(SYMPHONY_URL . $redirect);
902
                    }
903
                }
904
            }
905
906
            // If there was any errors, either with pre processing or because of a
907
            // duplicate page, return.
908
            if (is_array($this->_errors) && !empty($this->_errors)) {
909
                return $this->pageAlert(
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->pageAlert(__('An ...tails.'), Alert::ERROR) targeting AdministrationPage::pageAlert() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
910
                    __('An error occurred while processing this form. See below for details.'),
911
                    Alert::ERROR
912
                );
913
            }
914
        }
915
    }
916
917
    public function __actionDelete($pages, $redirect)
918
    {
919
        $success = true;
920
        $deleted_page_ids = array();
921
922
        if (!is_array($pages)) {
923
            $pages = array($pages);
924
        }
925
926
        /**
927
         * Prior to deleting Pages
928
         *
929
         * @delegate PagePreDelete
930
         * @since Symphony 2.2
931
         * @param string $context
932
         * '/blueprints/pages/'
933
         * @param array $page_ids
934
         *  An array of Page ID's that are about to be deleted, passed
935
         *  by reference
936
         * @param string $redirect
937
         *  The absolute path that the Developer will be redirected to
938
         *  after the Pages are deleted
939
         */
940
        Symphony::ExtensionManager()->notifyMembers('PagePreDelete', '/blueprints/pages/', array('page_ids' => &$pages, 'redirect' => &$redirect));
941
942
        foreach ($pages as $page_id) {
943
            $page = PageManager::fetchPageByID($page_id);
944
945
            if (empty($page)) {
946
                $success = false;
947
                $this->pageAlert(
948
                    __('Page could not be deleted because it does not exist.'),
949
                    Alert::ERROR
950
                );
951
952
                break;
953
            }
954
955
            if (PageManager::hasChildPages($page_id)) {
956
                $this->_hilights[] = $page['id'];
957
                $success = false;
958
                $this->pageAlert(
959
                    __('Page could not be deleted because it has children.'),
960
                    Alert::ERROR
961
                );
962
963
                continue;
964
            }
965
966
            if (!PageManager::deletePageFiles($page['path'], $page['handle'])) {
967
                $this->_hilights[] = $page['id'];
968
                $success = false;
969
                $this->pageAlert(
970
                    __('One or more pages could not be deleted.')
971
                    . ' ' . __('Please check permissions on %s.', array('<code>/workspace/pages</code>')),
972
                    Alert::ERROR
973
                );
974
975
                continue;
976
            }
977
978
            if (PageManager::delete($page_id, false)) {
979
                $deleted_page_ids[] = $page_id;
980
            }
981
        }
982
983
        if ($success) {
984
            /**
985
             * Fires after all Pages have been deleted
986
             *
987
             * @delegate PagePostDelete
988
             * @since Symphony 2.3
989
             * @param string $context
990
             * '/blueprints/pages/'
991
             * @param array $page_ids
992
             *  The page ID's that were just deleted
993
             */
994
            Symphony::ExtensionManager()->notifyMembers('PagePostDelete', '/blueprints/pages/', array('page_ids' => $deleted_page_ids));
995
            redirect($redirect);
996
        }
997
    }
998
}
999