2010-11-29 23:24:17 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-16 20:57:37 +01:00
|
|
|
namespace SilverStripe\Comments\Admin;
|
|
|
|
|
|
|
|
use SilverStripe\Admin\LeftAndMain;
|
|
|
|
use SilverStripe\Comments\Admin\CommentsGridField;
|
|
|
|
use SilverStripe\Comments\Model\Comment;
|
|
|
|
use SilverStripe\Forms\Tab;
|
|
|
|
use SilverStripe\Forms\TabSet;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\Security\PermissionProvider;
|
|
|
|
use SilverStripe\Security\Security;
|
2017-09-18 04:16:24 +02:00
|
|
|
use SilverStripe\View\SSViewer;
|
2017-01-16 20:57:37 +01:00
|
|
|
|
2010-11-29 23:24:17 +01:00
|
|
|
/**
|
|
|
|
* Comment administration system within the CMS
|
|
|
|
*
|
|
|
|
* @package comments
|
|
|
|
*/
|
2016-02-19 01:48:25 +01:00
|
|
|
class CommentAdmin extends LeftAndMain implements PermissionProvider
|
|
|
|
{
|
|
|
|
private static $url_segment = 'comments';
|
|
|
|
|
|
|
|
private static $url_rule = '/$Action';
|
|
|
|
|
|
|
|
private static $menu_title = 'Comments';
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
private static $menu_icon_class = 'font-icon-comment';
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
private static $allowed_actions = array(
|
|
|
|
'approvedmarked',
|
|
|
|
'deleteall',
|
|
|
|
'deletemarked',
|
|
|
|
'hammarked',
|
|
|
|
'showtable',
|
|
|
|
'spammarked',
|
|
|
|
'EditForm',
|
|
|
|
'unmoderated'
|
|
|
|
);
|
|
|
|
|
2017-09-18 04:16:24 +02:00
|
|
|
private static $required_permission_codes = 'CMS_ACCESS_CommentAdmin';
|
|
|
|
|
2016-02-19 01:48:25 +01:00
|
|
|
public function providePermissions()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
"CMS_ACCESS_CommentAdmin" => array(
|
2017-12-14 04:08:43 +01:00
|
|
|
'name' => _t(__CLASS__ . '.ADMIN_PERMISSION', "Access to 'Comments' section"),
|
2017-09-18 04:16:24 +02:00
|
|
|
'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
|
2016-02-19 01:48:25 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
public function getEditForm($id = null, $fields = null)
|
|
|
|
{
|
|
|
|
if (!$id) {
|
|
|
|
$id = $this->currentPageID();
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = parent::getEditForm($id);
|
|
|
|
$record = $this->getRecord($id);
|
|
|
|
|
|
|
|
if ($record && !$record->canView()) {
|
|
|
|
return Security::permissionFailure($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
$newComments = Comment::get()->filter('Moderated', 0);
|
|
|
|
|
|
|
|
$newGrid = new CommentsGridField(
|
|
|
|
'NewComments',
|
2017-09-18 04:16:24 +02:00
|
|
|
'',
|
2016-02-19 01:48:25 +01:00
|
|
|
$newComments,
|
|
|
|
CommentsGridFieldConfig::create()
|
|
|
|
);
|
|
|
|
|
|
|
|
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
|
|
|
|
|
|
|
|
$approvedGrid = new CommentsGridField(
|
|
|
|
'ApprovedComments',
|
2017-09-18 04:16:24 +02:00
|
|
|
'',
|
2016-02-19 01:48:25 +01:00
|
|
|
$approvedComments,
|
|
|
|
CommentsGridFieldConfig::create()
|
|
|
|
);
|
|
|
|
|
|
|
|
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
|
|
|
|
|
|
|
|
$spamGrid = new CommentsGridField(
|
|
|
|
'SpamComments',
|
2017-09-18 04:16:24 +02:00
|
|
|
'',
|
2016-02-19 01:48:25 +01:00
|
|
|
$spamComments,
|
|
|
|
CommentsGridFieldConfig::create()
|
|
|
|
);
|
|
|
|
|
2017-12-14 04:08:43 +01:00
|
|
|
$fields = FieldList::create(
|
|
|
|
$root = TabSet::create(
|
|
|
|
'Root',
|
|
|
|
Tab::create(
|
2017-09-13 23:41:11 +02:00
|
|
|
'NewComments',
|
2017-12-14 04:08:43 +01:00
|
|
|
_t(
|
|
|
|
__CLASS__.'.NewComments',
|
|
|
|
'New ({count})',
|
|
|
|
['count' => count($newComments)]
|
|
|
|
),
|
2016-02-19 01:48:25 +01:00
|
|
|
$newGrid
|
|
|
|
),
|
2017-12-14 04:08:43 +01:00
|
|
|
Tab::create(
|
2017-09-13 23:41:11 +02:00
|
|
|
'ApprovedComments',
|
2017-12-14 04:08:43 +01:00
|
|
|
_t(
|
|
|
|
__CLASS__.'.ApprovedComments',
|
|
|
|
'Approved ({count})',
|
|
|
|
['count' => count($approvedComments)]
|
|
|
|
),
|
2016-02-19 01:48:25 +01:00
|
|
|
$approvedGrid
|
|
|
|
),
|
2017-12-14 04:08:43 +01:00
|
|
|
Tab::create(
|
2017-09-13 23:41:11 +02:00
|
|
|
'SpamComments',
|
2017-12-14 04:08:43 +01:00
|
|
|
_t(
|
|
|
|
__CLASS__.'.SpamComments',
|
|
|
|
'Spam ({count})',
|
|
|
|
['count' => count($spamComments)]
|
|
|
|
),
|
2016-02-19 01:48:25 +01:00
|
|
|
$spamGrid
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2017-12-14 04:08:43 +01:00
|
|
|
$actions = FieldList::create();
|
2016-02-19 01:48:25 +01:00
|
|
|
|
2017-12-14 04:08:43 +01:00
|
|
|
$form = Form::create(
|
2016-02-19 01:48:25 +01:00
|
|
|
$this,
|
|
|
|
'EditForm',
|
|
|
|
$fields,
|
|
|
|
$actions
|
|
|
|
);
|
|
|
|
|
2018-08-27 04:31:52 +02:00
|
|
|
$form->addExtraClass('cms-edit-form fill-height');
|
2016-02-19 01:48:25 +01:00
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
|
|
|
|
|
|
|
if ($form->Fields()->hasTabset()) {
|
2017-12-14 04:08:43 +01:00
|
|
|
$form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet');
|
2016-02-19 01:48:25 +01:00
|
|
|
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->extend('updateEditForm', $form);
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
2010-11-29 23:24:17 +01:00
|
|
|
}
|