comment threading proof of concept

This commit is contained in:
Anselm Christophersen 2013-09-22 23:21:40 +02:00
parent 7933b3f27a
commit bbf9deefaf
8 changed files with 105 additions and 1 deletions

View File

@ -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
);
/**

View File

@ -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.

View File

@ -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
*

View File

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -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);

View File

@ -28,4 +28,9 @@
<% end_if %>
</ul>
<% end_if %>
<% if $CommentThreading %>
<% include NestedComments %>
<% end_if %>
<% end_if %>

View File

@ -0,0 +1,14 @@
<a class="replycomment" data-id="$ID" href="CommentingController/replyform/$ID"><% _t('REPLY', 'reply') %></a>
<div class="replycommentformholder" data-id="$ID">
</div>
<% if $Comments %>
<ul class="nested-comments-list">
<% loop $Comments %>
<li class="comment $EvenOdd<% if FirstLast %> $FirstLast <% end_if %> $SpamClass">
<% include CommentsInterface_singlecomment %>
</li>
<% end_loop %>
</ul>
<% end_if %>