-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPlugin.php
258 lines (232 loc) · 7.42 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php namespace Clake\UserExtended;
use Backend\Classes\Controller;
use Clake\UserExtended\Classes\UserExtended;
use System\Classes\PluginBase;
use Event;
use Backend;
use System\Classes\SettingsManager;
/**
* User Extended Core by Shawn Clake
* Major Contributors: Quinn Bast
*
* User Extended is licensed under the MIT license.
* @link https://github.com/ShawnClake/UserExtended
*
* @version 2.1.00 User Extended Core
*
* @author Shawn Clake <[email protected]>
* @link https://github.com/ShawnClake
* @link http://shawnclake.com
*
* Major Contributors:
* @link https://github.com/QuinnBast
*
* @license https://github.com/ShawnClake/UserExtended/blob/master/LICENSE
*
* Class Plugin
* @package Clake\UserExtended
*/
class Plugin extends PluginBase
{
/**
* @var array
*/
public $require = [
'RainLab.User'
];
/**
* Returns information about this plugin.
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'UserExtended',
'description' => 'Adds roles, friends, profiles, and utility functions to the Rainlab User plugin',
'author' => 'clake',
'icon' => 'icon-user-plus',
'homepage' => 'https://github.com/ShawnClake/UserExtended'
];
}
/**
* Adds twig filters and functions
* @return array
*/
public function registerMarkupTags()
{
return [
'filters' => [
'timezonify' => [
'Clake\Userextended\Classes\TimezoneHandler',
'twigTimezoneAdjustment'
],
'relative' => [
'Clake\Userextended\Classes\TimezoneHandler',
'twigRelativeTimeString'
]
]
];
}
/**
* Register method, called when the plugin is first registered.
* @return void
*/
public function register()
{
/*
* Registers the UE scaffolding command for creating modules
*/
$this->registerConsoleCommand('create:uemodule', 'Clake\UserExtended\Console\CreateUEModule');
/*
* Registers the UserExtended core module
*/
Module::register();
}
/**
* Boot method, called right before the request route.
* @return array
*/
public function boot()
{
/*
* Boots the modules which were registered with UserExtended
*/
UserExtended::boot();
/*
* Event listener adds the Group Manager button to the side bar of the User backend UI.
*/
Event::listen('backend.menu.extendItems', function ($manager)
{
$manager->addSideMenuItems('RainLab.User', 'user', [
/*'groups' => [
'label' => 'Group Manager',
'url' => Backend::url('clake/userextended/groupsextended'),
'icon' => 'icon-users',
'order' => 500
],*/
'roles' => [
'label' => 'Role Manager',
'url' => Backend::url('clake/userextended/roles/manage'),
'icon' => 'icon-pencil',
'order' => 600
],
'users-side' => [
'label' => 'Users',
'url' => Backend::url('rainlab/user/users'),
'icon' => 'icon-user',
'order' => 100
],
'fields' => [
'label' => 'Field Manager',
'url' => Backend::url('clake/userextended/fields/manage'),
'icon' => 'icon-pencil-square-o',
'order' => 700
],
]);
});
// TODO: Try and see if we can hack in some code for injecting fields into the user controller.
// TODO: The reason we can't right now, is although the field would appear the user controller
// TODO: Wouldn't know how to save them as they get array'd and saved as JSON.
/*$settings =
Event::listen('backend.form.extendFields', function($widget) {
// Only for the User controller
if (!$widget->getController() instanceof \RainLab\User\Controllers\Users) {
return;
}
// Only for the User model
if (!$widget->model instanceof \RainLab\User\Models\User) {
return;
}
// Add an extra birthday field
$widget->addFields([
'birthday' => [
'label' => 'Birthday',
'comment' => 'Select the users birthday',
'type' => 'datepicker'
]
]);
});*/
return [];
}
/**
* Registers any front-end components implemented in this plugin.
* @return array
*/
public function registerComponents()
{
return array_merge(
UserExtended::getComponents(),
[]
);
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'UserExtended Settings',
'description' => 'Manage user extended settings.',
'category' => SettingsManager::CATEGORY_USERS,
'icon' => 'icon-cog',
'class' => 'Clake\Userextended\Models\Settings',
'order' => 100,
'keywords' => 'security user extended',
'permissions' => ['']
]
];
}
/**
* Registers any back-end permissions used by this plugin.
* @return array
*/
public function registerPermissions()
{
return [];
}
/**
* Registers back-end navigation items for this plugin.
* @return array
*/
public function registerNavigation()
{
return array_merge(
UserExtended::getNavigation(),
[]
);
}
/**
* Injects assets from modules. Also overrides the defaults presented in general.js and general.css
* @param $component
*/
public static function injectAssets($component)
{
// Cant move these out because then the defaults wouldn't have top priority.
$component->addJs('/plugins/clake/userextended/assets/js/general.js');
$component->addCss('/plugins/clake/userextended/assets/css/general.css');
/*
* Handles injecting JS and CSS assets
*/
$assets = UserExtended::getAssets();
foreach ($assets as $asset) {
$type = trim(substr($asset, strrpos($asset, '.') + 1));
if ($type == 'js') {
$component->addJs($asset);
}
else if ($type == 'css') {
$component->addCss($asset);
}
}
}
/**
* Registers mail templates
* @return array
*/
public function registerMailTemplates()
{
return [
'clake.userextended::mail.on_group_role_changed' => 'Notify that the users group was changed',
'clake.userextended::mail.received_friend_request' => 'Friend request',
'clake.userextended::mail.received_profile_comment' => 'New comment on user profile',
'clake.userextended::mail.register' => 'Registration confirmation email'
];
}
}