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.

functions.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. # Line 3
  3. function get_group_info($GroupID, $Return = true, $RevisionID = 0, $PersonalProperties = true, $ApiCall = false)
  4. {
  5. global $Cache, $DB;
  6. if (!$RevisionID) {
  7. $TorrentCache = $Cache->get_value("torrents_details_$GroupID");
  8. }
  9. if ($RevisionID || !is_array($TorrentCache)) {
  10. // Fetch the group details
  11. $SQL = 'SELECT ';
  12. if (!$RevisionID) {
  13. $SQL .= '
  14. g.WikiBody,
  15. g.WikiImage, ';
  16. } else {
  17. $SQL .= '
  18. w.Body,
  19. w.Image, ';
  20. }
  21. $SQL .= "
  22. g.ID,
  23. g.Name,
  24. g.NameRJ,
  25. g.NameJP,
  26. g.Year,
  27. g.Studio,
  28. g.Series,
  29. g.CatalogueNumber,
  30. g.Pages,
  31. g.CategoryID,
  32. g.DLsiteID,
  33. g.Time,
  34. GROUP_CONCAT(DISTINCT tags.Name SEPARATOR '|'),
  35. GROUP_CONCAT(DISTINCT tags.ID SEPARATOR '|'),
  36. GROUP_CONCAT(tt.UserID SEPARATOR '|')
  37. FROM torrents_group AS g
  38. LEFT JOIN torrents_tags AS tt ON tt.GroupID = g.ID
  39. LEFT JOIN tags ON tags.ID = tt.TagID";
  40. if ($RevisionID) {
  41. $SQL .= "
  42. LEFT JOIN wiki_torrents AS w ON w.PageID = '".db_string($GroupID)."'
  43. AND w.RevisionID = '".db_string($RevisionID)."' ";
  44. }
  45. $SQL .= "
  46. WHERE g.ID = '".db_string($GroupID)."'
  47. GROUP BY NULL";
  48. $DB->query($SQL);
  49. $TorrentDetails = $DB->next_record(MYSQLI_ASSOC);
  50. $TorrentDetails['Screenshots'] = [];
  51. $TorrentDetails['Mirrors'] = [];
  52. # Screenshots (Publications)
  53. $DB->query("
  54. SELECT
  55. ID, UserID, Time, Image
  56. FROM torrents_screenshots
  57. WHERE GroupID = ".db_string($GroupID));
  58. if ($DB->has_results()) {
  59. while ($Screenshot = $DB->next_record(MYSQLI_ASSOC, true)) {
  60. $TorrentDetails['Screenshots'][] = $Screenshot;
  61. }
  62. }
  63. # Mirrors
  64. $DB->query("
  65. SELECT
  66. ID, UserID, Time, Resource
  67. FROM torrents_mirrors
  68. WHERE GroupID = ".db_string($GroupID));
  69. if ($DB->has_results()) {
  70. while ($Mirror = $DB->next_record(MYSQLI_ASSOC, true)) {
  71. $TorrentDetails['Mirrors'][] = $Mirror;
  72. }
  73. }
  74. // Fetch the individual torrents
  75. $DB->query("
  76. SELECT
  77. t.ID,
  78. t.Media,
  79. t.Container,
  80. t.Codec,
  81. t.Resolution,
  82. t.AudioFormat,
  83. t.Subbing,
  84. t.Subber,
  85. t.Language,
  86. t.Censored,
  87. t.Anonymous,
  88. t.Archive,
  89. t.FileCount,
  90. t.Size,
  91. t.Seeders,
  92. t.Leechers,
  93. t.Snatched,
  94. t.FreeTorrent,
  95. t.FreeLeechType,
  96. t.Time,
  97. t.Description,
  98. t.MediaInfo,
  99. t.FileList,
  100. t.FilePath,
  101. t.UserID,
  102. t.last_action,
  103. HEX(t.info_hash) AS InfoHash,
  104. tbt.TorrentID AS BadTags,
  105. tbf.TorrentID AS BadFolders,
  106. tfi.TorrentID AS BadFiles,
  107. t.LastReseedRequest,
  108. tln.TorrentID AS LogInDB,
  109. t.ID AS HasFile
  110. FROM torrents AS t
  111. LEFT JOIN torrents_bad_tags AS tbt ON tbt.TorrentID = t.ID
  112. LEFT JOIN torrents_bad_folders AS tbf ON tbf.TorrentID = t.ID
  113. LEFT JOIN torrents_bad_files AS tfi ON tfi.TorrentID = t.ID
  114. LEFT JOIN torrents_logs_new AS tln ON tln.TorrentID = t.ID
  115. WHERE t.GroupID = '".db_string($GroupID)."'
  116. GROUP BY t.ID
  117. ORDER BY
  118. t.Media ASC,
  119. t.ID");
  120. $TorrentList = $DB->to_array('ID', MYSQLI_ASSOC);
  121. if (count($TorrentList) === 0 && $ApiCall == false) {
  122. header('Location: log.php?search='.(empty($_GET['torrentid']) ? "Group+$GroupID" : "Torrent+$_GET[torrentid]"));
  123. die();
  124. } elseif (count($TorrentList) === 0 && $ApiCall == true) {
  125. return null;
  126. }
  127. if (in_array(0, $DB->collect('Seeders'))) {
  128. $CacheTime = 600;
  129. } else {
  130. $CacheTime = 3600;
  131. }
  132. // Store it all in cache
  133. if (!$RevisionID) {
  134. $Cache->cache_value("torrents_details_$GroupID", array($TorrentDetails, $TorrentList), $CacheTime);
  135. }
  136. } else { // If we're reading from cache
  137. $TorrentDetails = $TorrentCache[0];
  138. $TorrentList = $TorrentCache[1];
  139. }
  140. if ($PersonalProperties) {
  141. // Fetch all user specific torrent and group properties
  142. $TorrentDetails['Flags'] = array('IsSnatched' => false, 'IsLeeching' => false, 'IsSeeding' => false);
  143. foreach ($TorrentList as &$Torrent) {
  144. Torrents::torrent_properties($Torrent, $TorrentDetails['Flags']);
  145. }
  146. }
  147. if ($Return) {
  148. return array($TorrentDetails, $TorrentList);
  149. }
  150. }
  151. # Line 165