2010-11-29 23:24:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comment administration system within the CMS
|
|
|
|
*
|
|
|
|
* @package comments
|
|
|
|
*/
|
|
|
|
class CommentAdmin extends LeftAndMain {
|
|
|
|
|
|
|
|
static $url_segment = 'comments';
|
|
|
|
|
|
|
|
static $url_rule = '/$Action';
|
|
|
|
|
|
|
|
static $menu_title = 'Comments';
|
|
|
|
|
2012-06-01 08:34:31 +02:00
|
|
|
static $template_path = null; // defaults to (project)/templates/email
|
|
|
|
|
2010-11-29 23:24:17 +01:00
|
|
|
static $allowed_actions = array(
|
|
|
|
'approvedmarked',
|
|
|
|
'deleteall',
|
|
|
|
'deletemarked',
|
|
|
|
'hammarked',
|
|
|
|
'showtable',
|
|
|
|
'spammarked',
|
|
|
|
'EditForm',
|
|
|
|
'unmoderated'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int The number of comments per page for the {@link CommentTable} in this admin.
|
|
|
|
*/
|
2010-12-11 06:33:21 +01:00
|
|
|
static $comments_per_page = 20;
|
2010-11-29 23:24:17 +01:00
|
|
|
|
|
|
|
public function init() {
|
|
|
|
parent::init();
|
|
|
|
|
2012-06-01 08:34:31 +02:00
|
|
|
//Requirements::javascript(CMS_DIR . '/javascript/CommentAdmin_right.js');
|
|
|
|
//Requirements::css(CMS_DIR . '/css/CommentAdmin.css');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEditForm($id = null, $fields = null) {
|
|
|
|
// TODO Duplicate record fetching (see parent implementation)
|
|
|
|
if(!$id) $id = $this->currentPageID();
|
|
|
|
$form = parent::getEditForm($id);
|
|
|
|
|
|
|
|
// TODO Duplicate record fetching (see parent implementation)
|
|
|
|
$record = $this->getRecord($id);
|
|
|
|
if($record && !$record->canView()) return Security::permissionFailure($this);
|
|
|
|
|
|
|
|
$commentList = GridField::create(
|
|
|
|
'Comments',
|
|
|
|
false,
|
|
|
|
Comment::get(),
|
|
|
|
$commentListConfig = GridFieldConfig_RecordViewer::create()
|
|
|
|
//->addComponent(new GridFieldExportButton())
|
|
|
|
)->addExtraClass("comments_grid");
|
|
|
|
//$commentListConfig->getComponentByType('GridFieldDetailForm')->setValidator(new Comment_Validator());
|
|
|
|
|
|
|
|
$fields = new FieldList(
|
|
|
|
$root = new TabSet(
|
|
|
|
'Root',
|
|
|
|
$commentsTab = new Tab('Comments', _t('CommentAdmin.Comments', 'Comments'),
|
|
|
|
$commentList// ,
|
|
|
|
// new HeaderField(_t('CommentAdmin.IMPORTCOMMENTS', 'Import comments'), 3),
|
|
|
|
// new LiteralField(
|
|
|
|
// 'CommentImportFormIframe',
|
|
|
|
// sprintf(
|
|
|
|
// '<iframe src="%s" id="CommentImportFormIframe" width="100%%" height="250px" border="0"></iframe>',
|
|
|
|
// $this->Link('commentimport')
|
|
|
|
// )
|
|
|
|
// )
|
|
|
|
)
|
|
|
|
),
|
|
|
|
// necessary for tree node selection in LeftAndMain.EditForm.js
|
|
|
|
new HiddenField('ID', false, 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
$root->setTemplate('CMSTabSet');
|
|
|
|
|
|
|
|
$actions = new FieldList();
|
|
|
|
|
|
|
|
$form = new Form(
|
|
|
|
$this,
|
|
|
|
'EditForm',
|
|
|
|
$fields,
|
|
|
|
$actions
|
|
|
|
);
|
|
|
|
$form->addExtraClass('cms-edit-form');
|
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
|
|
|
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
|
|
|
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
|
|
|
|
|
|
|
|
$this->extend('updateEditForm', $form);
|
|
|
|
|
|
|
|
return $form;
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function showtable($params) {
|
|
|
|
return $this->getLastFormIn($this->renderWith('CommentAdmin_right'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Section() {
|
|
|
|
$url = rtrim($_SERVER['REQUEST_URI'], '/');
|
|
|
|
if(strrpos($url, '&')) {
|
|
|
|
$url = substr($url, 0, strrpos($url, '&'));
|
|
|
|
}
|
|
|
|
$section = substr($url, strrpos($url, '/') + 1);
|
|
|
|
|
|
|
|
if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') {
|
|
|
|
$section = Session::get('CommentsSection');
|
|
|
|
}
|
|
|
|
|
|
|
|
if($section != 'approved' && $section != 'unmoderated' && $section != 'spam') {
|
|
|
|
$section = 'approved';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $section;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function deletemarked() {
|
2010-12-11 06:33:21 +01:00
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
|
|
|
$comment = DataObject::get_by_id('Comment', $commentid);
|
|
|
|
if($comment && $comment->canDelete()) {
|
|
|
|
$comment->delete();
|
|
|
|
$numComments++;
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-11 06:33:21 +01:00
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2010-12-11 06:33:21 +01:00
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("Deleted $numComments comments.");
|
2010-11-29 23:24:17 +01:00
|
|
|
JS;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteall() {
|
|
|
|
$numComments = 0;
|
2010-12-11 06:33:21 +01:00
|
|
|
$spam = DataObject::get('Comment', "\"Comment\".\"IsSpam\" = '1'");
|
2010-11-29 23:24:17 +01:00
|
|
|
|
|
|
|
if($spam) {
|
|
|
|
$numComments = $spam->Count();
|
|
|
|
|
|
|
|
foreach($spam as $comment) {
|
2010-12-11 06:33:21 +01:00
|
|
|
if($comment->canDelete()) {
|
|
|
|
$comment->delete();
|
|
|
|
}
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$msg = sprintf(_t('CommentAdmin.DELETED', 'Deleted %s comments.'), $numComments);
|
|
|
|
echo <<<JS
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("$msg");
|
|
|
|
JS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function spammarked() {
|
2010-12-11 06:33:21 +01:00
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
|
|
|
$comment = DataObject::get_by_id('Comment', $commentid);
|
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = true;
|
|
|
|
$comment->Moderated = true;
|
|
|
|
$comment->write();
|
|
|
|
|
|
|
|
$numComments++;
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-11 06:33:21 +01:00
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2010-12-11 06:33:21 +01:00
|
|
|
$msg = sprintf(_t('CommentAdmin.MARKEDSPAM', 'Marked %s comments as spam.'), $numComments);
|
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("$msg");
|
2010-11-29 23:24:17 +01:00
|
|
|
JS;
|
|
|
|
}
|
|
|
|
|
|
|
|
function hammarked() {
|
2010-12-11 06:33:21 +01:00
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
|
|
|
$comment = DataObject::get_by_id('Comment', $commentid);
|
|
|
|
|
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = false;
|
|
|
|
$comment->Moderated = true;
|
|
|
|
$comment->write();
|
|
|
|
|
|
|
|
$numComments++;
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-11 06:33:21 +01:00
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2010-12-11 06:33:21 +01:00
|
|
|
$msg = sprintf(_t('CommentAdmin.MARKEDNOTSPAM', 'Marked %s comments as not spam.'), $numComments);
|
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("$msg");
|
2010-11-29 23:24:17 +01:00
|
|
|
JS;
|
|
|
|
}
|
|
|
|
|
|
|
|
function acceptmarked() {
|
2010-12-11 06:33:21 +01:00
|
|
|
$numComments = 0;
|
|
|
|
$folderID = 0;
|
|
|
|
$deleteList = '';
|
|
|
|
|
|
|
|
if($_REQUEST['Comments']) {
|
|
|
|
foreach($_REQUEST['Comments'] as $commentid) {
|
|
|
|
$comment = DataObject::get_by_id('Comment', $commentid);
|
|
|
|
if($comment) {
|
|
|
|
$comment->IsSpam = false;
|
|
|
|
$comment->Moderated = true;
|
|
|
|
$comment->write();
|
|
|
|
$numComments++;
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-11 06:33:21 +01:00
|
|
|
} else {
|
|
|
|
user_error("No comments in $commentList could be found!", E_USER_ERROR);
|
|
|
|
}
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2010-12-11 06:33:21 +01:00
|
|
|
$msg = sprintf(_t('CommentAdmin.APPROVED', 'Accepted %s comments.'), $numComments);
|
|
|
|
echo <<<JS
|
|
|
|
$deleteList
|
|
|
|
$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);
|
|
|
|
statusMessage("Accepted $numComments comments.");
|
2010-11-29 23:24:17 +01:00
|
|
|
JS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of moderated comments
|
2010-12-11 06:33:21 +01:00
|
|
|
*
|
|
|
|
* @return int
|
2010-11-29 23:24:17 +01:00
|
|
|
*/
|
|
|
|
function NumModerated() {
|
2010-12-11 06:33:21 +01:00
|
|
|
return DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\" = 1")->value();
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of unmoderated comments
|
2010-12-11 06:33:21 +01:00
|
|
|
*
|
|
|
|
* @return int
|
2010-11-29 23:24:17 +01:00
|
|
|
*/
|
|
|
|
function NumUnmoderated() {
|
2010-12-11 06:33:21 +01:00
|
|
|
return DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\" = 0")->value();
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of comments marked as spam
|
2010-12-11 06:33:21 +01:00
|
|
|
*
|
|
|
|
* @return int
|
2010-11-29 23:24:17 +01:00
|
|
|
*/
|
|
|
|
function NumSpam() {
|
2010-12-11 06:33:21 +01:00
|
|
|
return DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"IsSpam\" = 1")->value();
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-12-11 06:33:21 +01:00
|
|
|
* @param int
|
2010-11-29 23:24:17 +01:00
|
|
|
*/
|
|
|
|
function set_comments_per_page($num){
|
|
|
|
self::$comments_per_page = $num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function get_comments_per_page(){
|
|
|
|
return self::$comments_per_page;
|
|
|
|
}
|
|
|
|
}
|