This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 ImageGalleryPage extends Page |
||
0 ignored issues
–
show
|
|||
4 | { |
||
5 | private static $icon = "imagegallery_basic/images/treeicons/ImageGalleryPage"; |
||
0 ignored issues
–
show
|
|||
6 | |||
7 | private static $allowed_children = array("ImageGalleryPage"); //can also be "none"; |
||
0 ignored issues
–
show
|
|||
8 | |||
9 | private static $default_child = "ImageGalleryPage"; |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | private static $description = "Page used to display images in a gallery"; |
||
0 ignored issues
–
show
|
|||
12 | |||
13 | private static $has_one = array( |
||
0 ignored issues
–
show
|
|||
14 | "AutomaticallyIncludedFolder" => "Folder" |
||
15 | ); |
||
16 | |||
17 | private static $has_many = array( |
||
0 ignored issues
–
show
|
|||
18 | "ImageGalleryEntries" => "ImageGalleryEntry" |
||
19 | ); |
||
20 | |||
21 | public function getCMSFields() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
22 | { |
||
23 | $fields = parent::getCMSFields(); |
||
24 | $fields->addFieldToTab("Root.Gallery", $treeDropdowField = TreeDropdownField::create($name = "AutomaticallyIncludedFolderID", $title = "Quick Add from Folder", $sourceObjectName = "Folder")); |
||
25 | $treeDropdowField->setRightTitle(' |
||
26 | Add a folder here to add a bunch of images all at once.<br /> |
||
27 | <a href="/admin/assets/show/'.$this->AutomaticallyIncludedFolderID.'">see files and images</a> section to add, remove and edit images in a folder before selecting one here. |
||
28 | <br /> |
||
29 | Once added, you can edit the images below as you see fit. |
||
30 | '); |
||
31 | $gridField = new GridField('images', 'Linked images', $this->ImageGalleryEntries(), GridFieldConfig_RelationEditor::create()); |
||
32 | $fields->addFieldToTab("Root.Gallery", $gridField); |
||
33 | if (class_exists("DataObjectSorterController")) { |
||
34 | $fields->addFieldToTab( |
||
35 | "Root.Gallery", |
||
36 | LiteralField::create( |
||
37 | "ImageGalleryEntrySorter", |
||
38 | DataObjectSorterController::popup_link( |
||
39 | "ImageGalleryEntry", |
||
40 | $filterField = "ParentID", |
||
41 | $filterValue = $this->ID, |
||
42 | $linkText = "Sort Items", |
||
43 | $titleField = "FullTitle" |
||
44 | ) |
||
45 | ) |
||
46 | ); |
||
47 | } else { |
||
48 | $fields->addFieldToTab("Root.Gallery", new NumericField($name = "Sort", "Sort index number (the lower the number, the earlier it shows up")); |
||
49 | } |
||
50 | return $fields; |
||
51 | } |
||
52 | |||
53 | public function onBeforeWrite() |
||
54 | { |
||
55 | parent::onBeforeWrite(); |
||
56 | $imageAdded = false; |
||
57 | if ($this->AutomaticallyIncludedFolderID) { |
||
58 | if ($folder = Folder::get()->byID($this->AutomaticallyIncludedFolderID)) { |
||
59 | if ($files = Image::get()->filter("ParentID", $folder->ID)) { |
||
60 | foreach ($files as $file) { |
||
61 | if (ImageGalleryEntry::get()->filter(array("ImageID" => $file->ID, "ParentID" => $this->ID))->count()) { |
||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
62 | //do nothing |
||
63 | //debug::log("already exists"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% 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. ![]() |
|||
64 | } else { |
||
65 | $ImageGalleryEntry = new ImageGalleryEntry(); |
||
66 | $ImageGalleryEntry->Title = $file->Title; |
||
0 ignored issues
–
show
The property
Title does not exist on object<ImageGalleryEntry> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
67 | $ImageGalleryEntry->ImageID = $file->ID; |
||
0 ignored issues
–
show
The property
ImageID does not exist on object<ImageGalleryEntry> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
68 | $ImageGalleryEntry->ParentID = $this->ID; |
||
0 ignored issues
–
show
The property
ParentID does not exist on object<ImageGalleryEntry> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
69 | $ImageGalleryEntry->write(); |
||
70 | $imageAdded = true; |
||
71 | //debug::log("writing"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% 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. ![]() |
|||
72 | } |
||
73 | } |
||
74 | } else { |
||
0 ignored issues
–
show
This
else statement is empty and can be removed.
This check looks for the These if (rand(1, 6) > 3) {
print "Check failed";
} else {
//print "Check succeeded";
}
could be turned into if (rand(1, 6) > 3) {
print "Check failed";
}
This is much more concise to read. ![]() |
|||
75 | //debug::log("D"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% 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. ![]() |
|||
76 | } |
||
77 | } else { |
||
0 ignored issues
–
show
This
else statement is empty and can be removed.
This check looks for the These if (rand(1, 6) > 3) {
print "Check failed";
} else {
//print "Check succeeded";
}
could be turned into if (rand(1, 6) > 3) {
print "Check failed";
}
This is much more concise to read. ![]() |
|||
78 | //debug::log("C"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% 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. ![]() |
|||
79 | } |
||
80 | } else { |
||
0 ignored issues
–
show
This
else statement is empty and can be removed.
This check looks for the These if (rand(1, 6) > 3) {
print "Check failed";
} else {
//print "Check succeeded";
}
could be turned into if (rand(1, 6) > 3) {
print "Check failed";
}
This is much more concise to read. ![]() |
|||
81 | //debug::log("B"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% 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. ![]() |
|||
82 | } |
||
83 | if ($ImageGalleryEntries = ImageGalleryEntry::get()->filter(array("ParentID" => $this->ID))) { |
||
84 | foreach ($ImageGalleryEntries as $ImageGalleryEntry) { |
||
85 | $image = Image::get() |
||
86 | ->filter(array("ID" => $ImageGalleryEntry->ImageID)) |
||
87 | ->exclude(array("Title" => $ImageGalleryEntry->Title)) |
||
88 | ->First(); |
||
89 | if ($image) { |
||
90 | $image->Title = $image->Name = $ImageGalleryEntry->Title; |
||
91 | $image->write(); |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | if ($imageAdded) { |
||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
96 | //LeftAndMain::force_reload(); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% 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. ![]() |
|||
97 | } |
||
98 | $this->AutomaticallyIncludedFolderID = 0; |
||
99 | } |
||
100 | |||
101 | View Code Duplication | public function NextGallery() |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
102 | { |
||
103 | $pages = ImageGalleryPage::get() |
||
104 | ->exclude(array("ID" => $this->ID)) |
||
105 | ->where("TimeDiff(\"Created\",'".$this->Created."') > 0") |
||
106 | ->sort("Created", "ASC") |
||
107 | ->limit(1); |
||
108 | if ($pages) { |
||
109 | foreach ($pages as $page) { |
||
110 | return $page; |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | |||
115 | View Code Duplication | public function PreviousGallery() |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
116 | { |
||
117 | $pages = ImageGalleryPage::get() |
||
118 | ->exclude(array("ID" => $this->ID)) |
||
119 | ->where("TimeDiff(\"Created\",'".$this->Created."') < 0") |
||
120 | ->sort("Created", "DESC") |
||
121 | ->limit(1); |
||
122 | if ($pages) { |
||
123 | foreach ($pages as $page) { |
||
124 | return $page; |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | |||
130 | class ImageGalleryPage_Controller extends Page_Controller |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
131 | { |
||
132 | private static $allowed_actions = array( |
||
0 ignored issues
–
show
|
|||
133 | "updateimagegalleryentries" => "ADMIN" |
||
134 | ); |
||
135 | |||
136 | public function init() |
||
137 | { |
||
138 | parent::init(); |
||
139 | if (class_exists("PrettyPhoto")) { |
||
140 | PrettyPhoto::include_code(); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | public function updateimagegalleryentries() |
||
145 | { |
||
146 | $this->onBeforeWrite(); |
||
147 | return array(); |
||
148 | } |
||
149 | } |
||
150 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.