PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/profile.php

https://github.com/gencer/punbb
PHP | 2965 lines | 2277 code | 515 blank | 173 comment | 770 complexity | dbdb1b320f1dccb175935af8e043f434 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Allows users to view and edit their details.
  4. *
  5. * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
  6. * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  7. * @package PunBB
  8. */
  9. if (!defined('FORUM_ROOT'))
  10. define('FORUM_ROOT', './');
  11. require FORUM_ROOT.'include/common.php';
  12. ($hook = get_hook('pf_start')) ? eval($hook) : null;
  13. $action = isset($_GET['action']) ? $_GET['action'] : null;
  14. $section = isset($_GET['section']) ? $_GET['section'] : 'about'; // Default to section "about"
  15. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  16. if ($id < 2)
  17. message($lang_common['Bad request']);
  18. $errors = array();
  19. if ($action != 'change_pass' || !isset($_GET['key']))
  20. {
  21. if ($forum_user['g_read_board'] == '0')
  22. message($lang_common['No view']);
  23. else if ($forum_user['g_view_users'] == '0' && ($forum_user['is_guest'] || $forum_user['id'] != $id))
  24. message($lang_common['No permission']);
  25. }
  26. // Load the profile.php language file
  27. require FORUM_ROOT.'lang/'.$forum_user['language'].'/profile.php';
  28. // Fetch info about the user whose profile we're viewing
  29. $query = array(
  30. 'SELECT' => 'u.*, g.g_id, g.g_user_title, g.g_moderator',
  31. 'FROM' => 'users AS u',
  32. 'JOINS' => array(
  33. array(
  34. 'LEFT JOIN' => 'groups AS g',
  35. 'ON' => 'g.g_id=u.group_id'
  36. )
  37. ),
  38. 'WHERE' => 'u.id='.$id
  39. );
  40. ($hook = get_hook('pf_qr_get_user_info')) ? eval($hook) : null;
  41. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  42. $user = $forum_db->fetch_assoc($result);
  43. if (!$user)
  44. message($lang_common['Bad request']);
  45. if ($action == 'change_pass')
  46. {
  47. ($hook = get_hook('pf_change_pass_selected')) ? eval($hook) : null;
  48. // User pressed the cancel button
  49. if (isset($_POST['cancel']))
  50. redirect(forum_link($forum_url['profile_about'], $id), $lang_common['Cancel redirect']);
  51. if (isset($_GET['key']))
  52. {
  53. $key = $_GET['key'];
  54. // If the user is already logged in we shouldn't be here :)
  55. if (!$forum_user['is_guest'])
  56. message($lang_profile['Pass logout']);
  57. ($hook = get_hook('pf_change_pass_key_supplied')) ? eval($hook) : null;
  58. if ($key == '' || $key != $user['activate_key'])
  59. message(sprintf($lang_profile['Pass key bad'], '<a href="mailto:'.forum_htmlencode($forum_config['o_admin_email']).'">'.forum_htmlencode($forum_config['o_admin_email']).'</a>'));
  60. else
  61. {
  62. if (isset($_POST['form_sent']))
  63. {
  64. ($hook = get_hook('pf_change_pass_key_form_submitted')) ? eval($hook) : null;
  65. $new_password1 = forum_trim($_POST['req_new_password1']);
  66. $new_password2 = ($forum_config['o_mask_passwords'] == '1') ? forum_trim($_POST['req_new_password2']) : $new_password1;
  67. if (utf8_strlen($new_password1) < 4)
  68. $errors[] = $lang_profile['Pass too short'];
  69. else if ($new_password1 != $new_password2)
  70. $errors[] = $lang_profile['Pass not match'];
  71. // Did everything go according to plan?
  72. if (empty($errors))
  73. {
  74. $new_password_hash = forum_hash($new_password1, $user['salt']);
  75. $query = array(
  76. 'UPDATE' => 'users',
  77. 'SET' => 'password=\''.$new_password_hash.'\', activate_key=NULL',
  78. 'WHERE' => 'id='.$id
  79. );
  80. ($hook = get_hook('pf_change_pass_key_qr_update_password')) ? eval($hook) : null;
  81. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  82. // Add flash message
  83. $forum_flash->add_info($lang_profile['Pass updated']);
  84. ($hook = get_hook('pf_change_pass_key_pre_redirect')) ? eval($hook) : null;
  85. redirect(forum_link($forum_url['index']), $lang_profile['Pass updated']);
  86. }
  87. }
  88. // Is this users own profile
  89. $forum_page['own_profile'] = ($forum_user['id'] == $id) ? true : false;
  90. // Setup form
  91. $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
  92. $forum_page['form_action'] = forum_link($forum_url['change_password_key'], array($id, $key));
  93. // Setup breadcrumbs
  94. $forum_page['crumbs'] = array(
  95. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  96. array(sprintf($lang_profile['Users profile'], $user['username'], $lang_profile['Section about']), forum_link($forum_url['profile_about'], $id)),
  97. ($forum_page['own_profile']) ? $lang_profile['Change your password'] : sprintf($lang_profile['Change user password'], forum_htmlencode($user['username']))
  98. );
  99. ($hook = get_hook('pf_change_pass_key_pre_header_load')) ? eval($hook) : null;
  100. define('FORUM_PAGE', 'profile-changepass');
  101. require FORUM_ROOT.'header.php';
  102. // START SUBST - <!-- forum_main -->
  103. ob_start();
  104. ($hook = get_hook('pf_change_pass_key_output_start')) ? eval($hook) : null;
  105. ?>
  106. <div class="main-head">
  107. <h2 class="hn"><span><?php echo $forum_page['own_profile'] ? $lang_profile['Change your password'] : sprintf($lang_profile['Change user password'], forum_htmlencode($user['username'])) ?></span></h2>
  108. </div>
  109. <div class="main-content main-frm">
  110. <?php
  111. // If there were any errors, show them
  112. if (!empty($errors))
  113. {
  114. $forum_page['errors'] = array();
  115. foreach ($errors as $cur_error)
  116. $forum_page['errors'][] = '<li class="warn"><span>'.$cur_error.'</span></li>';
  117. ($hook = get_hook('pf_change_pass_key_pre_errors')) ? eval($hook) : null;
  118. ?>
  119. <div class="ct-box error-box">
  120. <h2 class="warn hn"><?php echo $lang_profile['Change pass errors'] ?></h2>
  121. <ul class="error-list">
  122. <?php echo implode("\n\t\t\t\t", $forum_page['errors'])."\n" ?>
  123. </ul>
  124. </div>
  125. <?php
  126. }
  127. ?>
  128. <div id="req-msg" class="req-warn ct-box error-box">
  129. <p class="important"><?php echo $lang_common['Required warn'] ?></p>
  130. </div>
  131. <form id="afocus" class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>" autocomplete="off">
  132. <div class="hidden">
  133. <input type="hidden" name="form_sent" value="1" />
  134. <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($forum_page['form_action']) ?>" />
  135. </div>
  136. <?php ($hook = get_hook('pf_change_pass_key_pre_fieldset')) ? eval($hook) : null; ?>
  137. <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  138. <legend class="group-legend"><strong><?php echo $lang_common['Required information'] ?></strong></legend>
  139. <?php ($hook = get_hook('pf_change_pass_key_pre_new_password')) ? eval($hook) : null; ?>
  140. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  141. <div class="sf-box text required">
  142. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_profile['New password'] ?></span> <small><?php echo $lang_profile['Password help'] ?></small></label><br />
  143. <span class="fld-input"><input type="<?php echo($forum_config['o_mask_passwords'] == '1' ? 'password' : 'text') ?>" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_new_password1" size="35" value="<?php if (isset($_POST['req_new_password1'])) echo forum_htmlencode($_POST['req_new_password1']); ?>" required autocomplete="off" /></span><br />
  144. </div>
  145. </div>
  146. <?php ($hook = get_hook('pf_change_pass_key_pre_new_password_confirm')) ? eval($hook) : null; ?>
  147. <?php if ($forum_config['o_mask_passwords'] == '1'): ?>
  148. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  149. <div class="sf-box text required">
  150. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_profile['Confirm new password'] ?></span> <small><?php echo $lang_profile['Confirm password help'] ?></small></label><br />
  151. <span class="fld-input"><input type="password" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_new_password2" size="35" value="<?php if (isset($_POST['req_new_password2'])) echo forum_htmlencode($_POST['req_new_password2']); ?>" required autocomplete="off" /></span><br />
  152. </div>
  153. </div>
  154. <?php endif; ?>
  155. <?php ($hook = get_hook('pf_change_pass_key_pre_fieldset_end')) ? eval($hook) : null; ?>
  156. </fieldset>
  157. <?php ($hook = get_hook('pf_change_pass_key_fieldset_end')) ? eval($hook) : null; ?>
  158. <div class="frm-buttons">
  159. <span class="submit primary"><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /></span>
  160. <span class="cancel"><input type="submit" name="cancel" value="<?php echo $lang_common['Cancel'] ?>" formnovalidate /></span>
  161. </div>
  162. </form>
  163. </div>
  164. <?php
  165. ($hook = get_hook('pf_change_pass_key_end')) ? eval($hook) : null;
  166. $tpl_temp = forum_trim(ob_get_contents());
  167. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  168. ob_end_clean();
  169. // END SUBST - <!-- forum_main -->
  170. require FORUM_ROOT.'footer.php';
  171. }
  172. }
  173. // Make sure we are allowed to change this user's password
  174. if ($forum_user['id'] != $id &&
  175. $forum_user['g_id'] != FORUM_ADMIN &&
  176. ($forum_user['g_moderator'] != '1' || $forum_user['g_mod_edit_users'] == '0' || $forum_user['g_mod_change_passwords'] == '0' || $user['g_id'] == FORUM_ADMIN || $user['g_moderator'] == '1'))
  177. message($lang_common['No permission']);
  178. if (isset($_POST['form_sent']))
  179. {
  180. ($hook = get_hook('pf_change_pass_normal_form_submitted')) ? eval($hook) : null;
  181. $old_password = isset($_POST['req_old_password']) ? forum_trim($_POST['req_old_password']) : '';
  182. $new_password1 = forum_trim($_POST['req_new_password1']);
  183. $new_password2 = ($forum_config['o_mask_passwords'] == '1') ? forum_trim($_POST['req_new_password2']) : $new_password1;
  184. if (utf8_strlen($new_password1) < 4)
  185. $errors[] = $lang_profile['Pass too short'];
  186. else if ($new_password1 != $new_password2)
  187. $errors[] = $lang_profile['Pass not match'];
  188. $authorized = false;
  189. if (!empty($user['password']))
  190. {
  191. $old_password_hash = forum_hash($old_password, $user['salt']);
  192. if (($user['password'] == $old_password_hash) || $forum_user['is_admmod'])
  193. $authorized = true;
  194. }
  195. if (!$authorized)
  196. $errors[] = $lang_profile['Wrong old password'];
  197. // Did everything go according to plan?
  198. if (empty($errors))
  199. {
  200. $new_password_hash = forum_hash($new_password1, $user['salt']);
  201. $query = array(
  202. 'UPDATE' => 'users',
  203. 'SET' => 'password=\''.$new_password_hash.'\'',
  204. 'WHERE' => 'id='.$id
  205. );
  206. ($hook = get_hook('pf_change_pass_normal_qr_update_password')) ? eval($hook) : null;
  207. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  208. if ($forum_user['id'] == $id)
  209. {
  210. $cookie_data = @explode('|', base64_decode($_COOKIE[$cookie_name]));
  211. $expire = ($cookie_data[2] > time() + $forum_config['o_timeout_visit']) ? time() + 1209600 : time() + $forum_config['o_timeout_visit'];
  212. forum_setcookie($cookie_name, base64_encode($forum_user['id'].'|'.$new_password_hash.'|'.$expire.'|'.sha1($user['salt'].$new_password_hash.forum_hash($expire, $user['salt']))), $expire);
  213. }
  214. // Add flash message
  215. $forum_flash->add_info($lang_profile['Pass updated redirect']);
  216. ($hook = get_hook('pf_change_pass_normal_pre_redirect')) ? eval($hook) : null;
  217. redirect(forum_link($forum_url['profile_about'], $id), $lang_profile['Pass updated redirect']);
  218. }
  219. }
  220. // Is this users own profile
  221. $forum_page['own_profile'] = ($forum_user['id'] == $id) ? true : false;
  222. // Setup form
  223. $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
  224. $forum_page['form_action'] = forum_link($forum_url['change_password'], $id);
  225. $forum_page['hidden_fields'] = array(
  226. 'form_sent' => '<input type="hidden" name="form_sent" value="1" />',
  227. 'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
  228. );
  229. // Setup breadcrumbs
  230. $forum_page['crumbs'] = array(
  231. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  232. array(sprintf($lang_profile['Users profile'], $user['username']), forum_link($forum_url['profile_about'], $id)),
  233. ($forum_page['own_profile']) ? $lang_profile['Change your password'] : sprintf($lang_profile['Change user password'], forum_htmlencode($user['username']))
  234. );
  235. ($hook = get_hook('pf_change_pass_normal_pre_header_load')) ? eval($hook) : null;
  236. define('FORUM_PAGE', 'profile-changepass');
  237. require FORUM_ROOT.'header.php';
  238. // START SUBST - <!-- forum_main -->
  239. ob_start();
  240. ($hook = get_hook('pf_change_pass_normal_output_start')) ? eval($hook) : null;
  241. ?>
  242. <div class="main-head">
  243. <h2 class="hn"><span><?php echo $forum_page['own_profile'] ? $lang_profile['Change your password'] : sprintf($lang_profile['Change user password'], forum_htmlencode($user['username'])) ?></span></h2>
  244. </div>
  245. <div class="main-content main-frm">
  246. <?php
  247. // If there were any errors, show them
  248. if (!empty($errors))
  249. {
  250. $forum_page['errors'] = array();
  251. foreach ($errors as $cur_error)
  252. $forum_page['errors'][] = '<li class="warn"><span>'.$cur_error.'</span></li>';
  253. ($hook = get_hook('pf_change_pass_normal_pre_errors')) ? eval($hook) : null;
  254. ?>
  255. <div class="ct-box error-box">
  256. <h2 class="warn hn"><?php echo $lang_profile['Change pass errors'] ?></h2>
  257. <ul class="error-list">
  258. <?php echo implode("\n\t\t\t\t", $forum_page['errors'])."\n" ?>
  259. </ul>
  260. </div>
  261. <?php
  262. }
  263. ?>
  264. <div id="req-msg" class="req-warn ct-box error-box">
  265. <p class="important"><?php echo $lang_common['Required warn'] ?></p>
  266. </div>
  267. <form id="afocus" class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>" autocomplete="off">
  268. <div class="hidden">
  269. <?php echo implode("\n\t\t\t\t", $forum_page['hidden_fields'])."\n" ?>
  270. </div>
  271. <?php ($hook = get_hook('pf_change_pass_normal_pre_fieldset')) ? eval($hook) : null; ?>
  272. <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  273. <legend class="group-legend"><strong><?php echo $lang_common['Required information'] ?></strong></legend>
  274. <?php ($hook = get_hook('pf_change_pass_normal_pre_old_password')) ? eval($hook) : null; ?>
  275. <?php if (!$forum_user['is_admmod'] || $forum_user['id'] == $id): ?>
  276. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  277. <div class="sf-box text required">
  278. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_profile['Old password'] ?></span> <small><?php echo $lang_profile['Old password help'] ?></small></label><br />
  279. <span class="fld-input"><input type="<?php echo($forum_config['o_mask_passwords'] == '1' ? 'password' : 'text') ?>" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_old_password" size="35" value="<?php if (isset($_POST['req_old_password'])) echo forum_htmlencode($_POST['req_old_password']); ?>" required /></span>
  280. </div>
  281. </div>
  282. <?php endif; ($hook = get_hook('pf_change_pass_normal_pre_new_password')) ? eval($hook) : null; ?>
  283. <div class="sf-set set<?php echo ++$forum_page['item_count']; if ($forum_config['o_mask_passwords'] == '1') echo ' prepend-top'; ?>">
  284. <div class="sf-box text required">
  285. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_profile['New password'] ?></span> <small><?php echo $lang_profile['Password help'] ?></small></label><br />
  286. <span class="fld-input"><input type="<?php echo($forum_config['o_mask_passwords'] == '1' ? 'password' : 'text') ?>" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_new_password1" size="35" value="<?php if (isset($_POST['req_new_password1'])) echo forum_htmlencode($_POST['req_new_password1']); ?>" required /></span><br />
  287. </div>
  288. </div>
  289. <?php ($hook = get_hook('pf_change_pass_normal_pre_new_password_confirm')) ? eval($hook) : null; ?>
  290. <?php if ($forum_config['o_mask_passwords'] == '1'): ?>
  291. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  292. <div class="sf-box text required">
  293. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_profile['Confirm new password'] ?></span> <small><?php echo $lang_profile['Confirm password help'] ?></small></label><br />
  294. <span class="fld-input"><input type="<?php echo($forum_config['o_mask_passwords'] == '1' ? 'password' : 'text') ?>" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_new_password2" size="35" value="<?php if (isset($_POST['req_new_password2'])) echo forum_htmlencode($_POST['req_new_password2']); ?>" required /></span><br />
  295. </div>
  296. </div>
  297. <?php endif; ?>
  298. <?php ($hook = get_hook('pf_change_pass_normal_pre_fieldset_end')) ? eval($hook) : null; ?>
  299. </fieldset>
  300. <?php ($hook = get_hook('pf_change_pass_normal_fieldset_end')) ? eval($hook) : null; ?>
  301. <div class="frm-buttons">
  302. <span class="submit primary"><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /></span>
  303. <span class="cancel"><input type="submit" name="cancel" value="<?php echo $lang_common['Cancel'] ?>" formnovalidate /></span>
  304. </div>
  305. </form>
  306. </div>
  307. <?php
  308. ($hook = get_hook('pf_change_pass_normal_end')) ? eval($hook) : null;
  309. $tpl_temp = forum_trim(ob_get_contents());
  310. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  311. ob_end_clean();
  312. // END SUBST - <!-- forum_main -->
  313. require FORUM_ROOT.'footer.php';
  314. }
  315. else if ($action == 'change_email')
  316. {
  317. // Make sure we are allowed to change this user's e-mail
  318. if ($forum_user['id'] != $id &&
  319. $forum_user['g_id'] != FORUM_ADMIN &&
  320. ($forum_user['g_moderator'] != '1' || $forum_user['g_mod_edit_users'] == '0' || $user['g_id'] == FORUM_ADMIN || $user['g_moderator'] == '1'))
  321. message($lang_common['No permission']);
  322. ($hook = get_hook('pf_change_email_selected')) ? eval($hook) : null;
  323. // User pressed the cancel button
  324. if (isset($_POST['cancel']))
  325. redirect(forum_link($forum_url['profile_about'], $id), $lang_common['Cancel redirect']);
  326. if (isset($_GET['key']))
  327. {
  328. $key = $_GET['key'];
  329. ($hook = get_hook('pf_change_email_key_supplied')) ? eval($hook) : null;
  330. if ($key == '' || $key != $user['activate_key'])
  331. message(sprintf($lang_profile['E-mail key bad'], '<a href="mailto:'.forum_htmlencode($forum_config['o_admin_email']).'">'.forum_htmlencode($forum_config['o_admin_email']).'</a>'));
  332. else
  333. {
  334. $query = array(
  335. 'UPDATE' => 'users',
  336. 'SET' => 'email=activate_string, activate_string=NULL, activate_key=NULL',
  337. 'WHERE' => 'id='.$id
  338. );
  339. ($hook = get_hook('pf_change_email_key_qr_update_email')) ? eval($hook) : null;
  340. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  341. message($lang_profile['E-mail updated']);
  342. }
  343. }
  344. else if (isset($_POST['form_sent']))
  345. {
  346. ($hook = get_hook('pf_change_email_normal_form_submitted')) ? eval($hook) : null;
  347. if (forum_hash($_POST['req_password'], $forum_user['salt']) !== $forum_user['password'])
  348. $errors[] = $lang_profile['Wrong password'];
  349. if (!defined('FORUM_EMAIL_FUNCTIONS_LOADED'))
  350. require FORUM_ROOT.'include/email.php';
  351. // Validate the email-address
  352. $new_email = strtolower(forum_trim($_POST['req_new_email']));
  353. if (!is_valid_email($new_email))
  354. $errors[] = $lang_common['Invalid e-mail'];
  355. // Check if it's a banned e-mail address
  356. if (is_banned_email($new_email))
  357. {
  358. ($hook = get_hook('pf_change_email_normal_banned_email')) ? eval($hook) : null;
  359. if ($forum_config['p_allow_banned_email'] == '0')
  360. $errors[] = $lang_profile['Banned e-mail'];
  361. else if ($forum_config['o_mailing_list'] != '')
  362. {
  363. $mail_subject = 'Alert - Banned e-mail detected';
  364. $mail_message = 'User \''.$forum_user['username'].'\' changed to banned e-mail address: '.$new_email."\n\n".'User profile: '.forum_link($forum_url['user'], $id)."\n\n".'-- '."\n".'Forum Mailer'."\n".'(Do not reply to this message)';
  365. forum_mail($forum_config['o_mailing_list'], $mail_subject, $mail_message);
  366. }
  367. }
  368. // Check if someone else already has registered with that e-mail address
  369. $query = array(
  370. 'SELECT' => 'u.id, u.username',
  371. 'FROM' => 'users AS u',
  372. 'WHERE' => 'u.email=\''.$forum_db->escape($new_email).'\''
  373. );
  374. ($hook = get_hook('pf_change_email_normal_qr_check_email_dupe')) ? eval($hook) : null;
  375. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  376. $dupe_list = array();
  377. while ($cur_dupe = $forum_db->fetch_assoc($result))
  378. {
  379. $dupe_list[] = $cur_dupe['username'];
  380. }
  381. if (!empty($dupe_list))
  382. {
  383. ($hook = get_hook('pf_change_email_normal_dupe_email')) ? eval($hook) : null;
  384. if ($forum_config['p_allow_dupe_email'] == '0')
  385. $errors[] = $lang_profile['Dupe e-mail'];
  386. else if (($forum_config['o_mailing_list'] != '') && empty($errors))
  387. {
  388. $mail_subject = 'Alert - Duplicate e-mail detected';
  389. $mail_message = 'User \''.$forum_user['username'].'\' changed to an e-mail address that also belongs to: '.implode(', ', $dupe_list)."\n\n".'User profile: '.forum_link($forum_url['user'], $id)."\n\n".'-- '."\n".'Forum Mailer'."\n".'(Do not reply to this message)';
  390. forum_mail($forum_config['o_mailing_list'], $mail_subject, $mail_message);
  391. }
  392. }
  393. // Did everything go according to plan?
  394. if (empty($errors))
  395. {
  396. if ($forum_config['o_regs_verify'] != '1')
  397. {
  398. // We have no confirmed e-mail so we change e-mail right now
  399. $query = array(
  400. 'UPDATE' => 'users',
  401. 'SET' => 'email=\''.$forum_db->escape($new_email).'\'',
  402. 'WHERE' => 'id='.$id
  403. );
  404. ($hook = get_hook('pf_change_email_key_qr_update_email')) ? eval($hook) : null;
  405. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  406. redirect(forum_link($forum_url['profile_about'], $id), $lang_profile['E-mail updated redirect']);
  407. }
  408. // We have a confirmed e-mail so we going to send an activation link
  409. $new_email_key = random_key(8, true);
  410. // Save new e-mail and activation key
  411. $query = array(
  412. 'UPDATE' => 'users',
  413. 'SET' => 'activate_string=\''.$forum_db->escape($new_email).'\', activate_key=\''.$new_email_key.'\'',
  414. 'WHERE' => 'id='.$id
  415. );
  416. ($hook = get_hook('pf_change_email_normal_qr_update_email_activation')) ? eval($hook) : null;
  417. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  418. // Load the "activate e-mail" template
  419. $mail_tpl = forum_trim(file_get_contents(FORUM_ROOT.'lang/'.$forum_user['language'].'/mail_templates/activate_email.tpl'));
  420. // The first row contains the subject
  421. $first_crlf = strpos($mail_tpl, "\n");
  422. $mail_subject = forum_trim(substr($mail_tpl, 8, $first_crlf-8));
  423. $mail_message = forum_trim(substr($mail_tpl, $first_crlf));
  424. $mail_message = str_replace('<username>', $forum_user['username'], $mail_message);
  425. $mail_message = str_replace('<base_url>', $base_url.'/', $mail_message);
  426. $mail_message = str_replace('<activation_url>', str_replace('&amp;', '&', forum_link($forum_url['change_email_key'], array($id, $new_email_key))), $mail_message);
  427. $mail_message = str_replace('<board_mailer>', sprintf($lang_common['Forum mailer'], $forum_config['o_board_title']), $mail_message);
  428. ($hook = get_hook('pf_change_email_normal_pre_activation_email_sent')) ? eval($hook) : null;
  429. forum_mail($new_email, $mail_subject, $mail_message);
  430. message(sprintf($lang_profile['Activate e-mail sent'], '<a href="mailto:'.forum_htmlencode($forum_config['o_admin_email']).'">'.forum_htmlencode($forum_config['o_admin_email']).'</a>'));
  431. }
  432. }
  433. // Is this users own profile
  434. $forum_page['own_profile'] = ($forum_user['id'] == $id) ? true : false;
  435. // Setup form
  436. $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
  437. $forum_page['form_action'] = forum_link($forum_url['change_email'], $id);
  438. $forum_page['hidden_fields'] = array(
  439. 'form_sent' => '<input type="hidden" name="form_sent" value="1" />',
  440. 'csrf_token' => '<input type="hidden" name="csrf_token" value="'.generate_form_token($forum_page['form_action']).'" />'
  441. );
  442. // Setup form information
  443. $forum_page['frm_info'] = '<p class="important"><span>'.$lang_profile['E-mail info'].'</span></p>';
  444. // Setup breadcrumbs
  445. $forum_page['crumbs'] = array(
  446. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  447. array(sprintf($lang_profile['Users profile'], $user['username'], $lang_profile['Section about']), forum_link($forum_url['profile_about'], $id)),
  448. ($forum_page['own_profile']) ? $lang_profile['Change your e-mail'] : sprintf($lang_profile['Change user e-mail'], forum_htmlencode($user['username']))
  449. );
  450. ($hook = get_hook('pf_change_email_normal_pre_header_load')) ? eval($hook) : null;
  451. define('FORUM_PAGE', 'profile-changemail');
  452. require FORUM_ROOT.'header.php';
  453. // START SUBST - <!-- forum_main -->
  454. ob_start();
  455. ($hook = get_hook('pf_change_email_normal_output_start')) ? eval($hook) : null;
  456. ?>
  457. <div class="main-head">
  458. <h2 class="hn"><span><?php printf(($forum_user['id'] == $id) ? $lang_profile['Profile welcome'] : $lang_profile['Profile welcome user'], forum_htmlencode($user['username'])) ?></span></h2>
  459. </div>
  460. <div class="main-content main-frm">
  461. <div class="ct-box info-box">
  462. <?php echo $forum_page['frm_info']."\n" ?>
  463. </div>
  464. <?php
  465. // If there were any errors, show them
  466. if (!empty($errors))
  467. {
  468. $forum_page['errors'] = array();
  469. foreach ($errors as $cur_error)
  470. $forum_page['errors'][] = '<li class="warn"><span>'.$cur_error.'</span></li>';
  471. ($hook = get_hook('pf_change_email_pre_errors')) ? eval($hook) : null;
  472. ?>
  473. <div class="ct-box error-box">
  474. <h2 class="warn hn"><?php echo $lang_profile['Change e-mail errors'] ?></h2>
  475. <ul class="error-list">
  476. <?php echo implode("\n\t\t\t\t", $forum_page['errors'])."\n" ?>
  477. </ul>
  478. </div>
  479. <?php
  480. }
  481. ?>
  482. <div id="req-msg" class="req-warn ct-box error-box">
  483. <p class="important"><?php echo $lang_common['Required warn'] ?></p>
  484. </div>
  485. <form id="afocus" class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>">
  486. <div class="hidden">
  487. <?php echo implode("\n\t\t\t", $forum_page['hidden_fields'])."\n" ?>
  488. </div>
  489. <?php ($hook = get_hook('pf_change_email_normal_pre_fieldset')) ? eval($hook) : null; ?>
  490. <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  491. <legend class="group-legend"><strong><?php echo $lang_common['Required information'] ?></strong></legend>
  492. <?php ($hook = get_hook('pf_change_email_normal_pre_new_email')) ? eval($hook) : null; ?>
  493. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  494. <div class="sf-box text required">
  495. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_profile['New e-mail'] ?></span></label><br />
  496. <span class="fld-input"><input type="email" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_new_email" size="35" maxlength="80" value="<?php if (isset($_POST['req_new_email'])) echo forum_htmlencode($_POST['req_new_email']); ?>" required /></span>
  497. </div>
  498. </div>
  499. <?php ($hook = get_hook('pf_change_email_normal_pre_password')) ? eval($hook) : null; ?>
  500. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  501. <div class="sf-box text required">
  502. <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_profile['Password'] ?></span><small><?php echo $lang_profile['Old password help'] ?></small></label><br />
  503. <span class="fld-input"><input type="<?php echo($forum_config['o_mask_passwords'] == '1' ? 'password' : 'text') ?>" id="fld<?php echo $forum_page['fld_count'] ?>" name="req_password" size="35" value="<?php if (isset($_POST['req_password'])) echo forum_htmlencode($_POST['req_password']); ?>" required autocomplete="off" /></span>
  504. </div>
  505. </div>
  506. <?php ($hook = get_hook('pf_change_email_normal_pre_fieldset_end')) ? eval($hook) : null; ?>
  507. </fieldset>
  508. <?php ($hook = get_hook('pf_change_email_normal_fieldset_end')) ? eval($hook) : null; ?>
  509. <div class="frm-buttons">
  510. <span class="submit primary"><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /></span>
  511. <span class="cancel"><input type="submit" name="cancel" value="<?php echo $lang_common['Cancel'] ?>" formnovalidate /></span>
  512. </div>
  513. </form>
  514. </div>
  515. <?php
  516. ($hook = get_hook('pf_change_email_normal_end')) ? eval($hook) : null;
  517. $tpl_temp = forum_trim(ob_get_contents());
  518. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  519. ob_end_clean();
  520. // END SUBST - <!-- forum_main -->
  521. require FORUM_ROOT.'footer.php';
  522. }
  523. else if ($action == 'delete_user' || isset($_POST['delete_user_comply']) || isset($_POST['cancel']))
  524. {
  525. // User pressed the cancel button
  526. if (isset($_POST['cancel']))
  527. redirect(forum_link($forum_url['profile_admin'], $id), $lang_common['Cancel redirect']);
  528. ($hook = get_hook('pf_delete_user_selected')) ? eval($hook) : null;
  529. if ($forum_user['g_id'] != FORUM_ADMIN)
  530. message($lang_common['No permission']);
  531. if ($user['g_id'] == FORUM_ADMIN)
  532. message($lang_profile['Cannot delete admin']);
  533. if (isset($_POST['delete_user_comply']))
  534. {
  535. ($hook = get_hook('pf_delete_user_form_submitted')) ? eval($hook) : null;
  536. delete_user($id, isset($_POST['delete_posts']));
  537. // Remove cache file with forum stats
  538. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  539. {
  540. require FORUM_ROOT.'include/cache.php';
  541. }
  542. clean_stats_cache();
  543. // Add flash message
  544. $forum_flash->add_info($lang_profile['User delete redirect']);
  545. ($hook = get_hook('pf_delete_user_pre_redirect')) ? eval($hook) : null;
  546. redirect(forum_link($forum_url['index']), $lang_profile['User delete redirect']);
  547. }
  548. // Setup form
  549. $forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
  550. $forum_page['form_action'] = forum_link($forum_url['delete_user'], $id);
  551. // Setup form information
  552. $forum_page['frm_info'] = array(
  553. '<li class="warn"><span>'.$lang_profile['Delete warning'].'</span></li>',
  554. '<li class="warn"><span>'.$lang_profile['Delete posts info'].'</span></li>'
  555. );
  556. // Setup breadcrumbs
  557. $forum_page['crumbs'] = array(
  558. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  559. array(sprintf($lang_profile['Users profile'], $user['username'], $lang_profile['Section admin']), forum_link($forum_url['profile_admin'], $id)),
  560. $lang_profile['Delete user']
  561. );
  562. ($hook = get_hook('pf_delete_user_pre_header_load')) ? eval($hook) : null;
  563. define('FORUM_PAGE', 'dialogue');
  564. require FORUM_ROOT.'header.php';
  565. // START SUBST - <!-- forum_main -->
  566. ob_start();
  567. ($hook = get_hook('pf_delete_user_output_start')) ? eval($hook) : null;
  568. ?>
  569. <div class="main-head">
  570. <h2 class="hn"><span><?php printf(($forum_user['id'] == $id) ? $lang_profile['Profile welcome'] : $lang_profile['Profile welcome user'], forum_htmlencode($user['username'])) ?></span></h2>
  571. </div>
  572. <div class="main-content main-frm">
  573. <div class="ct-box warn-box">
  574. <ul class="info-list">
  575. <?php echo implode("\n\t\t\t\t", $forum_page['frm_info'])."\n" ?>
  576. </ul>
  577. </div>
  578. <form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $forum_page['form_action'] ?>">
  579. <div class="hidden">
  580. <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($forum_page['form_action']) ?>" />
  581. </div>
  582. <?php ($hook = get_hook('pf_delete_user_pre_fieldset')) ? eval($hook) : null; ?>
  583. <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
  584. <legend class="group-legend"><strong><?php echo $lang_common['Required information'] ?></strong></legend>
  585. <?php ($hook = get_hook('pf_delete_user_pre_confirm_checkbox')) ? eval($hook) : null; ?>
  586. <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
  587. <div class="sf-box checkbox">
  588. <span class="fld-input"><input type="checkbox" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="delete_posts" value="1" checked="checked" /></span>
  589. <label for="fld<?php echo $forum_page['fld_count'] ?>"><span><?php echo $lang_profile['Delete posts'] ?></span> <?php printf($lang_profile['Delete posts label'], forum_htmlencode($user['username'])) ?></label>
  590. </div>
  591. </div>
  592. <?php ($hook = get_hook('pf_delete_user_pre_fieldset_end')) ? eval($hook) : null; ?>
  593. </fieldset>
  594. <?php ($hook = get_hook('pf_delete_user_fieldset_end')) ? eval($hook) : null; ?>
  595. <div class="frm-buttons">
  596. <span class="submit primary caution"><input type="submit" name="delete_user_comply" value="<?php echo $lang_profile['Delete user'] ?>" /></span>
  597. <span class="cancel"><input type="submit" name="cancel" value="<?php echo $lang_common['Cancel'] ?>" formnovalidate /></span>
  598. </div>
  599. </form>
  600. </div>
  601. <?php
  602. ($hook = get_hook('pf_delete_user_end')) ? eval($hook) : null;
  603. $tpl_temp = forum_trim(ob_get_contents());
  604. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  605. ob_end_clean();
  606. // END SUBST - <!-- forum_main -->
  607. require FORUM_ROOT.'footer.php';
  608. }
  609. else if ($action == 'delete_avatar')
  610. {
  611. // Make sure we are allowed to delete this user's avatar
  612. if ($forum_user['id'] != $id &&
  613. $forum_user['g_id'] != FORUM_ADMIN &&
  614. ($forum_user['g_moderator'] != '1' || $forum_user['g_mod_edit_users'] == '0' || $user['g_id'] == FORUM_ADMIN || $user['g_moderator'] == '1'))
  615. message($lang_common['No permission']);
  616. // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid.
  617. // If it's in GET, we need to make sure it's valid.
  618. if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('delete_avatar'.$id.$forum_user['id'])))
  619. csrf_confirm_form();
  620. ($hook = get_hook('pf_delete_avatar_selected')) ? eval($hook) : null;
  621. delete_avatar($id);
  622. // Add flash message
  623. $forum_flash->add_info($lang_profile['Avatar deleted redirect']);
  624. ($hook = get_hook('pf_delete_avatar_pre_redirect')) ? eval($hook) : null;
  625. redirect(forum_link($forum_url['profile_avatar'], $id), $lang_profile['Avatar deleted redirect']);
  626. }
  627. else if (isset($_POST['update_group_membership']))
  628. {
  629. if ($forum_user['g_id'] != FORUM_ADMIN)
  630. message($lang_common['No permission']);
  631. ($hook = get_hook('pf_change_group_form_submitted')) ? eval($hook) : null;
  632. $new_group_id = intval($_POST['group_id']);
  633. $query = array(
  634. 'UPDATE' => 'users',
  635. 'SET' => 'group_id='.$new_group_id,
  636. 'WHERE' => 'id='.$id
  637. );
  638. ($hook = get_hook('pf_change_group_qr_update_group')) ? eval($hook) : null;
  639. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  640. $query = array(
  641. 'SELECT' => 'g.g_moderator',
  642. 'FROM' => 'groups AS g',
  643. 'WHERE' => 'g.g_id='.$new_group_id
  644. );
  645. ($hook = get_hook('pf_change_group_qr_check_new_group_mod')) ? eval($hook) : null;
  646. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  647. $new_group_mod = $forum_db->result($result);
  648. // If the user was a moderator or an administrator (and no longer is), we remove him/her from the moderator list in all forums
  649. if (($user['g_id'] == FORUM_ADMIN || $user['g_moderator'] == '1') && $new_group_id != FORUM_ADMIN && $new_group_mod != '1')
  650. clean_forum_moderators();
  651. // Add flash message
  652. $forum_flash->add_info($lang_profile['Group membership redirect']);
  653. ($hook = get_hook('pf_change_group_pre_redirect')) ? eval($hook) : null;
  654. redirect(forum_link($forum_url['profile_admin'], $id), $lang_profile['Group membership redirect']);
  655. }
  656. else if (isset($_POST['update_forums']))
  657. {
  658. if ($forum_user['g_id'] != FORUM_ADMIN)
  659. message($lang_common['No permission']);
  660. ($hook = get_hook('pf_forum_moderators_form_submitted')) ? eval($hook) : null;
  661. $moderator_in = (isset($_POST['moderator_in'])) ? array_keys($_POST['moderator_in']) : array();
  662. // Loop through all forums
  663. $query = array(
  664. 'SELECT' => 'f.id, f.moderators',
  665. 'FROM' => 'forums AS f'
  666. );
  667. ($hook = get_hook('pf_forum_moderators_qr_get_all_forum_mods')) ? eval($hook) : null;
  668. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  669. while ($cur_forum = $forum_db->fetch_assoc($result))
  670. {
  671. $cur_moderators = ($cur_forum['moderators'] != '') ? unserialize($cur_forum['moderators']) : array();
  672. // If the user should have moderator access (and he/she doesn't already have it)
  673. if (in_array($cur_forum['id'], $moderator_in) && !in_array($id, $cur_moderators))
  674. {
  675. $cur_moderators[$user['username']] = $id;
  676. ksort($cur_moderators);
  677. }
  678. // If the user shouldn't have moderator access (and he/she already has it)
  679. else if (!in_array($cur_forum['id'], $moderator_in) && in_array($id, $cur_moderators))
  680. unset($cur_moderators[$user['username']]);
  681. $cur_moderators = (!empty($cur_moderators)) ? '\''.$forum_db->escape(serialize($cur_moderators)).'\'' : 'NULL';
  682. $query = array(
  683. 'UPDATE' => 'forums',
  684. 'SET' => 'moderators='.$cur_moderators,
  685. 'WHERE' => 'id='.$cur_forum['id']
  686. );
  687. ($hook = get_hook('pf_forum_moderators_qr_update_forum_moderators')) ? eval($hook) : null;
  688. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  689. }
  690. // Add flash message
  691. $forum_flash->add_info($lang_profile['Moderate forums redirect']);
  692. ($hook = get_hook('pf_forum_moderators_pre_redirect')) ? eval($hook) : null;
  693. redirect(forum_link($forum_url['profile_admin'], $id), $lang_profile['Moderate forums redirect']);
  694. }
  695. else if (isset($_POST['ban']))
  696. {
  697. if ($forum_user['g_id'] != FORUM_ADMIN && ($forum_user['g_moderator'] != '1' || $forum_user['g_mod_ban_users'] == '0'))
  698. message($lang_common['No permission']);
  699. ($hook = get_hook('pf_ban_user_selected')) ? eval($hook) : null;
  700. redirect(forum_link($forum_url['admin_bans']).'&amp;add_ban='.$id, $lang_profile['Ban redirect']);
  701. }
  702. else if (isset($_POST['form_sent']))
  703. {
  704. // Make sure we are allowed to edit this user's profile
  705. if ($forum_user['id'] != $id &&
  706. $forum_user['g_id'] != FORUM_ADMIN &&
  707. ($forum_user['g_moderator'] != '1' || $forum_user['g_mod_edit_users'] == '0' || $user['g_id'] == FORUM_ADMIN || $user['g_moderator'] == '1'))
  708. message($lang_common['No permission']);
  709. ($hook = get_hook('pf_change_details_form_submitted')) ? eval($hook) : null;
  710. // Extract allowed elements from $_POST['form']
  711. function extract_elements($allowed_elements)
  712. {
  713. $form = array();
  714. foreach ($_POST['form'] as $key => $value)
  715. {
  716. if (in_array($key, $allowed_elements))
  717. $form[$key] = $value;
  718. }
  719. return $form;
  720. }
  721. $username_updated = false;
  722. // Validate input depending on section
  723. switch ($section)
  724. {
  725. case 'identity':
  726. {
  727. $form = extract_elements(array('realname', 'url', 'location', 'jabber', 'icq', 'msn', 'aim', 'yahoo', 'facebook', 'twitter', 'linkedin', 'skype'));
  728. ($hook = get_hook('pf_change_details_identity_validation')) ? eval($hook) : null;
  729. if ($forum_user['is_admmod'])
  730. {
  731. // Are we allowed to change usernames?
  732. if ($forum_user['g_id'] == FORUM_ADMIN || ($forum_user['g_moderator'] == '1' && $forum_user['g_mod_rename_users'] == '1'))
  733. {
  734. $form['username'] = forum_trim($_POST['req_username']);
  735. $old_username = forum_trim($_POST['old_username']);
  736. // Validate the new username
  737. $errors = array_merge($errors, validate_username($form['username'], $id));
  738. if ($form['username'] != $old_username)
  739. $username_updated = true;
  740. }
  741. // We only allow administrators to update the post count
  742. if ($forum_user['g_id'] == FORUM_ADMIN)
  743. $form['num_posts'] = intval($_POST['num_posts']);
  744. }
  745. if ($forum_user['is_admmod'])
  746. {
  747. if (!defined('FORUM_EMAIL_FUNCTIONS_LOADED'))
  748. require FORUM_ROOT.'include/email.php';
  749. // Validate the email-address
  750. $form['email'] = strtolower(forum_trim($_POST['req_email']));
  751. if (!is_valid_email($form['email']))
  752. $errors[] = $lang_common['Invalid e-mail'];
  753. }
  754. if ($forum_user['is_admmod'])
  755. $form['admin_note'] = forum_trim($_POST['admin_note']);
  756. if ($forum_user['g_id'] == FORUM_ADMIN)
  757. $form['title'] = forum_trim($_POST['title']);
  758. else if ($forum_user['g_set_title'] == '1')
  759. {
  760. $form['title'] = forum_trim($_POST['title']);
  761. if ($form['title'] != '')
  762. {
  763. // A list of words that the title may not contain
  764. // If the language is English, there will be some duplicates, but it's not the end of the world
  765. $forbidden = array('Member', 'Moderator', 'Administrator', 'Banned', 'Guest', $lang_common['Member'], $lang_common['Moderator'], $lang_common['Administrator'], $lang_common['Banned'], $lang_common['Guest']);
  766. if (in_array($form['title'], $forbidden))
  767. $errors[] = $lang_profile['Forbidden title'];
  768. }
  769. }
  770. // Add http:// if the URL doesn't contain it or https:// already
  771. if ($form['url'] != '' && strpos(strtolower($form['url']), 'http://') !== 0 && strpos(strtolower($form['url']), 'https://') !== 0)
  772. $form['url'] = 'http://'.$form['url'];
  773. //check Facebook for validity
  774. if (strpos($form['facebook'], 'http://') === 0 || strpos($form['facebook'], 'https://') === 0)
  775. if (!preg_match('#https?://(www\.)?facebook.com/.+?#', $form['facebook']))
  776. $errors[] = $lang_profile['Bad Facebook'];
  777. //check Twitter for validity
  778. if (strpos($form['twitter'], 'http://') === 0 || strpos($form['twitter'], 'https://') === 0)
  779. if (!preg_match('#https?://twitter.com/.+?#', $form['twitter']))
  780. $errors[] = $lang_profile['Bad Twitter'];
  781. //check LinkedIn for validity
  782. if (!preg_match('#https?://(www\.)?linkedin.com/.+?#', $form['linkedin']))
  783. $errors[] = $lang_profile['Bad LinkedIn'];
  784. // Add http:// if the LinkedIn doesn't contain it or https:// already
  785. if ($form['linkedin'] != '' && strpos(strtolower($form['linkedin']), 'http://') !== 0 && strpos(strtolower($form['linkedin']), 'https://') !== 0)
  786. $form['linkedin'] = 'http://'.$form['linkedin'];
  787. // If the ICQ UIN contains anything other than digits it's invalid
  788. if ($form['icq'] != '' && !ctype_digit($form['icq']))
  789. $errors[] = $lang_profile['Bad ICQ'];
  790. break;
  791. }
  792. case 'settings':
  793. {
  794. $form = extract_elements(array('dst', 'timezone', 'language', 'email_setting', 'notify_with_post', 'auto_notify', 'time_format', 'date_format', 'disp_topics', 'disp_posts', 'show_smilies', 'show_img', 'show_img_sig', 'show_avatars', 'show_sig', 'style'));
  795. ($hook = get_hook('pf_change_details_settings_validation')) ? eval($hook) : null;
  796. $form['dst'] = (isset($form['dst'])) ? 1 : 0;
  797. $form['time_format'] = (isset($form['time_format'])) ? intval($form['time_format']) : 0;
  798. $form['date_format'] = (isset($form['date_format'])) ? intval($form['date_format']) : 0;
  799. $form['timezone'] = (isset($form['timezone'])) ? floatval($form['timezone']) : $forum_config['o_default_timezone'];
  800. // Validate timezone
  801. if (($form['timezone'] > 14.0) || ($form['timezone'] < -12.0)) {
  802. message($lang_common['Bad request']);
  803. }
  804. $form['email_setting'] = intval($form['email_setting']);
  805. if ($form['email_setting'] < 0 || $form['email_setting'] > 2) $form['email_setting'] = 1;
  806. if ($forum_config['o_subscriptions'] == '1')
  807. {
  808. if (!isset($form['notify_with_post']) || $form['notify_with_post'] != '1') $form['notify_with_post'] = '0';
  809. if (!isset($form['auto_notify']) || $form['auto_notify'] != '1') $form['auto_notify'] = '0';
  810. }
  811. // Make sure we got a valid language string
  812. if (isset($form['language']))
  813. {
  814. $form['language'] = preg_replace('#[\.\\\/]#', '', $form['language']);
  815. if (!file_exists(FORUM_ROOT.'lang/'.$form['language'].'/common.php'))
  816. message($lang_common['Bad request']);
  817. }
  818. if ($form['disp_topics'] != '' && intval($form['disp_topics']) < 3) $form['disp_topics'] = 3;
  819. if ($form['disp_topics'] != '' && intval($form['disp_topics']) > 75) $form['disp_topics'] = 75;
  820. if ($form['disp_posts'] != '' && intval($form['disp_posts']) < 3) $form['disp_posts'] = 3;
  821. if ($form['disp_posts'] != '' && intval($form['disp_posts']) > 75) $form['disp_posts'] = 75;
  822. if (!isset($form['show_smilies']) || $form['show_smilies'] != '1') $form['show_smilies'] = '0';
  823. if (!isset($form['show_img']) || $form['show_img'] != '1') $form['show_img'] = '0';
  824. if (!isset($form['show_img_sig']) || $form['show_img_sig'] != '1') $form['show_img_sig'] = '0';
  825. if (!isset($form['show_avatars']) || $form['show_avatars'] != '1') $form['show_avatars'] = '0';
  826. if (!isset($form['show_sig']) || $form['show_sig'] != '1') $form['show_sig'] = '0';
  827. // Make sure we got a valid style string
  828. if (isset($form['style']))
  829. {
  830. $form['style'] = preg_replace('#[\.\\\/]#', '', $form['style']);
  831. if (!file_exists(FORUM_ROOT.'style/'.$form['style'].'/'.$form['style'].'.php'))
  832. message($lang_common['Bad request']);
  833. }
  834. break;
  835. }
  836. case 'signature':
  837. {
  838. if ($forum_config['o_signatures'] == '0')
  839. message($lang_profile['Signatures disabled']);
  840. ($hook = get_hook('pf_change_details_signature_validation')) ? eval($hook) : null;
  841. // Clean up signature from POST
  842. $form['signature'] = forum_linebreaks(forum_trim($_POST['signature']));
  843. // Validate signature
  844. if (utf8_strlen($form['signature']) > $forum_config['p_sig_length'])
  845. $errors[] = sprintf($lang_profile['Sig too long'], forum_number_format($forum_config['p_sig_length']), forum_number_format(utf8_strlen($form['signature']) - $forum_config['p_sig_length']));
  846. if (substr_count($form['signature'], "\n") > ($forum_config['p_sig_lines'] - 1))
  847. $errors[] = sprintf($lang_profile['Sig too many lines'], forum_number_format($forum_config['p_sig_lines']));
  848. if ($form['signature'] != '' && $forum_config['p_sig_all_caps'] == '0' && check_is_all_caps($form['signature']) && !$forum_user['is_admmod'])
  849. $form['signature'] = utf8_ucwords(utf8_strtolower($form['signature']));
  850. // Validate BBCode syntax
  851. if ($forum_config['p_sig_bbcode'] == '1' || $forum_config['o_make_links'] == '1')
  852. {
  853. if (!defined('FORUM_PARSER_LOADED'))
  854. require FORUM_ROOT.'include/parser.php';
  855. $form['signature'] = preparse_bbcode($form['signature'], $errors, true);
  856. }
  857. break;
  858. }
  859. case 'avatar':
  860. {
  861. if ($forum_config['o_avatars'] == '0')
  862. message($lang_profile['Avatars disabled']);
  863. ($hook = get_hook('pf_change_details_avatar_validation')) ? eval($hook) : null;
  864. if (!isset($_FILES['req_file']))
  865. {
  866. $errors[] = $lang_profile['No file'];
  867. break;
  868. }
  869. else
  870. $uploaded_file = $_FILES['req_file'];
  871. // Make sure the upload went smooth
  872. if (isset($uploaded_file['error']) && empty($errors))
  873. {
  874. switch ($uploaded_file['error'])
  875. {
  876. case 1: // UPLOAD_ERR_INI_SIZE
  877. case 2: // UPLOAD_ERR_FORM_SIZE
  878. $errors[] = $lang_profile['Too large ini'];
  879. break;
  880. case 3: // UPLOAD_ERR_PARTIAL
  881. $errors[] = $lang_profile['Partial upload'];
  882. break;
  883. case 4: // UPLOAD_ERR_NO_FILE
  884. $errors[] = $lang_profile['No file'];
  885. break;
  886. case 6: // UPLOAD_ERR_NO_TMP_DIR
  887. $errors[] = $lang_profile['No tmp directory'];
  888. break;
  889. default:
  890. // No error occured, but was something actually uploaded?
  891. if ($uploaded_file['size'] == 0)
  892. $errors[] = $lang_profile['No file'];
  893. break;
  894. }
  895. }
  896. if (is_uploaded_file($uploaded_file['tmp_name']) && empty($errors))
  897. {
  898. // First check simple by size and mime type
  899. $allowed_mime_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
  900. $allowed_types = array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF);
  901. ($hook = get_hook('pf_change_details_avatar_allowed_types')) ? eval($hook) : null;
  902. if (!in_array($uploaded_file['type'], $allowed_mime_types))
  903. $errors[] = $lang_profile['Bad type'];
  904. else
  905. {
  906. // Make sure the file isn't too big
  907. if ($uploaded_file['size'] > $forum_config['o_avatars_size'])
  908. $errors[] = sprintf($lang_profile['Too large'], forum_number_format($forum_config['o_avatars_size']));
  909. }
  910. if (empty($errors))
  911. {
  912. $avatar_tmp_file = $forum_config['o_avatars_dir'].'/'.$id.'.tmp';
  913. // Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions.
  914. if (!@move_uploaded_file($uploaded_file['tmp_name'], $avatar_tmp_file))
  915. $errors[] = sprintf($lang_profile['Move failed'], '<a href="mailto:'.forum_htmlencode($forum_config['o_admin_email']).'">'.forum_htmlencode($forum_config['o_admin_email']).'</a>');
  916. if (empty($errors))
  917. {
  918. ($hook = get_hook('pf_change_details_avatar_modify_size')) ? eval($hook) : null;
  919. // Now check the width, height, type
  920. list($width, $height, $type,) = @/**/getimagesize($avatar_tmp_file);
  921. if (empty($width) || empty($height) || $width > $forum_config['o_avatars_width'] || $height > $forum_config['o_avatars_height'])
  922. {
  923. @unlink($avatar_tmp_file);
  924. $errors[] = sprintf($lang_profile['Too wide or high'], $forum_config['o_avatars_width'], $forum_config['o_avatars_height']);
  925. }
  926. else if ($type == IMAGETYPE_GIF && $uploaded_file['type'] != 'image/gif') // Prevent dodgy uploads
  927. {
  928. @unlink($avatar_tmp_file);
  929. $errors[] = $lang_profile['Bad type'];
  930. }
  931. // Determine type
  932. $extension = null;
  933. $avatar_type = FORUM_AVATAR_NONE;
  934. if ($type == IMAGETYPE_GIF)
  935. {
  936. $extension = '.gif';
  937. $avatar_type = FORUM_AVATAR_GIF;
  938. }
  939. else if ($type == IMAGETYPE_JPEG)
  940. {
  941. $extension = '.jpg';
  942. $avatar_type = FORUM_AVATAR_JPG;
  943. }
  944. else if ($type == IMAGETYPE_PNG)
  945. {
  946. $extension = '.png';
  947. $avatar_type = FORUM_AVATAR_PNG;
  948. }
  949. ($hook = get_hook('pf_change_details_avatar_determine_extension')) ? eval($hook) : null;
  950. // Check type from getimagesize type format
  951. if (!in_array($avatar_type, $allowed_types) || empty($extension))
  952. {
  953. @unlink($avatar_tmp_file);
  954. $errors[] = $lang_profile['Bad type'];
  955. }
  956. ($hook = get_hook('pf_change_details_avatar_validate_file')) ? eval($hook) : null;
  957. if (empty($errors))
  958. {
  959. // Delete any old avatars
  960. delete_avatar($id);
  961. // Put the new avatar in its place
  962. @rename($avatar_tmp_file, $forum_config['o_avatars_dir'].'/'.$id.$extension);
  963. @chmod($forum_config['o_avatars_dir'].'/'.$id.$extension, 0644);
  964. // Avatar
  965. $avatar_width = (intval($width) > 0) ? intval($width) : 0;
  966. $avatar_height = (intval($height) > 0) ? intval($height) : 0;
  967. // Save to DB
  968. $query

Large files files are truncated, but you can click here to view the full file