2
0

Profile.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  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 2014 Simple Machines and individual contributors
  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('No direct access...');
  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, $post_errors, $user_settings;
  27. // Don't reload this as we may have processed error strings.
  28. if (empty($post_errors))
  29. loadLanguage('Profile+Drafts');
  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, but only if you're not a guest.
  39. else
  40. {
  41. // Members only...
  42. is_not_guest();
  43. $memberResult = loadMemberData($user_info['id'], false, 'profile');
  44. }
  45. // Check if loadMemberData() has returned a valid result.
  46. if (!is_array($memberResult))
  47. fatal_lang_error('not_a_user', false);
  48. // If all went well, we have a valid member ID!
  49. list ($memID) = $memberResult;
  50. $context['id_member'] = $memID;
  51. $cur_profile = $user_profile[$memID];
  52. // Let's have some information about this member ready, too.
  53. loadMemberContext($memID);
  54. $context['member'] = $memberContext[$memID];
  55. // Is this the profile of the user himself or herself?
  56. $context['user']['is_owner'] = $memID == $user_info['id'];
  57. // Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission.
  58. // And we care about what the current user can do, not what the user whose profile it is.
  59. if ($user_info['mod_cache']['gq'] != '0=1')
  60. $user_info['permissions'][] = 'approve_group_requests';
  61. /* Define all the sections within the profile area!
  62. We start by defining the permission required - then SMF takes this and turns it into the relevant context ;)
  63. Possible fields:
  64. For Section:
  65. string $title: Section title.
  66. array $areas: Array of areas within this section.
  67. For Areas:
  68. string $label: Text string that will be used to show the area in the menu.
  69. string $file: Optional text string that may contain a file name that's needed for inclusion in order to display the area properly.
  70. string $custom_url: Optional href for area.
  71. string $function: Function to execute for this section.
  72. bool $enabled: Should area be shown?
  73. string $sc: Session check validation to do on save - note without this save will get unset - if set.
  74. bool $hidden: Does this not actually appear on the menu?
  75. bool $password: Whether to require the user's password in order to save the data in the area.
  76. array $subsections: Array of subsections, in order of appearance.
  77. array $permission: Array of permissions to determine who can access this area. Should contain arrays $own and $any.
  78. */
  79. $profile_areas = array(
  80. 'info' => array(
  81. 'title' => $txt['profileInfo'],
  82. 'areas' => array(
  83. 'summary' => array(
  84. 'label' => $txt['summary'],
  85. 'file' => 'Profile-View.php',
  86. 'function' => 'summary',
  87. 'icon' => 'administration.png',
  88. 'permission' => array(
  89. 'own' => 'is_not_guest',
  90. 'any' => 'profile_view',
  91. ),
  92. ),
  93. 'popup' => array(
  94. 'function' => 'profile_popup',
  95. 'permission' => array(
  96. 'own' => 'is_not_guest',
  97. 'any' => array(),
  98. ),
  99. 'select' => 'summary',
  100. ),
  101. 'alerts_popup' => array(
  102. 'function' => 'alerts_popup',
  103. 'permission' => array(
  104. 'own' => 'is_not_guest',
  105. 'any' => array(),
  106. ),
  107. 'select' => 'summary',
  108. ),
  109. 'statistics' => array(
  110. 'label' => $txt['statPanel'],
  111. 'file' => 'Profile-View.php',
  112. 'function' => 'statPanel',
  113. 'icon' => 'stats.png',
  114. 'permission' => array(
  115. 'own' => 'is_not_guest',
  116. 'any' => 'profile_view',
  117. ),
  118. ),
  119. 'showposts' => array(
  120. 'label' => $txt['showPosts'],
  121. 'file' => 'Profile-View.php',
  122. 'function' => 'showPosts',
  123. 'icon' => 'posts.png',
  124. 'subsections' => array(
  125. 'messages' => array($txt['showMessages'], array('is_not_guest', 'profile_view')),
  126. 'topics' => array($txt['showTopics'], array('is_not_guest', 'profile_view')),
  127. 'unwatchedtopics' => array($txt['showUnwatched'], array('is_not_guest', 'profile_view'), 'enabled' => $modSettings['enable_unwatch'] && $context['user']['is_owner']),
  128. 'attach' => array($txt['showAttachments'], array('is_not_guest', 'profile_view')),
  129. ),
  130. 'permission' => array(
  131. 'own' => 'is_not_guest',
  132. 'any' => 'profile_view',
  133. ),
  134. ),
  135. 'showdrafts' => array(
  136. 'label' => $txt['drafts_show'],
  137. 'file' => 'Drafts.php',
  138. 'function' => 'showProfileDrafts',
  139. 'icon' => 'drafts.png',
  140. 'enabled' => !empty($modSettings['drafts_post_enabled']) && $context['user']['is_owner'],
  141. 'permission' => array(
  142. 'own' => 'is_not_guest',
  143. 'any' => array(),
  144. ),
  145. ),
  146. 'permissions' => array(
  147. 'label' => $txt['showPermissions'],
  148. 'file' => 'Profile-View.php',
  149. 'function' => 'showPermissions',
  150. 'icon' => 'permissions.png',
  151. 'permission' => array(
  152. 'own' => 'manage_permissions',
  153. 'any' => 'manage_permissions',
  154. ),
  155. ),
  156. 'tracking' => array(
  157. 'label' => $txt['trackUser'],
  158. 'file' => 'Profile-View.php',
  159. 'function' => 'tracking',
  160. 'icon' => 'logs.png',
  161. 'subsections' => array(
  162. 'activity' => array($txt['trackActivity'], 'moderate_forum'),
  163. 'ip' => array($txt['trackIP'], 'moderate_forum'),
  164. 'edits' => array($txt['trackEdits'], 'moderate_forum', 'enabled' => !empty($modSettings['userlog_enabled'])),
  165. 'groupreq' => array($txt['trackGroupRequests'], 'approve_group_requests', 'enabled' => !empty($modSettings['show_group_membership'])),
  166. 'logins' => array($txt['trackLogins'], 'moderate_forum'),
  167. ),
  168. 'permission' => array(
  169. 'own' => array('moderate_forum', 'approve_group_requests'),
  170. 'any' => array('moderate_forum', 'approve_group_requests'),
  171. ),
  172. ),
  173. 'viewwarning' => array(
  174. 'label' => $txt['profile_view_warnings'],
  175. 'enabled' => $modSettings['warning_settings'][0] == 1 && $cur_profile['warning'] && (!empty($modSettings['warning_show']) && ($context['user']['is_owner'] || $modSettings['warning_show'] == 2)),
  176. 'file' => 'Profile-View.php',
  177. 'function' => 'viewWarning',
  178. 'icon' => 'warning.png',
  179. 'permission' => array(
  180. 'own' => 'is_not_guest', // @todo this needs to be a view-own warning
  181. 'any' => 'issue_warning',
  182. ),
  183. ),
  184. ),
  185. ),
  186. 'edit_profile' => array(
  187. 'title' => $txt['profileEdit'],
  188. 'areas' => array(
  189. 'account' => array(
  190. 'label' => $txt['account'],
  191. 'file' => 'Profile-Modify.php',
  192. 'function' => 'account',
  193. 'icon' => 'maintain.png',
  194. 'enabled' => $context['user']['is_admin'] || ($cur_profile['id_group'] != 1 && !in_array(1, explode(',', $cur_profile['additional_groups']))),
  195. 'sc' => 'post',
  196. 'token' => 'profile-ac%u',
  197. 'password' => true,
  198. 'permission' => array(
  199. 'own' => array('profile_identity_any', 'profile_identity_own', 'profile_password_any', 'profile_password_own', 'manage_membergroups'),
  200. 'any' => array('profile_identity_any', 'profile_password_any', 'manage_membergroups'),
  201. ),
  202. ),
  203. 'forumprofile' => array(
  204. 'label' => $txt['forumprofile'],
  205. 'file' => 'Profile-Modify.php',
  206. 'function' => 'forumProfile',
  207. 'icon' => 'members.png',
  208. 'sc' => 'post',
  209. 'token' => 'profile-fp%u',
  210. 'permission' => array(
  211. 'own' => array('profile_forum_any', 'profile_forum_own'),
  212. 'any' => array('profile_forum_any'),
  213. ),
  214. ),
  215. 'theme' => array(
  216. 'label' => $txt['theme'],
  217. 'file' => 'Profile-Modify.php',
  218. 'function' => 'theme',
  219. 'icon' => 'features.png',
  220. 'sc' => 'post',
  221. 'token' => 'profile-th%u',
  222. 'permission' => array(
  223. 'own' => array('profile_extra_any', 'profile_extra_own'),
  224. 'any' => array('profile_extra_any'),
  225. ),
  226. ),
  227. 'authentication' => array(
  228. 'label' => $txt['authentication'],
  229. 'file' => 'Profile-Modify.php',
  230. 'function' => 'authentication',
  231. 'icon' => 'openid.png',
  232. 'enabled' => !empty($modSettings['enableOpenID']) && ($modSettings['enableOpenID'] == 1 || !empty($cur_profile['openid_uri'])),
  233. 'sc' => 'post',
  234. 'token' => 'profile-au%u',
  235. 'hidden' => empty($modSettings['enableOpenID']) && empty($cur_profile['openid_uri']),
  236. 'password' => true,
  237. 'permission' => array(
  238. 'own' => array('profile_password_any', 'profile_password_own'),
  239. 'any' => array('profile_password_any'),
  240. ),
  241. ),
  242. 'notification' => array(
  243. 'label' => $txt['notification'],
  244. 'file' => 'Profile-Modify.php',
  245. 'function' => 'notification',
  246. 'icon' => 'mail.png',
  247. 'sc' => 'post',
  248. //'token' => 'profile-nt%u', This is not checked here. We do it in the function itself - but if it was checked, this is what it'd be.
  249. 'subsections' => array(
  250. 'alerts' => array($txt['alert_prefs'], array('is_not_guest', 'profile_extra_any')),
  251. 'topics' => array($txt['watched_topics'], array('is_not_guest', 'profile_extra_any')),
  252. 'boards' => array($txt['watched_boards'], array('is_not_guest', 'profile_extra_any')),
  253. ),
  254. 'permission' => array(
  255. 'own' => array('is_not_guest'),
  256. 'any' => array('profile_extra_any'), // If you change this, update it in the functions themselves; we delegate all saving checks there.
  257. ),
  258. ),
  259. 'ignoreboards' => array(
  260. 'label' => $txt['ignoreboards'],
  261. 'file' => 'Profile-Modify.php',
  262. 'function' => 'ignoreboards',
  263. 'icon' => 'boards.png',
  264. 'enabled' => !empty($modSettings['allow_ignore_boards']),
  265. 'sc' => 'post',
  266. 'token' => 'profile-ib%u',
  267. 'permission' => array(
  268. 'own' => array('profile_extra_any', 'profile_extra_own'),
  269. 'any' => array('profile_extra_any'),
  270. ),
  271. ),
  272. 'lists' => array(
  273. 'label' => $txt['editBuddyIgnoreLists'],
  274. 'file' => 'Profile-Modify.php',
  275. 'function' => 'editBuddyIgnoreLists',
  276. 'icon' => 'frenemy.png',
  277. 'enabled' => !empty($modSettings['enable_buddylist']) && $context['user']['is_owner'],
  278. 'sc' => 'post',
  279. 'subsections' => array(
  280. 'buddies' => array($txt['editBuddies']),
  281. 'ignore' => array($txt['editIgnoreList']),
  282. ),
  283. 'permission' => array(
  284. 'own' => array('profile_extra_any', 'profile_extra_own'),
  285. 'any' => array(),
  286. ),
  287. ),
  288. 'groupmembership' => array(
  289. 'label' => $txt['groupmembership'],
  290. 'file' => 'Profile-Modify.php',
  291. 'function' => 'groupMembership',
  292. 'icon' => 'membergroups.png',
  293. 'enabled' => !empty($modSettings['show_group_membership']) && $context['user']['is_owner'],
  294. 'sc' => 'request',
  295. 'token' => 'profile-gm%u',
  296. 'token_type' => 'request',
  297. 'permission' => array(
  298. 'own' => array('is_not_guest'),
  299. 'any' => array('manage_membergroups'),
  300. ),
  301. ),
  302. ),
  303. ),
  304. 'profile_action' => array(
  305. 'title' => $txt['profileAction'],
  306. 'areas' => array(
  307. 'sendpm' => array(
  308. 'label' => $txt['profileSendIm'],
  309. 'custom_url' => $scripturl . '?action=pm;sa=send',
  310. 'icon' => 'personal_message.png',
  311. 'permission' => array(
  312. 'own' => array(),
  313. 'any' => array('pm_send'),
  314. ),
  315. ),
  316. 'report' => array(
  317. 'label' => $txt['report_profile'],
  318. 'custom_url' => $scripturl . '?action=reporttm;' . $context['session_var'] . '=' . $context['session_id'],
  319. 'icon' => 'warning.png',
  320. 'permission' => array(
  321. 'own' => array(),
  322. 'any' => array('moderate_forum', 'report_user'),
  323. ),
  324. ),
  325. 'issuewarning' => array(
  326. 'label' => $txt['profile_issue_warning'],
  327. 'enabled' => $modSettings['warning_settings'][0] == 1,
  328. 'file' => 'Profile-Actions.php',
  329. 'function' => 'issueWarning',
  330. 'icon' => 'warning.png',
  331. 'token' => 'profile-iw%u',
  332. 'permission' => array(
  333. 'own' => array(),
  334. 'any' => array('issue_warning'),
  335. ),
  336. ),
  337. 'banuser' => array(
  338. 'label' => $txt['profileBanUser'],
  339. 'custom_url' => $scripturl . '?action=admin;area=ban;sa=add',
  340. 'icon' => 'ban.png',
  341. 'enabled' => $cur_profile['id_group'] != 1 && !in_array(1, explode(',', $cur_profile['additional_groups'])),
  342. 'permission' => array(
  343. 'own' => array(),
  344. 'any' => array('manage_bans'),
  345. ),
  346. ),
  347. 'subscriptions' => array(
  348. 'label' => $txt['subscriptions'],
  349. 'file' => 'Profile-Actions.php',
  350. 'function' => 'subscriptions',
  351. 'icon' => 'paid.png',
  352. 'enabled' => !empty($modSettings['paid_enabled']),
  353. 'permission' => array(
  354. 'own' => array('is_not_guest'),
  355. 'any' => array('moderate_forum'),
  356. ),
  357. ),
  358. 'deleteaccount' => array(
  359. 'label' => $txt['deleteAccount'],
  360. 'file' => 'Profile-Actions.php',
  361. 'function' => 'deleteAccount',
  362. 'icon' => 'members_delete.png',
  363. 'sc' => 'post',
  364. 'token' => 'profile-da%u',
  365. 'password' => true,
  366. 'permission' => array(
  367. 'own' => array('profile_remove_any', 'profile_remove_own'),
  368. 'any' => array('profile_remove_any'),
  369. ),
  370. ),
  371. 'activateaccount' => array(
  372. 'file' => 'Profile-Actions.php',
  373. 'function' => 'activateAccount',
  374. 'icon' => 'regcenter.png',
  375. 'sc' => 'get',
  376. 'token' => 'profile-aa%u',
  377. 'token_type' => 'get',
  378. 'permission' => array(
  379. 'own' => array(),
  380. 'any' => array('moderate_forum'),
  381. ),
  382. ),
  383. ),
  384. ),
  385. );
  386. // Let them modify profile areas easily.
  387. call_integration_hook('integrate_profile_areas', array(&$profile_areas));
  388. // Do some cleaning ready for the menu function.
  389. $context['password_areas'] = array();
  390. $current_area = isset($_REQUEST['area']) ? $_REQUEST['area'] : '';
  391. foreach ($profile_areas as $section_id => $section)
  392. {
  393. // Do a bit of spring cleaning so to speak.
  394. foreach ($section['areas'] as $area_id => $area)
  395. {
  396. // If it said no permissions that meant it wasn't valid!
  397. if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
  398. $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
  399. // Otherwise pick the right set.
  400. else
  401. $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
  402. // Password required - only if not on OpenID.
  403. if (!empty($area['password']))
  404. $context['password_areas'][] = $area_id;
  405. }
  406. }
  407. // Is there an updated message to show?
  408. if (isset($_GET['updated']))
  409. $context['profile_updated'] = $txt['profile_updated_own'];
  410. // Set a few options for the menu.
  411. $menuOptions = array(
  412. 'disable_url_session_check' => true,
  413. 'current_area' => $current_area,
  414. 'extra_url_parameters' => array(
  415. 'u' => $context['id_member'],
  416. ),
  417. );
  418. // Actually create the menu!
  419. $profile_include_data = createMenu($profile_areas, $menuOptions);
  420. // No menu means no access.
  421. if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
  422. fatal_lang_error('no_access', false);
  423. // Make a note of the Unique ID for this menu.
  424. $context['profile_menu_id'] = $context['max_menu_id'];
  425. $context['profile_menu_name'] = 'menu_data_' . $context['profile_menu_id'];
  426. // Set the selected item - now it's been validated.
  427. $current_area = $profile_include_data['current_area'];
  428. $current_sa = $profile_include_data['current_subsection'];
  429. $context['menu_item_selected'] = $current_area;
  430. // 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!
  431. $context['completed_save'] = false;
  432. $context['do_preview'] = isset($_REQUEST['preview_signature']);
  433. $security_checks = array();
  434. $found_area = false;
  435. foreach ($profile_areas as $section_id => $section)
  436. {
  437. // Do a bit of spring cleaning so to speak.
  438. foreach ($section['areas'] as $area_id => $area)
  439. {
  440. // Is this our area?
  441. if ($current_area == $area_id)
  442. {
  443. // This can't happen - but is a security check.
  444. if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
  445. fatal_lang_error('no_access', false);
  446. // Are we saving data in a valid area?
  447. if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview']))
  448. {
  449. $security_checks['session'] = $area['sc'];
  450. $context['completed_save'] = true;
  451. }
  452. // Do we need to perform a token check?
  453. if (!empty($area['token']))
  454. {
  455. $security_checks[isset($_REQUEST['save']) ? 'validateToken' : 'needsToken'] = $area['token'];
  456. $token_name = $area['token'] !== true ? str_replace('%u', $context['id_member'], $area['token']) : 'profile-u' . $context['id_member'];
  457. $token_type = isset($area['token_type']) && in_array($area['token_type'], array('request', 'post', 'get')) ? $area['token_type'] : 'post';
  458. }
  459. // Does this require session validating?
  460. if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner']))
  461. $security_checks['validate'] = true;
  462. // Permissions for good measure.
  463. if (!empty($profile_include_data['permission']))
  464. $security_checks['permission'] = $profile_include_data['permission'];
  465. // Either way got something.
  466. $found_area = true;
  467. }
  468. }
  469. }
  470. // Oh dear, some serious security lapse is going on here... we'll put a stop to that!
  471. if (!$found_area)
  472. fatal_lang_error('no_access', false);
  473. // Release this now.
  474. unset($profile_areas);
  475. // Now the context is setup have we got any security checks to carry out additional to that above?
  476. if (isset($security_checks['session']))
  477. checkSession($security_checks['session']);
  478. if (isset($security_checks['validate']))
  479. validateSession();
  480. if (isset($security_checks['validateToken']))
  481. validateToken($token_name, $token_type);
  482. if (isset($security_checks['permission']))
  483. isAllowedTo($security_checks['permission']);
  484. // Create a token if needed.
  485. if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
  486. {
  487. createToken($token_name, $token_type);
  488. $context['token_check'] = $token_name;
  489. }
  490. // File to include?
  491. if (isset($profile_include_data['file']))
  492. require_once($sourcedir . '/' . $profile_include_data['file']);
  493. // Make sure that the area function does exist!
  494. if (!isset($profile_include_data['function']) || !function_exists($profile_include_data['function']))
  495. {
  496. destroyMenu();
  497. fatal_lang_error('no_access', false);
  498. }
  499. // Build the link tree.
  500. $context['linktree'][] = array(
  501. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : ''),
  502. 'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
  503. );
  504. if (!empty($profile_include_data['label']))
  505. $context['linktree'][] = array(
  506. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
  507. 'name' => $profile_include_data['label'],
  508. );
  509. if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
  510. $context['linktree'][] = array(
  511. 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
  512. 'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
  513. );
  514. // Set the template for this area and add the profile layer.
  515. $context['sub_template'] = $profile_include_data['function'];
  516. $context['template_layers'][] = 'profile';
  517. // All the subactions that require a user password in order to validate.
  518. $check_password = $context['user']['is_owner'] && in_array($profile_include_data['current_area'], $context['password_areas']);
  519. $context['require_password'] = $check_password && empty($user_settings['openid_uri']);
  520. // If we're in wireless then we have a cut down template...
  521. if (WIRELESS && $context['sub_template'] == 'summary' && WIRELESS_PROTOCOL != 'wap')
  522. $context['sub_template'] = WIRELESS_PROTOCOL . '_profile';
  523. if (!WIRELESS)
  524. loadJavascriptFile('profile.js', array('default_theme' => true, 'defer' => false), 'smf_profile');
  525. // These will get populated soon!
  526. $post_errors = array();
  527. $profile_vars = array();
  528. // Right - are we saving - if so let's save the old data first.
  529. if ($context['completed_save'])
  530. {
  531. // Clean up the POST variables.
  532. $_POST = htmltrim__recursive($_POST);
  533. $_POST = htmlspecialchars__recursive($_POST);
  534. if ($check_password)
  535. {
  536. // If we're using OpenID try to revalidate.
  537. if (!empty($user_settings['openid_uri']))
  538. {
  539. require_once($sourcedir . '/Subs-OpenID.php');
  540. smf_openID_revalidate();
  541. }
  542. else
  543. {
  544. // You didn't even enter a password!
  545. if (trim($_POST['oldpasswrd']) == '')
  546. $post_errors[] = 'no_password';
  547. // Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
  548. $_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
  549. // Does the integration want to check passwords?
  550. $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
  551. // Bad password!!!
  552. if (!$good_password && $user_info['passwd'] != sha1(strtolower($user_profile[$memID]['member_name']) . un_htmlspecialchars(stripslashes($_POST['oldpasswrd']))))
  553. $post_errors[] = 'bad_password';
  554. // Warn other elements not to jump the gun and do custom changes!
  555. if (in_array('bad_password', $post_errors))
  556. $context['password_auth_failed'] = true;
  557. }
  558. }
  559. // Change the IP address in the database.
  560. if ($context['user']['is_owner'])
  561. $profile_vars['member_ip'] = $user_info['ip'];
  562. // Now call the sub-action function...
  563. if ($current_area == 'activateaccount')
  564. {
  565. if (empty($post_errors))
  566. activateAccount($memID);
  567. }
  568. elseif ($current_area == 'deleteaccount')
  569. {
  570. if (empty($post_errors))
  571. {
  572. deleteAccount2($memID);
  573. redirectexit();
  574. }
  575. }
  576. elseif ($current_area == 'groupmembership' && empty($post_errors))
  577. {
  578. $msg = groupMembership2($profile_vars, $post_errors, $memID);
  579. // Whatever we've done, we have nothing else to do here...
  580. redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : ''));
  581. }
  582. // Authentication changes?
  583. elseif ($current_area == 'authentication')
  584. {
  585. authentication($memID, true);
  586. }
  587. elseif (in_array($current_area, array('account', 'forumprofile', 'theme')))
  588. saveProfileFields();
  589. else
  590. {
  591. $force_redirect = true;
  592. // Ensure we include this.
  593. require_once($sourcedir . '/Profile-Modify.php');
  594. saveProfileChanges($profile_vars, $post_errors, $memID);
  595. }
  596. call_integration_hook('integrate_profile_save', array(&$profile_vars, &$post_errors, $memID));
  597. // There was a problem, let them try to re-enter.
  598. if (!empty($post_errors))
  599. {
  600. // Load the language file so we can give a nice explanation of the errors.
  601. loadLanguage('Errors');
  602. $context['post_errors'] = $post_errors;
  603. }
  604. elseif (!empty($profile_vars))
  605. {
  606. // If we've changed the password, notify any integration that may be listening in.
  607. if (isset($profile_vars['passwd']))
  608. call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
  609. updateMemberData($memID, $profile_vars);
  610. // What if this is the newest member?
  611. if ($modSettings['latestMember'] == $memID)
  612. updateStats('member');
  613. elseif (isset($profile_vars['real_name']))
  614. updateSettings(array('memberlist_updated' => time()));
  615. // If the member changed his/her birthdate, update calendar statistics.
  616. if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name']))
  617. updateSettings(array(
  618. 'calendar_updated' => time(),
  619. ));
  620. // Anything worth logging?
  621. if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled']))
  622. {
  623. $log_changes = array();
  624. require_once($sourcedir . '/Logging.php');
  625. foreach ($context['log_changes'] as $k => $v)
  626. $log_changes[] = array(
  627. 'action' => $k,
  628. 'log_type' => 'user',
  629. 'extra' => array_merge($v, array(
  630. 'applicator' => $user_info['id'],
  631. 'member_affected' => $memID,
  632. )),
  633. );
  634. logActions($log_changes);
  635. }
  636. // Have we got any post save functions to execute?
  637. if (!empty($context['profile_execute_on_save']))
  638. foreach ($context['profile_execute_on_save'] as $saveFunc)
  639. $saveFunc();
  640. // Let them know it worked!
  641. $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
  642. // Invalidate any cached data.
  643. cache_put_data('member_data-profile-' . $memID, null, 0);
  644. }
  645. }
  646. // Have some errors for some reason?
  647. if (!empty($post_errors))
  648. {
  649. // Set all the errors so the template knows what went wrong.
  650. foreach ($post_errors as $error_type)
  651. $context['modify_error'][$error_type] = true;
  652. }
  653. // If it's you then we should redirect upon save.
  654. elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
  655. redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
  656. elseif (!empty($force_redirect))
  657. redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
  658. // Call the appropriate subaction function.
  659. $profile_include_data['function']($memID);
  660. // Set the page title if it's not already set...
  661. if (!isset($context['page_title']))
  662. $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
  663. }
  664. /**
  665. * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user.
  666. *
  667. * @param int $memID
  668. */
  669. function profile_popup($memID)
  670. {
  671. global $context, $scripturl, $txt, $db_show_debug;
  672. // We do not want to output debug information here.
  673. $db_show_debug = false;
  674. // We only want to output our little layer here.
  675. $context['template_layers'] = array();
  676. // This list will pull from the master list wherever possible. Hopefully it should be clear what does what.
  677. $profile_items = array(
  678. array(
  679. 'menu' => 'info',
  680. 'area' => 'summary',
  681. 'title' => $txt['popup_summary'],
  682. ),
  683. array(
  684. 'menu' => 'edit_profile',
  685. 'area' => 'account',
  686. ),
  687. array(
  688. 'menu' => 'info',
  689. 'area' => 'showposts',
  690. 'title' => $txt['popup_showposts'],
  691. ),
  692. array(
  693. 'menu' => 'edit_profile',
  694. 'area' => 'forumprofile',
  695. 'title' => $txt['profileEdit'],
  696. ),
  697. array(
  698. 'menu' => 'edit_profile',
  699. 'area' => 'notification',
  700. ),
  701. array(
  702. 'menu' => 'edit_profile',
  703. 'area' => 'theme',
  704. 'title' => $txt['popup_preferences'],
  705. ),
  706. array(
  707. 'menu' => 'edit_profile',
  708. 'area' => 'ignoreboards',
  709. ),
  710. array(
  711. 'menu' => 'edit_profile',
  712. 'area' => 'lists',
  713. 'url' => $scripturl . '?action=profile;area=lists;sa=ignore',
  714. 'title' => $txt['popup_ignore'],
  715. ),
  716. array(
  717. 'menu' => 'edit_profile',
  718. 'area' => 'groupmembership',
  719. ),
  720. array(
  721. 'menu' => 'profile_action',
  722. 'area' => 'subscriptions',
  723. ),
  724. );
  725. call_integration_hook('integrate_profile_popup', array(&$profile_items));
  726. // Now check if these items are available
  727. $context['profile_items'] = array();
  728. $menu_context = &$context[$context['profile_menu_name']]['sections'];
  729. foreach ($profile_items as $item)
  730. {
  731. if (isset($menu_context[$item['menu']]['areas'][$item['area']]))
  732. {
  733. $context['profile_items'][] = $item;
  734. }
  735. }
  736. }
  737. /**
  738. * Set up the requirements for the alerts popup - the area that shows all the alerts just quickly for the current user.
  739. *
  740. * @param int $memID
  741. */
  742. function alerts_popup($memID)
  743. {
  744. global $context, $scripturl, $txt, $sourcedir, $db_show_debug;
  745. // We do not want to output debug information here.
  746. $db_show_debug = false;
  747. // We only want to output our little layer here.
  748. $context['template_layers'] = array();
  749. // Now fetch me my unread alerts, pronto!
  750. require_once($sourcedir . '/Profile-View.php');
  751. $context['unread_alerts'] = fetch_alerts($memID, false);
  752. }
  753. /**
  754. * Load any custom fields for this area... no area means load all, 'summary' loads all public ones.
  755. *
  756. * @param int $memID
  757. * @param string $area = 'summary'
  758. */
  759. function loadCustomFields($memID, $area = 'summary')
  760. {
  761. global $context, $txt, $user_profile, $smcFunc, $user_info, $settings, $scripturl;
  762. // Get the right restrictions in place...
  763. $where = 'active = 1';
  764. if (!allowedTo('admin_forum') && $area != 'register')
  765. {
  766. // If it's the owner they can see two types of private fields, regardless.
  767. if ($memID == $user_info['id'])
  768. $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
  769. else
  770. $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
  771. }
  772. if ($area == 'register')
  773. $where .= ' AND show_reg != 0';
  774. elseif ($area != 'summary')
  775. $where .= ' AND show_profile = {string:area}';
  776. // Load all the relevant fields - and data.
  777. $request = $smcFunc['db_query']('', '
  778. SELECT
  779. col_name, field_name, field_desc, field_type, show_reg, field_length, field_options,
  780. default_value, bbc, enclose, placement
  781. FROM {db_prefix}custom_fields
  782. WHERE ' . $where,
  783. array(
  784. 'area' => $area,
  785. )
  786. );
  787. $context['custom_fields'] = array();
  788. $context['custom_fields_required'] = false;
  789. while ($row = $smcFunc['db_fetch_assoc']($request))
  790. {
  791. // Shortcut.
  792. $exists = $memID && isset($user_profile[$memID], $user_profile[$memID]['options'][$row['col_name']]);
  793. $value = $exists ? $user_profile[$memID]['options'][$row['col_name']] : '';
  794. // If this was submitted already then make the value the posted version.
  795. if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
  796. {
  797. $value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
  798. if (in_array($row['field_type'], array('select', 'radio')))
  799. $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
  800. }
  801. // HTML for the input form.
  802. $output_html = $value;
  803. if ($row['field_type'] == 'check')
  804. {
  805. $true = (!$exists && $row['default_value']) || $value;
  806. $input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . ' class="input_check">';
  807. $output_html = $true ? $txt['yes'] : $txt['no'];
  808. }
  809. elseif ($row['field_type'] == 'select')
  810. {
  811. $input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
  812. $options = explode(',', $row['field_options']);
  813. foreach ($options as $k => $v)
  814. {
  815. $true = (!$exists && $row['default_value'] == $v) || $value == $v;
  816. $input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>';
  817. if ($true)
  818. $output_html = $v;
  819. }
  820. $input_html .= '</select>';
  821. }
  822. elseif ($row['field_type'] == 'radio')
  823. {
  824. $input_html = '<fieldset>';
  825. $options = explode(',', $row['field_options']);
  826. foreach ($options as $k => $v)
  827. {
  828. $true = (!$exists && $row['default_value'] == $v) || $value == $v;
  829. $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' : '') . '>' . $v . '</label><br>';
  830. if ($true)
  831. $output_html = $v;
  832. }
  833. $input_html .= '</fieldset>';
  834. }
  835. elseif ($row['field_type'] == 'text')
  836. {
  837. $input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="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"' . ($row['show_reg'] == 2 ? ' required' : '') . '>';
  838. }
  839. else
  840. {
  841. @list ($rows, $cols) = @explode(',', $row['default_value']);
  842. $input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '' ). '>' . $value . '</textarea>';
  843. }
  844. // Parse BBCode
  845. if ($row['bbc'])
  846. $output_html = parse_bbc($output_html);
  847. elseif ($row['field_type'] == 'textarea')
  848. // Allow for newlines at least
  849. $output_html = strtr($output_html, array("\n" => '<br>'));
  850. // Enclosing the user input within some other text?
  851. if (!empty($row['enclose']) && !empty($output_html))
  852. $output_html = strtr($row['enclose'], array(
  853. '{SCRIPTURL}' => $scripturl,
  854. '{IMAGES_URL}' => $settings['images_url'],
  855. '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
  856. '{INPUT}' => $output_html,
  857. ));
  858. $context['custom_fields'][] = array(
  859. 'name' => $row['field_name'],
  860. 'desc' => $row['field_desc'],
  861. 'type' => $row['field_type'],
  862. 'input_html' => $input_html,
  863. 'output_html' => $output_html,
  864. 'placement' => $row['placement'],
  865. 'colname' => $row['col_name'],
  866. 'value' => $value,
  867. 'show_reg' => $row['show_reg'],
  868. );
  869. $context['custom_fields_required'] = $context['custom_fields_required'] || $row['show_reg'] == 2;
  870. }
  871. $smcFunc['db_free_result']($request);
  872. call_integration_hook('integrate_load_custom_profile_fields', array($memID, $area));
  873. }
  874. ?>