-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin_config.php
323 lines (246 loc) · 7.38 KB
/
admin_config.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
require_once '../../class2.php';
if ( ! getperms('P') || ! e107::isInstalled('navatar')) {
e107::redirect('admin');
exit;
}
use Navatar\Plugin\Controllers\Font;
use Navatar\Plugin\Models\User;
use Navatar\Plugin\Controllers\File;
e107::lan('navatar', 'admin', true);
class NavatarAdmin extends e_admin_dispatcher
{
protected $modes = [
'main' => [
'controller' => 'NavatarAdminMain',
'path' => null,
'ui' => 'navatar_form_ui',
'uipath' => null,
],
'tools' => [
'controller' => 'NavatarAdminTools',
'path' => null,
'ui' => 'navatar_form_ui',
'uipath' => null,
],
];
protected $adminMenu = [
'main/prefs' => ['caption' => LAN_PREFS, 'perm' => 'P'],
'main/div0' => ['divider' => true],
'tools/tidyup' => ['caption' => 'Tidy-up Wizard', 'perm' => 'P'],
];
protected $adminMenuAliases = [
'main/edit' => 'main/list',
];
protected $menuTitle = 'Navatar';
}
class NavatarAdminMain extends e_admin_ui
{
protected $pluginTitle = 'Navatar';
protected $pluginName = 'navatar';
protected $preftabs = ['General', 'Text', 'Color', 'Font', 'Schedule'];
protected $prefs = [
'master_active' => [
'title' => 'Activate',
'tab' => 0,
'type' => 'boolean',
'data' => 'int',
'help' => 'Activate Navatar',
],
'user_trigger_event' => [
'title' => 'User event that trigger navatar generation:',
'tab' => 0,
'type' => 'dropdown',
'data' => 'str',
'help' => 'Which user event trigger generation of Navatar.',
],
'php_graphics_lib' => [
'title' => 'PHP Graphics Library:',
'tab' => 0,
'type' => 'dropdown',
'data' => 'str',
'help' => 'Which driver to use for Navatar generation.',
],
'navatar_size' => [
'title' => 'Navatar Image Size:',
'tab' => 0,
'type' => 'text',
'data' => 'int',
'help' => 'Navatar Image Size. Default is 48x48 pixels.',
],
'navatar_quality' => [
'title' => 'Image Quality:',
'tab' => 0,
'type' => 'text',
'data' => 'int',
'help' => 'Quality of generated Navatar image.',
],
'initials_source' => [
'title' => 'Initials source:',
'tab' => 1,
'type' => 'dropdown',
'data' => 'str',
'help' => 'Which source to use for initials - Username used on site or Real Name.',
],
'character_length' => [
'title' => 'Character Length:',
'tab' => 1,
'type' => 'dropdown',
'data' => 'int',
'help' => 'The number of characters to use in initials.',
],
'font_color' => [
'title' => 'Foreground (Font) Color:',
'tab' => 2,
'type' => 'text',
'data' => 'str',
'help' => 'The color of foreground text font.',
],
'background_colors' => [
'title' => 'Background Color(s):',
'tab' => 2,
'type' => 'textarea',
'data' => 'str',
'help' => 'Background colors in hex format each color in new line or separated with space or tab.',
],
'random_bg_color' => [
'title' => 'Randomize background color:',
'tab' => 2,
'type' => 'boolean',
'data' => 'int',
'help' => 'Randomize background color',
],
'font_size' => [
'title' => 'Font Size Factor:',
'tab' => 3,
'type' => 'text',
'data' => 'str',
'help' => 'The size of font. Default value is: 0.5. If the Image size is 50px and fontSize is 0.5, the font size will be 25px.',
],
'font_variant' => [
'title' => 'Font Variants:',
'tab' => 3,
'type' => 'dropdown',
'data' => 'str',
'help' => 'Select font variant.',
],
'job_queue_active' => [
'title' => 'Activate/Deactivate Cron Job Queue: (Not Implemented)',
'tab' => 4,
'type' => 'boolean',
'data' => 'int',
'help' => 'Not yet implemented.',
],
];
protected $intialsSource = [
'username' => LAN_NAVATAR_PREF_VAL_USERNAME,
'realname' => LAN_NAVATAR_PREF_VAL_REALNAME,
];
protected $characterLength = [
1 => 1,
2 => 2,
];
protected $graphicsLibrary = [
'gd' => 'GD',
'imagick' => 'Imagick',
];
protected $userTrigger = [
'login' => 'Login Event',
'activate' => 'Activation Event',
'both' => 'Login OR Activation Event',
];
public function init()
{
if (defined('NAVATAR_NO_DEPENDENCIES')) {
$message = e107::getMessage();
$tp = e107::getParser();
$warnMessageLink = $tp->lanVars(LAN_NAVATAR_NO_DEP_WARNING_3, [
'readme' => '<a href="README.md">README.md</a>',
'package' => '<a href="https://github.com/arunshekher/navatar/archive/master.zip">
https://github.com/arunshekher/navatar/archive/master.zip
</a>',
]);
$warning =
'<h4>' . LAN_NAVATAR_NO_DEP_WARNING_1 . '</h4><br>' . LAN_NAVATAR_NO_DEP_WARNING_2 . '<br>' . $warnMessageLink;
return $message->addWarning($warning, 'default');
}
$this->prefs['initials_source']['writeParms'] = $this->intialsSource;
$this->prefs['user_trigger_event']['writeParms'] = $this->userTrigger;
$this->prefs['character_length']['writeParms'] = $this->characterLength;
$this->prefs['php_graphics_lib']['writeParms'] = $this->graphicsLibrary;
$this->prefs['font_variant']['writeParms'] = Font::index();
}
public function renderHelp()
{
$template = e107::getTemplate('navatar', 'project_menu');
$text = e107::getParser()->parseTemplate($template, true, [
'DEV_SUPPORT' => LAN_NAVATAR_INFO_MENU_SUPPORT_DEV_TEXT,
'SIGN' => LAN_NAVATAR_INFO_MENU_SUPPORT_DEV_TEXT_SIGN,
]);
return [
'caption' => LAN_NAVATAR_INFO_MENU_TITLE,
'text' => $text,
];
}
}
class NavatarAdminTools extends e_admin_ui
{
public function tidyupPage()
{
$tp = e107::getParser();
$frm = e107::getForm();
$mes = e107::getMessage();
$this->tidyupPageProcess();
$userCount =
'<span class="badge badge-warning">' . User::count() . '</span>';
$confirmText = $tp->lanVars(LAN_NAVATAR_TIDY_CONFIRM_ROLLBACK,
['count' => $userCount, 'user' => MPREFIX . 'user']);
$mes->addInfo(LAN_NAVATAR_TIDY_INFO, 'navatar-mstack');
$message = $mes->render('navatar-mstack');
$mes->reset('navatar-mstack');
$text = '
<form method="post" action="' . e_SELF . '?' . e_QUERY . '">
<div class="form-group">
' . $frm->checkbox('confirm-delete', 1, false,
['label' => $confirmText, 'class' => 'form-check-label']) . '
</div>
' . $frm->admin_button('navatar-tidyup', 'Rollback Records', 'submit') . '
</form>';
return $message . $text;
}
public function tidyupPageProcess()
{
$mes = e107::getMessage();
$tp = e107::getParser();
if (strtolower($_SERVER['REQUEST_METHOD']) === 'post' && isset($_POST['navatar-tidyup'])) {
if (isset($_POST['confirm-delete'])) {
if (User::rollback()) {
$mes->addSuccess(LAN_NAVATAR_TIDY_MES_SUC_RECORDS_REMOVED,
'navatar-mstack');
$removal = File::remove('*');
if (count($removal['fail']) > 0) {
$failMessage =
$tp->lanVars(LAN_NAVATAR_TIDY_MES_WARN_FAIL_DELETE,
['files' => implode(', ', $removal['fail'])]);
return $mes->addWarning($failMessage, 'navatar-mstack');
}
return $mes->addStack(LAN_NAVATAR_TIDY_MES_SUC_FILES_REMOVED,
'navatar-mstack', E_MESSAGE_SUCCESS);
}
return $mes->addError(LAN_NAVATAR_TIDY_MES_ERR_NO_RECORDS,
'navatar-mstack');
}
return $mes->addWarning(LAN_NAVATAR_TIDY_MES_WARN_TICK,
'navatar-mstack');
}
return false;
}
}
class navatar_form_ui extends e_admin_form_ui
{
}
new NavatarAdmin();
require_once e_ADMIN . 'auth.php';
e107::getAdminUI()->runPage();
require_once e_ADMIN . 'footer.php';
exit;