BioTorrents.de’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.

user.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <?php
  2. #declare(strict_types=1);
  3. if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
  4. json_die('failure', 'bad id parameter');
  5. }
  6. $UserID = $_GET['id'];
  7. if ($UserID === $LoggedUser['ID']) {
  8. $OwnProfile = true;
  9. } else {
  10. $OwnProfile = false;
  11. }
  12. // Always view as a normal user
  13. $DB->query("
  14. SELECT
  15. m.`Username`,
  16. m.`Email`,
  17. m.`LastAccess`,
  18. m.`IP`,
  19. p.`Level` AS Class,
  20. m.`Uploaded`,
  21. m.`Downloaded`,
  22. m.`RequiredRatio`,
  23. m.`Enabled`,
  24. m.`Paranoia`,
  25. m.`Invites`,
  26. m.`Title`,
  27. m.`torrent_pass`,
  28. m.`can_leech`,
  29. i.`JoinDate`,
  30. i.`Info`,
  31. i.`Avatar`,
  32. i.`Donor`,
  33. i.`Warned`,
  34. COUNT(posts.`id`) AS ForumPosts,
  35. i.`Inviter`,
  36. i.`DisableInvites`,
  37. inviter.`username`
  38. FROM
  39. `users_main` AS m
  40. JOIN `users_info` AS i
  41. ON
  42. i.`UserID` = m.`ID`
  43. LEFT JOIN `permissions` AS p
  44. ON
  45. p.`ID` = m.`PermissionID`
  46. LEFT JOIN `users_main` AS inviter
  47. ON
  48. i.`Inviter` = inviter.`ID`
  49. LEFT JOIN `forums_posts` AS posts
  50. ON
  51. posts.`AuthorID` = m.`ID`
  52. WHERE
  53. m.`ID` = $UserID
  54. GROUP BY
  55. `AuthorID`
  56. ");
  57. // If user doesn't exist
  58. if (!$DB->has_results()) {
  59. json_die('failure', 'no such user');
  60. }
  61. list($Username, $Email, $LastAccess, $IP, $Class, $Uploaded, $Downloaded, $RequiredRatio, $Enabled, $Paranoia, $Invites, $CustomTitle, $torrent_pass, $DisableLeech, $JoinDate, $Info, $Avatar, $Donor, $Warned, $ForumPosts, $InviterID, $DisableInvites, $InviterName) = $DB->next_record(MYSQLI_NUM, array(9, 11));
  62. $Paranoia = unserialize($Paranoia);
  63. if (!is_array($Paranoia)) {
  64. $Paranoia = [];
  65. }
  66. $ParanoiaLevel = 0;
  67. foreach ($Paranoia as $P) {
  68. $ParanoiaLevel++;
  69. if (strpos($P, '+') !== false) {
  70. $ParanoiaLevel++;
  71. }
  72. }
  73. // Raw time is better for JSON
  74. //$JoinedDate = time_diff($JoinDate);
  75. //$LastAccess = time_diff($LastAccess);
  76. function check_paranoia_here($Setting)
  77. {
  78. global $Paranoia, $Class, $UserID;
  79. return check_paranoia($Setting, $Paranoia, $Class, $UserID);
  80. }
  81. $Friend = false;
  82. $DB->query("
  83. SELECT
  84. `FriendID`
  85. FROM
  86. `friends`
  87. WHERE
  88. `UserID` = '$LoggedUser[ID]'
  89. AND `FriendID` = '$UserID'
  90. ");
  91. if ($DB->has_results()) {
  92. $Friend = true;
  93. }
  94. if (check_paranoia_here('requestsfilled_count') || check_paranoia_here('requestsfilled_bounty')) {
  95. $DB->query("
  96. SELECT
  97. COUNT(DISTINCT r.`ID`),
  98. SUM(rv.`Bounty`)
  99. FROM
  100. `requests` AS r
  101. LEFT JOIN `requests_votes` AS rv
  102. ON
  103. r.`ID` = rv.`RequestID`
  104. WHERE
  105. r.`FillerID` = $UserID
  106. ");
  107. list($RequestsFilled, $TotalBounty) = $DB->next_record();
  108. $DB->query("
  109. SELECT
  110. COUNT(`RequestID`),
  111. SUM(`Bounty`)
  112. FROM
  113. `requests_votes`
  114. WHERE
  115. `UserID` = $UserID
  116. ");
  117. list($RequestsVoted, $TotalSpent) = $DB->next_record();
  118. $DB->query("
  119. SELECT
  120. COUNT(`ID`)
  121. FROM
  122. `torrents`
  123. WHERE
  124. `UserID` = '$UserID'
  125. ");
  126. list($Uploads) = $DB->next_record();
  127. } else {
  128. $RequestsFilled = null;
  129. $TotalBounty = null;
  130. $RequestsVoted = 0;
  131. $TotalSpent = 0;
  132. }
  133. if (check_paranoia_here('uploads+')) {
  134. $DB->query("
  135. SELECT
  136. COUNT(`ID`)
  137. FROM
  138. `torrents`
  139. WHERE
  140. `UserID` = '$UserID'
  141. ");
  142. list($Uploads) = $DB->next_record();
  143. } else {
  144. $Uploads = null;
  145. }
  146. if (check_paranoia_here('artistsadded')) {
  147. $DB->query("
  148. SELECT
  149. COUNT(`ArtistID`)
  150. FROM
  151. `torrents_artists`
  152. WHERE
  153. `UserID` = $UserID
  154. ");
  155. list($ArtistsAdded) = $DB->next_record();
  156. } else {
  157. $ArtistsAdded = null;
  158. }
  159. // Do the ranks
  160. if (check_paranoia_here('uploaded')) {
  161. $UploadedRank = UserRank::get_rank('uploaded', $Uploaded);
  162. } else {
  163. $UploadedRank = null;
  164. }
  165. if (check_paranoia_here('downloaded')) {
  166. $DownloadedRank = UserRank::get_rank('downloaded', $Downloaded);
  167. } else {
  168. $DownloadedRank = null;
  169. }
  170. if (check_paranoia_here('uploads+')) {
  171. $UploadsRank = UserRank::get_rank('uploads', $Uploads);
  172. } else {
  173. $UploadsRank = null;
  174. }
  175. if (check_paranoia_here('requestsfilled_count')) {
  176. $RequestRank = UserRank::get_rank('requests', $RequestsFilled);
  177. } else {
  178. $RequestRank = null;
  179. }
  180. $PostRank = UserRank::get_rank('posts', $ForumPosts);
  181. if (check_paranoia_here('requestsvoted_bounty')) {
  182. $BountyRank = UserRank::get_rank('bounty', $TotalSpent);
  183. } else {
  184. $BountyRank = null;
  185. }
  186. if (check_paranoia_here('artistsadded')) {
  187. $ArtistsRank = UserRank::get_rank('artists', $ArtistsAdded);
  188. } else {
  189. $ArtistsRank = null;
  190. }
  191. if ($Downloaded === 0) {
  192. $Ratio = 1;
  193. } elseif ($Uploaded === 0) {
  194. $Ratio = 0.5;
  195. } else {
  196. $Ratio = round($Uploaded / $Downloaded, 2);
  197. }
  198. if (check_paranoia_here(array('uploaded', 'downloaded', 'uploads+', 'requestsfilled_count', 'requestsvoted_bounty', 'artistsadded'))) {
  199. $OverallRank = floor(UserRank::overall_score($UploadedRank, $DownloadedRank, $UploadsRank, $RequestRank, $PostRank, $BountyRank, $ArtistsRank, $Ratio));
  200. } else {
  201. $OverallRank = null;
  202. }
  203. // Community section
  204. if (check_paranoia_here('snatched+')) {
  205. $DB->query("
  206. SELECT
  207. COUNT(x.`uid`),
  208. COUNT(DISTINCT x.`fid`)
  209. FROM
  210. `xbt_snatched` AS x
  211. INNER JOIN `torrents` AS t
  212. ON
  213. t.`ID` = x.`fid`
  214. WHERE
  215. x.`uid` = '$UserID'
  216. ");
  217. list($Snatched, $UniqueSnatched) = $DB->next_record();
  218. }
  219. if (check_paranoia_here('torrentcomments+')) {
  220. $DB->query("
  221. SELECT
  222. COUNT(`ID`)
  223. FROM
  224. `comments`
  225. WHERE
  226. `Page` = 'torrents'
  227. AND `AuthorID` = '$UserID'
  228. ");
  229. list($NumComments) = $DB->next_record();
  230. }
  231. if (check_paranoia_here('torrentcomments+')) {
  232. $DB->query("
  233. SELECT
  234. COUNT(`ID`)
  235. FROM
  236. `comments`
  237. WHERE
  238. `Page` = 'artist'
  239. AND `AuthorID` = '$UserID'
  240. ");
  241. list($NumArtistComments) = $DB->next_record();
  242. }
  243. if (check_paranoia_here('torrentcomments+')) {
  244. $DB->query("
  245. SELECT
  246. COUNT(`ID`)
  247. FROM
  248. `comments`
  249. WHERE
  250. `Page` = 'collages'
  251. AND `AuthorID` = '$UserID'
  252. ");
  253. list($NumCollageComments) = $DB->next_record();
  254. }
  255. if (check_paranoia_here('torrentcomments+')) {
  256. $DB->query("
  257. SELECT
  258. COUNT(`ID`)
  259. FROM
  260. `comments`
  261. WHERE
  262. `Page` = 'requests'
  263. AND `AuthorID` = '$UserID'
  264. ");
  265. list($NumRequestComments) = $DB->next_record();
  266. }
  267. if (check_paranoia_here('collages+')) {
  268. $DB->query("
  269. SELECT
  270. COUNT(`ID`)
  271. FROM
  272. `collages`
  273. WHERE
  274. `Deleted` = '0'
  275. AND `UserID` = '$UserID'
  276. ");
  277. list($NumCollages) = $DB->next_record();
  278. }
  279. if (check_paranoia_here('collagecontribs+')) {
  280. $DB->query("
  281. SELECT
  282. COUNT(DISTINCT ct.`CollageID`)
  283. FROM
  284. `collages_torrents` AS ct
  285. JOIN `collages` AS c
  286. ON
  287. ct.`CollageID` = c.`ID`
  288. WHERE
  289. c.`Deleted` = '0'
  290. AND ct.`UserID` = '$UserID'
  291. ");
  292. list($NumCollageContribs) = $DB->next_record();
  293. }
  294. if (check_paranoia_here('uniquegroups+')) {
  295. $DB->query("
  296. SELECT
  297. COUNT(DISTINCT `GroupID`)
  298. FROM
  299. `torrents`
  300. WHERE
  301. `UserID` = '$UserID'
  302. ");
  303. list($UniqueGroups) = $DB->next_record();
  304. }
  305. if (check_paranoia_here('seeding+')) {
  306. $DB->query("
  307. SELECT
  308. COUNT(x.`uid`)
  309. FROM
  310. `xbt_files_users` AS x
  311. INNER JOIN `torrents` AS t
  312. ON
  313. t.`ID` = x.`fid`
  314. WHERE
  315. x.`uid` = '$UserID'
  316. AND x.`remaining` = 0
  317. ");
  318. list($Seeding) = $DB->next_record();
  319. }
  320. if (check_paranoia_here('leeching+')) {
  321. $DB->query("
  322. SELECT
  323. COUNT(x.`uid`)
  324. FROM
  325. `xbt_files_users` AS x
  326. INNER JOIN `torrents` AS t
  327. ON
  328. t.`ID` = x.`fid`
  329. WHERE
  330. x.`uid` = '$UserID'
  331. AND x.`remaining` > 0
  332. ");
  333. list($Leeching) = $DB->next_record();
  334. }
  335. if (check_paranoia_here('invitedcount')) {
  336. $DB->query("
  337. SELECT
  338. COUNT(`UserID`)
  339. FROM
  340. `users_info`
  341. WHERE
  342. `Inviter` = '$UserID'
  343. ");
  344. list($Invited) = $DB->next_record();
  345. }
  346. if (!$OwnProfile) {
  347. $torrent_pass = '';
  348. }
  349. // Run through some paranoia stuff to decide what we can send out
  350. if (!check_paranoia_here('lastseen')) {
  351. $LastAccess = '';
  352. }
  353. if (check_paranoia_here('ratio')) {
  354. $Ratio = Format::get_ratio($Uploaded, $Downloaded, 5);
  355. } else {
  356. $Ratio = null;
  357. }
  358. if (!check_paranoia_here('uploaded')) {
  359. $Uploaded = null;
  360. }
  361. if (!check_paranoia_here('downloaded')) {
  362. $Downloaded = null;
  363. }
  364. if (isset($RequiredRatio) && !check_paranoia_here('requiredratio')) {
  365. $RequiredRatio = null;
  366. }
  367. if ($ParanoiaLevel === 0) {
  368. $ParanoiaLevelText = 'Off';
  369. } elseif ($ParanoiaLevel === 1) {
  370. $ParanoiaLevelText = 'Very Low';
  371. } elseif ($ParanoiaLevel <= 5) {
  372. $ParanoiaLevelText = 'Low';
  373. } elseif ($ParanoiaLevel <= 20) {
  374. $ParanoiaLevelText = 'High';
  375. } else {
  376. $ParanoiaLevelText = 'Very high';
  377. }
  378. // Bugfix for no access time available
  379. if (!$LastAccess) {
  380. $LastAccess = '';
  381. }
  382. header('Content-Type: text/plain; charset=utf-8');
  383. json_print('success', [
  384. 'username' => $Username,
  385. 'avatar' => $Avatar,
  386. 'isFriend' => (bool) $Friend,
  387. 'profileText' => Text::full_format($Info),
  388. 'stats' => [
  389. 'joinedDate' => $JoinDate,
  390. 'lastAccess' => $LastAccess,
  391. 'uploaded' => (int) $Uploaded,
  392. 'downloaded' => (int) $Downloaded,
  393. 'ratio' => (float) $Ratio,
  394. 'requiredRatio' => (float) $RequiredRatio
  395. ],
  396. 'ranks' => [
  397. 'uploaded' => (int) $UploadedRank,
  398. 'downloaded' => (int) $DownloadedRank,
  399. 'uploads' => (int) $UploadsRank,
  400. 'requests' => (int) $RequestRank,
  401. 'bounty' => (int) $BountyRank,
  402. 'posts' => (int) $PostRank,
  403. 'artists' => (int) $ArtistsRank,
  404. 'overall' => (int) $OverallRank
  405. ],
  406. 'personal' => [
  407. 'class' => $ClassLevels[$Class]['Name'],
  408. 'paranoia' => (int) $ParanoiaLevel,
  409. 'paranoiaText' => $ParanoiaLevelText,
  410. 'donor' => ($Donor === 1),
  411. 'warned' => (bool) $Warned,
  412. 'enabled' => ((int) $Enabled === 1 || (int) $Enabled === 0 || !$Enabled),
  413. 'passkey' => $torrent_pass
  414. ],
  415. 'community' => [
  416. 'posts' => (int) $ForumPosts,
  417. 'torrentComments' => (int) $NumComments,
  418. 'artistComments' => (int) $NumArtistComments,
  419. 'collageComments' => (int) $NumCollageComments,
  420. 'requestComments' => (int) $NumRequestComments,
  421. 'collagesStarted' => (int) $NumCollages,
  422. 'collagesContrib' => (int) $NumCollageContribs,
  423. 'requestsFilled' => (int) $RequestsFilled,
  424. 'bountyEarned' => (int) $TotalBounty,
  425. 'requestsVoted' => (int) $RequestsVoted,
  426. 'bountySpent' => (int) $TotalSpent,
  427. 'uploaded' => (int) $Uploads,
  428. 'groups' => (int) $UniqueGroups,
  429. 'seeding' => (int) $Seeding,
  430. 'leeching' => (int) $Leeching,
  431. 'snatched' => (int) $Snatched,
  432. 'invited' => (int) $Invited,
  433. 'artistsAdded' => (int) $ArtistsAdded
  434. ]
  435. ]);