PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/Upload/usercp.php

https://gitlab.com/mybbpl/ppm-1.6
PHP | 1886 lines | 1620 code | 202 blank | 64 comment | 386 complexity | 59144a3973516328c03b47975fa0ae8a MD5 | raw file
  1. <?php
  2. /**
  3. * MyBB 1.6
  4. * Copyright 2010 MyBB Group, All Rights Reserved
  5. *
  6. * Website: http://mybb.com
  7. * License: http://mybb.com/about/license
  8. *
  9. * $Id$
  10. */
  11. define("IN_MYBB", 1);
  12. define('THIS_SCRIPT', 'usercp.php');
  13. $templatelist = "usercp,usercp_nav,usercp_profile,usercp_changename,usercp_email,usercp_password,usercp_subscriptions_thread,forumbit_depth2_forum_lastpost,usercp_forumsubscriptions_forum";
  14. $templatelist .= ",usercp_usergroups_memberof_usergroup,usercp_usergroups_memberof,usercp_usergroups_joinable_usergroup,usercp_usergroups_joinable,usercp_usergroups";
  15. $templatelist .= ",usercp_nav_messenger,usercp_nav_changename,usercp_nav_profile,usercp_nav_misc,usercp_usergroups_leader_usergroup,usercp_usergroups_leader,usercp_currentavatar,usercp_reputation";
  16. $templatelist .= ",usercp_attachments_attachment,usercp_attachments,usercp_profile_away,usercp_profile_customfield,usercp_profile_profilefields,usercp_profile_customtitle,usercp_forumsubscriptions_none";
  17. $templatelist .= ",usercp_forumsubscriptions,usercp_subscriptions_none,usercp_subscriptions,usercp_options_pms_from_buddys,usercp_options_tppselect,usercp_options_pppselect,usercp_options";
  18. $templatelist .= ",usercp_nav_editsignature,usercp_referrals,usercp_notepad,usercp_latest_threads_threads,forumdisplay_thread_gotounread,usercp_latest_threads,usercp_subscriptions_remove";
  19. $templatelist .= ",usercp_editsig_suspended,usercp_editsig,usercp_avatar_gallery_avatar,usercp_avatar_gallery_blankblock,usercp_avatar_gallery_noavatars,usercp_avatar_gallery,usercp_avatar_current";
  20. $templatelist .= ",usercp_avatar,usercp_editlists_userusercp_editlists,usercp_drafts_draft,usercp_drafts_none,usercp_drafts_submit,usercp_drafts,usercp_usergroups_joingroup,usercp_attachments_none";
  21. $templatelist .= ",usercp_warnings_warning,usercp_warnings,usercp_latest_subscribed_threads,usercp_latest_subscribed,usercp_nav_messenger_tracking,multipage_prevpage,multipage_start,multipage_end";
  22. $templatelist .= ",multipage_nextpage,multipage,multipage_page_current,codebuttons,smilieinsert_getmore,smilieinsert";
  23. require_once "./global.php";
  24. require_once MYBB_ROOT."inc/functions_post.php";
  25. require_once MYBB_ROOT."inc/functions_user.php";
  26. require_once MYBB_ROOT."inc/class_parser.php";
  27. $parser = new postParser;
  28. // Load global language phrases
  29. $lang->load("usercp");
  30. if($mybb->user['uid'] == 0 || $mybb->usergroup['canusercp'] == 0)
  31. {
  32. error_no_permission();
  33. }
  34. if(!$mybb->user['pmfolders'])
  35. {
  36. $mybb->user['pmfolders'] = "1**".$lang->folder_inbox."$%%$2**".$lang->folder_sent_items."$%%$3**".$lang->folder_drafts."$%%$4**".$lang->folder_trash;
  37. $db->update_query("users", array('pmfolders' => $mybb->user['pmfolders']), "uid='".$mybb->user['uid']."'");
  38. }
  39. $errors = '';
  40. if(!isset($mybb->input['action']))
  41. {
  42. $mybb->input['action'] = '';
  43. }
  44. $collapse_options = array('usercppms', 'usercpprofile', 'usercpmisc');
  45. foreach($collapse_options as $option)
  46. {
  47. if(!isset($collapsedimg[$option]))
  48. {
  49. $collapsedimg[$option] = '';
  50. }
  51. if(!isset($collapsed[$option.'_e']))
  52. {
  53. $collapsed[$option.'_e'] = '';
  54. }
  55. }
  56. usercp_menu();
  57. $plugins->run_hooks("usercp_start");
  58. if($mybb->input['action'] == "do_editsig" && $mybb->request_method == "post")
  59. {
  60. $parser_options = array(
  61. 'allow_html' => $mybb->settings['sightml'],
  62. 'filter_badwords' => 1,
  63. 'allow_mycode' => $mybb->settings['sigmycode'],
  64. 'allow_smilies' => $mybb->settings['sigsmilies'],
  65. 'allow_imgcode' => $mybb->settings['sigimgcode'],
  66. "filter_badwords" => 1
  67. );
  68. $parsed_sig = $parser->parse_message($mybb->input['signature'], $parser_options);
  69. if((($mybb->settings['sigimgcode'] == 0 && $mybb->settings['sigsmilies'] != 1) &&
  70. substr_count($parsed_sig, "<img") > 0) ||
  71. (($mybb->settings['sigimgcode'] == 1 || $mybb->settings['sigsmilies'] == 1) &&
  72. substr_count($parsed_sig, "<img") > $mybb->settings['maxsigimages'])
  73. )
  74. {
  75. if($mybb->settings['sigimgcode'] == 1)
  76. {
  77. $imgsallowed = $mybb->settings['maxsigimages'];
  78. }
  79. else
  80. {
  81. $imgsallowed = 0;
  82. }
  83. $lang->too_many_sig_images2 = $lang->sprintf($lang->too_many_sig_images2, $imgsallowed);
  84. $error = inline_error($lang->too_many_sig_images." ".$lang->too_many_sig_images2);
  85. $mybb->input['preview'] = 1;
  86. }
  87. else if($mybb->settings['siglength'] > 0)
  88. {
  89. if($mybb->settings['sigcountmycode'] == 0)
  90. {
  91. $parsed_sig = $parser->text_parse_message($mybb->input['signature']);
  92. }
  93. else
  94. {
  95. $parsed_sig = $mybb->input['signature'];
  96. }
  97. $parsed_sig = preg_replace("#\s#", "", $parsed_sig);
  98. $sig_length = my_strlen($parsed_sig);
  99. if($sig_length > $mybb->settings['siglength'])
  100. {
  101. $lang->sig_too_long = $lang->sprintf($lang->sig_too_long, $mybb->settings['siglength']);
  102. if($sig_length - $mybb->settings['siglength'] > 1)
  103. {
  104. $lang->sig_too_long .= $lang->sprintf($lang->sig_remove_chars_plural, $sig_length-$mybb->settings['siglength']);
  105. }
  106. else
  107. {
  108. $lang->sig_too_long .= $lang->sig_remove_chars_singular;
  109. }
  110. $error = inline_error($lang->sig_too_long);
  111. }
  112. }
  113. if($error || $mybb->input['preview'])
  114. {
  115. $mybb->input['action'] = "editsig";
  116. }
  117. }
  118. // Make navigation
  119. add_breadcrumb($lang->nav_usercp, "usercp.php");
  120. switch($mybb->input['action'])
  121. {
  122. case "profile":
  123. case "do_profile":
  124. add_breadcrumb($lang->ucp_nav_profile);
  125. break;
  126. case "options":
  127. case "do_options":
  128. add_breadcrumb($lang->nav_options);
  129. break;
  130. case "email":
  131. case "do_email":
  132. add_breadcrumb($lang->nav_email);
  133. break;
  134. case "password":
  135. case "do_password":
  136. add_breadcrumb($lang->nav_password);
  137. break;
  138. case "changename":
  139. case "do_changename":
  140. add_breadcrumb($lang->nav_changename);
  141. break;
  142. case "subscriptions":
  143. add_breadcrumb($lang->ucp_nav_subscribed_threads);
  144. break;
  145. case "forumsubscriptions":
  146. add_breadcrumb($lang->ucp_nav_forum_subscriptions);
  147. break;
  148. case "editsig":
  149. case "do_editsig":
  150. add_breadcrumb($lang->nav_editsig);
  151. break;
  152. case "avatar":
  153. case "do_avatar":
  154. add_breadcrumb($lang->nav_avatar);
  155. break;
  156. case "notepad":
  157. case "do_notepad":
  158. add_breadcrumb($lang->ucp_nav_notepad);
  159. break;
  160. case "editlists":
  161. case "do_editlists":
  162. add_breadcrumb($lang->ucp_nav_editlists);
  163. break;
  164. case "drafts":
  165. add_breadcrumb($lang->ucp_nav_drafts);
  166. break;
  167. case "usergroups":
  168. add_breadcrumb($lang->ucp_nav_usergroups);
  169. break;
  170. case "attachments":
  171. add_breadcrumb($lang->ucp_nav_attachments);
  172. break;
  173. }
  174. if($mybb->input['action'] == "do_profile" && $mybb->request_method == "post")
  175. {
  176. // Verify incoming POST request
  177. verify_post_check($mybb->input['my_post_key']);
  178. $plugins->run_hooks("usercp_do_profile_start");
  179. if($mybb->input['away'] == 1 && $mybb->settings['allowaway'] != 0)
  180. {
  181. $awaydate = TIME_NOW;
  182. if($mybb->input['awayday'])
  183. {
  184. // If the user has indicated that they will return on a specific day, but not month or year, assume it is current month and year
  185. if(!$mybb->input['awaymonth'])
  186. {
  187. $mybb->input['awaymonth'] = my_date('n', $awaydate);
  188. }
  189. if(!$mybb->input['awayyear'])
  190. {
  191. $mybb->input['awayyear'] = my_date('Y', $awaydate);
  192. }
  193. $return_month = intval(substr($mybb->input['awaymonth'], 0, 2));
  194. $return_day = intval(substr($mybb->input['awayday'], 0, 2));
  195. $return_year = min(intval($mybb->input['awayyear']), 9999);
  196. // Check if return date is after the away date.
  197. $returntimestamp = gmmktime(0, 0, 0, $return_month, $return_day, $return_year);
  198. $awaytimestamp = gmmktime(0, 0, 0, my_date('n', $awaydate), my_date('j', $awaydate), my_date('Y', $awaydate));
  199. if($return_year < my_date('Y', $awaydate) || ($returntimestamp < $awaytimestamp && $return_year == my_date('Y', $awaydate)))
  200. {
  201. error($lang->error_usercp_return_date_past);
  202. }
  203. $returndate = "{$return_day}-{$return_month}-{$return_year}";
  204. }
  205. else
  206. {
  207. $returndate = "";
  208. }
  209. $away = array(
  210. "away" => 1,
  211. "date" => $awaydate,
  212. "returndate" => $returndate,
  213. "awayreason" => $mybb->input['awayreason']
  214. );
  215. }
  216. else
  217. {
  218. $away = array(
  219. "away" => 0,
  220. "date" => '',
  221. "returndate" => '',
  222. "awayreason" => ''
  223. );
  224. }
  225. $bday = array(
  226. "day" => $mybb->input['bday1'],
  227. "month" => $mybb->input['bday2'],
  228. "year" => $mybb->input['bday3']
  229. );
  230. // Set up user handler.
  231. require_once "inc/datahandlers/user.php";
  232. $userhandler = new UserDataHandler("update");
  233. $user = array(
  234. "uid" => $mybb->user['uid'],
  235. "postnum" => $mybb->user['postnum'],
  236. "website" => $mybb->input['website'],
  237. "icq" => intval($mybb->input['icq']),
  238. "aim" => $mybb->input['aim'],
  239. "yahoo" => $mybb->input['yahoo'],
  240. "msn" => $mybb->input['msn'],
  241. "birthday" => $bday,
  242. "birthdayprivacy" => $mybb->input['birthdayprivacy'],
  243. "away" => $away,
  244. "profile_fields" => $mybb->input['profile_fields']
  245. );
  246. if($mybb->usergroup['cancustomtitle'] == 1)
  247. {
  248. if($mybb->input['usertitle'] != '')
  249. {
  250. $user['usertitle'] = $mybb->input['usertitle'];
  251. }
  252. else if($mybb->input['reverttitle'])
  253. {
  254. $user['usertitle'] = '';
  255. }
  256. }
  257. $userhandler->set_data($user);
  258. if(!$userhandler->validate_user())
  259. {
  260. $errors = $userhandler->get_friendly_errors();
  261. // Set allowed value otherwise select options disappear
  262. if(in_array($lang->userdata_invalid_birthday_privacy, $errors))
  263. {
  264. $mybb->input['birthdayprivacy'] = 'none';
  265. }
  266. $errors = inline_error($errors);
  267. $mybb->input['action'] = "profile";
  268. }
  269. else
  270. {
  271. $userhandler->update_user();
  272. $plugins->run_hooks("usercp_do_profile_end");
  273. redirect("usercp.php", $lang->redirect_profileupdated);
  274. }
  275. }
  276. if($mybb->input['action'] == "profile")
  277. {
  278. if($errors)
  279. {
  280. $user = $mybb->input;
  281. $bday = array();
  282. $bday[0] = $mybb->input['bday1'];
  283. $bday[1] = $mybb->input['bday2'];
  284. $bday[2] = intval($mybb->input['bday3']);
  285. }
  286. else
  287. {
  288. $user = $mybb->user;
  289. $bday = explode("-", $user['birthday']);
  290. }
  291. $plugins->run_hooks("usercp_profile_start");
  292. $bdaysel = '';
  293. for($i = 1; $i <= 31; ++$i)
  294. {
  295. if($bday[0] == $i)
  296. {
  297. $bdaydaysel .= "<option value=\"$i\" selected=\"selected\">$i</option>\n";
  298. }
  299. else
  300. {
  301. $bdaydaysel .= "<option value=\"$i\">$i</option>\n";
  302. }
  303. }
  304. $bdaymonthsel[$bday[1]] = 'selected="selected"';
  305. $bdayprivacysel = '';
  306. if($user['birthdayprivacy'] == 'all' || !$user['birthdayprivacy'])
  307. {
  308. $bdayprivacysel .= "<option value=\"all\" selected=\"selected\">{$lang->birthdayprivacyall}</option>\n";
  309. $bdayprivacysel .= "<option value=\"none\">{$lang->birthdayprivacynone}</option>\n";
  310. $bdayprivacysel .= "<option value=\"age\">{$lang->birthdayprivacyage}</option>";
  311. }
  312. else if($user['birthdayprivacy'] == 'none')
  313. {
  314. $bdayprivacysel .= "<option value=\"all\">{$lang->birthdayprivacyall}</option>\n";
  315. $bdayprivacysel .= "<option value=\"none\" selected=\"selected\">{$lang->birthdayprivacynone}</option>\n";
  316. $bdayprivacysel .= "<option value=\"age\">{$lang->birthdayprivacyage}</option>";
  317. }
  318. else if($user['birthdayprivacy'] == 'age')
  319. {
  320. $bdayprivacysel .= "<option value=\"all\">{$lang->birthdayprivacyall}</option>\n";
  321. $bdayprivacysel .= "<option value=\"none\">{$lang->birthdayprivacynone}</option>\n";
  322. $bdayprivacysel .= "<option value=\"age\" selected=\"selected\">{$lang->birthdayprivacyage}</option>";
  323. }
  324. if($user['website'] == "" || $user['website'] == "http://")
  325. {
  326. $user['website'] = "http://";
  327. }
  328. else
  329. {
  330. $user['website'] = htmlspecialchars_uni($user['website']);
  331. }
  332. if($user['icq'] != "0")
  333. {
  334. $user['icq'] = intval($user['icq']);
  335. }
  336. if($user['icq'] == 0)
  337. {
  338. $user['icq'] = "";
  339. }
  340. if($errors)
  341. {
  342. $user['msn'] = htmlspecialchars_uni($user['msn']);
  343. $user['aim'] = htmlspecialchars_uni($user['aim']);
  344. $user['yahoo'] = htmlspecialchars_uni($user['yahoo']);
  345. }
  346. if($mybb->settings['allowaway'] != 0)
  347. {
  348. if($errors)
  349. {
  350. if($user['away'] == 1)
  351. {
  352. $awaycheck[1] = "checked=\"checked\"";
  353. }
  354. else
  355. {
  356. $awaycheck[0] = "checked=\"checked\"";
  357. }
  358. $returndate = array();
  359. $returndate[0] = $mybb->input['awayday'];
  360. $returndate[1] = $mybb->input['awaymonth'];
  361. $returndate[2] = intval($mybb->input['awayyear']);
  362. $user['awayreason'] = htmlspecialchars_uni($mybb->input['awayreason']);
  363. }
  364. else
  365. {
  366. $user['awayreason'] = htmlspecialchars_uni($user['awayreason']);
  367. if($mybb->user['away'] == 1)
  368. {
  369. $awaydate = my_date($mybb->settings['dateformat'], $mybb->user['awaydate']);
  370. $awaycheck[1] = "checked=\"checked\"";
  371. $awaynotice = $lang->sprintf($lang->away_notice_away, $awaydate);
  372. }
  373. else
  374. {
  375. $awaynotice = $lang->away_notice;
  376. $awaycheck[0] = "checked=\"checked\"";
  377. }
  378. $returndate = explode("-", $mybb->user['returndate']);
  379. }
  380. $returndatesel = '';
  381. for($i = 1; $i <= 31; ++$i)
  382. {
  383. if($returndate[0] == $i)
  384. {
  385. $returndatesel .= "<option value=\"$i\" selected=\"selected\">$i</option>\n";
  386. }
  387. else
  388. {
  389. $returndatesel .= "<option value=\"$i\">$i</option>\n";
  390. }
  391. }
  392. $returndatemonthsel[$returndate[1]] = "selected";
  393. eval("\$awaysection = \"".$templates->get("usercp_profile_away")."\";");
  394. }
  395. // Custom profile fields baby!
  396. $altbg = "trow1";
  397. $requiredfields = '';
  398. $customfields = '';
  399. $query = $db->simple_select("profilefields", "*", "editable=1", array('order_by' => 'disporder'));
  400. while($profilefield = $db->fetch_array($query))
  401. {
  402. // Does this field have a minimum post count?
  403. if($profilefield['postnum'] && $profilefield['postnum'] > $mybb->user['postnum'])
  404. {
  405. continue;
  406. }
  407. $profilefield['type'] = htmlspecialchars_uni($profilefield['type']);
  408. $profilefield['name'] = htmlspecialchars_uni($profilefield['name']);
  409. $profilefield['description'] = htmlspecialchars_uni($profilefield['description']);
  410. $thing = explode("\n", $profilefield['type'], "2");
  411. $type = $thing[0];
  412. $options = $thing[1];
  413. $field = "fid{$profilefield['fid']}";
  414. $select = '';
  415. if($errors)
  416. {
  417. $userfield = $mybb->input['profile_fields'][$field];
  418. }
  419. else
  420. {
  421. $userfield = $user[$field];
  422. }
  423. if($type == "multiselect")
  424. {
  425. if($errors)
  426. {
  427. $useropts = $userfield;
  428. }
  429. else
  430. {
  431. $useropts = explode("\n", $userfield);
  432. }
  433. if(is_array($useropts))
  434. {
  435. foreach($useropts as $key => $val)
  436. {
  437. $val = htmlspecialchars_uni($val);
  438. $seloptions[$val] = $val;
  439. }
  440. }
  441. $expoptions = explode("\n", $options);
  442. if(is_array($expoptions))
  443. {
  444. foreach($expoptions as $key => $val)
  445. {
  446. $val = trim($val);
  447. $val = str_replace("\n", "\\n", $val);
  448. $sel = "";
  449. if($val == $seloptions[$val])
  450. {
  451. $sel = " selected=\"selected\"";
  452. }
  453. $select .= "<option value=\"$val\"$sel>$val</option>\n";
  454. }
  455. if(!$profilefield['length'])
  456. {
  457. $profilefield['length'] = 3;
  458. }
  459. $code = "<select name=\"profile_fields[$field][]\" size=\"{$profilefield['length']}\" multiple=\"multiple\">$select</select>";
  460. }
  461. }
  462. elseif($type == "select")
  463. {
  464. $expoptions = explode("\n", $options);
  465. if(is_array($expoptions))
  466. {
  467. foreach($expoptions as $key => $val)
  468. {
  469. $val = trim($val);
  470. $val = str_replace("\n", "\\n", $val);
  471. $sel = "";
  472. if($val == htmlspecialchars_uni($userfield))
  473. {
  474. $sel = " selected=\"selected\"";
  475. }
  476. $select .= "<option value=\"$val\"$sel>$val</option>";
  477. }
  478. if(!$profilefield['length'])
  479. {
  480. $profilefield['length'] = 1;
  481. }
  482. $code = "<select name=\"profile_fields[$field]\" size=\"{$profilefield['length']}\">$select</select>";
  483. }
  484. }
  485. elseif($type == "radio")
  486. {
  487. $expoptions = explode("\n", $options);
  488. if(is_array($expoptions))
  489. {
  490. foreach($expoptions as $key => $val)
  491. {
  492. $checked = "";
  493. if($val == $userfield)
  494. {
  495. $checked = " checked=\"checked\"";
  496. }
  497. $code .= "<input type=\"radio\" class=\"radio\" name=\"profile_fields[$field]\" value=\"$val\"$checked /> <span class=\"smalltext\">$val</span><br />";
  498. }
  499. }
  500. }
  501. elseif($type == "checkbox")
  502. {
  503. if($errors)
  504. {
  505. $useropts = $userfield;
  506. }
  507. else
  508. {
  509. $useropts = explode("\n", $userfield);
  510. }
  511. if(is_array($useropts))
  512. {
  513. foreach($useropts as $key => $val)
  514. {
  515. $seloptions[$val] = $val;
  516. }
  517. }
  518. $expoptions = explode("\n", $options);
  519. if(is_array($expoptions))
  520. {
  521. foreach($expoptions as $key => $val)
  522. {
  523. $checked = "";
  524. if($val == $seloptions[$val])
  525. {
  526. $checked = " checked=\"checked\"";
  527. }
  528. $code .= "<input type=\"checkbox\" class=\"checkbox\" name=\"profile_fields[$field][]\" value=\"$val\"$checked /> <span class=\"smalltext\">$val</span><br />";
  529. }
  530. }
  531. }
  532. elseif($type == "textarea")
  533. {
  534. $value = htmlspecialchars_uni($userfield);
  535. $code = "<textarea name=\"profile_fields[$field]\" rows=\"6\" cols=\"30\" style=\"width: 95%\">$value</textarea>";
  536. }
  537. else
  538. {
  539. $value = htmlspecialchars_uni($userfield);
  540. $maxlength = "";
  541. if($profilefield['maxlength'] > 0)
  542. {
  543. $maxlength = " maxlength=\"{$profilefield['maxlength']}\"";
  544. }
  545. $code = "<input type=\"text\" name=\"profile_fields[$field]\" class=\"textbox\" size=\"{$profilefield['length']}\"{$maxlength} value=\"$value\" />";
  546. }
  547. if($profilefield['required'] == 1)
  548. {
  549. eval("\$requiredfields .= \"".$templates->get("usercp_profile_customfield")."\";");
  550. }
  551. else
  552. {
  553. eval("\$customfields .= \"".$templates->get("usercp_profile_customfield")."\";");
  554. }
  555. $altbg = alt_trow();
  556. $code = "";
  557. $select = "";
  558. $val = "";
  559. $options = "";
  560. $expoptions = "";
  561. $useropts = "";
  562. $seloptions = "";
  563. }
  564. if($customfields)
  565. {
  566. eval("\$customfields = \"".$templates->get("usercp_profile_profilefields")."\";");
  567. }
  568. if($mybb->usergroup['cancustomtitle'] == 1)
  569. {
  570. if($mybb->usergroup['usertitle'] == "")
  571. {
  572. $defaulttitle = '';
  573. $usertitles = $cache->read('usertitles');
  574. foreach($usertitles as $title)
  575. {
  576. if($title['posts'] <= $mybb->user['postnum'])
  577. {
  578. $defaulttitle = htmlspecialchars_uni($title['title']);
  579. break;
  580. }
  581. }
  582. }
  583. else
  584. {
  585. $defaulttitle = htmlspecialchars_uni($mybb->usergroup['usertitle']);
  586. }
  587. if(trim($user['usertitle']) == '')
  588. {
  589. $lang->current_custom_usertitle = '';
  590. }
  591. else
  592. {
  593. if($errors)
  594. {
  595. $newtitle = htmlspecialchars_uni($user['usertitle']);
  596. $user['usertitle'] = $mybb->user['usertitle'];
  597. }
  598. }
  599. eval("\$customtitle = \"".$templates->get("usercp_profile_customtitle")."\";");
  600. }
  601. else
  602. {
  603. $customtitle = "";
  604. }
  605. $plugins->run_hooks("usercp_profile_end");
  606. eval("\$editprofile = \"".$templates->get("usercp_profile")."\";");
  607. output_page($editprofile);
  608. }
  609. if($mybb->input['action'] == "do_options" && $mybb->request_method == "post")
  610. {
  611. // Verify incoming POST request
  612. verify_post_check($mybb->input['my_post_key']);
  613. $plugins->run_hooks("usercp_do_options_start");
  614. // Set up user handler.
  615. require_once MYBB_ROOT."inc/datahandlers/user.php";
  616. $userhandler = new UserDataHandler("update");
  617. $user = array(
  618. "uid" => $mybb->user['uid'],
  619. "style" => intval($mybb->input['style']),
  620. "dateformat" => intval($mybb->input['dateformat']),
  621. "timeformat" => intval($mybb->input['timeformat']),
  622. "timezone" => $db->escape_string($mybb->input['timezoneoffset']),
  623. "language" => $mybb->input['language']
  624. );
  625. $user['options'] = array(
  626. "allownotices" => $mybb->input['allownotices'],
  627. "hideemail" => $mybb->input['hideemail'],
  628. "subscriptionmethod" => $mybb->input['subscriptionmethod'],
  629. "invisible" => $mybb->input['invisible'],
  630. "dstcorrection" => $mybb->input['dstcorrection'],
  631. "threadmode" => $mybb->input['threadmode'],
  632. "showsigs" => $mybb->input['showsigs'],
  633. "showavatars" => $mybb->input['showavatars'],
  634. "showquickreply" => $mybb->input['showquickreply'],
  635. "receivepms" => $mybb->input['receivepms'],
  636. "pmnotice" => $mybb->input['pmnotice'],
  637. "receivefrombuddy" => $mybb->input['receivefrombuddy'],
  638. "daysprune" => $mybb->input['daysprune'],
  639. "showcodebuttons" => intval($mybb->input['showcodebuttons']),
  640. "pmnotify" => $mybb->input['pmnotify'],
  641. "showredirect" => $mybb->input['showredirect'],
  642. "classicpostbit" => $mybb->input['classicpostbit']
  643. );
  644. if($mybb->settings['usertppoptions'])
  645. {
  646. $user['options']['tpp'] = intval($mybb->input['tpp']);
  647. }
  648. if($mybb->settings['userpppoptions'])
  649. {
  650. $user['options']['ppp'] = intval($mybb->input['ppp']);
  651. }
  652. $userhandler->set_data($user);
  653. if(!$userhandler->validate_user())
  654. {
  655. $errors = $userhandler->get_friendly_errors();
  656. $errors = inline_error($errors);
  657. $mybb->input['action'] = "options";
  658. }
  659. else
  660. {
  661. $userhandler->update_user();
  662. $plugins->run_hooks("usercp_do_options_end");
  663. redirect("usercp.php", $lang->redirect_optionsupdated);
  664. }
  665. }
  666. if($mybb->input['action'] == "options")
  667. {
  668. $plugins->run_hooks("usercp_options_start");
  669. if($errors != '')
  670. {
  671. $user = $mybb->input;
  672. }
  673. else
  674. {
  675. $user = $mybb->user;
  676. }
  677. $languages = $lang->get_languages();
  678. $langoptions = '';
  679. foreach($languages as $lname => $language)
  680. {
  681. $sel = "";
  682. if($user['language'] == $lname)
  683. {
  684. $sel = " selected=\"selected\"";
  685. }
  686. $langoptions .= "<option value=\"$lname\"$sel>".htmlspecialchars_uni($language)."</option>\n";
  687. }
  688. // Lets work out which options the user has selected and check the boxes
  689. if($user['allownotices'] == 1)
  690. {
  691. $allownoticescheck = "checked=\"checked\"";
  692. }
  693. else
  694. {
  695. $allownoticescheck = "";
  696. }
  697. if($user['invisible'] == 1)
  698. {
  699. $invisiblecheck = "checked=\"checked\"";
  700. }
  701. else
  702. {
  703. $invisiblecheck = "";
  704. }
  705. if($user['hideemail'] == 1)
  706. {
  707. $hideemailcheck = "checked=\"checked\"";
  708. }
  709. else
  710. {
  711. $hideemailcheck = "";
  712. }
  713. if($user['subscriptionmethod'] == 1)
  714. {
  715. $no_email_subscribe_selected = "selected=\"selected\"";
  716. }
  717. else if($user['subscriptionmethod'] == 2)
  718. {
  719. $instant_email_subscribe_selected = "selected=\"selected\"";
  720. }
  721. else
  722. {
  723. $no_subscribe_selected = "selected=\"selected\"";
  724. }
  725. if($user['showsigs'] == 1)
  726. {
  727. $showsigscheck = "checked=\"checked\"";
  728. }
  729. else
  730. {
  731. $showsigscheck = "";
  732. }
  733. if($user['showavatars'] == 1)
  734. {
  735. $showavatarscheck = "checked=\"checked\"";
  736. }
  737. else
  738. {
  739. $showavatarscheck = "";
  740. }
  741. if($user['showquickreply'] == 1)
  742. {
  743. $showquickreplycheck = "checked=\"checked\"";
  744. }
  745. else
  746. {
  747. $showquickreplycheck = "";
  748. }
  749. if($user['receivepms'] == 1)
  750. {
  751. $receivepmscheck = "checked=\"checked\"";
  752. }
  753. else
  754. {
  755. $receivepmscheck = "";
  756. }
  757. if($user['receivefrombuddy'] == 1)
  758. {
  759. $receivefrombuddycheck = "checked=\"checked\"";
  760. }
  761. else
  762. {
  763. $receivefrombuddycheck = "";
  764. }
  765. if($user['pmnotice'] == 1 || $user['pmnotice'] == 2)
  766. {
  767. $pmnoticecheck = " checked=\"checked\"";
  768. }
  769. else
  770. {
  771. $pmnoticecheck = "";
  772. }
  773. if($user['dstcorrection'] == 2)
  774. {
  775. $dst_auto_selected = "selected=\"selected\"";
  776. }
  777. else if($user['dstcorrection'] == 1)
  778. {
  779. $dst_enabled_selected = "selected=\"selected\"";
  780. }
  781. else
  782. {
  783. $dst_disabled_selected = "selected=\"selected\"";
  784. }
  785. if($user['showcodebuttons'] == 1)
  786. {
  787. $showcodebuttonscheck = "checked=\"checked\"";
  788. }
  789. else
  790. {
  791. $showcodebuttonscheck = "";
  792. }
  793. if($user['showredirect'] != 0)
  794. {
  795. $showredirectcheck = "checked=\"checked\"";
  796. }
  797. else
  798. {
  799. $showredirectcheck = "";
  800. }
  801. if($user['pmnotify'] != 0)
  802. {
  803. $pmnotifycheck = "checked=\"checked\"";
  804. }
  805. else
  806. {
  807. $pmnotifycheck = '';
  808. }
  809. if($user['threadmode'] != "threaded" && $user['threadmode'] != "linear")
  810. {
  811. $user['threadmode'] = ''; // Leave blank to show default
  812. }
  813. if($user['classicpostbit'] != 0)
  814. {
  815. $classicpostbitcheck = "checked=\"checked\"";
  816. }
  817. else
  818. {
  819. $classicpostbitcheck = '';
  820. }
  821. $date_format_options = "<option value=\"0\">{$lang->use_default}</option>";
  822. foreach($date_formats as $key => $format)
  823. {
  824. if($user['dateformat'] == $key)
  825. {
  826. $date_format_options .= "<option value=\"$key\" selected=\"selected\">".my_date($format, TIME_NOW, "", 0)."</option>";
  827. }
  828. else
  829. {
  830. $date_format_options .= "<option value=\"$key\">".my_date($format, TIME_NOW, "", 0)."</option>";
  831. }
  832. }
  833. $time_format_options = "<option value=\"0\">{$lang->use_default}</option>";
  834. foreach($time_formats as $key => $format)
  835. {
  836. if($user['timeformat'] == $key)
  837. {
  838. $time_format_options .= "<option value=\"$key\" selected=\"selected\">".my_date($format, TIME_NOW, "", 0)."</option>";
  839. }
  840. else
  841. {
  842. $time_format_options .= "<option value=\"$key\">".my_date($format, TIME_NOW, "", 0)."</option>";
  843. }
  844. }
  845. $tzselect = build_timezone_select("timezoneoffset", $mybb->user['timezone'], true);
  846. if($mybb->settings['allowbuddyonly'] == 1)
  847. {
  848. eval("\$pms_from_buddys = \"".$templates->get("usercp_options_pms_from_buddys")."\";");
  849. }
  850. $threadview[$user['threadmode']] = 'selected="selected"';
  851. $daysprunesel[$user['daysprune']] = 'selected="selected"';
  852. $stylelist = build_theme_select("style", $user['style']);
  853. if($mybb->settings['usertppoptions'])
  854. {
  855. $explodedtpp = explode(",", $mybb->settings['usertppoptions']);
  856. $tppoptions = '';
  857. if(is_array($explodedtpp))
  858. {
  859. foreach($explodedtpp as $key => $val)
  860. {
  861. $val = trim($val);
  862. $selected = "";
  863. if($user['tpp'] == $val)
  864. {
  865. $selected = "selected=\"selected\"";
  866. }
  867. $tppoptions .= "<option value=\"$val\" $selected>".$lang->sprintf($lang->tpp_option, $val)."</option>\n";
  868. }
  869. }
  870. eval("\$tppselect = \"".$templates->get("usercp_options_tppselect")."\";");
  871. }
  872. if($mybb->settings['userpppoptions'])
  873. {
  874. $explodedppp = explode(",", $mybb->settings['userpppoptions']);
  875. $pppoptions = '';
  876. if(is_array($explodedppp))
  877. {
  878. foreach($explodedppp as $key => $val)
  879. {
  880. $val = trim($val);
  881. $selected = "";
  882. if($user['ppp'] == $val)
  883. {
  884. $selected = "selected=\"selected\"";
  885. }
  886. $pppoptions .= "<option value=\"$val\" $selected>".$lang->sprintf($lang->ppp_option, $val)."</option>\n";
  887. }
  888. }
  889. eval("\$pppselect = \"".$templates->get("usercp_options_pppselect")."\";");
  890. }
  891. $plugins->run_hooks("usercp_options_end");
  892. eval("\$editprofile = \"".$templates->get("usercp_options")."\";");
  893. output_page($editprofile);
  894. }
  895. if($mybb->input['action'] == "do_email" && $mybb->request_method == "post")
  896. {
  897. // Verify incoming POST request
  898. verify_post_check($mybb->input['my_post_key']);
  899. $errors = array();
  900. $plugins->run_hooks("usercp_do_email_start");
  901. if(validate_password_from_uid($mybb->user['uid'], $mybb->input['password']) == false)
  902. {
  903. $errors[] = $lang->error_invalidpassword;
  904. }
  905. else
  906. {
  907. // Set up user handler.
  908. require_once "inc/datahandlers/user.php";
  909. $userhandler = new UserDataHandler("update");
  910. $user = array(
  911. "uid" => $mybb->user['uid'],
  912. "email" => $mybb->input['email'],
  913. "email2" => $mybb->input['email2']
  914. );
  915. $userhandler->set_data($user);
  916. if(!$userhandler->validate_user())
  917. {
  918. $errors = $userhandler->get_friendly_errors();
  919. }
  920. else
  921. {
  922. if($mybb->user['usergroup'] != "5" && $mybb->usergroup['cancp'] != 1)
  923. {
  924. $activationcode = random_str();
  925. $now = TIME_NOW;
  926. $db->delete_query("awaitingactivation", "uid='".$mybb->user['uid']."'");
  927. $newactivation = array(
  928. "uid" => $mybb->user['uid'],
  929. "dateline" => TIME_NOW,
  930. "code" => $activationcode,
  931. "type" => "e",
  932. "oldgroup" => $mybb->user['usergroup'],
  933. "misc" => $db->escape_string($mybb->input['email'])
  934. );
  935. $db->insert_query("awaitingactivation", $newactivation);
  936. $username = $mybb->user['username'];
  937. $uid = $mybb->user['uid'];
  938. $lang->emailsubject_changeemail = $lang->sprintf($lang->emailsubject_changeemail, $mybb->settings['bbname']);
  939. $lang->email_changeemail = $lang->sprintf($lang->email_changeemail, $mybb->user['username'], $mybb->settings['bbname'], $mybb->user['email'], $mybb->input['email'], $mybb->settings['bburl'], $activationcode, $mybb->user['username'], $mybb->user['uid']);
  940. my_mail($mybb->input['email'], $lang->emailsubject_changeemail, $lang->email_changeemail);
  941. $plugins->run_hooks("usercp_do_email_verify");
  942. error($lang->redirect_changeemail_activation);
  943. }
  944. else
  945. {
  946. $userhandler->update_user();
  947. $plugins->run_hooks("usercp_do_email_changed");
  948. redirect("usercp.php", $lang->redirect_emailupdated);
  949. }
  950. }
  951. }
  952. if(count($errors) > 0)
  953. {
  954. $mybb->input['action'] = "email";
  955. $errors = inline_error($errors);
  956. }
  957. }
  958. if($mybb->input['action'] == "email")
  959. {
  960. // Coming back to this page after one or more errors were experienced, show fields the user previously entered (with the exception of the password)
  961. if($errors)
  962. {
  963. $email = htmlspecialchars_uni($mybb->input['email']);
  964. $email2 = htmlspecialchars_uni($mybb->input['email2']);
  965. }
  966. else
  967. {
  968. $email = $email2 = '';
  969. }
  970. $plugins->run_hooks("usercp_email");
  971. eval("\$changemail = \"".$templates->get("usercp_email")."\";");
  972. output_page($changemail);
  973. }
  974. if($mybb->input['action'] == "do_password" && $mybb->request_method == "post")
  975. {
  976. // Verify incoming POST request
  977. verify_post_check($mybb->input['my_post_key']);
  978. $errors = array();
  979. $plugins->run_hooks("usercp_do_password_start");
  980. if(validate_password_from_uid($mybb->user['uid'], $mybb->input['oldpassword']) == false)
  981. {
  982. $errors[] = $lang->error_invalidpassword;
  983. }
  984. else
  985. {
  986. // Set up user handler.
  987. require_once "inc/datahandlers/user.php";
  988. $userhandler = new UserDataHandler("update");
  989. $user = array(
  990. "uid" => $mybb->user['uid'],
  991. "password" => $mybb->input['password'],
  992. "password2" => $mybb->input['password2']
  993. );
  994. $userhandler->set_data($user);
  995. if(!$userhandler->validate_user())
  996. {
  997. $errors = $userhandler->get_friendly_errors();
  998. }
  999. else
  1000. {
  1001. $userhandler->update_user();
  1002. my_setcookie("mybbuser", $mybb->user['uid']."_".$userhandler->data['loginkey']);
  1003. $plugins->run_hooks("usercp_do_password_end");
  1004. redirect("usercp.php", $lang->redirect_passwordupdated);
  1005. }
  1006. }
  1007. if(count($errors) > 0)
  1008. {
  1009. $mybb->input['action'] = "password";
  1010. $errors = inline_error($errors);
  1011. }
  1012. }
  1013. if($mybb->input['action'] == "password")
  1014. {
  1015. $plugins->run_hooks("usercp_password");
  1016. eval("\$editpassword = \"".$templates->get("usercp_password")."\";");
  1017. output_page($editpassword);
  1018. }
  1019. if($mybb->input['action'] == "do_changename" && $mybb->request_method == "post")
  1020. {
  1021. // Verify incoming POST request
  1022. verify_post_check($mybb->input['my_post_key']);
  1023. $plugins->run_hooks("usercp_do_changename_start");
  1024. if($mybb->usergroup['canchangename'] != 1)
  1025. {
  1026. error_no_permission();
  1027. }
  1028. if(validate_password_from_uid($mybb->user['uid'], $mybb->input['password']) == false)
  1029. {
  1030. $errors[] = $lang->error_invalidpassword;
  1031. }
  1032. else
  1033. {
  1034. // Set up user handler.
  1035. require_once "inc/datahandlers/user.php";
  1036. $userhandler = new UserDataHandler("update");
  1037. $user = array(
  1038. "uid" => $mybb->user['uid'],
  1039. "username" => $mybb->input['username']
  1040. );
  1041. $userhandler->set_data($user);
  1042. if(!$userhandler->validate_user())
  1043. {
  1044. $errors = $userhandler->get_friendly_errors();
  1045. }
  1046. else
  1047. {
  1048. $userhandler->update_user();
  1049. $plugins->run_hooks("usercp_do_changename_end");
  1050. redirect("usercp.php", $lang->redirect_namechanged);
  1051. }
  1052. }
  1053. if(count($errors) > 0)
  1054. {
  1055. $errors = inline_error($errors);
  1056. $mybb->input['action'] = "changename";
  1057. }
  1058. }
  1059. if($mybb->input['action'] == "changename")
  1060. {
  1061. $plugins->run_hooks("usercp_changename_start");
  1062. if($mybb->usergroup['canchangename'] != 1)
  1063. {
  1064. error_no_permission();
  1065. }
  1066. $plugins->run_hooks("usercp_changename_end");
  1067. eval("\$changename = \"".$templates->get("usercp_changename")."\";");
  1068. output_page($changename);
  1069. }
  1070. if($mybb->input['action'] == "do_subscriptions")
  1071. {
  1072. // Verify incoming POST request
  1073. verify_post_check($mybb->input['my_post_key']);
  1074. $plugins->run_hooks("usercp_do_subscriptions_start");
  1075. if(!is_array($mybb->input['check']))
  1076. {
  1077. error($lang->no_subscriptions_selected);
  1078. }
  1079. // Clean input - only accept integers thanks!
  1080. $mybb->input['check'] = array_map('intval', $mybb->input['check']);
  1081. $tids = implode(",", $mybb->input['check']);
  1082. // Deleting these subscriptions?
  1083. if($mybb->input['do'] == "delete")
  1084. {
  1085. $db->delete_query("threadsubscriptions", "tid IN ($tids) AND uid='{$mybb->user['uid']}'");
  1086. }
  1087. // Changing subscription type
  1088. else
  1089. {
  1090. if($mybb->input['do'] == "no_notification")
  1091. {
  1092. $new_notification = 0;
  1093. }
  1094. else if($mybb->input['do'] == "instant_notification")
  1095. {
  1096. $new_notification = 1;
  1097. }
  1098. // Update
  1099. $update_array = array("notification" => $new_notification);
  1100. $db->update_query("threadsubscriptions", $update_array, "tid IN ($tids) AND uid='{$mybb->user['uid']}'");
  1101. }
  1102. // Done, redirect
  1103. redirect("usercp.php?action=subscriptions", $lang->redirect_subscriptions_updated);
  1104. }
  1105. if($mybb->input['action'] == "subscriptions")
  1106. {
  1107. $plugins->run_hooks("usercp_subscriptions_start");
  1108. // Thread visiblity
  1109. $visible = "AND t.visible != 0";
  1110. if(is_moderator() == true)
  1111. {
  1112. $visible = '';
  1113. }
  1114. // Do Multi Pages
  1115. $query = $db->query("
  1116. SELECT COUNT(ts.tid) as threads
  1117. FROM ".TABLE_PREFIX."threadsubscriptions ts
  1118. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid = ts.tid)
  1119. WHERE ts.uid = '".$mybb->user['uid']."' {$visible}
  1120. ");
  1121. $threadcount = $db->fetch_field($query, "threads");
  1122. if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1)
  1123. {
  1124. $mybb->settings['threadsperpage'] = 20;
  1125. }
  1126. $perpage = $mybb->settings['threadsperpage'];
  1127. $page = intval($mybb->input['page']);
  1128. if($page > 0)
  1129. {
  1130. $start = ($page-1) * $perpage;
  1131. $pages = $threadcount / $perpage;
  1132. $pages = ceil($pages);
  1133. if($page > $pages || $page <= 0)
  1134. {
  1135. $start = 0;
  1136. $page = 1;
  1137. }
  1138. }
  1139. else
  1140. {
  1141. $start = 0;
  1142. $page = 1;
  1143. }
  1144. $end = $start + $perpage;
  1145. $lower = $start+1;
  1146. $upper = $end;
  1147. if($upper > $threadcount)
  1148. {
  1149. $upper = $threadcount;
  1150. }
  1151. $multipage = multipage($threadcount, $perpage, $page, "usercp.php?action=subscriptions");
  1152. $fpermissions = forum_permissions();
  1153. // Fetch subscriptions
  1154. $query = $db->query("
  1155. SELECT s.*, t.*, t.username AS threadusername, u.username, p.displaystyle AS threadprefix
  1156. FROM ".TABLE_PREFIX."threadsubscriptions s
  1157. LEFT JOIN ".TABLE_PREFIX."threads t ON (s.tid=t.tid)
  1158. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
  1159. LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
  1160. WHERE s.uid='".$mybb->user['uid']."' {$visible}
  1161. ORDER BY t.lastpost DESC
  1162. LIMIT $start, $perpage
  1163. ");
  1164. while($subscription = $db->fetch_array($query))
  1165. {
  1166. $forumpermissions = $fpermissions[$subscription['fid']];
  1167. if($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0 || ($forumpermissions['canonlyviewownthreads'] != 0 && $subscription['uid'] != $mybb->user['uid']))
  1168. {
  1169. // Hmm, you don't have permission to view this thread - unsubscribe!
  1170. $del_subscriptions[] = $subscription['sid'];
  1171. }
  1172. else if($subscription['tid'])
  1173. {
  1174. $subscriptions[$subscription['tid']] = $subscription;
  1175. }
  1176. }
  1177. if(is_array($del_subscriptions))
  1178. {
  1179. $sids = implode(',', $del_subscriptions);
  1180. if($sids)
  1181. {
  1182. $db->delete_query("threadsubscriptions", "sid IN ({$sids}) AND uid='{$mybb->user['uid']}'");
  1183. }
  1184. $threadcount = $threadcount - count($del_subscriptions);
  1185. if($threadcount < 0)
  1186. {
  1187. $threadcount = 0;
  1188. }
  1189. }
  1190. if(is_array($subscriptions))
  1191. {
  1192. $tids = implode(",", array_keys($subscriptions));
  1193. if($mybb->user['uid'] == 0)
  1194. {
  1195. // Build a forum cache.
  1196. $query = $db->query("
  1197. SELECT fid
  1198. FROM ".TABLE_PREFIX."forums
  1199. WHERE active != 0
  1200. ORDER BY pid, disporder
  1201. ");
  1202. $forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
  1203. }
  1204. else
  1205. {
  1206. // Build a forum cache.
  1207. $query = $db->query("
  1208. SELECT f.fid, fr.dateline AS lastread
  1209. FROM ".TABLE_PREFIX."forums f
  1210. LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
  1211. WHERE f.active != 0
  1212. ORDER BY pid, disporder
  1213. ");
  1214. }
  1215. while($forum = $db->fetch_array($query))
  1216. {
  1217. if($mybb->user['uid'] == 0)
  1218. {
  1219. if($forumsread[$forum['fid']])
  1220. {
  1221. $forum['lastread'] = $forumsread[$forum['fid']];
  1222. }
  1223. }
  1224. $readforums[$forum['fid']] = $forum['lastread'];
  1225. }
  1226. // Check participation by the current user in any of these threads - for 'dot' folder icons
  1227. if($mybb->settings['dotfolders'] != 0)
  1228. {
  1229. $query = $db->simple_select("posts", "tid,uid", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
  1230. while($post = $db->fetch_array($query))
  1231. {
  1232. $subscriptions[$post['tid']]['doticon'] = 1;
  1233. }
  1234. }
  1235. // Read threads
  1236. if($mybb->settings['threadreadcut'] > 0)
  1237. {
  1238. $query = $db->simple_select("threadsread", "*", "uid='{$mybb->user['uid']}' AND tid IN ({$tids})");
  1239. while($readthread = $db->fetch_array($query))
  1240. {
  1241. $subscriptions[$readthread['tid']]['lastread'] = $readthread['dateline'];
  1242. }
  1243. }
  1244. $icon_cache = $cache->read("posticons");
  1245. // Now we can build our subscription list
  1246. foreach($subscriptions as $thread)
  1247. {
  1248. $bgcolor = alt_trow();
  1249. $folder = '';
  1250. $prefix = '';
  1251. // If this thread has a prefix, insert a space between prefix and subject
  1252. if($thread['prefix'] != 0)
  1253. {
  1254. $thread['threadprefix'] .= '&nbsp;';
  1255. }
  1256. // Sanitize
  1257. $thread['subject'] = $parser->parse_badwords($thread['subject']);
  1258. $thread['subject'] = htmlspecialchars_uni($thread['subject']);
  1259. // Build our links
  1260. $thread['threadlink'] = get_thread_link($thread['tid']);
  1261. $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
  1262. // Fetch the thread icon if we have one
  1263. if($thread['icon'] > 0 && $icon_cache[$thread['icon']])
  1264. {
  1265. $icon = $icon_cache[$thread['icon']];
  1266. $icon['path'] = htmlspecialchars_uni($icon['path']);
  1267. $icon['name'] = htmlspecialchars_uni($icon['name']);
  1268. $icon = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" />";
  1269. }
  1270. else
  1271. {
  1272. $icon = "&nbsp;";
  1273. }
  1274. // Determine the folder
  1275. $folder = '';
  1276. $folder_label = '';
  1277. if($thread['doticon'])
  1278. {
  1279. $folder = "dot_";
  1280. $folder_label .= $lang->icon_dot;
  1281. }
  1282. $gotounread = '';
  1283. $isnew = 0;
  1284. $donenew = 0;
  1285. $lastread = 0;
  1286. if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'])
  1287. {
  1288. $forum_read = $readforums[$thread['fid']];
  1289. $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
  1290. if($forum_read == 0 || $forum_read < $read_cutoff)
  1291. {
  1292. $forum_read = $read_cutoff;
  1293. }
  1294. }
  1295. else
  1296. {
  1297. $forum_read = $forumsread[$thread['fid']];
  1298. }
  1299. if($mybb->settings['threadreadcut'] > 0 && $thread['lastpost'] > $forum_read)
  1300. {
  1301. $cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
  1302. }
  1303. if($thread['lastpost'] > $cutoff)
  1304. {
  1305. if($thread['lastread'])
  1306. {
  1307. $lastread = $thread['lastread'];
  1308. }
  1309. else
  1310. {
  1311. $lastread = 1;
  1312. }
  1313. }
  1314. if(!$lastread)
  1315. {
  1316. $readcookie = $threadread = my_get_array_cookie("threadread", $thread['tid']);
  1317. if($readcookie > $forum_read)
  1318. {
  1319. $lastread = $readcookie;
  1320. }
  1321. else
  1322. {
  1323. $lastread = $forum_read;
  1324. }
  1325. }
  1326. if($lastread && $lastread < $thread['lastpost'])
  1327. {
  1328. $folder .= "new";
  1329. $folder_label .= $lang->icon_new;
  1330. $new_class = "subject_new";
  1331. $thread['newpostlink'] = get_thread_link($thread['tid'], 0, "newpost");
  1332. eval("\$gotounread = \"".$templates->get("forumdisplay_thread_gotounread")."\";");
  1333. $unreadpost = 1;
  1334. }
  1335. else
  1336. {
  1337. $folder_label .= $lang->icon_no_new;
  1338. $new_class = "subject_old";
  1339. }
  1340. if($thread['replies'] >= $mybb->settings['hottopic'] || $thread['views'] >= $mybb->settings['hottopicviews'])
  1341. {
  1342. $folder .= "hot";
  1343. $folder_label .= $lang->icon_hot;
  1344. }
  1345. if($thread['closed'] == 1)
  1346. {
  1347. $folder .= "lock";
  1348. $folder_label .= $lang->icon_lock;
  1349. }
  1350. $folder .= "folder";
  1351. if($thread['visible'] == 0)
  1352. {
  1353. $bgcolor = "trow_shaded";
  1354. }
  1355. // Build last post info
  1356. $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
  1357. $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
  1358. $lastposter = $thread['lastposter'];
  1359. $lastposteruid = $thread['lastposteruid'];
  1360. // Don't link to guest's profiles (they have no profile).
  1361. if($lastposteruid == 0)
  1362. {
  1363. $lastposterlink = $lastposter;
  1364. }
  1365. else
  1366. {
  1367. $lastposterlink = build_profile_link($lastposter, $lastposteruid);
  1368. }
  1369. $thread['replies'] = my_number_format($thread['replies']);
  1370. $thread['views'] = my_number_format($thread['views']);
  1371. // What kind of notification type do we have here?
  1372. switch($thread['notification'])
  1373. {
  1374. case "1": // Instant
  1375. $notification_type = $lang->instant_notification;
  1376. break;
  1377. default: // No notification
  1378. $notification_type = $lang->no_notification;
  1379. }
  1380. eval("\$threads .= \"".$templates->get("usercp_subscriptions_thread")."\";");
  1381. }
  1382. // Provide remove options
  1383. eval("\$remove_options = \"".$templates->get("usercp_subscriptions_remove")."\";");
  1384. }
  1385. else
  1386. {
  1387. eval("\$threads = \"".$templates->get("usercp_subscriptions_none")."\";");
  1388. }
  1389. $plugins->run_hooks("usercp_subscriptions_end");
  1390. eval("\$subscriptions = \"".$templates->get("usercp_subscriptions")."\";");
  1391. output_page($subscriptions);
  1392. }
  1393. if($mybb->input['action'] == "forumsubscriptions")
  1394. {
  1395. $plugins->run_hooks("usercp_forumsubscriptions_start");
  1396. if($mybb->user['uid'] == 0)
  1397. {
  1398. // Build a forum cache.
  1399. $query = $db->query("
  1400. SELECT fid
  1401. FROM ".TABLE_PREFIX."forums
  1402. WHERE active != 0
  1403. ORDER BY pid, disporder
  1404. ");
  1405. $forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
  1406. }
  1407. else
  1408. {
  1409. // Build a forum cache.
  1410. $query = $db->query("
  1411. SELECT f.fid, fr.dateline AS lastread
  1412. FROM ".TABLE_PREFIX."forums f
  1413. LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
  1414. WHERE f.active != 0
  1415. ORDER BY pid, disporder
  1416. ");
  1417. }
  1418. while($forum = $db->fetch_array($query))
  1419. {
  1420. if($mybb->user['uid'] == 0)
  1421. {
  1422. if($forumsread[$forum['fid']])
  1423. {
  1424. $forum['lastread'] = $forumsread[$forum['fid']];
  1425. }
  1426. }
  1427. $readforums[$forum['fid']] = $forum['lastread'];
  1428. }
  1429. $fpermissions = forum_permissions();
  1430. require_once MYBB_ROOT."inc/functions_forumlist.php";
  1431. $query = $db->query("
  1432. SELECT fs.*, f.*, t.subject AS lastpostsubject, fr.dateline AS lastread
  1433. FROM ".TABLE_PREFIX."forumsubscriptions fs
  1434. LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid = fs.fid)
  1435. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid = f.lastposttid)
  1436. LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
  1437. WHERE f.type='f' AND fs.uid='".$mybb->user['uid']."'
  1438. ORDER BY f.name ASC
  1439. ");
  1440. $forums = '';
  1441. while($forum = $db->fetch_array($query))
  1442. {
  1443. $forum_url = get_forum_link($forum['fid']);
  1444. $forumpermissions = $fpermissions[$forum['fid']];
  1445. if($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0)
  1446. {
  1447. continue;
  1448. }
  1449. $lightbulb = get_forum_lightbulb(array('open' => $forum['open'], 'lastread' => $forum['lastread']), array('lastpost' => $forum['lastpost']));
  1450. $folder = $lightbulb['folder'];
  1451. if($forumpermissions['canonlyviewownthreads'] != 0)
  1452. {
  1453. $posts = '-';
  1454. $threads = '-';
  1455. }
  1456. else
  1457. {
  1458. $posts = my_number_format($forum['posts']);
  1459. $threads = my_number_format($forum['threads']);
  1460. }
  1461. if($forum['lastpost'] == 0 || $forum['lastposter'] == "")
  1462. {
  1463. $lastpost = "<div align=\"center\">{$lang->never}</div>";
  1464. }
  1465. // Hide last post
  1466. elseif($forumpermissions['canonlyviewownthreads'] != 0 && $forum['lastposteruid'] != $mybb->user['uid'])
  1467. {
  1468. $lastpost = "<div align=\"center\">{$lang->na}</div>";
  1469. }
  1470. else
  1471. {
  1472. $forum['lastpostsubject'] = $parser->parse_badwords($forum['lastpostsubject']);
  1473. $lastpost_date = my_date($mybb->settings['dateformat'], $forum['lastpost']);
  1474. $lastpost_time = my_date($mybb->settings['timeformat'], $forum['lastpost']);
  1475. $lastposttid = $forum['lastposttid'];
  1476. $lastposter = $forum['lastposter'];
  1477. $lastpost_profilelink = build_profile_link($lastposter, $forum['lastposteruid']);
  1478. $lastpost_subject = htmlspecialchars_uni($forum['lastpostsubject']);
  1479. if(my_strlen($lastpost_subject) > 25)
  1480. {
  1481. $lastpost_subject = my_substr($lastpost_subject, 0, 25) . "...";
  1482. }
  1483. $lastpost_link = get_thread_link($forum['lastposttid'], 0, "lastpost");
  1484. eval("\$lastpost = \"".$templates->get("forumbit_depth2_forum_lastpost")."\";");
  1485. }
  1486. if($mybb->settings['showdescriptions'] == 0)
  1487. {
  1488. $forum['description'] = "";
  1489. }
  1490. eval("\$forums .= \"".$templates->get("usercp_forumsubscriptions_forum")."\";");
  1491. }
  1492. if(!$forums)
  1493. {
  1494. eval("\$forums = \"".$templates->get("usercp_forumsubscriptions_none")."\";");
  1495. }
  1496. $plugins->run_hooks("usercp_forumsubscriptions_end");
  1497. eval("\$forumsubscriptions = \"".$templates->get("usercp_forumsubscriptions")."\";");
  1498. output_page($forumsubscriptions);
  1499. }
  1500. if($mybb->input['action'] == "do_editsig" && $mybb->request_method == "post")
  1501. {
  1502. // Verify incoming POST request
  1503. verify_post_check($mybb->input['my_post_key']);
  1504. $plugins->run_hooks("usercp_do_editsig_start");
  1505. // User currently has a suspended signature
  1506. if($mybb->user['suspendsignature'] == 1 && $mybb->user['suspendsigtime'] > TIME_NOW)
  1507. {
  1508. error_no_permission();
  1509. }
  1510. if($mybb->input['updateposts'] == "enable")
  1511. {
  1512. $update_signature = array(
  1513. "includesig" => 1
  1514. );
  1515. $db->update_query("posts", $update_signature, "uid='".$mybb->user['uid']."'");
  1516. }
  1517. elseif($mybb->input['updateposts'] == "disable")
  1518. {
  1519. $update_signature = array(
  1520. "includesig" => 0
  1521. );
  1522. $db->update_query("posts", $update_signature, "uid='".$mybb->user['uid']."'");
  1523. }
  1524. $new_signature = array(
  1525. "signature" => $db->escape_string($mybb->input['signature'])
  1526. );
  1527. $plugins->run_hooks("usercp_do_editsig_process");
  1528. $db->update_query("users", $new_signature, "uid='".$mybb->user['uid']."'");
  1529. $plugins->run_hooks("usercp_do_editsig_end");
  1530. redirect("usercp.php?action=editsig", $lang->redirect_sigupdated);
  1531. }
  1532. if($mybb->input['action'] == "editsig")
  1533. {
  1534. $plugins->run_hooks("usercp_editsig_start");
  1535. if($mybb->input['preview'] && !$error)
  1536. {
  1537. $sig = $mybb->input['signature'];
  1538. $template = "usercp_editsig_preview";
  1539. }
  1540. elseif(!$error)
  1541. {
  1542. $sig = $mybb->user['signature'];
  1543. $template = "usercp_editsig_current";
  1544. }
  1545. else if($error)
  1546. {
  1547. $sig = $mybb->input['signature'];
  1548. $template = false;
  1549. }
  1550. if($mybb->user['suspendsignature'] && ($mybb->user['suspendsigtime'] == 0 || $mybb->user['suspendsigtime'] > 0 && $mybb->user['suspendsigtime'] > TIME_NOW))
  1551. {
  1552. // User currently has no signature and they're suspended
  1553. error($lang->sig_suspended);
  1554. }
  1555. if($mybb->usergroup['canusesig'] != 1)
  1556. {
  1557. // Usergroup has no permission to use this facility
  1558. error_no_permission();
  1559. }
  1560. else if($mybb->usergroup['canusesig'] == 1 && $mybb->usergroup['canusesigxposts'] > 0 && $mybb->user['postnum'] < $mybb->usergroup['canusesigxposts'])
  1561. {
  1562. // Usergroup can use this facility, but only after x posts
  1563. error($lang->sprintf($lang->sig_suspended_posts, $mybb->usergroup['canusesigxposts']));
  1564. }
  1565. if($sig && $template)
  1566. {
  1567. $sig_parser = array(
  1568. "allow_html" => $mybb->settings['sightml'],
  1569. "allow_mycode" => $mybb->settings['sigmycode'],
  1570. "allow_smilies" => $mybb->settings['sigsmilies'],
  1571. "allow_imgcode" => $mybb->settings['sigimgcode'],
  1572. "me_username" => $mybb->user['username'],
  1573. "filter_badwords" => 1
  1574. );
  1575. $sigpreview = $parser->parse_message($sig, $sig_parser);
  1576. eval("\$signature = \"".$templates->get($template)."\";");
  1577. }
  1578. // User has a current signature, so let's display it (but show an error message)
  1579. if($mybb->user['suspendsignature'] && $mybb->user['suspendsigtime'] > TIME_NOW)
  1580. {
  1581. $plugins->run_hooks("usercp_editsig_end");
  1582. // User either doesn't have permission, or has their signature suspended
  1583. eval("\$editsig = \"".$templates->get("usercp_editsig_suspended")."\";");
  1584. }
  1585. else
  1586. {
  1587. // User is allowed to edit their signature
  1588. if($mybb->settings['sigsmilies'] == 1)
  1589. {
  1590. $sigsmilies = $lang->on;
  1591. $smilieinserter = build_clickable_smilies();
  1592. }
  1593. else
  1594. {
  1595. $sigsmilies = $lang->off;
  1596. }
  1597. if($mybb->settings['sigmycode'] == 1)
  1598. {
  1599. $sigmycode = $lang->on;
  1600. }
  1601. else
  1602. {
  1603. $sigmycode = $lang->off;
  1604. }
  1605. if($mybb->settings['sightml'] == 1)
  1606. {
  1607. $sightml = $lang->on;
  1608. }
  1609. else
  1610. {
  1611. $sightml = $lang->off;
  1612. }
  1613. if($mybb->settings['sigimgcode'] == 1)
  1614. {
  1615. $sigimgcode = $lang->on;
  1616. }
  1617. else
  1618. {
  1619. $sigimgcode = $lang->off;
  1620. }
  1621. $sig = htmlspecialchars_uni($sig);
  1622. $lang->edit_sig_note2 = $lang->sprintf($lang->edit_sig_note2, $sigsmilies, $sigmycode, $sigimgcode, $sightml, $mybb->settings['siglength']);
  1623. if($mybb->settings['bbcodeinserter'] != 0 || $mybb->user['showcodebuttons'] != 0)
  1624. {
  1625. $codebuttons = build_mycode_inserter("signature");
  1626. }
  1627. $plugins->run_hooks("usercp_editsig_end");
  1628. eval("\$editsig = \"".$templates->get("usercp_editsig")."\";");
  1629. }
  1630. output_page($editsig);
  1631. }
  1632. if($mybb->input['action'] == "do_avatar" && $mybb->request_method == "post")
  1633. {
  1634. // Verify incoming POST request
  1635. verify_post_check($mybb->input['my_post_key']);
  1636. $plugins->run_hooks("usercp_do_avatar_start");
  1637. require_once MYBB_ROOT."inc/functions_upload.php";
  1638. $avatar_error = "";
  1639. if($mybb->input['remove']) // remove avatar
  1640. {
  1641. $updated_avatar = array(
  1642. "avatar" => "",
  1643. "avatardimensions" => "",
  1644. "avatartype" => ""
  1645. );
  1646. $db->update_query("users", $updated_avatar, "uid='".$mybb->user['uid']."'");
  1647. remove_avatars($mybb->user['uid']);
  1648. }
  1649. elseif($mybb->input['gallery']) // Gallery avatar
  1650. {
  1651. if(empty($mybb->input['avatar']))
  1652. {
  1653. $avatar_error = $lang->error_noavatar;
  1654. }
  1655. $mybb->input['gallery'] = str_replace(array("./", ".."), "", $mybb->input['gallery']);
  1656. $mybb->input['avatar'] = str_replace(array("./", ".."), "", $mybb->input['avatar']);
  1657. if(empty($avatar_error))
  1658. {
  1659. if($mybb->input['gallery'] == "default")
  1660. {
  1661. $avatarpath = $db->escape_string($mybb->settings['avatardir']."/".$mybb->input['avatar']);
  1662. }
  1663. else
  1664. {
  1665. $avatarpath = $db->escape_string($mybb->settings['avatardir']."/".$mybb->input['gallery']."/".$mybb->input['avatar']);
  1666. }
  1667. if(file_exists($avatarpath))
  1668. {
  1669. $dimensions = @getimagesize($avatarpath);
  1670. $updated_avatar = array(
  1671. "avatar" => $avatarpath.'?dateline='.TIME_NOW,
  1672. "avatardimensions" => "{$dimensions[0]}|{$dimensions[1]}",
  1673. "avatartype" => "gallery"
  1674. );
  1675. $db->update_query("users", $updated_avatar, "uid='".$mybb->user['uid']."'");
  1676. }
  1677. remove_avatars($mybb->user['uid']);
  1678. }
  1679. }
  1680. elseif($_FILES['avatarupload']['name']) // upload avatar
  1681. {
  1682. if($mybb->usergroup['canuploadavatars'] == 0)
  1683. {
  1684. error_no