@@ -116,7 +116,7 @@ |
||
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); |
@@ -31,8 +31,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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'); |
@@ -31,7 +31,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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'); |
@@ -28,7 +28,7 @@ discard block |
||
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 |
||
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 | } |
@@ -5,11 +5,11 @@ |
||
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 |
@@ -37,12 +37,12 @@ discard block |
||
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 |
||
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 | } |
@@ -37,7 +37,9 @@ |
||
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); |
@@ -5,7 +5,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -37,7 +37,9 @@ |
||
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 |
@@ -218,11 +218,15 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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)) { |
@@ -120,7 +120,7 @@ discard block |
||
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 |
@@ -280,6 +280,7 @@ discard block |
||
280 | 280 | * Redirect back to referer if available, ensuring that only site URLs |
281 | 281 | * are allowed to avoid phishing. If it's an AJAX request render the |
282 | 282 | * comment in it's new state |
283 | + * @param DataObject $comment |
|
283 | 284 | */ |
284 | 285 | private function renderChangedCommentState($comment) { |
285 | 286 | $referer = $this->request->getHeader('Referer'); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400); |
244 | 244 | |
245 | 245 | $comment->markSpam(); |
246 | - return $this->renderChangedCommentState($comment); |
|
246 | + return $this->renderChangedCommentState($comment); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400); |
259 | 259 | |
260 | 260 | $comment->markApproved(); |
261 | - return $this->renderChangedCommentState($comment); |
|
261 | + return $this->renderChangedCommentState($comment); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -273,36 +273,36 @@ discard block |
||
273 | 273 | if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400); |
274 | 274 | |
275 | 275 | $comment->markApproved(); |
276 | - return $this->renderChangedCommentState($comment); |
|
276 | + return $this->renderChangedCommentState($comment); |
|
277 | 277 | } |
278 | 278 | |
279 | - /** |
|
280 | - * Redirect back to referer if available, ensuring that only site URLs |
|
281 | - * are allowed to avoid phishing. If it's an AJAX request render the |
|
282 | - * comment in it's new state |
|
283 | - */ |
|
284 | - private function renderChangedCommentState($comment) { |
|
285 | - $referer = $this->request->getHeader('Referer'); |
|
286 | - |
|
287 | - // Render comment using AJAX |
|
288 | - if ($this->request->isAjax()) { |
|
289 | - return $comment->renderWith('CommentsInterface_singlecomment'); |
|
290 | - } else { |
|
291 | - // Redirect to either the comment or start of the page |
|
292 | - if (empty($referer)) { |
|
293 | - return $this->redirectBack(); |
|
294 | - } else { |
|
295 | - // Redirect to the comment, but check for phishing |
|
296 | - $url = $referer . '#comment-' . $comment->ID; |
|
297 | - // absolute redirection URLs not located on this site may cause phishing |
|
298 | - if(Director::is_site_url($url)) { |
|
299 | - return $this->redirect($url); |
|
300 | - } else { |
|
301 | - return false; |
|
302 | - } |
|
303 | - } |
|
304 | - } |
|
305 | - } |
|
279 | + /** |
|
280 | + * Redirect back to referer if available, ensuring that only site URLs |
|
281 | + * are allowed to avoid phishing. If it's an AJAX request render the |
|
282 | + * comment in it's new state |
|
283 | + */ |
|
284 | + private function renderChangedCommentState($comment) { |
|
285 | + $referer = $this->request->getHeader('Referer'); |
|
286 | + |
|
287 | + // Render comment using AJAX |
|
288 | + if ($this->request->isAjax()) { |
|
289 | + return $comment->renderWith('CommentsInterface_singlecomment'); |
|
290 | + } else { |
|
291 | + // Redirect to either the comment or start of the page |
|
292 | + if (empty($referer)) { |
|
293 | + return $this->redirectBack(); |
|
294 | + } else { |
|
295 | + // Redirect to the comment, but check for phishing |
|
296 | + $url = $referer . '#comment-' . $comment->ID; |
|
297 | + // absolute redirection URLs not located on this site may cause phishing |
|
298 | + if(Director::is_site_url($url)) { |
|
299 | + return $this->redirect($url); |
|
300 | + } else { |
|
301 | + return false; |
|
302 | + } |
|
303 | + } |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | 307 | /** |
308 | 308 | * Returns the comment referenced in the URL (by ID). Permission checking |
@@ -124,12 +124,12 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | return $this->renderChangedCommentState($comment); |
@@ -251,11 +251,11 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function ham() { |
253 | 253 | $comment = $this->getComment(); |
254 | - if(!$comment) return $this->httpError(404); |
|
255 | - if(!$comment->canEdit()) { |
|
254 | + if (!$comment) return $this->httpError(404); |
|
255 | + if (!$comment->canEdit()) { |
|
256 | 256 | return Security::permissionFailure($this, 'You do not have permission to edit this comment'); |
257 | 257 | } |
258 | - if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400); |
|
258 | + if (!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400); |
|
259 | 259 | |
260 | 260 | $comment->markApproved(); |
261 | 261 | return $this->renderChangedCommentState($comment); |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | */ |
267 | 267 | public function approve() { |
268 | 268 | $comment = $this->getComment(); |
269 | - if(!$comment) return $this->httpError(404); |
|
270 | - if(!$comment->canEdit()) { |
|
269 | + if (!$comment) return $this->httpError(404); |
|
270 | + if (!$comment->canEdit()) { |
|
271 | 271 | return Security::permissionFailure($this, 'You do not have permission to approve this comment'); |
272 | 272 | } |
273 | - if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400); |
|
273 | + if (!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400); |
|
274 | 274 | |
275 | 275 | $comment->markApproved(); |
276 | 276 | return $this->renderChangedCommentState($comment); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | // Redirect to the comment, but check for phishing |
296 | 296 | $url = $referer . '#comment-' . $comment->ID; |
297 | 297 | // absolute redirection URLs not located on this site may cause phishing |
298 | - if(Director::is_site_url($url)) { |
|
298 | + if (Director::is_site_url($url)) { |
|
299 | 299 | return $this->redirect($url); |
300 | 300 | } else { |
301 | 301 | return false; |
@@ -313,10 +313,10 @@ discard block |
||
313 | 313 | public function getComment() { |
314 | 314 | $id = isset($this->urlParams['ID']) ? $this->urlParams['ID'] : false; |
315 | 315 | |
316 | - if($id) { |
|
316 | + if ($id) { |
|
317 | 317 | $comment = DataObject::get_by_id('Comment', $id); |
318 | 318 | |
319 | - if($comment) { |
|
319 | + if ($comment) { |
|
320 | 320 | $this->fallbackReturnURL = $comment->Link(); |
321 | 321 | return $comment; |
322 | 322 | } |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | public function ReplyForm($comment) { |
334 | 334 | // Enables multiple forms with different names to use the same handler |
335 | 335 | $form = $this->CommentsForm(); |
336 | - $form->setName('ReplyForm_'.$comment->ID); |
|
336 | + $form->setName('ReplyForm_' . $comment->ID); |
|
337 | 337 | $form->addExtraClass('reply-form'); |
338 | 338 | |
339 | 339 | // Load parent into reply form |
@@ -357,9 +357,9 @@ discard block |
||
357 | 357 | */ |
358 | 358 | public function reply(SS_HTTPRequest $request) { |
359 | 359 | // Extract parent comment from reply and build this way |
360 | - if($parentID = $request->param('ParentCommentID')) { |
|
360 | + if ($parentID = $request->param('ParentCommentID')) { |
|
361 | 361 | $comment = DataObject::get_by_id('Comment', $parentID, true); |
362 | - if($comment) { |
|
362 | + if ($comment) { |
|
363 | 363 | return $this->ReplyForm($comment); |
364 | 364 | } |
365 | 365 | } |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | |
416 | 416 | // Preview formatted comment. Makes most sense when shortcodes or |
417 | 417 | // limited HTML is allowed. Populated by JS/Ajax. |
418 | - if($usePreview) { |
|
418 | + if ($usePreview) { |
|
419 | 419 | $fields->insertAfter( |
420 | 420 | ReadonlyField::create('PreviewComment', _t('CommentInterface.PREVIEWLABEL', 'Preview')) |
421 | 421 | ->setAttribute('style', 'display: none'), // enable through JS |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | $actions = new FieldList( |
430 | 430 | new FormAction("doPostComment", _t('CommentInterface.POST', 'Post')) |
431 | 431 | ); |
432 | - if($usePreview) { |
|
432 | + if ($usePreview) { |
|
433 | 433 | $actions->push( |
434 | 434 | FormAction::create('doPreviewComment', _t('CommentInterface.PREVIEW', 'Preview')) |
435 | 435 | ->addExtraClass('action-minor') |
@@ -444,11 +444,11 @@ discard block |
||
444 | 444 | $form = new Form($this, 'CommentsForm', $fields, $actions, $required); |
445 | 445 | |
446 | 446 | // if the record exists load the extra required data |
447 | - if($record = $this->getOwnerRecord()) { |
|
447 | + if ($record = $this->getOwnerRecord()) { |
|
448 | 448 | |
449 | 449 | // Load member data |
450 | 450 | $member = Member::currentUser(); |
451 | - if(($record->CommentsRequireLogin || $record->PostingRequiredPermission) && $member) { |
|
451 | + if (($record->CommentsRequireLogin || $record->PostingRequiredPermission) && $member) { |
|
452 | 452 | $fields = $form->Fields(); |
453 | 453 | |
454 | 454 | $fields->removeByName('Name'); |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | $form->setRedirectToFormOnValidationError(true); |
472 | 472 | |
473 | 473 | // load any data from the cookies |
474 | - if($data = Cookie::get('CommentsForm_UserData')) { |
|
474 | + if ($data = Cookie::get('CommentsForm_UserData')) { |
|
475 | 475 | $data = Convert::json2array($data); |
476 | 476 | |
477 | 477 | $form->loadDataFrom(array( |
@@ -481,12 +481,12 @@ discard block |
||
481 | 481 | )); |
482 | 482 | // allow previous value to fill if comment not stored in cookie (i.e. validation error) |
483 | 483 | $prevComment = Cookie::get('CommentsForm_Comment'); |
484 | - if($prevComment && $prevComment != ''){ |
|
484 | + if ($prevComment && $prevComment != '') { |
|
485 | 485 | $form->loadDataFrom(array("Comment" => $prevComment)); |
486 | 486 | } |
487 | 487 | } |
488 | 488 | |
489 | - if(!empty($member)) { |
|
489 | + if (!empty($member)) { |
|
490 | 490 | $form->loadDataFrom($member); |
491 | 491 | } |
492 | 492 | |
@@ -504,13 +504,13 @@ discard block |
||
504 | 504 | */ |
505 | 505 | public function doPostComment($data, $form) { |
506 | 506 | // Load class and parent from data |
507 | - if(isset($data['BaseClass'])) { |
|
507 | + if (isset($data['BaseClass'])) { |
|
508 | 508 | $this->setBaseClass($data['BaseClass']); |
509 | 509 | } |
510 | - if(isset($data['ParentID']) && ($class = $this->getBaseClass())) { |
|
510 | + if (isset($data['ParentID']) && ($class = $this->getBaseClass())) { |
|
511 | 511 | $this->setOwnerRecord($class::get()->byID($data['ParentID'])); |
512 | 512 | } |
513 | - if(!$this->getOwnerRecord()) return $this->httpError(404); |
|
513 | + if (!$this->getOwnerRecord()) return $this->httpError(404); |
|
514 | 514 | |
515 | 515 | // cache users data |
516 | 516 | Cookie::set("CommentsForm_UserData", Convert::raw2json($data)); |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | $this->extend('onBeforePostComment', $form); |
521 | 521 | |
522 | 522 | // If commenting can only be done by logged in users, make sure the user is logged in |
523 | - if(!$this->getOwnerRecord()->canPostComment()) { |
|
523 | + if (!$this->getOwnerRecord()->canPostComment()) { |
|
524 | 524 | return Security::permissionFailure( |
525 | 525 | $this, |
526 | 526 | _t( |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | ); |
532 | 532 | } |
533 | 533 | |
534 | - if($member = Member::currentUser()) { |
|
534 | + if ($member = Member::currentUser()) { |
|
535 | 535 | $form->Fields()->push(new HiddenField("AuthorID", "Author ID", $member->ID)); |
536 | 536 | } |
537 | 537 | |
538 | 538 | // What kind of moderation is required? |
539 | - switch($this->getOwnerRecord()->ModerationRequired) { |
|
539 | + switch ($this->getOwnerRecord()->ModerationRequired) { |
|
540 | 540 | case 'Required': |
541 | 541 | $requireModeration = true; |
542 | 542 | break; |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | // Save into DB, or call pre-save hooks to give accurate preview |
559 | 559 | $usePreview = $this->getOption('use_preview'); |
560 | 560 | $isPreview = $usePreview && !empty($data['IsPreview']); |
561 | - if($isPreview) { |
|
561 | + if ($isPreview) { |
|
562 | 562 | $comment->extend('onBeforeWrite'); |
563 | 563 | } else { |
564 | 564 | $comment->write(); |
@@ -576,19 +576,19 @@ discard block |
||
576 | 576 | Cookie::set('CommentsForm_Comment', false); |
577 | 577 | |
578 | 578 | // Find parent link |
579 | - if(!empty($data['ReturnURL'])) { |
|
579 | + if (!empty($data['ReturnURL'])) { |
|
580 | 580 | $url = $data['ReturnURL']; |
581 | - } elseif($parent = $comment->getParent()) { |
|
581 | + } elseif ($parent = $comment->getParent()) { |
|
582 | 582 | $url = $parent->Link(); |
583 | 583 | } else { |
584 | 584 | return $this->redirectBack(); |
585 | 585 | } |
586 | 586 | |
587 | 587 | // Given a redirect page exists, attempt to link to the correct anchor |
588 | - if($comment->IsSpam) { |
|
588 | + if ($comment->IsSpam) { |
|
589 | 589 | // Link to the form with the error message contained |
590 | 590 | $hash = $form->FormName(); |
591 | - } else if(!$comment->Moderated) { |
|
591 | + } else if (!$comment->Moderated) { |
|
592 | 592 | // Display the "awaiting moderation" text |
593 | 593 | $holder = $this->getOption('comments_holder_id'); |
594 | 594 | $hash = "{$holder}_PostCommentForm_error"; |
@@ -615,21 +615,21 @@ discard block |
||
615 | 615 | // In edge-cases, this will be called outside of a handleRequest() context; in that case, |
616 | 616 | // redirect to the homepage - don't break into the global state at this stage because we'll |
617 | 617 | // be calling from a test context or something else where the global state is inappropraite |
618 | - if($this->request) { |
|
619 | - if($this->request->requestVar('BackURL')) { |
|
618 | + if ($this->request) { |
|
619 | + if ($this->request->requestVar('BackURL')) { |
|
620 | 620 | $url = $this->request->requestVar('BackURL'); |
621 | - } else if($this->request->isAjax() && $this->request->getHeader('X-Backurl')) { |
|
621 | + } else if ($this->request->isAjax() && $this->request->getHeader('X-Backurl')) { |
|
622 | 622 | $url = $this->request->getHeader('X-Backurl'); |
623 | - } else if($this->request->getHeader('Referer')) { |
|
623 | + } else if ($this->request->getHeader('Referer')) { |
|
624 | 624 | $url = $this->request->getHeader('Referer'); |
625 | 625 | } |
626 | 626 | } |
627 | 627 | |
628 | - if(!$url) $url = $this->fallbackReturnURL; |
|
629 | - if(!$url) $url = Director::baseURL(); |
|
628 | + if (!$url) $url = $this->fallbackReturnURL; |
|
629 | + if (!$url) $url = Director::baseURL(); |
|
630 | 630 | |
631 | 631 | // absolute redirection URLs not located on this site may cause phishing |
632 | - if(Director::is_site_url($url)) { |
|
632 | + if (Director::is_site_url($url)) { |
|
633 | 633 | return $this->redirect($url); |
634 | 634 | } else { |
635 | 635 | return false; |
@@ -82,25 +82,25 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -291,7 +291,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -93,7 +93,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -316,7 +316,7 @@ discard block |
||
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 |
||
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 |
||
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) { |
@@ -570,15 +570,15 @@ discard block |
||
570 | 570 | _t('Comment.ParentComment_Title', 'This comment is a reply to the below') |
571 | 571 | )); |
572 | 572 | // Created date |
573 | - // FIXME - the method setName in DatetimeField is not chainable, hence |
|
574 | - // the lack of chaining here |
|
575 | - $createdField = $parent |
|
576 | - ->obj('Created') |
|
577 | - ->scaffoldFormField($parent->fieldLabel('Created')); |
|
578 | - $createdField->setName('ParentComment_Created'); |
|
579 | - $createdField->setValue($parent->Created); |
|
580 | - $createdField->performReadonlyTransformation(); |
|
581 | - $fields->push($createdField); |
|
573 | + // FIXME - the method setName in DatetimeField is not chainable, hence |
|
574 | + // the lack of chaining here |
|
575 | + $createdField = $parent |
|
576 | + ->obj('Created') |
|
577 | + ->scaffoldFormField($parent->fieldLabel('Created')); |
|
578 | + $createdField->setName('ParentComment_Created'); |
|
579 | + $createdField->setValue($parent->Created); |
|
580 | + $createdField->performReadonlyTransformation(); |
|
581 | + $fields->push($createdField); |
|
582 | 582 | |
583 | 583 | // Name (could be member or string value) |
584 | 584 | $fields->push( |
@@ -620,13 +620,13 @@ discard block |
||
620 | 620 | */ |
621 | 621 | public function getHtmlPurifierService() { |
622 | 622 | $config = HTMLPurifier_Config::createDefault(); |
623 | - $allowedElements = $this->getOption('html_allowed_elements'); |
|
624 | - $config->set('HTML.AllowedElements', $allowedElements); |
|
623 | + $allowedElements = $this->getOption('html_allowed_elements'); |
|
624 | + $config->set('HTML.AllowedElements', $allowedElements); |
|
625 | 625 | |
626 | - // This injector cannot be set unless the 'p' element is allowed |
|
627 | - if (in_array('p', $allowedElements)) { |
|
628 | - $config->set('AutoFormat.AutoParagraph', true); |
|
629 | - } |
|
626 | + // This injector cannot be set unless the 'p' element is allowed |
|
627 | + if (in_array('p', $allowedElements)) { |
|
628 | + $config->set('AutoFormat.AutoParagraph', true); |
|
629 | + } |
|
630 | 630 | |
631 | 631 | $config->set('AutoFormat.Linkify', true); |
632 | 632 | $config->set('URI.DisableExternalResources', true); |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | || ($this->getOption('frontend_moderation') && $parent->canModerateComments()) |
717 | 717 | ); |
718 | 718 | if (!$showUnmoderated) { |
719 | - $list = $list->filter('Moderated', 1); |
|
719 | + $list = $list->filter('Moderated', 1); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | $this->extend('updateReplies', $list); |
@@ -135,7 +135,9 @@ discard block |
||
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 |
||
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 |
||
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(), |
@@ -855,7 +860,9 @@ discard block |
||
855 | 860 | */ |
856 | 861 | public function checkRequest($request) { |
857 | 862 | $member = Member::currentUser(); |
858 | - if(!$member) return false; |
|
863 | + if(!$member) { |
|
864 | + return false; |
|
865 | + } |
|
859 | 866 | |
860 | 867 | $salt = $request->getVar('s'); |
861 | 868 | $memberSalt = $this->memberSalt($salt, $member); |
@@ -876,7 +883,9 @@ discard block |
||
876 | 883 | protected function generate($length = null) { |
877 | 884 | $generator = new RandomGenerator(); |
878 | 885 | $result = $generator->randomToken('sha256'); |
879 | - if($length !== null) return substr($result, 0, $length); |
|
886 | + if($length !== null) { |
|
887 | + return substr($result, 0, $length); |
|
888 | + } |
|
880 | 889 | return $result; |
881 | 890 | } |
882 | 891 | } |
@@ -40,16 +40,16 @@ discard block |
||
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 |
||
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 |
||
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 | ) { |
@@ -75,7 +75,9 @@ |
||
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(); |