From 2a64b249a278e50323b0488927de353097c070e1 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Sun, 12 Aug 2007 23:11:37 +0000 Subject: [PATCH] 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 --- code/CommentTableField.php | 44 +++++++++++++++++++++++++++++--------- code/FeedbackAdmin.php | 27 ++++++++++++++++++++++- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/code/CommentTableField.php b/code/CommentTableField.php index 6584009f..a87325b4 100644 --- a/code/CommentTableField.php +++ b/code/CommentTableField.php @@ -48,11 +48,23 @@ class CommentTableField extends ComplexTableField { $childId = Convert::raw2sql($_REQUEST['tf']['childID']); if (is_numeric($childId)) { - $childObject = DataObject::get_by_id($this->sourceClass, $childId); - if($childObject) { - $childObject->IsSpam = true; - $childObject->NeedsModeration = false; - $childObject->write(); + $comment = DataObject::get_by_id($this->sourceClass, $childId); + if($comment) { + $comment->IsSpam = true; + $comment->NeedsModeration = false; + $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']); if (is_numeric($childId)) { - $childObject = DataObject::get_by_id($this->sourceClass, $childId); - if($childObject) { - $childObject->IsSpam = false; - $childObject->NeedsModeration = false; - $childObject->write(); + $comment = DataObject::get_by_id($this->sourceClass, $childId); + if($comment) { + $comment->IsSpam = false; + $comment->NeedsModeration = false; + $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. + } + } } } } diff --git a/code/FeedbackAdmin.php b/code/FeedbackAdmin.php index 6698a10b..5a92e371 100644 --- a/code/FeedbackAdmin.php +++ b/code/FeedbackAdmin.php @@ -68,7 +68,7 @@ class FeedbackAdmin extends LeftAndMain { $actions->push(new FormAction('acceptmarked', 'Accept')); } - if($section == 'accepted' || $section == 'unmoderated') { + if($section == 'approved' || $section == 'unmoderated') { $actions->push(new FormAction('spammarked', 'Mark as spam')); } @@ -119,6 +119,18 @@ JS; $comment->IsSpam = true; $comment->NeedsModeration = false; $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++; } } @@ -145,6 +157,19 @@ JS; $comment->IsSpam = false; $comment->NeedsModeration = false; $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++; } }