diff --git a/code/Commenting.php b/code/Commenting.php index 2ea6827..655ddac 100644 --- a/code/Commenting.php +++ b/code/Commenting.php @@ -40,6 +40,7 @@ class Commenting { 'html_allowed' => false, // allow for sanitized HTML in comments 'html_allowed_elements' => array('a', 'img', 'i', 'b'), 'use_preview' => false, // preview formatted comment (when allowing HTML). Requires include_js=true + 'experimental_commentthreading' => false, //This is experimental - see https://github.com/silverstripe/silverstripe-comments/issues/28 ); /** diff --git a/code/controllers/CommentingController.php b/code/controllers/CommentingController.php index 5ce9127..95bb178 100644 --- a/code/controllers/CommentingController.php +++ b/code/controllers/CommentingController.php @@ -14,7 +14,8 @@ class CommentingController extends Controller { 'rss', 'CommentsForm', 'doPostComment', - 'doPreviewComment' + 'doPreviewComment', + 'replyform' ); private $baseClass = ""; @@ -206,6 +207,36 @@ class CommentingController extends Controller { return $this->httpError(404); } + /** + * Renders html for replying to threaded comments + * Should be called via AJAX + * Example of url: /CommentingController/replyform/5?ReturnURL=/blog/sample-blog-entry/ + * + * @return string + */ + public function replyform(){ + $p = $this->getURLParams(); + $cID = (int) $p['ID']; + $c = Comment::get()->ByID($cID); + + $controller = new CommentingController(); + $controller->setOwnerRecord($c); + $controller->setBaseClass('Comment'); + $controller->setOwnerController(Controller::curr()); + + $form = $controller->CommentsForm(); + + //setting return url + if (isset($_GET['ReturnURL'])) { + $form->loadDataFrom(array( + 'ReturnURL' => $_GET['ReturnURL'], + )); + } + + return $form->forTemplate(); + } + + /** * Returns the comment referenced in the URL (by ID). Permission checking * should be done in the callee. diff --git a/code/extensions/CommentsExtension.php b/code/extensions/CommentsExtension.php index 6f28dcd..2bab0b8 100644 --- a/code/extensions/CommentsExtension.php +++ b/code/extensions/CommentsExtension.php @@ -98,6 +98,9 @@ class CommentsExtension extends DataExtension { Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/jquery.validate.pack.js'); Requirements::javascript('comments/javascript/CommentsInterface.js'); + if ($this->CommentThreading()) { + Requirements::javascript('comments/javascript/CommentThreading.js'); + } } $interface = new SSViewer('CommentsInterface'); @@ -136,6 +139,16 @@ class CommentsExtension extends DataExtension { ))); } + + /** + * Returns true if comment threading is turned on + * NOTE: This is experimental + */ + public function CommentThreading(){ + return Commenting::get_config_value($this->ownerBaseClass, 'experimental_commentthreading'); + } + + /** * Returns whether this extension instance is attached to a {@link SiteTree} object * diff --git a/docs/en/CommentThreading.md b/docs/en/CommentThreading.md new file mode 100644 index 0000000..81bccc7 --- /dev/null +++ b/docs/en/CommentThreading.md @@ -0,0 +1,18 @@ +# Feature: Comment Threading + +This is an experimental feature as per September 2013. + +See [this ticket](https://github.com/silverstripe/silverstripe-comments/issues/28) for more info. + +## Installation + +Add the following lines to your `_config.php` (if this feature gets accepted, we'll find a better way of configuring this): + + Commenting::add('Comment'); + Commenting::set_config_value('Comment', 'experimental_commentthreading', true); + Commenting::set_config_value('SiteTree', 'experimental_commentthreading', true); + + +## Screenshot + +![Comment Threading](_images/CommentThreading.png) \ No newline at end of file diff --git a/docs/en/_images/CommentThreading.png b/docs/en/_images/CommentThreading.png new file mode 100644 index 0000000..44d128e Binary files /dev/null and b/docs/en/_images/CommentThreading.png differ diff --git a/javascript/CommentThreading.js b/javascript/CommentThreading.js new file mode 100644 index 0000000..fcb4493 --- /dev/null +++ b/javascript/CommentThreading.js @@ -0,0 +1,22 @@ +/** + * Comment Threading + * @package comments + */ +(function($) { + $(document).ready(function () { + + //Replying comments + $('body').on('click','.replycomment', function(){ + var $this = $(this); + var $rID = $this.attr('data-id'); + var url = $this.attr('href') + '?ReturnURL=' + location.pathname; + $.get(url, function(data){ + var holder = $('.replycommentformholder[data-id=' + $rID + ']'); + holder.html($(data)); + $this.hide(); + }); + return false; + }); + + }); +})(jQuery); diff --git a/templates/CommentsInterface_singlecomment.ss b/templates/CommentsInterface_singlecomment.ss index f4266d6..cc2c794 100755 --- a/templates/CommentsInterface_singlecomment.ss +++ b/templates/CommentsInterface_singlecomment.ss @@ -28,4 +28,9 @@ <% end_if %> <% end_if %> + + <% if $CommentThreading %> + <% include NestedComments %> + <% end_if %> + <% end_if %> diff --git a/templates/Includes/NestedComments.ss b/templates/Includes/NestedComments.ss new file mode 100644 index 0000000..1325470 --- /dev/null +++ b/templates/Includes/NestedComments.ss @@ -0,0 +1,14 @@ + +<% _t('REPLY', 'reply') %> +
+
+ +<% if $Comments %> + +<% end_if %>