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.

collage.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. #declare(strict_types=1);
  3. define('ARTIST_COLLAGE', 'Artists');
  4. if (empty($_GET['id']) || !is_number($_GET['id'])) {
  5. json_die('failure', 'bad parameters');
  6. }
  7. $CollageID = $_GET['id'];
  8. $CacheKey = "collage_$CollageID";
  9. $CollageData = $Cache->get_value($CacheKey);
  10. if ($CollageData) {
  11. list($Name, $Description, $CommentList, $Deleted, $CollageCategoryID, $CreatorID, $Locked, $MaxGroups, $MaxGroupsPerUser, $Updated, $Subscribers) = $CollageData;
  12. } else {
  13. $DB->query("
  14. SELECT
  15. `Name`,
  16. `Description`,
  17. `UserID`,
  18. `Deleted`,
  19. `CategoryID`,
  20. `Locked`,
  21. `MaxGroups`,
  22. `MaxGroupsPerUser`,
  23. `Updated`,
  24. `Subscribers`
  25. FROM
  26. `collages`
  27. WHERE
  28. `ID` = '$CollageID'
  29. ");
  30. if (!$DB->has_results()) {
  31. json_die("failure");
  32. }
  33. list($Name, $Description, $CreatorID, $Deleted, $CollageCategoryID, $Locked, $MaxGroups, $MaxGroupsPerUser, $Updated, $Subscribers) = $DB->next_record(MYSQLI_NUM);
  34. $CommentList = null;
  35. $SetCache = true;
  36. }
  37. // todo: Cache this
  38. $DB->query("
  39. SELECT
  40. `GroupID`
  41. FROM
  42. `collages_torrents`
  43. WHERE
  44. `CollageID` = $CollageID
  45. ");
  46. $TorrentGroups = $DB->collect('GroupID');
  47. $JSON = array(
  48. 'id' => (int) $CollageID,
  49. 'name' => $Name,
  50. 'description' => Text::full_format($Description),
  51. 'creatorID' => (int) $CreatorID,
  52. 'deleted' => (bool) $Deleted,
  53. 'collageCategoryID' => (int) $CollageCategoryID,
  54. 'collageCategoryName' => $CollageCats[(int) $CollageCategoryID],
  55. 'locked' => (bool) $Locked,
  56. 'maxGroups' => (int) $MaxGroups,
  57. 'maxGroupsPerUser' => (int) $MaxGroupsPerUser,
  58. 'hasBookmarked' => Bookmarks::has_bookmarked('collage', $CollageID),
  59. 'subscriberCount' => (int) $Subscribers,
  60. 'torrentGroupIDList' => $TorrentGroups
  61. );
  62. if ($CollageCategoryID !== array_search(ARTIST_COLLAGE, $CollageCats)) {
  63. // Torrent collage
  64. $TorrentGroups = [];
  65. $DB->query("
  66. SELECT
  67. ct.`GroupID`
  68. FROM
  69. `collages_torrents` AS ct
  70. JOIN `torrents_group` AS tg
  71. ON
  72. tg.`ID` = ct.`GroupID`
  73. WHERE
  74. ct.`CollageID` = '$CollageID'
  75. ORDER BY
  76. ct.`Sort`
  77. ");
  78. $GroupIDs = $DB->collect('GroupID');
  79. $GroupList = Torrents::get_groups($GroupIDs);
  80. foreach ($GroupIDs as $GroupID) {
  81. if (!empty($GroupList[$GroupID])) {
  82. $GroupDetails = Torrents::array_group($GroupList[$GroupID]);
  83. $TorrentList = [];
  84. foreach ($GroupDetails['Torrents'] as $Torrent) {
  85. $TorrentList[] = array(
  86. 'torrentid' => (int)$Torrent['ID'],
  87. 'platform' => $Torrent['Media'],
  88. 'fileCount' => (int)$Torrent['FileCount'],
  89. 'size' => (int)$Torrent['Size'],
  90. 'seeders' => (int)$Torrent['Seeders'],
  91. 'leechers' => (int)$Torrent['Leechers'],
  92. 'snatched' => (int)$Torrent['Snatched'],
  93. 'freeTorrent' => ($Torrent['FreeTorrent'] === 1),
  94. 'reported' => (count(Torrents::get_reports((int)$Torrent['ID'])) > 0),
  95. 'time' => $Torrent['Time']
  96. );
  97. }
  98. $TorrentGroups[] = array(
  99. 'id' => $GroupDetails['GroupID'],
  100. 'name' => $GroupDetails['GroupName'],
  101. 'year' => $GroupDetails['GroupYear'],
  102. 'categoryId' => $GroupDetails['GroupCategoryID'],
  103. 'accession' => $GroupDetails['GroupCatalogueNumber'],
  104. 'vanityHouse' => $GroupDetails['GroupVanityHouse'],
  105. 'tagList' => $GroupDetails['TagList'],
  106. 'picture' => $GroupDetails['WikiImage'],
  107. 'torrents' => $TorrentList
  108. );
  109. }
  110. }
  111. $JSON['torrentgroups'] = $TorrentGroups;
  112. } else {
  113. // Artist collage
  114. $DB->query("
  115. SELECT
  116. ca.`ArtistID`,
  117. ag.`Name`,
  118. aw.`Image`
  119. FROM
  120. `collages_artists` AS ca
  121. JOIN `artists_group` AS ag
  122. ON
  123. ag.`ArtistID` = ca.`ArtistID`
  124. LEFT JOIN `wiki_artists` AS aw
  125. ON
  126. aw.`RevisionID` = ag.`RevisionID`
  127. WHERE
  128. ca.`CollageID` = '$CollageID'
  129. ORDER BY
  130. ca.`Sort`
  131. ");
  132. $Artists = [];
  133. while (list($ArtistID, $ArtistName, $ArtistImage) = $DB->next_record()) {
  134. $Artists[] = array(
  135. 'id' => (int) $ArtistID,
  136. 'name' => $ArtistName,
  137. 'picture' => $ArtistImage
  138. );
  139. }
  140. $JSON['artists'] = $Artists;
  141. }
  142. if (isset($SetCache)) {
  143. $CollageData = array(
  144. $Name,
  145. $Description,
  146. $CommentList,
  147. (bool) $Deleted,
  148. (int) $CollageCategoryID,
  149. (int) $CreatorID,
  150. (bool) $Locked,
  151. (int) $MaxGroups,
  152. (int) $MaxGroupsPerUser,
  153. $Updated,
  154. (int) $Subscribers
  155. );
  156. $Cache->cache_value($CacheKey, $CollageData, 3600);
  157. }
  158. json_print('success', $JSON);