mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Merge pull request #64 from catcherdev/master
NEW Add require_moderation_nonmembers for non-members only
This commit is contained in:
commit
df64d7d098
@ -36,6 +36,7 @@ class Commenting {
|
|||||||
'comments_holder_id' => "comments-holder", // id for the comments holder
|
'comments_holder_id' => "comments-holder", // id for the comments holder
|
||||||
'comment_permalink_prefix' => "comment-", // id prefix for each comment. If needed make this different
|
'comment_permalink_prefix' => "comment-", // id prefix for each comment. If needed make this different
|
||||||
'require_moderation' => false,
|
'require_moderation' => false,
|
||||||
|
'require_moderation_nonmembers' => false, // requires moderation for comments posted by non-members. 'require_moderation' overrides this if set.
|
||||||
'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
|
||||||
@ -80,7 +81,7 @@ class Commenting {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function has_commenting($class) {
|
public static function has_commenting($class) {
|
||||||
return (isset(self::$enabled_classes[$class]));
|
return (isset(self::$enabled_classes[$class]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -341,17 +341,21 @@ class CommentingController extends Controller {
|
|||||||
// load any data from the cookies
|
// load any data from the cookies
|
||||||
if($data = Cookie::get('CommentsForm_UserData')) {
|
if($data = Cookie::get('CommentsForm_UserData')) {
|
||||||
$data = Convert::json2array($data);
|
$data = Convert::json2array($data);
|
||||||
|
|
||||||
$form->loadDataFrom(array(
|
$form->loadDataFrom(array(
|
||||||
"Name" => isset($data['Name']) ? $data['Name'] : '',
|
"Name" => isset($data['Name']) ? $data['Name'] : '',
|
||||||
"URL" => isset($data['URL']) ? $data['URL'] : '',
|
"URL" => isset($data['URL']) ? $data['URL'] : '',
|
||||||
"Email" => isset($data['Email']) ? $data['Email'] : '',
|
"Email" => isset($data['Email']) ? $data['Email'] : ''
|
||||||
"Comment" => Cookie::get('CommentsForm_Comment')
|
));
|
||||||
));
|
// allow previous value to fill if comment not stored in cookie (i.e. validation error)
|
||||||
|
$prevComment = Cookie::get('CommentsForm_Comment');
|
||||||
|
if($prevComment && $prevComment != ''){
|
||||||
|
$form->loadDataFrom(array("Comment" => $prevComment));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($member) {
|
if($member) {
|
||||||
$form->loadDataFrom($member);
|
$form->loadDataFrom($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hook to allow further extensions to alter the comments form
|
// hook to allow further extensions to alter the comments form
|
||||||
@ -397,7 +401,11 @@ class CommentingController extends Controller {
|
|||||||
|
|
||||||
// is moderation turned on
|
// is moderation turned on
|
||||||
$moderated = Commenting::get_config_value($class, 'require_moderation');
|
$moderated = Commenting::get_config_value($class, 'require_moderation');
|
||||||
|
if(!$moderated){
|
||||||
|
$moderated_nonmembers = Commenting::get_config_value($class, 'require_moderation_nonmembers');
|
||||||
|
$moderated = $moderated_nonmembers ? !Member::currentUser() : false;
|
||||||
|
}
|
||||||
|
|
||||||
// we want to show a notification if comments are moderated
|
// we want to show a notification if comments are moderated
|
||||||
if ($moderated) {
|
if ($moderated) {
|
||||||
Session::set('CommentsModerated', 1);
|
Session::set('CommentsModerated', 1);
|
||||||
|
@ -57,14 +57,14 @@ class CommentsExtension extends DataExtension {
|
|||||||
|
|
||||||
// Filter content for unauthorised users
|
// Filter content for unauthorised users
|
||||||
if (!($member = Member::currentUser()) || !Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin')) {
|
if (!($member = Member::currentUser()) || !Permission::checkMember($member, 'CMS_ACCESS_CommentAdmin')) {
|
||||||
|
|
||||||
// Filter unmoderated comments for non-administrators if moderation is enabled
|
// Filter unmoderated comments for non-administrators if moderation is enabled
|
||||||
if (Commenting::get_config_value($this->ownerBaseClass, 'require_moderation')) {
|
if (Commenting::get_config_value($this->ownerBaseClass, 'require_moderation') || Commenting::get_config_value($this->ownerBaseClass, 'require_moderation_nonmembers')) {
|
||||||
$list = $list->filter('Moderated', 1);
|
$list = $list->filter('Moderated', 1);
|
||||||
} else {
|
} else {
|
||||||
// Filter spam comments for non-administrators if auto-moderted
|
// Filter spam comments for non-administrators if auto-moderted
|
||||||
$list = $list->filter('IsSpam', 0);
|
$list = $list->filter('IsSpam', 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = new PaginatedList($list);
|
$list = new PaginatedList($list);
|
||||||
@ -106,7 +106,7 @@ class CommentsExtension extends DataExtension {
|
|||||||
// on a {@link DataObject} then it is enabled, however {@link SiteTree} objects can
|
// on a {@link DataObject} then it is enabled, however {@link SiteTree} objects can
|
||||||
// trigger comments on / off via ProvideComments
|
// trigger comments on / off via ProvideComments
|
||||||
$enabled = (!$this->attachedToSiteTree() || $this->owner->ProvideComments) ? true : false;
|
$enabled = (!$this->attachedToSiteTree() || $this->owner->ProvideComments) ? true : false;
|
||||||
|
|
||||||
// do not include the comments on pages which don't have id's such as security pages
|
// do not include the comments on pages which don't have id's such as security pages
|
||||||
if($this->owner->ID < 0) return false;
|
if($this->owner->ID < 0) return false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user