Issues (35)

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/Block.php (14 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
class Block extends DataObject {
3
	private static $db = array (
0 ignored issues
show
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
4
		'SortOrder'			=>	'Int',
5
		'Title'				=>	'Varchar(64)',
6
		'TitleWrapper'		=>	'Enum("h2,h3,h4,h5,h6")',
7
		'hideTitle'			=>	'Boolean',
8
		'showBlockbyClass'	=>	'Boolean',
9
		'Description'		=>	'Varchar(128)',
10
		'MemberVisibility'	=>	'Varchar(255)',
11
		'shownInClass'		=>	'Text',
12
		'addMarginTop'		=>	'Boolean',
13
		'addMarginBottom'	=>	'Boolean',
14
		'addPaddingTop'		=>	'Boolean',
15
		'addPaddingBottom'	=>	'Boolean'
16
	);
17
18
	private static $many_many = array (
0 ignored issues
show
The property $many_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
		'Pages'				=>	'Page'
20
	);
21
22
	private static $default_sort = array(
0 ignored issues
show
The property $default_sort is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
		'SortOrder'			=>	'ASC',
24
		'ID'					=>	'DESC'
25
	);
26
27
	private static $create_table_options = array(
0 ignored issues
show
The property $create_table_options is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
28
		'MySQLDatabase'		=> 'ENGINE=MyISAM'
29
    );
30
31
	private static $extensions = array (
0 ignored issues
show
The property $extensions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
32
		'StandardPermissions'
33
	);
34
35
	private static $summary_fields = array(
0 ignored issues
show
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
36
		'BlockType',
37
		'Title',
38
		'Description',
39
		'shownOn',
40
		'VisibleTo',
41
		'Published'
42
	);
43
44
	private static $field_labels = array(
0 ignored issues
show
The property $field_labels is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
45
		'BlockType'			=>	'Block type',
46
		'shownOn'			=>	'is shown on',
47
		'VisibleTo'			=>	'Visible to'
48
	);
49
50
	public function VisibleTo() {
51
		if (strlen(trim($this->MemberVisibility)) > 0) {
52
			$lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility);
53
		}else{
54
			$lists = '<em>&lt;All&gt;</em>';
55
		}
56
57
		return new LiteralField('VisibleTo',$lists);
58
	}
59
60
	public function BlockType() {
61
		return $this->singular_name();
62
	}
63
64
	public function shownOn() {
65
		if ($this->showBlockbyClass) {
66
			if (strlen(trim($this->shownInClass)) > 0) {
67
				$lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass);
68
			}else{
69
				$lists = '<em>&lt;not assigned&gt;</em>';
70
			}
71
		}else{
72
			if ($this->Pages()->count() > 0) {
73
				$lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title'));
74
			}else{
75
				$lists = '<em>&lt;not assigned&gt;</em>';
76
			}
77
		}
78
		return new LiteralField('shownOn',$lists);
79
	}
80
81
	public function getCMSFields() {
82
		$fields = parent::getCMSFields();
83
		$fields->removeFieldFromTab('Root', 'Pages');
84
		$fields->removeFieldsFromTab('Root.Main', array(
85
			'SortOrder',
86
			'showBlockbyClass',
87
			'shownInClass',
88
			'MemberVisibility'
89
		));
90
91
		$fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title');
92
93
		$memberGroups = Group::get();
94
		$sourcemap = $memberGroups->map('Code', 'Title');
95
		$source = array(
96
			'anonymous'		=>	'Anonymous visitors'
97
		);
98
		foreach ($sourcemap as $mapping => $key) {
99
			$source[$mapping] = $key;
100
		}
101
102
		$memberVisibility = new CheckboxSetField(
103
			$name = "MemberVisibility",
104
			$title = "Show block for specific groups",
105
			$source
106
		);
107
108
		$memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.');
109
110
		$availabelClasses = $this->availableClasses();
111
		$inClass = new CheckboxSetField(
112
			$name = "shownInClass",
113
			$title = "Show block for specific content types",
114
			$availabelClasses
115
		);
116
117
		$filterSelector = OptionsetField::create(
118
			'showBlockbyClass',
119
			'Choose filter set',
120
			array(
121
				'0'			=>	'by page',
122
				'1'			=>	'by page/data type'
123
			)
124
		)->setDescription('<p><br /><strong>by page</strong>: block will be displayed in the selected page(s)<br /><strong>by page/data type</strong>: block will be displayed on the pages created with the particular page/data type. e.g. is <strong>"InternalPage"</strong> is picked, the block will be displayed, and will ONLY be displayed on all <strong>Internal Pages</strong></p>');
125
126
		$availablePages = Page::get()->exclude('ClassName', array(
127
			'ErrorPage',
128
			'RedirectorPage',
129
			'VirtualPage'
130
		));
131
		$pageSelector = new CheckboxSetField(
132
			$name = "Pages",
133
			$title = "Show on Page(s)",
134
			$availablePages->map('ID','Title')
135
		);
136
137
138
		if ($this->canConfigPageAndType(Member::currentUser())) {
139
			$fields->addFieldsToTab('Root.VisibilitySettings', array(
140
				$filterSelector,
141
				$pageSelector,
142
				$inClass
143
			));
144
		}
145
146
		if ($this->canConfigMemberVisibility(Member::currentUser())) {
147
			$fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility);
148
		}
