-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathPlugin.php
176 lines (161 loc) · 5.29 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php namespace RainLab\Forum;
use Backend;
use RainLab\User\Models\User;
use RainLab\Forum\Models\Member;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
use RainLab\User\Controllers\Users as UsersController;
/**
* Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* @var array require other plugins
*/
public $require = [
'RainLab.User'
];
/**
* pluginDetails returns information about this plugin.
*/
public function pluginDetails()
{
return [
'name' => "Forum",
'description' => "A simple embeddable forum",
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-comments',
'homepage' => 'https://github.com/rainlab/forum-plugin'
];
}
/**
* register the service provider.
*/
public function register()
{
$this->registerSingletons();
}
/**
* boot
*/
public function boot()
{
User::extend(function($model) {
$model->hasOne['forum_member'] = \RainLab\Forum\Models\Member::class;
$model->bindEvent('model.beforeDelete', function() use ($model) {
$model->forum_member && $model->forum_member->delete();
});
});
UsersController::extendFormFields(function($widget, $model, $context) {
// Prevent extending of related form instead of the intended User form
if (!$widget->model instanceof \RainLab\User\Models\User) {
return;
}
if ($context != 'update') {
return;
}
if (!Member::getFromUser($model)) {
return;
}
$widget->addFields([
'forum_member[username]' => [
'label' => "Username",
'comment' => "The display to represent this user on the forum.",
'tab' => 'Forum'
],
'forum_member[is_moderator]' => [
'label' => "Forum moderator",
'comment' => "Place a tick in this box if this user can moderate the entire forum.",
'type' => 'checkbox',
'tab' => 'Forum',
'span' => 'auto'
],
'forum_member[is_banned]' => [
'label' => "Banned from forum",
'comment' => "Place a tick in this box if this user is banned from posting to the forum.",
'type' => 'checkbox',
'tab' => 'Forum',
'span' => 'auto'
]
], 'primary');
});
UsersController::extendListColumns(function($widget, $model) {
if (!$model instanceof \RainLab\User\Models\User) {
return;
}
$widget->addColumns([
'forum_member_username' => [
'label' => "Forum Username",
'relation' => 'forum_member',
'select' => 'username',
'searchable' => false,
'invisible' => true
]
]);
});
}
/**
* registerSingletons
*/
protected function registerSingletons()
{
$this->app->singleton('rainlab.forum.tracker', \RainLab\Forum\Classes\TopicTracker::class);
}
/**
* registerComponents
*/
public function registerComponents()
{
return [
\RainLab\Forum\Components\ForumChannel::class => 'forumChannel',
\RainLab\Forum\Components\ForumChannels::class => 'forumChannels',
\RainLab\Forum\Components\ForumTopic::class => 'forumTopic',
\RainLab\Forum\Components\ForumTopics::class => 'forumTopics',
\RainLab\Forum\Components\ForumPosts::class => 'forumPosts',
\RainLab\Forum\Components\ForumMember::class => 'forumMember',
\RainLab\Forum\Components\ForumEmbedTopic::class => 'forumEmbedTopic',
\RainLab\Forum\Components\ForumEmbedChannel::class => 'forumEmbedChannel',
\RainLab\Forum\Components\ForumRssFeed::class => 'forumRssFeed'
];
}
/**
* registerPermissions
*/
public function registerPermissions()
{
return [
'rainlab.forum.manage_channels' => [
'tab' => "Forum Channels",
'label' => "Manage available forum channels."
]
];
}
/**
* registerSettings
*/
public function registerSettings()
{
return [
'settings' => [
'label' => "Forum Channels",
'description' => "Manage available forum channels.",
'icon' => 'icon-comments',
'url' => Backend::url('rainlab/forum/channels'),
'category' => SettingsManager::CATEGORY_USERS,
'order' => 500,
'permissions' => ['rainlab.forum.manage_channels'],
]
];
}
/**
* registerMailTemplates
*/
public function registerMailTemplates()
{
return [
'rainlab.forum:topic_reply' => 'rainlab.forum::mail.topic_reply',
'rainlab.forum:member_report' => 'rainlab.forum::mail.member_report'
];
}
}