Completed
Branch master (167e4d)
by Gordon
04:03
created
code/Commenting.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@
 block discarded – undo
116 116
 	 * @param string $class
117 117
 	 * @param string $key
118 118
 	 * @param string $value Expected value
119
-	 * @return boolean
119
+	 * @return boolean|null
120 120
 	 */
121 121
 	public static function config_value_equals($class, $key, $value) {
122 122
 		$check = self::get_config_value($class, $key);
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 		Config::inst()->update($class, 'extensions', array('CommentsExtension'));
32 32
 
33 33
 		// Check if settings must be customised
34
-		if($settings === false) return;
35
-		if(!is_array($settings)) {
34
+		if ($settings === false) return;
35
+		if (!is_array($settings)) {
36 36
 			throw new InvalidArgumentException('$settings needs to be an array or null');
37 37
 		}
38 38
 		Config::inst()->update($class, 'comments', $settings);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public static function set_config_value($class, $key, $value = false) {
78 78
 		Deprecation::notice('2.0', 'Commenting::set_config_value is deprecated. Use the config api instead');
79
-		if($class === "all") $class = 'CommentsExtension';
79
+		if ($class === "all") $class = 'CommentsExtension';
80 80
 		Config::inst()->update($class, 'comments', array($key => $value));
81 81
 	}
82 82
 
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 		);
100 100
 
101 101
 		// Get settings
102
-		if(!$class) {
102
+		if (!$class) {
103 103
 			$class = 'CommentsExtension';
104
-		} elseif(!$class::has_extension('CommentsExtension')) {
104
+		} elseif (!$class::has_extension('CommentsExtension')) {
105 105
 			throw new InvalidArgumentException("$class does not have commenting enabled");
106 106
 		}
107 107
 		return singleton($class)->getCommentsOption($key);
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public static function config_value_equals($class, $key, $value) {
122 122
 		$check = self::get_config_value($class, $key);
123
-		if($check && ($check == $value)) return true;
123
+		if ($check && ($check == $value)) return true;
124 124
 	}
125 125
 
126 126
 	/**
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 	 * @return boolean true
133 133
 	 */
134 134
 	public static function can_member_post($class) {
135
-		Deprecation::notice('2.0',  'Use $instance->canPostComment() directly instead');
135
+		Deprecation::notice('2.0', 'Use $instance->canPostComment() directly instead');
136 136
 		$member = Member::currentUser();
137 137
 
138 138
 		// Check permission
139 139
 		$permission = self::get_config_value($class, 'required_permission');
140
-		if($permission && !Permission::check($permission)) return false;
140
+		if ($permission && !Permission::check($permission)) return false;
141 141
 
142 142
 		// Check login required
143 143
 		$requireLogin = self::get_config_value($class, 'require_login');
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@  discard block
 block discarded – undo
31 31
 		Config::inst()->update($class, 'extensions', array('CommentsExtension'));
32 32
 
33 33
 		// Check if settings must be customised
34
-		if($settings === false) return;
34
+		if($settings === false) {
35
+			return;
36
+		}
35 37
 		if(!is_array($settings)) {
36 38
 			throw new InvalidArgumentException('$settings needs to be an array or null');
37 39
 		}
@@ -76,7 +78,9 @@  discard block
 block discarded – undo
76 78
 	 */
77 79
 	public static function set_config_value($class, $key, $value = false) {
78 80
 		Deprecation::notice('2.0', 'Commenting::set_config_value is deprecated. Use the config api instead');
79
-		if($class === "all") $class = 'CommentsExtension';
81
+		if($class === "all") {
82
+			$class = 'CommentsExtension';
83
+		}
80 84
 		Config::inst()->update($class, 'comments', array($key => $value));
81 85
 	}
82 86
 
@@ -120,7 +124,9 @@  discard block
 block discarded – undo
120 124
 	 */
121 125
 	public static function config_value_equals($class, $key, $value) {
122 126
 		$check = self::get_config_value($class, $key);
123
-		if($check && ($check == $value)) return true;
127
+		if($check && ($check == $value)) {
128
+			return true;
129
+		}
124 130
 	}
125 131
 
126 132
 	/**
@@ -137,7 +143,9 @@  discard block
 block discarded – undo
137 143
 
138 144
 		// Check permission
139 145
 		$permission = self::get_config_value($class, 'required_permission');
140
-		if($permission && !Permission::check($permission)) return false;
146
+		if($permission && !Permission::check($permission)) {
147
+			return false;
148
+		}
141 149
 
142 150
 		// Check login required
143 151
 		$requireLogin = self::get_config_value($class, 'require_login');
Please login to merge, or discard this patch.
code/controllers/CommentingController.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@
 block discarded – undo
120 120
 	 * Get the commenting option for the current state
121 121
 	 *
122 122
 	 * @param string $key
123
-	 * @return mixed Result if the setting is available, or null otherwise
123
+	 * @return integer Result if the setting is available, or null otherwise
124 124
 	 */
125 125
 	public function getOption($key) {
126 126
 		// If possible use the current record
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 	 */
125 125
 	public function getOption($key) {
126 126
 		// If possible use the current record
127
-		if($record = $this->getOwnerRecord()) {
127
+		if ($record = $this->getOwnerRecord()) {
128 128
 			return $record->getCommentsOption($key);
129 129
 		}
130 130
 		
131 131
 		// Otherwise a singleton of that record
132
-		if($class = $this->getBaseClass()) {
132
+		if ($class = $this->getBaseClass()) {
133 133
 			return singleton($class)->getCommentsOption($key);
134 134
 		}
135 135
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @return string
144 144
 	 */
145 145
 	public function Link($action = '', $id = '', $other = '') {
146
-		return Controller::join_links(Director::baseURL(), __CLASS__ , $action, $id, $other);
146
+		return Controller::join_links(Director::baseURL(), __CLASS__, $action, $id, $other);
147 147
 	}
148 148
 	
149 149
 	/**
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		$id = $request->param('OtherID');
174 174
 
175 175
 		// Support old pageid param
176
-		if(!$id && !$class && ($id = $request->getVar('pageid'))) {
176
+		if (!$id && !$class && ($id = $request->getVar('pageid'))) {
177 177
 			$class = 'SiteTree';
178 178
 		}
179 179
 
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
 		));
184 184
 
185 185
 		// Check if class filter
186
-		if($class) {
187
-			if(!is_subclass_of($class, 'DataObject') || !$class::has_extension('CommentsExtension')) {
186
+		if ($class) {
187
+			if (!is_subclass_of($class, 'DataObject') || !$class::has_extension('CommentsExtension')) {
188 188
 				return $this->httpError(404);
189 189
 			}
190 190
 			$this->setBaseClass($class);
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 			$link = Controller::join_links($link, $class);
193 193
 
194 194
 			// Check if id filter
195
-			if($id) {
195
+			if ($id) {
196 196
 				$comments = $comments->filter('ParentID', $id);
197 197
 				$link = Controller::join_links($link, $id);
198 198
 				$this->setOwnerRecord(DataObject::get_by_id($class, $id));
@@ -218,11 +218,11 @@  discard block
 block discarded – undo
218 218
 	 */
219 219
 	public function delete() {
220 220
 		$comment = $this->getComment();
221
-		if(!$comment) return $this->httpError(404);
222
-		if(!$comment->canDelete()) {
221
+		if (!$comment) return $this->httpError(404);
222
+		if (!$comment->canDelete()) {
223 223
 			return Security::permissionFailure($this, 'You do not have permission to delete this comment');
224 224
 		}
225
-		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
225
+		if (!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
226 226
 
227 227
 		$comment->delete();
228 228
 
@@ -236,11 +236,11 @@  discard block
 block discarded – undo
236 236
 	 */
237 237
 	public function spam() {
238 238
 		$comment = $this->getComment();
239
-		if(!$comment) return $this->httpError(404);
240
-		if(!$comment->canEdit()) {
239
+		if (!$comment) return $this->httpError(404);
240
+		if (!$comment->canEdit()) {
241 241
 			return Security::permissionFailure($this, 'You do not have permission to edit this comment');
242 242
 		}
243
-		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
243
+		if (!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
244 244
 		
245 245
 		$comment->markSpam();
246 246
 
@@ -254,11 +254,11 @@  discard block
 block discarded – undo
254 254
 	 */
255 255
 	public function ham() {
256 256
 		$comment = $this->getComment();
257
-		if(!$comment) return $this->httpError(404);
258
-		if(!$comment->canEdit()) {
257
+		if (!$comment) return $this->httpError(404);
258
+		if (!$comment->canEdit()) {
259 259
 			return Security::permissionFailure($this, 'You do not have permission to edit this comment');
260 260
 		}
261
-		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
261
+		if (!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
262 262
 
263 263
 		$comment->markApproved();
264 264
 
@@ -272,11 +272,11 @@  discard block
 block discarded – undo
272 272
 	 */
273 273
 	public function approve() {
274 274
 		$comment = $this->getComment();
275
-		if(!$comment) return $this->httpError(404);
276
-		if(!$comment->canEdit()) {
275
+		if (!$comment) return $this->httpError(404);
276
+		if (!$comment->canEdit()) {
277 277
 			return Security::permissionFailure($this, 'You do not have permission to approve this comment');
278 278
 		}
279
-		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
279
+		if (!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
280 280
 
281 281
 		$comment->markApproved();
282 282
 
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
 	public function getComment() {
295 295
 		$id = isset($this->urlParams['ID']) ? $this->urlParams['ID'] : false;
296 296
 
297
-		if($id) {
297
+		if ($id) {
298 298
 			$comment = DataObject::get_by_id('Comment', $id);
299 299
 
300
-			if($comment) {
300
+			if ($comment) {
301 301
 				$this->fallbackReturnURL = $comment->Link();
302 302
 				return $comment;
303 303
 			}
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	public function ReplyForm($comment) {
315 315
 		// Enables multiple forms with different names to use the same handler
316 316
 		$form = $this->CommentsForm();
317
-		$form->setName('ReplyForm_'.$comment->ID);
317
+		$form->setName('ReplyForm_' . $comment->ID);
318 318
 		$form->addExtraClass('reply-form');
319 319
 
320 320
 		// Load parent into reply form
@@ -338,9 +338,9 @@  discard block
 block discarded – undo
338 338
 	 */
339 339
 	public function reply(SS_HTTPRequest $request) {
340 340
 		// Extract parent comment from reply and build this way
341
-		if($parentID = $request->param('ParentCommentID')) {
341
+		if ($parentID = $request->param('ParentCommentID')) {
342 342
 			$comment = DataObject::get_by_id('Comment', $parentID, true);
343
-			if($comment) {
343
+			if ($comment) {
344 344
 				return $this->ReplyForm($comment);
345 345
 			}
346 346
 		}
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 
397 397
 		// Preview formatted comment. Makes most sense when shortcodes or
398 398
 		// limited HTML is allowed. Populated by JS/Ajax.
399
-		if($usePreview) {
399
+		if ($usePreview) {
400 400
 			$fields->insertAfter(
401 401
 				ReadonlyField::create('PreviewComment', _t('CommentInterface.PREVIEWLABEL', 'Preview'))
402 402
 					->setAttribute('style', 'display: none'), // enable through JS
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 		$actions = new FieldList(
411 411
 			new FormAction("doPostComment", _t('CommentInterface.POST', 'Post'))
412 412
 		);
413
-		if($usePreview) {
413
+		if ($usePreview) {
414 414
 			$actions->push(
415 415
 				FormAction::create('doPreviewComment', _t('CommentInterface.PREVIEW', 'Preview'))
416 416
 					->addExtraClass('action-minor')
@@ -425,11 +425,11 @@  discard block
 block discarded – undo
425 425
 		$form = new Form($this, 'CommentsForm', $fields, $actions, $required);
426 426
 
427 427
 		// if the record exists load the extra required data
428
-		if($record = $this->getOwnerRecord()) {
428
+		if ($record = $this->getOwnerRecord()) {
429 429
 
430 430
 			// Load member data
431 431
 			$member = Member::currentUser();
432
-			if(($record->CommentsRequireLogin || $record->PostingRequiredPermission) && $member) {
432
+			if (($record->CommentsRequireLogin || $record->PostingRequiredPermission) && $member) {
433 433
 				$fields = $form->Fields();
434 434
 
435 435
 				$fields->removeByName('Name');
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 		$form->setRedirectToFormOnValidationError(true);
453 453
 
454 454
 		// load any data from the cookies
455
-		if($data = Cookie::get('CommentsForm_UserData')) {
455
+		if ($data = Cookie::get('CommentsForm_UserData')) {
456 456
 			$data = Convert::json2array($data); 
457 457
 			  
458 458
 			$form->loadDataFrom(array(
@@ -462,12 +462,12 @@  discard block
 block discarded – undo
462 462
 			));
463 463
 			// allow previous value to fill if comment not stored in cookie (i.e. validation error)
464 464
 			$prevComment = Cookie::get('CommentsForm_Comment');
465
-			if($prevComment && $prevComment != ''){
465
+			if ($prevComment && $prevComment != '') {
466 466
 				$form->loadDataFrom(array("Comment" => $prevComment));
467 467
 			}
468 468
 		}
469 469
 
470
-		if(!empty($member)) {
470
+		if (!empty($member)) {
471 471
 			$form->loadDataFrom($member);
472 472
 		}
473 473
 		
@@ -485,13 +485,13 @@  discard block
 block discarded – undo
485 485
 	 */
486 486
 	public function doPostComment($data, $form) {
487 487
 		// Load class and parent from data
488
-		if(isset($data['BaseClass'])) {
488
+		if (isset($data['BaseClass'])) {
489 489
 			$this->setBaseClass($data['BaseClass']);
490 490
 		}
491
-		if(isset($data['ParentID']) && ($class = $this->getBaseClass())) {
491
+		if (isset($data['ParentID']) && ($class = $this->getBaseClass())) {
492 492
 			$this->setOwnerRecord($class::get()->byID($data['ParentID']));
493 493
 		}
494
-		if(!$this->getOwnerRecord()) return $this->httpError(404);
494
+		if (!$this->getOwnerRecord()) return $this->httpError(404);
495 495
 		
496 496
 		// cache users data
497 497
 		Cookie::set("CommentsForm_UserData", Convert::raw2json($data));
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 		$this->extend('onBeforePostComment', $form);	
502 502
 		
503 503
 		// If commenting can only be done by logged in users, make sure the user is logged in
504
-		if(!$this->getOwnerRecord()->canPostComment()) {
504
+		if (!$this->getOwnerRecord()->canPostComment()) {
505 505
 			return Security::permissionFailure(
506 506
 				$this,
507 507
 				_t(
@@ -512,12 +512,12 @@  discard block
 block discarded – undo
512 512
 			);
513 513
 		}
514 514
 
515
-		if($member = Member::currentUser()) {
515
+		if ($member = Member::currentUser()) {
516 516
 			$form->Fields()->push(new HiddenField("AuthorID", "Author ID", $member->ID));
517 517
 		} 
518 518
 
519 519
 		// What kind of moderation is required?
520
-		switch($this->getOwnerRecord()->ModerationRequired) {
520
+		switch ($this->getOwnerRecord()->ModerationRequired) {
521 521
 			case 'Required':
522 522
 				$requireModeration = true;
523 523
 				break;
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 		// Save into DB, or call pre-save hooks to give accurate preview
540 540
 		$usePreview = $this->getOption('use_preview');
541 541
 		$isPreview = $usePreview && !empty($data['IsPreview']);
542
-		if($isPreview) {
542
+		if ($isPreview) {
543 543
 			$comment->extend('onBeforeWrite');
544 544
 		} else {
545 545
 			$comment->write();
@@ -557,19 +557,19 @@  discard block
 block discarded – undo
557 557
 		Cookie::set('CommentsForm_Comment', false);
558 558
 
559 559
 		// Find parent link
560
-		if(!empty($data['ReturnURL'])) {
560
+		if (!empty($data['ReturnURL'])) {
561 561
 			$url = $data['ReturnURL'];
562
-		} elseif($parent = $comment->getParent()) {
562
+		} elseif ($parent = $comment->getParent()) {
563 563
 			$url = $parent->Link();
564 564
 		} else {
565 565
 			return $this->redirectBack();
566 566
 		}
567 567
 
568 568
 		// Given a redirect page exists, attempt to link to the correct anchor
569
-		if($comment->IsSpam) {
569
+		if ($comment->IsSpam) {
570 570
 			// Link to the form with the error message contained
571 571
 			$hash = $form->FormName();
572
-		} else if(!$comment->Moderated) {
572
+		} else if (!$comment->Moderated) {
573 573
 			// Display the "awaiting moderation" text
574 574
 			$holder = $this->getOption('comments_holder_id');
575 575
 			$hash = "{$holder}_PostCommentForm_error";
@@ -596,21 +596,21 @@  discard block
 block discarded – undo
596 596
 		// In edge-cases, this will be called outside of a handleRequest() context; in that case,
597 597
 		// redirect to the homepage - don't break into the global state at this stage because we'll
598 598
 		// be calling from a test context or something else where the global state is inappropraite
599
-		if($this->request) {
600
-			if($this->request->requestVar('BackURL')) {
599
+		if ($this->request) {
600
+			if ($this->request->requestVar('BackURL')) {
601 601
 				$url = $this->request->requestVar('BackURL');
602
-			} else if($this->request->isAjax() && $this->request->getHeader('X-Backurl')) {
602
+			} else if ($this->request->isAjax() && $this->request->getHeader('X-Backurl')) {
603 603
 				$url = $this->request->getHeader('X-Backurl');
604
-			} else if($this->request->getHeader('Referer')) {
604
+			} else if ($this->request->getHeader('Referer')) {
605 605
 				$url = $this->request->getHeader('Referer');
606 606
 			}
607 607
 		}
608 608
 
609
-		if(!$url) $url = $this->fallbackReturnURL;
610
-		if(!$url) $url = Director::baseURL();
609
+		if (!$url) $url = $this->fallbackReturnURL;
610
+		if (!$url) $url = Director::baseURL();
611 611
 
612 612
 		// absolute redirection URLs not located on this site may cause phishing
613
-		if(Director::is_site_url($url)) {
613
+		if (Director::is_site_url($url)) {
614 614
 			return $this->redirect($url);
615 615
 		} else {
616 616
 			return false;
Please login to merge, or discard this patch.
Braces   +33 added lines, -11 removed lines patch added patch discarded remove patch
@@ -218,11 +218,15 @@  discard block
 block discarded – undo
218 218
 	 */
219 219
 	public function delete() {
220 220
 		$comment = $this->getComment();
221
-		if(!$comment) return $this->httpError(404);
221
+		if(!$comment) {
222
+			return $this->httpError(404);
223
+		}
222 224
 		if(!$comment->canDelete()) {
223 225
 			return Security::permissionFailure($this, 'You do not have permission to delete this comment');
224 226
 		}
225
-		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
227
+		if(!$comment->getSecurityToken()->checkRequest($this->request)) {
228
+			return $this->httpError(400);
229
+		}
226 230
 
227 231
 		$comment->delete();
228 232
 
@@ -236,11 +240,15 @@  discard block
 block discarded – undo
236 240
 	 */
237 241
 	public function spam() {
238 242
 		$comment = $this->getComment();
239
-		if(!$comment) return $this->httpError(404);
243
+		if(!$comment) {
244
+			return $this->httpError(404);
245
+		}
240 246
 		if(!$comment->canEdit()) {
241 247
 			return Security::permissionFailure($this, 'You do not have permission to edit this comment');
242 248
 		}
243
-		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
249
+		if(!$comment->getSecurityToken()->checkRequest($this->request)) {
250
+			return $this->httpError(400);
251
+		}
244 252
 		
245 253
 		$comment->markSpam();
246 254
 
@@ -254,11 +262,15 @@  discard block
 block discarded – undo
254 262
 	 */
255 263
 	public function ham() {
256 264
 		$comment = $this->getComment();
257
-		if(!$comment) return $this->httpError(404);
265
+		if(!$comment) {
266
+			return $this->httpError(404);
267
+		}
258 268
 		if(!$comment->canEdit()) {
259 269
 			return Security::permissionFailure($this, 'You do not have permission to edit this comment');
260 270
 		}
261
-		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
271
+		if(!$comment->getSecurityToken()->checkRequest($this->request)) {
272
+			return $this->httpError(400);
273
+		}
262 274
 
263 275
 		$comment->markApproved();
264 276
 
@@ -272,11 +284,15 @@  discard block
 block discarded – undo
272 284
 	 */
273 285
 	public function approve() {
274 286
 		$comment = $this->getComment();
275
-		if(!$comment) return $this->httpError(404);
287
+		if(!$comment) {
288
+			return $this->httpError(404);
289
+		}
276 290
 		if(!$comment->canEdit()) {
277 291
 			return Security::permissionFailure($this, 'You do not have permission to approve this comment');
278 292
 		}
279
-		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
293
+		if(!$comment->getSecurityToken()->checkRequest($this->request)) {
294
+			return $this->httpError(400);
295
+		}
280 296
 
281 297
 		$comment->markApproved();
282 298
 
@@ -491,7 +507,9 @@  discard block
 block discarded – undo
491 507
 		if(isset($data['ParentID']) && ($class = $this->getBaseClass())) {
492 508
 			$this->setOwnerRecord($class::get()->byID($data['ParentID']));
493 509
 		}
494
-		if(!$this->getOwnerRecord()) return $this->httpError(404);
510
+		if(!$this->getOwnerRecord()) {
511
+			return $this->httpError(404);
512
+		}
495 513
 		
496 514
 		// cache users data
497 515
 		Cookie::set("CommentsForm_UserData", Convert::raw2json($data));
@@ -606,8 +624,12 @@  discard block
 block discarded – undo
606 624
 			}
607 625
 		}
608 626
 
609
-		if(!$url) $url = $this->fallbackReturnURL;
610
-		if(!$url) $url = Director::baseURL();
627
+		if(!$url) {
628
+			$url = $this->fallbackReturnURL;
629
+		}
630
+		if(!$url) {
631
+			$url = Director::baseURL();
632
+		}
611 633
 
612 634
 		// absolute redirection URLs not located on this site may cause phishing
613 635
 		if(Director::is_site_url($url)) {
Please login to merge, or discard this patch.
code/model/Comment.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @param string $key
199 199
 	 *
200
-	 * @return mixed Result if the setting is available, or null otherwise
200
+	 * @return integer Result if the setting is available, or null otherwise
201 201
 	 */
202 202
 	public function getOption($key) {
203 203
 		// If possible use the current record
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 	/**
317 317
 	 * Checks if the comment can be edited.
318 318
 	 *
319
-	 * @param null|int|Member $member
319
+	 * @param DataObject|null $member
320 320
 	 *
321 321
 	 * @return Boolean
322 322
 	 */
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 	/**
347 347
 	 * Checks if the comment can be deleted.
348 348
 	 *
349
-	 * @param null|int|Member $member
349
+	 * @param Member|null $member
350 350
 	 *
351 351
 	 * @return Boolean
352 352
 	 */
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 	 * Resolves Member object.
370 370
 	 *
371 371
 	 * @param Member|int|null $member
372
-	 * @return Member|null
372
+	 * @return DataObject|null
373 373
 	 */
374 374
 	protected function getMember($member = null) {
375 375
 		if(!$member) {
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -709,7 +709,7 @@
 block discarded – undo
709 709
 			|| ($this->getOption('frontend_moderation') && $parent->canModerateComments())
710 710
 		);
711 711
 		if (!$showUnmoderated) {
712
-		    $list = $list->filter('Moderated', 1);
712
+			$list = $list->filter('Moderated', 1);
713 713
 		}
714 714
 
715 715
 		$this->extend('updateReplies', $list);
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		parent::onBeforeWrite();
94 94
 
95 95
 		// Sanitize HTML, because its expected to be passed to the template unescaped later
96
-		if($this->AllowHtml) {
96
+		if ($this->AllowHtml) {
97 97
 			$this->Comment = $this->purifyHtml($this->Comment);
98 98
 		}
99 99
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		parent::onBeforeDelete();
106 106
 
107 107
 		// Delete all children
108
-		foreach($this->ChildComments() as $comment) {
108
+		foreach ($this->ChildComments() as $comment) {
109 109
 			$comment->delete();
110 110
 		}
111 111
 	}
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
 	public function requireDefaultRecords() {
124 124
 		parent::requireDefaultRecords();
125 125
 
126
-		if(DB::getConn()->hasTable('PageComment')) {
126
+		if (DB::getConn()->hasTable('PageComment')) {
127 127
 			$comments = DB::query('SELECT * FROM "PageComment"');
128 128
 
129
-			if($comments) {
130
-				while($pageComment = $comments->nextRecord()) {
129
+			if ($comments) {
130
+				while ($pageComment = $comments->nextRecord()) {
131 131
 					// create a new comment from the older page comment
132 132
 					$comment = new Comment();
133 133
 					$comment->update($pageComment);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 					// set the variables which have changed
136 136
 					$comment->BaseClass = 'SiteTree';
137 137
 					$comment->URL = (isset($pageComment['CommenterURL'])) ? $pageComment['CommenterURL'] : '';
138
-					if((int) $pageComment['NeedsModeration'] == 0) $comment->Moderated = true;
138
+					if ((int) $pageComment['NeedsModeration'] == 0) $comment->Moderated = true;
139 139
 
140 140
 					$comment->write();
141 141
 				}
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @return string link to this comment.
155 155
 	 */
156 156
 	public function Link($action = '') {
157
-		if($parent = $this->getParent()) {
157
+		if ($parent = $this->getParent()) {
158 158
 			return $parent->Link($action) . '#' . $this->Permalink();
159 159
 		}
160 160
 	}
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 		// If possible use the current record
204 204
 		$record = $this->getParent();
205 205
 		
206
-		if(!$record && $this->BaseClass) {
206
+		if (!$record && $this->BaseClass) {
207 207
 			// Otherwise a singleton of that record
208 208
 			$record = singleton($this->BaseClass);
209 209
 		} 
210
-		else if(!$record) {
210
+		else if (!$record) {
211 211
 			// Otherwise just use the default options
212 212
 			$record = singleton('CommentsExtension');
213 213
 		}
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	 * @return string
234 234
 	 */
235 235
 	public function getParentTitle() {
236
-		if($parent = $this->getParent()) {
236
+		if ($parent = $this->getParent()) {
237 237
 			return $parent->Title ?: ($parent->ClassName . ' #' . $parent->ID);
238 238
 		}
239 239
 	}
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 
250 250
 	public function castingHelper($field) {
251 251
 		// Safely escape the comment
252
-		if($field === 'EscapedComment') {
252
+		if ($field === 'EscapedComment') {
253 253
 			return $this->AllowHtml ? 'HTMLText' : 'Text';
254 254
 		}
255 255
 		return parent::castingHelper($field);
@@ -296,15 +296,15 @@  discard block
 block discarded – undo
296 296
 		$member = $this->getMember($member);
297 297
 
298 298
 		$extended = $this->extendedCan('canView', $member);
299
-		if($extended !== null) {
299
+		if ($extended !== null) {
300 300
 			return $extended;
301 301
 		}
302 302
 
303
-		if(Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin')) {
303
+		if (Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin')) {
304 304
 			return true;
305 305
 		}
306 306
 
307
-		if($parent = $this->getParent()) {
307
+		if ($parent = $this->getParent()) {
308 308
 			return $parent->canView($member)
309 309
 				&& $parent->has_extension('CommentsExtension')
310 310
 				&& $parent->CommentsEnabled;
@@ -323,20 +323,20 @@  discard block
 block discarded – undo
323 323
 	public function canEdit($member = null) {
324 324
 		$member = $this->getMember($member);
325 325
 
326
-		if(!$member) {
326
+		if (!$member) {
327 327
 			return false;
328 328
 		}
329 329
 
330 330
 		$extended = $this->extendedCan('canEdit', $member);
331
-		if($extended !== null) {
331
+		if ($extended !== null) {
332 332
 			return $extended;
333 333
 		}
334 334
 
335
-		if(Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin')) {
335
+		if (Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin')) {
336 336
 			return true;
337 337
 		}
338 338
 
339
-		if($parent = $this->getParent()) {
339
+		if ($parent = $this->getParent()) {
340 340
 			return $parent->canEdit($member);
341 341
 		}
342 342
 
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
 	public function canDelete($member = null) {
354 354
 		$member = $this->getMember($member);
355 355
 
356
-		if(!$member) {
356
+		if (!$member) {
357 357
 			return false;
358 358
 		}
359 359
 
360 360
 		$extended = $this->extendedCan('canDelete', $member);
361
-		if($extended !== null) {
361
+		if ($extended !== null) {
362 362
 			return $extended;
363 363
 		}
364 364
 
@@ -372,11 +372,11 @@  discard block
 block discarded – undo
372 372
 	 * @return Member|null
373 373
 	 */
374 374
 	protected function getMember($member = null) {
375
-		if(!$member) {
375
+		if (!$member) {
376 376
 			$member = Member::currentUser();
377 377
 		}
378 378
 
379
-		if(is_numeric($member)) {
379
+		if (is_numeric($member)) {
380 380
 			$member = DataObject::get_by_id('Member', $member, true);
381 381
 		}
382 382
 
@@ -389,9 +389,9 @@  discard block
 block discarded – undo
389 389
 	 * @return string
390 390
 	 */
391 391
 	public function getAuthorName() {
392
-		if($this->Name) {
392
+		if ($this->Name) {
393 393
 			return $this->Name;
394
-		} else if($author = $this->Author()) {
394
+		} else if ($author = $this->Author()) {
395 395
 			return $author->getName();
396 396
 		}
397 397
 	}
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
 	 * @return string
406 406
 	 */
407 407
 	protected function actionLink($action, $member = null) {
408
-		if(!$member) $member = Member::currentUser();
409
-		if(!$member) return false;
408
+		if (!$member) $member = Member::currentUser();
409
+		if (!$member) return false;
410 410
 
411 411
 		$url = Controller::join_links(
412 412
 			Director::baseURL(),
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 	 * @return string
429 429
 	 */
430 430
 	public function DeleteLink($member = null) {
431
-		if($this->canDelete($member)) {
431
+		if ($this->canDelete($member)) {
432 432
 			return $this->actionLink('delete', $member);
433 433
 		}
434 434
 	}
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 	 * @return string
442 442
 	 */
443 443
 	public function SpamLink($member = null) {
444
-		if($this->canEdit($member) && !$this->IsSpam) {
444
+		if ($this->canEdit($member) && !$this->IsSpam) {
445 445
 			return $this->actionLink('spam', $member);
446 446
 		}
447 447
 	}
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 * @return string
455 455
 	 */
456 456
 	public function HamLink($member = null) {
457
-		if($this->canEdit($member) && $this->IsSpam) {
457
+		if ($this->canEdit($member) && $this->IsSpam) {
458 458
 			return $this->actionLink('ham', $member);
459 459
 		}
460 460
 	}
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	 * @return string
468 468
 	 */
469 469
 	public function ApproveLink($member = null) {
470
-		if($this->canEdit($member) && !$this->Moderated) {
470
+		if ($this->canEdit($member) && !$this->Moderated) {
471 471
 			return $this->actionLink('approve', $member);
472 472
 		}
473 473
 	}
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
 	 * @return string
506 506
 	 */
507 507
 	public function SpamClass() {
508
-		if($this->IsSpam) {
508
+		if ($this->IsSpam) {
509 509
 			return 'spam';
510
-		} else if(!$this->Moderated) {
510
+		} else if (!$this->Moderated) {
511 511
 			return 'unmoderated';
512 512
 		} else {
513 513
 			return 'notspam';
@@ -520,8 +520,8 @@  discard block
 block discarded – undo
520 520
 	public function getTitle() {
521 521
 		$title = sprintf(_t('Comment.COMMENTBY', 'Comment by %s', 'Name'), $this->getAuthorName());
522 522
 
523
-		if($parent = $this->getParent()) {
524
-			if($parent->Title) {
523
+		if ($parent = $this->getParent()) {
524
+			if ($parent->Title) {
525 525
 				$title .= sprintf(' %s %s', _t('Comment.ON', 'on'), $parent->Title);
526 526
 			}
527 527
 		}
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
 		);
556 556
 
557 557
 		// Show member name if given
558
-		if(($author = $this->Author()) && $author->exists()) {
558
+		if (($author = $this->Author()) && $author->exists()) {
559 559
 			$fields->insertAfter(
560 560
 				TextField::create('AuthorMember', $this->fieldLabel('Author'), $author->Title)
561 561
 					->performReadonlyTransformation(),
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
 		}
565 565
 
566 566
 		// Show parent comment if given
567
-		if(($parent = $this->ParentComment()) && $parent->exists()) {
567
+		if (($parent = $this->ParentComment()) && $parent->exists()) {
568 568
 			$fields->push(new HeaderField(
569 569
 				'ParentComment_Title',
570 570
 				_t('Comment.ParentComment_Title', 'This comment is a reply to the below')
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 	public function Gravatar() {
636 636
 		$gravatar = '';
637 637
 		$use_gravatar = $this->getOption('use_gravatar');
638
-		if($use_gravatar) {
638
+		if ($use_gravatar) {
639 639
 			$gravatar = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($this->Email)));
640 640
 			$gravatarsize = $this->getOption('gravatar_size');
641 641
 			$gravatardefault = $this->getOption('gravatar_default');
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 	 */
654 654
 	public function getRepliesEnabled() {
655 655
 		// Check reply option
656
-		if(!$this->getOption('nested_comments')) {
656
+		if (!$this->getOption('nested_comments')) {
657 657
 			return false;
658 658
 		}
659 659
 
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 	 */
670 670
 	public function AllReplies() {
671 671
 		// No replies if disabled
672
-		if(!$this->getRepliesEnabled()) {
672
+		if (!$this->getRepliesEnabled()) {
673 673
 			return new ArrayList();
674 674
 		}
675 675
 		
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 	 */
692 692
 	public function Replies() {
693 693
 		// No replies if disabled
694
-		if(!$this->getRepliesEnabled()) {
694
+		if (!$this->getRepliesEnabled()) {
695 695
 			return new ArrayList();
696 696
 		}
697 697
 		$list = $this->AllReplies();
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
 		// Filter spam comments for non-administrators if configured
700 700
 		$parent = $this->getParent();
701 701
 		$showSpam = $this->getOption('frontend_spam') && $parent && $parent->canModerateComments();
702
-		if(!$showSpam) {
702
+		if (!$showSpam) {
703 703
 			$list = $list->filter('IsSpam', 0);
704 704
 		}
705 705
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 
727 727
 		// Add pagination
728 728
 		$list = new PaginatedList($list, Controller::curr()->getRequest());
729
-		$list->setPaginationGetVar('repliesstart'.$this->ID);
729
+		$list->setPaginationGetVar('repliesstart' . $this->ID);
730 730
 		$list->setPageLength($this->getOption('comments_per_page'));
731 731
 
732 732
 		$this->extend('updatePagedReplies', $list);
@@ -740,13 +740,13 @@  discard block
 block discarded – undo
740 740
 	 */
741 741
 	public function ReplyForm() {
742 742
 		// Ensure replies are enabled
743
-		if(!$this->getRepliesEnabled()) {
743
+		if (!$this->getRepliesEnabled()) {
744 744
 			return null;
745 745
 		}
746 746
 
747 747
 		// Check parent is available
748 748
 		$parent = $this->getParent();
749
-		if(!$parent || !$parent->exists()) {
749
+		if (!$parent || !$parent->exists()) {
750 750
 			return null;
751 751
 		}
752 752
 
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 	 */
765 765
 	public function updateDepth() {
766 766
 		$parent = $this->ParentComment();
767
-		if($parent && $parent->exists()) {
767
+		if ($parent && $parent->exists()) {
768 768
 			$parent->updateDepth();
769 769
 			$this->Depth = $parent->Depth + 1;
770 770
 		} else {
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 	 * @param Comment $comment Comment to generate this token for
786 786
 	 */
787 787
 	public function __construct($comment) {
788
-		if(!$comment->SecretToken) {
788
+		if (!$comment->SecretToken) {
789 789
 			$comment->SecretToken = $this->generate();
790 790
 			$comment->write();
791 791
 		}
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 */
849 849
 	public function checkRequest($request) {
850 850
 		$member = Member::currentUser();
851
-		if(!$member) return false;
851
+		if (!$member) return false;
852 852
 
853 853
 		$salt = $request->getVar('s');
854 854
 		$memberSalt = $this->memberSalt($salt, $member);
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 	protected function generate($length = null) {
870 870
 		$generator = new RandomGenerator();
871 871
 		$result = $generator->randomToken('sha256');
872
-		if($length !== null) return substr($result, 0, $length);
872
+		if ($length !== null) return substr($result, 0, $length);
873 873
 		return $result;
874 874
 	}
875 875
 }
Please login to merge, or discard this patch.
Braces   +16 added lines, -7 removed lines patch added patch discarded remove patch
@@ -135,7 +135,9 @@  discard block
 block discarded – undo
135 135
 					// set the variables which have changed
136 136
 					$comment->BaseClass = 'SiteTree';
137 137
 					$comment->URL = (isset($pageComment['CommenterURL'])) ? $pageComment['CommenterURL'] : '';
138
-					if((int) $pageComment['NeedsModeration'] == 0) $comment->Moderated = true;
138
+					if((int) $pageComment['NeedsModeration'] == 0) {
139
+						$comment->Moderated = true;
140
+					}
139 141
 
140 142
 					$comment->write();
141 143
 				}
@@ -206,8 +208,7 @@  discard block
 block discarded – undo
206 208
 		if(!$record && $this->BaseClass) {
207 209
 			// Otherwise a singleton of that record
208 210
 			$record = singleton($this->BaseClass);
209
-		} 
210
-		else if(!$record) {
211
+		} else if(!$record) {
211 212
 			// Otherwise just use the default options
212 213
 			$record = singleton('CommentsExtension');
213 214
 		}
@@ -405,8 +406,12 @@  discard block
 block discarded – undo
405 406
 	 * @return string
406 407
 	 */
407 408
 	protected function actionLink($action, $member = null) {
408
-		if(!$member) $member = Member::currentUser();
409
-		if(!$member) return false;
409
+		if(!$member) {
410
+			$member = Member::currentUser();
411
+		}
412
+		if(!$member) {
413
+			return false;
414
+		}
410 415
 
411 416
 		$url = Controller::join_links(
412 417
 			Director::baseURL(),
@@ -848,7 +853,9 @@  discard block
 block discarded – undo
848 853
 	 */
849 854
 	public function checkRequest($request) {
850 855
 		$member = Member::currentUser();
851
-		if(!$member) return false;
856
+		if(!$member) {
857
+			return false;
858
+		}
852 859
 
853 860
 		$salt = $request->getVar('s');
854 861
 		$memberSalt = $this->memberSalt($salt, $member);
@@ -869,7 +876,9 @@  discard block
 block discarded – undo
869 876
 	protected function generate($length = null) {
870 877
 		$generator = new RandomGenerator();
871 878
 		$result = $generator->randomToken('sha256');
872
-		if($length !== null) return substr($result, 0, $length);
879
+		if($length !== null) {
880
+			return substr($result, 0, $length);
881
+		}
873 882
 		return $result;
874 883
 	}
875 884
 }
Please login to merge, or discard this patch.
code/admin/CommentsGridFieldBulkAction.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	public function spam(SS_HTTPRequest $request) {
29 29
 		$ids = array();
30 30
 
31
-		foreach($this->getRecords() as $record) {
31
+		foreach ($this->getRecords() as $record) {
32 32
 			array_push($ids, $record->ID);
33 33
 			$record->markSpam();
34 34
 		}
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	public function approve(SS_HTTPRequest $request) {
48 48
 		$ids = array();
49 49
 
50
-		foreach($this->getRecords() as $record) {
50
+		foreach ($this->getRecords() as $record) {
51 51
 			array_push($ids, $record->ID);
52 52
 			$record->markApproved();
53 53
 		}
Please login to merge, or discard this patch.
code/admin/CommentsGridField.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@
 block discarded – undo
5 5
 	 * {@inheritdoc}
6 6
 	 */
7 7
 	protected function newRow($total, $index, $record, $attributes, $content) {
8
-		if(!isset($attributes['class'])) {
8
+		if (!isset($attributes['class'])) {
9 9
 			$attributes['class'] = '';
10 10
 		}
11 11
 
12
-		if($record->IsSpam) {
12
+		if ($record->IsSpam) {
13 13
 			$attributes['class'] .= ' spam';
14 14
 		}
15 15
 
Please login to merge, or discard this patch.
code/admin/CommentAdmin.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 	 * @return Form
38 38
 	 */
39 39
 	public function getEditForm($id = null, $fields = null) {
40
-		if(!$id) $id = $this->currentPageID();
40
+		if (!$id) $id = $this->currentPageID();
41 41
 
42 42
 		$form = parent::getEditForm($id);
43 43
 		$record = $this->getRecord($id);
44 44
 
45
-		if($record && !$record->canView()) {
45
+		if ($record && !$record->canView()) {
46 46
 			return Security::permissionFailure($this);
47 47
 		}
48 48
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 		$form->addExtraClass('cms-edit-form');
107 107
 		$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
108 108
 
109
-		if($form->Fields()->hasTabset()) {
109
+		if ($form->Fields()->hasTabset()) {
110 110
 			$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
111 111
 			$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
112 112
 		}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,9 @@
 block discarded – undo
37 37
 	 * @return Form
38 38
 	 */
39 39
 	public function getEditForm($id = null, $fields = null) {
40
-		if(!$id) $id = $this->currentPageID();
40
+		if(!$id) {
41
+			$id = $this->currentPageID();
42
+		}
41 43
 
42 44
 		$form = parent::getEditForm($id);
43 45
 		$record = $this->getRecord($id);
Please login to merge, or discard this patch.
code/admin/CommentsGridFieldAction.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 	 * {@inheritdoc}
6 6
 	 */
7 7
 	public function augmentColumns($gridField, &$columns) {
8
-		if(!in_array('Actions', $columns)) {
8
+		if (!in_array('Actions', $columns)) {
9 9
 			$columns[] = 'Actions';
10 10
 		}
11 11
 	}
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * {@inheritdoc}
22 22
 	 */
23 23
 	public function getColumnMetadata($gridField, $columnName) {
24
-		if($columnName == 'Actions') {
24
+		if ($columnName == 'Actions') {
25 25
 			return array('title' => '');
26 26
 		}
27 27
 	}
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	 * {@inheritdoc}
38 38
 	 */
39 39
 	public function getColumnContent($gridField, $record, $columnName) {
40
-		if(!$record->canEdit()) return;
40
+		if (!$record->canEdit()) return;
41 41
 
42 42
 		$field = "";
43 43
 
44
-		if(!$record->IsSpam || !$record->Moderated) {
44
+		if (!$record->IsSpam || !$record->Moderated) {
45 45
 			$field .= GridField_FormAction::create(
46 46
 				$gridField,
47 47
 				'CustomAction' . $record->ID . 'Spam',
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 			)->Field();
52 52
 		}
53 53
 
54
-		if($record->IsSpam || !$record->Moderated) {
54
+		if ($record->IsSpam || !$record->Moderated) {
55 55
 			$field .= GridField_FormAction::create(
56 56
 				$gridField,
57 57
 				'CustomAction' . $record->ID . 'Approve',
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * {@inheritdoc}
76 76
 	 */
77 77
 	public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
78
-		if($actionName == 'spam') {
78
+		if ($actionName == 'spam') {
79 79
 			$comment = Comment::get()->byID($arguments["RecordID"]);
80 80
 			$comment->markSpam();
81 81
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			);
87 87
 		}
88 88
 
89
-		if($actionName == 'approve') {
89
+		if ($actionName == 'approve') {
90 90
 			$comment = Comment::get()->byID($arguments["RecordID"]);
91 91
 			$comment->markApproved();
92 92
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,9 @@
 block discarded – undo
37 37
 	 * {@inheritdoc}
38 38
 	 */
39 39
 	public function getColumnContent($gridField, $record, $columnName) {
40
-		if(!$record->canEdit()) return;
40
+		if(!$record->canEdit()) {
41
+			return;
42
+		}
41 43
 
42 44
 		$field = "";
43 45
 
Please login to merge, or discard this patch.
code/extensions/CommentsExtension.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -82,25 +82,25 @@  discard block
 block discarded – undo
82 82
 		$defaults = $this->owner->config()->defaults;
83 83
 		
84 84
 		// Set if comments should be enabled by default
85
-		if(isset($defaults['ProvideComments'])) {
85
+		if (isset($defaults['ProvideComments'])) {
86 86
 			$this->owner->ProvideComments = $defaults['ProvideComments'];
87 87
 		} else {
88 88
 			$this->owner->ProvideComments = $this->owner->getCommentsOption('enabled') ? 1 : 0;
89 89
 		}
90 90
 
91 91
 		// If moderation options should be configurable via the CMS then
92
-		if(isset($defaults['ModerationRequired'])) {
92
+		if (isset($defaults['ModerationRequired'])) {
93 93
 			$this->owner->ModerationRequired = $defaults['ModerationRequired'];
94
-		} elseif($this->owner->getCommentsOption('require_moderation')) {
94
+		} elseif ($this->owner->getCommentsOption('require_moderation')) {
95 95
 			$this->owner->ModerationRequired = 'Required';
96
-		} elseif($this->owner->getCommentsOption('require_moderation_nonmembers')) {
96
+		} elseif ($this->owner->getCommentsOption('require_moderation_nonmembers')) {
97 97
 			$this->owner->ModerationRequired = 'NonMembersOnly';
98 98
 		} else {
99 99
 			$this->owner->ModerationRequired = 'None';
100 100
 		}
101 101
 
102 102
 		// Set login required
103
-		if(isset($defaults['CommentsRequireLogin'])) {
103
+		if (isset($defaults['CommentsRequireLogin'])) {
104 104
 			$this->owner->CommentsRequireLogin = $defaults['CommentsRequireLogin'];
105 105
 		} else {
106 106
 			$this->owner->CommentsRequireLogin = $this->owner->getCommentsOption('require_login') ? 1 : 0;
@@ -122,12 +122,12 @@  discard block
 block discarded – undo
122 122
 		$options = FieldGroup::create()->setTitle(_t('CommentsExtension.COMMENTOPTIONS', 'Comments'));
123 123
 
124 124
 		// Check if enabled setting should be cms configurable
125
-		if($this->owner->getCommentsOption('enabled_cms')) {
125
+		if ($this->owner->getCommentsOption('enabled_cms')) {
126 126
 			$options->push(new CheckboxField('ProvideComments', _t('Comment.ALLOWCOMMENTS', 'Allow Comments')));
127 127
 		}
128 128
 
129 129
 		// Check if we should require users to login to comment
130
-		if($this->owner->getCommentsOption('require_login_cms')) {
130
+		if ($this->owner->getCommentsOption('require_login_cms')) {
131 131
 			$options->push(
132 132
 				new CheckboxField(
133 133
 					'CommentsRequireLogin',
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 			);
137 137
 		}
138 138
 
139
-		if($options->FieldList()->count()) {
140
-			if($fields->hasTabSet()) {
139
+		if ($options->FieldList()->count()) {
140
+			if ($fields->hasTabSet()) {
141 141
 				$fields->addFieldsToTab('Root.Settings', $options);
142 142
 			} else {
143 143
 				$fields->push($options);
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		}
146 146
 
147 147
 		// Check if moderation should be enabled via cms configurable
148
-		if($this->owner->getCommentsOption('require_moderation_cms')) {
148
+		if ($this->owner->getCommentsOption('require_moderation_cms')) {
149 149
 			$moderationField = new DropdownField('ModerationRequired', 'Comment Moderation', array(
150 150
 				'None' => _t('CommentsExtension.MODERATIONREQUIRED_NONE', 'No moderation required'),
151 151
 				'Required' => _t('CommentsExtension.MODERATIONREQUIRED_REQUIRED', 'Moderate all comments'),
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 					'Only moderate non-members'
155 155
 				),
156 156
 			));
157
-			if($fields->hasTabSet()) {
157
+			if ($fields->hasTabSet()) {
158 158
 				$fields->addFieldsToTab('Root.Settings', $moderationField);
159 159
 			} else {
160 160
 				$fields->push($moderationField);
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	 * @return string
173 173
 	 */
174 174
 	public function getModerationRequired() {
175
-		if($this->owner->getCommentsOption('require_moderation_cms')) {
175
+		if ($this->owner->getCommentsOption('require_moderation_cms')) {
176 176
 			return $this->owner->getField('ModerationRequired');
177
-		} elseif($this->owner->getCommentsOption('require_moderation')) {
177
+		} elseif ($this->owner->getCommentsOption('require_moderation')) {
178 178
 			return 'Required';
179
-		} elseif($this->owner->getCommentsOption('require_moderation_nonmembers')) {
179
+		} elseif ($this->owner->getCommentsOption('require_moderation_nonmembers')) {
180 180
 			return 'NonMembersOnly';
181 181
 		} else {
182 182
 			return 'None';
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @return boolean
190 190
 	 */
191 191
 	public function getCommentsRequireLogin() {
192
-		if($this->owner->getCommentsOption('require_login_cms')) {
192
+		if ($this->owner->getCommentsOption('require_login_cms')) {
193 193
 			return (bool) $this->owner->getField('CommentsRequireLogin');
194 194
 		} else {
195 195
 			return (bool) $this->owner->getCommentsOption('require_login');
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 
222 222
 		// Filter spam comments for non-administrators if configured
223 223
 		$showSpam = $this->owner->getCommentsOption('frontend_spam') && $this->owner->canModerateComments();
224
-		if(!$showSpam) {
224
+		if (!$showSpam) {
225 225
 			$list = $list->filter('IsSpam', 0);
226 226
 		}
227 227
 
228 228
 		// Filter un-moderated comments for non-administrators if moderation is enabled
229 229
 		$showUnmoderated = ($this->owner->ModerationRequired === 'None')
230 230
 			|| ($this->owner->getCommentsOption('frontend_moderation') && $this->owner->canModerateComments());
231
-		if(!$showUnmoderated) {
231
+		if (!$showUnmoderated) {
232 232
 			$list = $list->filter('Moderated', 1);
233 233
 		}
234 234
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 		$list = $this->AllVisibleComments();
246 246
 
247 247
 		// If nesting comments, only show root level
248
-		if($this->owner->getCommentsOption('nested_comments')) {
248
+		if ($this->owner->getCommentsOption('nested_comments')) {
249 249
 			$list = $list->filter('ParentCommentID', 0);
250 250
 		}
251 251
 
@@ -291,10 +291,10 @@  discard block
 block discarded – undo
291 291
 	 */
292 292
 	public function getCommentsEnabled() {
293 293
 		// Don't display comments form for pseudo-pages (such as the login form)
294
-		if(!$this->owner->exists()) return false;
294
+		if (!$this->owner->exists()) return false;
295 295
 		
296 296
 		// Determine which flag should be used to determine if this is enabled
297
-		if($this->owner->getCommentsOption('enabled_cms')) {
297
+		if ($this->owner->getCommentsOption('enabled_cms')) {
298 298
 			return $this->owner->ProvideComments;
299 299
 		} else {
300 300
 			return $this->owner->getCommentsOption('enabled');
@@ -341,19 +341,19 @@  discard block
 block discarded – undo
341 341
 	 */
342 342
 	public function canPostComment($member = null) {
343 343
 		// Deny if not enabled for this object
344
-		if(!$this->owner->CommentsEnabled) return false;
344
+		if (!$this->owner->CommentsEnabled) return false;
345 345
 
346 346
 		// Check if member is required
347 347
 		$requireLogin = $this->owner->CommentsRequireLogin;
348
-		if(!$requireLogin) return true;
348
+		if (!$requireLogin) return true;
349 349
 
350 350
 		// Check member is logged in
351 351
 		$member = $member ?: Member::currentUser();
352
-		if(!$member) return false;
352
+		if (!$member) return false;
353 353
 
354 354
 		// If member required check permissions
355 355
 		$requiredPermission = $this->owner->PostingRequiredPermission;
356
-		if($requiredPermission && !Permission::checkMember($member, $requiredPermission)) return false;
356
+		if ($requiredPermission && !Permission::checkMember($member, $requiredPermission)) return false;
357 357
 
358 358
 		return true;
359 359
 	}
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 	 */
368 368
 	public function canModerateComments($member = null) {
369 369
 		// Deny if not enabled for this object
370
-		if(!$this->owner->CommentsEnabled) return false;
370
+		if (!$this->owner->CommentsEnabled) return false;
371 371
 
372 372
 		// Fallback to can-edit
373 373
 		return $this->owner->canEdit($member);
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 	public function CommentsForm() {
418 418
 		// Check if enabled
419 419
 		$enabled = $this->getCommentsEnabled();
420
-		if($enabled && $this->owner->getCommentsOption('include_js')) {
420
+		if ($enabled && $this->owner->getCommentsOption('include_js')) {
421 421
 			Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
422 422
 			Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
423 423
 			Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js');
@@ -480,10 +480,10 @@  discard block
 block discarded – undo
480 480
 			? $this->owner->config()->comments
481 481
 			: Config::inst()->get(__CLASS__, 'comments');
482 482
 		$value = null;
483
-		if(isset($settings[$key])) $value = $settings[$key];
483
+		if (isset($settings[$key])) $value = $settings[$key];
484 484
 
485 485
 		// To allow other extensions to customise this option
486
-		if($this->owner) $this->owner->extend('updateCommentsOption', $key, $value);
486
+		if ($this->owner) $this->owner->extend('updateCommentsOption', $key, $value);
487 487
 		return $value;
488 488
 	}
489 489
 
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 		$approvedCount = '(' . count($approvedComments) . ')';
527 527
 		$spamCount = '(' . count($spamComments) . ')';
528 528
 
529
-		if($fields->hasTabSet()) {
529
+		if ($fields->hasTabSet()) {
530 530
 			$tabs = new TabSet(
531 531
 				'Comments',
532 532
 				new Tab('CommentsNewCommentsTab', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount,
@@ -549,12 +549,12 @@  discard block
 block discarded – undo
549 549
 
550 550
 	public function updateCMSFields(FieldList $fields) {
551 551
 		// Disable moderation if not permitted
552
-		if($this->owner->canModerateComments()) {
552
+		if ($this->owner->canModerateComments()) {
553 553
 			$this->updateModerationFields($fields);
554 554
 		}
555 555
 
556 556
 		// If this isn't a page we should merge the settings into the CMS fields
557
-		if(!$this->attachedToSiteTree()) {
557
+		if (!$this->attachedToSiteTree()) {
558 558
 			$this->updateSettingsFields($fields);
559 559
 		}
560 560
 	}
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -291,7 +291,9 @@  discard block
 block discarded – undo
291 291
 	 */
292 292
 	public function getCommentsEnabled() {
293 293
 		// Don't display comments form for pseudo-pages (such as the login form)
294
-		if(!$this->owner->exists()) return false;
294
+		if(!$this->owner->exists()) {
295
+			return false;
296
+		}
295 297
 		
296 298
 		// Determine which flag should be used to determine if this is enabled
297 299
 		if($this->owner->getCommentsOption('enabled_cms')) {
@@ -341,19 +343,27 @@  discard block
 block discarded – undo
341 343
 	 */
342 344
 	public function canPostComment($member = null) {
343 345
 		// Deny if not enabled for this object
344
-		if(!$this->owner->CommentsEnabled) return false;
346
+		if(!$this->owner->CommentsEnabled) {
347
+			return false;
348
+		}
345 349
 
346 350
 		// Check if member is required
347 351
 		$requireLogin = $this->owner->CommentsRequireLogin;
348
-		if(!$requireLogin) return true;
352
+		if(!$requireLogin) {
353
+			return true;
354
+		}
349 355
 
350 356
 		// Check member is logged in
351 357
 		$member = $member ?: Member::currentUser();
352
-		if(!$member) return false;
358
+		if(!$member) {
359
+			return false;
360
+		}
353 361
 
354 362
 		// If member required check permissions
355 363
 		$requiredPermission = $this->owner->PostingRequiredPermission;
356
-		if($requiredPermission && !Permission::checkMember($member, $requiredPermission)) return false;
364
+		if($requiredPermission && !Permission::checkMember($member, $requiredPermission)) {
365
+			return false;
366
+		}
357 367
 
358 368
 		return true;
359 369
 	}
@@ -367,7 +377,9 @@  discard block
 block discarded – undo
367 377
 	 */
368 378
 	public function canModerateComments($member = null) {
369 379
 		// Deny if not enabled for this object
370
-		if(!$this->owner->CommentsEnabled) return false;
380
+		if(!$this->owner->CommentsEnabled) {
381
+			return false;
382
+		}
371 383
 
372 384
 		// Fallback to can-edit
373 385
 		return $this->owner->canEdit($member);
@@ -480,10 +492,14 @@  discard block
 block discarded – undo
480 492
 			? $this->owner->config()->comments
481 493
 			: Config::inst()->get(__CLASS__, 'comments');
482 494
 		$value = null;
483
-		if(isset($settings[$key])) $value = $settings[$key];
495
+		if(isset($settings[$key])) {
496
+			$value = $settings[$key];
497
+		}
484 498
 
485 499
 		// To allow other extensions to customise this option
486
-		if($this->owner) $this->owner->extend('updateCommentsOption', $key, $value);
500
+		if($this->owner) {
501
+			$this->owner->extend('updateCommentsOption', $key, $value);
502
+		}
487 503
 		return $value;
488 504
 	}
489 505
 
Please login to merge, or discard this patch.
code/model/CommentList.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	public function add($item) {
42 42
 		// Check item given
43
-		if(is_numeric($item)) {
43
+		if (is_numeric($item)) {
44 44
 			$item = Comment::get()->byID($item);
45 45
 		}
46
-		if(!($item instanceof Comment)) {
46
+		if (!($item instanceof Comment)) {
47 47
 			throw new InvalidArgumentException("CommentList::add() expecting a Comment object, or ID value");
48 48
 		}
49 49
 		
50 50
 		// Validate foreignID
51 51
 		$foreignID = $this->getForeignID();
52
-		if(!$foreignID || is_array($foreignID)) {
52
+		if (!$foreignID || is_array($foreignID)) {
53 53
 			throw new InvalidArgumentException("CommentList::add() can't be called until a single foreign ID is set");
54 54
 		}
55 55
 
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function remove($item) {
66 66
 		// Check item given
67
-		if(is_numeric($item)) {
67
+		if (is_numeric($item)) {
68 68
 			$item = Comment::get()->byID($item);
69 69
 		}
70
-		if(!($item instanceof Comment)) {
70
+		if (!($item instanceof Comment)) {
71 71
 			throw new InvalidArgumentException("CommentList::remove() expecting a Comment object, or ID",
72 72
 				E_USER_ERROR);
73 73
 		}
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
 		// Don't remove item with unrelated class key
76 76
 		$foreignClass = $this->getForeignClass();
77 77
 		$classNames = ClassInfo::subclassesFor($foreignClass);
78
-		if(!in_array($item->BaseClass, $classNames)) return;
78
+		if (!in_array($item->BaseClass, $classNames)) return;
79 79
 		
80 80
 		// Don't remove item which doesn't belong to this list
81 81
 		$foreignID = $this->getForeignID();
82
-		if(	empty($foreignID)
82
+		if (empty($foreignID)
83 83
 			|| (is_array($foreignID) && in_array($item->ParentID, $foreignID))
84 84
 			|| $foreignID == $item->ParentID
85 85
 		) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,9 @@
 block discarded – undo
75 75
 		// Don't remove item with unrelated class key
76 76
 		$foreignClass = $this->getForeignClass();
77 77
 		$classNames = ClassInfo::subclassesFor($foreignClass);
78
-		if(!in_array($item->BaseClass, $classNames)) return;
78
+		if(!in_array($item->BaseClass, $classNames)) {
79
+			return;
80
+		}
79 81
 		
80 82
 		// Don't remove item which doesn't belong to this list
81 83
 		$foreignID = $this->getForeignID();
Please login to merge, or discard this patch.