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", "Comment" => "Text",
"IsSpam" => "Boolean", "IsSpam" => "Boolean",
"NeedsModeration" => "Boolean", "NeedsModeration" => "Boolean",
"CommenterURL" => "Varchar(255)" "CommenterURL" => "Varchar(255)",
"SessionID" => "Varchar(255)"
); );
static $has_one = array( static $has_one = array(
@ -185,6 +186,8 @@ class PageComment_Controller extends Controller {
$comment->NeedsModeration = false; $comment->NeedsModeration = false;
$comment->write(); $comment->write();
// @todo Report to spamprotecter this is true
if(Director::is_ajax()) { if(Director::is_ajax()) {
echo $comment->renderWith('PageCommentInterface_singlecomment'); echo $comment->renderWith('PageCommentInterface_singlecomment');
} else { } else {
@ -194,16 +197,25 @@ class PageComment_Controller extends Controller {
} }
function reportspam() { 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 { try {
$akismet = new SSAkismet(); $akismet = new SSAkismet();
$akismet->setCommentAuthor($comment->getField('Name')); $akismet->setCommentAuthor($comment->getField('Name'));
$akismet->setCommentContent($comment->getField('Comment')); $akismet->setCommentContent($comment->getField('Comment'));
$akismet->submitSpam(); $akismet->submitSpam();
} catch (Exception $e) { } catch (Exception $e) {
// Akismet didn't work, most likely the service is down. // Akismet didn't work, most likely the service is down.
@ -212,12 +224,10 @@ class PageComment_Controller extends Controller {
if(SSAkismet::getSaveSpam()) { if(SSAkismet::getSaveSpam()) {
$comment->setField('IsSpam', true); $comment->setField('IsSpam', true);
$comment->write(); $comment->write();
} else {
$comment->delete();
} }
} }
} }
}
if(Director::is_ajax()) { if(Director::is_ajax()) {
if(SSAkismet::getSaveSpam()) { if(SSAkismet::getSaveSpam()) {
echo $comment->renderWith('PageCommentInterface_singlecomment'); echo $comment->renderWith('PageCommentInterface_singlecomment');
@ -228,36 +238,41 @@ class PageComment_Controller extends Controller {
Director::redirectBack(); Director::redirectBack();
} }
} }
/**
* Report a Spam Comment as valid comment (not spam)
*/
function reportham() {
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
if($comment) {
if(Permission::check('CMS_ACCESS_CMSMain')) {
// if spam protection module exists
if(class_exists('SpamProtecterManager')) {
SpamProtecterManager::send_feedback($comment, 'ham');
$comment->setField('IsSpam', false);
$comment->write();
} }
function reportham() {
if(SSAkismet::isEnabled()) { if(SSAkismet::isEnabled()) {
if(Permission::check('CMS_ACCESS_CMSMain')) {
$comment = DataObject::get_by_id("PageComment", $this->urlParams['ID']);
if($comment) {
try { try {
$akismet = new SSAkismet(); $akismet = new SSAkismet();
$akismet->setCommentAuthor($comment->getField('Name')); $akismet->setCommentAuthor($comment->getField('Name'));
$akismet->setCommentContent($comment->getField('Comment')); $akismet->setCommentContent($comment->getField('Comment'));
$akismet->submitHam(); $akismet->submitHam();
} catch (Exception $e) { } catch (Exception $e) {
// Akismet didn't work, most likely the service is down. // Akismet didn't work, most likely the service is down.
} }
$comment->setField('IsSpam', false); $comment->setField('IsSpam', false);
$comment->write(); $comment->write();
} }
} }
}
if(Director::is_ajax()) { if(Director::is_ajax()) {
echo $comment->renderWith('PageCommentInterface_singlecomment'); echo $comment->renderWith('PageCommentInterface_singlecomment');
} else { } else {
Director::redirectBack(); Director::redirectBack();
} }
} }
}
} }

View File

@ -269,9 +269,16 @@ class PageCommentInterface_Form extends Form {
$comment = Object::create('PageComment'); $comment = Object::create('PageComment');
$this->saveInto($comment); $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->IsSpam = false;
$comment->NeedsModeration = PageComment::moderationEnabled(); $comment->NeedsModeration = PageComment::moderationEnabled();
$comment->write(); $comment->write();
Cookie::set("PageCommentInterface_Comment", ''); Cookie::set("PageCommentInterface_Comment", '');
if(Director::is_ajax()) { if(Director::is_ajax()) {
if($comment->NeedsModeration){ if($comment->NeedsModeration){