PageRenderTime 252ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/forum/Sources/Subs-Members.php

https://github.com/leftnode/nooges.com
PHP | 1389 lines | 1017 code | 160 blank | 212 comment | 186 complexity | c8aa5f31745649d1712fa884f0d8a374 MD5 | raw file
  1. <?php
  2. /**********************************************************************************
  3. * Subs-Members.php *
  4. ***********************************************************************************
  5. * SMF: Simple Machines Forum *
  6. * Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com) *
  7. * =============================================================================== *
  8. * Software Version: SMF 2.0 RC2 *
  9. * Software by: Simple Machines (http://www.simplemachines.org) *
  10. * Copyright 2006-2009 by: Simple Machines LLC (http://www.simplemachines.org) *
  11. * 2001-2006 by: Lewis Media (http://www.lewismedia.com) *
  12. * Support, News, Updates at: http://www.simplemachines.org *
  13. ***********************************************************************************
  14. * This program is free software; you may redistribute it and/or modify it under *
  15. * the terms of the provided license as published by Simple Machines LLC. *
  16. * *
  17. * This program is distributed in the hope that it is and will be useful, but *
  18. * WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY *
  19. * or FITNESS FOR A PARTICULAR PURPOSE. *
  20. * *
  21. * See the "license.txt" file for details of the Simple Machines license. *
  22. * The latest version can always be found at http://www.simplemachines.org. *
  23. **********************************************************************************/
  24. if (!defined('SMF'))
  25. die('Hacking attempt...');
  26. /* This file contains some useful functions for members and membergroups.
  27. void deleteMembers(array $users, bool check_not_admin = false)
  28. - delete of one or more members.
  29. - requires profile_remove_own or profile_remove_any permission for
  30. respectively removing your own account or any account.
  31. - non-admins cannot delete admins.
  32. - changes author of messages, topics and polls to guest authors.
  33. - removes all log entries concerning the deleted members, except the
  34. error logs, ban logs and moderation logs.
  35. - removes these members' personal messages (only the inbox), avatars,
  36. ban entries, theme settings, moderator positions, poll votes, and
  37. karma votes.
  38. - updates member statistics afterwards.
  39. int registerMember(array options, bool return_errors)
  40. - registers a member to the forum.
  41. - returns the ID of the newly created member.
  42. - allows two types of interface: 'guest' and 'admin'. The first
  43. includes hammering protection, the latter can perform the
  44. registration silently.
  45. - the strings used in the options array are assumed to be escaped.
  46. - allows to perform several checks on the input, e.g. reserved names.
  47. - adjusts member statistics.
  48. - if an error is detected will fatal error on all errors unless return_errors is true.
  49. bool isReservedName(string name, int id_member = 0, bool is_name = true, bool fatal = true)
  50. - checks if name is a reserved name or username.
  51. - if is_name is false, the name is assumed to be a username.
  52. - the id_member variable is used to ignore duplicate matches with the
  53. current member.
  54. array groupsAllowedTo(string permission, int board_id = null)
  55. - retrieves a list of membergroups that are allowed to do the given
  56. permission.
  57. - if board_id is not null, a board permission is assumed.
  58. - takes different permission settings into account.
  59. - returns an array containing an array for the allowed membergroup ID's
  60. and an array for the denied membergroup ID's.
  61. array membersAllowedTo(string permission, int board_id = null)
  62. - retrieves a list of members that are allowed to do the given
  63. permission.
  64. - if board_id is not null, a board permission is assumed.
  65. - takes different permission settings into account.
  66. - takes possible moderators (on board 'board_id') into account.
  67. - returns an array containing member ID's.
  68. int reattributePosts(int id_member, string email = false, string membername = false, bool add_to_post_count = false)
  69. - reattribute guest posts to a specified member.
  70. - does not check for any permissions.
  71. - returns the number of successful reattributed posts.
  72. - if add_to_post_count is set, the member's post count is increased.
  73. void BuddyListToggle()
  74. - add a member to your buddy list or remove it.
  75. - requires profile_identity_own permission.
  76. - called by ?action=buddy;u=x;session_id=y.
  77. - redirects to ?action=profile;u=x.
  78. void populateDuplicateMembers(&array members)
  79. // !!!
  80. */
  81. // Delete a group of/single member.
  82. function deleteMembers($users, $check_not_admin = false)
  83. {
  84. global $sourcedir, $modSettings, $user_info, $smcFunc;
  85. // Try give us a while to sort this out...
  86. @set_time_limit(600);
  87. // Try to get some more memory.
  88. if (@ini_get('memory_limit') < 128)
  89. @ini_set('memory_limit', '128M');
  90. // If it's not an array, make it so!
  91. if (!is_array($users))
  92. $users = array($users);
  93. else
  94. $users = array_unique($users);
  95. // Make sure there's no void user in here.
  96. $users = array_diff($users, array(0));
  97. // How many are they deleting?
  98. if (empty($users))
  99. return;
  100. elseif (count($users) == 1)
  101. {
  102. list ($user) = $users;
  103. if ($user == $user_info['id'])
  104. isAllowedTo('profile_remove_own');
  105. else
  106. isAllowedTo('profile_remove_any');
  107. }
  108. else
  109. {
  110. foreach ($users as $k => $v)
  111. $users[$k] = (int) $v;
  112. // Deleting more than one? You can't have more than one account...
  113. isAllowedTo('profile_remove_any');
  114. }
  115. // Get their names for logging purposes.
  116. $request = $smcFunc['db_query']('', '
  117. SELECT id_member, member_name, 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
  118. FROM {db_prefix}members
  119. WHERE id_member IN ({array_int:user_list})
  120. LIMIT ' . count($users),
  121. array(
  122. 'user_list' => $users,
  123. 'admin_group' => 1,
  124. )
  125. );
  126. $admins = array();
  127. $user_log_details = array();
  128. while ($row = $smcFunc['db_fetch_assoc']($request))
  129. {
  130. if ($row['is_admin'])
  131. $admins[] = $row['id_member'];
  132. $user_log_details[$row['id_member']] = array($row['id_member'], $row['member_name']);
  133. }
  134. $smcFunc['db_free_result']($request);
  135. if (empty($user_log_details))
  136. return;
  137. // Make sure they aren't trying to delete administrators if they aren't one. But don't bother checking if it's just themself.
  138. if (!empty($admins) && ($check_not_admin || (!allowedTo('admin_forum') && (count($users) != 1 || $users[0] != $user_info['id']))))
  139. {
  140. $users = array_diff($users, $admins);
  141. foreach ($admins as $id)
  142. unset($user_log_details[$id]);
  143. }
  144. // No one left?
  145. if (empty($users))
  146. return;
  147. // Log the action - regardless of who is deleting it.
  148. $log_inserts = array();
  149. foreach ($user_log_details as $user)
  150. {
  151. // Integration rocks!
  152. if (isset($modSettings['integrate_delete_member']) && function_exists($modSettings['integrate_delete_member']))
  153. call_user_func($modSettings['integrate_delete_member'], $user[0]);
  154. // Add it to the administration log for future reference.
  155. $log_inserts[] = array(
  156. time(), 3, $user_info['id'], $user_info['ip'], 'delete_member',
  157. 0, 0, 0, serialize(array('member' => $user[0], 'name' => $user[1], 'member_acted' => $user_info['name'])),
  158. );
  159. // Remove any cached data if enabled.
  160. if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
  161. cache_put_data('user_settings-' . $user[0], null, 60);
  162. }
  163. // Do the actual logging...
  164. if (!empty($log_inserts) && !empty($modSettings['modlog_enabled']))
  165. $smcFunc['db_insert']('',
  166. '{db_prefix}log_actions',
  167. array(
  168. 'log_time' => 'int', 'id_log' => 'int', 'id_member' => 'int', 'ip' => 'string-16', 'action' => 'string',
  169. 'id_board' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'extra' => 'string-65534',
  170. ),
  171. $log_inserts,
  172. array('id_action')
  173. );
  174. // Make these peoples' posts guest posts.
  175. $smcFunc['db_query']('', '
  176. UPDATE {db_prefix}messages
  177. SET id_member = {int:guest_id}, poster_email = {string:blank_email}
  178. WHERE id_member IN ({array_int:users})',
  179. array(
  180. 'guest_id' => 0,
  181. 'blank_email' => '',
  182. 'users' => $users,
  183. )
  184. );
  185. $smcFunc['db_query']('', '
  186. UPDATE {db_prefix}polls
  187. SET id_member = {int:guest_id}
  188. WHERE id_member IN ({array_int:users})',
  189. array(
  190. 'guest_id' => 0,
  191. 'users' => $users,
  192. )
  193. );
  194. // Make these peoples' posts guest first posts and last posts.
  195. $smcFunc['db_query']('', '
  196. UPDATE {db_prefix}topics
  197. SET id_member_started = {int:guest_id}
  198. WHERE id_member_started IN ({array_int:users})',
  199. array(
  200. 'guest_id' => 0,
  201. 'users' => $users,
  202. )
  203. );
  204. $smcFunc['db_query']('', '
  205. UPDATE {db_prefix}topics
  206. SET id_member_updated = {int:guest_id}
  207. WHERE id_member_updated IN ({array_int:users})',
  208. array(
  209. 'guest_id' => 0,
  210. 'users' => $users,
  211. )
  212. );
  213. $smcFunc['db_query']('', '
  214. UPDATE {db_prefix}log_actions
  215. SET id_member = {int:guest_id}
  216. WHERE id_member IN ({array_int:users})',
  217. array(
  218. 'guest_id' => 0,
  219. 'users' => $users,
  220. )
  221. );
  222. $smcFunc['db_query']('', '
  223. UPDATE {db_prefix}log_banned
  224. SET id_member = {int:guest_id}
  225. WHERE id_member IN ({array_int:users})',
  226. array(
  227. 'guest_id' => 0,
  228. 'users' => $users,
  229. )
  230. );
  231. $smcFunc['db_query']('', '
  232. UPDATE {db_prefix}log_errors
  233. SET id_member = {int:guest_id}
  234. WHERE id_member IN ({array_int:users})',
  235. array(
  236. 'guest_id' => 0,
  237. 'users' => $users,
  238. )
  239. );
  240. // Delete the member.
  241. $smcFunc['db_query']('', '
  242. DELETE FROM {db_prefix}members
  243. WHERE id_member IN ({array_int:users})',
  244. array(
  245. 'users' => $users,
  246. )
  247. );
  248. // Delete the logs...
  249. $smcFunc['db_query']('', '
  250. DELETE FROM {db_prefix}log_actions
  251. WHERE id_log = {int:log_type}
  252. AND id_member IN ({array_int:users})',
  253. array(
  254. 'log_type' => 2,
  255. 'users' => $users,
  256. )
  257. );
  258. $smcFunc['db_query']('', '
  259. DELETE FROM {db_prefix}log_boards
  260. WHERE id_member IN ({array_int:users})',
  261. array(
  262. 'users' => $users,
  263. )
  264. );
  265. $smcFunc['db_query']('', '
  266. DELETE FROM {db_prefix}log_comments
  267. WHERE id_recipient IN ({array_int:users})
  268. AND comment_type = {string:warntpl}',
  269. array(
  270. 'users' => $users,
  271. 'warntpl' => 'warntpl',
  272. )
  273. );
  274. $smcFunc['db_query']('', '
  275. DELETE FROM {db_prefix}log_group_requests
  276. WHERE id_member IN ({array_int:users})',
  277. array(
  278. 'users' => $users,
  279. )
  280. );
  281. $smcFunc['db_query']('', '
  282. DELETE FROM {db_prefix}log_karma
  283. WHERE id_target IN ({array_int:users})
  284. OR id_executor IN ({array_int:users})',
  285. array(
  286. 'users' => $users,
  287. )
  288. );
  289. $smcFunc['db_query']('', '
  290. DELETE FROM {db_prefix}log_mark_read
  291. WHERE id_member IN ({array_int:users})',
  292. array(
  293. 'users' => $users,
  294. )
  295. );
  296. $smcFunc['db_query']('', '
  297. DELETE FROM {db_prefix}log_notify
  298. WHERE id_member IN ({array_int:users})',
  299. array(
  300. 'users' => $users,
  301. )
  302. );
  303. $smcFunc['db_query']('', '
  304. DELETE FROM {db_prefix}log_online
  305. WHERE id_member IN ({array_int:users})',
  306. array(
  307. 'users' => $users,
  308. )
  309. );
  310. $smcFunc['db_query']('', '
  311. DELETE FROM {db_prefix}log_subscribed
  312. WHERE id_member IN ({array_int:users})',
  313. array(
  314. 'users' => $users,
  315. )
  316. );
  317. $smcFunc['db_query']('', '
  318. DELETE FROM {db_prefix}log_topics
  319. WHERE id_member IN ({array_int:users})',
  320. array(
  321. 'users' => $users,
  322. )
  323. );
  324. $smcFunc['db_query']('', '
  325. DELETE FROM {db_prefix}collapsed_categories
  326. WHERE id_member IN ({array_int:users})',
  327. array(
  328. 'users' => $users,
  329. )
  330. );
  331. // Make their votes appear as guest votes - at least it keeps the totals right.
  332. //!!! Consider adding back in cookie protection.
  333. $smcFunc['db_query']('', '
  334. UPDATE {db_prefix}log_polls
  335. SET id_member = {int:guest_id}
  336. WHERE id_member IN ({array_int:users})',
  337. array(
  338. 'guest_id' => 0,
  339. 'users' => $users,
  340. )
  341. );
  342. // Delete personal messages.
  343. require_once($sourcedir . '/PersonalMessage.php');
  344. deleteMessages(null, null, $users);
  345. $smcFunc['db_query']('', '
  346. UPDATE {db_prefix}personal_messages
  347. SET id_member_from = {int:guest_id}
  348. WHERE id_member_from IN ({array_int:users})',
  349. array(
  350. 'guest_id' => 0,
  351. 'users' => $users,
  352. )
  353. );
  354. // They no longer exist, so we don't know who it was sent to.
  355. $smcFunc['db_query']('', '
  356. DELETE FROM {db_prefix}pm_recipients
  357. WHERE id_member IN ({array_int:users})',
  358. array(
  359. 'users' => $users,
  360. )
  361. );
  362. // Delete avatar.
  363. require_once($sourcedir . '/ManageAttachments.php');
  364. removeAttachments(array('id_member' => $users));
  365. // It's over, no more moderation for you.
  366. $smcFunc['db_query']('', '
  367. DELETE FROM {db_prefix}moderators
  368. WHERE id_member IN ({array_int:users})',
  369. array(
  370. 'users' => $users,
  371. )
  372. );
  373. $smcFunc['db_query']('', '
  374. DELETE FROM {db_prefix}group_moderators
  375. WHERE id_member IN ({array_int:users})',
  376. array(
  377. 'users' => $users,
  378. )
  379. );
  380. // If you don't exist we can't ban you.
  381. $smcFunc['db_query']('', '
  382. DELETE FROM {db_prefix}ban_items
  383. WHERE id_member IN ({array_int:users})',
  384. array(
  385. 'users' => $users,
  386. )
  387. );
  388. // Remove individual theme settings.
  389. $smcFunc['db_query']('', '
  390. DELETE FROM {db_prefix}themes
  391. WHERE id_member IN ({array_int:users})',
  392. array(
  393. 'users' => $users,
  394. )
  395. );
  396. // These users are nobody's buddy nomore.
  397. $request = $smcFunc['db_query']('', '
  398. SELECT id_member, pm_ignore_list, buddy_list
  399. FROM {db_prefix}members
  400. WHERE FIND_IN_SET({raw:pm_ignore_list}, pm_ignore_list) OR FIND_IN_SET({raw:buddy_list}, buddy_list)',
  401. array(
  402. 'pm_ignore_list' => implode(', pm_ignore_list) OR FIND_IN_SET(', $users),
  403. 'buddy_list' => implode(', buddy_list) OR FIND_IN_SET(', $users),
  404. )
  405. );
  406. while ($row = $smcFunc['db_fetch_assoc']($request))
  407. $smcFunc['db_query']('', '
  408. UPDATE {db_prefix}members
  409. SET
  410. pm_ignore_list = {string:pm_ignore_list},
  411. buddy_list = {string:buddy_list}
  412. WHERE id_member = {int:id_member}',
  413. array(
  414. 'id_member' => $row['id_member'],
  415. 'pm_ignore_list' => implode(',', array_diff(explode(',', $row['pm_ignore_list']), $users)),
  416. 'buddy_list' => implode(',', array_diff(explode(',', $row['buddy_list']), $users)),
  417. )
  418. );
  419. $smcFunc['db_free_result']($request);
  420. // Make sure no member's birthday is still sticking in the calendar...
  421. updateSettings(array(
  422. 'calendar_updated' => time(),
  423. ));
  424. updateStats('member');
  425. }
  426. function registerMember(&$regOptions, $return_errors = false)
  427. {
  428. global $scripturl, $txt, $modSettings, $context, $sourcedir;
  429. global $user_info, $options, $settings, $smcFunc;
  430. loadLanguage('Login');
  431. // We'll need some external functions.
  432. require_once($sourcedir . '/Subs-Auth.php');
  433. require_once($sourcedir . '/Subs-Post.php');
  434. // Put any errors in here.
  435. $reg_errors = array();
  436. // Registration from the admin center, let them sweat a little more.
  437. if ($regOptions['interface'] == 'admin')
  438. {
  439. is_not_guest();
  440. isAllowedTo('moderate_forum');
  441. }
  442. // If you're an admin, you're special ;).
  443. elseif ($regOptions['interface'] == 'guest')
  444. {
  445. // You cannot register twice...
  446. if (empty($user_info['is_guest']))
  447. redirectexit();
  448. // Make sure they didn't just register with this session.
  449. if (!empty($_SESSION['just_registered']) && empty($modSettings['disableRegisterCheck']))
  450. fatal_lang_error('register_only_once', false);
  451. }
  452. // What method of authorizaton are we going to use?
  453. if (empty($regOptions['auth_method']) || !in_array($regOptions['auth_method'], array('password', 'openid')))
  454. {
  455. if (!empty($regOptions['openid']))
  456. $regOptions['auth_method'] = 'openid';
  457. else
  458. $regOptions['auth_method'] = 'password';
  459. }
  460. // No name?! How can you register with no name?
  461. if (empty($regOptions['username']))
  462. $reg_errors[] = array('lang', 'need_username');
  463. // Spaces and other odd characters are evil...
  464. $regOptions['username'] = preg_replace('~[\t\n\r\x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $regOptions['username']);
  465. // Don't use too long a name.
  466. if ($smcFunc['strlen']($regOptions['username']) > 25)
  467. $reg_errors[] = array('lang', 'error_long_name');
  468. // Only these characters are permitted.
  469. if (preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $regOptions['username'])) != 0 || $regOptions['username'] == '_' || $regOptions['username'] == '|' || strpos($regOptions['username'], '[code') !== false || strpos($regOptions['username'], '[/code') !== false)
  470. $reg_errors[] = array('lang', 'error_invalid_characters_username');
  471. if ($smcFunc['strtolower']($regOptions['username']) === $smcFunc['strtolower']($txt['guest_title']))
  472. $reg_errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
  473. // !!! Separate the sprintf?
  474. if (empty($regOptions['email']) || preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $regOptions['email']) === 0 || strlen($regOptions['email']) > 255)
  475. $reg_errors[] = array('done', sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($regOptions['username'])));
  476. if (!empty($regOptions['check_reserved_name']) && isReservedName($regOptions['username'], 0, false))
  477. {
  478. if ($regOptions['password'] == 'chocolate cake')
  479. $reg_errors[] = array('done', 'Sorry, I don\'t take bribes... you\'ll need to come up with a different name.');
  480. $reg_errors[] = array('done', '(' . htmlspecialchars($regOptions['username']) . ') ' . $txt['name_in_use']);
  481. }
  482. // Generate a validation code if it's supposed to be emailed.
  483. $validation_code = '';
  484. if ($regOptions['require'] == 'activation')
  485. $validation_code = generateValidationCode();
  486. // If you haven't put in a password generate one.
  487. if ($regOptions['interface'] == 'admin' && $regOptions['password'] == '' && $regOptions['auth_method'] == 'password')
  488. {
  489. mt_srand(time() + 1277);
  490. $regOptions['password'] = generateValidationCode();
  491. $regOptions['password_check'] = $regOptions['password'];
  492. }
  493. // Does the first password match the second?
  494. elseif ($regOptions['password'] != $regOptions['password_check'] && $regOptions['auth_method'] == 'password')
  495. $reg_errors[] = array('lang', 'passwords_dont_match');
  496. // That's kind of easy to guess...
  497. if ($regOptions['password'] == '')
  498. {
  499. if ($regOptions['auth_method'] == 'password')
  500. $reg_errors[] = array('lang', 'no_password');
  501. else
  502. $regOptions['password'] = sha1(mt_rand());
  503. }
  504. // Now perform hard password validation as required.
  505. if (!empty($regOptions['check_password_strength']))
  506. {
  507. $passwordError = validatePassword($regOptions['password'], $regOptions['username'], array($regOptions['email']));
  508. // Password isn't legal?
  509. if ($passwordError != null)
  510. $reg_errors[] = array('lang', 'profile_error_password_' . $passwordError);
  511. }
  512. // If they are using an OpenID that hasn't been verified yet error out.
  513. // !!! Change this so they can register without having to attempt a login first
  514. if ($regOptions['auth_method'] == 'openid' && (empty($_SESSION['openid']['verified']) || $_SESSION['openid']['openid_uri'] != $regOptions['openid']))
  515. $reg_errors[] = array('lang', 'openid_not_verified');
  516. // You may not be allowed to register this email.
  517. if (!empty($regOptions['check_email_ban']))
  518. isBannedEmail($regOptions['email'], 'cannot_register', $txt['ban_register_prohibited']);
  519. // Check if the email address is in use.
  520. $request = $smcFunc['db_query']('', '
  521. SELECT id_member
  522. FROM {db_prefix}members
  523. WHERE email_address = {string:email_address}
  524. OR email_address = {string:username}
  525. LIMIT 1',
  526. array(
  527. 'email_address' => $regOptions['email'],
  528. 'username' => $regOptions['username'],
  529. )
  530. );
  531. // !!! Separate the sprintf?
  532. if ($smcFunc['db_num_rows']($request) != 0)
  533. $reg_errors[] = array('lang', 'email_in_use', false, array(htmlspecialchars($regOptions['email'])));
  534. $smcFunc['db_free_result']($request);
  535. // If we found any errors we need to do something about it right away!
  536. foreach ($reg_errors as $key => $error)
  537. {
  538. /* Note for each error:
  539. 0 = 'lang' if it's an index, 'done' if it's clear text.
  540. 1 = The text/index.
  541. 2 = Whether to log.
  542. 3 = sprintf data if necessary. */
  543. if ($error[0] == 'lang')
  544. loadLanguage('Errors');
  545. $message = $error[0] == 'lang' ? (empty($error[3]) ? $txt[$error[1]] : vsprintf($txt[$error[1]], $error[3])) : $error[1];
  546. // What to do, what to do, what to do.
  547. if ($return_errors)
  548. {
  549. if (!empty($error[2]))
  550. log_error($message, $error[2]);
  551. $reg_errors[$key] = $message;
  552. }
  553. else
  554. fatal_error($message, empty($error[2]) ? false : $error[2]);
  555. }
  556. // If there's any errors left return them at once!
  557. if (!empty($reg_errors))
  558. return $reg_errors;
  559. $reservedVars = array(
  560. 'actual_theme_url',
  561. 'actual_images_url',
  562. 'base_theme_dir',
  563. 'base_theme_url',
  564. 'default_images_url',
  565. 'default_theme_dir',
  566. 'default_theme_url',
  567. 'default_template',
  568. 'images_url',
  569. 'number_recent_posts',
  570. 'smiley_sets_default',
  571. 'theme_dir',
  572. 'theme_id',
  573. 'theme_layers',
  574. 'theme_templates',
  575. 'theme_url',
  576. );
  577. // Can't change reserved vars.
  578. if (isset($regOptions['theme_vars']) && array_intersect($regOptions['theme_vars'], $reservedVars) != array())
  579. fatal_lang_error('no_theme');
  580. // Some of these might be overwritten. (the lower ones that are in the arrays below.)
  581. $regOptions['register_vars'] = array(
  582. 'member_name' => $regOptions['username'],
  583. 'email_address' => $regOptions['email'],
  584. 'passwd' => sha1(strtolower($regOptions['username']) . $regOptions['password']),
  585. 'password_salt' => substr(md5(mt_rand()), 0, 4) ,
  586. 'posts' => 0,
  587. 'date_registered' => time(),
  588. 'member_ip' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $user_info['ip'],
  589. 'member_ip2' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $_SERVER['BAN_CHECK_IP'],
  590. 'validation_code' => $validation_code,
  591. 'real_name' => $regOptions['username'],
  592. 'personal_text' => $modSettings['default_personal_text'],
  593. 'pm_email_notify' => 1,
  594. 'id_theme' => 0,
  595. 'id_post_group' => 4,
  596. 'lngfile' => '',
  597. 'buddy_list' => '',
  598. 'pm_ignore_list' => '',
  599. 'message_labels' => '',
  600. 'website_title' => '',
  601. 'website_url' => '',
  602. 'location' => '',
  603. 'icq' => '',
  604. 'aim' => '',
  605. 'yim' => '',
  606. 'msn' => '',
  607. 'time_format' => '',
  608. 'signature' => '',
  609. 'avatar' => '',
  610. 'usertitle' => '',
  611. 'secret_question' => '',
  612. 'secret_answer' => '',
  613. 'additional_groups' => '',
  614. 'ignore_boards' => '',
  615. 'smiley_set' => '',
  616. 'openid_uri' => (!empty($regOptions['openid']) ? $regOptions['openid'] : ''),
  617. );
  618. // Setup the activation status on this new account so it is correct - firstly is it an under age account?
  619. if ($regOptions['require'] == 'coppa')
  620. {
  621. $regOptions['register_vars']['is_activated'] = 5;
  622. // !!! This should be changed. To what should be it be changed??
  623. $regOptions['register_vars']['validation_code'] = '';
  624. }
  625. // Maybe it can be activated right away?
  626. elseif ($regOptions['require'] == 'nothing')
  627. $regOptions['register_vars']['is_activated'] = 1;
  628. // Maybe it must be activated by email?
  629. elseif ($regOptions['require'] == 'activation')
  630. $regOptions['register_vars']['is_activated'] = 0;
  631. // Otherwise it must be awaiting approval!
  632. else
  633. $regOptions['register_vars']['is_activated'] = 3;
  634. if (isset($regOptions['memberGroup']))
  635. {
  636. // Make sure the id_group will be valid, if this is an administator.
  637. $regOptions['register_vars']['id_group'] = $regOptions['memberGroup'] == 1 && !allowedTo('admin_forum') ? 0 : $regOptions['memberGroup'];
  638. // Check if this group is assignable.
  639. $unassignableGroups = array(-1, 3);
  640. $request = $smcFunc['db_query']('', '
  641. SELECT id_group
  642. FROM {db_prefix}membergroups
  643. WHERE min_posts != {int:min_posts}',
  644. array(
  645. 'min_posts' => -1,
  646. )
  647. );
  648. while ($row = $smcFunc['db_fetch_assoc']($request))
  649. $unassignableGroups[] = $row['id_group'];
  650. $smcFunc['db_free_result']($request);
  651. if (in_array($regOptions['register_vars']['id_group'], $unassignableGroups))
  652. $regOptions['register_vars']['id_group'] = 0;
  653. }
  654. // ICQ cannot be zero.
  655. if (isset($regOptions['extra_register_vars']['icq']) && empty($regOptions['extra_register_vars']['icq']))
  656. $regOptions['extra_register_vars']['icq'] = '';
  657. // Integrate optional member settings to be set.
  658. if (!empty($regOptions['extra_register_vars']))
  659. foreach ($regOptions['extra_register_vars'] as $var => $value)
  660. $regOptions['register_vars'][$var] = $value;
  661. // Integrate optional user theme options to be set.
  662. $theme_vars = array();
  663. if (!empty($regOptions['theme_vars']))
  664. foreach ($regOptions['theme_vars'] as $var => $value)
  665. $theme_vars[$var] = $value;
  666. // Call an optional function to validate the users' input.
  667. if (isset($modSettings['integrate_register']) && function_exists($modSettings['integrate_register']))
  668. $modSettings['integrate_register']($regOptions, $theme_vars);
  669. // Right, now let's prepare for insertion.
  670. $knownInts = array(
  671. 'date_registered', 'posts', 'id_group', 'last_login', 'instant_messages', 'unread_messages',
  672. 'new_pm', 'pm_prefs', 'gender', 'hide_email', 'show_online', 'pm_email_notify', 'karma_good', 'karma_bad',
  673. 'notify_announcements', 'notify_send_body', 'notify_regularity', 'notify_types',
  674. 'id_theme', 'is_activated', 'id_msg_last_visit', 'id_post_group', 'total_time_logged_in', 'warning',
  675. );
  676. $knownFloats = array(
  677. 'time_offset',
  678. );
  679. $column_names = array();
  680. $values = array();
  681. foreach ($regOptions['register_vars'] as $var => $val)
  682. {
  683. $type = 'string';
  684. if (in_array($var, $knownInts))
  685. $type = 'int';
  686. elseif (in_array($var, $knownFloats))
  687. $type = 'float';
  688. elseif ($var == 'birthdate')
  689. $type = 'date';
  690. $column_names[$var] = $type;
  691. $values[$var] = $val;
  692. }
  693. // Register them into the database.
  694. $smcFunc['db_insert']('',
  695. '{db_prefix}members',
  696. $column_names,
  697. $values,
  698. array('id_member')
  699. );
  700. $memberID = $smcFunc['db_insert_id']('{db_prefix}members', 'id_member');
  701. // Update the number of members and latest member's info - and pass the name, but remove the 's.
  702. if ($regOptions['register_vars']['is_activated'] == 1)
  703. updateStats('member', $memberID, $regOptions['register_vars']['real_name']);
  704. else
  705. updateStats('member');
  706. // Theme variables too?
  707. if (!empty($theme_vars))
  708. {
  709. $inserts = array();
  710. foreach ($theme_vars as $var => $val)
  711. $inserts[] = array($memberID, $var, $val);
  712. $smcFunc['db_insert']('insert',
  713. '{db_prefix}themes',
  714. array('id_member' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
  715. $inserts,
  716. array('id_member', 'variable')
  717. );
  718. }
  719. // If it's enabled, increase the registrations for today.
  720. trackStats(array('registers' => '+'));
  721. // Administrative registrations are a bit different...
  722. if ($regOptions['interface'] == 'admin')
  723. {
  724. if ($regOptions['require'] == 'activation')
  725. $email_message = 'admin_register_activate';
  726. elseif (!empty($regOptions['send_welcome_email']))
  727. $email_message = 'admin_register_immediate';
  728. if (isset($email_message))
  729. {
  730. $replacements = array(
  731. 'REALNAME' => $regOptions['register_vars']['real_name'],
  732. 'USERNAME' => $regOptions['username'],
  733. 'PASSWORD' => $regOptions['password'],
  734. 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
  735. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $memberID . ';code=' . $validation_code,
  736. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $memberID,
  737. 'ACTIVATIONCODE' => $validation_code,
  738. );
  739. $emaildata = loadEmailTemplate($email_message, $replacements);
  740. sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  741. }
  742. // All admins are finished here.
  743. return $memberID;
  744. }
  745. // Can post straight away - welcome them to your fantastic community...
  746. if ($regOptions['require'] == 'nothing')
  747. {
  748. if (!empty($regOptions['send_welcome_email']))
  749. {
  750. $replacements = array(
  751. 'REALNAME' => $regOptions['register_vars']['real_name'],
  752. 'USERNAME' => $regOptions['username'],
  753. 'PASSWORD' => $regOptions['password'],
  754. 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
  755. 'OPENID' => !empty($regOptions['openid']) ? $regOptions['openid'] : '',
  756. );
  757. $emaildata = loadEmailTemplate('register_' . ($regOptions['auth_method'] == 'openid' ? 'openid_' : '') . 'immediate', $replacements);
  758. sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  759. }
  760. // Send admin their notification.
  761. adminNotify('standard', $memberID, $regOptions['username']);
  762. }
  763. // Need to activate their account - or fall under COPPA.
  764. elseif ($regOptions['require'] == 'activation' || $regOptions['require'] == 'coppa')
  765. {
  766. $replacements = array(
  767. 'REALNAME' => $regOptions['register_vars']['real_name'],
  768. 'USERNAME' => $regOptions['username'],
  769. 'PASSWORD' => $regOptions['password'],
  770. 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
  771. 'OPENID' => !empty($regOptions['openid']) ? $regOptions['openid'] : '',
  772. );
  773. if ($regOptions['require'] == 'activation')
  774. $replacements += array(
  775. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $memberID . ';code=' . $validation_code,
  776. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $memberID,
  777. 'ACTIVATIONCODE' => $validation_code,
  778. );
  779. else
  780. $replacements += array(
  781. 'COPPALINK' => $scripturl . '?action=coppa;u=' . $memberID,
  782. );
  783. $emaildata = loadEmailTemplate('register_' . ($regOptions['auth_method'] == 'openid' ? 'openid_' : '') . ($regOptions['require'] == 'activation' ? 'activate' : 'coppa'), $replacements);
  784. sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  785. }
  786. // Must be awaiting approval.
  787. else
  788. {
  789. $replacements = array(
  790. 'REALNAME' => $regOptions['register_vars']['real_name'],
  791. 'USERNAME' => $regOptions['username'],
  792. 'PASSWORD' => $regOptions['password'],
  793. 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
  794. 'OPENID' => !empty($regOptions['openid']) ? $regOptions['openid'] : '',
  795. );
  796. $emaildata = loadEmailTemplate('register_' . ($regOptions['auth_method'] == 'openid' ? 'openid_' : '') . 'pending', $replacements);
  797. sendmail($regOptions['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  798. // Admin gets informed here...
  799. adminNotify('approval', $memberID, $regOptions['username']);
  800. }
  801. // Okay, they're for sure registered... make sure the session is aware of this for security. (Just married :P!)
  802. $_SESSION['just_registered'] = 1;
  803. return $memberID;
  804. }
  805. // Check if a name is in the reserved words list. (name, current member id, name/username?.)
  806. function isReservedName($name, $current_ID_MEMBER = 0, $is_name = true, $fatal = true)
  807. {
  808. global $user_info, $modSettings, $smcFunc;
  809. $checkName = $smcFunc['strtolower']($name);
  810. // Administrators are never restricted ;).
  811. if (!allowedTo('moderate_forum') && ((!empty($modSettings['reserveName']) && $is_name) || !empty($modSettings['reserveUser']) && !$is_name))
  812. {
  813. $reservedNames = explode("\n", $modSettings['reserveNames']);
  814. // Case sensitive check?
  815. $checkMe = empty($modSettings['reserveCase']) ? $checkName : $name;
  816. // Check each name in the list...
  817. foreach ($reservedNames as $reserved)
  818. {
  819. if ($reserved == '')
  820. continue;
  821. // Case sensitive name?
  822. $reservedCheck = empty($modSettings['reserveCase']) ? $smcFunc['strtolower']($reserved) : $reserved;
  823. // If it's not just entire word, check for it in there somewhere...
  824. if ($checkMe == $reservedCheck || ($smcFunc['strpos']($checkMe, $reservedCheck) !== false && empty($modSettings['reserveWord'])))
  825. if ($fatal)
  826. fatal_lang_error('username_reserved', 'password', array($reserved));
  827. else
  828. return true;
  829. }
  830. $censor_name = $name;
  831. if (censorText($censor_name) != $name)
  832. if ($fatal)
  833. fatal_lang_error('name_censored', 'password', array($name));
  834. else
  835. return true;
  836. }
  837. // Charaters we just shouldn't allow, regardless.
  838. foreach (array('*') as $char)
  839. if (strpos($checkName, $char) !== false)
  840. if ($fatal)
  841. fatal_lang_error('username_reserved', 'password', array($char));
  842. else
  843. return true;
  844. // Get rid of any SQL parts of the reserved name...
  845. $checkName = strtr($name, array('_' => '\\_', '%' => '\\%'));
  846. // Make sure they don't want someone else's name.
  847. $request = $smcFunc['db_query']('', '
  848. SELECT id_member
  849. FROM {db_prefix}members
  850. WHERE ' . (empty($current_ID_MEMBER) ? '' : 'id_member != {int:current_member}
  851. AND ') . '(real_name LIKE {string:check_name} OR member_name LIKE {string:check_name})
  852. LIMIT 1',
  853. array(
  854. 'current_member' => $current_ID_MEMBER,
  855. 'check_name' => $checkName,
  856. )
  857. );
  858. if ($smcFunc['db_num_rows']($request) > 0)
  859. {
  860. $smcFunc['db_free_result']($request);
  861. return true;
  862. }
  863. // Does name case insensitive match a member group name?
  864. $request = $smcFunc['db_query']('', '
  865. SELECT id_group
  866. FROM {db_prefix}membergroups
  867. WHERE group_name LIKE {string:check_name}
  868. LIMIT 1',
  869. array(
  870. 'check_name' => $checkName,
  871. )
  872. );
  873. if ($smcFunc['db_num_rows']($request) > 0)
  874. {
  875. $smcFunc['db_free_result']($request);
  876. return true;
  877. }
  878. // Okay, they passed.
  879. return false;
  880. }
  881. // Get a list of groups that have a given permission (on a given board).
  882. function groupsAllowedTo($permission, $board_id = null)
  883. {
  884. global $modSettings, $board_info, $smcFunc;
  885. // Admins are allowed to do anything.
  886. $member_groups = array(
  887. 'allowed' => array(1),
  888. 'denied' => array(),
  889. );
  890. // Assume we're dealing with regular permissions (like profile_view_own).
  891. if ($board_id === null)
  892. {
  893. $request = $smcFunc['db_query']('', '
  894. SELECT id_group, add_deny
  895. FROM {db_prefix}permissions
  896. WHERE permission = {string:permission}',
  897. array(
  898. 'permission' => $permission,
  899. )
  900. );
  901. while ($row = $smcFunc['db_fetch_assoc']($request))
  902. $member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
  903. $smcFunc['db_free_result']($request);
  904. }
  905. // Otherwise it's time to look at the board.
  906. else
  907. {
  908. // First get the profile of the given board.
  909. if (isset($board_info['id']) && $board_info['id'] == $board_id)
  910. $profile_id = $board_info['profile'];
  911. elseif ($board_id !== 0)
  912. {
  913. $request = $smcFunc['db_query']('', '
  914. SELECT id_profile
  915. FROM {db_prefix}boards
  916. WHERE id_board = {int:id_board}
  917. LIMIT 1',
  918. array(
  919. 'id_board' => $board_id,
  920. )
  921. );
  922. if ($smcFunc['db_num_rows']($request) == 0)
  923. fatal_lang_error('no_board');
  924. list ($profile_id) = $smcFunc['db_fetch_row']($request);
  925. $smcFunc['db_free_result']($request);
  926. }
  927. else
  928. $profile_id = 1;
  929. $request = $smcFunc['db_query']('', '
  930. SELECT bp.id_group, bp.add_deny
  931. FROM {db_prefix}board_permissions AS bp
  932. WHERE bp.permission = {string:permission}
  933. AND bp.id_profile = {int:profile_id}',
  934. array(
  935. 'profile_id' => $profile_id,
  936. 'permission' => $permission,
  937. )
  938. );
  939. while ($row = $smcFunc['db_fetch_assoc']($request))
  940. $member_groups[$row['add_deny'] === '1' ? 'allowed' : 'denied'][] = $row['id_group'];
  941. $smcFunc['db_free_result']($request);
  942. }
  943. // Denied is never allowed.
  944. $member_groups['allowed'] = array_diff($member_groups['allowed'], $member_groups['denied']);
  945. return $member_groups;
  946. }
  947. // Get a list of members that have a given permission (on a given board).
  948. function membersAllowedTo($permission, $board_id = null)
  949. {
  950. global $smcFunc;
  951. $member_groups = groupsAllowedTo($permission, $board_id);
  952. $include_moderators = in_array(3, $member_groups['allowed']) && $board_id !== null;
  953. $member_groups['allowed'] = array_diff($member_groups['allowed'], array(3));
  954. $exclude_moderators = in_array(3, $member_groups['denied']) && $board_id !== null;
  955. $member_groups['denied'] = array_diff($member_groups['denied'], array(3));
  956. $request = $smcFunc['db_query']('', '
  957. SELECT mem.id_member
  958. FROM {db_prefix}members AS mem' . ($include_moderators || $exclude_moderators ? '
  959. LEFT JOIN {db_prefix}moderators AS mods ON (mods.id_member = mem.id_member AND mods.id_board = {int:board_id})' : '') . '
  960. WHERE (' . ($include_moderators ? 'mods.id_member IS NOT NULL OR ' : '') . 'mem.id_group IN ({array_int:member_groups_allowed}) OR FIND_IN_SET({raw:member_group_allowed_implode}, mem.additional_groups))' . (empty($member_groups['denied']) ? '' : '
  961. AND NOT (' . ($exclude_moderators ? 'mods.id_member IS NOT NULL OR ' : '') . 'mem.id_group IN ({array_int:member_groups_denied}) OR FIND_IN_SET({raw:member_group_denied_implode}, mem.additional_groups))'),
  962. array(
  963. 'member_groups_allowed' => $member_groups['allowed'],
  964. 'member_groups_denied' => $member_groups['denied'],
  965. 'board_id' => $board_id,
  966. 'member_group_allowed_implode' => implode(', mem.additional_groups) OR FIND_IN_SET(', $member_groups['allowed']),
  967. 'member_group_denied_implode' => implode(', mem.additional_groups) OR FIND_IN_SET(', $member_groups['denied']),
  968. )
  969. );
  970. $members = array();
  971. while ($row = $smcFunc['db_fetch_assoc']($request))
  972. $members[] = $row['id_member'];
  973. $smcFunc['db_free_result']($request);
  974. return $members;
  975. }
  976. // This function is used to reassociate members with relevant posts.
  977. function reattributePosts($memID, $email = false, $membername = false, $post_count = false)
  978. {
  979. global $smcFunc;
  980. // Firstly, if email and username aren't passed find out the members email address and name.
  981. if ($email === false && $membername === false)
  982. {
  983. $request = $smcFunc['db_query']('', '
  984. SELECT email_address, member_name
  985. FROM {db_prefix}members
  986. WHERE id_member = {int:memID}
  987. LIMIT 1',
  988. array(
  989. 'memID' => $memID,
  990. )
  991. );
  992. list ($email, $membername) = $smcFunc['db_fetch_row']($request);
  993. $smcFunc['db_free_result']($request);
  994. }
  995. $query_parts = array();
  996. if (!empty($email))
  997. $query_parts[] = 'm.poster_email = {string:email_address}';
  998. if (!empty($membername))
  999. $query_parts[] = 'm.poster_name = {string:member_name}';
  1000. $query = implode(' AND ', $query_parts);
  1001. // If they want the post count restored then we need to do some research.
  1002. if ($post_count)
  1003. {
  1004. $request = $smcFunc['db_query']('', '
  1005. SELECT COUNT(*)
  1006. FROM {db_prefix}messages AS m
  1007. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND b.count_posts = {int:count_posts})
  1008. WHERE m.id_member = {int:guest_id}
  1009. AND m.approved = {int:is_approved}
  1010. AND m.icon != {string:recycled_icon}
  1011. AND ' . $query,
  1012. array(
  1013. 'count_posts' => 0,
  1014. 'guest_id' => 0,
  1015. 'email_address' => $email,
  1016. 'member_name' => $membername,
  1017. 'is_approved' => 1,
  1018. 'recycled_icon' => 'recycled',
  1019. )
  1020. );
  1021. list ($messageCount) = $smcFunc['db_fetch_row']($request);
  1022. $smcFunc['db_free_result']($request);
  1023. updateMemberData($memID, array('posts' => 'posts + ' . $messageCount));
  1024. }
  1025. // Finally, update the posts themselves!
  1026. $smcFunc['db_query']('', '
  1027. UPDATE {db_prefix}messages AS m
  1028. SET m.id_member = {int:memID}
  1029. WHERE ' . $query,
  1030. array(
  1031. 'memID' => $memID,
  1032. 'email_address' => $email,
  1033. 'member_name' => $membername,
  1034. )
  1035. );
  1036. return $smcFunc['db_affected_rows']();
  1037. }
  1038. // This simple function adds/removes the passed user from the current users buddy list.
  1039. function BuddyListToggle()
  1040. {
  1041. global $user_info;
  1042. checkSession('get');
  1043. isAllowedTo('profile_identity_own');
  1044. is_not_guest();
  1045. if (empty($_REQUEST['u']))
  1046. fatal_lang_error('no_access', false);
  1047. $_REQUEST['u'] = (int) $_REQUEST['u'];
  1048. // Remove if it's already there...
  1049. if (in_array($_REQUEST['u'], $user_info['buddies']))
  1050. $user_info['buddies'] = array_diff($user_info['buddies'], array($_REQUEST['u']));
  1051. // ...or add if it's not.
  1052. else
  1053. $user_info['buddies'][] = (int) $_REQUEST['u'];
  1054. // Update the settings.
  1055. updateMemberData($user_info['id'], array('buddy_list' => implode(',', $user_info['buddies'])));
  1056. // Redirect back to the profile
  1057. redirectexit('action=profile;u=' . $_REQUEST['u']);
  1058. }
  1059. function list_getMembers($start, $items_per_page, $sort, $where, $where_params = array(), $get_duplicates = false)
  1060. {
  1061. global $smcFunc;
  1062. $request = $smcFunc['db_query']('', '
  1063. SELECT
  1064. mem.id_member, mem.member_name, mem.real_name, mem.email_address, mem.icq, mem.aim, mem.yim, mem.msn, mem.member_ip, mem.member_ip2, mem.last_login,
  1065. mem.posts, mem.is_activated, mem.date_registered, mem.id_group, mem.additional_groups, mg.group_name
  1066. FROM {db_prefix}members AS mem
  1067. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
  1068. WHERE ' . $where . '
  1069. ORDER BY {raw:sort}
  1070. LIMIT {int:start}, {int:per_page}',
  1071. array_merge($where_params, array(
  1072. 'sort' => $sort,
  1073. 'start' => $start,
  1074. 'per_page' => $items_per_page,
  1075. ))
  1076. );
  1077. $members = array();
  1078. while ($row = $smcFunc['db_fetch_assoc']($request))
  1079. $members[] = $row;
  1080. $smcFunc['db_free_result']($request);
  1081. // If we want duplicates pass the members array off.
  1082. if ($get_duplicates)
  1083. populateDuplicateMembers($members);
  1084. return $members;
  1085. }
  1086. function list_getNumMembers($where, $where_params = array())
  1087. {
  1088. global $smcFunc, $modSettings;
  1089. // We know how many members there are in total.
  1090. if (empty($where) || $where == '1')
  1091. $num_members = $modSettings['totalMembers'];
  1092. // The database knows the amount when there are extra conditions.
  1093. else
  1094. {
  1095. $request = $smcFunc['db_query']('', '
  1096. SELECT COUNT(*)
  1097. FROM {db_prefix}members AS mem
  1098. WHERE ' . $where,
  1099. array_merge($where_params, array(
  1100. ))
  1101. );
  1102. list ($num_members) = $smcFunc['db_fetch_row']($request);
  1103. $smcFunc['db_free_result']($request);
  1104. }
  1105. return $num_members;
  1106. }
  1107. function populateDuplicateMembers(&$members)
  1108. {
  1109. global $smcFunc;
  1110. // This will hold all the ip addresses.
  1111. $ips = array();
  1112. foreach ($members as $key => $member)
  1113. {
  1114. // Create the duplicate_members element.
  1115. $members[$key]['duplicate_members'] = array();
  1116. // Store the IPs.
  1117. if (!empty($member['member_ip']))
  1118. $ips[] = $member['member_ip'];
  1119. if (!empty($member['member_ip2']))
  1120. $ips[] = $member['member_ip2'];
  1121. }
  1122. $ips = array_unique($ips);
  1123. if (empty($ips))
  1124. return false;
  1125. // Fetch all members with this IP address, we'll filter out the current ones in a sec.
  1126. $request = $smcFunc['db_query']('', '
  1127. SELECT
  1128. id_member, member_name, email_address, member_ip, member_ip2, is_activated
  1129. FROM {db_prefix}members
  1130. WHERE member_ip IN ({array_string:ips})
  1131. OR member_ip2 IN ({array_string:ips})',
  1132. array(
  1133. 'ips' => $ips,
  1134. )
  1135. );
  1136. $duplicate_members = array();
  1137. $duplicate_ids = array();
  1138. while ($row = $smcFunc['db_fetch_assoc']($request))
  1139. {
  1140. //$duplicate_ids[] = $row['id_member'];
  1141. $member_context = array(
  1142. 'id' => $row['id_member'],
  1143. 'name' => $row['member_name'],
  1144. 'email' => $row['email_address'],
  1145. 'is_banned' => $row['is_activated'] > 10,
  1146. 'ip' => $row['member_ip'],
  1147. 'ip2' => $row['member_ip2'],
  1148. );
  1149. if (in_array($row['member_ip'], $ips))
  1150. $duplicate_members[$row['member_ip']][] = $member_context;
  1151. if ($row['member_ip'] != $row['member_ip2'] && in_array($row['member_ip2'], $ips))
  1152. $duplicate_members[$row['member_ip2']][] = $member_context;
  1153. }
  1154. $smcFunc['db_free_result']($request);
  1155. // Also try to get a list of messages using these ips.
  1156. $request = $smcFunc['db_query']('', '
  1157. SELECT
  1158. m.poster_ip, mem.id_member, mem.member_name, mem.email_address, mem.is_activated
  1159. FROM {db_prefix}messages AS m
  1160. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1161. WHERE m.id_member != 0
  1162. ' . (!empty($duplicate_ids) ? 'AND m.id_member NOT IN ({array_int:duplicate_ids})' : '') . '
  1163. AND m.poster_ip IN ({array_string:ips})',
  1164. array(
  1165. 'duplicate_ids' => $duplicate_ids,
  1166. 'ips' => $ips,
  1167. )
  1168. );
  1169. $had_ips = array();
  1170. while ($row = $smcFunc['db_fetch_assoc']($request))
  1171. {
  1172. // Don't collect lots of the same.
  1173. if (isset($had_ips[$row['poster_ip']]) && in_array($row['id_member'], $had_ips[$row['poster_ip']]))
  1174. continue;
  1175. $had_ips[$row['poster_ip']][] = $row['id_member'];
  1176. $duplicate_members[$row['poster_ip']][] = array(
  1177. 'id' => $row['id_member'],
  1178. 'name' => $row['member_name'],
  1179. 'email' => $row['email_address'],
  1180. 'is_banned' => $row['is_activated'] > 10,
  1181. 'ip' => $row['poster_ip'],
  1182. 'ip2' => $row['poster_ip'],
  1183. );
  1184. }
  1185. $smcFunc['db_free_result']($request);
  1186. // Now we have all the duplicate members, stick them with their respective member in the list.
  1187. if (!empty($duplicate_members))
  1188. foreach ($members as $key => $member)
  1189. {
  1190. if (isset($duplicate_members[$member['member_ip']]))
  1191. $members[$key]['duplicate_members'] = $duplicate_members[$member['member_ip']];
  1192. if ($member['member_ip'] != $member['member_ip2'] && isset($duplicate_members[$member['member_ip2']]))
  1193. $members[$key]['duplicate_members'] = array_merge($member['duplicate_members'], $duplicate_members[$member['member_ip2']]);
  1194. // Check we don't have lots of the same member.
  1195. $member_track = array($member['id_member']);
  1196. foreach ($members[$key]['duplicate_members'] as $duplicate_id_member => $duplicate_member)
  1197. {
  1198. if (in_array($duplicate_member['id'], $member_track))
  1199. {
  1200. unset($members[$key]['duplicate_members'][$duplicate_id_member]);
  1201. continue;
  1202. }
  1203. $member_track[] = $duplicate_member['id'];
  1204. }
  1205. }
  1206. }
  1207. // Generate a random validation code.
  1208. function generateValidationCode()
  1209. {
  1210. global $smcFunc, $modSettings;
  1211. $request = $smcFunc['db_query']('get_random_number', '
  1212. SELECT RAND()',
  1213. array(
  1214. )
  1215. );
  1216. list ($dbRand) = $smcFunc['db_fetch_row']($request);
  1217. $smcFunc['db_free_result']($request);
  1218. return substr(preg_replace('/\W/', '', sha1(microtime() . mt_rand() . $dbRand . $modSettings['rand_seed'])), 0, 10);
  1219. }
  1220. ?>