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';
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2008-11-02 22:27:55 +01:00
|
|
|
static $url_rule = '/$Action';
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2008-11-02 22:27:55 +01:00
|
|
|
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',
|
2009-05-21 06:07:01 +02:00
|
|
|
'unmoderated'
|
2008-02-25 03:10:37 +01:00
|
|
|
);
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-08 03:16:02 +02:00
|
|
|
public function init() {
|
|
|
|
parent::init();
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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
|
|
|
}
|
2009-05-21 06:07:01 +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);
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2009-01-05 05:20:04 +01:00
|
|
|
if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') {
|
|
|
|
$section = Session::get('CommentsSection');
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 07:02:52 +02:00
|
|
|
return $section;
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 07:02:52 +02:00
|
|
|
public function EditForm() {
|
|
|
|
$section = $this->Section();
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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';
|
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') {
|
2007-08-08 03:16:02 +02:00
|
|
|
$filter = 'NeedsModeration=1';
|
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 {
|
|
|
|
$filter = 'IsSpam=1';
|
2008-02-25 03:10:37 +01:00
|
|
|
$title = "<h2>"._t('CommentAdmin.SPAM', 'Spam')."</h2>";
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-11-04 22:46:36 +01:00
|
|
|
$filter .= ' AND ParentID>0';
|
2009-05-21 06:07:01 +02: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'),
|
2009-03-10 23:33:29 +01:00
|
|
|
"CommenterURL" => _t('CommentAdmin.COMMENTERURL', 'URL'),
|
2008-02-25 03:10:37 +01:00
|
|
|
"PageTitle" => _t('CommentAdmin.PAGE', 'Page'),
|
|
|
|
"Created" => _t('CommentAdmin.DATEPOSTED', 'Date Posted')
|
2009-05-21 06:07:01 +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')),
|
2009-03-10 23:33:29 +01:00
|
|
|
new TextField('CommenterURL', _t('CommentAdmin.COMMENTERURL', 'URL')),
|
2008-02-25 03:10:37 +01:00
|
|
|
new TextareaField('Comment', _t('CommentAdmin.COMMENT', 'Comment'))
|
2007-08-08 08:00:20 +02:00
|
|
|
);
|
2009-05-21 06:07:01 +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);
|
2009-05-21 06:07:01 +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
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
$actions = new FieldSet();
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
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
|
|
|
}
|
2009-05-21 06:07:01 +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
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
$actions->push(new FormAction('deletemarked', _t('CommentAdmin.DELETE', 'Delete')));
|
2009-05-21 06:07:01 +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
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-08 03:16:02 +02:00
|
|
|
$form = new Form($this, "EditForm", $fields, $actions);
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-08 03:16:02 +02:00
|
|
|
return $form;
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 00:59:20 +02:00
|
|
|
function deletemarked() {
|
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 00:59:20 +02:00
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
2009-03-18 03:53:28 +01:00
|
|
|
$comment = DataObject::get_by_id('PageComment', $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);
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 00:59:20 +02:00
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("Deleted $numComments comments.");
|
2007-08-10 01:19:20 +02:00
|
|
|
JS;
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-13 02:39:37 +02:00
|
|
|
function deleteall() {
|
|
|
|
$numComments = 0;
|
2008-02-25 03:10:37 +01:00
|
|
|
$spam = DataObject::get('PageComment', 'PageComment.IsSpam=1');
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-13 02:39:37 +02:00
|
|
|
if($spam) {
|
|
|
|
$numComments = $spam->Count();
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-13 02:39:37 +02:00
|
|
|
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;
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-13 02:39:37 +02:00
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
function spammarked() {
|
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
2009-03-18 03:53:28 +01:00
|
|
|
$comment = DataObject::get_by_id('PageComment', $commentid);
|
2007-08-10 01:19:20 +02:00
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = true;
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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'));
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-13 01:11:37 +02:00
|
|
|
$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);
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
function hammarked() {
|
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
2009-03-18 03:53:28 +01:00
|
|
|
$comment = DataObject::get_by_id('PageComment', $commentid);
|
2007-08-10 01:19:20 +02:00
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = false;
|
|
|
|
$comment->NeedsModeration = false;
|
|
|
|
$comment->write();
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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'));
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-13 01:11:37 +02:00
|
|
|
$akismet->submitSpam();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Akismet didn't work, most likely the service is down.
|
|
|
|
}
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
$numComments++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2008-11-10 05:07:03 +01:00
|
|
|
function acceptmarked() {
|
2007-08-10 01:19:20 +02:00
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2007-08-10 01:19:20 +02:00
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
2009-03-18 03:53:28 +01:00
|
|
|
$comment = DataObject::get_by_id('PageComment', $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);
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2008-09-30 02:05:22 +02:00
|
|
|
/**
|
|
|
|
* Return the number of moderated comments
|
|
|
|
*/
|
|
|
|
function NumModerated() {
|
|
|
|
return DB::query("SELECT COUNT(*) FROM PageComment WHERE !IsSpam AND !NeedsModeration")->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of unmoderated comments
|
|
|
|
*/
|
|
|
|
function NumUnmoderated() {
|
|
|
|
return DB::query("SELECT COUNT(*) FROM PageComment WHERE !IsSpam AND NeedsModeration")->value();
|
|
|
|
}
|
2009-05-21 06:07:01 +02:00
|
|
|
|
2008-09-30 02:05:22 +02:00
|
|
|
/**
|
|
|
|
* Return the number of comments marked as spam
|
|
|
|
*/
|
|
|
|
function NumSpam() {
|
|
|
|
return DB::query("SELECT COUNT(*) FROM PageComment WHERE IsSpam")->value();
|
|
|
|
}
|
2007-08-08 03:16:02 +02:00
|
|
|
}
|
|
|
|
|
2009-03-10 23:33:29 +01:00
|
|
|
?>
|