Don't show unmoderated comments unless user is admin, add link to accept comment

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@39818 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2007-08-10 01:29:09 +00:00
parent e3445db25b
commit 6de32f6edc
4 changed files with 117 additions and 56 deletions

View File

@ -52,18 +52,23 @@ class PageComment extends DataObject {
function SpamLink() {
$member = Member::currentUser();
if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain') && !$this->getField('IsSpam')) {
if(Permission::check('CMS_ACCESS_CMSMain') && !$this->getField('IsSpam')) {
return "PageComment/reportspam/$this->ID";
}
}
function HamLink() {
$member = Member::currentUser();
if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) {
if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) {
return "PageComment/reportham/$this->ID";
}
}
function AcceptLink() {
if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('NeedsModeration')) {
return "PageComment/accept/$this->ID";
}
}
function SpamClass() {
if($this->getField('IsSpam')) {
return 'spam';
@ -72,65 +77,83 @@ class PageComment extends DataObject {
}
}
function reportspam() {
if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain')) {
function accept() {
if(Permission::check('CMS_ACCESS_CMSMain')) {
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
$comment->NeedsModeration = false;
$comment->write();
if($comment) {
try {
$akismet = new SSAkismet();
$akismet->setCommentAuthor($comment->getField('Name'));
$akismet->setCommentContent($comment->getField('Comment'));
$akismet->submitSpam();
} catch (Exception $e) {
// Akismet didn't work, most likely the service is down.
}
if(SSAkismet::getSaveSpam()) {
$comment->setField('IsSpam', true);
$comment->write();
} else {
$comment->delete();
}
}
}
if(Director::is_ajax()) {
if(SSAkismet::getSaveSpam()) {
if(Director::is_ajax()) {
echo $comment->renderWith('PageCommentInterface_singlecomment');
} else {
echo '';
Director::redirectBack();
}
}
}
function reportspam() {
if(SSAkismet::isEnabled()) {
if(Permission::check('CMS_ACCESS_CMSMain')) {
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
if($comment) {
try {
$akismet = new SSAkismet();
$akismet->setCommentAuthor($comment->getField('Name'));
$akismet->setCommentContent($comment->getField('Comment'));
$akismet->submitSpam();
} catch (Exception $e) {
// Akismet didn't work, most likely the service is down.
}
if(SSAkismet::getSaveSpam()) {
$comment->setField('IsSpam', true);
$comment->write();
} else {
$comment->delete();
}
}
}
if(Director::is_ajax()) {
if(SSAkismet::getSaveSpam()) {
echo $comment->renderWith('PageCommentInterface_singlecomment');
} else {
echo '';
}
} else {
Director::redirectBack();
}
} else {
Director::redirectBack();
}
}
function reportham() {
if(SSAkismet::isEnabled() && Permission::check('CMS_ACCESS_CMSMain')) {
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
if($comment) {
try {
$akismet = new SSAkismet();
$akismet->setCommentAuthor($comment->getField('Name'));
$akismet->setCommentContent($comment->getField('Comment'));
$akismet->submitHam();
} catch (Exception $e) {
// Akismet didn't work, most likely the service is down.
}
if(SSAkismet::isEnabled()) {
if(Permission::check('CMS_ACCESS_CMSMain')) {
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
$comment->setField('IsSpam', false);
$comment->write();
if($comment) {
try {
$akismet = new SSAkismet();
$akismet->setCommentAuthor($comment->getField('Name'));
$akismet->setCommentContent($comment->getField('Comment'));
$akismet->submitHam();
} catch (Exception $e) {
// Akismet didn't work, most likely the service is down.
}
$comment->setField('IsSpam', false);
$comment->write();
}
}
}
if(Director::is_ajax()) {
echo $comment->renderWith('PageCommentInterface_singlecomment');
} else {
Director::redirectBack();
if(Director::is_ajax()) {
echo $comment->renderWith('PageCommentInterface_singlecomment');
} else {
Director::redirectBack();
}
}
}
@ -158,7 +181,7 @@ class PageComment extends DataObject {
}
static function moderationEnabled() {
return self::moderate;
return self::$moderate;
}
}

View File

@ -142,9 +142,9 @@ class PageCommentInterface_Form extends Form {
$comment = Object::create('PageComment');
$this->saveInto($comment);
$comment->IsSpam = false;
$comment->write();
$comment->NeedsModeration = PageComment::moderationEnabled();
$comment->NeedsModeration = PageComment::moderationEnable();
$comment->write();
if(Director::is_ajax()) {
echo $comment->renderWith('PageCommentInterface_singlecomment');

View File

@ -19,6 +19,9 @@ PageCommentInterface.prototype = {
},
'#PageComments a.hamlink' : {
onclick : this.reportHam
},
'#PageComments a.acceptlink' : {
onclick : this.acceptComment
}
});
},
@ -179,6 +182,33 @@ PageCommentInterface.prototype = {
}
});
return false;
},
/**
* Ajax handler of ham reporting
*/
acceptComment: function() {
var __comment = this.parentNode.parentNode.parentNode;
__comment.getElementsByTagName('span')[0].innerHTML = "Marking comment as accepted...";
new Ajax.Request(this.href + '?ajax=1', {
onSuccess : function(response) {
// Load the response into the <li>
__comment.innerHTML = response.responseText;
Behaviour.apply(__comment);
// Flash it using Scriptaculous
new Effect.Highlight(__comment, { endcolor: '#e9e9e9' } );
__comment.className = 'notspam';
},
onFailure : function(response) {
alert(response.responseText);
}
});
return false;
}
}

View File

@ -1,10 +1,15 @@
<p class="comment" id="PageComment_$ID">$Comment.XML</p>
<p class="comment" id="PageComment_$ID">
<% if NeedsModeration %>
<p><b>Unmoderated comment</b></p>
<% end_if %>
$Comment.XML
</p>
<p class="info">
<span>Posted by $Name.XML, $Created.Nice ($Created.Ago)</span>
<br />
<span>
<% if DeleteLink %>
<a href="$DeleteLink" class="deletelink">remove this comment</a>
<% if AcceptLink %>
<a href="$AcceptLink" class="acceptlink">accept this comment</a>
<% end_if %>
<% if SpamLink %>
<a href="$SpamLink" class="spamlink">this comment is spam</a>
@ -12,5 +17,8 @@
<% if HamLink %>
<a href="$HamLink" class="hamlink">this comment is not spam</a>
<% end_if %>
<% if DeleteLink %>
<a href="$DeleteLink" class="deletelink">remove this comment</a>
<% end_if %>
</span>
</p>