forked from elkarte/Elkarte
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Members.subs.php
2456 lines (2167 loc) · 70.6 KB
/
Members.subs.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
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This file contains some useful functions for members and membergroups.
*
* @name ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
*
* This software is a derived product, based on:
*
* Simple Machines Forum (SMF)
* copyright: 2011 Simple Machines (http://www.simplemachines.org)
* license: BSD, See included LICENSE.TXT for terms and conditions.
*
* @version 1.0 Beta 2
*
*/
if (!defined('ELK'))
die('No access...');
/**
* Delete one or more members.
*
* What it does:
* - Requires profile_remove_own or profile_remove_any permission for
* respectively removing your own account or any account.
* - Non-admins cannot delete admins.
*
* The function:
* - changes author of messages, topics and polls to guest authors.
* - removes all log entries concerning the deleted members, except the
* error logs, ban logs and moderation logs.
* - removes these members' personal messages (only the inbox)
* - rmoves avatars, ban entries, theme settings, moderator positions, poll votes,
* drafts, likes, mentions, notifications
* - removes custom field data associated with them
* - updates member statistics afterwards.
*
* @package Members
* @param int[]|int $users
* @param bool $check_not_admin = false
*/
function deleteMembers($users, $check_not_admin = false)
{
global $modSettings, $user_info;
$db = database();
// Try give us a while to sort this out...
@set_time_limit(600);
// Try to get some more memory.
setMemoryLimit('128M');
// If it's not an array, make it so!
if (!is_array($users))
$users = array($users);
else
$users = array_unique($users);
// Make sure there's no void user in here.
$users = array_diff($users, array(0));
// How many are they deleting?
if (empty($users))
return;
elseif (count($users) == 1)
{
list ($user) = $users;
if ($user == $user_info['id'])
isAllowedTo('profile_remove_own');
else
isAllowedTo('profile_remove_any');
}
else
{
foreach ($users as $k => $v)
$users[$k] = (int) $v;
// Deleting more than one? You can't have more than one account...
isAllowedTo('profile_remove_any');
}
// Get their names for logging purposes.
$request = $db->query('', '
SELECT id_member, member_name, email_address, CASE WHEN id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0 THEN 1 ELSE 0 END AS is_admin
FROM {db_prefix}members
WHERE id_member IN ({array_int:user_list})
LIMIT ' . count($users),
array(
'user_list' => $users,
'admin_group' => 1,
)
);
$admins = array();
$emails = array();
$user_log_details = array();
while ($row = $db->fetch_assoc($request))
{
if ($row['is_admin'])
$admins[] = $row['id_member'];
$user_log_details[$row['id_member']] = array($row['id_member'], $row['member_name']);
$emails[] = $row['email_address'];
}
$db->free_result($request);
if (empty($user_log_details))
return;
// Make sure they aren't trying to delete administrators if they aren't one. But don't bother checking if it's just themself.
if (!empty($admins) && ($check_not_admin || (!allowedTo('admin_forum') && (count($users) != 1 || $users[0] != $user_info['id']))))
{
$users = array_diff($users, $admins);
foreach ($admins as $id)
unset($user_log_details[$id]);
}
// No one left?
if (empty($users))
return;
// Log the action - regardless of who is deleting it.
$log_changes = array();
foreach ($user_log_details as $user)
{
$log_changes[] = array(
'action' => 'delete_member',
'log_type' => 'admin',
'extra' => array(
'member' => $user[0],
'name' => $user[1],
'member_acted' => $user_info['name'],
),
);
// Remove any cached data if enabled.
if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
cache_put_data('user_settings-' . $user[0], null, 60);
}
// Make these peoples' posts guest posts.
$db->query('', '
UPDATE {db_prefix}messages
SET id_member = {int:guest_id}' . (!empty($modSettings['deleteMembersRemovesEmail']) ? ',
poster_email = {string:blank_email}' : '') . '
WHERE id_member IN ({array_int:users})',
array(
'guest_id' => 0,
'blank_email' => '',
'users' => $users,
)
);
$db->query('', '
UPDATE {db_prefix}polls
SET id_member = {int:guest_id}
WHERE id_member IN ({array_int:users})',
array(
'guest_id' => 0,
'users' => $users,
)
);
// Make these peoples' posts guest first posts and last posts.
$db->query('', '
UPDATE {db_prefix}topics
SET id_member_started = {int:guest_id}
WHERE id_member_started IN ({array_int:users})',
array(
'guest_id' => 0,
'users' => $users,
)
);
$db->query('', '
UPDATE {db_prefix}topics
SET id_member_updated = {int:guest_id}
WHERE id_member_updated IN ({array_int:users})',
array(
'guest_id' => 0,
'users' => $users,
)
);
$db->query('', '
UPDATE {db_prefix}log_actions
SET id_member = {int:guest_id}
WHERE id_member IN ({array_int:users})',
array(
'guest_id' => 0,
'users' => $users,
)
);
$db->query('', '
UPDATE {db_prefix}log_banned
SET id_member = {int:guest_id}
WHERE id_member IN ({array_int:users})',
array(
'guest_id' => 0,
'users' => $users,
)
);
$db->query('', '
UPDATE {db_prefix}log_errors
SET id_member = {int:guest_id}
WHERE id_member IN ({array_int:users})',
array(
'guest_id' => 0,
'users' => $users,
)
);
// Delete the member.
$db->query('', '
DELETE FROM {db_prefix}members
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// Delete any drafts...
$db->query('', '
DELETE FROM {db_prefix}user_drafts
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// Delete any likes...
$db->query('', '
DELETE FROM {db_prefix}message_likes
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// Delete any custom field data...
$db->query('', '
DELETE FROM {db_prefix}custom_fields_data
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// Delete any post by email keys...
$db->query('', '
DELETE FROM {db_prefix}postby_emails
WHERE email_to IN ({array_string:emails})',
array(
'emails' => $emails,
)
);
// Delete the logs...
$db->query('', '
DELETE FROM {db_prefix}log_actions
WHERE id_log = {int:log_type}
AND id_member IN ({array_int:users})',
array(
'log_type' => 2,
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}log_boards
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}log_comments
WHERE id_recipient IN ({array_int:users})
AND comment_type = {string:warntpl}',
array(
'users' => $users,
'warntpl' => 'warntpl',
)
);
$db->query('', '
DELETE FROM {db_prefix}log_group_requests
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}log_karma
WHERE id_target IN ({array_int:users})
OR id_executor IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}log_mark_read
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}log_notify
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}log_online
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}log_subscribed
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}log_topics
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}collapsed_categories
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// Make their votes appear as guest votes - at least it keeps the totals right.
// @todo Consider adding back in cookie protection.
$db->query('', '
UPDATE {db_prefix}log_polls
SET id_member = {int:guest_id}
WHERE id_member IN ({array_int:users})',
array(
'guest_id' => 0,
'users' => $users,
)
);
// Remove the mentions
$db->query('', '
DELETE FROM {db_prefix}log_mentions
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// Delete personal messages.
require_once(SUBSDIR . '/PersonalMessage.subs.php');
deleteMessages(null, null, $users);
$db->query('', '
UPDATE {db_prefix}personal_messages
SET id_member_from = {int:guest_id}
WHERE id_member_from IN ({array_int:users})',
array(
'guest_id' => 0,
'users' => $users,
)
);
// They no longer exist, so we don't know who it was sent to.
$db->query('', '
DELETE FROM {db_prefix}pm_recipients
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// Delete avatar.
require_once(SUBSDIR . '/ManageAttachments.subs.php');
removeAttachments(array('id_member' => $users));
// It's over, no more moderation for you.
$db->query('', '
DELETE FROM {db_prefix}moderators
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
$db->query('', '
DELETE FROM {db_prefix}group_moderators
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// If you don't exist we can't ban you.
$db->query('', '
DELETE FROM {db_prefix}ban_items
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// Remove individual theme settings.
$db->query('', '
DELETE FROM {db_prefix}themes
WHERE id_member IN ({array_int:users})',
array(
'users' => $users,
)
);
// These users are nobody's buddy nomore.
$request = $db->query('', '
SELECT id_member, pm_ignore_list, buddy_list
FROM {db_prefix}members
WHERE FIND_IN_SET({raw:pm_ignore_list}, pm_ignore_list) != 0 OR FIND_IN_SET({raw:buddy_list}, buddy_list) != 0',
array(
'pm_ignore_list' => implode(', pm_ignore_list) != 0 OR FIND_IN_SET(', $users),
'buddy_list' => implode(', buddy_list) != 0 OR FIND_IN_SET(', $users),
)
);
while ($row = $db->fetch_assoc($request))
updateMemberData($row['id_member'], array(
'pm_ignore_list' => implode(',', array_diff(explode(',', $row['pm_ignore_list']), $users)),
'buddy_list' => implode(',', array_diff(explode(',', $row['buddy_list']), $users))
));
$db->free_result($request);
// Make sure no member's birthday is still sticking in the calendar...
updateSettings(array(
'calendar_updated' => time(),
));
// Integration rocks!
call_integration_hook('integrate_delete_members', array($users));
updateMemberStats();
logActions($log_changes);
}
/**
* Registers a member to the forum.
*
* What it does:
* - Allows two types of interface: 'guest' and 'admin'. The first
* - includes hammering protection, the latter can perform the registration silently.
* - The strings used in the options array are assumed to be escaped.
* - Allows to perform several checks on the input, e.g. reserved names.
* - The function will adjust member statistics.
* - If an error is detected will fatal error on all errors unless return_errors is true.
*
* @package Members
* @uses Auth.subs.php
* @uses Mail.subs.php
* @param mixed[] $regOptions
* @param string $error_context
* @return integer the ID of the newly created member
*/
function registerMember(&$regOptions, $error_context = 'register')
{
global $scripturl, $txt, $modSettings, $user_info;
$db = database();
loadLanguage('Login');
// We'll need some external functions.
require_once(SUBSDIR . '/Auth.subs.php');
require_once(SUBSDIR . '/Mail.subs.php');
// Put any errors in here.
$reg_errors = Error_Context::context($error_context, 0);
// Registration from the admin center, let them sweat a little more.
if ($regOptions['interface'] == 'admin')
{
is_not_guest();
isAllowedTo('moderate_forum');
}
// You're new around, aren't you? or else!
elseif ($regOptions['interface'] == 'guest')
{
// You cannot register twice...
if (empty($user_info['is_guest']))
redirectexit();
// Make sure they didn't just register with this session.
if (!empty($_SESSION['just_registered']) && empty($modSettings['disableRegisterCheck']))
fatal_lang_error('register_only_once', false);
}
// What method of authorization are we going to use?
if (empty($regOptions['auth_method']) || !in_array($regOptions['auth_method'], array('password', 'openid')))
{
if (!empty($regOptions['openid']))
$regOptions['auth_method'] = 'openid';
else
$regOptions['auth_method'] = 'password';
}
// Spaces and other odd characters are evil...
$regOptions['username'] = trim(preg_replace('~[\t\n\r \x0B\0\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}]+~u', ' ', $regOptions['username']));
// Valid emails only
require_once(SUBSDIR . '/DataValidator.class.php');
if (!Data_Validator::is_valid($regOptions, array('email' => 'valid_email|required|max_length[255]'), array('email' => 'trim')))
$reg_errors->addError('bad_email');
validateUsername(0, $regOptions['username'], $error_context, !empty($regOptions['check_reserved_name']));
// Generate a validation code if it's supposed to be emailed.
$validation_code = '';
if ($regOptions['require'] == 'activation')
$validation_code = generateValidationCode();
// If you haven't put in a password generate one.
if ($regOptions['interface'] == 'admin' && $regOptions['password'] == '' && $regOptions['auth_method'] == 'password')
{
mt_srand(time() + 1277);
$regOptions['password'] = generateValidationCode();
$regOptions['password_check'] = $regOptions['password'];
}
// Does the first password match the second?
elseif ($regOptions['password'] != $regOptions['password_check'] && $regOptions['auth_method'] == 'password')
$reg_errors->addError('passwords_dont_match');
// That's kind of easy to guess...
if ($regOptions['password'] == '')
{
if ($regOptions['auth_method'] == 'password')
$reg_errors->addError('no_password');
else
$regOptions['password'] = sha1(mt_rand());
}
// Now perform hard password validation as required.
if (!empty($regOptions['check_password_strength']) && $regOptions['password'] != '')
{
$passwordError = validatePassword($regOptions['password'], $regOptions['username'], array($regOptions['email']));
// Password isn't legal?
if ($passwordError != null)
$reg_errors->addError('profile_error_password_' . $passwordError);
}
// You may not be allowed to register this email.
if (!empty($regOptions['check_email_ban']))
isBannedEmail($regOptions['email'], 'cannot_register', $txt['ban_register_prohibited']);
// Check if the email address is in use.
$request = $db->query('', '
SELECT id_member
FROM {db_prefix}members
WHERE email_address = {string:email_address}
OR email_address = {string:username}
LIMIT 1',
array(
'email_address' => $regOptions['email'],
'username' => $regOptions['username'],
)
);
if ($db->num_rows($request) != 0)
$reg_errors->addError(array('email_in_use', array(htmlspecialchars($regOptions['email'], ENT_COMPAT, 'UTF-8'))));
$db->free_result($request);
// Perhaps someone else wants to check this user
call_integration_hook('integrate_register_check', array(&$regOptions, &$reg_errors));
// If there's any errors left return them at once!
if ($reg_errors->hasErrors())
return false;
$reservedVars = array(
'actual_theme_url',
'actual_images_url',
'base_theme_dir',
'base_theme_url',
'default_images_url',
'default_theme_dir',
'default_theme_url',
'default_template',
'images_url',
'number_recent_posts',
'smiley_sets_default',
'theme_dir',
'theme_id',
'theme_layers',
'theme_templates',
'theme_url',
);
// Can't change reserved vars.
if (isset($regOptions['theme_vars']) && count(array_intersect(array_keys($regOptions['theme_vars']), $reservedVars)) != 0)
fatal_lang_error('no_theme');
// New password hash
require_once(SUBSDIR . '/Auth.subs.php');
// Some of these might be overwritten. (the lower ones that are in the arrays below.)
$regOptions['register_vars'] = array(
'member_name' => $regOptions['username'],
'email_address' => $regOptions['email'],
'passwd' => validateLoginPassword($regOptions['password'], '', $regOptions['username'], true),
'password_salt' => substr(md5(mt_rand()), 0, 4) ,
'posts' => 0,
'date_registered' => time(),
'member_ip' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $regOptions['ip'],
'member_ip2' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $regOptions['ip2'],
'validation_code' => $validation_code,
'real_name' => $regOptions['username'],
'personal_text' => $modSettings['default_personal_text'],
'pm_email_notify' => 1,
'id_theme' => 0,
'id_post_group' => 4,
'lngfile' => '',
'buddy_list' => '',
'pm_ignore_list' => '',
'message_labels' => '',
'website_title' => '',
'website_url' => '',
'location' => '',
'time_format' => '',
'signature' => '',
'avatar' => '',
'usertitle' => '',
'secret_question' => '',
'secret_answer' => '',
'additional_groups' => '',
'ignore_boards' => '',
'smiley_set' => '',
'openid_uri' => (!empty($regOptions['openid']) ? $regOptions['openid'] : ''),
);
// Setup the activation status on this new account so it is correct - firstly is it an under age account?
if ($regOptions['require'] == 'coppa')
{
$regOptions['register_vars']['is_activated'] = 5;
// @todo This should be changed. To what should be it be changed??
$regOptions['register_vars']['validation_code'] = '';
}
// Maybe it can be activated right away?
elseif ($regOptions['require'] == 'nothing')
$regOptions['register_vars']['is_activated'] = 1;
// Maybe it must be activated by email?
elseif ($regOptions['require'] == 'activation')
$regOptions['register_vars']['is_activated'] = 0;
// Otherwise it must be awaiting approval!
else
$regOptions['register_vars']['is_activated'] = 3;
if (isset($regOptions['memberGroup']))
{
// Make sure the id_group will be valid, if this is an administator.
$regOptions['register_vars']['id_group'] = $regOptions['memberGroup'] == 1 && !allowedTo('admin_forum') ? 0 : $regOptions['memberGroup'];
// Check if this group is assignable.
$unassignableGroups = array(-1, 3);
$request = $db->query('', '
SELECT id_group
FROM {db_prefix}membergroups
WHERE min_posts != {int:min_posts}' . (allowedTo('admin_forum') ? '' : '
OR group_type = {int:is_protected}'),
array(
'min_posts' => -1,
'is_protected' => 1,
)
);
while ($row = $db->fetch_assoc($request))
$unassignableGroups[] = $row['id_group'];
$db->free_result($request);
if (in_array($regOptions['register_vars']['id_group'], $unassignableGroups))
$regOptions['register_vars']['id_group'] = 0;
}
// Integrate optional member settings to be set.
if (!empty($regOptions['extra_register_vars']))
foreach ($regOptions['extra_register_vars'] as $var => $value)
$regOptions['register_vars'][$var] = $value;
// Integrate optional user theme options to be set.
$theme_vars = array();
if (!empty($regOptions['theme_vars']))
foreach ($regOptions['theme_vars'] as $var => $value)
$theme_vars[$var] = $value;
// Right, now let's prepare for insertion.
$knownInts = array(
'date_registered', 'posts', 'id_group', 'last_login', 'personal_messages', 'unread_messages', 'notifications',
'new_pm', 'pm_prefs', 'gender', 'hide_email', 'show_online', 'pm_email_notify', 'karma_good', 'karma_bad',
'notify_announcements', 'notify_send_body', 'notify_regularity', 'notify_types',
'id_theme', 'is_activated', 'id_msg_last_visit', 'id_post_group', 'total_time_logged_in', 'warning',
);
$knownFloats = array(
'time_offset',
);
// Call an optional function to validate the users' input.
call_integration_hook('integrate_register', array(&$regOptions, &$theme_vars, &$knownInts, &$knownFloats));
$column_names = array();
$values = array();
foreach ($regOptions['register_vars'] as $var => $val)
{
$type = 'string';
if (in_array($var, $knownInts))
$type = 'int';
elseif (in_array($var, $knownFloats))
$type = 'float';
elseif ($var == 'birthdate')
$type = 'date';
$column_names[$var] = $type;
$values[$var] = $val;
}
// Register them into the database.
$db->insert('',
'{db_prefix}members',
$column_names,
$values,
array('id_member')
);
$memberID = $db->insert_id('{db_prefix}members', 'id_member');
// Update the number of members and latest member's info - and pass the name, but remove the 's.
if ($regOptions['register_vars']['is_activated'] == 1)
updateMemberStats($memberID, $regOptions['register_vars']['real_name']);
else
updateMemberStats();
// Theme variables too?
if (!empty($theme_vars))
{
$inserts = array();
foreach ($theme_vars as $var => $val)
$inserts[] = array($memberID, $var, $val);
$db->insert('insert',
'{db_prefix}themes',
array('id_member' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
$inserts,
array('id_member', 'variable')
);
}
// If it's enabled, increase the registrations for today.
trackStats(array('registers' => '+'));
// Administrative registrations are a bit different...
if ($regOptions['interface'] == 'admin')
{
if ($regOptions['require'] == 'activation')
$email_message = 'admin_register_activate';
elseif (!empty($regOptions['send_welcome_email']))
$email_message = 'admin_register_immediate';
if (isset($email_message))
{
$replacements = array(
'REALNAME' => $regOptions['register_vars']['real_name'],
'USERNAME' => $regOptions['username'],
'PASSWORD' => $regOptions['password'],
'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $memberID . ';code=' . $validation_code,
'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $memberID,
'ACTIVATIONCODE' => $validation_code,
);
$emaildata = loadEmailTemplate($email_message, $replacements);
sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
}
}
else
{
// Can post straight away - welcome them to your fantastic community...
if ($regOptions['require'] == 'nothing')
{
if (!empty($regOptions['send_welcome_email']))
{
$replacements = array(
'REALNAME' => $regOptions['register_vars']['real_name'],
'USERNAME' => $regOptions['username'],
'PASSWORD' => $regOptions['password'],
'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
'OPENID' => !empty($regOptions['openid']) ? $regOptions['openid'] : '',
);
$emaildata = loadEmailTemplate('register_' . ($regOptions['auth_method'] == 'openid' ? 'openid_' : '') . 'immediate', $replacements);
sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
}
// Send admin their notification.
require_once(SUBSDIR . '/Notification.subs.php');
sendAdminNotifications('standard', $memberID, $regOptions['username']);
}
// Need to activate their account - or fall under COPPA.
elseif ($regOptions['require'] == 'activation' || $regOptions['require'] == 'coppa')
{
$replacements = array(
'REALNAME' => $regOptions['register_vars']['real_name'],
'USERNAME' => $regOptions['username'],
'PASSWORD' => $regOptions['password'],
'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
'OPENID' => !empty($regOptions['openid']) ? $regOptions['openid'] : '',
);
if ($regOptions['require'] == 'activation')
$replacements += array(
'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $memberID . ';code=' . $validation_code,
'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $memberID,
'ACTIVATIONCODE' => $validation_code,
);
else
$replacements += array(
'COPPALINK' => $scripturl . '?action=coppa;u=' . $memberID,
);
$emaildata = loadEmailTemplate('register_' . ($regOptions['auth_method'] == 'openid' ? 'openid_' : '') . ($regOptions['require'] == 'activation' ? 'activate' : 'coppa'), $replacements);
sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
}
// Must be awaiting approval.
else
{
$replacements = array(
'REALNAME' => $regOptions['register_vars']['real_name'],
'USERNAME' => $regOptions['username'],
'PASSWORD' => $regOptions['password'],
'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
'OPENID' => !empty($regOptions['openid']) ? $regOptions['openid'] : '',
);
$emaildata = loadEmailTemplate('register_' . ($regOptions['auth_method'] == 'openid' ? 'openid_' : '') . 'pending', $replacements);
sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
// Admin gets informed here...
require_once(SUBSDIR . '/Notification.subs.php');
sendAdminNotifications('approval', $memberID, $regOptions['username']);
}
// Okay, they're for sure registered... make sure the session is aware of this for security. (Just married :P!)
$_SESSION['just_registered'] = 1;
}
// If they are for sure registered, let other people to know about it
call_integration_hook('integrate_register_after', array($regOptions, $memberID));
return $memberID;
}
/**
* Check if a name is in the reserved words list. (name, current member id, name/username?.)
*
* - checks if name is a reserved name or username.
* - if is_name is false, the name is assumed to be a username.
* - the id_member variable is used to ignore duplicate matches with the current member.
*
* @package Members
* @param string $name
* @param int $current_ID_MEMBER
* @param bool $is_name
* @param bool $fatal
*/
function isReservedName($name, $current_ID_MEMBER = 0, $is_name = true, $fatal = true)
{
global $modSettings;
$db = database();
$name = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'replaceEntities__callback', $name);
$checkName = Util::strtolower($name);
// Administrators are never restricted ;).
if (!allowedTo('moderate_forum') && ((!empty($modSettings['reserveName']) && $is_name) || !empty($modSettings['reserveUser']) && !$is_name))
{
$reservedNames = explode("\n", $modSettings['reserveNames']);
// Case sensitive check?
$checkMe = empty($modSettings['reserveCase']) ? $checkName : $name;
// Check each name in the list...
foreach ($reservedNames as $reserved)
{
if ($reserved == '')
continue;
// The admin might've used entities too, level the playing field.
$reservedCheck = preg_replace('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'replaceEntities__callback', $reserved);
// Case sensitive name?
if (empty($modSettings['reserveCase']))
$reservedCheck = Util::strtolower($reservedCheck);
// If it's not just entire word, check for it in there somewhere...
if ($checkMe == $reservedCheck || (Util::strpos($checkMe, $reservedCheck) !== false && empty($modSettings['reserveWord'])))
if ($fatal)
fatal_lang_error('username_reserved', 'password', array($reserved));
else
return true;
}
$censor_name = $name;
if (censorText($censor_name) != $name)
if ($fatal)
fatal_lang_error('name_censored', 'password', array($name));
else
return true;
}
// Characters we just shouldn't allow, regardless.
foreach (array('*') as $char)
if (strpos($checkName, $char) !== false)
if ($fatal)
fatal_lang_error('username_reserved', 'password', array($char));
else
return true;
// Get rid of any SQL parts of the reserved name...
$checkName = strtr($name, array('_' => '\\_', '%' => '\\%'));
// Make sure they don't want someone else's name.
$request = $db->query('', '
SELECT id_member
FROM {db_prefix}members
WHERE ' . (empty($current_ID_MEMBER) ? '' : 'id_member != {int:current_member}
AND ') . '({raw:real_name} LIKE {string:check_name} OR {raw:member_name} LIKE {string:check_name})
LIMIT 1',
array(
'real_name' => defined('DB_CASE_SENSITIVE') ? 'LOWER(real_name)' : 'real_name',
'member_name' => defined('DB_CASE_SENSITIVE') ? 'LOWER(member_name)' : 'member_name',
'current_member' => $current_ID_MEMBER,
'check_name' => $checkName,
)
);
if ($db->num_rows($request) > 0)
{
$db->free_result($request);
return true;
}
// Does name case insensitive match a member group name?
$request = $db->query('', '
SELECT id_group
FROM {db_prefix}membergroups
WHERE {raw:group_name} LIKE {string:check_name}
LIMIT 1',
array(
'group_name' => defined('DB_CASE_SENSITIVE') ? 'LOWER(group_name)' : 'group_name',
'check_name' => $checkName,
)
);
if ($db->num_rows($request) > 0)
{
$db->free_result($request);
return true;
}
// Okay, they passed.
return false;
}
/**
* Retrieves a list of membergroups that are allowed to do the given
* permission. (on the given board)
*
* - If board_id is not null, a board permission is assumed.
* - The function takes different permission settings into account.
*
* @package Members
* @param string $permission
* @param integer|null $board_id = null
* @return an array containing an array for the allowed membergroup ID's
* and an array for the denied membergroup ID's.
*/
function groupsAllowedTo($permission, $board_id = null)
{
global $board_info;
$db = database();
// Admins are allowed to do anything.
$member_groups = array(
'allowed' => array(1),