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
This commit is contained in:
Will Rossiter 2009-03-11 04:45:41 +00:00 committed by Sam Minnee
parent 27bfe60a33
commit 5e5a06d8e9
2 changed files with 57 additions and 35 deletions

View File

@ -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,16 +197,25 @@ class PageComment_Controller extends Controller {
}
function reportspam() {
if(SSAkismet::isEnabled()) {
if(Permission::check('CMS_ACCESS_CMSMain')) {
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
if($comment) {
if($comment) {
// check they have access
if(Permission::check('CMS_ACCESS_CMSMain')) {
// 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.
@ -212,50 +224,53 @@ class PageComment_Controller extends Controller {
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 '';
}
}
if(Director::is_ajax()) {
if(SSAkismet::getSaveSpam()) {
echo $comment->renderWith('PageCommentInterface_singlecomment');
} else {
Director::redirectBack();
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($comment) {
// if spam protection module exists
if(class_exists('SpamProtecterManager')) {
SpamProtecterManager::send_feedback($comment, 'ham');
$comment->setField('IsSpam', 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.
}
$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();
}
}

View File

@ -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){