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;
}
public function EditForm() {
$section = $this->Section();
if($section == 'approved') {
$filter = "\"IsSpam\" = 0 AND \"NeedsModeration\" = 0";
$title = "
". _t('CommentAdmin.APPROVEDCOMMENTS', 'Approved Comments')."
";
} else if($section == 'unmoderated') {
$filter = '"NeedsModeration" = 1';
$title = ""._t('CommentAdmin.COMMENTSAWAITINGMODERATION', 'Comments Awaiting Moderation')."
";
} else {
$filter = '"IsSpam" = 1';
$title = ""._t('CommentAdmin.SPAM', 'Spam')."
";
}
$filter .= ' AND "ParentID">0';
$tableFields = array(
"Name" => _t('CommentAdmin.AUTHOR', 'Author'),
"Comment" => _t('CommentAdmin.COMMENT', 'Comment'),
"Parent.Title" => _t('CommentAdmin.PAGE', 'Page'),
"URL" => _t('CommentAdmin.COMMENTERURL', 'URL'),
"Created" => _t('CommentAdmin.DATEPOSTED', 'Date Posted')
);
$popupFields = new FieldSet(
new TextField('Name', _t('CommentAdmin.NAME', 'Name')),
new TextField('URL', _t('CommentAdmin.URL', 'URL')),
new TextareaField('Comment', _t('CommentAdmin.COMMENT', 'Comment'))
);
$idField = new HiddenField('ID', '', $section);
$table = new CommentTableField($this, "Comments", "Comment", $section, $tableFields, $popupFields, array($filter), 'Created DESC');
$table->setParentClass(false);
$table->setFieldCasting(array(
'Created' => 'SSDatetime->Full',
'Comment' => array('HTMLText->LimitCharacters', 150)
));
$table->setPageSize(self::get_comments_per_page());
$table->addSelectOptions(array('all'=>'All', 'none'=>'None'));
$table->Markable = true;
$fields = new FieldSet(
new LiteralField("Title", $title),
$idField,
$table
);
$actions = new FieldSet();
if($section == 'unmoderated') {
$actions->push(new FormAction('acceptmarked', _t('CommentAdmin.ACCEPT', 'Accept')));
}
if($section == 'approved' || $section == 'unmoderated') {
$actions->push(new FormAction('spammarked', _t('CommentAdmin.SPAMMARKED', 'Mark as spam')));
}
if($section == 'spam') {
$actions->push(new FormAction('hammarked', _t('CommentAdmin.MARKASNOTSPAM', 'Mark as not spam')));
}
$actions->push(new FormAction('deletemarked', _t('CommentAdmin.DELETE', 'Delete')));
if($section == 'spam') {
$actions->push(new FormAction('deleteall', _t('CommentAdmin.DELETEALL', 'Delete All')));
}
$form = new Form($this, "EditForm", $fields, $actions);
return $form;
}
function deletemarked() {
$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++;
}
}
} else {
user_error("No comments in $commentList could be found!", E_USER_ERROR);
}
echo <<Count();
foreach($spam as $comment) {
if($comment->canDelete()) {
$comment->delete();
}
}
}
$msg = sprintf(_t('CommentAdmin.DELETED', 'Deleted %s comments.'), $numComments);
echo <<IsSpam = true;
$comment->Moderated = true;
$comment->write();
$numComments++;
}
}
} else {
user_error("No comments in $commentList could be found!", E_USER_ERROR);
}
$msg = sprintf(_t('CommentAdmin.MARKEDSPAM', 'Marked %s comments as spam.'), $numComments);
echo <<IsSpam = false;
$comment->Moderated = true;
$comment->write();
$numComments++;
}
}
} else {
user_error("No comments in $commentList could be found!", E_USER_ERROR);
}
$msg = sprintf(_t('CommentAdmin.MARKEDNOTSPAM', 'Marked %s comments as not spam.'), $numComments);
echo <<IsSpam = false;
$comment->Moderated = true;
$comment->write();
$numComments++;
}
}
} else {
user_error("No comments in $commentList could be found!", E_USER_ERROR);
}
$msg = sprintf(_t('CommentAdmin.APPROVED', 'Accepted %s comments.'), $numComments);
echo <<value();
}
/**
* Return the number of unmoderated comments
*
* @return int
*/
function NumUnmoderated() {
return DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\" = 0")->value();
}
/**
* Return the number of comments marked as spam
*
* @return int
*/
function NumSpam() {
return DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"IsSpam\" = 1")->value();
}
/**
* @param int
*/
function set_comments_per_page($num){
self::$comments_per_page = $num;
}
/**
* @return int
*/
function get_comments_per_page(){
return self::$comments_per_page;
}
}