mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Compare commits
2 Commits
3d6e44aaa1
...
3dc22e9c39
Author | SHA1 | Date | |
---|---|---|---|
|
3dc22e9c39 | ||
|
e7f9e60352 |
@ -100,7 +100,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
||||
_t(
|
||||
__CLASS__.'.NewComments',
|
||||
'New ({count})',
|
||||
['count' => count($newComments)]
|
||||
['count' => count($newComments ?? [])]
|
||||
),
|
||||
$newGrid
|
||||
),
|
||||
@ -109,7 +109,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
||||
_t(
|
||||
__CLASS__.'.ApprovedComments',
|
||||
'Approved ({count})',
|
||||
['count' => count($approvedComments)]
|
||||
['count' => count($approvedComments ?? [])]
|
||||
),
|
||||
$approvedGrid
|
||||
),
|
||||
@ -118,7 +118,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider
|
||||
_t(
|
||||
__CLASS__.'.SpamComments',
|
||||
'Spam ({count})',
|
||||
['count' => count($spamComments)]
|
||||
['count' => count($spamComments ?? [])]
|
||||
),
|
||||
$spamGrid
|
||||
)
|
||||
|
@ -19,7 +19,7 @@ class CommentsGridFieldAction implements GridField_ColumnProvider, GridField_Act
|
||||
*/
|
||||
public function augmentColumns($gridField, &$columns)
|
||||
{
|
||||
if (!in_array('Actions', $columns)) {
|
||||
if (!in_array('Actions', $columns ?? [])) {
|
||||
$columns[] = 'Actions';
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class CommentsGridFieldApproveAction implements
|
||||
*/
|
||||
public function augmentColumns($gridField, &$columns)
|
||||
{
|
||||
if (!in_array('Actions', $columns)) {
|
||||
if (!in_array('Actions', $columns ?? [])) {
|
||||
$columns[] = 'Actions';
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class CommentsGridFieldSpamAction implements
|
||||
*/
|
||||
public function augmentColumns($gridField, &$columns)
|
||||
{
|
||||
if (!in_array('Actions', $columns)) {
|
||||
if (!in_array('Actions', $columns ?? [])) {
|
||||
$columns[] = 'Actions';
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class CommentingController extends Controller
|
||||
*/
|
||||
public function encodeClassName($input)
|
||||
{
|
||||
return str_replace('\\', '-', $input);
|
||||
return str_replace('\\', '-', $input ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,7 +126,7 @@ class CommentingController extends Controller
|
||||
*/
|
||||
public function decodeClassName($input)
|
||||
{
|
||||
return str_replace('-', '\\', $input);
|
||||
return str_replace('-', '\\', $input ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -583,9 +583,9 @@ class CommentsExtension extends DataExtension
|
||||
CommentsGridFieldConfig::create()
|
||||
);
|
||||
|
||||
$newCount = '(' . count($newComments) . ')';
|
||||
$approvedCount = '(' . count($approvedComments) . ')';
|
||||
$spamCount = '(' . count($spamComments) . ')';
|
||||
$newCount = '(' . count($newComments ?? []) . ')';
|
||||
$approvedCount = '(' . count($approvedComments ?? []) . ')';
|
||||
$spamCount = '(' . count($spamComments ?? []) . ')';
|
||||
|
||||
if ($fields->hasTabSet()) {
|
||||
$tabs = TabSet::create(
|
||||
|
@ -145,8 +145,8 @@ class CommentForm extends Form
|
||||
}
|
||||
|
||||
// load user data from previous form request back into form.
|
||||
if (array_key_exists('UserData', $data)) {
|
||||
$formData = json_decode($data['UserData'], true);
|
||||
if (array_key_exists('UserData', $data ?? [])) {
|
||||
$formData = json_decode($data['UserData'] ?? '', true);
|
||||
|
||||
$this->loadDataFrom([
|
||||
'Name' => isset($formData['Name']) ? $formData['Name'] : '',
|
||||
@ -156,7 +156,7 @@ class CommentForm extends Form
|
||||
}
|
||||
|
||||
// allow previous value to fill if comment
|
||||
if (array_key_exists('Comment', $data)) {
|
||||
if (array_key_exists('Comment', $data ?? [])) {
|
||||
$prevComment = $data['Comment'];
|
||||
|
||||
if ($prevComment && $prevComment != '') {
|
||||
|
@ -608,7 +608,7 @@ class Comment extends DataObject
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
$title = sprintf(_t(__CLASS__ . '.COMMENTBY', 'Comment by %s', 'Name'), $this->getAuthorName());
|
||||
$title = sprintf(_t(__CLASS__ . '.COMMENTBY', 'Comment by %s', 'Name') ?? '', $this->getAuthorName());
|
||||
|
||||
if ($parent = $this->Parent()) {
|
||||
if ($parent->Title) {
|
||||
@ -726,7 +726,7 @@ class Comment extends DataObject
|
||||
}
|
||||
|
||||
// This injector cannot be set unless the 'p' element is allowed
|
||||
if (in_array('p', $allowedElements)) {
|
||||
if (in_array('p', $allowedElements ?? [])) {
|
||||
$config->set('AutoFormat.AutoParagraph', true);
|
||||
}
|
||||
|
||||
@ -747,7 +747,7 @@ class Comment extends DataObject
|
||||
$use_gravatar = $this->getOption('use_gravatar');
|
||||
|
||||
if ($use_gravatar) {
|
||||
$gravatar = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($this->Email)));
|
||||
$gravatar = 'https://www.gravatar.com/avatar/' . md5(strtolower(trim($this->Email ?? '')));
|
||||
$gravatarsize = $this->getOption('gravatar_size');
|
||||
$gravatardefault = $this->getOption('gravatar_default');
|
||||
$gravatarrating = $this->getOption('gravatar_rating');
|
||||
|
@ -37,7 +37,7 @@ class SecurityToken
|
||||
*/
|
||||
protected function getToken($salt)
|
||||
{
|
||||
return hash_pbkdf2('sha256', $this->secret, $salt, 1000, 30);
|
||||
return hash_pbkdf2('sha256', $this->secret ?? '', $salt ?? '', 1000, 30);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,8 +74,8 @@ class SecurityToken
|
||||
$url,
|
||||
sprintf(
|
||||
'?t=%s&s=%s',
|
||||
urlencode($token),
|
||||
urlencode($salt)
|
||||
urlencode($token ?? ''),
|
||||
urlencode($salt ?? '')
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -113,7 +113,7 @@ class SecurityToken
|
||||
$generator = new RandomGenerator();
|
||||
$result = $generator->randomToken('sha256');
|
||||
if ($length !== null) {
|
||||
return substr($result, 0, $length);
|
||||
return substr($result ?? '', 0, $length);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -179,21 +179,29 @@ class CommentingControllerTest extends FunctionalTest
|
||||
// comments sitewide
|
||||
$response = $this->get('comments/rss');
|
||||
$comment = "10 approved, non spam comments on page 1";
|
||||
$this->assertEquals(10, substr_count($response->getBody(), "<item>"), $comment);
|
||||
$this->assertEquals(10, substr_count($response->getBody() ?? '', "<item>"), $comment);
|
||||
|
||||
$response = $this->get('comments/rss?start=10');
|
||||
$this->assertEquals(4, substr_count($response->getBody(), "<item>"), "3 approved, non spam comments on page 2");
|
||||
$this->assertEquals(
|
||||
4,
|
||||
substr_count($response->getBody() ?? '', "<item>"),
|
||||
"3 approved, non spam comments on page 2"
|
||||
);
|
||||
|
||||
// all comments on a type
|
||||
$response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem');
|
||||
$this->assertEquals(10, substr_count($response->getBody(), "<item>"));
|
||||
$this->assertEquals(10, substr_count($response->getBody() ?? '', "<item>"));
|
||||
|
||||
$response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem?start=10');
|
||||
$this->assertEquals(4, substr_count($response->getBody(), "<item>"), "3 approved, non spam comments on page 2");
|
||||
$this->assertEquals(
|
||||
4,
|
||||
substr_count($response->getBody() ?? '', "<item>"),
|
||||
"3 approved, non spam comments on page 2"
|
||||
);
|
||||
|
||||
// specific page
|
||||
$response = $this->get('comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/'.$item->ID);
|
||||
$this->assertEquals(1, substr_count($response->getBody(), "<item>"));
|
||||
$this->assertEquals(1, substr_count($response->getBody() ?? '', "<item>"));
|
||||
$this->assertStringContainsString('<dc:creator>FA</dc:creator>', $response->getBody());
|
||||
|
||||
// test accessing comments on a type that doesn't exist
|
||||
|
@ -343,7 +343,7 @@ class CommentsExtensionTest extends FunctionalTest
|
||||
$results[0]->Comment
|
||||
);
|
||||
|
||||
$this->assertEquals(4, sizeof($results));
|
||||
$this->assertEquals(4, sizeof($results ?? []));
|
||||
}
|
||||
|
||||
public function testUpdateModerationFields()
|
||||
|
Loading…
Reference in New Issue
Block a user