mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUGFIX: missing unmoderated action in CommentAdmin.php
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@77528 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
17ff86de18
commit
cf8a2ae0c9
@ -7,9 +7,9 @@
|
|||||||
class CommentAdmin extends LeftAndMain {
|
class CommentAdmin extends LeftAndMain {
|
||||||
|
|
||||||
static $url_segment = 'comments';
|
static $url_segment = 'comments';
|
||||||
|
|
||||||
static $url_rule = '/$Action';
|
static $url_rule = '/$Action';
|
||||||
|
|
||||||
static $menu_title = 'Comments';
|
static $menu_title = 'Comments';
|
||||||
|
|
||||||
static $allowed_actions = array(
|
static $allowed_actions = array(
|
||||||
@ -20,40 +20,41 @@ class CommentAdmin extends LeftAndMain {
|
|||||||
'showtable',
|
'showtable',
|
||||||
'spammarked',
|
'spammarked',
|
||||||
'EditForm',
|
'EditForm',
|
||||||
|
'unmoderated'
|
||||||
);
|
);
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
Requirements::javascript(CMS_DIR . '/javascript/CommentAdmin_right.js');
|
Requirements::javascript(CMS_DIR . '/javascript/CommentAdmin_right.js');
|
||||||
Requirements::css(CMS_DIR . 'css/CommentAdmin.css');
|
Requirements::css(CMS_DIR . 'css/CommentAdmin.css');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showtable($params) {
|
public function showtable($params) {
|
||||||
return $this->getLastFormIn($this->renderWith('CommentAdmin_right'));
|
return $this->getLastFormIn($this->renderWith('CommentAdmin_right'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Section() {
|
public function Section() {
|
||||||
$url = rtrim($_SERVER['REQUEST_URI'], '/');
|
$url = rtrim($_SERVER['REQUEST_URI'], '/');
|
||||||
if(strrpos($url, '&')) {
|
if(strrpos($url, '&')) {
|
||||||
$url = substr($url, 0, strrpos($url, '&'));
|
$url = substr($url, 0, strrpos($url, '&'));
|
||||||
}
|
}
|
||||||
$section = substr($url, strrpos($url, '/') + 1);
|
$section = substr($url, strrpos($url, '/') + 1);
|
||||||
|
|
||||||
if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') {
|
if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') {
|
||||||
$section = Session::get('CommentsSection');
|
$section = Session::get('CommentsSection');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') {
|
if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') {
|
||||||
$section = 'approved';
|
$section = 'approved';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $section;
|
return $section;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function EditForm() {
|
public function EditForm() {
|
||||||
$section = $this->Section();
|
$section = $this->Section();
|
||||||
|
|
||||||
if($section == 'approved') {
|
if($section == 'approved') {
|
||||||
$filter = 'IsSpam=0 AND NeedsModeration=0';
|
$filter = 'IsSpam=0 AND NeedsModeration=0';
|
||||||
$title = "<h2>". _t('CommentAdmin.APPROVEDCOMMENTS', 'Approved Comments')."</h2>";
|
$title = "<h2>". _t('CommentAdmin.APPROVEDCOMMENTS', 'Approved Comments')."</h2>";
|
||||||
@ -64,27 +65,27 @@ class CommentAdmin extends LeftAndMain {
|
|||||||
$filter = 'IsSpam=1';
|
$filter = 'IsSpam=1';
|
||||||
$title = "<h2>"._t('CommentAdmin.SPAM', 'Spam')."</h2>";
|
$title = "<h2>"._t('CommentAdmin.SPAM', 'Spam')."</h2>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$filter .= ' AND ParentID>0';
|
$filter .= ' AND ParentID>0';
|
||||||
|
|
||||||
$tableFields = array(
|
$tableFields = array(
|
||||||
"Name" => _t('CommentAdmin.AUTHOR', 'Author'),
|
"Name" => _t('CommentAdmin.AUTHOR', 'Author'),
|
||||||
"Comment" => _t('CommentAdmin.COMMENT', 'Comment'),
|
"Comment" => _t('CommentAdmin.COMMENT', 'Comment'),
|
||||||
"CommenterURL" => _t('CommentAdmin.COMMENTERURL', 'URL'),
|
"CommenterURL" => _t('CommentAdmin.COMMENTERURL', 'URL'),
|
||||||
"PageTitle" => _t('CommentAdmin.PAGE', 'Page'),
|
"PageTitle" => _t('CommentAdmin.PAGE', 'Page'),
|
||||||
"Created" => _t('CommentAdmin.DATEPOSTED', 'Date Posted')
|
"Created" => _t('CommentAdmin.DATEPOSTED', 'Date Posted')
|
||||||
);
|
);
|
||||||
|
|
||||||
$popupFields = new FieldSet(
|
$popupFields = new FieldSet(
|
||||||
new TextField('Name', _t('CommentAdmin.NAME', 'Name')),
|
new TextField('Name', _t('CommentAdmin.NAME', 'Name')),
|
||||||
new TextField('CommenterURL', _t('CommentAdmin.COMMENTERURL', 'URL')),
|
new TextField('CommenterURL', _t('CommentAdmin.COMMENTERURL', 'URL')),
|
||||||
new TextareaField('Comment', _t('CommentAdmin.COMMENT', 'Comment'))
|
new TextareaField('Comment', _t('CommentAdmin.COMMENT', 'Comment'))
|
||||||
);
|
);
|
||||||
|
|
||||||
$idField = new HiddenField('ID', '', $section);
|
$idField = new HiddenField('ID', '', $section);
|
||||||
$table = new CommentTableField($this, "Comments", "PageComment", $section, $tableFields, $popupFields, array($filter));
|
$table = new CommentTableField($this, "Comments", "PageComment", $section, $tableFields, $popupFields, array($filter));
|
||||||
$table->setParentClass(false);
|
$table->setParentClass(false);
|
||||||
|
|
||||||
$fields = new FieldSet(
|
$fields = new FieldSet(
|
||||||
new TabSet( 'Root',
|
new TabSet( 'Root',
|
||||||
new Tab(_t('CommentAdmin.COMMENTS', 'Comments'),
|
new Tab(_t('CommentAdmin.COMMENTS', 'Comments'),
|
||||||
@ -94,37 +95,37 @@ class CommentAdmin extends LeftAndMain {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$actions = new FieldSet();
|
$actions = new FieldSet();
|
||||||
|
|
||||||
if($section == 'unmoderated') {
|
if($section == 'unmoderated') {
|
||||||
$actions->push(new FormAction('acceptmarked', _t('CommentAdmin.ACCEPT', 'Accept')));
|
$actions->push(new FormAction('acceptmarked', _t('CommentAdmin.ACCEPT', 'Accept')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($section == 'approved' || $section == 'unmoderated') {
|
if($section == 'approved' || $section == 'unmoderated') {
|
||||||
$actions->push(new FormAction('spammarked', _t('CommentAdmin.SPAMMARKED', 'Mark as spam')));
|
$actions->push(new FormAction('spammarked', _t('CommentAdmin.SPAMMARKED', 'Mark as spam')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($section == 'spam') {
|
if($section == 'spam') {
|
||||||
$actions->push(new FormAction('hammarked', _t('CommentAdmin.MARKASNOTSPAM', 'Mark as not spam')));
|
$actions->push(new FormAction('hammarked', _t('CommentAdmin.MARKASNOTSPAM', 'Mark as not spam')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$actions->push(new FormAction('deletemarked', _t('CommentAdmin.DELETE', 'Delete')));
|
$actions->push(new FormAction('deletemarked', _t('CommentAdmin.DELETE', 'Delete')));
|
||||||
|
|
||||||
if($section == 'spam') {
|
if($section == 'spam') {
|
||||||
$actions->push(new FormAction('deleteall', _t('CommentAdmin.DELETEALL', 'Delete All')));
|
$actions->push(new FormAction('deleteall', _t('CommentAdmin.DELETEALL', 'Delete All')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = new Form($this, "EditForm", $fields, $actions);
|
$form = new Form($this, "EditForm", $fields, $actions);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deletemarked() {
|
function deletemarked() {
|
||||||
$numComments = 0;
|
$numComments = 0;
|
||||||
$folderID = 0;
|
$folderID = 0;
|
||||||
$deleteList = '';
|
$deleteList = '';
|
||||||
|
|
||||||
if($_REQUEST['Comments']) {
|
if($_REQUEST['Comments']) {
|
||||||
foreach($_REQUEST['Comments'] as $commentid) {
|
foreach($_REQUEST['Comments'] as $commentid) {
|
||||||
$comment = DataObject::get_by_id('PageComment', $commentid);
|
$comment = DataObject::get_by_id('PageComment', $commentid);
|
||||||
@ -136,21 +137,21 @@ class CommentAdmin extends LeftAndMain {
|
|||||||
} else {
|
} else {
|
||||||
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo <<<JS
|
echo <<<JS
|
||||||
$deleteList
|
$deleteList
|
||||||
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
||||||
statusMessage("Deleted $numComments comments.");
|
statusMessage("Deleted $numComments comments.");
|
||||||
JS;
|
JS;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteall() {
|
function deleteall() {
|
||||||
$numComments = 0;
|
$numComments = 0;
|
||||||
$spam = DataObject::get('PageComment', 'PageComment.IsSpam=1');
|
$spam = DataObject::get('PageComment', 'PageComment.IsSpam=1');
|
||||||
|
|
||||||
if($spam) {
|
if($spam) {
|
||||||
$numComments = $spam->Count();
|
$numComments = $spam->Count();
|
||||||
|
|
||||||
foreach($spam as $comment) {
|
foreach($spam as $comment) {
|
||||||
$comment->delete();
|
$comment->delete();
|
||||||
}
|
}
|
||||||
@ -161,14 +162,14 @@ JS;
|
|||||||
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
||||||
statusMessage("$msg");
|
statusMessage("$msg");
|
||||||
JS;
|
JS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function spammarked() {
|
function spammarked() {
|
||||||
$numComments = 0;
|
$numComments = 0;
|
||||||
$folderID = 0;
|
$folderID = 0;
|
||||||
$deleteList = '';
|
$deleteList = '';
|
||||||
|
|
||||||
if($_REQUEST['Comments']) {
|
if($_REQUEST['Comments']) {
|
||||||
foreach($_REQUEST['Comments'] as $commentid) {
|
foreach($_REQUEST['Comments'] as $commentid) {
|
||||||
$comment = DataObject::get_by_id('PageComment', $commentid);
|
$comment = DataObject::get_by_id('PageComment', $commentid);
|
||||||
@ -176,13 +177,13 @@ JS;
|
|||||||
$comment->IsSpam = true;
|
$comment->IsSpam = true;
|
||||||
$comment->NeedsModeration = false;
|
$comment->NeedsModeration = false;
|
||||||
$comment->write();
|
$comment->write();
|
||||||
|
|
||||||
if(SSAkismet::isEnabled()) {
|
if(SSAkismet::isEnabled()) {
|
||||||
try {
|
try {
|
||||||
$akismet = new SSAkismet();
|
$akismet = new SSAkismet();
|
||||||
$akismet->setCommentAuthor($comment->getField('Name'));
|
$akismet->setCommentAuthor($comment->getField('Name'));
|
||||||
$akismet->setCommentContent($comment->getField('Comment'));
|
$akismet->setCommentContent($comment->getField('Comment'));
|
||||||
|
|
||||||
$akismet->submitSpam();
|
$akismet->submitSpam();
|
||||||
} 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.
|
||||||
@ -194,7 +195,7 @@ JS;
|
|||||||
} else {
|
} else {
|
||||||
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg = sprintf(_t('CommentAdmin.MARKEDSPAM', 'Marked %s comments as spam.'), $numComments);
|
$msg = sprintf(_t('CommentAdmin.MARKEDSPAM', 'Marked %s comments as spam.'), $numComments);
|
||||||
echo <<<JS
|
echo <<<JS
|
||||||
$deleteList
|
$deleteList
|
||||||
@ -202,12 +203,12 @@ JS;
|
|||||||
statusMessage("$msg");
|
statusMessage("$msg");
|
||||||
JS;
|
JS;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hammarked() {
|
function hammarked() {
|
||||||
$numComments = 0;
|
$numComments = 0;
|
||||||
$folderID = 0;
|
$folderID = 0;
|
||||||
$deleteList = '';
|
$deleteList = '';
|
||||||
|
|
||||||
if($_REQUEST['Comments']) {
|
if($_REQUEST['Comments']) {
|
||||||
foreach($_REQUEST['Comments'] as $commentid) {
|
foreach($_REQUEST['Comments'] as $commentid) {
|
||||||
$comment = DataObject::get_by_id('PageComment', $commentid);
|
$comment = DataObject::get_by_id('PageComment', $commentid);
|
||||||
@ -215,26 +216,26 @@ JS;
|
|||||||
$comment->IsSpam = false;
|
$comment->IsSpam = false;
|
||||||
$comment->NeedsModeration = false;
|
$comment->NeedsModeration = false;
|
||||||
$comment->write();
|
$comment->write();
|
||||||
|
|
||||||
if(SSAkismet::isEnabled()) {
|
if(SSAkismet::isEnabled()) {
|
||||||
try {
|
try {
|
||||||
$akismet = new SSAkismet();
|
$akismet = new SSAkismet();
|
||||||
$akismet->setCommentAuthor($comment->getField('Name'));
|
$akismet->setCommentAuthor($comment->getField('Name'));
|
||||||
$akismet->setCommentContent($comment->getField('Comment'));
|
$akismet->setCommentContent($comment->getField('Comment'));
|
||||||
|
|
||||||
$akismet->submitSpam();
|
$akismet->submitSpam();
|
||||||
} 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.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$numComments++;
|
$numComments++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg = sprintf(_t('CommentAdmin.MARKEDNOTSPAM', 'Marked %s comments as not spam.'), $numComments);
|
$msg = sprintf(_t('CommentAdmin.MARKEDNOTSPAM', 'Marked %s comments as not spam.'), $numComments);
|
||||||
echo <<<JS
|
echo <<<JS
|
||||||
$deleteList
|
$deleteList
|
||||||
@ -242,12 +243,12 @@ JS;
|
|||||||
statusMessage("$msg");
|
statusMessage("$msg");
|
||||||
JS;
|
JS;
|
||||||
}
|
}
|
||||||
|
|
||||||
function acceptmarked() {
|
function acceptmarked() {
|
||||||
$numComments = 0;
|
$numComments = 0;
|
||||||
$folderID = 0;
|
$folderID = 0;
|
||||||
$deleteList = '';
|
$deleteList = '';
|
||||||
|
|
||||||
if($_REQUEST['Comments']) {
|
if($_REQUEST['Comments']) {
|
||||||
foreach($_REQUEST['Comments'] as $commentid) {
|
foreach($_REQUEST['Comments'] as $commentid) {
|
||||||
$comment = DataObject::get_by_id('PageComment', $commentid);
|
$comment = DataObject::get_by_id('PageComment', $commentid);
|
||||||
@ -261,7 +262,7 @@ JS;
|
|||||||
} else {
|
} else {
|
||||||
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg = sprintf(_t('CommentAdmin.APPROVED', 'Accepted %s comments.'), $numComments);
|
$msg = sprintf(_t('CommentAdmin.APPROVED', 'Accepted %s comments.'), $numComments);
|
||||||
echo <<<JS
|
echo <<<JS
|
||||||
$deleteList
|
$deleteList
|
||||||
@ -269,7 +270,7 @@ JS;
|
|||||||
statusMessage("Accepted $numComments comments.");
|
statusMessage("Accepted $numComments comments.");
|
||||||
JS;
|
JS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of moderated comments
|
* Return the number of moderated comments
|
||||||
*/
|
*/
|
||||||
@ -283,7 +284,7 @@ JS;
|
|||||||
function NumUnmoderated() {
|
function NumUnmoderated() {
|
||||||
return DB::query("SELECT COUNT(*) FROM PageComment WHERE !IsSpam AND NeedsModeration")->value();
|
return DB::query("SELECT COUNT(*) FROM PageComment WHERE !IsSpam AND NeedsModeration")->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of comments marked as spam
|
* Return the number of comments marked as spam
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user