Profile.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. <?php
  2. /**
  3. * This file has the primary job of showing and editing people's profiles.
  4. * It also allows the user to change some of their or another's preferences,
  5. * and such things.
  6. *
  7. * Simple Machines Forum (SMF)
  8. *
  9. * @package SMF
  10. * @author Simple Machines http://www.simplemachines.org
  11. * @copyright 2011 Simple Machines
  12. * @license http://www.simplemachines.org/about/smf/license.php BSD
  13. *
  14. * @version 2.1 Alpha 1
  15. */
  16. if (!defined('SMF'))
  17. die('Hacking attempt...');
  18. /**
  19. * Allow the change or view of profiles...
  20. *
  21. * @param array $post_errors = array()
  22. */
  23. function ModifyProfile($post_errors = array())
  24. {
  25. global $txt, $scripturl, $user_info, $context, $sourcedir, $user_profile, $cur_profile;
  26. global $modSettings, $memberContext, $profile_vars, $smcFunc, $post_errors, $options, $user_settings;
  27. // Don't reload this as we may have processed error strings.
  28. if (empty($post_errors))
  29. loadLanguage('Profile');
  30. loadTemplate('Profile');
  31. require_once($sourcedir . '/Subs-Menu.php');
  32. // Did we get the user by name...
  33. if (isset($_REQUEST['user']))
  34. $memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
  35. // ... or by id_member?
  36. elseif (!empty($_REQUEST['u']))
  37. $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
  38. // If it was just ?action=profile, edit your own profile.
  39. else
  40. $memberResult = loadMemberData($user_info['id'], false, 'profile');
  41. // Check if loadMemberData() has returned a valid result.
  42. if (!is_array($memberResult))
  43. fatal_lang_error('not_a_user', false);
  44. // If all went well, we have a valid member ID!
  45. list ($memID) = $memberResult;
  46. $context['id_member'] = $memID;
  47. $cur_profile = $user_profile[$memID];
  48. // Let's have some information about this member ready, too.
  49. loadMemberContext($memID);
  50. $context['member'] = $memberContext[$memID];
  51. // Is this the profile of the user himself or herself?
  52. $context['user']['is_owner'] = $memID == $user_info['id'];
  53. /* Define all the sections within the profile area!
  54. We start by defining the permission required - then SMF takes this and turns it into the relevant context ;)
  55. Possible fields:
  56. For Section:
  57. string $title: Section title.
  58. array $areas: Array of areas within this section.
  59. For Areas:
  60. string $label: Text string that will be used to show the area in the menu.
  61. string $file: Optional text string that may contain a file name that's needed for inclusion in order to display the area properly.
  62. string $custom_url: Optional href for area.
  63. string $function: Function to execute for this section.
  64. bool $enabled: Should area be shown?
  65. string $sc: Session check validation to do on save - note without this save will get unset - if set.
  66. bool $hidden: Does this not actually appear on the menu?
  67. bool $password: Whether to require the user's password in order to save the data in the area.
  68. array $subsections: Array of subsections, in order of appearance.
  69. array $permission: Array of permissions to determine who can access this area. Should contain arrays $own and $any.
  70. */
  71. $profile_areas = array(
  72. 'info' => array(
  73. 'title' => $txt['profileInfo'],
  74. 'areas' => array(
  75. 'summary' => array(
  76. 'label' => $txt['summary'],
  77. 'file' => 'Profile-View.php',
  78. 'function' => 'summary',
  79. 'permission' => array(
  80. 'own' => 'profile_view_own',
  81. 'any' => 'profile_view_any',
  82. ),
  83. ),
  84. 'statistics' => array(
  85. 'label' => $txt['statPanel'],
  86. 'file' => 'Profile-View.php',
  87. 'function' => 'statPanel',
  88. 'permission' => array(
  89. 'own' => 'profile_view_own',
  90. 'any' => 'profile_view_any',
  91. ),
  92. ),
  93. 'showposts' => array(
  94. 'label' => $txt['showPosts'],
  95. 'file' => 'Profile-View.php',
  96. 'function' => 'showPosts',
  97. 'subsections' => array(
  98. 'messages' => array($txt['showMessages'], array('profile_view_own', 'profile_view_any')),
  99. 'topics' => array($txt['showTopics'], array('profile_view_own', 'profile_view_any')),
  100. 'attach' => array($txt['showAttachments'], array('profile_view_own', 'profile_view_any')),
  101. ),
  102. 'permission' => array(
  103. 'own' => 'profile_view_own',
  104. 'any' => 'profile_view_any',
  105. ),
  106. ),
  107. 'permissions' => array(
  108. 'label' => $txt['showPermissions'],
  109. 'file' => 'Profile-View.php',
  110. 'function' => 'showPermissions',
  111. 'permission' => array(
  112. 'own' => 'manage_permissions',
  113. 'any' => 'manage_permissions',
  114. ),
  115. ),
  116. 'tracking' => array(
  117. 'label' => $txt['trackUser'],
  118. 'file' => 'Profile-View.php',
  119. 'function' => 'tracking',
  120. 'subsections' => array(
  121. 'activity' => array($txt['trackActivity'], 'moderate_forum'),
  122. 'ip' => array($txt['trackIP'], 'moderate_forum'),
  123. 'edits' => array($txt['trackEdits'], 'moderate_forum'),
  124. 'logins' => array($txt['trackLogins'], array('profile_view_own', 'moderate_forum')),
  125. ),
  126. 'permission' => array(
  127. 'own' => 'moderate_forum',
  128. 'any' => 'moderate_forum',
  129. ),
  130. ),
  131. 'viewwarning' => array(
  132. 'label' => $txt['profile_view_warnings'],
  133. 'enabled' => in_array('w', $context['admin_features']) && $modSettings['warning_settings'][0] == 1 && $cur_profile['warning'] && (!empty($modSettings['warning_show']) && ($context['user']['is_owner'] || $modSettings['warning_show'] == 2)),
  134. 'file' => 'Profile-View.php',
  135. 'function' => 'viewWarning',
  136. 'permission' => array(
  137. 'own' => 'profile_view_own',
  138. 'any' => 'issue_warning',
  139. ),
  140. ),
  141. ),
  142. ),
  143. 'edit_profile' => array(
  144. 'title' => $txt['profileEdit'],
  145. 'areas' => array(
  146. 'account' => array(
  147. 'label' => $txt['account'],
  148. 'file' => 'Profile-Modify.php',
  149. 'function' => 'account',
  150. 'enabled' => $context['user']['is_admin'] || ($cur_profile['id_group'] != 1 && !in_array(1, explode(',', $cur_profile['additional_groups']))),
  151. 'sc' => 'post',
  152. 'token' => 'profile-ac%u',
  153. 'password' => true,
  154. 'permission' => array(
  155. 'own' => array('profile_identity_any', 'profile_identity_own', 'manage_membergroups'),
  156. 'any' => array('profile_identity_any', 'manage_membergroups'),
  157. ),
  158. ),
  159. 'forumprofile' => array(
  160. 'label' => $txt['forumprofile'],
  161. 'file' => 'Profile-Modify.php',
  162. 'function' => 'forumProfile',
  163. 'sc' => 'post',
  164. 'token' => 'profile-fp%u',
  165. 'permission' => array(
  166. 'own' => array('profile_extra_any', 'profile_extra_own', 'profile_title_own', 'profile_title_any'),
  167. 'any' => array('profile_extra_any', 'profile_title_any'),
  168. ),
  169. ),
  170. 'theme' => array(
  171. 'label' => $txt['theme'],
  172. 'file' => 'Profile-Modify.php',
  173. 'function' => 'theme',
  174. 'sc' => 'post',
  175. 'token' => 'profile-th%u',
  176. 'permission' => array(
  177. 'own' => array('profile_extra_any', 'profile_extra_own'),
  178. 'any' => array('profile_extra_any'),
  179. ),
  180. ),
  181. 'authentication' => array(
  182. 'label' => $txt['authentication'],
  183. 'file' => 'Profile-Modify.php',
  184. 'function' => 'authentication',
  185. 'enabled' => !empty($modSettings['enableOpenID']) || !empty($cur_profile['openid_uri']),
  186. 'sc' => 'post',
  187. 'token' => 'profile-au%u',
  188. 'hidden' => empty($modSettings['enableOpenID']) && empty($cur_profile['openid_uri']),
  189. 'password' => true,
  190. 'permission' => array(
  191. 'own' => array('profile_identity_any', 'profile_identity_own'),
  192. 'any' => array('profile_identity_any'),
  193. ),
  194. ),
  195. 'notification' => array(
  196. 'label' => $txt['notification'],
  197. 'file' => 'Profile-Modify.php',
  198. 'function' => 'notification',
  199. 'sc' => 'post',
  200. 'token' => 'profile-nt%u',
  201. 'permission' => array(
  202. 'own' => array('profile_extra_any', 'profile_extra_own'),
  203. 'any' => array('profile_extra_any'),
  204. ),
  205. ),
  206. // Without profile_extra_own, settings are accessible from the PM section.
  207. 'pmprefs' => array(
  208. 'label' => $txt['pmprefs'],
  209. 'file' => 'Profile-Modify.php',
  210. 'function' => 'pmprefs',
  211. 'enabled' => allowedTo(array('profile_extra_own', 'profile_extra_any')),
  212. 'sc' => 'post',
  213. 'token' => 'profile-pm%u',
  214. 'permission' => array(
  215. 'own' => array('pm_read'),
  216. 'any' => array('profile_extra_any'),
  217. ),
  218. ),
  219. 'ignoreboards' => array(
  220. 'label' => $txt['ignoreboards'],
  221. 'file' => 'Profile-Modify.php',
  222. 'function' => 'ignoreboards',
  223. 'enabled' => !empty($modSettings['allow_ignore_boards']),
  224. 'sc' => 'post',
  225. 'token' => 'profile-ib%u',
  226. 'permission' => array(
  227. 'own' => array('profile_extra_any', 'profile_extra_own'),
  228. 'any' => array('profile_extra_any'),
  229. ),
  230. ),
  231. 'lists' => array(
  232. 'label' => $txt['editBuddyIgnoreLists'],
  233. 'file' => 'Profile-Modify.php',
  234. 'function' => 'editBuddyIgnoreLists',
  235. 'enabled' => !empty($modSettings['enable_buddylist']) && $context['user']['is_owner'],
  236. 'sc' => 'post',
  237. 'token' => 'profile-bl%u',
  238. 'subsections' => array(
  239. 'buddies' => array($txt['editBuddies']),
  240. 'ignore' => array($txt['editIgnoreList']),
  241. ),
  242. 'permission' => array(
  243. 'own' => array('profile_extra_any', 'profile_extra_own'),
  244. 'any' => array(),
  245. ),
  246. ),
  247. 'groupmembership' => array(
  248. 'label' => $txt['groupmembership'],
  249. 'file' => 'Profile-Modify.php',
  250. 'function' => 'groupMembership',
  251. 'enabled' => !empty($modSettings['show_group_membership']) && $context['user']['is_owner'],
  252. 'sc' => 'request',
  253. 'token' => 'profile-gm%u',
  254. 'token_type' => 'request',
  255. 'permission' => array(
  256. 'own' => array('profile_view_own'),
  257. 'any' => array('manage_membergroups'),
  258. ),
  259. ),
  260. ),
  261. ),
  262. 'profile_action' => array(
  263. 'title' => $txt['profileAction'],
  264. 'areas' => array(
  265. 'sendpm' => array(
  266. 'label' => $txt['profileSendIm'],
  267. 'custom_url' => $scripturl . '?action=pm;sa=send',
  268. 'permission' => array(
  269. 'own' => array(),
  270. 'any' => array('pm_send'),
  271. ),
  272. ),
  273. 'issuewarning' => array(
  274. 'label' => $txt['profile_issue_warning'],
  275. 'enabled' => in_array('w', $context['admin_features']) && $modSettings['warning_settings'][0] == 1 && (!$context['user']['is_owner'] || $context['user']['is_admin']),
  276. 'file' => 'Profile-Actions.php',
  277. 'function' => 'issueWarning',
  278. 'token' => 'profile-iw%u',
  279. 'enabled' => !$context['user']['is_owner'],
  280. 'permission' => array(
  281. 'own' => array('issue_warning'),
  282. 'any' => array('issue_warning'),
  283. ),
  284. ),
  285. 'banuser' => array(
  286. 'label' => $txt['profileBanUser'],
  287. 'custom_url' => $scripturl . '?action=admin;area=ban;sa=add',
  288. 'enabled' => $cur_profile['id_group'] != 1 && !in_array(1, explode(',', $cur_profile['additional_groups'])),
  289. 'permission' => array(
  290. 'own' => array(),
  291. 'any' => array('manage_bans'),
  292. ),
  293. ),
  294. 'subscriptions' => array(
  295. 'label' => $txt['subscriptions'],
  296. 'file' => 'Profile-Actions.php',
  297. 'function' => 'subscriptions',
  298. 'enabled' => !empty($modSettings['paid_enabled']),
  299. 'permission' => array(
  300. 'own' => array('profile_view_own'),
  301. 'any' => array('moderate_forum'),
  302. ),
  303. ),
  304. 'deleteaccount' => array(
  305. 'label' => $txt['deleteAccount'],
  306. 'file' => 'Profile-Actions.php',
  307. 'function' => 'deleteAccount',
  308. 'sc' => 'post',
  309. 'token' => 'profile-da%u',
  310. 'password' => true,
  311. 'permission' => array(
  312. 'own' => array('profile_remove_any', 'profile_remove_own'),
  313. 'any' => array('profile_remove_any'),
  314. ),
  315. ),
  316. 'activateaccount' => array(
  317. 'file' => 'Profile-Actions.php',
  318. 'function' => 'activateAccount',
  319. 'sc' => 'get',
  320. 'token' => 'profile-aa%u',
  321. 'select' => 'summary',
  322. 'permission' => array(
  323. 'own' => array(),
  324. 'any' => array('moderate_forum'),
  325. ),
  326. ),
  327. ),
  328. ),
  329. );
  330. // Let them modify profile areas easily.
  331. call_integration_hook('integrate_profile_areas', array(&$profile_areas));
  332. // Do some cleaning ready for the menu function.
  333. $context['password_areas'] = array();
  334. $current_area = isset($_REQUEST['area']) ? $_REQUEST['area'] : '';
  335. foreach ($profile_areas as $section_id => $section)
  336. {
  337. // Do a bit of spring cleaning so to speak.
  338. foreach ($section['areas'] as $area_id => $area)
  339. {
  340. // If it said no permissions that meant it wasn't valid!
  341. if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
  342. $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
  343. // Otherwise pick the right set.
  344. else
  345. $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
  346. // Password required - only if not on OpenID.
  347. if (!empty($area['password']))
  348. $context['password_areas'][] = $area_id;
  349. }
  350. }
  351. // Is there an updated message to show?
  352. if (isset($_GET['updated']))
  353. $context['profile_updated'] = $txt['profile_updated_own'];
  354. // Set a few options for the menu.
  355. $menuOptions = array(
  356. 'disable_url_session_check' => true,
  357. 'current_area' => $current_area,
  358. 'extra_url_parameters' => array(
  359. 'u' => $context['id_member'],
  360. ),
  361. );
  362. // Actually create the menu!
  363. $profile_include_data = createMenu($profile_areas, $menuOptions);
  364. // No menu means no access.
  365. if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
  366. fatal_lang_error('no_access', false);
  367. // Make a note of the Unique ID for this menu.
  368. $context['profile_menu_id'] = $context['max_menu_id'];
  369. $context['profile_menu_name'] = 'menu_data_' . $context['profile_menu_id'];
  370. // Set the selected item - now it's been validated.
  371. $current_area = $profile_include_data['current_area'];
  372. $context['menu_item_selected'] = $current_area;
  373. // Before we go any further, let's work on the area we've said is valid. Note this is done here just in case we ever compromise the menu function in error!
  374. $context['completed_save'] = false;
  375. $context['do_preview'] = isset($_REQUEST['preview_signature']);
  376. $security_checks = array();
  377. $found_area = false;
  378. foreach ($profile_areas as $section_id => $section)
  379. {
  380. // Do a bit of spring cleaning so to speak.
  381. foreach ($section['areas'] as $area_id => $area)
  382. {
  383. // Is this our area?
  384. if ($current_area == $area_id)
  385. {
  386. // This can't happen - but is a security check.
  387. if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
  388. fatal_lang_error('no_access', false);
  389. // Are we saving data in a valid area?
  390. if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview']))
  391. {
  392. $security_checks['session'] = $area['sc'];
  393. $context['completed_save'] = true;
  394. }
  395. // Do we need to perform a token check?
  396. if (!empty($area['token']))
  397. {
  398. $security_checks[isset($_REQUEST['save']) ? 'validateToken' : 'needsToken'] = $area['token'];
  399. $token_name = $area['token'] !== true ? str_replace('%u', $context['id_member'], $area['token']) : 'profile-u' . $context['id_member'];
  400. $token_type = isset($area['token_type']) && in_array($area['token_type'], array('request', 'post', 'get')) ? $area['token_type'] : 'post';
  401. }
  402. // Does this require session validating?
  403. if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner']))
  404. $security_checks['validate'] = true;
  405. // Permissions for good measure.
  406. if (!empty($profile_include_data['permission']))
  407. $security_checks['permission'] = $profile_include_data['permission'];
  408. // Either way got something.
  409. $found_area = true;
  410. }
  411. }
  412. }
  413. // Oh dear, some serious security lapse is going on here... we'll put a stop to that!
  414. if (!$found_area)
  415. fatal_lang_error('no_access', false);
  416. // Release this now.
  417. unset($profile_areas);
  418. // Now the context is setup have we got any security checks to carry out additional to that above?
  419. if (isset($security_checks['session']))
  420. checkSession($security_checks['session']);
  421. if (isset($security_checks['validate']))
  422. validateSession();
  423. if (isset($security_checks['validateToken']))
  424. validateToken($token_name, $token_type);
  425. if (isset($security_checks['permission']))
  426. isAllowedTo($security_checks['permission']);
  427. // Create a token if needed.
  428. if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
  429. {
  430. createToken($token_name, $token_type);
  431. $context['token_check'] = $token_name;
  432. }
  433. // File to include?
  434. if (isset($profile_include_data['file']))
  435. require_once($sourcedir . '/' . $profile_include_data['file']);
  436. // Make sure that the area function does exist!
  437. if (!isset($profile_include_data['function']) || !function_exists($profile_include_data['function']))
  438. {
  439. destroyMenu();
  440. fatal_lang_error('no_access', false);
  441. }
  442. // Build the link tree.
  443. $context['linktree'][] = array(
  444. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : ''),
  445. 'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
  446. );
  447. if (!empty($profile_include_data['label']))
  448. $context['linktree'][] = array(
  449. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
  450. 'name' => $profile_include_data['label'],
  451. );
  452. if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
  453. $context['linktree'][] = array(
  454. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
  455. 'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
  456. );
  457. // Set the template for this area and add the profile layer.
  458. $context['sub_template'] = $profile_include_data['function'];
  459. $context['template_layers'][] = 'profile';
  460. // All the subactions that require a user password in order to validate.
  461. $check_password = $context['user']['is_owner'] && in_array($profile_include_data['current_area'], $context['password_areas']);
  462. $context['require_password'] = $check_password && empty($user_settings['openid_uri']);
  463. // If we're in wireless then we have a cut down template...
  464. if (WIRELESS && $context['sub_template'] == 'summary' && WIRELESS_PROTOCOL != 'wap')
  465. $context['sub_template'] = WIRELESS_PROTOCOL . '_profile';
  466. // These will get populated soon!
  467. $post_errors = array();
  468. $profile_vars = array();
  469. // Right - are we saving - if so let's save the old data first.
  470. if ($context['completed_save'])
  471. {
  472. // Clean up the POST variables.
  473. $_POST = htmltrim__recursive($_POST);
  474. $_POST = htmlspecialchars__recursive($_POST);
  475. if ($check_password)
  476. {
  477. // If we're using OpenID try to revalidate.
  478. if (!empty($user_settings['openid_uri']))
  479. {
  480. require_once($sourcedir . '/Subs-OpenID.php');
  481. smf_openID_revalidate();
  482. }
  483. else
  484. {
  485. // You didn't even enter a password!
  486. if (trim($_POST['oldpasswrd']) == '')
  487. $post_errors[] = 'no_password';
  488. // Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
  489. $_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
  490. // Does the integration want to check passwords?
  491. $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
  492. // Bad password!!!
  493. if (!$good_password && $user_info['passwd'] != sha1(strtolower($user_profile[$memID]['member_name']) . un_htmlspecialchars(stripslashes($_POST['oldpasswrd']))))
  494. $post_errors[] = 'bad_password';
  495. // Warn other elements not to jump the gun and do custom changes!
  496. if (in_array('bad_password', $post_errors))
  497. $context['password_auth_failed'] = true;
  498. }
  499. }
  500. // Change the IP address in the database.
  501. if ($context['user']['is_owner'])
  502. $profile_vars['member_ip'] = $user_info['ip'];
  503. // Now call the sub-action function...
  504. if ($current_area == 'activateaccount')
  505. {
  506. if (empty($post_errors))
  507. activateAccount($memID);
  508. }
  509. elseif ($current_area == 'deleteaccount')
  510. {
  511. if (empty($post_errors))
  512. {
  513. deleteAccount2($memID);
  514. redirectexit();
  515. }
  516. }
  517. elseif ($current_area == 'groupmembership' && empty($post_errors))
  518. {
  519. $msg = groupMembership2($profile_vars, $post_errors, $memID);
  520. // Whatever we've done, we have nothing else to do here...
  521. redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : ''));
  522. }
  523. // Authentication changes?
  524. elseif ($current_area == 'authentication')
  525. {
  526. authentication($memID, true);
  527. }
  528. elseif (in_array($current_area, array('account', 'forumprofile', 'theme', 'pmprefs')))
  529. saveProfileFields();
  530. else
  531. {
  532. $force_redirect = true;
  533. // Ensure we include this.
  534. require_once($sourcedir . '/Profile-Modify.php');
  535. saveProfileChanges($profile_vars, $post_errors, $memID);
  536. }
  537. call_integration_hook('integrate_profile_save', array($profile_vars, $post_errors, $memID));
  538. // There was a problem, let them try to re-enter.
  539. if (!empty($post_errors))
  540. {
  541. // Load the language file so we can give a nice explanation of the errors.
  542. loadLanguage('Errors');
  543. $context['post_errors'] = $post_errors;
  544. }
  545. elseif (!empty($profile_vars))
  546. {
  547. // If we've changed the password, notify any integration that may be listening in.
  548. if (isset($profile_vars['passwd']))
  549. call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
  550. updateMemberData($memID, $profile_vars);
  551. // What if this is the newest member?
  552. if ($modSettings['latestMember'] == $memID)
  553. updateStats('member');
  554. elseif (isset($profile_vars['real_name']))
  555. updateSettings(array('memberlist_updated' => time()));
  556. // If the member changed his/her birthdate, update calendar statistics.
  557. if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name']))
  558. updateSettings(array(
  559. 'calendar_updated' => time(),
  560. ));
  561. // Anything worth logging?
  562. if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled']))
  563. {
  564. $log_changes = array();
  565. require_once($sourcedir . '/Logging.php');
  566. foreach ($context['log_changes'] as $k => $v)
  567. $log_changes[] = array(
  568. 'action' => $k,
  569. 'log_type' => 'user',
  570. 'extra' => array_merge($v, array(
  571. 'applicator' => $user_info['id'],
  572. 'member_affected' => $memID,
  573. )),
  574. );
  575. logActions($log_changes);
  576. }
  577. // Have we got any post save functions to execute?
  578. if (!empty($context['profile_execute_on_save']))
  579. foreach ($context['profile_execute_on_save'] as $saveFunc)
  580. $saveFunc();
  581. // Let them know it worked!
  582. $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
  583. // Invalidate any cached data.
  584. cache_put_data('member_data-profile-' . $memID, null, 0);
  585. }
  586. }
  587. // Have some errors for some reason?
  588. if (!empty($post_errors))
  589. {
  590. // Set all the errors so the template knows what went wrong.
  591. foreach ($post_errors as $error_type)
  592. $context['modify_error'][$error_type] = true;
  593. }
  594. // If it's you then we should redirect upon save.
  595. elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
  596. redirectexit('action=profile;area=' . $current_area . ';updated');
  597. elseif (!empty($force_redirect))
  598. redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
  599. // Call the appropriate subaction function.
  600. $profile_include_data['function']($memID);
  601. // Set the page title if it's not already set...
  602. if (!isset($context['page_title']))
  603. $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
  604. }
  605. /**
  606. * Load any custom fields for this area... no area means load all, 'summary' loads all public ones.
  607. *
  608. * @param int $memID
  609. * @param string $area = 'summary'
  610. */
  611. function loadCustomFields($memID, $area = 'summary')
  612. {
  613. global $context, $txt, $user_profile, $smcFunc, $user_info, $settings, $scripturl;
  614. // Get the right restrictions in place...
  615. $where = 'active = 1';
  616. if (!allowedTo('admin_forum') && $area != 'register')
  617. {
  618. // If it's the owner they can see two types of private fields, regardless.
  619. if ($memID == $user_info['id'])
  620. $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
  621. else
  622. $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
  623. }
  624. if ($area == 'register')
  625. $where .= ' AND show_reg != 0';
  626. elseif ($area != 'summary')
  627. $where .= ' AND show_profile = {string:area}';
  628. // Load all the relevant fields - and data.
  629. $request = $smcFunc['db_query']('', '
  630. SELECT
  631. col_name, field_name, field_desc, field_type, show_reg, field_length, field_options,
  632. default_value, bbc, enclose, placement
  633. FROM {db_prefix}custom_fields
  634. WHERE ' . $where,
  635. array(
  636. 'area' => $area,
  637. )
  638. );
  639. $context['custom_fields'] = array();
  640. $context['custom_fields_required'] = false;
  641. while ($row = $smcFunc['db_fetch_assoc']($request))
  642. {
  643. // Shortcut.
  644. $exists = $memID && isset($user_profile[$memID], $user_profile[$memID]['options'][$row['col_name']]);
  645. $value = $exists ? $user_profile[$memID]['options'][$row['col_name']] : '';
  646. // If this was submitted already then make the value the posted version.
  647. if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
  648. {
  649. $value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
  650. if (in_array($row['field_type'], array('select', 'radio')))
  651. $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
  652. }
  653. // HTML for the input form.
  654. $output_html = $value;
  655. if ($row['field_type'] == 'check')
  656. {
  657. $true = (!$exists && $row['default_value']) || $value;
  658. $input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" ' . ($true ? 'checked="checked"' : '') . ' class="input_check" />';
  659. $output_html = $true ? $txt['yes'] : $txt['no'];
  660. }
  661. elseif ($row['field_type'] == 'select')
  662. {
  663. $input_html = '<select name="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
  664. $options = explode(',', $row['field_options']);
  665. foreach ($options as $k => $v)
  666. {
  667. $true = (!$exists && $row['default_value'] == $v) || $value == $v;
  668. $input_html .= '<option value="' . $k . '"' . ($true ? ' selected="selected"' : '') . '>' . $v . '</option>';
  669. if ($true)
  670. $output_html = $v;
  671. }
  672. $input_html .= '</select>';
  673. }
  674. elseif ($row['field_type'] == 'radio')
  675. {
  676. $input_html = '<fieldset>';
  677. $options = explode(',', $row['field_options']);
  678. foreach ($options as $k => $v)
  679. {
  680. $true = (!$exists && $row['default_value'] == $v) || $value == $v;
  681. $input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" class="input_radio" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '" ' . ($true ? 'checked="checked"' : '') . ' />' . $v . '</label><br />';
  682. if ($true)
  683. $output_html = $v;
  684. }
  685. $input_html .= '</fieldset>';
  686. }
  687. elseif ($row['field_type'] == 'text')
  688. {
  689. $input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" ' . ($row['field_length'] != 0 ? 'maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . $value . '" class="input_text" />';
  690. }
  691. else
  692. {
  693. @list ($rows, $cols) = @explode(',', $row['default_value']);
  694. $input_html = '<textarea name="customfield[' . $row['col_name'] . ']" ' . (!empty($rows) ? 'rows="' . $rows . '"' : '') . ' ' . (!empty($cols) ? 'cols="' . $cols . '"' : '') . '>' . $value . '</textarea>';
  695. }
  696. // Parse BBCode
  697. if ($row['bbc'])
  698. $output_html = parse_bbc($output_html);
  699. elseif($row['field_type'] == 'textarea')
  700. // Allow for newlines at least
  701. $output_html = strtr($output_html, array("\n" => '<br />'));
  702. // Enclosing the user input within some other text?
  703. if (!empty($row['enclose']) && !empty($output_html))
  704. $output_html = strtr($row['enclose'], array(
  705. '{SCRIPTURL}' => $scripturl,
  706. '{IMAGES_URL}' => $settings['images_url'],
  707. '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
  708. '{INPUT}' => $output_html,
  709. ));
  710. $context['custom_fields'][] = array(
  711. 'name' => $row['field_name'],
  712. 'desc' => $row['field_desc'],
  713. 'type' => $row['field_type'],
  714. 'input_html' => $input_html,
  715. 'output_html' => $output_html,
  716. 'placement' => $row['placement'],
  717. 'colname' => $row['col_name'],
  718. 'value' => $value,
  719. 'show_reg' => $row['show_reg'],
  720. );
  721. $context['custom_fields_required'] = $context['custom_fields_required'] || $row['show_reg'];
  722. }
  723. $smcFunc['db_free_result']($request);
  724. call_integration_hook('integrate_load_custom_profile_fields', array($memID, $area));
  725. }
  726. ?>