Profile.php 35 KB

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