1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Comments\Admin; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Admin\LeftAndMain; |
6
|
|
|
use SilverStripe\Comments\Model\Comment; |
7
|
|
|
use SilverStripe\Forms\FieldList; |
8
|
|
|
use SilverStripe\Forms\Form; |
9
|
|
|
use SilverStripe\Forms\Tab; |
10
|
|
|
use SilverStripe\Forms\TabSet; |
11
|
|
|
use SilverStripe\Security\PermissionProvider; |
12
|
|
|
use SilverStripe\Security\Security; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Comment administration system within the CMS |
16
|
|
|
* |
17
|
|
|
* @package comments |
18
|
|
|
*/ |
19
|
|
|
class CommentAdmin extends LeftAndMain implements PermissionProvider |
20
|
|
|
{ |
21
|
|
|
private static $url_segment = 'comments'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
private static $url_rule = '/$Action'; |
|
|
|
|
24
|
|
|
|
25
|
|
|
private static $menu_title = 'Comments'; |
|
|
|
|
26
|
|
|
|
27
|
|
|
private static $menu_icon_class = 'font-icon-comment'; |
|
|
|
|
28
|
|
|
|
29
|
|
|
private static $allowed_actions = [ |
|
|
|
|
30
|
|
|
'approvedmarked', |
31
|
|
|
'deleteall', |
32
|
|
|
'deletemarked', |
33
|
|
|
'hammarked', |
34
|
|
|
'showtable', |
35
|
|
|
'spammarked', |
36
|
|
|
'EditForm', |
37
|
|
|
'unmoderated' |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
private static $required_permission_codes = 'CMS_ACCESS_CommentAdmin'; |
|
|
|
|
41
|
|
|
|
42
|
|
|
public function providePermissions() |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
'CMS_ACCESS_CommentAdmin' => [ |
46
|
|
|
'name' => _t(__CLASS__ . '.ADMIN_PERMISSION', "Access to 'Comments' section"), |
47
|
|
|
'category' => _t('SilverStripe\\Security\\Permission.CMS_ACCESS_CATEGORY', 'CMS Access') |
48
|
|
|
], |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return Form |
54
|
|
|
*/ |
55
|
|
|
public function getEditForm($id = null, $fields = null) |
56
|
|
|
{ |
57
|
|
|
if (!$id) { |
58
|
|
|
$id = $this->currentPageID(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$form = parent::getEditForm($id); |
|
|
|
|
62
|
|
|
$record = $this->getRecord($id); |
63
|
|
|
|
64
|
|
|
if ($record && !$record->canView()) { |
65
|
|
|
return Security::permissionFailure($this); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$newComments = Comment::get()->filter('Moderated', 0); |
69
|
|
|
|
70
|
|
|
$newGrid = CommentsGridField::create( |
71
|
|
|
'NewComments', |
72
|
|
|
'', |
73
|
|
|
$newComments, |
74
|
|
|
CommentsGridFieldConfig::create() |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0); |
78
|
|
|
|
79
|
|
|
$approvedGrid = CommentsGridField::create( |
80
|
|
|
'ApprovedComments', |
81
|
|
|
'', |
82
|
|
|
$approvedComments, |
83
|
|
|
CommentsGridFieldConfig::create() |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1); |
87
|
|
|
|
88
|
|
|
$spamGrid = CommentsGridField::create( |
89
|
|
|
'SpamComments', |
90
|
|
|
'', |
91
|
|
|
$spamComments, |
92
|
|
|
CommentsGridFieldConfig::create() |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$fields = FieldList::create( |
96
|
|
|
$root = TabSet::create( |
97
|
|
|
'Root', |
98
|
|
|
Tab::create( |
99
|
|
|
'NewComments', |
100
|
|
|
_t( |
101
|
|
|
__CLASS__.'.NewComments', |
102
|
|
|
'New ({count})', |
103
|
|
|
['count' => count($newComments)] |
104
|
|
|
), |
105
|
|
|
$newGrid |
106
|
|
|
), |
107
|
|
|
Tab::create( |
108
|
|
|
'ApprovedComments', |
109
|
|
|
_t( |
110
|
|
|
__CLASS__.'.ApprovedComments', |
111
|
|
|
'Approved ({count})', |
112
|
|
|
['count' => count($approvedComments)] |
113
|
|
|
), |
114
|
|
|
$approvedGrid |
115
|
|
|
), |
116
|
|
|
Tab::create( |
117
|
|
|
'SpamComments', |
118
|
|
|
_t( |
119
|
|
|
__CLASS__.'.SpamComments', |
120
|
|
|
'Spam ({count})', |
121
|
|
|
['count' => count($spamComments)] |
122
|
|
|
), |
123
|
|
|
$spamGrid |
124
|
|
|
) |
125
|
|
|
) |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$actions = FieldList::create(); |
129
|
|
|
|
130
|
|
|
$form = Form::create( |
131
|
|
|
$this, |
132
|
|
|
'EditForm', |
133
|
|
|
$fields, |
134
|
|
|
$actions |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
$form->addExtraClass('cms-edit-form fill-height'); |
138
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
139
|
|
|
|
140
|
|
|
if ($form->Fields()->hasTabset()) { |
141
|
|
|
$form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
142
|
|
|
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$this->extend('updateEditForm', $form); |
146
|
|
|
|
147
|
|
|
return $form; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|