diff --git a/javascript/CommentsInterface.js b/javascript/CommentsInterface.js index 231266c..d27ab84 100755 --- a/javascript/CommentsInterface.js +++ b/javascript/CommentsInterface.js @@ -2,7 +2,16 @@ * @package comments */ (function($) { + // The above closure encapsulates the $ variable away from the global scope + // and the one below is the `$(document).ready(...)` shorthand. $(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 */ diff --git a/lang/en.yml b/lang/en.yml index b059e8d..82c7592 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -18,10 +18,10 @@ en: CommentsInterface_pendingcomment_ss: AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.' CommentsInterface_singlecomment_ss: - APPROVE: 'approve it' - ISNTSPAM: 'not spam' - ISSPAM: 'spam it' - REMCOM: 'reject it' + APPROVE: 'Approve it' + ISNTSPAM: 'Not spam' + ISSPAM: 'Spam it' + REMCOM: 'Reject it' REPLYTO: 'Reply to' CommentsInterface_ss: AWAITINGMODERATION: 'Your comment has been submitted and is now awaiting moderation.' @@ -74,7 +74,7 @@ en: EMAIL: Email ISSPAM: 'Spam?' MODERATED: 'Moderated?' - NAME: 'Author Name' + NAME: 'Author name' 'ON': 'on' OPTIONS: Options OPTION_DESCRIPTION: 'Unmoderated and spam comments will not be displayed until approved' diff --git a/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php b/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php index b22d04f..f2e1739 100644 --- a/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php +++ b/src/Admin/CommentsGridFieldBulkAction/CommentHandler.php @@ -27,7 +27,7 @@ abstract class CommentHandler extends Handler $this->updateComment($comment); } - $response = new HTTPResponse(Convert::raw2json([ + $response = new HTTPResponse(json_encode([ 'done' => true, 'records' => $ids, ])); diff --git a/src/Admin/CommentsGridFieldBulkAction/Handler.php b/src/Admin/CommentsGridFieldBulkAction/Handler.php index d47be6b..ced63e4 100644 --- a/src/Admin/CommentsGridFieldBulkAction/Handler.php +++ b/src/Admin/CommentsGridFieldBulkAction/Handler.php @@ -37,7 +37,7 @@ class Handler extends GridFieldBulkActionHandler $record->markSpam(); } - $response = new HTTPResponse(Convert::raw2json(array( + $response = new HTTPResponse(json_encode(array( 'done' => true, 'records' => $ids ))); @@ -60,7 +60,7 @@ class Handler extends GridFieldBulkActionHandler $record->markApproved(); } - $response = new HTTPResponse(Convert::raw2json(array( + $response = new HTTPResponse(json_encode(array( 'done' => true, 'records' => $ids ))); diff --git a/src/Extensions/CommentsExtension.php b/src/Extensions/CommentsExtension.php index ce0ec93..892d190 100644 --- a/src/Extensions/CommentsExtension.php +++ b/src/Extensions/CommentsExtension.php @@ -441,7 +441,7 @@ class CommentsExtension extends DataExtension { return Controller::join_links( $this->getCommentRSSLink(), - str_replace('\\', '-', $this->owner->baseClass()), + str_replace('\\', '-', get_class($this->owner)), $this->owner->ID ); } diff --git a/src/Forms/CommentForm.php b/src/Forms/CommentForm.php index 04c1a68..c8639f5 100644 --- a/src/Forms/CommentForm.php +++ b/src/Forms/CommentForm.php @@ -146,7 +146,7 @@ class CommentForm extends Form // load user data from previous form request back into form. if (array_key_exists('UserData', $data)) { - $formData = Convert::json2array($data['UserData']); + $formData = json_decode($data['UserData'], true); $this->loadDataFrom([ 'Name' => isset($formData['Name']) ? $formData['Name'] : '', @@ -199,7 +199,7 @@ class CommentForm extends Form // cache users data $form->setSessionData([ - 'UserData' => Convert::raw2json($data), + 'UserData' => json_encode($data), 'Comment' => $data['Comment'] ]); @@ -270,7 +270,7 @@ class CommentForm extends Form // cache users data (name, email, etc to prepopulate on other forms). $form->setSessionData([ - 'UserData' => Convert::raw2json($data), + 'UserData' => json_encode($data), ]); // Find parent link diff --git a/src/Model/Comment.php b/src/Model/Comment.php index 0dd6eec..8c47ac6 100755 --- a/src/Model/Comment.php +++ b/src/Model/Comment.php @@ -125,8 +125,8 @@ class Comment extends DataObject * {@inheritDoc} */ private static $summary_fields = array( - 'Name' => 'Submitted By', - 'Email' => 'Email', + 'getAuthorName' => 'Submitted By', + 'getAuthorEmail' => 'Email', 'Comment.LimitWordCount' => 'Comment', 'Created' => 'Date Posted', 'Parent.Title' => 'Post', @@ -219,7 +219,7 @@ class Comment extends DataObject { $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['Email'] = _t(__CLASS__ . '.EMAIL', 'Email'); $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 * diff --git a/templates/Includes/CommentsInterface_singlecomment.ss b/templates/Includes/CommentsInterface_singlecomment.ss index aab7204..73f644f 100755 --- a/templates/Includes/CommentsInterface_singlecomment.ss +++ b/templates/Includes/CommentsInterface_singlecomment.ss @@ -20,21 +20,21 @@ diff --git a/tests/CommentsTest.php b/tests/CommentsTest.php index a319a90..9f9836e 100644 --- a/tests/CommentsTest.php +++ b/tests/CommentsTest.php @@ -605,52 +605,19 @@ class CommentsTest extends FunctionalTest */ public function testFieldLabels() { - $locale = i18n::get_locale(); - i18n::set_locale('fr'); - /** @var Comment $comment */ $comment = $this->objFromFixture(Comment::class, 'firstComA'); $labels = $comment->FieldLabels(); $expected = array( - 'Name' => 'Nom de l\'Auteur', - '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', + 'Name' => 'Author name', 'Comment' => 'Comment', 'Email' => 'Email', 'URL' => 'URL', - 'Moderated' => 'Moderated?', 'IsSpam' => 'Spam?', - 'AllowHtml' => 'Allow Html', - 'SecretToken' => 'Secret Token', - 'Depth' => 'Depth', - 'Author' => 'Author Member', - 'ParentComment' => 'Parent Comment', - 'ChildComments' => 'Child Comments', + 'Moderated' => 'Moderated?', 'ParentTitle' => 'Parent', 'Created' => 'Date posted', - 'Parent' => 'Parent' ); foreach ($expected as $key => $value) { $this->assertEquals($value, $labels[$key]);