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.

user.php 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 users_main AS m
  38. JOIN users_info AS i ON i.UserID = m.ID
  39. LEFT JOIN permissions AS p ON p.ID = m.PermissionID
  40. LEFT JOIN users_main AS inviter ON i.Inviter = inviter.ID
  41. LEFT JOIN forums_posts AS posts ON posts.AuthorID = m.ID
  42. WHERE m.ID = $UserID
  43. GROUP BY AuthorID");
  44. if (!$DB->has_results()) { // If user doesn't exist
  45. json_die("failure", "no such user");
  46. }
  47. 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));
  48. $Paranoia = unserialize($Paranoia);
  49. if (!is_array($Paranoia)) {
  50. $Paranoia = array();
  51. }
  52. $ParanoiaLevel = 0;
  53. foreach ($Paranoia as $P) {
  54. $ParanoiaLevel++;
  55. if (strpos($P, '+') !== false) {
  56. $ParanoiaLevel++;
  57. }
  58. }
  59. // Raw time is better for JSON.
  60. //$JoinedDate = time_diff($JoinDate);
  61. //$LastAccess = time_diff($LastAccess);
  62. function check_paranoia_here($Setting) {
  63. global $Paranoia, $Class, $UserID;
  64. return check_paranoia($Setting, $Paranoia, $Class, $UserID);
  65. }
  66. $Friend = false;
  67. $DB->query("
  68. SELECT FriendID
  69. FROM friends
  70. WHERE UserID = '$LoggedUser[ID]'
  71. AND FriendID = '$UserID'");
  72. if ($DB->has_results()) {
  73. $Friend = true;
  74. }
  75. if (check_paranoia_here('requestsfilled_count') || check_paranoia_here('requestsfilled_bounty')) {
  76. $DB->query("
  77. SELECT COUNT(DISTINCT r.ID), SUM(rv.Bounty)
  78. FROM requests AS r
  79. LEFT JOIN requests_votes AS rv ON r.ID = rv.RequestID
  80. WHERE r.FillerID = $UserID");
  81. list($RequestsFilled, $TotalBounty) = $DB->next_record();
  82. $DB->query("
  83. SELECT COUNT(RequestID), SUM(Bounty)
  84. FROM requests_votes
  85. WHERE UserID = $UserID");
  86. list($RequestsVoted, $TotalSpent) = $DB->next_record();
  87. $DB->query("
  88. SELECT COUNT(ID)
  89. FROM torrents
  90. WHERE UserID = '$UserID'");
  91. list($Uploads) = $DB->next_record();
  92. } else {
  93. $RequestsFilled = null;
  94. $TotalBounty = null;
  95. $RequestsVoted = 0;
  96. $TotalSpent = 0;
  97. }
  98. if (check_paranoia_here('uploads+')) {
  99. $DB->query("
  100. SELECT COUNT(ID)
  101. FROM torrents
  102. WHERE UserID = '$UserID'");
  103. list($Uploads) = $DB->next_record();
  104. } else {
  105. $Uploads = null;
  106. }
  107. if (check_paranoia_here('artistsadded')) {
  108. $DB->query("
  109. SELECT COUNT(ArtistID)
  110. FROM torrents_artists
  111. WHERE UserID = $UserID");
  112. list($ArtistsAdded) = $DB->next_record();
  113. } else {
  114. $ArtistsAdded = null;
  115. }
  116. // Do the ranks.
  117. if (check_paranoia_here('uploaded')) {
  118. $UploadedRank = UserRank::get_rank('uploaded', $Uploaded);
  119. } else {
  120. $UploadedRank = null;
  121. }
  122. if (check_paranoia_here('downloaded')) {
  123. $DownloadedRank = UserRank::get_rank('downloaded', $Downloaded);
  124. } else {
  125. $DownloadedRank = null;
  126. }
  127. if (check_paranoia_here('uploads+')) {
  128. $UploadsRank = UserRank::get_rank('uploads', $Uploads);
  129. } else {
  130. $UploadsRank = null;
  131. }
  132. if (check_paranoia_here('requestsfilled_count')) {
  133. $RequestRank = UserRank::get_rank('requests', $RequestsFilled);
  134. } else {
  135. $RequestRank = null;
  136. }
  137. $PostRank = UserRank::get_rank('posts', $ForumPosts);
  138. if (check_paranoia_here('requestsvoted_bounty')) {
  139. $BountyRank = UserRank::get_rank('bounty', $TotalSpent);
  140. } else {
  141. $BountyRank = null;
  142. }
  143. if (check_paranoia_here('artistsadded')) {
  144. $ArtistsRank = UserRank::get_rank('artists', $ArtistsAdded);
  145. } else {
  146. $ArtistsRank = null;
  147. }
  148. if ($Downloaded == 0) {
  149. $Ratio = 1;
  150. } elseif ($Uploaded == 0) {
  151. $Ratio = 0.5;
  152. } else {
  153. $Ratio = round($Uploaded / $Downloaded, 2);
  154. }
  155. if (check_paranoia_here(array('uploaded', 'downloaded', 'uploads+', 'requestsfilled_count', 'requestsvoted_bounty', 'artistsadded'))) {
  156. $OverallRank = floor(UserRank::overall_score($UploadedRank, $DownloadedRank, $UploadsRank, $RequestRank, $PostRank, $BountyRank, $ArtistsRank, $Ratio));
  157. } else {
  158. $OverallRank = null;
  159. }
  160. // Community section
  161. if (check_paranoia_here('snatched+')) {
  162. $DB->query("
  163. SELECT COUNT(x.uid), COUNT(DISTINCT x.fid)
  164. FROM xbt_snatched AS x
  165. INNER JOIN torrents AS t ON t.ID = x.fid
  166. WHERE x.uid = '$UserID'");
  167. list($Snatched, $UniqueSnatched) = $DB->next_record();
  168. }
  169. if (check_paranoia_here('torrentcomments+')) {
  170. $DB->query("
  171. SELECT COUNT(ID)
  172. FROM comments
  173. WHERE Page = 'torrents'
  174. AND AuthorID = '$UserID'");
  175. list($NumComments) = $DB->next_record();
  176. }
  177. if (check_paranoia_here('torrentcomments+')) {
  178. $DB->query("
  179. SELECT COUNT(ID)
  180. FROM comments
  181. WHERE Page = 'artist'
  182. AND AuthorID = '$UserID'");
  183. list($NumArtistComments) = $DB->next_record();
  184. }
  185. if (check_paranoia_here('torrentcomments+')) {
  186. $DB->query("
  187. SELECT COUNT(ID)
  188. FROM comments
  189. WHERE Page = 'collages'
  190. AND AuthorID = '$UserID'");
  191. list($NumCollageComments) = $DB->next_record();
  192. }
  193. if (check_paranoia_here('torrentcomments+')) {
  194. $DB->query("
  195. SELECT COUNT(ID)
  196. FROM comments
  197. WHERE Page = 'requests'
  198. AND AuthorID = '$UserID'");
  199. list($NumRequestComments) = $DB->next_record();
  200. }
  201. if (check_paranoia_here('collages+')) {
  202. $DB->query("
  203. SELECT COUNT(ID)
  204. FROM collages
  205. WHERE Deleted = '0'
  206. AND UserID = '$UserID'");
  207. list($NumCollages) = $DB->next_record();
  208. }
  209. if (check_paranoia_here('collagecontribs+')) {
  210. $DB->query("
  211. SELECT COUNT(DISTINCT ct.CollageID)
  212. FROM collages_torrents AS ct
  213. JOIN collages AS c ON ct.CollageID = c.ID
  214. WHERE c.Deleted = '0'
  215. AND ct.UserID = '$UserID'");
  216. list($NumCollageContribs) = $DB->next_record();
  217. }
  218. if (check_paranoia_here('uniquegroups+')) {
  219. $DB->query("
  220. SELECT COUNT(DISTINCT GroupID)
  221. FROM torrents
  222. WHERE UserID = '$UserID'");
  223. list($UniqueGroups) = $DB->next_record();
  224. }
  225. if (check_paranoia_here('seeding+')) {
  226. $DB->query("
  227. SELECT COUNT(x.uid)
  228. FROM xbt_files_users AS x
  229. INNER JOIN torrents AS t ON t.ID = x.fid
  230. WHERE x.uid = '$UserID'
  231. AND x.remaining = 0");
  232. list($Seeding) = $DB->next_record();
  233. }
  234. if (check_paranoia_here('leeching+')) {
  235. $DB->query("
  236. SELECT COUNT(x.uid)
  237. FROM xbt_files_users AS x
  238. INNER JOIN torrents AS t ON t.ID = x.fid
  239. WHERE x.uid = '$UserID'
  240. AND x.remaining > 0");
  241. list($Leeching) = $DB->next_record();
  242. }
  243. if (check_paranoia_here('invitedcount')) {
  244. $DB->query("
  245. SELECT COUNT(UserID)
  246. FROM users_info
  247. WHERE Inviter = '$UserID'");
  248. list($Invited) = $DB->next_record();
  249. }
  250. if (!$OwnProfile) {
  251. $torrent_pass = '';
  252. }
  253. // Run through some paranoia stuff to decide what we can send out.
  254. if (!check_paranoia_here('lastseen')) {
  255. $LastAccess = '';
  256. }
  257. if (check_paranoia_here('ratio')) {
  258. $Ratio = Format::get_ratio($Uploaded, $Downloaded, 5);
  259. } else {
  260. $Ratio = null;
  261. }
  262. if (!check_paranoia_here('uploaded')) {
  263. $Uploaded = null;
  264. }
  265. if (!check_paranoia_here('downloaded')) {
  266. $Downloaded = null;
  267. }
  268. if (isset($RequiredRatio) && !check_paranoia_here('requiredratio')) {
  269. $RequiredRatio = null;
  270. }
  271. if ($ParanoiaLevel == 0) {
  272. $ParanoiaLevelText = 'Off';
  273. } elseif ($ParanoiaLevel == 1) {
  274. $ParanoiaLevelText = 'Very Low';
  275. } elseif ($ParanoiaLevel <= 5) {
  276. $ParanoiaLevelText = 'Low';
  277. } elseif ($ParanoiaLevel <= 20) {
  278. $ParanoiaLevelText = 'High';
  279. } else {
  280. $ParanoiaLevelText = 'Very high';
  281. }
  282. //Bugfix for no access time available
  283. if (!$LastAccess) { $LastAccess = ''; }
  284. header('Content-Type: text/plain; charset=utf-8');
  285. json_print("success", [
  286. 'username' => $Username,
  287. 'avatar' => $Avatar,
  288. 'isFriend' => (bool)$Friend,
  289. 'profileText' => Text::full_format($Info),
  290. 'stats' => [
  291. 'joinedDate' => $JoinDate,
  292. 'lastAccess' => $LastAccess,
  293. 'uploaded' => (int)$Uploaded,
  294. 'downloaded' => (int)$Downloaded,
  295. 'ratio' => (float)$Ratio,
  296. 'requiredRatio' => (float)$RequiredRatio
  297. ],
  298. 'ranks' => [
  299. 'uploaded' => (int)$UploadedRank,
  300. 'downloaded' => (int)$DownloadedRank,
  301. 'uploads' => (int)$UploadsRank,
  302. 'requests' => (int)$RequestRank,
  303. 'bounty' => (int)$BountyRank,
  304. 'posts' => (int)$PostRank,
  305. 'artists' => (int)$ArtistsRank,
  306. 'overall' => (int)$OverallRank
  307. ],
  308. 'personal' => [
  309. 'class' => $ClassLevels[$Class]['Name'],
  310. 'paranoia' => (int)$ParanoiaLevel,
  311. 'paranoiaText' => $ParanoiaLevelText,
  312. 'donor' => ($Donor == 1),
  313. 'warned' => (bool)$Warned,
  314. 'enabled' => ($Enabled == '1' || $Enabled == '0' || !$Enabled),
  315. 'passkey' => $torrent_pass
  316. ],
  317. 'community' => [
  318. 'posts' => (int)$ForumPosts,
  319. 'torrentComments' => (int)$NumComments,
  320. 'artistComments' => (int)$NumArtistComments,
  321. 'collageComments' => (int)$NumCollageComments,
  322. 'requestComments' => (int)$NumRequestComments,
  323. 'collagesStarted' => (int)$NumCollages,
  324. 'collagesContrib' => (int)$NumCollageContribs,
  325. 'requestsFilled' => (int)$RequestsFilled,
  326. 'bountyEarned' => (int)$TotalBounty,
  327. 'requestsVoted' => (int)$RequestsVoted,
  328. 'bountySpent' => (int)$TotalSpent,
  329. 'uploaded' => (int)$Uploads,
  330. 'groups' => (int)$UniqueGroups,
  331. 'seeding' => (int)$Seeding,
  332. 'leeching' => (int)$Leeching,
  333. 'snatched' => (int)$Snatched,
  334. 'invited' => (int)$Invited,
  335. 'artistsAdded' => (int)$ArtistsAdded
  336. ]
  337. ]);
  338. ?>