BUGFIX: Fixed Links to Moderate Comments from the CMS and front end. MINOR: removed complextable functions which no longer get called, moved logic to the PageComment Class (from r86325)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90853 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-11-05 01:16:09 +00:00
parent 966c869cd4
commit 8adc6757c2
2 changed files with 18 additions and 121 deletions

View File

@ -50,87 +50,6 @@ class CommentTableField extends ComplexTableField {
return $output; return $output;
} }
function spam() {
if(!Permission::check('ADMIN')) {
return false;
}
$this->methodName = "spam";
$childId = Convert::raw2sql($_REQUEST['ctf']['childID']);
if (is_numeric($childId)) {
$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.
}
}
}
}
}
function ham() {
if(!Permission::check('ADMIN')) {
return false;
}
$this->methodName = "ham";
$childId = Convert::raw2sql($_REQUEST['ctf']['childID']);
if (is_numeric($childId)) {
$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.
}
}
}
}
}
function approve() {
if(!Permission::check('ADMIN')) {
return false;
}
$this->methodName = "accept";
$childId = Convert::raw2sql($_REQUEST['ctf']['childID']);
if(is_numeric($childId)) {
$childObject = DataObject::get_by_id($this->sourceClass, $childId);
if($childObject) {
$childObject->IsSpam = false;
$childObject->NeedsModeration = false;
$childObject->write();
}
}
}
function HasSpamButton() { function HasSpamButton() {
return $this->mode == 'approved' || $this->mode == 'unmoderated'; return $this->mode == 'approved' || $this->mode == 'unmoderated';
} }
@ -180,18 +99,6 @@ class CommentTableField_Item extends ComplexTableField_Item {
function HasHamButton() { function HasHamButton() {
return $this->parent()->HasHamButton(); return $this->parent()->HasHamButton();
} }
function SpamLink() {
return Controller::join_links($this->Link(), "?methodName=spam");
}
function HamLink() {
return Controller::join_links($this->Link(), "?methodName=ham");
}
function ApproveLink() {
return Controller::join_links($this->Link(), "?methodName=approve");
}
} }
?> ?>

View File

@ -59,9 +59,7 @@ class PageComment extends DataObject {
} }
function DeleteLink() { function DeleteLink() {
if(Permission::check('CMS_ACCESS_CMSMain')) { return (Permission::check('CMS_ACCESS_CMSMain')) ? "PageComment_Controller/deletecomment/$this->ID" : false;
return "PageComment/deletecomment/$this->ID";
}
} }
function CommentTextWithLinks() { function CommentTextWithLinks() {
@ -71,22 +69,15 @@ class PageComment extends DataObject {
} }
function SpamLink() { function SpamLink() {
$member = Member::currentUser(); return (Permission::check('CMS_ACCESS_CMSMain') && !$this->IsSpam) ? "PageComment_Controller/reportspam/$this->ID" : false;
if(Permission::check('CMS_ACCESS_CMSMain') && !$this->getField('IsSpam')) {
return "PageComment/reportspam/$this->ID";
}
} }
function HamLink() { function HamLink() {
if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('IsSpam')) { return (Permission::check('CMS_ACCESS_CMSMain') && $this->IsSpam) ? "PageComment_Controller/reportham/$this->ID" : false;
return "PageComment/reportham/$this->ID";
}
} }
function ApproveLink() { function ApproveLink() {
if(Permission::check('CMS_ACCESS_CMSMain') && $this->getField('NeedsModeration')) { return (Permission::check('CMS_ACCESS_CMSMain') && $this->NeedsModeration) ? "PageComment_Controller/approve/$this->ID" : false;
return "PageComment/approve/$this->ID";
}
} }
function SpamClass() { function SpamClass() {
@ -203,6 +194,8 @@ class PageComment_Controller extends Controller {
function approve() { function approve() {
if(Permission::check('CMS_ACCESS_CMSMain')) { 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) {
$comment->NeedsModeration = false; $comment->NeedsModeration = false;
$comment->write(); $comment->write();
@ -215,10 +208,10 @@ class PageComment_Controller extends Controller {
} }
} }
} }
}
function reportspam() { function reportspam() {
$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 // check they have access
if(Permission::check('CMS_ACCESS_CMSMain')) { if(Permission::check('CMS_ACCESS_CMSMain')) {
@ -226,8 +219,6 @@ class PageComment_Controller extends Controller {
// if spam protection module exists // if spam protection module exists
if(class_exists('SpamProtectorManager')) { if(class_exists('SpamProtectorManager')) {
SpamProtectorManager::send_feedback($comment, 'spam'); SpamProtectorManager::send_feedback($comment, 'spam');
$comment->setField('IsSpam', true);
$comment->write();
} }
// If Akismet is enabled // If Akismet is enabled
@ -240,14 +231,13 @@ class PageComment_Controller extends Controller {
} 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.
} }
}
if(SSAkismet::getSaveSpam()) { $comment->IsSpam = true;
$comment->setField('IsSpam', true); $comment->NeedsModeration = false;
$comment->write(); $comment->write();
} }
} }
}
}
if(Director::is_ajax()) { if(Director::is_ajax()) {
if(SSAkismet::getSaveSpam()) { if(SSAkismet::getSaveSpam()) {
echo $comment->renderWith('PageCommentInterface_singlecomment'); echo $comment->renderWith('PageCommentInterface_singlecomment');