2010-11-29 23:24:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comment administration system within the CMS
|
|
|
|
*
|
|
|
|
* @package comments
|
|
|
|
*/
|
2014-11-11 22:35:35 +01:00
|
|
|
class CommentAdmin extends LeftAndMain implements PermissionProvider {
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2013-04-11 14:23:03 +02:00
|
|
|
private static $url_segment = 'comments';
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2013-04-11 14:23:03 +02:00
|
|
|
private static $url_rule = '/$Action';
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2013-04-11 14:23:03 +02:00
|
|
|
private static $menu_title = 'Comments';
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2013-04-11 14:23:03 +02:00
|
|
|
private static $allowed_actions = array(
|
2010-11-29 23:24:17 +01:00
|
|
|
'approvedmarked',
|
|
|
|
'deleteall',
|
|
|
|
'deletemarked',
|
|
|
|
'hammarked',
|
|
|
|
'showtable',
|
|
|
|
'spammarked',
|
|
|
|
'EditForm',
|
|
|
|
'unmoderated'
|
|
|
|
);
|
2012-07-22 02:47:59 +02:00
|
|
|
|
2014-11-11 22:35:35 +01:00
|
|
|
public function providePermissions() {
|
|
|
|
return array(
|
|
|
|
"CMS_ACCESS_CommentAdmin" => array(
|
|
|
|
'name' => _t('CommentAdmin.ADMIN_PERMISSION', "Access to 'Comments' section"),
|
|
|
|
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-11-29 23:24:17 +01:00
|
|
|
/**
|
2012-07-22 02:47:59 +02:00
|
|
|
* @return Form
|
2010-11-29 23:24:17 +01:00
|
|
|
*/
|
2012-06-01 08:34:31 +02:00
|
|
|
public function getEditForm($id = null, $fields = null) {
|
|
|
|
if(!$id) $id = $this->currentPageID();
|
2012-07-22 02:47:59 +02:00
|
|
|
|
2012-06-01 08:34:31 +02:00
|
|
|
$form = parent::getEditForm($id);
|
|
|
|
$record = $this->getRecord($id);
|
2012-07-22 02:47:59 +02:00
|
|
|
|
|
|
|
if($record && !$record->canView()) {
|
|
|
|
return Security::permissionFailure($this);
|
|
|
|
}
|
2013-12-21 00:19:11 +01:00
|
|
|
|
2015-04-13 05:41:18 +02:00
|
|
|
$newComments = Comment::get()->filter('Moderated', 0);
|
|
|
|
|
2015-04-17 02:36:15 +02:00
|
|
|
$newGrid = new CommentsGridField(
|
2015-04-13 05:41:18 +02:00
|
|
|
'NewComments',
|
2015-04-16 04:40:16 +02:00
|
|
|
_t('CommentsAdmin.NewComments', 'New'),
|
2015-04-13 05:41:18 +02:00
|
|
|
$newComments,
|
2015-11-17 00:47:07 +01:00
|
|
|
CommentsGridFieldConfig::create()
|
2015-04-13 05:41:18 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
|
|
|
|
|
2015-04-17 02:36:15 +02:00
|
|
|
$approvedGrid = new CommentsGridField(
|
2015-04-13 05:41:18 +02:00
|
|
|
'ApprovedComments',
|
2015-04-16 04:40:16 +02:00
|
|
|
_t('CommentsAdmin.ApprovedComments', 'Approved'),
|
2015-04-13 05:41:18 +02:00
|
|
|
$approvedComments,
|
2015-11-17 00:47:07 +01:00
|
|
|
CommentsGridFieldConfig::create()
|
2012-07-22 02:47:59 +02:00
|
|
|
);
|
|
|
|
|
2015-04-13 05:41:18 +02:00
|
|
|
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
|
|
|
|
|
2015-04-17 02:36:15 +02:00
|
|
|
$spamGrid = new CommentsGridField(
|
2015-04-13 05:41:18 +02:00
|
|
|
'SpamComments',
|
|
|
|
_t('CommentsAdmin.SpamComments', 'Spam'),
|
|
|
|
$spamComments,
|
2015-11-17 00:47:07 +01:00
|
|
|
CommentsGridFieldConfig::create()
|
2012-07-22 02:47:59 +02:00
|
|
|
);
|
|
|
|
|
2015-04-13 05:41:18 +02:00
|
|
|
$newCount = '(' . count($newComments) . ')';
|
|
|
|
$approvedCount = '(' . count($approvedComments) . ')';
|
|
|
|
$spamCount = '(' . count($spamComments) . ')';
|
|
|
|
|
2012-06-01 08:34:31 +02:00
|
|
|
$fields = new FieldList(
|
|
|
|
$root = new TabSet(
|
|
|
|
'Root',
|
2015-04-16 04:40:16 +02:00
|
|
|
new Tab('NewComments', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount,
|
2015-04-13 05:41:18 +02:00
|
|
|
$newGrid
|
|
|
|
),
|
2015-04-16 04:40:16 +02:00
|
|
|
new Tab('ApprovedComments', _t('CommentAdmin.ApprovedComments', 'Approved') . ' ' . $approvedCount,
|
2015-04-13 05:41:18 +02:00
|
|
|
$approvedGrid
|
2012-07-22 02:47:59 +02:00
|
|
|
),
|
2015-04-13 05:41:18 +02:00
|
|
|
new Tab('SpamComments', _t('CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount,
|
|
|
|
$spamGrid
|
2012-06-01 08:34:31 +02:00
|
|
|
)
|
2012-07-22 02:47:59 +02:00
|
|
|
)
|
2012-06-01 08:34:31 +02:00
|
|
|
);
|
2015-04-13 05:41:18 +02:00
|
|
|
|
2012-06-01 08:34:31 +02:00
|
|
|
$root->setTemplate('CMSTabSet');
|
|
|
|
|
|
|
|
$actions = new FieldList();
|
2015-04-13 05:41:18 +02:00
|
|
|
|
2012-06-01 08:34:31 +02:00
|
|
|
$form = new Form(
|
|
|
|
$this,
|
|
|
|
'EditForm',
|
|
|
|
$fields,
|
|
|
|
$actions
|
|
|
|
);
|
2012-07-22 02:47:59 +02:00
|
|
|
|
2012-06-01 08:34:31 +02:00
|
|
|
$form->addExtraClass('cms-edit-form');
|
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2015-04-13 05:41:18 +02:00
|
|
|
if($form->Fields()->hasTabset()) {
|
2012-07-22 02:47:59 +02:00
|
|
|
$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
|
|
|
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
|
2010-12-11 06:33:21 +01:00
|
|
|
}
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2012-07-22 02:47:59 +02:00
|
|
|
$this->extend('updateEditForm', $form);
|
2010-11-29 23:24:17 +01:00
|
|
|
|
2012-07-22 02:47:59 +02:00
|
|
|
return $form;
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|
|
|
|
}
|