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.

request.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. #declare(strict_types=1);
  3. $RequestTax = 0.1;
  4. // Minimum and default amount of upload to remove from the user when they vote.
  5. // Also change in static/functions/requests.js
  6. $MinimumVote = 20 * 1024 * 1024;
  7. /*
  8. * This is the page that displays the request to the end user after being created.
  9. */
  10. if (empty($_GET['id']) || !is_number($_GET['id'])) {
  11. json_die("failure");
  12. }
  13. $RequestID = (int)$_GET['id'];
  14. //First things first, lets get the data for the request.
  15. $Request = Requests::get_request($RequestID);
  16. if ($Request === false) {
  17. json_die("failure");
  18. }
  19. $CategoryID = $Request['CategoryID'];
  20. $Requestor = Users::user_info($Request['UserID']);
  21. $Filler = $Request['FillerID'] ? Users::user_info($Request['FillerID']) : null;
  22. //Convenience variables
  23. $IsFilled = !empty($Request['TorrentID']);
  24. $CanVote = !$IsFilled && check_perms('site_vote');
  25. if ($CategoryID == 0) {
  26. $CategoryName = 'Unknown';
  27. } else {
  28. $CategoryName = $Categories[$CategoryID - 1];
  29. }
  30. $JsonArtists = Requests::get_artists($RequestID);
  31. //Votes time
  32. $RequestVotes = Requests::get_votes_array($RequestID);
  33. $VoteCount = count($RequestVotes['Voters']);
  34. $ProjectCanEdit = (check_perms('project_team') && !$IsFilled && (($CategoryID == 0) || ($CategoryName == 'Music' && $Request['Year'] == 0)));
  35. $UserCanEdit = (!$IsFilled && $LoggedUser['ID'] == $Request['UserID'] && $VoteCount < 2);
  36. $CanEdit = ($UserCanEdit || $ProjectCanEdit || check_perms('site_moderate_requests'));
  37. $JsonTopContributors = [];
  38. $VoteMax = ($VoteCount < 5 ? $VoteCount : 5);
  39. for ($i = 0; $i < $VoteMax; $i++) {
  40. $User = array_shift($RequestVotes['Voters']);
  41. $JsonTopContributors[] = array(
  42. 'userId' => (int)$User['UserID'],
  43. 'userName' => $User['Username'],
  44. 'bounty' => (int)$User['Bounty']
  45. );
  46. }
  47. reset($RequestVotes['Voters']);
  48. list($NumComments, $Page, $Thread) = Comments::load('requests', $RequestID, false);
  49. $JsonRequestComments = [];
  50. foreach ($Thread as $Key => $Post) {
  51. list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
  52. list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
  53. $JsonRequestComments[] = array(
  54. 'postId' => (int)$PostID,
  55. 'authorId' => (int)$AuthorID,
  56. 'name' => $Username,
  57. 'donor' => ($Donor == 1),
  58. 'warned' => (bool)$Warned,
  59. 'enabled' => ($Enabled == 2 ? false : true),
  60. 'class' => Users::make_class_string($PermissionID),
  61. 'addedTime' => $AddedTime,
  62. 'avatar' => $Avatar,
  63. 'comment' => Text::full_format($Body),
  64. 'editedUserId' => (int)$EditedUserID,
  65. 'editedUsername' => $EditedUsername,
  66. 'editedTime' => $EditedTime
  67. );
  68. }
  69. $JsonTags = [];
  70. foreach ($Request['Tags'] as $Tag) {
  71. $JsonTags[] = $Tag;
  72. }
  73. json_die('success', array(
  74. 'requestId' => (int)$RequestID,
  75. 'requestorId' => (int)$Request['UserID'],
  76. 'requestorName' => $Requestor['Username'],
  77. 'isBookmarked' => Bookmarks::has_bookmarked('request', $RequestID),
  78. 'requestTax' => (float)$RequestTax,
  79. 'timeAdded' => $Request['TimeAdded'],
  80. 'canEdit' => (bool)$CanEdit,
  81. 'canVote' => (bool)$CanVote,
  82. 'minimumVote' => (int)$MinimumVote,
  83. 'voteCount' => (int)$VoteCount,
  84. 'lastVote' => $Request['LastVote'],
  85. 'topContributors' => $JsonTopContributors,
  86. 'totalBounty' => (int)$RequestVotes['TotalBounty'],
  87. 'categoryId' => (int)$CategoryID,
  88. 'categoryName' => $CategoryName,
  89. 'title' => $Request['Title'],
  90. 'year' => (int)$Request['Year'],
  91. 'image' => $Request['Image'],
  92. 'bbDescription' => $Request['Description'],
  93. 'description' => Text::full_format($Request['Description']),
  94. 'artists' => $JsonArtists,
  95. 'isFilled' => (bool)$IsFilled,
  96. 'fillerId' => (int)$Request['FillerID'],
  97. 'fillerName' => $Filler ? $Filler['Username'] : '',
  98. 'torrentId' => (int)$Request['TorrentID'],
  99. 'timeFilled' => $Request['TimeFilled'],
  100. 'tags' => $JsonTags,
  101. 'comments' => $JsonRequestComments,
  102. 'commentPage' => (int)$Page,
  103. 'commentPages' => (int)ceil($NumComments / TORRENT_COMMENTS_PER_PAGE)
  104. ));