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

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