From 5e5a06d8e92645e85b0dc15729301840b5ddaa55 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 11 Mar 2009 04:45:41 +0000 Subject: [PATCH] MINOR: fixed whitespace issue and added SessionID to page comment git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@72903 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/sitefeatures/PageComment.php | 75 +++++++++++++--------- code/sitefeatures/PageCommentInterface.php | 17 +++-- 2 files changed, 57 insertions(+), 35 deletions(-) diff --git a/code/sitefeatures/PageComment.php b/code/sitefeatures/PageComment.php index 8a63626f..bcc846fe 100755 --- a/code/sitefeatures/PageComment.php +++ b/code/sitefeatures/PageComment.php @@ -11,7 +11,8 @@ class PageComment extends DataObject { "Comment" => "Text", "IsSpam" => "Boolean", "NeedsModeration" => "Boolean", - "CommenterURL" => "Varchar(255)" + "CommenterURL" => "Varchar(255)", + "SessionID" => "Varchar(255)" ); static $has_one = array( @@ -185,6 +186,8 @@ class PageComment_Controller extends Controller { $comment->NeedsModeration = false; $comment->write(); + // @todo Report to spamprotecter this is true + if(Director::is_ajax()) { echo $comment->renderWith('PageCommentInterface_singlecomment'); } else { @@ -194,68 +197,80 @@ class PageComment_Controller extends Controller { } function reportspam() { - if(SSAkismet::isEnabled()) { + $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); + + if($comment) { + // check they have access if(Permission::check('CMS_ACCESS_CMSMain')) { - $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); - if($comment) { + // if spam protection module exists + if(class_exists('SpamProtecterManager')) { + SpamProtecterManager::send_feedback($comment, 'spam'); + $comment->setField('IsSpam', true); + $comment->write(); + } + + // If Akismet is enabled + else 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. } - + 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(); - } } + if(Director::is_ajax()) { + if(SSAkismet::getSaveSpam()) { + echo $comment->renderWith('PageCommentInterface_singlecomment'); + } else { + echo ''; + } + } else { + Director::redirectBack(); + } } - + /** + * Report a Spam Comment as valid comment (not spam) + */ function reportham() { - if(SSAkismet::isEnabled()) { + $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); + if($comment) { if(Permission::check('CMS_ACCESS_CMSMain')) { - $comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']); + + // if spam protection module exists + if(class_exists('SpamProtecterManager')) { + SpamProtecterManager::send_feedback($comment, 'ham'); + $comment->setField('IsSpam', false); + $comment->write(); + } - if($comment) { + 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. } - $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(); } } diff --git a/code/sitefeatures/PageCommentInterface.php b/code/sitefeatures/PageCommentInterface.php index f80700e5..f9cd5ff4 100755 --- a/code/sitefeatures/PageCommentInterface.php +++ b/code/sitefeatures/PageCommentInterface.php @@ -221,7 +221,7 @@ class PageCommentInterface_Form extends Form { Cookie::set("PageCommentInterface_Name", $data['Name']); Cookie::set("PageCommentInterface_CommenterURL", $data['CommenterURL']); Cookie::set("PageCommentInterface_Comment", $data['Comment']); - + if(SSAkismet::isEnabled()) { try { $akismet = new SSAkismet(); @@ -251,10 +251,10 @@ class PageCommentInterface_Form extends Form { //check if spam question was right. if(MathSpamProtection::isEnabled()){ if(!MathSpamProtection::correctAnswer($data['Math'])){ - if(!Director::is_ajax()) { - Director::redirectBack(); - } - return "spamprotectionfailed"; //used by javascript for checking if the spam question was wrong + if(!Director::is_ajax()) { + Director::redirectBack(); + } + return "spamprotectionfailed"; //used by javascript for checking if the spam question was wrong } } @@ -269,9 +269,16 @@ class PageCommentInterface_Form extends Form { $comment = Object::create('PageComment'); $this->saveInto($comment); + + // Store the Session ID if needed for Spamprotection + if($session = Session::get('mollom_user_session_id')) { + $comment->SessionID = $session; + Session::clear('mollom_user_session_id'); + } $comment->IsSpam = false; $comment->NeedsModeration = PageComment::moderationEnabled(); $comment->write(); + Cookie::set("PageCommentInterface_Comment", ''); if(Director::is_ajax()) { if($comment->NeedsModeration){