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
|
|
|
|
2012-07-22 02:47:59 +02:00
|
|
|
$commentsConfig = GridFieldConfig::create()->addComponents(
|
|
|
|
new GridFieldFilterHeader(),
|
2013-12-21 05:05:37 +01:00
|
|
|
$columns = new GridFieldDataColumns(),
|
2012-07-22 02:47:59 +02:00
|
|
|
new GridFieldSortableHeader(),
|
|
|
|
new GridFieldPaginator(25),
|
|
|
|
new GridFieldDeleteAction(),
|
|
|
|
new GridFieldDetailForm(),
|
|
|
|
new GridFieldExportButton(),
|
|
|
|
new GridFieldEditButton(),
|
2013-12-21 00:19:11 +01:00
|
|
|
new GridFieldDetailForm(),
|
|
|
|
$manager = new GridFieldBulkManager()
|
|
|
|
);
|
|
|
|
|
|
|
|
$manager->addBulkAction(
|
|
|
|
'markAsSpam', 'Mark as spam', 'CommentsGridFieldBulkAction_MarkAsSpam',
|
|
|
|
array(
|
|
|
|
'isAjax' => true,
|
|
|
|
'icon' => 'delete',
|
|
|
|
'isDestructive' => true
|
|
|
|
)
|
2012-07-22 02:47:59 +02:00
|
|
|
);
|
|
|
|
|
2013-12-21 05:05:37 +01:00
|
|
|
$columns->setFieldFormatting(array(
|
|
|
|
'ParentTitle' => function($value, &$item) {
|
|
|
|
return sprintf(
|
|
|
|
'<a href="%s" class="cms-panel-link external-link action" target="_blank">%s</a>',
|
|
|
|
Convert::raw2xml($item->Link()),
|
|
|
|
Convert::raw2xml($value)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2012-07-22 02:47:59 +02:00
|
|
|
$needs = new GridField(
|
|
|
|
'Comments',
|
|
|
|
_t('CommentsAdmin.NeedsModeration', 'Needs Moderation'),
|
2012-12-17 20:53:16 +01:00
|
|
|
Comment::get()->filter('Moderated',0),
|
2012-07-22 02:47:59 +02:00
|
|
|
$commentsConfig
|
|
|
|
);
|
|
|
|
|
|
|
|
$moderated = new GridField(
|
|
|
|
'CommentsModerated',
|
|
|
|
_t('CommentsAdmin.CommentsModerated'),
|
2012-12-17 20:53:16 +01:00
|
|
|
Comment::get()->filter('Moderated',1),
|
2012-07-22 02:47:59 +02:00
|
|
|
$commentsConfig
|
|
|
|
);
|
|
|
|
|
2012-06-01 08:34:31 +02:00
|
|
|
$fields = new FieldList(
|
|
|
|
$root = new TabSet(
|
|
|
|
'Root',
|
2012-07-22 02:47:59 +02:00
|
|
|
new Tab('NeedsModeration', _t('CommentAdmin.NeedsModeration', 'Needs Moderation'),
|
|
|
|
$needs
|
|
|
|
),
|
|
|
|
new Tab('Comments', _t('CommentAdmin.Moderated', 'Moderated'),
|
|
|
|
$moderated
|
2012-06-01 08:34:31 +02:00
|
|
|
)
|
2012-07-22 02:47:59 +02:00
|
|
|
)
|
2012-06-01 08:34:31 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$root->setTemplate('CMSTabSet');
|
|
|
|
|
|
|
|
$actions = new FieldList();
|
|
|
|
|
|
|
|
$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
|
|
|
|
2012-07-22 02:47:59 +02:00
|
|
|
if($form->Fields()->hasTabset()) {
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|