PageRenderTime 70ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/php/Sources/Profile-Modify.php

https://github.com/dekoza/openshift-smf-2.0.7
PHP | 3428 lines | 2652 code | 338 blank | 438 comment | 549 complexity | b2a8651f2e0bd60a6f495117185d7839 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.0.7
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /* This file has the primary job of showing and editing people's profiles.
  15. It also allows the user to change some of their or another's preferences,
  16. and such things. It uses the following functions:
  17. void loadProfileFields(bool force_reload = false)
  18. // !!!
  19. void setupProfileContext(array fields)
  20. // !!!
  21. void saveProfileFields()
  22. // !!!
  23. void saveProfileChanges(array &profile_variables, array &errors, int id_member)
  24. // !!!
  25. void makeThemeChanges(int id_member, int id_theme)
  26. // !!!
  27. void makeNotificationChanges(int id_member)
  28. // !!!
  29. void makeCustomFieldChanges(int id_member, string area, bool sanitize = true)
  30. // !!!
  31. void editBuddies(int id_member)
  32. // !!!
  33. void editIgnoreList(int id_member)
  34. // !!!
  35. void account(int id_member)
  36. // !!!
  37. void forumProfile(int id_member)
  38. // !!!
  39. void pmprefs(int id_member)
  40. // !!!
  41. array getAvatars(string directory, int level)
  42. // !!!
  43. void theme(int id_member)
  44. // !!!
  45. void authentication(int id_member, bool saving = false)
  46. // !!!
  47. void notification(int id_member)
  48. // !!!
  49. int list_getTopicNotificationCount(int memID)
  50. // !!!
  51. array list_getTopicNotifications(int start, int items_per_page, string sort, int memID)
  52. // !!!
  53. array list_getBoardNotifications(int start, int items_per_page, string sort, int memID)
  54. // !!!
  55. void loadThemeOptions(int id_member)
  56. // !!!
  57. void ignoreboards(int id_member)
  58. // !!!
  59. bool profileLoadLanguages()
  60. // !!!
  61. bool profileLoadGroups()
  62. // !!!
  63. bool profileLoadSignatureData()
  64. // !!!
  65. bool profileLoadAvatarData()
  66. // !!!
  67. bool profileSaveGroups(mixed &value)
  68. // !!!
  69. mixed profileSaveAvatarData(array &value)
  70. // !!!
  71. mixed profileValidateSignature(mixed &value)
  72. // !!!
  73. bool profileValidateEmail(string email, int id_member = none)
  74. // !!!
  75. void profileReloadUser()
  76. // !!!
  77. void profileSendActivation()
  78. // !!!
  79. void groupMembership(int id_member)
  80. // !!!
  81. mixed groupMembership2(array profile_vars, array post_erros, int id_member)
  82. // !!!
  83. Adding new fields to the profile:
  84. ---------------------------------------------------------------------------
  85. // !!!
  86. */
  87. // This defines every profile field known to man.
  88. function loadProfileFields($force_reload = false)
  89. {
  90. global $context, $profile_fields, $txt, $scripturl, $modSettings, $user_info, $old_profile, $smcFunc, $cur_profile, $language;
  91. // Don't load this twice!
  92. if (!empty($profile_fields) && !$force_reload)
  93. return;
  94. /* This horrific array defines all the profile fields in the whole world!
  95. In general each "field" has one array - the key of which is the database column name associated with said field. Each item
  96. can have the following attributes:
  97. string $type: The type of field this is - valid types are:
  98. - callback: This is a field which has its own callback mechanism for templating.
  99. - check: A simple checkbox.
  100. - hidden: This doesn't have any visual aspects but may have some validity.
  101. - password: A password box.
  102. - select: A select box.
  103. - text: A string of some description.
  104. string $label: The label for this item - default will be $txt[$key] if this isn't set.
  105. string $subtext: The subtext (Small label) for this item.
  106. int $size: Optional size for a text area.
  107. array $input_attr: An array of text strings to be added to the input box for this item.
  108. string $value: The value of the item. If not set $cur_profile[$key] is assumed.
  109. string $permission: Permission required for this item (Excluded _any/_own subfix which is applied automatically).
  110. function $input_validate: A runtime function which validates the element before going to the database. It is passed
  111. the relevant $_POST element if it exists and should be treated like a reference.
  112. Return types:
  113. - true: Element can be stored.
  114. - false: Skip this element.
  115. - a text string: An error occured - this is the error message.
  116. function $preload: A function that is used to load data required for this element to be displayed. Must return
  117. true to be displayed at all.
  118. string $cast_type: If set casts the element to a certain type. Valid types (bool, int, float).
  119. string $save_key: If the index of this element isn't the database column name it can be overriden
  120. with this string.
  121. bool $is_dummy: If set then nothing is acted upon for this element.
  122. bool $enabled: A test to determine whether this is even available - if not is unset.
  123. string $link_with: Key which links this field to an overall set.
  124. Note that all elements that have a custom input_validate must ensure they set the value of $cur_profile correct to enable
  125. the changes to be displayed correctly on submit of the form.
  126. */
  127. $profile_fields = array(
  128. 'aim' => array(
  129. 'type' => 'text',
  130. 'label' => $txt['aim'],
  131. 'subtext' => $txt['your_aim'],
  132. 'size' => 24,
  133. 'value' => strtr(empty($cur_profile['aim']) ? '' : $cur_profile['aim'], '+', ' '),
  134. 'permission' => 'profile_extra',
  135. 'input_validate' => create_function('&$value', '
  136. $value = strtr($value, \' \', \'+\');
  137. return true;
  138. '),
  139. ),
  140. 'avatar_choice' => array(
  141. 'type' => 'callback',
  142. 'callback_func' => 'avatar_select',
  143. // This handles the permissions too.
  144. 'preload' => 'profileLoadAvatarData',
  145. 'input_validate' => 'profileSaveAvatarData',
  146. 'save_key' => 'avatar',
  147. ),
  148. 'bday1' => array(
  149. 'type' => 'callback',
  150. 'callback_func' => 'birthdate',
  151. 'permission' => 'profile_extra',
  152. 'preload' => create_function('', '
  153. global $cur_profile, $context;
  154. // Split up the birthdate....
  155. list ($uyear, $umonth, $uday) = explode(\'-\', empty($cur_profile[\'birthdate\']) || $cur_profile[\'birthdate\'] == \'0001-01-01\' ? \'0000-00-00\' : $cur_profile[\'birthdate\']);
  156. $context[\'member\'][\'birth_date\'] = array(
  157. \'year\' => $uyear == \'0004\' ? \'0000\' : $uyear,
  158. \'month\' => $umonth,
  159. \'day\' => $uday,
  160. );
  161. return true;
  162. '),
  163. 'input_validate' => create_function('&$value', '
  164. global $profile_vars, $cur_profile;
  165. if (isset($_POST[\'bday2\'], $_POST[\'bday3\']) && $value > 0 && $_POST[\'bday2\'] > 0)
  166. {
  167. // Set to blank?
  168. if ((int) $_POST[\'bday3\'] == 1 && (int) $_POST[\'bday2\'] == 1 && (int) $value == 1)
  169. $value = \'0001-01-01\';
  170. else
  171. $value = checkdate($value, $_POST[\'bday2\'], $_POST[\'bday3\'] < 4 ? 4 : $_POST[\'bday3\']) ? sprintf(\'%04d-%02d-%02d\', $_POST[\'bday3\'] < 4 ? 4 : $_POST[\'bday3\'], $_POST[\'bday1\'], $_POST[\'bday2\']) : \'0001-01-01\';
  172. }
  173. else
  174. $value = \'0001-01-01\';
  175. $profile_vars[\'birthdate\'] = $value;
  176. $cur_profile[\'birthdate\'] = $value;
  177. return false;
  178. '),
  179. ),
  180. // Setting the birthdate the old style way?
  181. 'birthdate' => array(
  182. 'type' => 'hidden',
  183. 'permission' => 'profile_extra',
  184. 'input_validate' => create_function('&$value', '
  185. global $cur_profile;
  186. // !!! Should we check for this year and tell them they made a mistake :P? (based on coppa at least?)
  187. if (preg_match(\'/(\d{4})[\-\., ](\d{2})[\-\., ](\d{2})/\', $value, $dates) === 1)
  188. {
  189. $value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf(\'%04d-%02d-%02d\', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : \'0001-01-01\';
  190. return true;
  191. }
  192. else
  193. {
  194. $value = empty($cur_profile[\'birthdate\']) ? \'0001-01-01\' : $cur_profile[\'birthdate\'];
  195. return false;
  196. }
  197. '),
  198. ),
  199. 'date_registered' => array(
  200. 'type' => 'text',
  201. 'value' => empty($cur_profile['date_registered']) ? $txt['not_applicable'] : strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
  202. 'label' => $txt['date_registered'],
  203. 'log_change' => true,
  204. 'permission' => 'moderate_forum',
  205. 'input_validate' => create_function('&$value', '
  206. global $txt, $user_info, $modSettings, $cur_profile, $context;
  207. // Bad date! Go try again - please?
  208. if (($value = strtotime($value)) === -1)
  209. {
  210. $value = $cur_profile[\'date_registered\'];
  211. return $txt[\'invalid_registration\'] . \' \' . strftime(\'%d %b %Y \' . (strpos($user_info[\'time_format\'], \'%H\') !== false ? \'%I:%M:%S %p\' : \'%H:%M:%S\'), forum_time(false));
  212. }
  213. // As long as it doesn\'t equal "N/A"...
  214. elseif ($value != $txt[\'not_applicable\'] && $value != strtotime(strftime(\'%Y-%m-%d\', $cur_profile[\'date_registered\'] + ($user_info[\'time_offset\'] + $modSettings[\'time_offset\']) * 3600)))
  215. $value = $value - ($user_info[\'time_offset\'] + $modSettings[\'time_offset\']) * 3600;
  216. else
  217. $value = $cur_profile[\'date_registered\'];
  218. return true;
  219. '),
  220. ),
  221. 'email_address' => array(
  222. 'type' => 'text',
  223. 'label' => $txt['email'],
  224. 'subtext' => $txt['valid_email'],
  225. 'log_change' => true,
  226. 'permission' => 'profile_identity',
  227. 'input_validate' => create_function('&$value', '
  228. global $context, $old_profile, $context, $profile_vars, $sourcedir, $modSettings;
  229. if (strtolower($value) == strtolower($old_profile[\'email_address\']))
  230. return false;
  231. $isValid = profileValidateEmail($value, $context[\'id_member\']);
  232. // Do they need to revalidate? If so schedule the function!
  233. if ($isValid === true && !empty($modSettings[\'send_validation_onChange\']) && !allowedTo(\'moderate_forum\'))
  234. {
  235. require_once($sourcedir . \'/Subs-Members.php\');
  236. $profile_vars[\'validation_code\'] = generateValidationCode();
  237. $profile_vars[\'is_activated\'] = 2;
  238. $context[\'profile_execute_on_save\'][] = \'profileSendActivation\';
  239. unset($context[\'profile_execute_on_save\'][\'reload_user\']);
  240. }
  241. return $isValid;
  242. '),
  243. ),
  244. 'gender' => array(
  245. 'type' => 'select',
  246. 'cast_type' => 'int',
  247. 'options' => 'return array(0 => \'\', 1 => $txt[\'male\'], 2 => $txt[\'female\']);',
  248. 'label' => $txt['gender'],
  249. 'permission' => 'profile_extra',
  250. ),
  251. 'hide_email' => array(
  252. 'type' => 'check',
  253. 'value' => empty($cur_profile['hide_email']) ? true : false,
  254. 'label' => $txt['allow_user_email'],
  255. 'permission' => 'profile_identity',
  256. 'input_validate' => create_function('&$value', '
  257. $value = $value == 0 ? 1 : 0;
  258. return true;
  259. '),
  260. ),
  261. 'icq' => array(
  262. 'type' => 'text',
  263. 'label' => $txt['icq'],
  264. 'subtext' => $txt['your_icq'],
  265. 'size' => 24,
  266. 'permission' => 'profile_extra',
  267. // Need to make sure ICQ doesn't equal 0.
  268. 'input_validate' => create_function('&$value', '
  269. if (empty($value))
  270. $value = \'\';
  271. else
  272. $value = (int) $value;
  273. return true;
  274. '),
  275. ),
  276. // Selecting group membership is a complicated one so we treat it separate!
  277. 'id_group' => array(
  278. 'type' => 'callback',
  279. 'callback_func' => 'group_manage',
  280. 'permission' => 'manage_membergroups',
  281. 'preload' => 'profileLoadGroups',
  282. 'log_change' => true,
  283. 'input_validate' => 'profileSaveGroups',
  284. ),
  285. 'id_theme' => array(
  286. 'type' => 'callback',
  287. 'callback_func' => 'theme_pick',
  288. 'permission' => 'profile_extra',
  289. 'enabled' => $modSettings['theme_allow'] || allowedTo('admin_forum'),
  290. 'preload' => create_function('', '
  291. global $smcFunc, $context, $cur_profile, $txt;
  292. $request = $smcFunc[\'db_query\'](\'\', \'
  293. SELECT value
  294. FROM {db_prefix}themes
  295. WHERE id_theme = {int:id_theme}
  296. AND variable = {string:variable}
  297. LIMIT 1\', array(
  298. \'id_theme\' => $cur_profile[\'id_theme\'],
  299. \'variable\' => \'name\',
  300. )
  301. );
  302. list ($name) = $smcFunc[\'db_fetch_row\']($request);
  303. $smcFunc[\'db_free_result\']($request);
  304. $context[\'member\'][\'theme\'] = array(
  305. \'id\' => $cur_profile[\'id_theme\'],
  306. \'name\' => empty($cur_profile[\'id_theme\']) ? $txt[\'theme_forum_default\'] : $name
  307. );
  308. return true;
  309. '),
  310. 'input_validate' => create_function('&$value', '
  311. $value = (int) $value;
  312. return true;
  313. '),
  314. ),
  315. 'karma_good' => array(
  316. 'type' => 'callback',
  317. 'callback_func' => 'karma_modify',
  318. 'permission' => 'admin_forum',
  319. // Set karma_bad too!
  320. 'input_validate' => create_function('&$value', '
  321. global $profile_vars, $cur_profile;
  322. $value = (int) $value;
  323. if (isset($_POST[\'karma_bad\']))
  324. {
  325. $profile_vars[\'karma_bad\'] = $_POST[\'karma_bad\'] != \'\' ? (int) $_POST[\'karma_bad\'] : 0;
  326. $cur_profile[\'karma_bad\'] = $_POST[\'karma_bad\'] != \'\' ? (int) $_POST[\'karma_bad\'] : 0;
  327. }
  328. return true;
  329. '),
  330. 'preload' => create_function('', '
  331. global $context, $cur_profile;
  332. $context[\'member\'][\'karma\'][\'good\'] = $cur_profile[\'karma_good\'];
  333. $context[\'member\'][\'karma\'][\'bad\'] = $cur_profile[\'karma_bad\'];
  334. return true;
  335. '),
  336. 'enabled' => !empty($modSettings['karmaMode']),
  337. ),
  338. 'lngfile' => array(
  339. 'type' => 'select',
  340. 'options' => 'return $context[\'profile_languages\'];',
  341. 'label' => $txt['preferred_language'],
  342. 'permission' => 'profile_identity',
  343. 'preload' => 'profileLoadLanguages',
  344. 'enabled' => !empty($modSettings['userLanguage']),
  345. 'value' => empty($cur_profile['lngfile']) ? $language : $cur_profile['lngfile'],
  346. 'input_validate' => create_function('&$value', '
  347. global $context, $cur_profile;
  348. // Load the languages.
  349. profileLoadLanguages();
  350. if (isset($context[\'profile_languages\'][$value]))
  351. {
  352. if ($context[\'user\'][\'is_owner\'] && empty($context[\'password_auth_failed\']))
  353. $_SESSION[\'language\'] = $value;
  354. return true;
  355. }
  356. else
  357. {
  358. $value = $cur_profile[\'lngfile\'];
  359. return false;
  360. }
  361. '),
  362. ),
  363. 'location' => array(
  364. 'type' => 'text',
  365. 'label' => $txt['location'],
  366. 'log_change' => true,
  367. 'size' => 50,
  368. 'permission' => 'profile_extra',
  369. ),
  370. // The username is not always editable - so adjust it as such.
  371. 'member_name' => array(
  372. 'type' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? 'text' : 'label',
  373. 'label' => $txt['username'],
  374. 'subtext' => allowedTo('admin_forum') && !isset($_GET['changeusername']) ? '(<a href="' . $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=account;changeusername" style="font-style: italic;">' . $txt['username_change'] . '</a>)' : '',
  375. 'log_change' => true,
  376. 'permission' => 'profile_identity',
  377. 'prehtml' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? '<div class="alert">' . $txt['username_warning'] . '</div>' : '',
  378. 'input_validate' => create_function('&$value', '
  379. global $sourcedir, $context, $user_info, $cur_profile;
  380. if (allowedTo(\'admin_forum\'))
  381. {
  382. // We\'ll need this...
  383. require_once($sourcedir . \'/Subs-Auth.php\');
  384. // Maybe they are trying to change their password as well?
  385. $resetPassword = true;
  386. if (isset($_POST[\'passwrd1\']) && $_POST[\'passwrd1\'] != \'\' && isset($_POST[\'passwrd2\']) && $_POST[\'passwrd1\'] == $_POST[\'passwrd2\'] && validatePassword($_POST[\'passwrd1\'], $value, array($cur_profile[\'real_name\'], $user_info[\'username\'], $user_info[\'name\'], $user_info[\'email\'])) == null)
  387. $resetPassword = false;
  388. // Do the reset... this will send them an email too.
  389. if ($resetPassword)
  390. resetPassword($context[\'id_member\'], $value);
  391. elseif ($value !== null)
  392. {
  393. validateUsername($context[\'id_member\'], trim(preg_replace(\'~[\t\n\r \x0B\0\' . ($context[\'utf8\'] ? ($context[\'server\'][\'complex_preg_chars\'] ? \'\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}\' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : \'\x00-\x08\x0B\x0C\x0E-\x19\xA0\') . \']+~\' . ($context[\'utf8\'] ? \'u\' : \'\'), \' \', $value)));
  394. updateMemberData($context[\'id_member\'], array(\'member_name\' => $value));
  395. }
  396. }
  397. return false;
  398. '),
  399. ),
  400. 'msn' => array(
  401. 'type' => 'text',
  402. 'label' => $txt['msn'],
  403. 'subtext' => $txt['msn_email_address'],
  404. 'size' => 24,
  405. 'permission' => 'profile_extra',
  406. 'input_validate' => create_function('&$value', '
  407. global $cur_profile;
  408. // Make sure the msn one is an email address, not something like \'none\' :P.
  409. if ($value != \'\' && preg_match(\'~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\\\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~\', $value) == 0)
  410. {
  411. $value = $cur_profile[\'msn\'];
  412. return false;
  413. }
  414. return true;
  415. '),
  416. ),
  417. 'passwrd1' => array(
  418. 'type' => 'password',
  419. 'label' => $txt['choose_pass'],
  420. 'subtext' => $txt['password_strength'],
  421. 'size' => 20,
  422. 'value' => '',
  423. 'enabled' => empty($cur_profile['openid_uri']),
  424. 'permission' => 'profile_identity',
  425. 'save_key' => 'passwd',
  426. // Note this will only work if passwrd2 also exists!
  427. 'input_validate' => create_function('&$value', '
  428. global $sourcedir, $user_info, $smcFunc, $cur_profile;
  429. // If we didn\'t try it then ignore it!
  430. if ($value == \'\')
  431. return false;
  432. // Do the two entries for the password even match?
  433. if (!isset($_POST[\'passwrd2\']) || $value != $_POST[\'passwrd2\'])
  434. return \'bad_new_password\';
  435. // Let\'s get the validation function into play...
  436. require_once($sourcedir . \'/Subs-Auth.php\');
  437. $passwordErrors = validatePassword($value, $cur_profile[\'member_name\'], array($cur_profile[\'real_name\'], $user_info[\'username\'], $user_info[\'name\'], $user_info[\'email\']));
  438. // Were there errors?
  439. if ($passwordErrors != null)
  440. return \'password_\' . $passwordErrors;
  441. // Set up the new password variable... ready for storage.
  442. $value = sha1(strtolower($cur_profile[\'member_name\']) . un_htmlspecialchars($value));
  443. return true;
  444. '),
  445. ),
  446. 'passwrd2' => array(
  447. 'type' => 'password',
  448. 'label' => $txt['verify_pass'],
  449. 'enabled' => empty($cur_profile['openid_uri']),
  450. 'size' => 20,
  451. 'value' => '',
  452. 'permission' => 'profile_identity',
  453. 'is_dummy' => true,
  454. ),
  455. 'personal_text' => array(
  456. 'type' => 'text',
  457. 'label' => $txt['personal_text'],
  458. 'log_change' => true,
  459. 'input_attr' => array('maxlength="50"'),
  460. 'size' => 50,
  461. 'permission' => 'profile_extra',
  462. ),
  463. // This does ALL the pm settings
  464. 'pm_prefs' => array(
  465. 'type' => 'callback',
  466. 'callback_func' => 'pm_settings',
  467. 'permission' => 'pm_read',
  468. 'preload' => create_function('', '
  469. global $context, $cur_profile;
  470. $context[\'display_mode\'] = $cur_profile[\'pm_prefs\'] & 3;
  471. $context[\'send_email\'] = $cur_profile[\'pm_email_notify\'];
  472. $context[\'receive_from\'] = !empty($cur_profile[\'pm_receive_from\']) ? $cur_profile[\'pm_receive_from\'] : 0;
  473. return true;
  474. '),
  475. 'input_validate' => create_function('&$value', '
  476. global $cur_profile, $profile_vars;
  477. // Simple validate and apply the two "sub settings"
  478. $value = max(min($value, 2), 0);
  479. $cur_profile[\'pm_email_notify\'] = $profile_vars[\'pm_email_notify\'] = max(min((int) $_POST[\'pm_email_notify\'], 2), 0);
  480. $cur_profile[\'pm_receive_from\'] = $profile_vars[\'pm_receive_from\'] = max(min((int) $_POST[\'pm_receive_from\'], 4), 0);
  481. return true;
  482. '),
  483. ),
  484. 'posts' => array(
  485. 'type' => 'int',
  486. 'label' => $txt['profile_posts'],
  487. 'log_change' => true,
  488. 'size' => 7,
  489. 'permission' => 'moderate_forum',
  490. 'input_validate' => create_function('&$value', '
  491. $value = $value != \'\' ? strtr($value, array(\',\' => \'\', \'.\' => \'\', \' \' => \'\')) : 0;
  492. return true;
  493. '),
  494. ),
  495. 'real_name' => array(
  496. 'type' => !empty($modSettings['allow_editDisplayName']) || allowedTo('moderate_forum') ? 'text' : 'label',
  497. 'label' => $txt['name'],
  498. 'subtext' => $txt['display_name_desc'],
  499. 'log_change' => true,
  500. 'input_attr' => array('maxlength="60"'),
  501. 'permission' => 'profile_identity',
  502. 'enabled' => !empty($modSettings['allow_editDisplayName']) || allowedTo('moderate_forum'),
  503. 'input_validate' => create_function('&$value', '
  504. global $context, $smcFunc, $sourcedir, $cur_profile;
  505. $value = trim(preg_replace(\'~[\t\n\r \x0B\0\' . ($context[\'utf8\'] ? ($context[\'server\'][\'complex_preg_chars\'] ? \'\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}\' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : \'\x00-\x08\x0B\x0C\x0E-\x19\xA0\') . \']+~\' . ($context[\'utf8\'] ? \'u\' : \'\'), \' \', $value));
  506. if (trim($value) == \'\')
  507. return \'no_name\';
  508. elseif ($smcFunc[\'strlen\']($value) > 60)
  509. return \'name_too_long\';
  510. elseif ($cur_profile[\'real_name\'] != $value)
  511. {
  512. require_once($sourcedir . \'/Subs-Members.php\');
  513. if (isReservedName($value, $context[\'id_member\']))
  514. return \'name_taken\';
  515. }
  516. return true;
  517. '),
  518. ),
  519. 'secret_question' => array(
  520. 'type' => 'text',
  521. 'label' => $txt['secret_question'],
  522. 'subtext' => $txt['secret_desc'],
  523. 'size' => 50,
  524. 'permission' => 'profile_identity',
  525. ),
  526. 'secret_answer' => array(
  527. 'type' => 'text',
  528. 'label' => $txt['secret_answer'],
  529. 'subtext' => $txt['secret_desc2'],
  530. 'size' => 20,
  531. 'postinput' => '<span class="smalltext" style="margin-left: 4ex;"><a href="' . $scripturl . '?action=helpadmin;help=secret_why_blank" onclick="return reqWin(this.href);">' . $txt['secret_why_blank'] . '</a></span>',
  532. 'value' => '',
  533. 'permission' => 'profile_identity',
  534. 'input_validate' => create_function('&$value', '
  535. $value = $value != \'\' ? md5($value) : \'\';
  536. return true;
  537. '),
  538. ),
  539. 'signature' => array(
  540. 'type' => 'callback',
  541. 'callback_func' => 'signature_modify',
  542. 'permission' => 'profile_extra',
  543. 'enabled' => substr($modSettings['signature_settings'], 0, 1) == 1,
  544. 'preload' => 'profileLoadSignatureData',
  545. 'input_validate' => 'profileValidateSignature',
  546. ),
  547. 'show_online' => array(
  548. 'type' => 'check',
  549. 'label' => $txt['show_online'],
  550. 'permission' => 'profile_identity',
  551. 'enabled' => !empty($modSettings['allow_hideOnline']) || allowedTo('moderate_forum'),
  552. ),
  553. 'smiley_set' => array(
  554. 'type' => 'callback',
  555. 'callback_func' => 'smiley_pick',
  556. 'enabled' => !empty($modSettings['smiley_sets_enable']),
  557. 'permission' => 'profile_extra',
  558. 'preload' => create_function('', '
  559. global $modSettings, $context, $txt, $cur_profile;
  560. $context[\'member\'][\'smiley_set\'][\'id\'] = empty($cur_profile[\'smiley_set\']) ? \'\' : $cur_profile[\'smiley_set\'];
  561. $context[\'smiley_sets\'] = explode(\',\', \'none,,\' . $modSettings[\'smiley_sets_known\']);
  562. $set_names = explode("\n", $txt[\'smileys_none\'] . "\n" . $txt[\'smileys_forum_board_default\'] . "\n" . $modSettings[\'smiley_sets_names\']);
  563. foreach ($context[\'smiley_sets\'] as $i => $set)
  564. {
  565. $context[\'smiley_sets\'][$i] = array(
  566. \'id\' => htmlspecialchars($set),
  567. \'name\' => htmlspecialchars($set_names[$i]),
  568. \'selected\' => $set == $context[\'member\'][\'smiley_set\'][\'id\']
  569. );
  570. if ($context[\'smiley_sets\'][$i][\'selected\'])
  571. $context[\'member\'][\'smiley_set\'][\'name\'] = $set_names[$i];
  572. }
  573. return true;
  574. '),
  575. 'input_validate' => create_function('&$value', '
  576. global $modSettings;
  577. $smiley_sets = explode(\',\', $modSettings[\'smiley_sets_known\']);
  578. if (!in_array($value, $smiley_sets) && $value != \'none\')
  579. $value = \'\';
  580. return true;
  581. '),
  582. ),
  583. // Pretty much a dummy entry - it populates all the theme settings.
  584. 'theme_settings' => array(
  585. 'type' => 'callback',
  586. 'callback_func' => 'theme_settings',
  587. 'permission' => 'profile_extra',
  588. 'is_dummy' => true,
  589. 'preload' => create_function('', '
  590. loadLanguage(\'Settings\');
  591. return true;
  592. '),
  593. ),
  594. 'time_format' => array(
  595. 'type' => 'callback',
  596. 'callback_func' => 'timeformat_modify',
  597. 'permission' => 'profile_extra',
  598. 'preload' => create_function('', '
  599. global $context, $user_info, $txt, $cur_profile, $modSettings;
  600. $context[\'easy_timeformats\'] = array(
  601. array(\'format\' => \'\', \'title\' => $txt[\'timeformat_default\']),
  602. array(\'format\' => \'%B %d, %Y, %I:%M:%S %p\', \'title\' => $txt[\'timeformat_easy1\']),
  603. array(\'format\' => \'%B %d, %Y, %H:%M:%S\', \'title\' => $txt[\'timeformat_easy2\']),
  604. array(\'format\' => \'%Y-%m-%d, %H:%M:%S\', \'title\' => $txt[\'timeformat_easy3\']),
  605. array(\'format\' => \'%d %B %Y, %H:%M:%S\', \'title\' => $txt[\'timeformat_easy4\']),
  606. array(\'format\' => \'%d-%m-%Y, %H:%M:%S\', \'title\' => $txt[\'timeformat_easy5\'])
  607. );
  608. $context[\'member\'][\'time_format\'] = $cur_profile[\'time_format\'];
  609. $context[\'current_forum_time\'] = timeformat(time() - $user_info[\'time_offset\'] * 3600, false);
  610. $context[\'current_forum_time_js\'] = strftime(\'%Y,\' . ((int) strftime(\'%m\', time() + $modSettings[\'time_offset\'] * 3600) - 1) . \',%d,%H,%M,%S\', time() + $modSettings[\'time_offset\'] * 3600);
  611. $context[\'current_forum_time_hour\'] = (int) strftime(\'%H\', forum_time(false));
  612. return true;
  613. '),
  614. ),
  615. 'time_offset' => array(
  616. 'type' => 'callback',
  617. 'callback_func' => 'timeoffset_modify',
  618. 'permission' => 'profile_extra',
  619. 'preload' => create_function('', '
  620. global $context, $cur_profile;
  621. $context[\'member\'][\'time_offset\'] = $cur_profile[\'time_offset\'];
  622. return true;
  623. '),
  624. 'input_validate' => create_function('&$value', '
  625. // Validate the time_offset...
  626. $value = (float) strtr($value, \',\', \'.\');
  627. if ($value < -23.5 || $value > 23.5)
  628. return \'bad_offset\';
  629. return true;
  630. '),
  631. ),
  632. 'usertitle' => array(
  633. 'type' => 'text',
  634. 'label' => $txt['custom_title'],
  635. 'log_change' => true,
  636. 'size' => 50,
  637. 'permission' => 'profile_title',
  638. 'enabled' => !empty($modSettings['titlesEnable']),
  639. ),
  640. 'website_title' => array(
  641. 'type' => 'text',
  642. 'label' => $txt['website_title'],
  643. 'subtext' => $txt['include_website_url'],
  644. 'size' => 50,
  645. 'permission' => 'profile_extra',
  646. 'link_with' => 'website',
  647. ),
  648. 'website_url' => array(
  649. 'type' => 'text',
  650. 'label' => $txt['website_url'],
  651. 'subtext' => $txt['complete_url'],
  652. 'size' => 50,
  653. 'permission' => 'profile_extra',
  654. // Fix the URL...
  655. 'input_validate' => create_function('&$value', '
  656. if (strlen(trim($value)) > 0 && strpos($value, \'://\') === false)
  657. $value = \'http://\' . $value;
  658. if (strlen($value) < 8 || (substr($value, 0, 7) !== \'http://\' && substr($value, 0, 8) !== \'https://\'))
  659. $value = \'\';
  660. return true;
  661. '),
  662. 'link_with' => 'website',
  663. ),
  664. 'yim' => array(
  665. 'type' => 'text',
  666. 'label' => $txt['yim'],
  667. 'subtext' => $txt['your_yim'],
  668. 'size' => 24,
  669. 'input_attr' => array('maxlength="32"'),
  670. 'permission' => 'profile_extra',
  671. ),
  672. );
  673. $disabled_fields = !empty($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
  674. // For each of the above let's take out the bits which don't apply - to save memory and security!
  675. foreach ($profile_fields as $key => $field)
  676. {
  677. // Do we have permission to do this?
  678. if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
  679. unset($profile_fields[$key]);
  680. // Is it enabled?
  681. if (isset($field['enabled']) && !$field['enabled'])
  682. unset($profile_fields[$key]);
  683. // Is it specifically disabled?
  684. if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
  685. unset($profile_fields[$key]);
  686. }
  687. }
  688. // Setup the context for a page load!
  689. function setupProfileContext($fields)
  690. {
  691. global $profile_fields, $context, $cur_profile, $smcFunc, $txt;
  692. // Make sure we have this!
  693. loadProfileFields(true);
  694. // First check for any linked sets.
  695. foreach ($profile_fields as $key => $field)
  696. if (isset($field['link_with']) && in_array($field['link_with'], $fields))
  697. $fields[] = $key;
  698. // Some default bits.
  699. $context['profile_prehtml'] = '';
  700. $context['profile_posthtml'] = '';
  701. $context['profile_javascript'] = '';
  702. $context['profile_onsubmit_javascript'] = '';
  703. $i = 0;
  704. $last_type = '';
  705. foreach ($fields as $key => $field)
  706. {
  707. if (isset($profile_fields[$field]))
  708. {
  709. // Shortcut.
  710. $cur_field = &$profile_fields[$field];
  711. // Does it have a preload and does that preload succeed?
  712. if (isset($cur_field['preload']) && !$cur_field['preload']())
  713. continue;
  714. // If this is anything but complex we need to do more cleaning!
  715. if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
  716. {
  717. if (!isset($cur_field['label']))
  718. $cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
  719. // Everything has a value!
  720. if (!isset($cur_field['value']))
  721. {
  722. $cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
  723. }
  724. // Any input attributes?
  725. $cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
  726. }
  727. // Was there an error with this field on posting?
  728. if (isset($context['profile_errors'][$field]))
  729. $cur_field['is_error'] = true;
  730. // Any javascript stuff?
  731. if (!empty($cur_field['js_submit']))
  732. $context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
  733. if (!empty($cur_field['js']))
  734. $context['profile_javascript'] .= $cur_field['js'];
  735. // Any template stuff?
  736. if (!empty($cur_field['prehtml']))
  737. $context['profile_prehtml'] .= $cur_field['prehtml'];
  738. if (!empty($cur_field['posthtml']))
  739. $context['profile_posthtml'] .= $cur_field['posthtml'];
  740. // Finally put it into context?
  741. if ($cur_field['type'] != 'hidden')
  742. {
  743. $last_type = $cur_field['type'];
  744. $context['profile_fields'][$field] = &$profile_fields[$field];
  745. }
  746. }
  747. // Bodge in a line break - without doing two in a row ;)
  748. elseif ($field == 'hr' && $last_type != 'hr' && $last_type != '')
  749. {
  750. $last_type = 'hr';
  751. $context['profile_fields'][$i++]['type'] = 'hr';
  752. }
  753. }
  754. // Free up some memory.
  755. unset($profile_fields);
  756. }
  757. // Save the profile changes.
  758. function saveProfileFields()
  759. {
  760. global $profile_fields, $profile_vars, $context, $old_profile, $post_errors, $sourcedir, $modSettings, $cur_profile, $smcFunc;
  761. // Load them up.
  762. loadProfileFields();
  763. // This makes things easier...
  764. $old_profile = $cur_profile;
  765. // This allows variables to call activities when they save - by default just to reload their settings
  766. $context['profile_execute_on_save'] = array();
  767. if ($context['user']['is_owner'])
  768. $context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
  769. // Assume we log nothing.
  770. $context['log_changes'] = array();
  771. // Cycle through the profile fields working out what to do!
  772. foreach ($profile_fields as $key => $field)
  773. {
  774. if (!isset($_POST[$key]) || !empty($field['is_dummy']))
  775. continue;
  776. // What gets updated?
  777. $db_key = isset($field['save_key']) ? $field['save_key'] : $key;
  778. // Right - we have something that is enabled, we can act upon and has a value posted to it. Does it have a validation function?
  779. if (isset($field['input_validate']))
  780. {
  781. $is_valid = $field['input_validate']($_POST[$key]);
  782. // An error occured - set it as such!
  783. if ($is_valid !== true)
  784. {
  785. // Is this an actual error?
  786. if ($is_valid !== false)
  787. {
  788. $post_errors[$key] = $is_valid;
  789. $profile_fields[$key]['is_error'] = $is_valid;
  790. }
  791. // Retain the old value.
  792. $cur_profile[$key] = $_POST[$key];
  793. continue;
  794. }
  795. }
  796. // Are we doing a cast?
  797. $field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
  798. // Finally, clean up certain types.
  799. if ($field['cast_type'] == 'int')
  800. $_POST[$key] = (int) $_POST[$key];
  801. elseif ($field['cast_type'] == 'float')
  802. $_POST[$key] = (float) $_POST[$key];
  803. elseif ($field['cast_type'] == 'check')
  804. $_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
  805. // If we got here we're doing OK.
  806. if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
  807. {
  808. // Set the save variable.
  809. $profile_vars[$db_key] = $_POST[$key];
  810. // And update the user profile.
  811. $cur_profile[$key] = $_POST[$key];
  812. // Are we logging it?
  813. if (!empty($field['log_change']) && isset($old_profile[$key]))
  814. $context['log_changes'][$key] = array(
  815. 'previous' => $old_profile[$key],
  816. 'new' => $_POST[$key],
  817. );
  818. }
  819. // Logging group changes are a bit different...
  820. if ($key == 'id_group' && $field['log_change'])
  821. {
  822. profileLoadGroups();
  823. // Any changes to primary group?
  824. if ($_POST['id_group'] != $old_profile['id_group'])
  825. {
  826. $context['log_changes']['id_group'] = array(
  827. 'previous' => !empty($old_profile[$key]) && isset($context['member_groups'][$old_profile[$key]]) ? $context['member_groups'][$old_profile[$key]]['name'] : '',
  828. 'new' => !empty($_POST[$key]) && isset($context['member_groups'][$_POST[$key]]) ? $context['member_groups'][$_POST[$key]]['name'] : '',
  829. );
  830. }
  831. // Prepare additional groups for comparison.
  832. $additional_groups = array(
  833. 'previous' => !empty($old_profile['additional_groups']) ? explode(',', $old_profile['additional_groups']) : array(),
  834. 'new' => !empty($_POST['additional_groups']) ? array_diff($_POST['additional_groups'], array(0)) : array(),
  835. );
  836. sort($additional_groups['previous']);
  837. sort($additional_groups['new']);
  838. // What about additional groups?
  839. if ($additional_groups['previous'] != $additional_groups['new'])
  840. {
  841. foreach ($additional_groups as $type => $groups)
  842. {
  843. foreach ($groups as $id => $group)
  844. {
  845. if (isset($context['member_groups'][$group]))
  846. $additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
  847. else
  848. unset($additional_groups[$type][$id]);
  849. }
  850. $additional_groups[$type] = implode(', ', $additional_groups[$type]);
  851. }
  852. $context['log_changes']['additional_groups'] = $additional_groups;
  853. }
  854. }
  855. }
  856. //!!! Temporary
  857. if ($context['user']['is_owner'])
  858. $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
  859. else
  860. $changeOther = allowedTo('profile_extra_any');
  861. if ($changeOther && empty($post_errors))
  862. {
  863. makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
  864. if (!empty($_REQUEST['sa']))
  865. makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false);
  866. }
  867. // Free memory!
  868. unset($profile_fields);
  869. }
  870. // Save the profile changes....
  871. function saveProfileChanges(&$profile_vars, &$post_errors, $memID)
  872. {
  873. global $user_info, $txt, $modSettings, $user_profile;
  874. global $context, $settings, $sourcedir;
  875. global $smcFunc;
  876. // These make life easier....
  877. $old_profile = &$user_profile[$memID];
  878. // Permissions...
  879. if ($context['user']['is_owner'])
  880. {
  881. $changeIdentity = allowedTo(array('profile_identity_any', 'profile_identity_own'));
  882. $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
  883. }
  884. else
  885. {
  886. $changeIdentity = allowedTo('profile_identity_any');
  887. $changeOther = allowedTo('profile_extra_any');
  888. }
  889. // Arrays of all the changes - makes things easier.
  890. $profile_bools = array(
  891. 'notify_announcements', 'notify_send_body',
  892. );
  893. $profile_ints = array(
  894. 'notify_regularity',
  895. 'notify_types',
  896. );
  897. $profile_floats = array(
  898. );
  899. $profile_strings = array(
  900. 'buddy_list',
  901. 'ignore_boards',
  902. );
  903. if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
  904. $_POST['ignore_brd'] = array();
  905. unset($_POST['ignore_boards']); // Whatever it is set to is a dirty fithy thing. Kinda like our minds.
  906. if (isset($_POST['ignore_brd']))
  907. {
  908. if (!is_array($_POST['ignore_brd']))
  909. $_POST['ignore_brd'] = array ($_POST['ignore_brd']);
  910. foreach ($_POST['ignore_brd'] as $k => $d)
  911. {
  912. $d = (int) $d;
  913. if ($d != 0)
  914. $_POST['ignore_brd'][$k] = $d;
  915. else
  916. unset($_POST['ignore_brd'][$k]);
  917. }
  918. $_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
  919. unset($_POST['ignore_brd']);
  920. }
  921. // Here's where we sort out all the 'other' values...
  922. if ($changeOther)
  923. {
  924. makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
  925. //makeAvatarChanges($memID, $post_errors);
  926. makeNotificationChanges($memID);
  927. if (!empty($_REQUEST['sa']))
  928. makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
  929. foreach ($profile_bools as $var)
  930. if (isset($_POST[$var]))
  931. $profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
  932. foreach ($profile_ints as $var)
  933. if (isset($_POST[$var]))
  934. $profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
  935. foreach ($profile_floats as $var)
  936. if (isset($_POST[$var]))
  937. $profile_vars[$var] = (float) $_POST[$var];
  938. foreach ($profile_strings as $var)
  939. if (isset($_POST[$var]))
  940. $profile_vars[$var] = $_POST[$var];
  941. }
  942. }
  943. // Make any theme changes that are sent with the profile..
  944. function makeThemeChanges($memID, $id_theme)
  945. {
  946. global $modSettings, $smcFunc, $context;
  947. $reservedVars = array(
  948. 'actual_theme_url',
  949. 'actual_images_url',
  950. 'base_theme_dir',
  951. 'base_theme_url',
  952. 'default_images_url',
  953. 'default_theme_dir',
  954. 'default_theme_url',
  955. 'default_template',
  956. 'images_url',
  957. 'number_recent_posts',
  958. 'smiley_sets_default',
  959. 'theme_dir',
  960. 'theme_id',
  961. 'theme_layers',
  962. 'theme_templates',
  963. 'theme_url',
  964. );
  965. // Can't change reserved vars.
  966. if ((isset($_POST['options']) && array_intersect($_POST['options'], $reservedVars) != array()) || (isset($_POST['default_options']) && array_intersect($_POST['default_options'], $reservedVars) != array()))
  967. fatal_lang_error('no_access', false);
  968. // Don't allow any overriding of custom fields with default or non-default options.
  969. $request = $smcFunc['db_query']('', '
  970. SELECT col_name
  971. FROM {db_prefix}custom_fields
  972. WHERE active = {int:is_active}',
  973. array(
  974. 'is_active' => 1,
  975. )
  976. );
  977. $custom_fields = array();
  978. while ($row = $smcFunc['db_fetch_assoc']($request))
  979. $custom_fields[] = $row['col_name'];
  980. $smcFunc['db_free_result']($request);
  981. // These are the theme changes...
  982. $themeSetArray = array();
  983. if (isset($_POST['options']) && is_array($_POST['options']))
  984. {
  985. foreach ($_POST['options'] as $opt => $val)
  986. {
  987. if (in_array($opt, $custom_fields))
  988. continue;
  989. // These need to be controlled.
  990. if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
  991. $val = max(0, min($val, 50));
  992. $themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
  993. }
  994. }
  995. $erase_options = array();
  996. if (isset($_POST['default_options']) && is_array($_POST['default_options']))
  997. foreach ($_POST['default_options'] as $opt => $val)
  998. {
  999. if (in_array($opt, $custom_fields))
  1000. continue;
  1001. // These need to be controlled.
  1002. if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
  1003. $val = max(0, min($val, 50));
  1004. $themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
  1005. $erase_options[] = $opt;
  1006. }
  1007. // If themeSetArray isn't still empty, send it to the database.
  1008. if (empty($context['password_auth_failed']))
  1009. {
  1010. if (!empty($themeSetArray))
  1011. {
  1012. $smcFunc['db_insert']('replace',
  1013. '{db_prefix}themes',
  1014. array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
  1015. $themeSetArray,
  1016. array('id_member', 'id_theme', 'variable')
  1017. );
  1018. }
  1019. if (!empty($erase_options))
  1020. {
  1021. $smcFunc['db_query']('', '
  1022. DELETE FROM {db_prefix}themes
  1023. WHERE id_theme != {int:id_theme}
  1024. AND variable IN ({array_string:erase_variables})
  1025. AND id_member = {int:id_member}',
  1026. array(
  1027. 'id_theme' => 1,
  1028. 'id_member' => $memID,
  1029. 'erase_variables' => $erase_options
  1030. )
  1031. );
  1032. }
  1033. $themes = explode(',', $modSettings['knownThemes']);
  1034. foreach ($themes as $t)
  1035. cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
  1036. }
  1037. }
  1038. // Make any notification changes that need to be made.
  1039. function makeNotificationChanges($memID)
  1040. {
  1041. global $smcFunc;
  1042. // Update the boards they are being notified on.
  1043. if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
  1044. {
  1045. // Make sure only integers are deleted.
  1046. foreach ($_POST['notify_boards'] as $index => $id)
  1047. $_POST['notify_boards'][$index] = (int) $id;
  1048. // id_board = 0 is reserved for topic notifications.
  1049. $_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
  1050. $smcFunc['db_query']('', '
  1051. DELETE FROM {db_prefix}log_notify
  1052. WHERE id_board IN ({array_int:board_list})
  1053. AND id_member = {int:selected_member}',
  1054. array(
  1055. 'board_list' => $_POST['notify_boards'],
  1056. 'selected_member' => $memID,
  1057. )
  1058. );
  1059. }
  1060. // We are editing topic notifications......
  1061. elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
  1062. {
  1063. foreach ($_POST['notify_topics'] as $index => $id)
  1064. $_POST['notify_topics'][$index] = (int) $id;
  1065. // Make sure there are no zeros left.
  1066. $_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
  1067. $smcFunc['db_query']('', '
  1068. DELETE FROM {db_prefix}log_notify
  1069. WHERE id_topic IN ({array_int:topic_list})
  1070. AND id_member = {int:selected_member}',
  1071. array(
  1072. 'topic_list' => $_POST['notify_topics'],
  1073. 'selected_member' => $memID,
  1074. )
  1075. );
  1076. }
  1077. }
  1078. // Save any changes to the custom profile fields...
  1079. function makeCustomFieldChanges($memID, $area, $sanitize = true)
  1080. {
  1081. global $context, $smcFunc, $user_profile, $user_info, $modSettings;
  1082. if ($sanitize && isset($_POST['customfield']))
  1083. $_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
  1084. $where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
  1085. // Load the fields we are saving too - make sure we save valid data (etc).
  1086. $request = $smcFunc['db_query']('', '
  1087. SELECT col_name, field_name, field_desc, field_type, field_length, field_options, default_value, show_reg, mask, private
  1088. FROM {db_prefix}custom_fields
  1089. WHERE ' . $where . '
  1090. AND active = {int:is_active}',
  1091. array(
  1092. 'is_active' => 1,
  1093. 'area' => $area,
  1094. )
  1095. );
  1096. $changes = array();
  1097. $log_changes = array();
  1098. while ($row = $smcFunc['db_fetch_assoc']($request))
  1099. {
  1100. /* This means don't save if:
  1101. - The user is NOT an admin.
  1102. - The data is not freely viewable and editable by users.
  1103. - The data is not invisible to users but editable by the owner (or if it is the user is not the owner)
  1104. - The area isn't registration, and if it is that the field is not suppossed to be shown there.
  1105. */
  1106. if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
  1107. continue;
  1108. // Validate the user data.
  1109. if ($row['field_type'] == 'check')
  1110. $value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
  1111. elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
  1112. {
  1113. $value = $row['default_value'];
  1114. foreach (explode(',', $row['field_options']) as $k => $v)
  1115. if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
  1116. $value = $v;
  1117. }
  1118. // Otherwise some form of text!
  1119. else
  1120. {
  1121. $value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
  1122. if ($row['field_length'])
  1123. $value = $smcFunc['substr']($value, 0, $row['field_length']);
  1124. // Any masks?
  1125. if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
  1126. {
  1127. //!!! We never error on this - just ignore it at the moment...
  1128. if ($row['mask'] == 'email' && (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $value) === 0 || strlen($value) > 255))
  1129. $value = '';
  1130. elseif ($row['mask'] == 'number')
  1131. {
  1132. $value = (int) $value;
  1133. }
  1134. elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
  1135. $value = '';
  1136. }
  1137. }
  1138. // Did it change?
  1139. if (!isset($user_profile[$memID]['options'][$row['col_name']]) || $user_profile[$memID]['options'][$row['col_name']] != $value)
  1140. {
  1141. $log_changes[] = array(
  1142. 'action' => 'customfield_' . $row['col_name'],
  1143. 'id_log' => 2,
  1144. 'log_time' => time(),
  1145. 'id_member' => $memID,
  1146. 'ip' => $user_info['ip'],
  1147. 'extra' => serialize(array('previous' => !empty($user_profile[$memID]['options'][$row['col_name']]) ? $user_profile[$memID]['options'][$row['col_name']] : '', 'new' => $value, 'applicator' => $user_info['id'])),
  1148. );
  1149. $changes[] = array(1, $row['col_name'], $value, $memID);
  1150. $user_profile[$memID]['options'][$row['col_name']] = $value;
  1151. }
  1152. }
  1153. $smcFunc['db_free_result']($request);
  1154. // Make those changes!
  1155. if (!empty($changes) && empty($context['password_auth_failed']))
  1156. {
  1157. $smcFunc['db_insert']('replace',
  1158. '{db_prefix}themes',
  1159. array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534', 'id_member' => 'int'),
  1160. $changes,
  1161. array('id_theme', 'variable', 'id_member')
  1162. );
  1163. if (!empty($log_changes) && !empty($modSettings['modlog_enabled']))
  1164. $smcFunc['db_insert']('',
  1165. '{db_prefix}log_actions',
  1166. array(
  1167. 'action' => 'string', 'id_log' => 'int', 'log_time' => 'int', 'id_member' => 'int', 'ip' => 'string-16',
  1168. 'extra' => 'string-65534',
  1169. ),
  1170. $log_changes,
  1171. array('id_action')
  1172. );
  1173. }
  1174. }
  1175. // Show all the users buddies, as well as a add/delete interface.
  1176. function editBuddyIgnoreLists($memID)
  1177. {
  1178. global $sourcedir, $context, $txt, $scripturl, $modSettings, $user_profile;
  1179. // Do a quick check to ensure people aren't getting here illegally!
  1180. if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
  1181. fatal_lang_error('no_access', false);
  1182. // Can we email the user direct?
  1183. $context['can_moderate_forum'] = allowedTo('moderate_forum');
  1184. $subActions = array(
  1185. 'buddies' => array('editBuddies', $txt['editBuddies']),
  1186. 'ignore' => array('editIgnoreList', $txt['editIgnoreList']),
  1187. );
  1188. $context['list_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'buddies';
  1189. // Create the tabs for the template.
  1190. $context[$context['profile_menu_name']]['tab_data'] = array(
  1191. 'title' => $txt['editBuddyIgnoreLists'],
  1192. 'description' => $txt['buddy_ignore_desc'],
  1193. 'icon' => 'profile_sm.gif',
  1194. 'tabs' => array(
  1195. 'buddies' => array(),
  1196. 'ignore' => array(),
  1197. ),
  1198. );
  1199. // Pass on to the actual function.
  1200. $context['sub_template'] = $subActions[$context['list_area']][0];
  1201. $subActions[$context['list_area']][0]($memID);
  1202. }
  1203. // Show all the users buddies, as well as a add/delete interface.
  1204. function editBuddies($memID)
  1205. {
  1206. global $txt, $scripturl, $modSettings;
  1207. global $context, $user_profile, $memberContext, $smcFunc;
  1208. // For making changes!
  1209. $buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
  1210. foreach ($buddiesArray as $k => $dummy)
  1211. if ($dummy == '')
  1212. unset($buddiesArray[$k]);
  1213. // Removing a buddy?
  1214. if (isset($_GET['remove']))
  1215. {
  1216. checkSession('get');
  1217. // Heh, I'm lazy, do it the easy way...
  1218. foreach ($buddiesArray as $key => $buddy)
  1219. if ($buddy == (int) $_GET['remove'])
  1220. unset($buddiesArray[$key]);
  1221. // Make the changes.
  1222. $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
  1223. updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list']));
  1224. // Redirect off the page because we don't like all this ugly query stuff to stick in the history.
  1225. redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
  1226. }
  1227. elseif (isset($_POST['new_buddy']))
  1228. {
  1229. // Prepare the string for extraction...
  1230. $_POST['new_buddy'] = strtr($smcFunc['htmlspecialchars']($_POST['new_buddy'], ENT_QUOTES), array('&quot;' => '"'));
  1231. preg_match_all('~"([^"]+)"~', $_POST['new_buddy'], $matches);
  1232. $new_buddies = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_buddy']))));
  1233. foreach ($new_buddies as $k => $dummy)
  1234. {
  1235. $new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '&#039;'));
  1236. if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
  1237. unset($new_buddies[$k]);
  1238. }
  1239. if (!empty($new_buddies))
  1240. {
  1241. // Now find out the id_member of the buddy.
  1242. $request = $smcFunc['db_query']('', '
  1243. SELECT id_member
  1244. FROM {db_prefix}members
  1245. WHERE member_name IN ({array_string:new_buddies}) OR real_name IN ({array_string:new_buddies})
  1246. LIMIT {int:count_new_buddies}',
  1247. array(
  1248. 'new_buddies' => $new_buddies,
  1249. 'count_new_buddies' => count($new_buddies),
  1250. )
  1251. );
  1252. // Add the new member to the buddies array.
  1253. while ($row = $smcFunc['db_fetch_assoc']($request))
  1254. $buddiesArray[] = (int) $row['id_member'];
  1255. $smcFunc['db_free_result']($request);
  1256. // Now update the current users buddy list.
  1257. $user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
  1258. updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list']));
  1259. }
  1260. // Back to the buddy list!
  1261. redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
  1262. }
  1263. // Get all the users "buddies"...
  1264. $buddies = array();
  1265. if (!empty($buddiesArray))
  1266. {
  1267. $result = $smcFunc['db_query']('', '
  1268. SELECT id_member
  1269. FROM {db_prefix}members
  1270. WHERE id_member IN ({array_int:buddy_list})
  1271. ORDER BY real_name
  1272. LIMIT {int:buddy_list_count}',
  1273. array(
  1274. 'buddy_list' => $buddiesArray,
  1275. 'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
  1276. )
  1277. );
  1278. while ($row = $smcFunc['db_fetch_assoc']($result))
  1279. $buddies[] = $row['id_member'];
  1280. $smcFunc['db_free_result']($result);
  1281. }
  1282. $context['buddy_count'] = count($buddies);
  1283. // Load all the members up.
  1284. loadMemberData($buddies, false, 'profile');
  1285. // Setup the context for each buddy.
  1286. $context['buddies'] = array();
  1287. foreach ($buddies as $buddy)
  1288. {
  1289. loadMemberContext($buddy);
  1290. $context['buddies'][$buddy] = $memberContext[$buddy];
  1291. }
  1292. }
  1293. // Allows the user to view their ignore list, as well as the option to manage members on it.
  1294. function editIgnoreList($memID)
  1295. {
  1296. global $txt, $scripturl, $modSettings;
  1297. global $context, $user_profile, $memberContext, $smcFunc;
  1298. // For making changes!
  1299. $ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
  1300. foreach ($ignoreArray as $k => $dummy)
  1301. if ($dummy == '')
  1302. unset($ignoreArray[$k]);
  1303. // Removing a member from the ignore list?
  1304. if (isset($_GET['remove']))
  1305. {
  1306. checkSession('get');
  1307. // Heh, I'm lazy, do it the easy way...
  1308. foreach ($ignoreArray as $key => $id_remove)
  1309. if ($id_remove == (int) $_GET['remove'])
  1310. unset($ignoreArray[$key]);
  1311. // Make the changes.
  1312. $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
  1313. updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
  1314. // Redirect off the page because we don't like all this ugly query stuff to stick in the history.
  1315. redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
  1316. }
  1317. elseif (isset($_POST['new_ignore']))
  1318. {
  1319. // Prepare the string for extraction...
  1320. $_POST['new_ignore'] = strtr($smcFunc['htmlspecialchars']($_POST['new_ignore'], ENT_QUOTES), array('&quot;' => '"'));
  1321. preg_match_all('~"([^"]+)"~', $_POST['new_ignore'], $matches);
  1322. $new_entries = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_ignore']))));
  1323. foreach ($new_entries as $k => $dummy)
  1324. {
  1325. $new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '&#039;'));
  1326. if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
  1327. unset($new_entries[$k]);
  1328. }
  1329. if (!empty($new_entries))
  1330. {
  1331. // Now find out the id_member for the members in question.
  1332. $request = $smcFunc['db_query']('', '
  1333. SELECT id_member
  1334. FROM {db_prefix}members
  1335. WHERE member_name IN ({array_string:new_entries}) OR real_name IN ({array_string:new_entries})
  1336. LIMIT {int:count_new_entries}',
  1337. array(
  1338. 'new_entries' => $new_entries,
  1339. 'count_new_entries' => count($new_entries),
  1340. )
  1341. );
  1342. // Add the new member to the buddies array.
  1343. while ($row = $smcFunc['db_fetch_assoc']($request))
  1344. $ignoreArray[] = (int) $row['id_member'];
  1345. $smcFunc['db_free_result']($request);
  1346. // Now update the current users buddy list.
  1347. $user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
  1348. updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
  1349. }
  1350. // Back to the list of pityful people!
  1351. redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
  1352. }
  1353. // Initialise the list of members we're ignoring.
  1354. $ignored = array();
  1355. if (!empty($ignoreArray))
  1356. {
  1357. $result = $smcFunc['db_query']('', '
  1358. SELECT id_member
  1359. FROM {db_prefix}members
  1360. WHERE id_member IN ({array_int:ignore_list})
  1361. ORDER BY real_name
  1362. LIMIT {int:ignore_list_count}',
  1363. array(
  1364. 'ignore_list' => $ignoreArray,
  1365. 'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
  1366. )
  1367. );
  1368. while ($row = $smcFunc['db_fetch_assoc']($result))
  1369. $ignored[] = $row['id_member'];
  1370. $smcFunc['db_free_result']($result);
  1371. }
  1372. $context['ignore_count'] = count($ignored);
  1373. // Load all the members up.
  1374. loadMemberData($ignored, false, 'profile');
  1375. // Setup the context for each buddy.
  1376. $context['ignore_list'] = array();
  1377. foreach ($ignored as $ignore_member)
  1378. {
  1379. loadMemberContext($ignore_member);
  1380. $context['ignore_list'][$ignore_member] = $memberContext[$ignore_member];
  1381. }
  1382. }
  1383. function account($memID)
  1384. {
  1385. global $context, $txt;
  1386. loadThemeOptions($memID);
  1387. if (allowedTo(array('profile_identity_own', 'profile_identity_any')))
  1388. loadCustomFields($memID, 'account');
  1389. $context['sub_template'] = 'edit_options';
  1390. $context['page_desc'] = $txt['account_info'];
  1391. setupProfileContext(
  1392. array(
  1393. 'member_name', 'real_name', 'date_registered', 'posts', 'lngfile', 'hr',
  1394. 'id_group', 'hr',
  1395. 'email_address', 'hide_email', 'show_online', 'hr',
  1396. 'passwrd1', 'passwrd2', 'hr',
  1397. 'secret_question', 'secret_answer',
  1398. )
  1399. );
  1400. }
  1401. function forumProfile($memID)
  1402. {
  1403. global $context, $user_profile, $user_info, $txt, $modSettings;
  1404. loadThemeOptions($memID);
  1405. if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
  1406. loadCustomFields($memID, 'forumprofile');
  1407. $context['sub_template'] = 'edit_options';
  1408. $context['page_desc'] = $txt['forumProfile_info'];
  1409. setupProfileContext(
  1410. array(
  1411. 'avatar_choice', 'hr', 'personal_text', 'hr',
  1412. 'bday1', 'location', 'gender', 'hr',
  1413. 'icq', 'aim', 'msn', 'yim', 'hr',
  1414. 'usertitle', 'signature', 'hr',
  1415. 'karma_good', 'hr',
  1416. 'website_title', 'website_url',
  1417. )
  1418. );
  1419. }
  1420. // Allow the edit of *someone elses* personal message settings.
  1421. function pmprefs($memID)
  1422. {
  1423. global $sourcedir, $context, $txt, $scripturl;
  1424. loadThemeOptions($memID);
  1425. loadCustomFields($memID, 'pmprefs');
  1426. $context['sub_template'] = 'edit_options';
  1427. $context['page_desc'] = $txt['pm_settings_desc'];
  1428. setupProfileContext(
  1429. array(
  1430. 'pm_prefs',
  1431. )
  1432. );
  1433. }
  1434. // Recursive function to retrieve avatar files
  1435. function getAvatars($directory, $level)
  1436. {
  1437. global $context, $txt, $modSettings;
  1438. $result = array();
  1439. // Open the directory..
  1440. $dir = dir($modSettings['avatar_directory'] . (!empty($directory) ? '/' : '') . $directory);
  1441. $dirs = array();
  1442. $files = array();
  1443. if (!$dir)
  1444. return array();
  1445. while ($line = $dir->read())
  1446. {
  1447. if (in_array($line, array('.', '..', 'blank.gif', 'index.php')))
  1448. continue;
  1449. if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
  1450. $dirs[] = $line;
  1451. else
  1452. $files[] = $line;
  1453. }
  1454. $dir->close();
  1455. // Sort the results...
  1456. natcasesort($dirs);
  1457. natcasesort($files);
  1458. if ($level == 0)
  1459. {
  1460. $result[] = array(
  1461. 'filename' => 'blank.gif',
  1462. 'checked' => in_array($context['member']['avatar']['server_pic'], array('', 'blank.gif')),
  1463. 'name' => $txt['no_pic'],
  1464. 'is_dir' => false
  1465. );
  1466. }
  1467. foreach ($dirs as $line)
  1468. {
  1469. $tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
  1470. if (!empty($tmp))
  1471. $result[] = array(
  1472. 'filename' => htmlspecialchars($line),
  1473. 'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
  1474. 'name' => '[' . htmlspecialchars(str_replace('_', ' ', $line)) . ']',
  1475. 'is_dir' => true,
  1476. 'files' => $tmp
  1477. );
  1478. unset($tmp);
  1479. }
  1480. foreach ($files as $line)
  1481. {
  1482. $filename = substr($line, 0, (strlen($line) - strlen(strrchr($line, '.'))));
  1483. $extension = substr(strrchr($line, '.'), 1);
  1484. // Make sure it is an image.
  1485. if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
  1486. continue;
  1487. $result[] = array(
  1488. 'filename' => htmlspecialchars($line),
  1489. 'checked' => $line == $context['member']['avatar']['server_pic'],
  1490. 'name' => htmlspecialchars(str_replace('_', ' ', $filename)),
  1491. 'is_dir' => false
  1492. );
  1493. if ($level == 1)
  1494. $context['avatar_list'][] = $directory . '/' . $line;
  1495. }
  1496. return $result;
  1497. }
  1498. function theme($memID)
  1499. {
  1500. global $txt, $context, $user_profile, $modSettings, $settings, $user_info, $smcFunc;
  1501. loadThemeOptions($memID);
  1502. if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
  1503. loadCustomFields($memID, 'theme');
  1504. $context['sub_template'] = 'edit_options';
  1505. $context['page_desc'] = $txt['theme_info'];
  1506. setupProfileContext(
  1507. array(
  1508. 'id_theme', 'smiley_set', 'hr',
  1509. 'time_format', 'time_offset', 'hr',
  1510. 'theme_settings',
  1511. )
  1512. );
  1513. }
  1514. // Changing authentication method? Only appropriate for people using OpenID.
  1515. function authentication($memID, $saving = false)
  1516. {
  1517. global $context, $cur_profile, $sourcedir, $txt, $post_errors, $modSettings;
  1518. loadLanguage('Login');
  1519. // We are saving?
  1520. if ($saving)
  1521. {
  1522. // Moving to password passed authentication?
  1523. if ($_POST['authenticate'] == 'passwd')
  1524. {
  1525. // Didn't enter anything?
  1526. if ($_POST['passwrd1'] == '')
  1527. $post_errors[] = 'no_password';
  1528. // Do the two entries for the password even match?
  1529. elseif (!isset($_POST['passwrd2']) || $_POST['passwrd1'] != $_POST['passwrd2'])
  1530. $post_errors[] = 'bad_new_password';
  1531. // Is it valid?
  1532. else
  1533. {
  1534. require_once($sourcedir . '/Subs-Auth.php');
  1535. $passwordErrors = validatePassword($_POST['passwrd1'], $cur_profile['member_name'], array($cur_profile['real_name'], $cur_profile['email_address']));
  1536. // Were there errors?
  1537. if ($passwordErrors != null)
  1538. $post_errors[] = 'password_' . $passwordErrors;
  1539. }
  1540. if (empty($post_errors))
  1541. {
  1542. // Integration?
  1543. call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd1']));
  1544. // Go then.
  1545. $passwd = sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd1']));
  1546. // Do the important bits.
  1547. updateMemberData($memID, array('openid_uri' => '', 'passwd' => $passwd));
  1548. if ($context['user']['is_owner'])
  1549. setLoginCookie(60 * $modSettings['cookieTime'], $memID, sha1(sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd2'])) . $cur_profile['password_salt']));
  1550. redirectexit('action=profile;u=' . $memID);
  1551. }
  1552. return true;
  1553. }
  1554. // Not right yet!
  1555. elseif ($_POST['authenticate'] == 'openid' && !empty($_POST['openid_identifier']))
  1556. {
  1557. require_once($sourcedir . '/Subs-OpenID.php');
  1558. $_POST['openid_identifier'] = smf_openID_canonize($_POST['openid_identifier']);
  1559. if (smf_openid_member_exists($_POST['openid_identifier']))
  1560. $post_errors[] = 'openid_in_use';
  1561. elseif (empty($post_errors))
  1562. {
  1563. // Authenticate using the new OpenID URI first to make sure they didn't make a mistake.
  1564. if ($context['user']['is_owner'])
  1565. {
  1566. $_SESSION['new_openid_uri'] = $_POST['openid_identifier'];
  1567. smf_openID_validate($_POST['openid_identifier'], false, null, 'change_uri');
  1568. }
  1569. else
  1570. updateMemberData($memID, array('openid_uri' => $_POST['openid_identifier']));
  1571. }
  1572. }
  1573. }
  1574. // Some stuff.
  1575. $context['member']['openid_uri'] = $cur_profile['openid_uri'];
  1576. $context['auth_method'] = empty($cur_profile['openid_uri']) ? 'password' : 'openid';
  1577. $context['sub_template'] = 'authentication_method';
  1578. }
  1579. // Display the notifications and settings for changes.
  1580. function notification($memID)
  1581. {
  1582. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
  1583. // Gonna want this for the list.
  1584. require_once($sourcedir . '/Subs-List.php');
  1585. // Fine, start with the board list.
  1586. $listOptions = array(
  1587. 'id' => 'board_notification_list',
  1588. 'width' => '100%',
  1589. 'no_items_label' => $txt['notifications_boards_none'] . '<br /><br />' . $txt['notifications_boards_howto'],
  1590. 'no_items_align' => 'left',
  1591. 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification',
  1592. 'default_sort_col' => 'board_name',
  1593. 'get_items' => array(
  1594. 'function' => 'list_getBoardNotifications',
  1595. 'params' => array(
  1596. $memID,
  1597. ),
  1598. ),
  1599. 'columns' => array(
  1600. 'board_name' => array(
  1601. 'header' => array(
  1602. 'value' => $txt['notifications_boards'],
  1603. 'class' => 'lefttext first_th',
  1604. ),
  1605. 'data' => array(
  1606. 'function' => create_function('$board', '
  1607. global $settings, $txt;
  1608. $link = $board[\'link\'];
  1609. if ($board[\'new\'])
  1610. $link .= \' <a href="\' . $board[\'href\'] . \'"><img src="\' . $settings[\'lang_images_url\'] . \'/new.gif" alt="\' . $txt[\'new\'] . \'" /></a>\';
  1611. return $link;
  1612. '),
  1613. ),
  1614. 'sort' => array(
  1615. 'default' => 'name',
  1616. 'reverse' => 'name DESC',
  1617. ),
  1618. ),
  1619. 'delete' => array(
  1620. 'header' => array(
  1621. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />',
  1622. 'style' => 'width: 4%;',
  1623. ),
  1624. 'data' => array(
  1625. 'sprintf' => array(
  1626. 'format' => '<input type="checkbox" name="notify_boards[]" value="%1$d" class="input_check" />',
  1627. 'params' => array(
  1628. 'id' => false,
  1629. ),
  1630. ),
  1631. 'style' => 'text-align: center;',
  1632. ),
  1633. ),
  1634. ),
  1635. 'form' => array(
  1636. 'href' => $scripturl . '?action=profile;area=notification;save',
  1637. 'include_sort' => true,
  1638. 'include_start' => true,
  1639. 'hidden_fields' => array(
  1640. 'u' => $memID,
  1641. 'sa' => $context['menu_item_selected'],
  1642. $context['session_var'] => $context['session_id'],
  1643. ),
  1644. ),
  1645. 'additional_rows' => array(
  1646. array(
  1647. 'position' => 'bottom_of_list',
  1648. 'value' => '<input type="submit" name="edit_notify_boards" value="' . $txt['notifications_update'] . '" class="button_submit" />',
  1649. 'align' => 'right',
  1650. ),
  1651. ),
  1652. );
  1653. // Create the board notification list.
  1654. createList($listOptions);
  1655. // Now do the topic notifications.
  1656. $listOptions = array(
  1657. 'id' => 'topic_notification_list',
  1658. 'width' => '100%',
  1659. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1660. 'no_items_label' => $txt['notifications_topics_none'] . '<br /><br />' . $txt['notifications_topics_howto'],
  1661. 'no_items_align' => 'left',
  1662. 'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification',
  1663. 'default_sort_col' => 'last_post',
  1664. 'get_items' => array(
  1665. 'function' => 'list_getTopicNotifications',
  1666. 'params' => array(
  1667. $memID,
  1668. ),
  1669. ),
  1670. 'get_count' => array(
  1671. 'function' => 'list_getTopicNotificationCount',
  1672. 'params' => array(
  1673. $memID,
  1674. ),
  1675. ),
  1676. 'columns' => array(
  1677. 'subject' => array(
  1678. 'header' => array(
  1679. 'value' => $txt['notifications_topics'],
  1680. 'class' => 'lefttext first_th',
  1681. ),
  1682. 'data' => array(
  1683. 'function' => create_function('$topic', '
  1684. global $settings, $txt;
  1685. $link = $topic[\'link\'];
  1686. if ($topic[\'new\'])
  1687. $link .= \' <a href="\' . $topic[\'new_href\'] . \'"><img src="\' . $settings[\'lang_images_url\'] . \'/new.gif" alt="\' . $txt[\'new\'] . \'" /></a>\';
  1688. $link .= \'<br /><span class="smalltext"><em>\' . $txt[\'in\'] . \' \' . $topic[\'board_link\'] . \'</em></span>\';
  1689. return $link;
  1690. '),
  1691. ),
  1692. 'sort' => array(
  1693. 'default' => 'ms.subject',
  1694. 'reverse' => 'ms.subject DESC',
  1695. ),
  1696. ),
  1697. 'started_by' => array(
  1698. 'header' => array(
  1699. 'value' => $txt['started_by'],
  1700. 'class' => 'lefttext',
  1701. ),
  1702. 'data' => array(
  1703. 'db' => 'poster_link',
  1704. ),
  1705. 'sort' => array(
  1706. 'default' => 'real_name_col',
  1707. 'reverse' => 'real_name_col DESC',
  1708. ),
  1709. ),
  1710. 'last_post' => array(
  1711. 'header' => array(
  1712. 'value' => $txt['last_post'],
  1713. 'class' => 'lefttext',
  1714. ),
  1715. 'data' => array(
  1716. 'sprintf' => array(
  1717. 'format' => '<span class="smalltext">%1$s<br />' . $txt['by'] . ' %2$s</span>',
  1718. 'params' => array(
  1719. 'updated' => false,
  1720. 'poster_updated_link' => false,
  1721. ),
  1722. ),
  1723. ),
  1724. 'sort' => array(
  1725. 'default' => 'ml.id_msg DESC',
  1726. 'reverse' => 'ml.id_msg',
  1727. ),
  1728. ),
  1729. 'delete' => array(
  1730. 'header' => array(
  1731. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />',
  1732. 'style' => 'width: 4%;',
  1733. ),
  1734. 'data' => array(
  1735. 'sprintf' => array(
  1736. 'format' => '<input type="checkbox" name="notify_topics[]" value="%1$d" class="input_check" />',
  1737. 'params' => array(
  1738. 'id' => false,
  1739. ),
  1740. ),
  1741. 'style' => 'text-align: center;',
  1742. ),
  1743. ),
  1744. ),
  1745. 'form' => array(
  1746. 'href' => $scripturl . '?action=profile;area=notification;save',
  1747. 'include_sort' => true,
  1748. 'include_start' => true,
  1749. 'hidden_fields' => array(
  1750. 'u' => $memID,
  1751. 'sa' => $context['menu_item_selected'],
  1752. $context['session_var'] => $context['session_id'],
  1753. ),
  1754. ),
  1755. 'additional_rows' => array(
  1756. array(
  1757. 'position' => 'bottom_of_list',
  1758. 'value' => '<input type="submit" name="edit_notify_topics" value="' . $txt['notifications_update'] . '" class="button_submit" />',
  1759. 'align' => 'right',
  1760. ),
  1761. ),
  1762. );
  1763. // Create the notification list.
  1764. createList($listOptions);
  1765. // What options are set?
  1766. $context['member'] += array(
  1767. 'notify_announcements' => $user_profile[$memID]['notify_announcements'],
  1768. 'notify_send_body' => $user_profile[$memID]['notify_send_body'],
  1769. 'notify_types' => $user_profile[$memID]['notify_types'],
  1770. 'notify_regularity' => $user_profile[$memID]['notify_regularity'],
  1771. );
  1772. loadThemeOptions($memID);
  1773. }
  1774. function list_getTopicNotificationCount($memID)
  1775. {
  1776. global $smcFunc, $user_info, $context, $modSettings;
  1777. $request = $smcFunc['db_query']('', '
  1778. SELECT COUNT(*)
  1779. FROM {db_prefix}log_notify AS ln' . (!$modSettings['postmod_active'] && $user_info['query_see_board'] === '1=1' ? '' : '
  1780. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)') . ($user_info['query_see_board'] === '1=1' ? '' : '
  1781. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)') . '
  1782. WHERE ln.id_member = {int:selected_member}' . ($user_info['query_see_board'] === '1=1' ? '' : '
  1783. AND {query_see_board}') . ($modSettings['postmod_active'] ? '
  1784. AND t.approved = {int:is_approved}' : ''),
  1785. array(
  1786. 'selected_member' => $memID,
  1787. 'is_approved' => 1,
  1788. )
  1789. );
  1790. list ($totalNotifications) = $smcFunc['db_fetch_row']($request);
  1791. $smcFunc['db_free_result']($request);
  1792. return $totalNotifications;
  1793. }
  1794. function list_getTopicNotifications($start, $items_per_page, $sort, $memID)
  1795. {
  1796. global $smcFunc, $txt, $scripturl, $user_info, $context, $modSettings;
  1797. // All the topics with notification on...
  1798. $request = $smcFunc['db_query']('', '
  1799. SELECT
  1800. IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from, b.id_board, b.name,
  1801. t.id_topic, ms.subject, ms.id_member, IFNULL(mem.real_name, ms.poster_name) AS real_name_col,
  1802. ml.id_msg_modified, ml.poster_time, ml.id_member AS id_member_updated,
  1803. IFNULL(mem2.real_name, ml.poster_name) AS last_real_name
  1804. FROM {db_prefix}log_notify AS ln
  1805. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ')
  1806. INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})
  1807. INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
  1808. INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
  1809. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ms.id_member)
  1810. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = ml.id_member)
  1811. LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
  1812. LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})
  1813. WHERE ln.id_member = {int:selected_member}
  1814. ORDER BY {raw:sort}
  1815. LIMIT {int:offset}, {int:items_per_page}',
  1816. array(
  1817. 'current_member' => $user_info['id'],
  1818. 'is_approved' => 1,
  1819. 'selected_member' => $memID,
  1820. 'sort' => $sort,
  1821. 'offset' => $start,
  1822. 'items_per_page' => $items_per_page,
  1823. )
  1824. );
  1825. $notification_topics = array();
  1826. while ($row = $smcFunc['db_fetch_assoc']($request))
  1827. {
  1828. censorText($row['subject']);
  1829. $notification_topics[] = array(
  1830. 'id' => $row['id_topic'],
  1831. 'poster_link' => empty($row['id_member']) ? $row['real_name_col'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name_col'] . '</a>',
  1832. 'poster_updated_link' => empty($row['id_member_updated']) ? $row['last_real_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_updated'] . '">' . $row['last_real_name'] . '</a>',
  1833. 'subject' => $row['subject'],
  1834. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
  1835. 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>',
  1836. 'new' => $row['new_from'] <= $row['id_msg_modified'],
  1837. 'new_from' => $row['new_from'],
  1838. 'updated' => timeformat($row['poster_time']),
  1839. 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new',
  1840. 'new_link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new">' . $row['subject'] . '</a>',
  1841. 'board_link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  1842. );
  1843. }
  1844. $smcFunc['db_free_result']($request);
  1845. return $notification_topics;
  1846. }
  1847. function list_getBoardNotifications($start, $items_per_page, $sort, $memID)
  1848. {
  1849. global $smcFunc, $txt, $scripturl, $user_info;
  1850. $request = $smcFunc['db_query']('', '
  1851. SELECT b.id_board, b.name, IFNULL(lb.id_msg, 0) AS board_read, b.id_msg_updated
  1852. FROM {db_prefix}log_notify AS ln
  1853. INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board)
  1854. LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
  1855. WHERE ln.id_member = {int:selected_member}
  1856. AND {query_see_board}
  1857. ORDER BY ' . $sort,
  1858. array(
  1859. 'current_member' => $user_info['id'],
  1860. 'selected_member' => $memID,
  1861. )
  1862. );
  1863. $notification_boards = array();
  1864. while ($row = $smcFunc['db_fetch_assoc']($request))
  1865. $notification_boards[] = array(
  1866. 'id' => $row['id_board'],
  1867. 'name' => $row['name'],
  1868. 'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
  1869. 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
  1870. 'new' => $row['board_read'] < $row['id_msg_updated']
  1871. );
  1872. $smcFunc['db_free_result']($request);
  1873. return $notification_boards;
  1874. }
  1875. function loadThemeOptions($memID)
  1876. {
  1877. global $context, $options, $cur_profile, $smcFunc;
  1878. if (isset($_POST['default_options']))
  1879. $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
  1880. if ($context['user']['is_owner'])
  1881. {
  1882. $context['member']['options'] = $options;
  1883. if (isset($_POST['options']) && is_array($_POST['options']))
  1884. foreach ($_POST['options'] as $k => $v)
  1885. $context['member']['options'][$k] = $v;
  1886. }
  1887. else
  1888. {
  1889. $request = $smcFunc['db_query']('', '
  1890. SELECT id_member, variable, value
  1891. FROM {db_prefix}themes
  1892. WHERE id_theme IN (1, {int:member_theme})
  1893. AND id_member IN (-1, {int:selected_member})',
  1894. array(
  1895. 'member_theme' => (int) $cur_profile['id_theme'],
  1896. 'selected_member' => $memID,
  1897. )
  1898. );
  1899. $temp = array();
  1900. while ($row = $smcFunc['db_fetch_assoc']($request))
  1901. {
  1902. if ($row['id_member'] == -1)
  1903. {
  1904. $temp[$row['variable']] = $row['value'];
  1905. continue;
  1906. }
  1907. if (isset($_POST['options'][$row['variable']]))
  1908. $row['value'] = $_POST['options'][$row['variable']];
  1909. $context['member']['options'][$row['variable']] = $row['value'];
  1910. }
  1911. $smcFunc['db_free_result']($request);
  1912. // Load up the default theme options for any missing.
  1913. foreach ($temp as $k => $v)
  1914. {
  1915. if (!isset($context['member']['options'][$k]))
  1916. $context['member']['options'][$k] = $v;
  1917. }
  1918. }
  1919. }
  1920. function ignoreboards($memID)
  1921. {
  1922. global $txt, $user_info, $context, $modSettings, $smcFunc, $cur_profile;
  1923. // Have the admins enabled this option?
  1924. if (empty($modSettings['allow_ignore_boards']))
  1925. fatal_lang_error('ignoreboards_disallowed', 'user');
  1926. // Find all the boards this user is allowed to see.
  1927. $request = $smcFunc['db_query']('order_by_board_order', '
  1928. SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level,
  1929. '. (!empty($cur_profile['ignore_boards']) ? 'b.id_board IN ({array_int:ignore_boards})' : '0') . ' AS is_ignored
  1930. FROM {db_prefix}boards AS b
  1931. LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
  1932. WHERE {query_see_board}
  1933. AND redirect = {string:empty_string}',
  1934. array(
  1935. 'ignore_boards' => !empty($cur_profile['ignore_boards']) ? explode(',', $cur_profile['ignore_boards']) : array(),
  1936. 'empty_string' => '',
  1937. )
  1938. );
  1939. $context['num_boards'] = $smcFunc['db_num_rows']($request);
  1940. $context['categories'] = array();
  1941. while ($row = $smcFunc['db_fetch_assoc']($request))
  1942. {
  1943. // This category hasn't been set up yet..
  1944. if (!isset($context['categories'][$row['id_cat']]))
  1945. $context['categories'][$row['id_cat']] = array(
  1946. 'id' => $row['id_cat'],
  1947. 'name' => $row['cat_name'],
  1948. 'boards' => array()
  1949. );
  1950. // Set this board up, and let the template know when it's a child. (indent them..)
  1951. $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
  1952. 'id' => $row['id_board'],
  1953. 'name' => $row['name'],
  1954. 'child_level' => $row['child_level'],
  1955. 'selected' => $row['is_ignored'],
  1956. );
  1957. }
  1958. $smcFunc['db_free_result']($request);
  1959. // Now, let's sort the list of categories into the boards for templates that like that.
  1960. $temp_boards = array();
  1961. foreach ($context['categories'] as $category)
  1962. {
  1963. // Include a list of boards per category for easy toggling.
  1964. $context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
  1965. $temp_boards[] = array(
  1966. 'name' => $category['name'],
  1967. 'child_ids' => array_keys($category['boards'])
  1968. );
  1969. $temp_boards = array_merge($temp_boards, array_values($category['boards']));
  1970. }
  1971. $max_boards = ceil(count($temp_boards) / 2);
  1972. if ($max_boards == 1)
  1973. $max_boards = 2;
  1974. // Now, alternate them so they can be shown left and right ;).
  1975. $context['board_columns'] = array();
  1976. for ($i = 0; $i < $max_boards; $i++)
  1977. {
  1978. $context['board_columns'][] = $temp_boards[$i];
  1979. if (isset($temp_boards[$i + $max_boards]))
  1980. $context['board_columns'][] = $temp_boards[$i + $max_boards];
  1981. else
  1982. $context['board_columns'][] = array();
  1983. }
  1984. loadThemeOptions($memID);
  1985. }
  1986. // Load all the languages for the profile.
  1987. function profileLoadLanguages()
  1988. {
  1989. global $context, $modSettings, $settings, $cur_profile, $language, $smcFunc;
  1990. $context['profile_languages'] = array();
  1991. // Get our languages!
  1992. getLanguages(true, true);
  1993. // Setup our languages.
  1994. foreach ($context['languages'] as $lang)
  1995. {
  1996. $context['profile_languages'][$lang['filename']] = strtr($lang['name'], array('-utf8' => ''));
  1997. }
  1998. ksort($context['profile_languages']);
  1999. // Return whether we should proceed with this.
  2000. return count($context['profile_languages']) > 1 ? true : false;
  2001. }
  2002. // Load all the group info for the profile.
  2003. function profileLoadGroups()
  2004. {
  2005. global $cur_profile, $txt, $context, $smcFunc, $user_settings;
  2006. $context['member_groups'] = array(
  2007. 0 => array(
  2008. 'id' => 0,
  2009. 'name' => $txt['no_primary_membergroup'],
  2010. 'is_primary' => $cur_profile['id_group'] == 0,
  2011. 'can_be_additional' => false,
  2012. 'can_be_primary' => true,
  2013. )
  2014. );
  2015. $curGroups = explode(',', $cur_profile['additional_groups']);
  2016. // Load membergroups, but only those groups the user can assign.
  2017. $request = $smcFunc['db_query']('', '
  2018. SELECT group_name, id_group, hidden
  2019. FROM {db_prefix}membergroups
  2020. WHERE id_group != {int:moderator_group}
  2021. AND min_posts = {int:min_posts}' . (allowedTo('admin_forum') ? '' : '
  2022. AND group_type != {int:is_protected}') . '
  2023. ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
  2024. array(
  2025. 'moderator_group' => 3,
  2026. 'min_posts' => -1,
  2027. 'is_protected' => 1,
  2028. 'newbie_group' => 4,
  2029. )
  2030. );
  2031. while ($row = $smcFunc['db_fetch_assoc']($request))
  2032. {
  2033. // We should skip the administrator group if they don't have the admin_forum permission!
  2034. if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
  2035. continue;
  2036. $context['member_groups'][$row['id_group']] = array(
  2037. 'id' => $row['id_group'],
  2038. 'name' => $row['group_name'],
  2039. 'is_primary' => $cur_profile['id_group'] == $row['id_group'],
  2040. 'is_additional' => in_array($row['id_group'], $curGroups),
  2041. 'can_be_additional' => true,
  2042. 'can_be_primary' => $row['hidden'] != 2,
  2043. );
  2044. }
  2045. $smcFunc['db_free_result']($request);
  2046. $context['member']['group_id'] = $user_settings['id_group'];
  2047. return true;
  2048. }
  2049. // Load key signature context data.
  2050. function profileLoadSignatureData()
  2051. {
  2052. global $modSettings, $context, $txt, $cur_profile, $smcFunc;
  2053. // Signature limits.
  2054. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  2055. $sig_limits = explode(',', $sig_limits);
  2056. $context['signature_enabled'] = isset($sig_limits[0]) ? $sig_limits[0] : 0;
  2057. $context['signature_limits'] = array(
  2058. 'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
  2059. 'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
  2060. 'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
  2061. 'max_smileys' => isset($sig_limits[4]) ? $sig_limits[4] : 0,
  2062. 'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
  2063. 'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
  2064. 'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
  2065. 'bbc' => !empty($sig_bbc) ? explode(',', $sig_bbc) : array(),
  2066. );
  2067. // Kept this line in for backwards compatibility!
  2068. $context['max_signature_length'] = $context['signature_limits']['max_length'];
  2069. // Warning message for signature image limits?
  2070. $context['signature_warning'] = '';
  2071. if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
  2072. $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
  2073. elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
  2074. $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
  2075. $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new');
  2076. $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br />', '<', '>', '"', '\''), array("\n", '&lt;', '&gt;', '&quot;', '&#039;'), $cur_profile['signature']);
  2077. return true;
  2078. }
  2079. // Load avatar context data.
  2080. function profileLoadAvatarData()
  2081. {
  2082. global $context, $cur_profile, $modSettings, $scripturl;
  2083. $context['avatar_url'] = $modSettings['avatar_url'];
  2084. // Default context.
  2085. $context['member']['avatar'] += array(
  2086. 'custom' => stristr($cur_profile['avatar'], 'http://') ? $cur_profile['avatar'] : 'http://',
  2087. 'selection' => $cur_profile['avatar'] == '' || stristr($cur_profile['avatar'], 'http://') ? '' : $cur_profile['avatar'],
  2088. 'id_attach' => $cur_profile['id_attach'],
  2089. 'filename' => $cur_profile['filename'],
  2090. 'allow_server_stored' => allowedTo('profile_server_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2091. 'allow_upload' => allowedTo('profile_upload_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2092. 'allow_external' => allowedTo('profile_remote_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any')),
  2093. );
  2094. if ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
  2095. {
  2096. $context['member']['avatar'] += array(
  2097. 'choice' => 'upload',
  2098. 'server_pic' => 'blank.gif',
  2099. 'external' => 'http://'
  2100. );
  2101. $context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
  2102. }
  2103. elseif (stristr($cur_profile['avatar'], 'http://') && $context['member']['avatar']['allow_external'])
  2104. $context['member']['avatar'] += array(
  2105. 'choice' => 'external',
  2106. 'server_pic' => 'blank.gif',
  2107. 'external' => $cur_profile['avatar']
  2108. );
  2109. elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
  2110. $context['member']['avatar'] += array(
  2111. 'choice' => 'server_stored',
  2112. 'server_pic' => $cur_profile['avatar'] == '' ? 'blank.gif' : $cur_profile['avatar'],
  2113. 'external' => 'http://'
  2114. );
  2115. else
  2116. $context['member']['avatar'] += array(
  2117. 'choice' => 'none',
  2118. 'server_pic' => 'blank.gif',
  2119. 'external' => 'http://'
  2120. );
  2121. // Get a list of all the avatars.
  2122. if ($context['member']['avatar']['allow_server_stored'])
  2123. {
  2124. $context['avatar_list'] = array();
  2125. $context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
  2126. }
  2127. else
  2128. $context['avatars'] = array();
  2129. // Second level selected avatar...
  2130. $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
  2131. return true;
  2132. }
  2133. // Save a members group.
  2134. function profileSaveGroups(&$value)
  2135. {
  2136. global $profile_vars, $old_profile, $context, $smcFunc, $cur_profile;
  2137. // Do we need to protect some groups?
  2138. if (!allowedTo('admin_forum'))
  2139. {
  2140. $request = $smcFunc['db_query']('', '
  2141. SELECT id_group
  2142. FROM {db_prefix}membergroups
  2143. WHERE group_type = {int:is_protected}',
  2144. array(
  2145. 'is_protected' => 1,
  2146. )
  2147. );
  2148. $protected_groups = array(1);
  2149. while ($row = $smcFunc['db_fetch_assoc']($request))
  2150. $protected_groups[] = $row['id_group'];
  2151. $smcFunc['db_free_result']($request);
  2152. $protected_groups = array_unique($protected_groups);
  2153. }
  2154. // The account page allows the change of your id_group - but not to a protected group!
  2155. if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
  2156. $value = (int) $value;
  2157. // ... otherwise it's the old group sir.
  2158. else
  2159. $value = $old_profile['id_group'];
  2160. // Find the additional membergroups (if any)
  2161. if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
  2162. {
  2163. $additional_groups = array();
  2164. foreach ($_POST['additional_groups'] as $group_id)
  2165. {
  2166. $group_id = (int) $group_id;
  2167. if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
  2168. $additional_groups[] = $group_id;
  2169. }
  2170. // Put the protected groups back in there if you don't have permission to take them away.
  2171. $old_additional_groups = explode(',', $old_profile['additional_groups']);
  2172. foreach ($old_additional_groups as $group_id)
  2173. {
  2174. if (!empty($protected_groups) && in_array($group_id, $protected_groups))
  2175. $additional_groups[] = $group_id;
  2176. }
  2177. if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
  2178. {
  2179. $profile_vars['additional_groups'] = implode(',', $additional_groups);
  2180. $cur_profile['additional_groups'] = implode(',', $additional_groups);
  2181. }
  2182. }
  2183. // Too often, people remove delete their own account, or something.
  2184. if (in_array(1, explode(',', $old_profile['additional_groups'])) || $old_profile['id_group'] == 1)
  2185. {
  2186. $stillAdmin = $value == 1 || (isset($additional_groups) && in_array(1, $additional_groups));
  2187. // If they would no longer be an admin, look for any other...
  2188. if (!$stillAdmin)
  2189. {
  2190. $request = $smcFunc['db_query']('', '
  2191. SELECT id_member
  2192. FROM {db_prefix}members
  2193. WHERE (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0)
  2194. AND id_member != {int:selected_member}
  2195. LIMIT 1',
  2196. array(
  2197. 'admin_group' => 1,
  2198. 'selected_member' => $context['id_member'],
  2199. )
  2200. );
  2201. list ($another) = $smcFunc['db_fetch_row']($request);
  2202. $smcFunc['db_free_result']($request);
  2203. if (empty($another))
  2204. fatal_lang_error('at_least_one_admin', 'critical');
  2205. }
  2206. }
  2207. // If we are changing group status, update permission cache as necessary.
  2208. if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
  2209. {
  2210. if ($context['user']['is_owner'])
  2211. $_SESSION['mc']['time'] = 0;
  2212. else
  2213. updateSettings(array('settings_updated' => time()));
  2214. }
  2215. return true;
  2216. }
  2217. // The avatar is incredibly complicated, what with the options... and what not.
  2218. function profileSaveAvatarData(&$value)
  2219. {
  2220. global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
  2221. $memID = $context['id_member'];
  2222. if (empty($memID) && !empty($context['password_auth_failed']))
  2223. return false;
  2224. require_once($sourcedir . '/ManageAttachments.php');
  2225. // We need to know where we're going to be putting it..
  2226. if (!empty($modSettings['custom_avatar_enabled']))
  2227. {
  2228. $uploadDir = $modSettings['custom_avatar_dir'];
  2229. $id_folder = 1;
  2230. }
  2231. elseif (!empty($modSettings['currentAttachmentUploadDir']))
  2232. {
  2233. if (!is_array($modSettings['attachmentUploadDir']))
  2234. $modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
  2235. // Just use the current path for temp files.
  2236. $uploadDir = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
  2237. $id_folder = $modSettings['currentAttachmentUploadDir'];
  2238. }
  2239. else
  2240. {
  2241. $uploadDir = $modSettings['attachmentUploadDir'];
  2242. $id_folder = 1;
  2243. }
  2244. $downloadedExternalAvatar = false;
  2245. if ($value == 'external' && allowedTo('profile_remote_avatar') && strtolower(substr($_POST['userpicpersonal'], 0, 7)) == 'http://' && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
  2246. {
  2247. if (!is_writable($uploadDir))
  2248. fatal_lang_error('attachments_no_write', 'critical');
  2249. require_once($sourcedir . '/Subs-Package.php');
  2250. $url = parse_url($_POST['userpicpersonal']);
  2251. $contents = fetch_web_data('http://' . $url['host'] . (empty($url['port']) ? '' : ':' . $url['port']) . str_replace(' ', '%20', trim($url['path'])));
  2252. $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
  2253. if ($contents != false && $tmpAvatar = fopen($new_filename, 'wb'))
  2254. {
  2255. fwrite($tmpAvatar, $contents);
  2256. fclose($tmpAvatar);
  2257. $downloadedExternalAvatar = true;
  2258. $_FILES['attachment']['tmp_name'] = $new_filename;
  2259. }
  2260. }
  2261. if ($value == 'none')
  2262. {
  2263. $profile_vars['avatar'] = '';
  2264. // Reset the attach ID.
  2265. $cur_profile['id_attach'] = 0;
  2266. $cur_profile['attachment_type'] = 0;
  2267. $cur_profile['filename'] = '';
  2268. removeAttachments(array('id_member' => $memID));
  2269. }
  2270. elseif ($value == 'server_stored' && allowedTo('profile_server_avatar'))
  2271. {
  2272. $profile_vars['avatar'] = strtr(empty($_POST['file']) ? (empty($_POST['cat']) ? '' : $_POST['cat']) : $_POST['file'], array('&amp;' => '&'));
  2273. $profile_vars['avatar'] = preg_match('~^([\w _!@%*=\-#()\[\]&.,]+/)?[\w _!@%*=\-#()\[\]&.,]+$~', $profile_vars['avatar']) != 0 && preg_match('/\.\./', $profile_vars['avatar']) == 0 && file_exists($modSettings['avatar_directory'] . '/' . $profile_vars['avatar']) ? ($profile_vars['avatar'] == 'blank.gif' ? '' : $profile_vars['avatar']) : '';
  2274. // Clear current profile...
  2275. $cur_profile['id_attach'] = 0;
  2276. $cur_profile['attachment_type'] = 0;
  2277. $cur_profile['filename'] = '';
  2278. // Get rid of their old avatar. (if uploaded.)
  2279. removeAttachments(array('id_member' => $memID));
  2280. }
  2281. elseif ($value == 'external' && allowedTo('profile_remote_avatar') && strtolower(substr($_POST['userpicpersonal'], 0, 7)) == 'http://' && empty($modSettings['avatar_download_external']))
  2282. {
  2283. // We need these clean...
  2284. $cur_profile['id_attach'] = 0;
  2285. $cur_profile['attachment_type'] = 0;
  2286. $cur_profile['filename'] = '';
  2287. // Remove any attached avatar...
  2288. removeAttachments(array('id_member' => $memID));
  2289. $profile_vars['avatar'] = str_replace('%20', '', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
  2290. if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
  2291. $profile_vars['avatar'] = '';
  2292. // Trying to make us do something we'll regret?
  2293. elseif (substr($profile_vars['avatar'], 0, 7) != 'http://')
  2294. return 'bad_avatar';
  2295. // Should we check dimensions?
  2296. elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
  2297. {
  2298. // Now let's validate the avatar.
  2299. $sizes = url_image_size($profile_vars['avatar']);
  2300. if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
  2301. {
  2302. // Houston, we have a problem. The avatar is too large!!
  2303. if ($modSettings['avatar_action_too_large'] == 'option_refuse')
  2304. return 'bad_avatar';
  2305. elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
  2306. {
  2307. require_once($sourcedir . '/Subs-Graphics.php');
  2308. if (downloadAvatar($profile_vars['avatar'], $memID, $modSettings['avatar_max_width_external'], $modSettings['avatar_max_height_external']))
  2309. {
  2310. $profile_vars['avatar'] = '';
  2311. $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
  2312. $cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
  2313. $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
  2314. }
  2315. else
  2316. return 'bad_avatar';
  2317. }
  2318. }
  2319. }
  2320. }
  2321. elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
  2322. {
  2323. if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
  2324. {
  2325. // Get the dimensions of the image.
  2326. if (!$downloadedExternalAvatar)
  2327. {
  2328. if (!is_writable($uploadDir))
  2329. fatal_lang_error('attachments_no_write', 'critical');
  2330. $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
  2331. if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
  2332. fatal_lang_error('attach_timeout', 'critical');
  2333. $_FILES['attachment']['tmp_name'] = $new_filename;
  2334. }
  2335. $sizes = @getimagesize($_FILES['attachment']['tmp_name']);
  2336. // No size, then it's probably not a valid pic.
  2337. // No size, then it's probably not a valid pic.
  2338. if ($sizes === false)
  2339. {
  2340. @unlink($_FILES['attachment']['tmp_name']);
  2341. return 'bad_avatar';
  2342. }
  2343. // Check whether the image is too large.
  2344. elseif ((!empty($modSettings['avatar_max_width_upload']) && $sizes[0] > $modSettings['avatar_max_width_upload']) || (!empty($modSettings['avatar_max_height_upload']) && $sizes[1] > $modSettings['avatar_max_height_upload']))
  2345. {
  2346. if (!empty($modSettings['avatar_resize_upload']))
  2347. {
  2348. // Attempt to chmod it.
  2349. @chmod($_FILES['attachment']['tmp_name'], 0644);
  2350. require_once($sourcedir . '/Subs-Graphics.php');
  2351. if (!downloadAvatar($_FILES['attachment']['tmp_name'], $memID, $modSettings['avatar_max_width_upload'], $modSettings['avatar_max_height_upload']))
  2352. {
  2353. @unlink($_FILES['attachment']['tmp_name']);
  2354. return 'bad_avatar';
  2355. }
  2356. // Reset attachment avatar data.
  2357. $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
  2358. $cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
  2359. $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
  2360. }
  2361. else
  2362. {
  2363. @unlink($_FILES['attachment']['tmp_name']);
  2364. return 'bad_avatar';
  2365. }
  2366. }
  2367. elseif (is_array($sizes))
  2368. {
  2369. // Now try to find an infection.
  2370. require_once($sourcedir . '/Subs-Graphics.php');
  2371. if (!checkImageContents($_FILES['attachment']['tmp_name'], !empty($modSettings['avatar_paranoid'])))
  2372. {
  2373. // It's bad. Try to re-encode the contents?
  2374. if (empty($modSettings['avatar_reencode']) || (!reencodeImage($_FILES['attachment']['tmp_name'], $sizes[2])))
  2375. {
  2376. @unlink($_FILES['attachment']['tmp_name']);
  2377. return 'bad_avatar';
  2378. }
  2379. // We were successful. However, at what price?
  2380. $sizes = @getimagesize($_FILES['attachment']['tmp_name']);
  2381. // Hard to believe this would happen, but can you bet?
  2382. if ($sizes === false)
  2383. {
  2384. @unlink($_FILES['attachment']['tmp_name']);
  2385. return 'bad_avatar';
  2386. }
  2387. }
  2388. $extensions = array(
  2389. '1' => 'gif',
  2390. '2' => 'jpg',
  2391. '3' => 'png',
  2392. '6' => 'bmp'
  2393. );
  2394. $extension = isset($extensions[$sizes[2]]) ? $extensions[$sizes[2]] : 'bmp';
  2395. $mime_type = 'image/' . ($extension === 'jpg' ? 'jpeg' : ($extension === 'bmp' ? 'x-ms-bmp' : $extension));
  2396. $destName = 'avatar_' . $memID . '_' . time() . '.' . $extension;
  2397. list ($width, $height) = getimagesize($_FILES['attachment']['tmp_name']);
  2398. $file_hash = empty($modSettings['custom_avatar_enabled']) ? getAttachmentFilename($destName, false, null, true) : '';
  2399. // Remove previous attachments this member might have had.
  2400. removeAttachments(array('id_member' => $memID));
  2401. $smcFunc['db_insert']('',
  2402. '{db_prefix}attachments',
  2403. array(
  2404. 'id_member' => 'int', 'attachment_type' => 'int', 'filename' => 'string', 'file_hash' => 'string', 'fileext' => 'string', 'size' => 'int',
  2405. 'width' => 'int', 'height' => 'int', 'mime_type' => 'string', 'id_folder' => 'int',
  2406. ),
  2407. array(
  2408. $memID, (empty($modSettings['custom_avatar_enabled']) ? 0 : 1), $destName, $file_hash, $extension, filesize($_FILES['attachment']['tmp_name']),
  2409. (int) $width, (int) $height, $mime_type, $id_folder,
  2410. ),
  2411. array('id_attach')
  2412. );
  2413. $cur_profile['id_attach'] = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
  2414. $cur_profile['filename'] = $destName;
  2415. $cur_profile['attachment_type'] = empty($modSettings['custom_avatar_enabled']) ? 0 : 1;
  2416. $destinationPath = $uploadDir . '/' . (empty($file_hash) ? $destName : $cur_profile['id_attach'] . '_' . $file_hash);
  2417. if (!rename($_FILES['attachment']['tmp_name'], $destinationPath))
  2418. {
  2419. // I guess a man can try.
  2420. removeAttachments(array('id_member' => $memID));
  2421. fatal_lang_error('attach_timeout', 'critical');
  2422. }
  2423. // Attempt to chmod it.
  2424. @chmod($uploadDir . '/' . $destinationPath, 0644);
  2425. }
  2426. $profile_vars['avatar'] = '';
  2427. // Delete any temporary file.
  2428. if (file_exists($_FILES['attachment']['tmp_name']))
  2429. @unlink($_FILES['attachment']['tmp_name']);
  2430. }
  2431. // Selected the upload avatar option and had one already uploaded before or didn't upload one.
  2432. else
  2433. $profile_vars['avatar'] = '';
  2434. }
  2435. else
  2436. $profile_vars['avatar'] = '';
  2437. // Setup the profile variables so it shows things right on display!
  2438. $cur_profile['avatar'] = $profile_vars['avatar'];
  2439. return false;
  2440. }
  2441. // Validate the signature!
  2442. function profileValidateSignature(&$value)
  2443. {
  2444. global $sourcedir, $modSettings, $smcFunc, $txt;
  2445. require_once($sourcedir . '/Subs-Post.php');
  2446. // Admins can do whatever they hell they want!
  2447. if (!allowedTo('admin_forum'))
  2448. {
  2449. // Load all the signature limits.
  2450. list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
  2451. $sig_limits = explode(',', $sig_limits);
  2452. $disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
  2453. $unparsed_signature = strtr(un_htmlspecialchars($value), array("\r" => '', '&#039' => '\''));
  2454. // Too long?
  2455. if (!empty($sig_limits[1]) && $smcFunc['strlen']($unparsed_signature) > $sig_limits[1])
  2456. {
  2457. $_POST['signature'] = trim(htmlspecialchars($smcFunc['substr']($unparsed_signature, 0, $sig_limits[1]), ENT_QUOTES));
  2458. $txt['profile_error_signature_max_length'] = sprintf($txt['profile_error_signature_max_length'], $sig_limits[1]);
  2459. return 'signature_max_length';
  2460. }
  2461. // Too many lines?
  2462. if (!empty($sig_limits[2]) && substr_count($unparsed_signature, "\n") >= $sig_limits[2])
  2463. {
  2464. $txt['profile_error_signature_max_lines'] = sprintf($txt['profile_error_signature_max_lines'], $sig_limits[2]);
  2465. return 'signature_max_lines';
  2466. }
  2467. // Too many images?!
  2468. if (!empty($sig_limits[3]) && (substr_count(strtolower($unparsed_signature), '[img') + substr_count(strtolower($unparsed_signature), '<img')) > $sig_limits[3])
  2469. {
  2470. $txt['profile_error_signature_max_image_count'] = sprintf($txt['profile_error_signature_max_image_count'], $sig_limits[3]);
  2471. return 'signature_max_image_count';
  2472. }
  2473. // What about too many smileys!
  2474. $smiley_parsed = $unparsed_signature;
  2475. parsesmileys($smiley_parsed);
  2476. $smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
  2477. if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
  2478. return 'signature_allow_smileys';
  2479. elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
  2480. {
  2481. $txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
  2482. return 'signature_max_smileys';
  2483. }
  2484. // Maybe we are abusing font sizes?
  2485. if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $unparsed_signature, $matches) !== false && isset($matches[2]))
  2486. {
  2487. foreach ($matches[1] as $ind => $size)
  2488. {
  2489. $limit_broke = 0;
  2490. // Attempt to allow all sizes of abuse, so to speak.
  2491. if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
  2492. $limit_broke = $sig_limits[7] . 'px';
  2493. elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
  2494. $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
  2495. elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
  2496. $limit_broke = ((float) $sig_limits[7] / 16) . 'em';
  2497. elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
  2498. $limit_broke = 'large';
  2499. if ($limit_broke)
  2500. {
  2501. $txt['profile_error_signature_max_font_size'] = sprintf($txt['profile_error_signature_max_font_size'], $limit_broke);
  2502. return 'signature_max_font_size';
  2503. }
  2504. }
  2505. }
  2506. // The difficult one - image sizes! Don't error on this - just fix it.
  2507. if ((!empty($sig_limits[5]) || !empty($sig_limits[6])))
  2508. {
  2509. // Get all BBC tags...
  2510. preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br />)*([^<">]+?)(?:<br />)*\[/img\]~i', $unparsed_signature, $matches);
  2511. // ... and all HTML ones.
  2512. preg_match_all('~<img\s+src=(?:")?((?:http://|ftp://|https://|ftps://).+?)(?:")?(?:\s+alt=(?:")?(.*?)(?:")?)?(?:\s?/)?>~i', $unparsed_signature, $matches2, PREG_PATTERN_ORDER);
  2513. // And stick the HTML in the BBC.
  2514. if (!empty($matches2))
  2515. {
  2516. foreach ($matches2[0] as $ind => $dummy)
  2517. {
  2518. $matches[0][] = $matches2[0][$ind];
  2519. $matches[1][] = '';
  2520. $matches[2][] = '';
  2521. $matches[3][] = '';
  2522. $matches[4][] = '';
  2523. $matches[5][] = '';
  2524. $matches[6][] = '';
  2525. $matches[7][] = $matches2[1][$ind];
  2526. }
  2527. }
  2528. $replaces = array();
  2529. // Try to find all the images!
  2530. if (!empty($matches))
  2531. {
  2532. foreach ($matches[0] as $key => $image)
  2533. {
  2534. $width = -1; $height = -1;
  2535. // Does it have predefined restraints? Width first.
  2536. if ($matches[6][$key])
  2537. $matches[2][$key] = $matches[6][$key];
  2538. if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
  2539. {
  2540. $width = $sig_limits[5];
  2541. $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
  2542. }
  2543. elseif ($matches[2][$key])
  2544. $width = $matches[2][$key];
  2545. // ... and height.
  2546. if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
  2547. {
  2548. $height = $sig_limits[6];
  2549. if ($width != -1)
  2550. $width = $width * ($height / $matches[4][$key]);
  2551. }
  2552. elseif ($matches[4][$key])
  2553. $height = $matches[4][$key];
  2554. // If the dimensions are still not fixed - we need to check the actual image.
  2555. if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
  2556. {
  2557. $sizes = url_image_size($matches[7][$key]);
  2558. if (is_array($sizes))
  2559. {
  2560. // Too wide?
  2561. if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
  2562. {
  2563. $width = $sig_limits[5];
  2564. $sizes[1] = $sizes[1] * ($width / $sizes[0]);
  2565. }
  2566. // Too high?
  2567. if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
  2568. {
  2569. $height = $sig_limits[6];
  2570. if ($width == -1)
  2571. $width = $sizes[0];
  2572. $width = $width * ($height / $sizes[1]);
  2573. }
  2574. elseif ($width != -1)
  2575. $height = $sizes[1];
  2576. }
  2577. }
  2578. // Did we come up with some changes? If so remake the string.
  2579. if ($width != -1 || $height != -1)
  2580. $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
  2581. }
  2582. if (!empty($replaces))
  2583. $value = str_replace(array_keys($replaces), array_values($replaces), $value);
  2584. }
  2585. }
  2586. // Any disabled BBC?
  2587. $disabledSigBBC = implode('|', $disabledTags);
  2588. if (!empty($disabledSigBBC))
  2589. {
  2590. if (preg_match('~\[(' . $disabledSigBBC . ')~i', $unparsed_signature, $matches) !== false && isset($matches[1]))
  2591. {
  2592. $disabledTags = array_unique($disabledTags);
  2593. $txt['profile_error_signature_disabled_bbc'] = sprintf($txt['profile_error_signature_disabled_bbc'], implode(', ', $disabledTags));
  2594. return 'signature_disabled_bbc';
  2595. }
  2596. }
  2597. }
  2598. preparsecode($value);
  2599. return true;
  2600. }
  2601. // Validate an email address.
  2602. function profileValidateEmail($email, $memID = 0)
  2603. {
  2604. global $smcFunc, $context;
  2605. $email = strtr($email, array('&#039;' => '\''));
  2606. // Check the name and email for validity.
  2607. if (trim($email) == '')
  2608. return 'no_email';
  2609. if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $email) == 0)
  2610. return 'bad_email';
  2611. // Email addresses should be and stay unique.
  2612. $request = $smcFunc['db_query']('', '
  2613. SELECT id_member
  2614. FROM {db_prefix}members
  2615. WHERE ' . ($memID != 0 ? 'id_member != {int:selected_member} AND ' : '') . '
  2616. email_address = {string:email_address}
  2617. LIMIT 1',
  2618. array(
  2619. 'selected_member' => $memID,
  2620. 'email_address' => $email,
  2621. )
  2622. );
  2623. if ($smcFunc['db_num_rows']($request) > 0)
  2624. return 'email_taken';
  2625. $smcFunc['db_free_result']($request);
  2626. return true;
  2627. }
  2628. // Reload a users settings.
  2629. function profileReloadUser()
  2630. {
  2631. global $sourcedir, $modSettings, $context, $cur_profile, $smcFunc, $profile_vars;
  2632. // Log them back in - using the verify password as they must have matched and this one doesn't get changed by anyone!
  2633. if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
  2634. {
  2635. require_once($sourcedir . '/Subs-Auth.php');
  2636. setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], sha1(sha1(strtolower($cur_profile['member_name']) . un_htmlspecialchars($_POST['passwrd2'])) . $cur_profile['password_salt']));
  2637. }
  2638. loadUserSettings();
  2639. writeLog();
  2640. }
  2641. // Send the user a new activation email if they need to reactivate!
  2642. function profileSendActivation()
  2643. {
  2644. global $sourcedir, $profile_vars, $txt, $context, $scripturl, $smcFunc, $cookiename, $cur_profile, $language, $modSettings;
  2645. require_once($sourcedir . '/Subs-Post.php');
  2646. // Shouldn't happen but just in case.
  2647. if (empty($profile_vars['email_address']))
  2648. return;
  2649. $replacements = array(
  2650. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
  2651. 'ACTIVATIONCODE' => $profile_vars['validation_code'],
  2652. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $context['id_member'],
  2653. );
  2654. // Send off the email.
  2655. $emaildata = loadEmailTemplate('activate_reactivate', $replacements, empty($cur_profile['lngfile']) || empty($modSettings['userLanguage']) ? $language : $cur_profile['lngfile']);
  2656. sendmail($profile_vars['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  2657. // Log the user out.
  2658. $smcFunc['db_query']('', '
  2659. DELETE FROM {db_prefix}log_online
  2660. WHERE id_member = {int:selected_member}',
  2661. array(
  2662. 'selected_member' => $context['id_member'],
  2663. )
  2664. );
  2665. $_SESSION['log_time'] = 0;
  2666. $_SESSION['login_' . $cookiename] = serialize(array(0, '', 0));
  2667. if (isset($_COOKIE[$cookiename]))
  2668. $_COOKIE[$cookiename] = '';
  2669. loadUserSettings();
  2670. $context['user']['is_logged'] = false;
  2671. $context['user']['is_guest'] = true;
  2672. // Send them to the done-with-registration-login screen.
  2673. loadTemplate('Register');
  2674. $context['page_title'] = $txt['profile'];
  2675. $context['sub_template'] = 'after';
  2676. $context['title'] = $txt['activate_changed_email_title'];
  2677. $context['description'] = $txt['activate_changed_email_desc'];
  2678. // We're gone!
  2679. obExit();
  2680. }
  2681. // Function to allow the user to choose group membership etc...
  2682. function groupMembership($memID)
  2683. {
  2684. global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc;
  2685. $curMember = $user_profile[$memID];
  2686. $context['primary_group'] = $curMember['id_group'];
  2687. // Can they manage groups?
  2688. $context['can_manage_membergroups'] = allowedTo('manage_membergroups');
  2689. $context['can_manage_protected'] = allowedTo('admin_forum');
  2690. $context['can_edit_primary'] = $context['can_manage_protected'];
  2691. $context['update_message'] = isset($_GET['msg']) && isset($txt['group_membership_msg_' . $_GET['msg']]) ? $txt['group_membership_msg_' . $_GET['msg']] : '';
  2692. // Get all the groups this user is a member of.
  2693. $groups = explode(',', $curMember['additional_groups']);
  2694. $groups[] = $curMember['id_group'];
  2695. // Ensure the query doesn't croak!
  2696. if (empty($groups))
  2697. $groups = array(0);
  2698. // Just to be sure...
  2699. foreach ($groups as $k => $v)
  2700. $groups[$k] = (int) $v;
  2701. // Get all the membergroups they can join.
  2702. $request = $smcFunc['db_query']('', '
  2703. SELECT mg.id_group, mg.group_name, mg.description, mg.group_type, mg.online_color, mg.hidden,
  2704. IFNULL(lgr.id_member, 0) AS pending
  2705. FROM {db_prefix}membergroups AS mg
  2706. LEFT JOIN {db_prefix}log_group_requests AS lgr ON (lgr.id_member = {int:selected_member} AND lgr.id_group = mg.id_group)
  2707. WHERE (mg.id_group IN ({array_int:group_list})
  2708. OR mg.group_type > {int:nonjoin_group_id})
  2709. AND mg.min_posts = {int:min_posts}
  2710. AND mg.id_group != {int:moderator_group}
  2711. ORDER BY group_name',
  2712. array(
  2713. 'group_list' => $groups,
  2714. 'selected_member' => $memID,
  2715. 'nonjoin_group_id' => 1,
  2716. 'min_posts' => -1,
  2717. 'moderator_group' => 3,
  2718. )
  2719. );
  2720. // This beast will be our group holder.
  2721. $context['groups'] = array(
  2722. 'member' => array(),
  2723. 'available' => array()
  2724. );
  2725. while ($row = $smcFunc['db_fetch_assoc']($request))
  2726. {
  2727. // Can they edit their primary group?
  2728. if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
  2729. $context['can_edit_primary'] = true;
  2730. // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it.
  2731. if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
  2732. continue;
  2733. $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
  2734. 'id' => $row['id_group'],
  2735. 'name' => $row['group_name'],
  2736. 'desc' => $row['description'],
  2737. 'color' => $row['online_color'],
  2738. 'type' => $row['group_type'],
  2739. 'pending' => $row['pending'],
  2740. 'is_primary' => $row['id_group'] == $context['primary_group'],
  2741. 'can_be_primary' => $row['hidden'] != 2,
  2742. // Anything more than this needs to be done through account settings for security.
  2743. 'can_leave' => $row['id_group'] != 1 && $row['group_type'] > 1 ? true : false,
  2744. );
  2745. }
  2746. $smcFunc['db_free_result']($request);
  2747. // Add registered members on the end.
  2748. $context['groups']['member'][0] = array(
  2749. 'id' => 0,
  2750. 'name' => $txt['regular_members'],
  2751. 'desc' => $txt['regular_members_desc'],
  2752. 'type' => 0,
  2753. 'is_primary' => $context['primary_group'] == 0 ? true : false,
  2754. 'can_be_primary' => true,
  2755. 'can_leave' => 0,
  2756. );
  2757. // No changing primary one unless you have enough groups!
  2758. if (count($context['groups']['member']) < 2)
  2759. $context['can_edit_primary'] = false;
  2760. // In the special case that someone is requesting membership of a group, setup some special context vars.
  2761. if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
  2762. $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
  2763. }
  2764. // This function actually makes all the group changes...
  2765. function groupMembership2($profile_vars, $post_errors, $memID)
  2766. {
  2767. global $user_info, $sourcedir, $context, $user_profile, $modSettings, $txt, $smcFunc, $scripturl, $language;
  2768. // Let's be extra cautious...
  2769. if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
  2770. isAllowedTo('manage_membergroups');
  2771. if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
  2772. fatal_lang_error('no_access', false);
  2773. checkSession(isset($_GET['gid']) ? 'get' : 'post');
  2774. $old_profile = &$user_profile[$memID];
  2775. $context['can_manage_membergroups'] = allowedTo('manage_membergroups');
  2776. $context['can_manage_protected'] = allowedTo('admin_forum');
  2777. // By default the new primary is the old one.
  2778. $newPrimary = $old_profile['id_group'];
  2779. $addGroups = array_flip(explode(',', $old_profile['additional_groups']));
  2780. $canChangePrimary = $old_profile['id_group'] == 0 ? 1 : 0;
  2781. $changeType = isset($_POST['primary']) ? 'primary' : (isset($_POST['req']) ? 'request' : 'free');
  2782. // One way or another, we have a target group in mind...
  2783. $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : (int) $_POST['primary'];
  2784. $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
  2785. // Sanity check!!
  2786. if ($group_id == 1)
  2787. isAllowedTo('admin_forum');
  2788. // Protected groups too!
  2789. else
  2790. {
  2791. $request = $smcFunc['db_query']('', '
  2792. SELECT group_type
  2793. FROM {db_prefix}membergroups
  2794. WHERE id_group = {int:current_group}
  2795. LIMIT {int:limit}',
  2796. array(
  2797. 'current_group' => $group_id,
  2798. 'limit' => 1,
  2799. )
  2800. );
  2801. list ($is_protected) = $smcFunc['db_fetch_row']($request);
  2802. $smcFunc['db_free_result']($request);
  2803. if ($is_protected == 1)
  2804. isAllowedTo('admin_forum');
  2805. }
  2806. // What ever we are doing, we need to determine if changing primary is possible!
  2807. $request = $smcFunc['db_query']('', '
  2808. SELECT id_group, group_type, hidden, group_name
  2809. FROM {db_prefix}membergroups
  2810. WHERE id_group IN ({int:group_list}, {int:current_group})',
  2811. array(
  2812. 'group_list' => $group_id,
  2813. 'current_group' => $old_profile['id_group'],
  2814. )
  2815. );
  2816. while ($row = $smcFunc['db_fetch_assoc']($request))
  2817. {
  2818. // Is this the new group?
  2819. if ($row['id_group'] == $group_id)
  2820. {
  2821. $foundTarget = true;
  2822. $group_name = $row['group_name'];
  2823. // Does the group type match what we're doing - are we trying to request a non-requestable group?
  2824. if ($changeType == 'request' && $row['group_type'] != 2)
  2825. fatal_lang_error('no_access', false);
  2826. // What about leaving a requestable group we are not a member of?
  2827. elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
  2828. fatal_lang_error('no_access', false);
  2829. elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
  2830. fatal_lang_error('no_access', false);
  2831. // We can't change the primary group if this is hidden!
  2832. if ($row['hidden'] == 2)
  2833. $canChangePrimary = false;
  2834. }
  2835. // If this is their old primary, can we change it?
  2836. if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
  2837. $canChangePrimary = 1;
  2838. // If we are not doing a force primary move, don't do it automatically if current primary is not 0.
  2839. if ($changeType != 'primary' && $old_profile['id_group'] != 0)
  2840. $canChangePrimary = false;
  2841. // If this is the one we are acting on, can we even act?
  2842. if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
  2843. $canChangePrimary = false;
  2844. }
  2845. $smcFunc['db_free_result']($request);
  2846. // Didn't find the target?
  2847. if (!$foundTarget)
  2848. fatal_lang_error('no_access', false);
  2849. // Final security check, don't allow users to promote themselves to admin.
  2850. if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
  2851. {
  2852. $request = $smcFunc['db_query']('', '
  2853. SELECT COUNT(permission)
  2854. FROM {db_prefix}permissions
  2855. WHERE id_group = {int:selected_group}
  2856. AND permission = {string:admin_forum}
  2857. AND add_deny = {int:not_denied}',
  2858. array(
  2859. 'selected_group' => $group_id,
  2860. 'not_denied' => 1,
  2861. 'admin_forum' => 'admin_forum',
  2862. )
  2863. );
  2864. list ($disallow) = $smcFunc['db_fetch_row']($request);
  2865. $smcFunc['db_free_result']($request);
  2866. if ($disallow)
  2867. isAllowedTo('admin_forum');
  2868. }
  2869. // If we're requesting, add the note then return.
  2870. if ($changeType == 'request')
  2871. {
  2872. $request = $smcFunc['db_query']('', '
  2873. SELECT id_member
  2874. FROM {db_prefix}log_group_requests
  2875. WHERE id_member = {int:selected_member}
  2876. AND id_group = {int:selected_group}',
  2877. array(
  2878. 'selected_member' => $memID,
  2879. 'selected_group' => $group_id,
  2880. )
  2881. );
  2882. if ($smcFunc['db_num_rows']($request) != 0)
  2883. fatal_lang_error('profile_error_already_requested_group');
  2884. $smcFunc['db_free_result']($request);
  2885. // Log the request.
  2886. $smcFunc['db_insert']('',
  2887. '{db_prefix}log_group_requests',
  2888. array(
  2889. 'id_member' => 'int', 'id_group' => 'int', 'time_applied' => 'int', 'reason' => 'string-65534',
  2890. ),
  2891. array(
  2892. $memID, $group_id, time(), $_POST['reason'],
  2893. ),
  2894. array('id_request')
  2895. );
  2896. // Send an email to all group moderators etc.
  2897. require_once($sourcedir . '/Subs-Post.php');
  2898. // Do we have any group moderators?
  2899. $request = $smcFunc['db_query']('', '
  2900. SELECT id_member
  2901. FROM {db_prefix}group_moderators
  2902. WHERE id_group = {int:selected_group}',
  2903. array(
  2904. 'selected_group' => $group_id,
  2905. )
  2906. );
  2907. $moderators = array();
  2908. while ($row = $smcFunc['db_fetch_assoc']($request))
  2909. $moderators[] = $row['id_member'];
  2910. $smcFunc['db_free_result']($request);
  2911. // Otherwise this is the backup!
  2912. if (empty($moderators))
  2913. {
  2914. require_once($sourcedir . '/Subs-Members.php');
  2915. $moderators = membersAllowedTo('manage_membergroups');
  2916. }
  2917. if (!empty($moderators))
  2918. {
  2919. $request = $smcFunc['db_query']('', '
  2920. SELECT id_member, email_address, lngfile, member_name, mod_prefs
  2921. FROM {db_prefix}members
  2922. WHERE id_member IN ({array_int:moderator_list})
  2923. AND notify_types != {int:no_notifications}
  2924. ORDER BY lngfile',
  2925. array(
  2926. 'moderator_list' => $moderators,
  2927. 'no_notifications' => 4,
  2928. )
  2929. );
  2930. while ($row = $smcFunc['db_fetch_assoc']($request))
  2931. {
  2932. // Check whether they are interested.
  2933. if (!empty($row['mod_prefs']))
  2934. {
  2935. list(,, $pref_binary) = explode('|', $row['mod_prefs']);
  2936. if (!($pref_binary & 4))
  2937. continue;
  2938. }
  2939. $replacements = array(
  2940. 'RECPNAME' => $row['member_name'],
  2941. 'APPYNAME' => $old_profile['member_name'],
  2942. 'GROUPNAME' => $group_name,
  2943. 'REASON' => $_POST['reason'],
  2944. 'MODLINK' => $scripturl . '?action=moderate;area=groups;sa=requests',
  2945. );
  2946. $emaildata = loadEmailTemplate('request_membership', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
  2947. sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 2);
  2948. }
  2949. $smcFunc['db_free_result']($request);
  2950. }
  2951. return $changeType;
  2952. }
  2953. // Otherwise we are leaving/joining a group.
  2954. elseif ($changeType == 'free')
  2955. {
  2956. // Are we leaving?
  2957. if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
  2958. {
  2959. if ($old_profile['id_group'] == $group_id)
  2960. $newPrimary = 0;
  2961. else
  2962. unset($addGroups[$group_id]);
  2963. }
  2964. // ... if not, must be joining.
  2965. else
  2966. {
  2967. // Can we change the primary, and do we want to?
  2968. if ($canChangePrimary)
  2969. {
  2970. if ($old_profile['id_group'] != 0)
  2971. $addGroups[$old_profile['id_group']] = -1;
  2972. $newPrimary = $group_id;
  2973. }
  2974. // Otherwise it's an additional group...
  2975. else
  2976. $addGroups[$group_id] = -1;
  2977. }
  2978. }
  2979. // Finally, we must be setting the primary.
  2980. elseif ($canChangePrimary)
  2981. {
  2982. if ($old_profile['id_group'] != 0)
  2983. $addGroups[$old_profile['id_group']] = -1;
  2984. if (isset($addGroups[$group_id]))
  2985. unset($addGroups[$group_id]);
  2986. $newPrimary = $group_id;
  2987. }
  2988. // Finally, we can make the changes!
  2989. foreach ($addGroups as $id => $dummy)
  2990. if (empty($id))
  2991. unset($addGroups[$id]);
  2992. $addGroups = implode(',', array_flip($addGroups));
  2993. // Ensure that we don't cache permissions if the group is changing.
  2994. if ($context['user']['is_owner'])
  2995. $_SESSION['mc']['time'] = 0;
  2996. else
  2997. updateSettings(array('settings_updated' => time()));
  2998. updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
  2999. return $changeType;
  3000. }
  3001. ?>