Merge branch '3.1'

This commit is contained in:
Robbie Averill 2019-01-11 09:13:31 +01:00
commit d504d4a847
9 changed files with 45 additions and 55 deletions

View File

@ -2,7 +2,16 @@
* @package comments * @package comments
*/ */
(function($) { (function($) {
// The above closure encapsulates the $ variable away from the global scope
// and the one below is the `$(document).ready(...)` shorthand.
$(function() { $(function() {
// Override the default URL validator in order to extend it to allow protocol-less URLs
$.validator.methods.url = function( value, element ) {
// This line is copied directly from the jQuery.validation source (version 1.19.0)
// the only change is a single question mark added here ---------v
return this.optional( element ) || /^(?:(?:(?:https?|ftp):)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value );
}
/** /**
* Enable form validation * Enable form validation
*/ */

View File

@ -18,10 +18,10 @@ en:
CommentsInterface_pendingcomment_ss: CommentsInterface_pendingcomment_ss:
AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.' AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.'
CommentsInterface_singlecomment_ss: CommentsInterface_singlecomment_ss:
APPROVE: 'approve it' APPROVE: 'Approve it'
ISNTSPAM: 'not spam' ISNTSPAM: 'Not spam'
ISSPAM: 'spam it' ISSPAM: 'Spam it'
REMCOM: 'reject it' REMCOM: 'Reject it'
REPLYTO: 'Reply to' REPLYTO: 'Reply to'
CommentsInterface_ss: CommentsInterface_ss:
AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.' AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.'
@ -74,7 +74,7 @@ en:
EMAIL: Email EMAIL: Email
ISSPAM: 'Spam?' ISSPAM: 'Spam?'
MODERATED: 'Moderated?' MODERATED: 'Moderated?'
NAME: 'Author Name' NAME: 'Author name'
'ON': 'on' 'ON': 'on'
OPTIONS: Options OPTIONS: Options
OPTION_DESCRIPTION: 'Unmoderated and spam comments will not be displayed until approved' OPTION_DESCRIPTION: 'Unmoderated and spam comments will not be displayed until approved'

View File

@ -27,7 +27,7 @@ abstract class CommentHandler extends Handler
$this->updateComment($comment); $this->updateComment($comment);
} }
$response = new HTTPResponse(Convert::raw2json([ $response = new HTTPResponse(json_encode([
'done' => true, 'done' => true,
'records' => $ids, 'records' => $ids,
])); ]));

View File

@ -37,7 +37,7 @@ class Handler extends GridFieldBulkActionHandler
$record->markSpam(); $record->markSpam();
} }
$response = new HTTPResponse(Convert::raw2json(array( $response = new HTTPResponse(json_encode(array(
'done' => true, 'done' => true,
'records' => $ids 'records' => $ids
))); )));
@ -60,7 +60,7 @@ class Handler extends GridFieldBulkActionHandler
$record->markApproved(); $record->markApproved();
} }
$response = new HTTPResponse(Convert::raw2json(array( $response = new HTTPResponse(json_encode(array(
'done' => true, 'done' => true,
'records' => $ids 'records' => $ids
))); )));

View File

@ -441,7 +441,7 @@ class CommentsExtension extends DataExtension
{ {
return Controller::join_links( return Controller::join_links(
$this->getCommentRSSLink(), $this->getCommentRSSLink(),
str_replace('\\', '-', $this->owner->baseClass()), str_replace('\\', '-', get_class($this->owner)),
$this->owner->ID $this->owner->ID
); );
} }

View File

@ -146,7 +146,7 @@ class CommentForm extends Form
// load user data from previous form request back into form. // load user data from previous form request back into form.
if (array_key_exists('UserData', $data)) { if (array_key_exists('UserData', $data)) {
$formData = Convert::json2array($data['UserData']); $formData = json_decode($data['UserData'], true);
$this->loadDataFrom([ $this->loadDataFrom([
'Name' => isset($formData['Name']) ? $formData['Name'] : '', 'Name' => isset($formData['Name']) ? $formData['Name'] : '',
@ -199,7 +199,7 @@ class CommentForm extends Form
// cache users data // cache users data
$form->setSessionData([ $form->setSessionData([
'UserData' => Convert::raw2json($data), 'UserData' => json_encode($data),
'Comment' => $data['Comment'] 'Comment' => $data['Comment']
]); ]);
@ -270,7 +270,7 @@ class CommentForm extends Form
// cache users data (name, email, etc to prepopulate on other forms). // cache users data (name, email, etc to prepopulate on other forms).
$form->setSessionData([ $form->setSessionData([
'UserData' => Convert::raw2json($data), 'UserData' => json_encode($data),
]); ]);
// Find parent link // Find parent link

View File

@ -125,8 +125,8 @@ class Comment extends DataObject
* {@inheritDoc} * {@inheritDoc}
*/ */
private static $summary_fields = array( private static $summary_fields = array(
'Name' => 'Submitted By', 'getAuthorName' => 'Submitted By',
'Email' => 'Email', 'getAuthorEmail' => 'Email',
'Comment.LimitWordCount' => 'Comment', 'Comment.LimitWordCount' => 'Comment',
'Created' => 'Date Posted', 'Created' => 'Date Posted',
'Parent.Title' => 'Post', 'Parent.Title' => 'Post',
@ -219,7 +219,7 @@ class Comment extends DataObject
{ {
$labels = parent::fieldLabels($includerelations); $labels = parent::fieldLabels($includerelations);
$labels['Name'] = _t(__CLASS__ . '.NAME', 'Author Name'); $labels['Name'] = _t(__CLASS__ . '.NAME', 'Author name');
$labels['Comment'] = _t(__CLASS__ . '.COMMENT', 'Comment'); $labels['Comment'] = _t(__CLASS__ . '.COMMENT', 'Comment');
$labels['Email'] = _t(__CLASS__ . '.EMAIL', 'Email'); $labels['Email'] = _t(__CLASS__ . '.EMAIL', 'Email');
$labels['URL'] = _t(__CLASS__ . '.URL', 'URL'); $labels['URL'] = _t(__CLASS__ . '.URL', 'URL');
@ -450,6 +450,20 @@ class Comment extends DataObject
} }
} }
/**
* Return the comment authors email address
*
* @return string
*/
public function getAuthorEmail()
{
if ($this->Email) {
return $this->Email;
} elseif ($author = $this->Author()) {
return $author->Email;
}
}
/** /**
* Generate a secure admin-action link authorised for the specified member * Generate a secure admin-action link authorised for the specified member
* *

View File

@ -20,21 +20,21 @@
<div class="comment-action-links"> <div class="comment-action-links">
<div class="comment-moderation-options"> <div class="comment-moderation-options">
<% if $ApproveLink %> <% if $ApproveLink %>
<a href="$ApproveLink.ATT" class="approve"><% _t('CommentsInterface_singlecomment_ss.APPROVE', 'approve it') %></a> <a href="$ApproveLink.ATT" class="approve"><%t CommentsInterface_singlecomment_ss.APPROVE "Approve it" %></a>
<% end_if %> <% end_if %>
<% if $SpamLink %> <% if $SpamLink %>
<a href="$SpamLink.ATT" class="spam"><% _t('CommentsInterface_singlecomment_ss.ISSPAM','spam it') %></a> <a href="$SpamLink.ATT" class="spam"><%t CommentsInterface_singlecomment_ss.ISSPAM "Spam it" %></a>
<% end_if %> <% end_if %>
<% if $HamLink %> <% if $HamLink %>
<a href="$HamLink.ATT" class="ham"><% _t('CommentsInterface_singlecomment_ss.ISNTSPAM','not spam') %></a> <a href="$HamLink.ATT" class="ham"><%t CommentsInterface_singlecomment_ss.ISNTSPAM "Not spam" %></a>
<% end_if %> <% end_if %>
<% if $DeleteLink %> <% if $DeleteLink %>
<a href="$DeleteLink.ATT" class="delete"><% _t('CommentsInterface_singlecomment_ss.REMCOM','reject it') %></a> <a href="$DeleteLink.ATT" class="delete"><%t CommentsInterface_singlecomment_ss.REMCOM "Reject it" %></a>
<% end_if %> <% end_if %>
</div> </div>
<% if $RepliesEnabled && $canPostComment %> <% if $RepliesEnabled && $canPostComment %>
<button class="comment-reply-link" type="button" aria-controls="$ReplyForm.FormName" aria-expanded="false"> <button class="comment-reply-link" type="button" aria-controls="$ReplyForm.FormName" aria-expanded="false">
<% _t('CommentsInterface_singlecomment_ss.REPLYTO','Reply to') %> $AuthorName.XML <%t CommentsInterface_singlecomment_ss.REPLYTO "Reply to" %> $AuthorName.XML
</button> </button>
<% end_if %> <% end_if %>
</div> </div>

View File

@ -605,52 +605,19 @@ class CommentsTest extends FunctionalTest
*/ */
public function testFieldLabels() public function testFieldLabels()
{ {
$locale = i18n::get_locale();
i18n::set_locale('fr');
/** @var Comment $comment */ /** @var Comment $comment */
$comment = $this->objFromFixture(Comment::class, 'firstComA'); $comment = $this->objFromFixture(Comment::class, 'firstComA');
$labels = $comment->FieldLabels(); $labels = $comment->FieldLabels();
$expected = array( $expected = array(
'Name' => 'Nom de l\'Auteur', 'Name' => 'Author name',
'Comment' => 'Commentaire',
'Email' => 'Email',
'URL' => 'URL',
'Moderated' => 'Modéré?',
'IsSpam' => 'Spam?',
'AllowHtml' => 'Allow Html',
'SecretToken' => 'Secret Token',
'Depth' => 'Depth',
'Author' => 'Author Member',
'ParentComment' => 'Parent Comment',
'ChildComments' => 'Child Comments',
'ParentTitle' => 'Parent',
'Created' => 'Date de publication',
'Parent' => 'Parent'
);
i18n::set_locale($locale);
foreach ($expected as $key => $value) {
$this->assertEquals($value, $labels[$key]);
}
$labels = $comment->FieldLabels();
$expected = array(
'Name' => 'Author Name',
'Comment' => 'Comment', 'Comment' => 'Comment',
'Email' => 'Email', 'Email' => 'Email',
'URL' => 'URL', 'URL' => 'URL',
'Moderated' => 'Moderated?',
'IsSpam' => 'Spam?', 'IsSpam' => 'Spam?',
'AllowHtml' => 'Allow Html', 'Moderated' => 'Moderated?',
'SecretToken' => 'Secret Token',
'Depth' => 'Depth',
'Author' => 'Author Member',
'ParentComment' => 'Parent Comment',
'ChildComments' => 'Child Comments',
'ParentTitle' => 'Parent', 'ParentTitle' => 'Parent',
'Created' => 'Date posted', 'Created' => 'Date posted',
'Parent' => 'Parent'
); );
foreach ($expected as $key => $value) { foreach ($expected as $key => $value) {
$this->assertEquals($value, $labels[$key]); $this->assertEquals($value, $labels[$key]);