|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Comment administration system within the CMS |
|
5
|
|
|
* |
|
6
|
|
|
* @package comments |
|
7
|
|
|
*/ |
|
8
|
|
|
class CommentAdmin extends LeftAndMain implements PermissionProvider |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
private static $url_segment = 'comments'; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
private static $url_rule = '/$Action'; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
private static $menu_title = 'Comments'; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
18
|
|
|
'approvedmarked', |
|
19
|
|
|
'deleteall', |
|
20
|
|
|
'deletemarked', |
|
21
|
|
|
'hammarked', |
|
22
|
|
|
'showtable', |
|
23
|
|
|
'spammarked', |
|
24
|
|
|
'EditForm', |
|
25
|
|
|
'unmoderated' |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
public function providePermissions() |
|
29
|
|
|
{ |
|
30
|
|
|
return array( |
|
31
|
|
|
"CMS_ACCESS_CommentAdmin" => array( |
|
32
|
|
|
'name' => _t('CommentAdmin.ADMIN_PERMISSION', "Access to 'Comments' section"), |
|
33
|
|
|
'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access') |
|
34
|
|
|
) |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return Form |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getEditForm($id = null, $fields = null) |
|
42
|
|
|
{ |
|
43
|
|
|
if (!$id) { |
|
44
|
|
|
$id = $this->currentPageID(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$form = parent::getEditForm($id); |
|
|
|
|
|
|
48
|
|
|
$record = $this->getRecord($id); |
|
49
|
|
|
|
|
50
|
|
|
if ($record && !$record->canView()) { |
|
51
|
|
|
return Security::permissionFailure($this); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$newComments = Comment::get()->filter('Moderated', 0); |
|
55
|
|
|
|
|
56
|
|
|
$newGrid = new CommentsGridField( |
|
57
|
|
|
'NewComments', |
|
58
|
|
|
_t('CommentsAdmin.NewComments', 'New'), |
|
59
|
|
|
$newComments, |
|
60
|
|
|
CommentsGridFieldConfig::create() |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0); |
|
64
|
|
|
|
|
65
|
|
|
$approvedGrid = new CommentsGridField( |
|
66
|
|
|
'ApprovedComments', |
|
67
|
|
|
_t('CommentsAdmin.ApprovedComments', 'Approved'), |
|
68
|
|
|
$approvedComments, |
|
69
|
|
|
CommentsGridFieldConfig::create() |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1); |
|
73
|
|
|
|
|
74
|
|
|
$spamGrid = new CommentsGridField( |
|
75
|
|
|
'SpamComments', |
|
76
|
|
|
_t('CommentsAdmin.SpamComments', 'Spam'), |
|
77
|
|
|
$spamComments, |
|
78
|
|
|
CommentsGridFieldConfig::create() |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$newCount = '(' . count($newComments) . ')'; |
|
82
|
|
|
$approvedCount = '(' . count($approvedComments) . ')'; |
|
83
|
|
|
$spamCount = '(' . count($spamComments) . ')'; |
|
84
|
|
|
|
|
85
|
|
|
$fields = new FieldList( |
|
86
|
|
|
$root = new TabSet( |
|
87
|
|
|
'Root', |
|
88
|
|
|
new Tab('NewComments', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount, |
|
89
|
|
|
$newGrid |
|
90
|
|
|
), |
|
91
|
|
|
new Tab('ApprovedComments', _t('CommentAdmin.ApprovedComments', 'Approved') . ' ' . $approvedCount, |
|
92
|
|
|
$approvedGrid |
|
93
|
|
|
), |
|
94
|
|
|
new Tab('SpamComments', _t('CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount, |
|
95
|
|
|
$spamGrid |
|
96
|
|
|
) |
|
97
|
|
|
) |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$root->setTemplate('CMSTabSet'); |
|
101
|
|
|
|
|
102
|
|
|
$actions = new FieldList(); |
|
103
|
|
|
|
|
104
|
|
|
$form = new Form( |
|
105
|
|
|
$this, |
|
106
|
|
|
'EditForm', |
|
107
|
|
|
$fields, |
|
108
|
|
|
$actions |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
$form->addExtraClass('cms-edit-form'); |
|
112
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
if ($form->Fields()->hasTabset()) { |
|
115
|
|
|
$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); |
|
116
|
|
|
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$this->extend('updateEditForm', $form); |
|
120
|
|
|
|
|
121
|
|
|
return $form; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.