2007-08-08 03:16:02 +02:00
|
|
|
<?php
|
|
|
|
|
2008-01-08 07:41:55 +01:00
|
|
|
/**
|
|
|
|
* @package cms
|
2008-01-10 01:33:49 +01:00
|
|
|
* @subpackage comments
|
2008-01-08 07:41:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comment administration system within the CMS
|
2008-01-10 01:33:49 +01:00
|
|
|
* @package cms
|
|
|
|
* @subpackage comments
|
2008-01-08 07:41:55 +01:00
|
|
|
*/
|
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();
|
|
|
|
|
2008-01-10 23:27:38 +01:00
|
|
|
Requirements::javascript('cms/javascript/CommentAdmin_right.js');
|
|
|
|
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-12-12 23:57:29 +01:00
|
|
|
$title = "<h2>". _t('CommentAdmin.APPROVEDCOMMENTS', '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-12-12 23:57:29 +01:00
|
|
|
$title = "<h2>"._t('CommentAdmin.COMMENTSAWAITINGMODERATION', 'Comments Awaiting Moderation')."</h2>";
|
2007-08-08 03:16:02 +02:00
|
|
|
} else {
|
|
|
|
$filter = 'IsSpam=1';
|
2007-12-12 23:57:29 +01:00
|
|
|
$title = "<h2>"._t('CommentAdmin.SPAM', '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-12-12 23:57:29 +01:00
|
|
|
"Name" => _t('CommentAdmin.AUTHOR', 'Author'),
|
|
|
|
"Comment" => _t('CommentAdmin.COMMENT', 'Comment'),
|
|
|
|
"PageTitle" => _t('CommentAdmin.PAGE', 'Page'),
|
|
|
|
"Created" => _t('CommentAdmin.DATEPOSTED', '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(
|
2008-01-10 04:28:13 +01:00
|
|
|
new TextField('Name', _t('CommentAdmin.NAME', 'Name')),
|
|
|
|
new TextareaField('Comment', _t('CommentAdmin.COMMENT', 'Comment'))
|
2007-08-08 08:00:20 +02:00
|
|
|
);
|
|
|
|
|
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',
|
2008-01-10 04:28:13 +01:00
|
|
|
new Tab(_t('CommentAdmin.COMMENTS', 'Comments'),
|
2007-11-05 22:03:19 +01:00
|
|
|
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') {
|
2007-12-12 23:57:29 +01:00
|
|
|
$actions->push(new FormAction('acceptmarked', _t('CommentAdmin.ACCEPT', 'Accept')));
|
2007-08-10 01:19:20 +02:00
|
|
|
}
|
|
|
|
|
2007-08-13 01:11:37 +02:00
|
|
|
if($section == 'approved' || $section == 'unmoderated') {
|
2007-12-12 23:57:29 +01:00
|
|
|
$actions->push(new FormAction('spammarked', _t('CommentAdmin.SPAMMARKED', 'Mark as spam')));
|
2007-08-10 01:19:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if($section == 'spam') {
|
2007-12-12 23:57:29 +01:00
|
|
|
$actions->push(new FormAction('hammarked', _t('CommentAdmin.MARKASNOTSPAM', 'Mark as not spam')));
|
2007-08-10 01:19:20 +02:00
|
|
|
}
|
|
|
|
|
2007-12-12 23:57:29 +01:00
|
|
|
$actions->push(new FormAction('deletemarked', _t('CommentAdmin.DELETE', 'Delete')));
|
2007-08-10 00:59:20 +02:00
|
|
|
|
2007-08-13 02:39:37 +02:00
|
|
|
if($section == 'spam') {
|
2007-12-12 23:57:29 +01:00
|
|
|
$actions->push(new FormAction('deleteall', _t('CommentAdmin.DELETEALL', 'Delete All')));
|
2007-08-13 02:39:37 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2008-01-10 23:27:38 +01:00
|
|
|
$spam = DataObject::get('PageComment', 'PageComment.IsSpam=1');
|
2007-08-13 02:39:37 +02:00
|
|
|
|
|
|
|
if($spam) {
|
|
|
|
$numComments = $spam->Count();
|
|
|
|
|
|
|
|
foreach($spam as $comment) {
|
|
|
|
$comment->delete();
|
|
|
|
}
|
|
|
|
}
|
2008-01-10 04:28:13 +01:00
|
|
|
|
|
|
|
$msg = sprintf(_t('CommentAdmin.DELETED', 'Deleted %s comments.'), $numComments);
|
2007-08-13 02:39:37 +02:00
|
|
|
echo <<<JS
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
2008-01-10 04:28:13 +01:00
|
|
|
statusMessage("$msg");
|
2007-08-13 02:39:37 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-01-10 04:28:13 +01:00
|
|
|
$msg = sprintf(_t('CommentAdmin.MARKEDSPAM', 'Marked %s comments as spam.'), $numComments);
|
2007-08-10 01:19:20 +02:00
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
2008-01-10 04:28:13 +01:00
|
|
|
statusMessage("$msg");
|
2007-08-10 01:19:20 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-01-10 04:28:13 +01:00
|
|
|
$msg = sprintf(_t('CommentAdmin.MARKEDNOTSPAM', 'Marked %s comments as not spam.'), $numComments);
|
2007-08-10 01:19:20 +02:00
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
2008-01-10 04:28:13 +01:00
|
|
|
statusMessage("$msg");
|
2007-08-10 01:19:20 +02:00
|
|
|
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);
|
|
|
|
}
|
2008-01-10 04:28:13 +01:00
|
|
|
|
|
|
|
$msg = sprintf(_t('CommentAdmin.APPROVED', 'Accepted %s comments.'), $numComments);
|
2007-08-10 01:19:20 +02:00
|
|
|
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
|
|
|
?>
|