Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

take_edit.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <?
  2. authorize();
  3. $UserID = $_REQUEST['userid'];
  4. if (!is_number($UserID)) {
  5. error(404);
  6. }
  7. //For this entire page, we should generally be using $UserID not $LoggedUser['ID'] and $U[] not $LoggedUser[]
  8. $U = Users::user_info($UserID);
  9. if (!$U) {
  10. error(404);
  11. }
  12. $Permissions = Permissions::get_permissions($U['PermissionID']);
  13. if ($UserID != $LoggedUser['ID'] && !check_perms('users_edit_profiles', $Permissions['Class'])) {
  14. send_irc('PRIVMSG '.ADMIN_CHAN.' :User '.$LoggedUser['Username'].' ('.site_url().'user.php?id='.$LoggedUser['ID'].') just tried to edit the profile of '.site_url().'user.php?id='.$_REQUEST['userid']);
  15. error(403);
  16. }
  17. $Val->SetFields('stylesheet', 1, "number", "You forgot to select a stylesheet.");
  18. $Val->SetFields('styleurl', 0, "regex", "You did not enter a valid stylesheet URL.", array('regex' => '/^'.CSS_REGEX.'$/i'));
  19. // The next two are commented out because the drop-down menus were replaced with a check box and radio buttons
  20. //$Val->SetFields('disablegrouping', 0, "number", "You forgot to select your torrent grouping option.");
  21. //$Val->SetFields('torrentgrouping', 0, "number", "You forgot to select your torrent grouping option.");
  22. $Val->SetFields('postsperpage', 1, "number", "You forgot to select your posts per page option.", array('inarray' => array(25, 50, 100)));
  23. //$Val->SetFields('hidecollage', 1, "number", "You forgot to select your collage option.", array('minlength' => 0, 'maxlength' => 1));
  24. $Val->SetFields('collagecovers', 1, "number", "You forgot to select your collage option.");
  25. $Val->SetFields('avatar', 0, "regex", "You did not enter a valid avatar URL.", array('regex' => "/^".IMAGE_REGEX."$/i"));
  26. $Val->SetFields('email', 1, "email", "You did not enter a valid email address.");
  27. $Val->SetFields('irckey', 0, "string", "You did not enter a valid IRC key. An IRC key must be between 6 and 32 characters long.", array('minlength' => 6, 'maxlength' => 32));
  28. $Val->SetFields('new_pass_1', 0, "regex", "You did not enter a valid password. A valid password is 6 characters or longer.", array('regex' => '/(?=^.{6,}$).*$/'));
  29. $Val->SetFields('new_pass_2', 1, "compare", "Your passwords do not match.", array('comparefield' => 'new_pass_1'));
  30. if (check_perms('site_advanced_search')) {
  31. $Val->SetFields('searchtype', 1, "number", "You forgot to select your default search preference.", array('minlength' => 0, 'maxlength' => 1));
  32. }
  33. $Err = $Val->ValidateForm($_POST);
  34. if (!apc_exists('DBKEY')) {
  35. $Err = "Cannot edit profile until database fully decrypted.";
  36. }
  37. if ($Err) {
  38. error($Err);
  39. header("Location: user.php?action=edit&userid=$UserID");
  40. die();
  41. }
  42. // Begin building $Paranoia
  43. // Reduce the user's input paranoia until it becomes consistent
  44. if (isset($_POST['p_uniquegroups_l'])) {
  45. $_POST['p_uploads_l'] = 'on';
  46. $_POST['p_uploads_c'] = 'on';
  47. }
  48. if (isset($_POST['p_uploads_l'])) {
  49. $_POST['p_uniquegroups_l'] = 'on';
  50. $_POST['p_uniquegroups_c'] = 'on';
  51. $_POST['p_perfectflacs_l'] = 'on';
  52. $_POST['p_perfectflacs_c'] = 'on';
  53. $_POST['p_artistsadded'] = 'on';
  54. }
  55. if (isset($_POST['p_collagecontribs_l'])) {
  56. $_POST['p_collages_l'] = 'on';
  57. $_POST['p_collages_c'] = 'on';
  58. }
  59. if (isset($_POST['p_snatched_c']) && isset($_POST['p_seeding_c']) && isset($_POST['p_downloaded'])) {
  60. $_POST['p_requiredratio'] = 'on';
  61. }
  62. // if showing exactly 2 of stats, show all 3 of stats
  63. $StatsShown = 0;
  64. $Stats = array('downloaded', 'uploaded', 'ratio');
  65. foreach ($Stats as $S) {
  66. if (isset($_POST["p_$S"])) {
  67. $StatsShown++;
  68. }
  69. }
  70. if ($StatsShown == 2) {
  71. foreach ($Stats as $S) {
  72. $_POST["p_$S"] = 'on';
  73. }
  74. }
  75. $Paranoia = array();
  76. $Checkboxes = array('downloaded', 'uploaded', 'ratio', 'lastseen', 'requiredratio', 'invitedcount', 'artistsadded', 'notifications');
  77. foreach ($Checkboxes as $C) {
  78. if (!isset($_POST["p_$C"])) {
  79. $Paranoia[] = $C;
  80. }
  81. }
  82. $SimpleSelects = array('torrentcomments', 'collages', 'collagecontribs', 'uploads', 'uniquegroups', 'perfectflacs', 'seeding', 'leeching', 'snatched');
  83. foreach ($SimpleSelects as $S) {
  84. if (!isset($_POST["p_$S".'_c']) && !isset($_POST["p_$S".'_l'])) {
  85. // Very paranoid - don't show count or list
  86. $Paranoia[] = "$S+";
  87. } elseif (!isset($_POST["p_$S".'_l'])) {
  88. // A little paranoid - show count, don't show list
  89. $Paranoia[] = $S;
  90. }
  91. }
  92. $Bounties = array('requestsfilled', 'requestsvoted');
  93. foreach ($Bounties as $B) {
  94. if (isset($_POST["p_$B".'_list'])) {
  95. $_POST["p_$B".'_count'] = 'on';
  96. $_POST["p_$B".'_bounty'] = 'on';
  97. }
  98. if (!isset($_POST["p_$B".'_list'])) {
  99. $Paranoia[] = $B.'_list';
  100. }
  101. if (!isset($_POST["p_$B".'_count'])) {
  102. $Paranoia[] = $B.'_count';
  103. }
  104. if (!isset($_POST["p_$B".'_bounty'])) {
  105. $Paranoia[] = $B.'_bounty';
  106. }
  107. }
  108. if (!isset($_POST['p_donor_heart'])) {
  109. $Paranoia[] = 'hide_donor_heart';
  110. }
  111. if (isset($_POST['p_donor_stats'])) {
  112. Donations::show_stats($UserID);
  113. } else {
  114. Donations::hide_stats($UserID);
  115. }
  116. // End building $Paranoia
  117. // Email change
  118. $DB->query("
  119. SELECT Email
  120. FROM users_main
  121. WHERE ID = $UserID");
  122. list($CurEmail) = $DB->next_record();
  123. $CurEmail = DBCrypt::decrypt($CurEmail);
  124. if ($CurEmail != $_POST['email']) {
  125. if (!check_perms('users_edit_profiles')) { // Non-admins have to authenticate to change email
  126. $DB->query("
  127. SELECT PassHash
  128. FROM users_main
  129. WHERE ID = '".db_string($UserID)."'");
  130. list($PassHash)=$DB->next_record();
  131. if (!Users::check_password($_POST['cur_pass'], $PassHash)) {
  132. $Err = 'You did not enter the correct password.';
  133. }
  134. }
  135. if (!$Err) {
  136. $NewEmail = db_string($_POST['email']);
  137. //This piece of code will update the time of their last email change to the current time *not* the current change.
  138. $ChangerIP = db_string($LoggedUser['IP']);
  139. $DB->query("
  140. UPDATE users_history_emails
  141. SET Time = '".sqltime()."'
  142. WHERE UserID = '$UserID'
  143. AND Time IS NULL");
  144. $DB->query("
  145. INSERT INTO users_history_emails
  146. (UserID, Email, Time, IP)
  147. VALUES
  148. ('$UserID', '".DBCrypt::encrypt($NewEmail)."', NULL, '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."')");
  149. } else {
  150. error($Err);
  151. header("Location: user.php?action=edit&userid=$UserID");
  152. die();
  153. }
  154. }
  155. //End email change
  156. if (!$Err && ($_POST['cur_pass'] || $_POST['new_pass_1'] || $_POST['new_pass_2'])) {
  157. $DB->query("
  158. SELECT PassHash
  159. FROM users_main
  160. WHERE ID = '".db_string($UserID)."'");
  161. list($PassHash) = $DB->next_record();
  162. if (Users::check_password($_POST['cur_pass'], $PassHash)) {
  163. if ($_POST['new_pass_1'] && $_POST['new_pass_2']) {
  164. $ResetPassword = true;
  165. }
  166. } else {
  167. $Err = 'You did not enter the correct password.';
  168. }
  169. }
  170. if ($LoggedUser['DisableAvatar'] && $_POST['avatar'] != $U['Avatar']) {
  171. $Err = 'Your avatar privileges have been revoked.';
  172. }
  173. if ($Err) {
  174. error($Err);
  175. header("Location: user.php?action=edit&userid=$UserID");
  176. die();
  177. }
  178. if (!empty($LoggedUser['DefaultSearch'])) {
  179. $Options['DefaultSearch'] = $LoggedUser['DefaultSearch'];
  180. }
  181. $Options['DisableGrouping2'] = (!empty($_POST['disablegrouping']) ? 0 : 1);
  182. $Options['TorrentGrouping'] = (!empty($_POST['torrentgrouping']) ? 1 : 0);
  183. $Options['PostsPerPage'] = (int)$_POST['postsperpage'];
  184. $Options['CollageCovers'] = (empty($_POST['collagecovers']) ? 0 : $_POST['collagecovers']);
  185. $Options['ShowTorFilter'] = (empty($_POST['showtfilter']) ? 0 : 1);
  186. $Options['ShowTags'] = (!empty($_POST['showtags']) ? 1 : 0);
  187. $Options['AutoSubscribe'] = (!empty($_POST['autosubscribe']) ? 1 : 0);
  188. $Options['DisableSmileys'] = (!empty($_POST['disablesmileys']) ? 1 : 0);
  189. $Options['AutoloadCommStats'] = (check_perms('users_mod') && !empty($_POST['autoload_comm_stats']) ? 1 : 0);
  190. $Options['DisableAvatars'] = db_string($_POST['disableavatars']);
  191. $Options['Identicons'] = (!empty($_POST['identicons']) ? (int)$_POST['identicons'] : 0);
  192. $Options['DisablePMAvatars'] = (!empty($_POST['disablepmavatars']) ? 1 : 0);
  193. $Options['NotifyOnQuote'] = (!empty($_POST['notifications_Quotes_popup']) ? 1 : 0);
  194. $Options['ListUnreadPMsFirst'] = (!empty($_POST['list_unread_pms_first']) ? 1 : 0);
  195. $Options['ShowSnatched'] = (!empty($_POST['showsnatched']) ? 1 : 0);
  196. $Options['DisableAutoSave'] = (!empty($_POST['disableautosave']) ? 1 : 0);
  197. $Options['NoVoteLinks'] = (!empty($_POST['novotelinks']) ? 1 : 0);
  198. $Options['CoverArt'] = (int)!empty($_POST['coverart']);
  199. $Options['ShowExtraCovers'] = (int)!empty($_POST['show_extra_covers']);
  200. $Options['HideLolicon'] = (int)!empty($_POST['hide_lolicon']);
  201. $Options['HideScat'] = (int)!empty($_POST['hide_scat']);
  202. $Options['HideSnuff'] = (int)!empty($_POST['hide_snuff']);
  203. $Options['AutoComplete'] = (int)$_POST['autocomplete'];
  204. $Options['StyleAdditions'] = $_POST['style_additions'] ?? [];
  205. if (isset($LoggedUser['DisableFreeTorrentTop10'])) {
  206. $Options['DisableFreeTorrentTop10'] = $LoggedUser['DisableFreeTorrentTop10'];
  207. }
  208. if (!empty($_POST['sorthide'])) {
  209. $JSON = json_decode($_POST['sorthide']);
  210. foreach ($JSON as $J) {
  211. $E = explode('_', $J);
  212. $Options['SortHide'][$E[0]] = $E[1];
  213. }
  214. } else {
  215. $Options['SortHide'] = array();
  216. }
  217. if (check_perms('site_advanced_search')) {
  218. $Options['SearchType'] = $_POST['searchtype'];
  219. } else {
  220. unset($Options['SearchType']);
  221. }
  222. //TODO: Remove the following after a significant amount of time
  223. unset($Options['ArtistNoRedirect']);
  224. unset($Options['ShowQueryList']);
  225. unset($Options['ShowCacheList']);
  226. $DownloadAlt = isset($_POST['downloadalt']) ? 1 : 0;
  227. $UnseededAlerts = isset($_POST['unseededalerts']) ? 1 : 0;
  228. Donations::update_rewards($UserID);
  229. NotificationsManager::save_settings($UserID);
  230. // Begin Badge settings
  231. if (!empty($_POST['badges'])) {
  232. $BadgeIDs = array_slice($_POST['badges'], 0, 5);
  233. } else {
  234. $BadgeIDs = array();
  235. }
  236. $BadgesChanged = false;
  237. $NewBadges = array();
  238. if ($Cache->get_value('user_badges_'.$UserID)) {
  239. $Badges = $Cache->get_value('user_badges_'.$UserID);
  240. foreach ($Badges as $Badge) {
  241. if (in_array($Badge['BadgeID'], $BadgeIDs)) { // Is the current badge in the list of badges the user wants to display?
  242. $Displayed = true;
  243. $DisplayedBadgeIDs[] = $Badge['BadgeID'];
  244. if ($Badge['Displayed'] == 0) { // The user wants to display a badge that wasn't displayed before
  245. $BadgesChanged = true;
  246. }
  247. } else { // The user no longer wants to display a badge that was displayed before
  248. $Displayed = false;
  249. $BadgesChanged = true;
  250. }
  251. $NewBadges[] = array('BadgeID' => $Badge['BadgeID'], 'Displayed' => $Displayed?'1':'0');
  252. }
  253. } else {
  254. $BadgesChanged = true;
  255. }
  256. if ($BadgesChanged) {
  257. $Cache->cache_value('user_badges_'.$UserID, $NewBadges);
  258. }
  259. // End Badge settings
  260. // Information on how the user likes to download torrents is stored in cache
  261. if ($DownloadAlt != $LoggedUser['DownloadAlt']) {
  262. $Cache->delete_value('user_'.$LoggedUser['torrent_pass']);
  263. }
  264. $Cache->begin_transaction("user_info_$UserID");
  265. $Cache->update_row(false, array(
  266. 'Avatar' => display_str($_POST['avatar']),
  267. 'Paranoia' => $Paranoia
  268. ));
  269. $Cache->commit_transaction(0);
  270. $Cache->begin_transaction("user_info_heavy_$UserID");
  271. $Cache->update_row(false, array(
  272. 'StyleID' => $_POST['stylesheet'],
  273. 'StyleURL' => display_str($_POST['styleurl']),
  274. 'DownloadAlt' => $DownloadAlt
  275. ));
  276. $Cache->update_row(false, $Options);
  277. $Cache->commit_transaction(0);
  278. $SQL = "
  279. UPDATE users_main AS m
  280. JOIN users_info AS i ON m.ID = i.UserID
  281. SET
  282. i.StyleID = '".db_string($_POST['stylesheet'])."',
  283. i.StyleURL = '".db_string($_POST['styleurl'])."',
  284. i.Avatar = '".db_string($_POST['avatar'])."',
  285. i.SiteOptions = '".db_string(serialize($Options))."',
  286. i.NotifyOnQuote = '".db_string($Options['NotifyOnQuote'])."',
  287. i.Info = '".db_string($_POST['info'])."',
  288. i.InfoTitle = '".db_string($_POST['profile_title'])."',
  289. i.DownloadAlt = '$DownloadAlt',
  290. i.UnseededAlerts = '$UnseededAlerts',
  291. m.Email = '".DBCrypt::encrypt($_POST['email'])."',
  292. m.IRCKey = '".db_string($_POST['irckey'])."',
  293. m.Paranoia = '".db_string(serialize($Paranoia))."'";
  294. if ($ResetPassword) {
  295. $ChangerIP = db_string(DBCrypt::encrypt($LoggedUser['IP']));
  296. $PassHash = Users::make_sec_hash($_POST['new_pass_1']);
  297. $SQL.= ",m.PassHash = '".db_string($PassHash)."'";
  298. $DB->query("
  299. INSERT INTO users_history_passwords
  300. (UserID, ChangerIP, ChangeTime)
  301. VALUES
  302. ('$UserID', '$ChangerIP', '".sqltime()."')");
  303. }
  304. if (isset($_POST['resetpasskey'])) {
  305. $UserInfo = Users::user_heavy_info($UserID);
  306. $OldPassKey = db_string($UserInfo['torrent_pass']);
  307. $NewPassKey = db_string(Users::make_secret());
  308. $ChangerIP = db_string(DBCrypt::encrypt($LoggedUser['IP']));
  309. $SQL .= ",m.torrent_pass = '$NewPassKey'";
  310. $DB->query("
  311. INSERT INTO users_history_passkeys
  312. (UserID, OldPassKey, NewPassKey, ChangerIP, ChangeTime)
  313. VALUES
  314. ('$UserID', '$OldPassKey', '$NewPassKey', '$ChangerIP', '".sqltime()."')");
  315. $Cache->begin_transaction("user_info_heavy_$UserID");
  316. $Cache->update_row(false, array('torrent_pass' => $NewPassKey));
  317. $Cache->commit_transaction(0);
  318. $Cache->delete_value("user_$OldPassKey");
  319. Tracker::update_tracker('change_passkey', array('oldpasskey' => $OldPassKey, 'newpasskey' => $NewPassKey));
  320. }
  321. $SQL .= "WHERE m.ID = '".db_string($UserID)."'";
  322. $DB->query($SQL);
  323. if ($BadgesChanged) {
  324. $DB->query("
  325. UPDATE users_badges
  326. SET Displayed = 0
  327. WHERE UserID = $UserID");
  328. if (!empty($BadgeIDs)) {
  329. $DB->query("
  330. UPDATE users_badges
  331. SET Displayed = 1
  332. WHERE UserID = $UserID
  333. AND BadgeID IN (".db_string(implode(',', $BadgeIDs)).")");
  334. }
  335. }
  336. if ($ResetPassword) {
  337. logout_all_sessions();
  338. }
  339. header("Location: user.php?action=edit&userid=$UserID");
  340. ?>