mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
comment threading proof of concept
This commit is contained in:
parent
7933b3f27a
commit
bbf9deefaf
@ -40,6 +40,7 @@ class Commenting {
|
|||||||
'html_allowed' => false, // allow for sanitized HTML in comments
|
'html_allowed' => false, // allow for sanitized HTML in comments
|
||||||
'html_allowed_elements' => array('a', 'img', 'i', 'b'),
|
'html_allowed_elements' => array('a', 'img', 'i', 'b'),
|
||||||
'use_preview' => false, // preview formatted comment (when allowing HTML). Requires include_js=true
|
'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
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,7 +14,8 @@ class CommentingController extends Controller {
|
|||||||
'rss',
|
'rss',
|
||||||
'CommentsForm',
|
'CommentsForm',
|
||||||
'doPostComment',
|
'doPostComment',
|
||||||
'doPreviewComment'
|
'doPreviewComment',
|
||||||
|
'replyform'
|
||||||
);
|
);
|
||||||
|
|
||||||
private $baseClass = "";
|
private $baseClass = "";
|
||||||
@ -206,6 +207,36 @@ class CommentingController extends Controller {
|
|||||||
return $this->httpError(404);
|
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
|
* Returns the comment referenced in the URL (by ID). Permission checking
|
||||||
* should be done in the callee.
|
* should be done in the callee.
|
||||||
|
@ -98,6 +98,9 @@ class CommentsExtension extends DataExtension {
|
|||||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js');
|
||||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/jquery.validate.pack.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/jquery.validate.pack.js');
|
||||||
Requirements::javascript('comments/javascript/CommentsInterface.js');
|
Requirements::javascript('comments/javascript/CommentsInterface.js');
|
||||||
|
if ($this->CommentThreading()) {
|
||||||
|
Requirements::javascript('comments/javascript/CommentThreading.js');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$interface = new SSViewer('CommentsInterface');
|
$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
|
* Returns whether this extension instance is attached to a {@link SiteTree} object
|
||||||
*
|
*
|
||||||
|
18
docs/en/CommentThreading.md
Normal file
18
docs/en/CommentThreading.md
Normal 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)
|
BIN
docs/en/_images/CommentThreading.png
Normal file
BIN
docs/en/_images/CommentThreading.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
22
javascript/CommentThreading.js
Normal file
22
javascript/CommentThreading.js
Normal 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);
|
@ -28,4 +28,9 @@
|
|||||||
<% end_if %>
|
<% end_if %>
|
||||||
</ul>
|
</ul>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
|
||||||
|
<% if $CommentThreading %>
|
||||||
|
<% include NestedComments %>
|
||||||
|
<% end_if %>
|
||||||
|
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
|
14
templates/Includes/NestedComments.ss
Normal file
14
templates/Includes/NestedComments.ss
Normal 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 %>
|
Loading…
Reference in New Issue
Block a user