2007-08-08 03:16:02 +02:00
|
|
|
<?php
|
|
|
|
|
2007-08-13 02:32:48 +02:00
|
|
|
class CommentAdmin extends LeftAndMain {
|
2007-08-08 03:16:02 +02:00
|
|
|
|
|
|
|
public function init() {
|
|
|
|
parent::init();
|
|
|
|
|
2007-08-13 02:32:48 +02:00
|
|
|
Requirements::javascript("cms/javascript/CommentAdmin_right.js");
|
2007-09-27 22:56:55 +02:00
|
|
|
Requirements::css("cms/css/CommentAdmin.css");
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function Link($action = null) {
|
2007-08-13 02:32:48 +02:00
|
|
|
return "admin/comments/$action";
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function showtable($params) {
|
2007-08-13 02:32:48 +02:00
|
|
|
return $this->getLastFormIn($this->renderWith('CommentAdmin_right'));
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
2007-08-10 07:02:52 +02:00
|
|
|
public function Section() {
|
2007-08-08 03:16:02 +02:00
|
|
|
$url = rtrim($_SERVER['REQUEST_URI'], '/');
|
2007-08-10 00:59:20 +02:00
|
|
|
if(strrpos($url, '&')) {
|
|
|
|
$url = substr($url, 0, strrpos($url, '&'));
|
|
|
|
}
|
2007-08-08 03:16:02 +02:00
|
|
|
$section = substr($url, strrpos($url, '/') + 1);
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') {
|
|
|
|
$section = 'approved';
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
2007-08-10 07:02:52 +02:00
|
|
|
return $section;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function EditForm() {
|
|
|
|
$section = $this->Section();
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
if($section == 'approved') {
|
2007-08-08 03:16:02 +02:00
|
|
|
$filter = 'IsSpam=0 AND NeedsModeration=0';
|
2007-08-13 00:19:06 +02:00
|
|
|
$title = "<h2>Approved Comments</h2>";
|
2007-08-08 08:00:20 +02:00
|
|
|
} else if($section == 'unmoderated') {
|
2007-08-08 03:16:02 +02:00
|
|
|
$filter = 'NeedsModeration=1';
|
2007-08-10 02:03:30 +02:00
|
|
|
$title = "<h2>Comments Awaiting Moderation</h2>";
|
2007-08-08 03:16:02 +02:00
|
|
|
} else {
|
|
|
|
$filter = 'IsSpam=1';
|
2007-08-10 02:03:30 +02:00
|
|
|
$title = "<h2>Spam</h2>";
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
2007-11-04 22:46:36 +01:00
|
|
|
$filter .= ' AND ParentID>0';
|
|
|
|
|
2007-08-08 05:59:50 +02:00
|
|
|
$tableFields = array(
|
2007-08-08 08:00:20 +02:00
|
|
|
"Name" => "Author",
|
2007-08-08 05:59:50 +02:00
|
|
|
"Comment" => "Comment",
|
2007-08-10 02:47:11 +02:00
|
|
|
"PageTitle" => "Page",
|
|
|
|
"Created" => "Date Posted"
|
2007-08-10 02:03:30 +02:00
|
|
|
);
|
2007-08-08 05:59:50 +02:00
|
|
|
|
2007-08-08 08:00:20 +02:00
|
|
|
$popupFields = new FieldSet(
|
|
|
|
new TextField("Name"),
|
|
|
|
new TextareaField("Comment", "Comment")
|
|
|
|
);
|
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
$idField = new HiddenField('ID', '', $section);
|
2007-08-10 02:03:30 +02:00
|
|
|
$table = new CommentTableField($this, "Comments", "PageComment", $section, $tableFields, $popupFields, array($filter));
|
2007-08-08 08:00:20 +02:00
|
|
|
$table->setParentClass(false);
|
2007-08-08 03:16:02 +02:00
|
|
|
|
2007-11-05 22:03:19 +01:00
|
|
|
$fields = new FieldSet(
|
|
|
|
new TabSet( 'Root',
|
|
|
|
new Tab('Comments',
|
|
|
|
new LiteralField("Title", $title),
|
|
|
|
$idField,
|
|
|
|
$table
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2007-08-10 00:59:20 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
$actions = new FieldSet();
|
|
|
|
|
|
|
|
if($section == 'unmoderated') {
|
|
|
|
$actions->push(new FormAction('acceptmarked', 'Accept'));
|
|
|
|
}
|
|
|
|
|
2007-08-13 01:11:37 +02:00
|
|
|
if($section == 'approved' || $section == 'unmoderated') {
|
2007-08-10 01:19:20 +02:00
|
|
|
$actions->push(new FormAction('spammarked', 'Mark as spam'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if($section == 'spam') {
|
|
|
|
$actions->push(new FormAction('hammarked', 'Mark as not spam'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$actions->push(new FormAction('deletemarked', 'Delete'));
|
2007-08-10 00:59:20 +02:00
|
|
|
|
2007-08-13 02:39:37 +02:00
|
|
|
if($section == 'spam') {
|
|
|
|
$actions->push(new FormAction('deleteall', 'Delete All'));
|
|
|
|
}
|
|
|
|
|
2007-08-08 03:16:02 +02:00
|
|
|
$form = new Form($this, "EditForm", $fields, $actions);
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
2007-08-10 00:59:20 +02:00
|
|
|
|
|
|
|
function deletemarked() {
|
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
|
|
|
$comment = DataObject::get_one('PageComment', "`PageComment`.ID = $commentid");
|
|
|
|
if($comment) {
|
|
|
|
$comment->delete();
|
|
|
|
$numComments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("Deleted $numComments comments.");
|
2007-08-10 01:19:20 +02:00
|
|
|
JS;
|
|
|
|
}
|
|
|
|
|
2007-08-13 02:39:37 +02:00
|
|
|
function deleteall() {
|
|
|
|
$numComments = 0;
|
|
|
|
$spam = DataObject::get('PageComment', "PageComment.IsSpam=1");
|
|
|
|
|
|
|
|
if($spam) {
|
|
|
|
$numComments = $spam->Count();
|
|
|
|
|
|
|
|
foreach($spam as $comment) {
|
|
|
|
$comment->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo <<<JS
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("Deleted $numComments comments.");
|
|
|
|
JS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
function spammarked() {
|
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
|
|
|
$comment = DataObject::get_one('PageComment', "`PageComment`.ID = $commentid");
|
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = true;
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
2007-08-13 01:11:37 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
}
|
2007-08-10 01:19:20 +02:00
|
|
|
$numComments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("Marked $numComments comments as spam.");
|
|
|
|
JS;
|
|
|
|
}
|
|
|
|
|
|
|
|
function hammarked() {
|
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
|
|
|
$comment = DataObject::get_one('PageComment', "`PageComment`.ID = $commentid");
|
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = false;
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
2007-08-13 01:11:37 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
$numComments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("Marked $numComments comments as not spam.");
|
|
|
|
JS;
|
|
|
|
}
|
|
|
|
|
2007-08-13 00:19:06 +02:00
|
|
|
function approvemarked() {
|
2007-08-10 01:19:20 +02:00
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
|
|
|
$comment = DataObject::get_one('PageComment', "`PageComment`.ID = $commentid");
|
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = false;
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
|
|
|
$numComments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("Accepted $numComments comments.");
|
2007-08-10 00:59:20 +02:00
|
|
|
JS;
|
|
|
|
}
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
2007-11-05 22:03:19 +01:00
|
|
|
?>
|