Profile.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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. 'permission' => array(
  280. 'own' => array('issue_warning'),
  281. 'any' => array('issue_warning'),
  282. ),
  283. ),
  284. 'banuser' => array(
  285. 'label' => $txt['profileBanUser'],
  286. 'custom_url' => $scripturl . '?action=admin;area=ban;sa=add',
  287. 'enabled' => $cur_profile['id_group'] != 1 && !in_array(1, explode(',', $cur_profile['additional_groups'])),
  288. 'permission' => array(
  289. 'own' => array(),
  290. 'any' => array('manage_bans'),
  291. ),
  292. ),
  293. 'subscriptions' => array(
  294. 'label' => $txt['subscriptions'],
  295. 'file' => 'Profile-Actions.php',
  296. 'function' => 'subscriptions',
  297. 'enabled' => !empty($modSettings['paid_enabled']),
  298. 'permission' => array(
  299. 'own' => array('profile_view_own'),
  300. 'any' => array('moderate_forum'),
  301. ),
  302. ),
  303. 'deleteaccount' => array(
  304. 'label' => $txt['deleteAccount'],
  305. 'file' => 'Profile-Actions.php',
  306. 'function' => 'deleteAccount',
  307. 'sc' => 'post',
  308. 'token' => 'profile-da%u',
  309. 'password' => true,
  310. 'permission' => array(
  311. 'own' => array('profile_remove_any', 'profile_remove_own'),
  312. 'any' => array('profile_remove_any'),
  313. ),
  314. ),
  315. 'activateaccount' => array(
  316. 'file' => 'Profile-Actions.php',
  317. 'function' => 'activateAccount',
  318. 'sc' => 'get',
  319. 'token' => 'profile-aa%u',
  320. 'select' => 'summary',
  321. 'permission' => array(
  322. 'own' => array(),
  323. 'any' => array('moderate_forum'),
  324. ),
  325. ),
  326. ),
  327. ),
  328. );
  329. // Let them modify profile areas easily.
  330. call_integration_hook('integrate_profile_areas', array(&$profile_areas));
  331. // Do some cleaning ready for the menu function.
  332. $context['password_areas'] = array();
  333. $current_area = isset($_REQUEST['area']) ? $_REQUEST['area'] : '';
  334. foreach ($profile_areas as $section_id => $section)
  335. {
  336. // Do a bit of spring cleaning so to speak.
  337. foreach ($section['areas'] as $area_id => $area)
  338. {
  339. // If it said no permissions that meant it wasn't valid!
  340. if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
  341. $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
  342. // Otherwise pick the right set.
  343. else
  344. $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
  345. // Password required - only if not on OpenID.
  346. if (!empty($area['password']))
  347. $context['password_areas'][] = $area_id;
  348. }
  349. }
  350. // Is there an updated message to show?
  351. if (isset($_GET['updated']))
  352. $context['profile_updated'] = $txt['profile_updated_own'];
  353. // Set a few options for the menu.
  354. $menuOptions = array(
  355. 'disable_url_session_check' => true,
  356. 'current_area' => $current_area,
  357. 'extra_url_parameters' => array(
  358. 'u' => $context['id_member'],
  359. ),
  360. );
  361. // Actually create the menu!
  362. $profile_include_data = createMenu($profile_areas, $menuOptions);
  363. // No menu means no access.
  364. if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
  365. fatal_lang_error('no_access', false);
  366. // Make a note of the Unique ID for this menu.
  367. $context['profile_menu_id'] = $context['max_menu_id'];
  368. $context['profile_menu_name'] = 'menu_data_' . $context['profile_menu_id'];
  369. // Set the selected item - now it's been validated.
  370. $current_area = $profile_include_data['current_area'];
  371. $context['menu_item_selected'] = $current_area;
  372. // 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!
  373. $context['completed_save'] = false;
  374. $security_checks = array();
  375. $found_area = false;
  376. foreach ($profile_areas as $section_id => $section)
  377. {
  378. // Do a bit of spring cleaning so to speak.
  379. foreach ($section['areas'] as $area_id => $area)
  380. {
  381. // Is this our area?
  382. if ($current_area == $area_id)
  383. {
  384. // This can't happen - but is a security check.
  385. if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
  386. fatal_lang_error('no_access', false);
  387. // Are we saving data in a valid area?
  388. if (isset($area['sc']) && isset($_REQUEST['save']))
  389. {
  390. $security_checks['session'] = $area['sc'];
  391. $context['completed_save'] = true;
  392. }
  393. // Do we need to perform a token check?
  394. if (!empty($area['token']))
  395. {
  396. $security_checks[isset($_REQUEST['save']) ? 'validateToken' : 'needsToken'] = $area['token'];
  397. $token_name = $area['token'] !== true ? str_replace('%u', $context['id_member'], $area['token']) : 'profile-u' . $context['id_member'];
  398. $token_type = isset($area['token_type']) && in_array($area['token_type'], array('request', 'post', 'get')) ? $area['token_type'] : 'post';
  399. }
  400. // Does this require session validating?
  401. if (!empty($area['validate']))
  402. $security_checks['validate'] = true;
  403. // Permissions for good measure.
  404. if (!empty($profile_include_data['permission']))
  405. $security_checks['permission'] = $profile_include_data['permission'];
  406. // Either way got something.
  407. $found_area = true;
  408. }
  409. }
  410. }
  411. // Oh dear, some serious security lapse is going on here... we'll put a stop to that!
  412. if (!$found_area)
  413. fatal_lang_error('no_access', false);
  414. // Release this now.
  415. unset($profile_areas);
  416. // Now the context is setup have we got any security checks to carry out additional to that above?
  417. if (isset($security_checks['session']))
  418. checkSession($security_checks['session']);
  419. if (isset($security_checks['validate']))
  420. validateSession();
  421. if (isset($security_checks['validateToken']))
  422. validateToken($token_name, $token_type);
  423. if (isset($security_checks['permission']))
  424. isAllowedTo($security_checks['permission']);
  425. // Create a token if needed.
  426. if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
  427. {
  428. createToken($token_name, $token_type);
  429. $context['token_check'] = $token_name;
  430. }
  431. // File to include?
  432. if (isset($profile_include_data['file']))
  433. require_once($sourcedir . '/' . $profile_include_data['file']);
  434. // Make sure that the area function does exist!
  435. if (!isset($profile_include_data['function']) || !function_exists($profile_include_data['function']))
  436. {
  437. destroyMenu();
  438. fatal_lang_error('no_access', false);
  439. }
  440. // Build the link tree.
  441. $context['linktree'][] = array(
  442. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : ''),
  443. 'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
  444. );
  445. if (!empty($profile_include_data['label']))
  446. $context['linktree'][] = array(
  447. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
  448. 'name' => $profile_include_data['label'],
  449. );
  450. if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
  451. $context['linktree'][] = array(
  452. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
  453. 'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
  454. );
  455. // Set the template for this area and add the profile layer.
  456. $context['sub_template'] = $profile_include_data['function'];
  457. $context['template_layers'][] = 'profile';
  458. // All the subactions that require a user password in order to validate.
  459. $check_password = $context['user']['is_owner'] && in_array($profile_include_data['current_area'], $context['password_areas']);
  460. $context['require_password'] = $check_password && empty($user_settings['openid_uri']);
  461. // If we're in wireless then we have a cut down template...
  462. if (WIRELESS && $context['sub_template'] == 'summary' && WIRELESS_PROTOCOL != 'wap')
  463. $context['sub_template'] = WIRELESS_PROTOCOL . '_profile';
  464. // These will get populated soon!
  465. $post_errors = array();
  466. $profile_vars = array();
  467. // Right - are we saving - if so let's save the old data first.
  468. if ($context['completed_save'])
  469. {
  470. // If it's someone elses profile then validate the session.
  471. if (!$context['user']['is_owner'])
  472. validateSession();
  473. // Clean up the POST variables.
  474. $_POST = htmltrim__recursive($_POST);
  475. $_POST = htmlspecialchars__recursive($_POST);
  476. if ($check_password)
  477. {
  478. // If we're using OpenID try to revalidate.
  479. if (!empty($user_settings['openid_uri']))
  480. {
  481. require_once($sourcedir . '/Subs-OpenID.php');
  482. smf_openID_revalidate();
  483. }
  484. else
  485. {
  486. // You didn't even enter a password!
  487. if (trim($_POST['oldpasswrd']) == '')
  488. $post_errors[] = 'no_password';
  489. // Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
  490. $_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
  491. // Does the integration want to check passwords?
  492. $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
  493. // Bad password!!!
  494. if (!$good_password && $user_info['passwd'] != sha1(strtolower($cur_profile['member_name']) . $_POST['oldpasswrd']))
  495. $post_errors[] = 'bad_password';
  496. // Warn other elements not to jump the gun and do custom changes!
  497. if (in_array('bad_password', $post_errors))
  498. $context['password_auth_failed'] = true;
  499. }
  500. }
  501. // Change the IP address in the database.
  502. if ($context['user']['is_owner'])
  503. $profile_vars['member_ip'] = $user_info['ip'];
  504. // Now call the sub-action function...
  505. if ($current_area == 'activateaccount')
  506. {
  507. if (empty($post_errors))
  508. activateAccount($memID);
  509. }
  510. elseif ($current_area == 'deleteaccount')
  511. {
  512. if (empty($post_errors))
  513. {
  514. deleteAccount2($profile_vars, $post_errors, $memID);
  515. redirectexit();
  516. }
  517. }
  518. elseif ($current_area == 'groupmembership' && empty($post_errors))
  519. {
  520. $msg = groupMembership2($profile_vars, $post_errors, $memID);
  521. // Whatever we've done, we have nothing else to do here...
  522. redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : ''));
  523. }
  524. // Authentication changes?
  525. elseif ($current_area == 'authentication')
  526. {
  527. authentication($memID, true);
  528. }
  529. elseif (in_array($current_area, array('account', 'forumprofile', 'theme', 'pmprefs')))
  530. saveProfileFields();
  531. else
  532. {
  533. $force_redirect = true;
  534. // Ensure we include this.
  535. require_once($sourcedir . '/Profile-Modify.php');
  536. saveProfileChanges($profile_vars, $post_errors, $memID);
  537. }
  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. logAction($k, array_merge($v, array('applicator' => $user_info['id'], 'member_affected' => $memID)), 'user');
  568. }
  569. // Have we got any post save functions to execute?
  570. if (!empty($context['profile_execute_on_save']))
  571. foreach ($context['profile_execute_on_save'] as $saveFunc)
  572. $saveFunc();
  573. // Let them know it worked!
  574. $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
  575. // Invalidate any cached data.
  576. cache_put_data('member_data-profile-' . $memID, null, 0);
  577. }
  578. }
  579. // Have some errors for some reason?
  580. if (!empty($post_errors))
  581. {
  582. // Set all the errors so the template knows what went wrong.
  583. foreach ($post_errors as $error_type)
  584. $context['modify_error'][$error_type] = true;
  585. }
  586. // If it's you then we should redirect upon save.
  587. elseif (!empty($profile_vars) && $context['user']['is_owner'])
  588. redirectexit('action=profile;area=' . $current_area . ';updated');
  589. elseif (!empty($force_redirect))
  590. redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
  591. // Call the appropriate subaction function.
  592. $profile_include_data['function']($memID);
  593. // Set the page title if it's not already set...
  594. if (!isset($context['page_title']))
  595. $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
  596. }
  597. /**
  598. * Load any custom fields for this area... no area means load all, 'summary' loads all public ones.
  599. *
  600. * @param int $memID
  601. * @param string $area = 'summary'
  602. */
  603. function loadCustomFields($memID, $area = 'summary')
  604. {
  605. global $context, $txt, $user_profile, $smcFunc, $user_info, $settings, $scripturl;
  606. // Get the right restrictions in place...
  607. $where = 'active = 1';
  608. if (!allowedTo('admin_forum') && $area != 'register')
  609. {
  610. // If it's the owner they can see two types of private fields, regardless.
  611. if ($memID == $user_info['id'])
  612. $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
  613. else
  614. $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
  615. }
  616. if ($area == 'register')
  617. $where .= ' AND show_reg != 0';
  618. elseif ($area != 'summary')
  619. $where .= ' AND show_profile = {string:area}';
  620. // Load all the relevant fields - and data.
  621. $request = $smcFunc['db_query']('', '
  622. SELECT
  623. col_name, field_name, field_desc, field_type, field_length, field_options,
  624. default_value, bbc, enclose, placement
  625. FROM {db_prefix}custom_fields
  626. WHERE ' . $where,
  627. array(
  628. 'area' => $area,
  629. )
  630. );
  631. $context['custom_fields'] = array();
  632. while ($row = $smcFunc['db_fetch_assoc']($request))
  633. {
  634. // Shortcut.
  635. $exists = $memID && isset($user_profile[$memID], $user_profile[$memID]['options'][$row['col_name']]);
  636. $value = $exists ? $user_profile[$memID]['options'][$row['col_name']] : '';
  637. // If this was submitted already then make the value the posted version.
  638. if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
  639. {
  640. $value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
  641. if (in_array($row['field_type'], array('select', 'radio')))
  642. $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
  643. }
  644. // HTML for the input form.
  645. $output_html = $value;
  646. if ($row['field_type'] == 'check')
  647. {
  648. $true = (!$exists && $row['default_value']) || $value;
  649. $input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" ' . ($true ? 'checked="checked"' : '') . ' class="input_check" />';
  650. $output_html = $true ? $txt['yes'] : $txt['no'];
  651. }
  652. elseif ($row['field_type'] == 'select')
  653. {
  654. $input_html = '<select name="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
  655. $options = explode(',', $row['field_options']);
  656. foreach ($options as $k => $v)
  657. {
  658. $true = (!$exists && $row['default_value'] == $v) || $value == $v;
  659. $input_html .= '<option value="' . $k . '"' . ($true ? ' selected="selected"' : '') . '>' . $v . '</option>';
  660. if ($true)
  661. $output_html = $v;
  662. }
  663. $input_html .= '</select>';
  664. }
  665. elseif ($row['field_type'] == 'radio')
  666. {
  667. $input_html = '<fieldset>';
  668. $options = explode(',', $row['field_options']);
  669. foreach ($options as $k => $v)
  670. {
  671. $true = (!$exists && $row['default_value'] == $v) || $value == $v;
  672. $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 />';
  673. if ($true)
  674. $output_html = $v;
  675. }
  676. $input_html .= '</fieldset>';
  677. }
  678. elseif ($row['field_type'] == 'text')
  679. {
  680. $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" />';
  681. }
  682. else
  683. {
  684. @list ($rows, $cols) = @explode(',', $row['default_value']);
  685. $input_html = '<textarea name="customfield[' . $row['col_name'] . ']" ' . (!empty($rows) ? 'rows="' . $rows . '"' : '') . ' ' . (!empty($cols) ? 'cols="' . $cols . '"' : '') . '>' . $value . '</textarea>';
  686. }
  687. // Parse BBCode
  688. if ($row['bbc'])
  689. $output_html = parse_bbc($output_html);
  690. elseif($row['field_type'] == 'textarea')
  691. // Allow for newlines at least
  692. $output_html = strtr($output_html, array("\n" => '<br />'));
  693. // Enclosing the user input within some other text?
  694. if (!empty($row['enclose']) && !empty($output_html))
  695. $output_html = strtr($row['enclose'], array(
  696. '{SCRIPTURL}' => $scripturl,
  697. '{IMAGES_URL}' => $settings['images_url'],
  698. '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
  699. '{INPUT}' => $output_html,
  700. ));
  701. $context['custom_fields'][] = array(
  702. 'name' => $row['field_name'],
  703. 'desc' => $row['field_desc'],
  704. 'type' => $row['field_type'],
  705. 'input_html' => $input_html,
  706. 'output_html' => $output_html,
  707. 'placement' => $row['placement'],
  708. 'colname' => $row['col_name'],
  709. 'value' => $value,
  710. );
  711. }
  712. $smcFunc['db_free_result']($request);
  713. }
  714. ?>