2007-08-08 03:16:02 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Comment administration system within the CMS
|
|
|
|
* @package cms
|
|
|
|
* @subpackage comments
|
|
|
|
*/
|
2007-08-13 02:32:48 +02:00
|
|
|
class CommentAdmin extends LeftAndMain {
|
2008-11-02 22:27:55 +01:00
|
|
|
|
|
|
|
static $url_segment = 'comments';
|
|
|
|
|
|
|
|
static $url_rule = '/$Action';
|
|
|
|
|
|
|
|
static $menu_title = 'Comments';
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
static $allowed_actions = array(
|
|
|
|
'approvedmarked',
|
|
|
|
'deleteall',
|
|
|
|
'deletemarked',
|
|
|
|
'hammarked',
|
|
|
|
'showtable',
|
|
|
|
'spammarked',
|
2008-08-11 02:03:57 +02:00
|
|
|
'EditForm',
|
2008-02-25 03:10:37 +01:00
|
|
|
);
|
2007-08-08 03:16:02 +02:00
|
|
|
|
|
|
|
public function init() {
|
|
|
|
parent::init();
|
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::javascript(CMS_DIR . '/javascript/CommentAdmin_right.js');
|
|
|
|
Requirements::css(CMS_DIR . 'css/CommentAdmin.css');
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
2008-11-02 22:27:55 +01:00
|
|
|
public function getMenuTitle() {
|
|
|
|
return _t('LeftAndMain.COMMENTS', 'Comments', PR_HIGH, 'Menu title');
|
|
|
|
}
|
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') {
|
2008-11-24 10:30:41 +01:00
|
|
|
$filter = 'NOT "IsSpam" AND NOT "NeedsModeration"';
|
2008-02-25 03:10:37 +01:00
|
|
|
$title = "<h2>". _t('CommentAdmin.APPROVEDCOMMENTS', 'Approved Comments')."</h2>";
|
2007-08-08 08:00:20 +02:00
|
|
|
} else if($section == 'unmoderated') {
|
2008-11-24 10:30:41 +01:00
|
|
|
$filter = '"NeedsModeration"';
|
2008-02-25 03:10:37 +01:00
|
|
|
$title = "<h2>"._t('CommentAdmin.COMMENTSAWAITINGMODERATION', 'Comments Awaiting Moderation')."</h2>";
|
2007-08-08 03:16:02 +02:00
|
|
|
} else {
|
2008-11-24 10:30:41 +01:00
|
|
|
$filter = '"IsSpam"';
|
2008-02-25 03:10:37 +01:00
|
|
|
$title = "<h2>"._t('CommentAdmin.SPAM', 'Spam')."</h2>";
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
2008-11-24 10:30:41 +01:00
|
|
|
$filter .= ' AND "ParentID">0';
|
2007-11-04 22:46:36 +01:00
|
|
|
|
2007-08-08 05:59:50 +02:00
|
|
|
$tableFields = array(
|
2008-02-25 03:10:37 +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-02-25 03:10:37 +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-02-25 03:10:37 +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') {
|
2008-02-25 03:10:37 +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') {
|
2008-02-25 03:10:37 +01:00
|
|
|
$actions->push(new FormAction('spammarked', _t('CommentAdmin.SPAMMARKED', 'Mark as spam')));
|
2007-08-10 01:19:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if($section == 'spam') {
|
2008-02-25 03:10:37 +01:00
|
|
|
$actions->push(new FormAction('hammarked', _t('CommentAdmin.MARKASNOTSPAM', 'Mark as not spam')));
|
2007-08-10 01:19:20 +02:00
|
|
|
}
|
|
|
|
|
2008-02-25 03:10:37 +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') {
|
2008-02-25 03:10:37 +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) {
|
2008-11-24 10:30:41 +01:00
|
|
|
$comment = DataObject::get_one('PageComment', "\"PageComment\".\"ID\" = $commentid");
|
2007-08-10 00:59:20 +02:00
|
|
|
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-11-24 10:30:41 +01:00
|
|
|
$spam = DataObject::get('PageComment', '"PageComment"."IsSpam"');
|
2007-08-13 02:39:37 +02:00
|
|
|
|
|
|
|
if($spam) {
|
|
|
|
$numComments = $spam->Count();
|
|
|
|
|
|
|
|
foreach($spam as $comment) {
|
|
|
|
$comment->delete();
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 03:10:37 +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-02-25 03:10:37 +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) {
|
2008-11-24 10:30:41 +01:00
|
|
|
$comment = DataObject::get_one('PageComment', "\"PageComment\".\"ID\" = $commentid");
|
2007-08-10 01:19:20 +02:00
|
|
|
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-02-25 03:10:37 +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-02-25 03:10:37 +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) {
|
2008-11-24 10:30:41 +01:00
|
|
|
$comment = DataObject::get_one('PageComment', "\"PageComment\".\"ID\" = $commentid");
|
2007-08-10 01:19:20 +02:00
|
|
|
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-02-25 03:10:37 +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-02-25 03:10:37 +01:00
|
|
|
statusMessage("$msg");
|
2007-08-10 01:19:20 +02:00
|
|
|
JS;
|
|
|
|
}
|
|
|
|
|
2008-11-10 05:07:03 +01:00
|
|
|
function acceptmarked() {
|
2007-08-10 01:19:20 +02:00
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
2008-11-24 10:30:41 +01:00
|
|
|
$comment = DataObject::get_one('PageComment', "\"PageComment\".\"ID\" = $commentid");
|
2007-08-10 01:19:20 +02:00
|
|
|
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-02-25 03:10:37 +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;
|
|
|
|
}
|
2008-09-30 02:05:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of moderated comments
|
|
|
|
*/
|
|
|
|
function NumModerated() {
|
2008-11-24 10:30:41 +01:00
|
|
|
return DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE NOT \"IsSpam\" AND NOT \"NeedsModeration\"")->value();
|
2008-09-30 02:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of unmoderated comments
|
|
|
|
*/
|
|
|
|
function NumUnmoderated() {
|
2008-11-24 10:30:41 +01:00
|
|
|
return DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE NOT \"IsSpam\" AND \"NeedsModeration\"")->value();
|
2008-09-30 02:05:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of comments marked as spam
|
|
|
|
*/
|
|
|
|
function NumSpam() {
|
2008-11-24 10:30:41 +01:00
|
|
|
return DB::query("SELECT COUNT(*) FROM \"PageComment\" WHERE \"IsSpam\"")->value();
|
2008-09-30 02:05:22 +02:00
|
|
|
}
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
2009-01-05 07:17:59 +01:00
|
|
|
?>
|