Report spam/ham to akismet if it is enabled

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@39887 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2007-08-12 23:11:37 +00:00
parent d7ea506562
commit 2a64b249a2
2 changed files with 60 additions and 11 deletions

View File

@ -48,11 +48,23 @@ class CommentTableField extends ComplexTableField {
$childId = Convert::raw2sql($_REQUEST['tf']['childID']); $childId = Convert::raw2sql($_REQUEST['tf']['childID']);
if (is_numeric($childId)) { if (is_numeric($childId)) {
$childObject = DataObject::get_by_id($this->sourceClass, $childId); $comment = DataObject::get_by_id($this->sourceClass, $childId);
if($childObject) { if($comment) {
$childObject->IsSpam = true; $comment->IsSpam = true;
$childObject->NeedsModeration = false; $comment->NeedsModeration = false;
$childObject->write(); $comment->write();
if(SSAkismet::isEnabled()) {
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.
}
}
} }
} }
} }
@ -67,11 +79,23 @@ class CommentTableField extends ComplexTableField {
$childId = Convert::raw2sql($_REQUEST['tf']['childID']); $childId = Convert::raw2sql($_REQUEST['tf']['childID']);
if (is_numeric($childId)) { if (is_numeric($childId)) {
$childObject = DataObject::get_by_id($this->sourceClass, $childId); $comment = DataObject::get_by_id($this->sourceClass, $childId);
if($childObject) { if($comment) {
$childObject->IsSpam = false; $comment->IsSpam = false;
$childObject->NeedsModeration = false; $comment->NeedsModeration = false;
$childObject->write(); $comment->write();
if(SSAkismet::isEnabled()) {
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.
}
}
} }
} }
} }

View File

@ -68,7 +68,7 @@ class FeedbackAdmin extends LeftAndMain {
$actions->push(new FormAction('acceptmarked', 'Accept')); $actions->push(new FormAction('acceptmarked', 'Accept'));
} }
if($section == 'accepted' || $section == 'unmoderated') { if($section == 'approved' || $section == 'unmoderated') {
$actions->push(new FormAction('spammarked', 'Mark as spam')); $actions->push(new FormAction('spammarked', 'Mark as spam'));
} }
@ -119,6 +119,18 @@ JS;
$comment->IsSpam = true; $comment->IsSpam = true;
$comment->NeedsModeration = false; $comment->NeedsModeration = false;
$comment->write(); $comment->write();
if(SSAkismet::isEnabled()) {
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.
}
}
$numComments++; $numComments++;
} }
} }
@ -145,6 +157,19 @@ JS;
$comment->IsSpam = false; $comment->IsSpam = false;
$comment->NeedsModeration = false; $comment->NeedsModeration = false;
$comment->write(); $comment->write();
if(SSAkismet::isEnabled()) {
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.
}
}
$numComments++; $numComments++;
} }
} }