mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Merge pull request #51 from PutmanMedia/pulls/remove-ajax-commenting
API Removed ajax comment submission
This commit is contained in:
commit
0c27bc0f66
@ -25,7 +25,7 @@ class Commenting {
|
|||||||
private static $default_config = array(
|
private static $default_config = array(
|
||||||
'require_login' => false, // boolean, whether a user needs to login
|
'require_login' => false, // boolean, whether a user needs to login
|
||||||
'required_permission' => false, // required permission to comment (or array of permissions)
|
'required_permission' => false, // required permission to comment (or array of permissions)
|
||||||
'use_ajax_commenting' => true, // use ajax to post comments.
|
'include_js' => true, // Enhance operation by ajax behaviour on moderation links
|
||||||
'use_gravatar' => false, // set to true to show gravatar icons,
|
'use_gravatar' => false, // set to true to show gravatar icons,
|
||||||
'gravatar_size' => 80, // size of gravatar in pixels. This is the same as the standard default
|
'gravatar_size' => 80, // size of gravatar in pixels. This is the same as the standard default
|
||||||
'show_comments_when_disabled' => false, // when comments are disabled should we show older comments (if available)
|
'show_comments_when_disabled' => false, // when comments are disabled should we show older comments (if available)
|
||||||
@ -36,7 +36,7 @@ class Commenting {
|
|||||||
'require_moderation' => false,
|
'require_moderation' => false,
|
||||||
'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)
|
'use_preview' => false, // preview formatted comment (when allowing HTML). Requires include_js=true
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -423,17 +423,9 @@ class CommentingController extends Controller {
|
|||||||
// clear the users comment since it passed validation
|
// clear the users comment since it passed validation
|
||||||
Cookie::set('CommentsForm_Comment', false);
|
Cookie::set('CommentsForm_Comment', false);
|
||||||
|
|
||||||
if(Director::is_ajax()) {
|
|
||||||
if(!$comment->Moderated && !$isPreview) {
|
|
||||||
return $comment->renderWith('CommentsInterface_pendingcomment');
|
|
||||||
} else {
|
|
||||||
return $comment->renderWith('CommentsInterface_singlecomment');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$holder = Commenting::get_config_value($comment->BaseClass, 'comments_holder_id');
|
$holder = Commenting::get_config_value($comment->BaseClass, 'comments_holder_id');
|
||||||
|
|
||||||
$hash = ($moderated) ? $comment->Permalink() : $holder;
|
$hash = ($moderated) ? $holder : $comment->Permalink();
|
||||||
$url = (isset($data['ReturnURL'])) ? $data['ReturnURL'] : false;
|
$url = (isset($data['ReturnURL'])) ? $data['ReturnURL'] : false;
|
||||||
|
|
||||||
return ($url) ? $this->redirect($url .'#'. $hash) : $this->redirectBack();
|
return ($url) ? $this->redirect($url .'#'. $hash) : $this->redirectBack();
|
||||||
|
@ -97,7 +97,7 @@ class CommentsExtension extends DataExtension {
|
|||||||
* @see docs/en/Extending
|
* @see docs/en/Extending
|
||||||
*/
|
*/
|
||||||
public function CommentsForm() {
|
public function CommentsForm() {
|
||||||
if (Commenting::has_commenting($this->ownerBaseClass) && Commenting::get_config_value($this->ownerBaseClass, 'use_ajax_commenting')) {
|
if(Commenting::has_commenting($this->ownerBaseClass) && Commenting::get_config_value($this->ownerBaseClass, 'include_js')) {
|
||||||
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
|
||||||
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');
|
||||||
|
@ -7,18 +7,18 @@ The module provides a number of built in configuration settings below are the de
|
|||||||
// mysite/_config.php
|
// mysite/_config.php
|
||||||
|
|
||||||
Commenting::add('Foo', array(
|
Commenting::add('Foo', array(
|
||||||
'require_login' => false,
|
'require_login' => false, // boolean, whether a user needs to login
|
||||||
'required_permission' => false,
|
'required_permission' => false, // required permission to comment (or array of permissions)
|
||||||
'use_ajax_commenting' => true,
|
'include_js' => true, // Enhance operation by ajax behaviour on moderation links
|
||||||
'show_comments_when_disabled' => false,
|
'show_comments_when_disabled' => false, // when comments are disabled should we show older comments (if available)
|
||||||
'order_comments_by' => "\"Created\" DESC",
|
'order_comments_by' => "\"Created\" DESC",
|
||||||
'comments_per_page' => 10,
|
'comments_per_page' => 10,
|
||||||
'comments_holder_id' => "comments-holder",
|
'comments_holder_id' => "comments-holder", // id for the comments holder
|
||||||
'comment_permalink_prefix' => "comment-",
|
'comment_permalink_prefix' => "comment-", // id prefix for each comment. If needed make this different
|
||||||
'require_moderation' => false,
|
'require_moderation' => false,
|
||||||
'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),
|
'use_preview' => false, // preview formatted comment (when allowing HTML). Requires include_js=true
|
||||||
'use_gravatar' => false,
|
'use_gravatar' => false,
|
||||||
'gravatar_size' => 80
|
'gravatar_size' => 80
|
||||||
);
|
);
|
||||||
|
@ -68,44 +68,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clicking one of the metalinks performs the operation via ajax
|
|
||||||
* this inclues the spam and approve links
|
|
||||||
*/
|
|
||||||
form.submit(function (e) {
|
form.submit(function (e) {
|
||||||
// trigger validation
|
// trigger validation
|
||||||
if(!form.validate().valid()){
|
if(!form.validate().valid()) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
previewEl.removeClass('loading').hide();
|
|
||||||
|
|
||||||
// submit the form
|
|
||||||
$(this).ajaxSubmit(function(response) {
|
|
||||||
noCommentsYet.hide();
|
|
||||||
|
|
||||||
if(!commentsList.length){
|
|
||||||
commentsHolder.append("<ul class='comments-list'></ul>");
|
|
||||||
commentsList = $('.comments-list', commentsHolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
var evenOdd = (commentsList.children('.first').removeClass('first').hasClass('even')) ? 'odd' : 'even';
|
|
||||||
var newComment = $('<li />')
|
|
||||||
.addClass('comment first ' + evenOdd)
|
|
||||||
.html(response)
|
|
||||||
.hide();
|
|
||||||
|
|
||||||
if(response.match('<b>Spam detected!!</b>')) {
|
|
||||||
newComment.addClass('spam');
|
|
||||||
}
|
|
||||||
|
|
||||||
commentsList.prepend(newComment.fadeIn());
|
|
||||||
});
|
|
||||||
|
|
||||||
$(this).resetForm();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user