Issues (136)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/PageRowPageExtension.php (12 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class PageRowPageExtension extends SiteTreeExtension
4
{
5
6
7
    private static $many_many = [
8
        'PageRows' => 'PageRow'
9
    ];
10
11
    private static $many_many_extraFields = [
12
        'PageRows' => [
13
            'SortOrder' => 'Int'
14
        ]
15
    ];
16
17
    public function PageRows()
18
    {
19
        return $this->getPageRows();
20
    }
21
22
    public function getPageRows()
23
    {
24
        return $this->owner->getManyManyComponents('PageRows')->sort(['SortOrder' => 'ASC']);
25
    }
26
27
    #######################
28
    ### Further DB Field Details
29
    #######################
30
31
    #######################
32
    ### Field Names and Presentation Section
33
    #######################
34
35
    private static $field_labels = [
36
        'PageRows' => 'Content Blocks'
37
    ];
38
39
    private static $field_labels_right = [
40
        'PageRows' => 'Please edit with care! You can add content blocks that are not ready for publication, but they will not be visible until they are ticked as available.',
41
    ];
42
43
44
    #######################
45
    ### Casting Section
46
    #######################
47
48
49
    #######################
50
    ### can Section
51
    #######################
52
53
54
55
    #######################
56
    ### write Section
57
    #######################
58
59
60
61
    public function onAfterWrite()
62
    {
63
        if (Security::database_is_ready()  && $this->owner->HasPageRows()) {
64
            // debug::Log('-------------------------');
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
65
            $currentPageRows = [];
66
            if ($this->owner->PageRows()->count() > 0) {
67
                $sortOrder = 1;
68
                foreach ($this->owner->PageRows() as $pageRow) {
69
                    $currentPageRows[$sortOrder] = $pageRow;
70
                    $sortOrder++;
71
                }
72
            }
73
            $rowClassNames = $this->owner->DefaultPageRows();
74
            $sortOrder = 1;
75
            foreach ($rowClassNames as $className) {
76
                $childClassName = null;
77
                if (is_array($className)) {
78
                    $childClassName = $className['Child'];
79
                    // debug::log($childClassName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
80
                    $className = $className['Parent'];
81
                }
82
                if (isset($currentPageRows[$sortOrder])) {
83
                    $row = $currentPageRows[$sortOrder];
84
                    if ($row->ClassName === $className) {
85
                        //all OK!
86
                    } else {
87
                        // $this->owner->removePageRowFromThisPage($row);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
88
                        //we do not delete the row as it may be used somewhere else ...
89
                        // $this->owner->deletePageRowFromMe($row);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
90
                    }
91
                } else {
92
                    $row = $className::create();
93
                    $row->Title = 'Title '.$row->singular_name().' #'.$className::get()->count().' for '.$this->owner->MenuTitle;
94
                    $row->write();
95
                    $this->owner->PageRows()->add($row, ['SortOrder' => $sortOrder]);
96
                    $currentPageRows[$sortOrder] = $row;
97
                }
98
                DB::query('
99
                    UPDATE "Page_PageRows"
100
                    SET "SortOrder" = '.$sortOrder.'
101
                    WHERE
102
                        "PageID" ='.$this->owner->ID.' AND
103
                        "PageRowID" = '.$row->ID.'
104
                    LIMIT 1;
105
                ');
106
                if ($childClassName) {
107
                    $childClassMethod = $row->ChildClassMethodName();
108
                    if ($childClassMethod) {
109
                        $child = $row->$childClassMethod();
110
                        if ($child && $child->exists()) {
111
                        } else {
112
                            $childClassMethodFieldName = $childClassMethod.'ID';
113
                            $child = $childClassName::create();
114
                            $child->Title = 'New '.$child->singular_name().' for '.$row->getTitle();
115
                            $child->write();
116
                            // debug::log($childClassMethodFieldName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
117
                            // debug::log($child->ID);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
118
                            // debug::log($child->Title);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
119
                            $row->$childClassMethodFieldName = $child->ID;
120
                            $row->write();
121
                        }
122
                    } else {
123
                        user_error('no childclass method set in '.$row->ClassName);
124
                    }
125
                }
126
                $sortOrder++;
127
            }
128
            $sortOrder = 1;
129
            foreach ($this->owner->PageRows() as $pageRow) {
130
                $sortOrder++;
131
                $delete = false;
132
                if (!isset($rowClassNames[$sortOrder])) {
133
                    $delete = true;
134
                } elseif ($rowClassNames[$sortOrder] !== $pageRow->ClassName) {
135
                    $delete = true;
136
                }
137
                if ($delete) {
138
                    // $this->owner->removePageRowFromThisPage($pageRow);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
139
                }
140
            }
141
        }
142
    }
143
144
    protected function removePageRowFromThisPage($rowOrRowID)
145
    {
146
        if ($rowOrRowID instanceof PageRow) {
147
            $rowOrRowID = $rowOrRowID->ID;
148
        }
149
        DB::query('
150
            DELETE
151
            FROM "Page_PageRows"
152
            WHERE
153
                "PageID" ='.$this->owner->ID.' AND
154
                "PageRowID" = '.$rowOrRowID.'
155
            LIMIT 1;
156
        ');
157
    }
158
159
160
    public function DefaultPageRows()
161
    {
162
        if($this->owner->hasMethod('MyDefaultPageRows')) {
163
            return $this->owner->MyDefaultPageRows();
164
        }
165
        return [];
166
    }
167
168
    #######################
169
    ### Import / Export Section
170
    #######################
171
172
173
174
    #######################
175
    ### CMS Edit Section
176
    #######################
177
178
    /**
179
     * Update Fields
180
     * @return FieldList
181
     */
182
    public function updateCMSFields(FieldList $fields)
183
    {
184
        $list = $this->owner->PageRows();
185
        if($this->owner->canEdit() && $this->owner->exists() && $this->HasPageRows()) {
186
            $fields->addFieldsToTab(
187
                'Root.ContentBlocks',
188
                $this->owner->ContentBlocksFields()
189
            );
190
        }
191
    }
192
193
    public function ContentBlocksFields()
194
    {
195
        $conf = GridFieldConfig_RelationEditor::create(100);
196
        $conf->addComponent(new GridFieldSortableRows('SortOrder'));
197
        // switch ($this->owner->ClassName) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
198
        //     case 'HomePage':
199
        //         // leave as is ...
200
        //         $conf->removeComponentsByType('GridFieldAddExistingAutocompleter');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
201
        //         $conf->removeComponentsByType('GridFieldDeleteAction');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
202
        //         $conf->removeComponentsByType('GridFieldAddNewButton');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
203
        //         break;
204
        //     default:
205
        // }
206
        //
207
        $conf->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(['Code', 'Title']);
208
209
        $pageRowField = GridField::create(
210
            'PageRows',
211
            'Content Blocks',
212
            $this->owner->PageRows(),
213
            $conf
214
        );
215
        $array = [$pageRowField];
216
        $arrayRowList = [];
217
        foreach ($this->owner->DefaultPageRows() as $count => $className) {
218
            if (is_array($className)) {
219
                $className = $className['Parent'];
220
            }
221
            $humanCount = $count + 1;
222
            $arrayRowList[$className.'_'.$count] = $humanCount . ' - '.Injector::inst()->get($className)->singular_name().' ('.$className.')';
223
        }
224
        if(count($arrayRowList)) {
225
            $array[] = LiteralField::create(
226
                'ListOfContentBlocks',
227
                '<h2>By default, this page type ('.$this->owner->singular_name().') has the following content blocks:</h2><p>'.implode('</p><p>', $arrayRowList).'</p>'
228
            );
229
        }
230
231
        return $array;
232
    }
233
234
    public function HasPageRows()
235
    {
236
        switch($this->owner->ClassName) {
237
            case 'ErrorPage':
238
            case 'RedirectorPage':
239
            case 'VirtualPage':
240
                return false;
241
        }
242
        if($this->owner->hasMethod('MyHasPageRows')) {
243
            return $this->owner->MyHasPageRows();
244
        }
245
        return true;
246
    }
247
248
}
249