149
150
		if (!$fields->fieldByName('Options')) {
151
			$fields->insertBefore($right = RightSidebar::create('Options'), 'Root');
0 ignored issues
show
'Root' is of type string, but the function expects a object<FormField>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
152
	    }
153
154
	    $fields->addFieldsToTab('Options', array(
155
			CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'),
156
			CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper'),
157
            		CheckboxField::create('addPaddingTop', 'add "padding-top" class to block wrapper'),
158
			CheckboxField::create('addPaddingBottom', 'add "padding-bottom" class to block wrapper')
159
	    ));
160
161
		return $fields;
162
	}
163
164
	public function doPublish() {
165
		$this->writeToStage('Live');
0 ignored issues
show
Documentation Bug introduced by
The method writeToStage does not exist on object<Block>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
166
	}
167
168
	public function onBeforeWrite() {
169
		parent::onBeforeWrite();
170
		if (empty($this->byPass)) {
0 ignored issues
show
The property byPass does not exist on object<Block>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
171
			$this->readmode = Versioned::get_reading_mode();
0 ignored issues
show
The property readmode does not exist on object<Block>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
172
			Versioned::set_reading_mode('Stage.Stage');
173
		}
174
	}
175
176
	public function onAfterWrite() {
177
		parent::onAfterWrite();
178
		if (isset($this->readmode)) {
179
			Versioned::set_reading_mode('Stage.' . $this->readmode);
0 ignored issues
show
The property readmode does not exist on object<Block>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
180
		}
181
182
		/*if ($this->isPublished()) {
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...
183
			$live = Versioned::get_by_stage('Block', 'Live')->byID($this->ID);
184
			$stage = Versioned::get_by_stage('Block', 'Stage')->byID($this->ID);
185
			if ($live->SortOrder != $stage->SortOrder) {
186
187
				$this->byPass = true;
188
				$this->doPublish();
189
			}
190
		}*/
191
	}
192
193
	public function availableClasses() {
194
		$Classes = array_diff(
195
			ClassInfo::subclassesFor('Page'),
196
			ClassInfo::subclassesFor('RedirectorPage'),
197
			ClassInfo::subclassesFor('VirtualPage')
198
		);
199
		return $Classes;
200
	}
201
202
	public function forTemplate() {
203
		if ($this->canDisplayMemberCheck()) {
204
			return $this->renderWith(array($this->getClassName(), 'BaseBlock'));
205
		}
206
207
		return false;
208
	}
209
210
	public function canDisplayMemberCheck() {
211
		$rawVisibility = $this->MemberVisibility;
212
213
		if (empty($rawVisibility)) {
214
			return true;
215
		}
216
217
		$visibility = explode(',', $rawVisibility);
218
		$member = Member::currentUser();
219
220
		if (!$member && in_array('anonymous', $visibility)) {
221
			return true;
222
		}
223
224
		if ($member) {
225
			$memberGroups = $member->Groups()->column('Code');
226
			foreach ($memberGroups as $memberGroup) {
227
				if (in_array($memberGroup, $visibility)) {
228
					return true;
229
				}
230
			}
231
		}
232
233
		return false;
234
	}
235
236
	public function frontendEditable() {
237
		$member = Member::currentUser();
238
		return $this->canEdit($member) && Config::inst()->get('Block', 'FrontendEditable');
239
	}
240
241
	public function Type2Class() {
242
		return strtolower(str_replace(' ', '-', $this->singular_name()));
243
	}
244
245
	/*public function doPublish() {
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
246
		$this->writeToStage('Live');
247
	}*/
248
249
	public function Published() {
250
		return $this->isPublished() ? 'Yes' : 'No';
251
	}
252
253
	public function isPublished() {
254
		if (!empty(Versioned::get_by_stage('Block', 'Live')->byID($this->ID))) {
255
			return true;
256
		}
257
258
		return false;
259
	}
260
261
}
262