-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathProfile.php
More file actions
369 lines (312 loc) · 16.7 KB
/
Profile.php
File metadata and controls
369 lines (312 loc) · 16.7 KB
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Controller;
use FeatherBB\Core\Database as DB;
use FeatherBB\Core\Error;
use FeatherBB\Core\Interfaces\Container;
use FeatherBB\Core\Interfaces\ForumEnv;
use FeatherBB\Core\Interfaces\ForumSettings;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\Input;
use FeatherBB\Core\Interfaces\Lang;
use FeatherBB\Core\Interfaces\Parser;
use FeatherBB\Core\Interfaces\Perms;
use FeatherBB\Core\Interfaces\Request;
use FeatherBB\Core\Interfaces\Router;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Interfaces\View;
use FeatherBB\Core\Utils;
class Profile
{
public function __construct()
{
$this->model = new \FeatherBB\Model\Profile();
Lang::load('profile');
Lang::load('register');
Lang::load('prof_reg');
Lang::load('misc');
}
public function display($req, $res, $args)
{
if ($args['id'] < 2) {
throw new Error(__('Bad request'), 400);
}
$args['id'] = Hooks::fire('controller.profile.display', $args['id']);
if (Input::post('update_group_membership')) {
if (User::get()->g_id > ForumEnv::get('FEATHER_ADMIN')) {
throw new Error(__('No permission'), 403);
}
return $this->model->updateGroupMembership($args['id']);
} elseif (Input::post('update_forums')) {
if (User::get()->g_id > ForumEnv::get('FEATHER_ADMIN')) {
throw new Error(__('No permission'), 403);
}
return $this->model->updateModForums($args['id']);
} elseif (Input::post('ban')) {
if (!User::isAdmin() && (!User::isAdminMod() || !User::can('mod.ban_users'))) {
throw new Error(__('No permission'), 403);
}
return $this->model->banUser($args['id']);
} elseif (Input::post('delete_user') || Input::post('delete_user_comply')) {
if (User::get()->g_id > ForumEnv::get('FEATHER_ADMIN')) {
throw new Error(__('No permission'), 403);
}
if (Input::post('delete_user_comply')) {
return $this->model->deleteUser($args['id']);
} else {
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Confirm delete user')],
'active_page' => 'profile',
'username' => $this->model->getUsername($args['id']),
'id' => $args['id'],
])->addTemplate('@forum/profile/delete_user')->display();
}
} elseif (Input::post('form_sent')) {
// Fetch the user group of the user we are editing
$info = $this->model->getUserGroup($args['id']);
if (User::get()->id != $args['id'] && // If we aren't the user (i.e. editing your own profile)
(!User::isAdminMod() || // and we are not an admin or mod
(!User::isAdmin() && // or we aren't an admin and ...
(!User::can('mod.edit_users') || // mods aren't allowed to edit users
$info['group_id'] == ForumEnv::get('FEATHER_ADMIN') || // or the user is an admin
Perms::getGroupPermissions($info['group_id'], 'mod.is_mod'))))) { // or the user is another mod
throw new Error(__('No permission'), 403);
}
return $this->model->updateProfile($args['id'], $info, $args['section']);
}
$user = $this->model->getUserInfo($args['id']);
if ($user['signature'] != '') {
$parsedSignature = Parser::parseSignature($user['signature']);
}
// View or edit?
if (User::get()->id != $args['id'] && // If we aren't the user (i.e. editing your own profile)
(!User::isAdminMod() || // and we are not an admin or mod
(!User::isAdmin() && // or we aren't an admin and ...
(!User::can('mod.edit_users') || // mods aren't allowed to edit users
User::isAdmin($user) || // or the user is an admin
User::isAdminMod($user)))) // or the user is another mod
) {
$userInfo = $this->model->parseUserInfo($user);
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), sprintf(__('Users profile'), Utils::escape($user['username']))],
'active_page' => 'profile',
'user_info' => $userInfo,
'id' => $args['id']
]);
View::addTemplate('profile/view_profile')->display();
} else {
if (!isset($args['section']) || $args['section'] == 'essentials') {
$userDisp = $this->model->editEssentials($args['id'], $user);
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Section essentials')],
'active_page' => 'profile',
'id' => $args['id'],
'page' => 'essentials',
'user' => $user,
'user_disp' => $userDisp,
'forum_time_formats' => Container::get('forum_time_formats'),
'forum_date_formats' => Container::get('forum_date_formats')
]);
View::addTemplate('profile/menu.php', 5)->addTemplate('@forum/profile/section_essentials')->display();
} elseif ($args['section'] == 'personal') {
if (User::can('user.set_title')) {
$titleField = '<label>'.__('Title').' <em>('.__('Leave blank').')</em><br /><input type="text" name="title" value="'.Utils::escape($user['title']).'" size="30" maxlength="50" /><br /></label>'."\n";
}
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Section personal')],
'active_page' => 'profile',
'id' => $args['id'],
'page' => 'personal',
'user' => $user,
'title_field' => $titleField,
]);
View::addTemplate('profile/menu.php', 5)->addTemplate('@forum/profile/section_personal')->display();
} elseif ($args['section'] == 'personality') {
if (ForumSettings::get('o_avatars') == '0' && ForumSettings::get('o_signatures') == '0') {
throw new Error(__('Bad request'), 404);
}
$avatarField = '<span><a href="'.Router::pathFor('profileAction', ['id' => $args['id'], 'action' => 'upload_avatar']).'">'.__('Change avatar').'</a></span>';
$userAvatar = Utils::generateAvatarMarkup($args['id']);
if ($userAvatar) {
$avatarField .= ' <span><a href="'.Router::pathFor('profileAction', ['id' => $args['id'], 'action' => 'delete_avatar']).'">'.__('Delete avatar').'</a></span>';
} else {
$avatarField = '<span><a href="'.Router::pathFor('profileAction', ['id' => $args['id'], 'action' => 'upload_avatar']).'">'.__('Upload avatar').'</a></span>';
}
if ($user['signature'] != '') {
$signaturePreview = '<p>'.__('Sig preview').'</p>'."\n\t\t\t\t\t\t\t".'<div class="postsignature postmsg">'."\n\t\t\t\t\t\t\t\t".'<hr />'."\n\t\t\t\t\t\t\t\t".$parsedSignature."\n\t\t\t\t\t\t\t".'</div>'."\n";
} else {
$signaturePreview = '<p>'.__('No sig').'</p>'."\n";
}
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Section personality')],
'active_page' => 'profile',
'user_avatar' => $userAvatar,
'avatar_field' => $avatarField,
'signature_preview' => $signaturePreview,
'page' => 'personality',
'user' => $user,
'id' => $args['id'],
]);
View::addTemplate('profile/menu.php', 5)->addTemplate('@forum/profile/section_personality')->display();
} elseif ($args['section'] == 'display') {
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Section display')],
'active_page' => 'profile',
'page' => 'display',
'user' => $user,
'id' => $args['id']
]);
View::addTemplate('profile/menu.php', 5)->addTemplate('@forum/profile/section_display')->display();
} elseif ($args['section'] == 'privacy') {
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Section privacy')],
'active_page' => 'profile',
'page' => 'privacy',
'user' => $user,
'id' => $args['id']
]);
View::addTemplate('profile/menu.php', 5)->addTemplate('@forum/profile/section_privacy')->display();
} elseif ($args['section'] == 'admin') {
if (!User::isAdminMod() || (User::isAdminMod() && !User::can('mod.ban_users'))) {
throw new Error(__('Bad request'), 404);
}
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Section admin')],
'active_page' => 'profile',
'page' => 'admin',
'user' => $user,
'forum_list' => $this->model->forumList($args['id']),
'group_list' => $this->model->groupList($user),
'id' => $args['id']
]);
return View::addTemplate('profile/menu.php', 5)->addTemplate('@forum/profile/section_admin')->display();
} else {
throw new Error(__('Bad request'), 404);
}
}
}
public function action($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.profile.action', $args['id']);
if ($args['action'] != 'change_pass' || !Input::query('key')) {
if (!User::can('board.read')) {
throw new Error(__('No view'), 403);
} elseif (!User::can('users.view') && (User::get()->is_guest || User::get()->id != $args['id'])) {
throw new Error(__('No permission'), 403);
}
}
// Make sure user exists
if (!DB::table('users')->findOne($args['id']) || $args['id'] < 2) {
throw new Error(__('Bad request'), 404);
}
if ($args['action'] == 'change_pass') {
// Make sure we are allowed to change this user's password
if (User::get()->id != $args['id']) {
$args['id'] = Hooks::fire('controller.profile.change_pass_key_not_id', $args['id']);
if (!User::isAdminMod()) { // A regular user trying to change another user's password?
throw new Error(__('No permission'), 403);
} elseif (User::isAdminMod()) {
// A moderator trying to change a user's password?
if (!User::can('mod.edit_users') || !User::can('mod.change_passwords') || User::isAdminMod($args['id'])) {
throw new Error(__('No permission'), 403);
}
}
}
// User is allowed to change pass and has submitted the forum, do it
if (Request::isPost()) {
return $this->model->changePass($args['id']);
}
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Change pass')],
'active_page' => 'profile',
'id' => $args['id']
]
)->addTemplate('@forum/profile/change_pass')->display();
} elseif ($args['action'] == 'change_email') {
// Make sure we are allowed to change this user's email
if (User::get()->id != $args['id']) {
$args['id'] = Hooks::fire('controller.profile.change_email_not_id', $args['id']);
if (!User::isAdminMod()) { // A regular user trying to change another user's email?
throw new Error(__('No permission'), 403);
} elseif (User::isAdminMod()) {
// A moderator trying to change a user's email?
if (!User::can('mod.edit_users') || !User::can('mod.change_passwords') || User::isAdminMod($args['id'])) {
throw new Error(__('No permission'), 403);
}
}
}
// User is allowed to change email and has submitted the forum, do it
if (Request::isPost() || Input::query('key')) {
return $this->model->changeEmail($args['id']);
}
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Change email')],
'active_page' => 'profile',
'id' => $args['id'],
]
)->addTemplate('@forum/profile/change_mail')->display();
} elseif ($args['action'] == 'upload_avatar' || $args['action'] == 'upload_avatar2') {
if (ForumSettings::get('o_avatars') == '0') {
throw new Error(__('Avatars disabled'), 400);
}
if (User::get()->id != $args['id'] && !User::isAdminMod()) {
throw new Error(__('No permission'), 403);
}
if (Request::isPost()) {
return $this->model->uploadAvatar($args['id'], $_fILES);
}
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Upload avatar')],
'active_page' => 'profile',
'id' => $args['id'],
]
)->addTemplate('@forum/profile/upload_avatar')->display();
} elseif ($args['action'] == 'delete_avatar') {
if (User::get()->id != $args['id'] && !User::isAdminMod()) {
throw new Error(__('No permission'), 403);
}
$this->model->deleteAvatar($args['id']);
return Router::redirect(Router::pathFor('profileSection', ['id' => $args['id'], 'section' => 'personality']), __('Avatar deleted redirect'));
} elseif ($args['action'] == 'promote') {
if (!User::isAdmin() && (!User::isAdminMod() || !User::can('mod.promote_users'))) {
throw new Error(__('No permission'), 403);
}
return $this->model->promoteUser($args['id'], $args['pid']);
} else {
throw new Error(__('Bad request'), 404);
}
}
public function email($req, $res, $args)
{
$args['id'] = Hooks::fire('controller.profile.email', $args['id']);
if (!User::can('email.send')) {
throw new Error(__('No permission'), 403);
}
if ($args['id'] < 2) {
throw new Error(__('Bad request'), 400);
}
$mail = $this->model->getInfoMail($args['id']);
if ($mail['email_setting'] == 2 && !User::isAdminMod()) {
throw new Error(__('Form email disabled'), 403);
}
if (Request::isPost()) {
return $this->model->sendEmail($mail);
}
return View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Send email to').' '.Utils::escape($mail['recipient'])],
'active_page' => 'email',
'id' => $args['id'],
'mail' => $mail
])->addTemplate('@forum/misc/email')->display();
}
public function gethostip($req, $res, $args)
{
$args['ip'] = Hooks::fire('controller.profile.gethostip', $args['ip']);
$this->model->displayIpInfo($args['ip']);
}
}