-
Notifications
You must be signed in to change notification settings - Fork 9
/
users.php
301 lines (264 loc) · 7.02 KB
/
users.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
<?php
/**
* users.php
*
* Allows editing of user settings / accounts, and viewing of other users.
* @author Nijiko Yonskai <me@nijikokun.com>
* @version 1.3RC2
* @lyric Why can't our bodies reset themselves? Won't you please reset me.
* @copyright (c) 2010 ANIGAIKU
* @package ninko
*/
include("include/common.php");
// Requesting what page?
switch($_GET['a'])
{
case "home": $action = "home"; break;
case "account": $action = "account"; break;
case "avatar": $action = "avatar"; break;
case "profile": $action = "profile"; break;
case "view": $action = "view"; break;
default: $action = "home"; break;
}
// Are they logged in? Are they trying to view a profile?
if(!$_SESSION['logged_in'])
{
if($action != "view")
{
header('Location: index.php');
}
}
// Include header
include($config['template_path'] . "header.php");
// Include the navigation
include($config['template_path'] . "navigation.php");
if($action == "home")
{
// Include the navigation
include($config['template_path'] . "user/navigation.php");
// Include profile template
include($config['template_path'] . "user/home.php");
}
else if($action == "account")
{
if(isset($_POST['account']))
{
// If no email we just don't update it.
if($_POST['email'] != "")
{
// Make sure we aren't just submitting the same email.
if($_POST['email'] != $user_data['email'])
{
if(is_email($_POST['email']))
{
update_user($user_data['id'], false, 'email', $_POST['email']);
}
else
{
$error = lang_parse('error_invalid_chars', array(lang('email')));
}
}
}
// New password, Log them out, log them in.
if($_POST['npassword'] != "" && !$error)
{
if($_POST['npassword'] == $_POST['npassworda'])
{
# Check Password Length
$length = length($_POST['npassword'], $config['min_name_length'], $config['max_name_length']);
if($length)
{
if($length == "TOO_LONG")
{
$error = lang('error_password_too_long');
}
else
{
$error = lang('error_password_too_short');
}
}
if(md5($_POST['current']) != $user_data['password'])
{
$error = lang('error_current_pass');
}
// Are there any errors? If not update password.
if(!$error)
{
$password = md5( $_POST['npassword'] );
update_user($user_data['id'], false, 'password', $password);
}
}
else
{
$error = lang('error_password_match');
}
}
if(!$error)
{
$success = lang('success_update_account');
}
}
// Include the navigation
include($config['template_path'] . "user/navigation.php");
// Include profile template
include($config['template_path'] . "user/account.php");
}
else if($action == "avatar")
{
// Trying to submit an avatar
if(isset($_POST['avatar']))
{
switch($config['avatar_use'])
{
case "username": $status = avatar_upload($user_data['username'], $_FILES); break;
case "email": $status = avatar_upload($user_data['email'], $_FILES); break;
case "id": $status = avatar_upload($user_data['id'], $_FILES); break;
default: $status = avatar_upload($user_data['username'], $_FILES); break;
}
switch($status)
{
case "NO_FILE":
$error = lang('error_no_file');
break;
case "NOT_IMAGE":
$error = lang('error_filetype');
break;
case "TOO_LARGE":
$error = lang_parse('error_file_size', array($config['avatar_max_size']));
break;
case "WRONG_DIMENSIONS":
$error = lang_parse('error_file_wxh', array($config['avatar_max_width'], $config['avatar_max_height']));
break;
case "done":
// Update that the user now has an avatar
update_user($user_data['id'], false, 'avatar', 1);
// Send em back!
print_out(lang('success_update_avatar'), lang('redirecting_back'), $config['url_path'] . "/users.php?a=avatar");
break;
}
}
// Do they have one?
if($user_data['avatar'])
{
// Set current avatar link
$current_avatar_link = get_avatar($user_data['id']);
}
// Include the navigation
include($config['template_path'] . "user/navigation.php");
// Include profile template
include($config['template_path'] . "user/avatar.php");
}
else if($action == "profile")
{
if(isset($_POST['profile']))
{
foreach($_POST as $key => $data)
{
$data = trim($data);
// Check the key
if(!alpha($key, 'alpha-underscore'))
{
$errors[$key] = lang_parse('error_invalid_chars', array(lang('key_c')));
}
if(!$errors)
{
if($key == "interests" || $key == "location")
{
$data = strip_tags($data);
}
if($data != $user_data[$key])
{
// Check what the key is for certain checks
if($key == "interests" || $key == "location")
{
// Check the data, output error into errors array if there was an error.
if(alpha($data, 'alpha-extra') || $data == "")
{
update_user($user_data['id'], false, $key, $data);
}
else
{
$errors[$key] = lang_parse('error_invalid_chars', array(lang($key)));
}
}
else if($key == "msn")
{
// Check the data, output error into errors array if there was an error.
if(alpha($data, 'email') || $data == "")
{
update_user($user_data['id'], false, $key, $data);
}
else
{
$errors[$key] = lang('error_msn_handle');
}
}
else if($key == "aim")
{
// Check the data, output error into errors array if there was an error.
if(alpha($data, 'alpha-spacers') || $data == "")
{
update_user($user_data['id'], false, $key, $data);
}
else
{
$errors[$key] = lang_parse('error_invalid_chars', array(lang($key)));
}
}
else if($key == "first_name" || $key == "last_name")
{
// Check the data, output error into errors array if there was an error.
if(alpha($data, 'alpha-space') || $data == "")
{
update_user($user_data['id'], false, $key, $data);
}
else
{
$errors[$key] = lang_parse('error_invalid_chars', array(lang($key)));
}
}
load_hook('user_profile_post');
}
}
}
if(!$error && !$errors)
{
$success = lang('success_update_profile');
// Get new details
unset($_POST); $user_data = user_data($_SESSION['user_id']);
}
}
// Include the navigation
include($config['template_path'] . "user/navigation.php");
// Include profile template
include($config['template_path'] . "user/profile.php");
}
else if($action == "signature")
{
// Include the navigation
include($config['template_path'] . "user/navigation.php");
// Include profile template
include($config['template_path'] . "user/signature.php");
}
else if($action == "view")
{
if(isset($_GET['id']))
{
if(alpha($_GET['id'], 'numeric'))
{
$viewing = user_data($_GET['id']);
}
else
{
print_out(lang_parse('error_invalid_given'), array(lang('id')));
}
}
else
{
print_out(lang_parse('error_no_given'), array(lang('id')));
}
// Include profile template
include($config['template_path'] . "user/view.php");
}
include($config['template_path'] . "footer.php");
?>