get_value("torrents_details_$GroupID"); } if ($RevisionID || !is_array($TorrentCache)) { // Fetch the group details $SQL = 'SELECT '; if (!$RevisionID) { $SQL .= ' g.`description`, g.`picture`, '; } else { $SQL .= ' w.`Body`, w.`Image`, '; } $SQL .= " g.`id`, g.`title`, g.`subject`, g.`object`, g.`published`, g.`workgroup`, g.`location`, g.`identifier`, g.`category_id`, g.`timestamp`, GROUP_CONCAT(DISTINCT tags.`Name` SEPARATOR '|'), GROUP_CONCAT(DISTINCT tags.`ID` SEPARATOR '|'), GROUP_CONCAT(tt.`UserID` SEPARATOR '|') FROM `torrents_group` AS g LEFT JOIN `torrents_tags` AS tt ON tt.`GroupID` = g.`id` LEFT JOIN `tags` ON tags.`ID` = tt.`TagID`"; if ($RevisionID) { $SQL .= " LEFT JOIN `wiki_torrents` AS w ON w.`PageID` = '".db_string($GroupID)."' AND w.`RevisionID` = '".db_string($RevisionID)."' "; } $SQL .= " WHERE g.`id` = '".db_string($GroupID)."' GROUP BY NULL"; $DB->query($SQL); $TorrentDetails = $DB->next_record(MYSQLI_ASSOC); $TorrentDetails['Screenshots'] = []; $TorrentDetails['Mirrors'] = []; # Screenshots (Publications) $DB->query(" SELECT `ID`, `UserID`, `Time`, `URI` FROM `torrents_doi` WHERE `TorrentID` = '$GroupID' "); if ($DB->has_results()) { while ($Screenshot = $DB->next_record(MYSQLI_ASSOC, true)) { $TorrentDetails['Screenshots'][] = $Screenshot; } } # Mirrors $DB->query(" SELECT `ID`, `UserID`, `Time`, `URI` FROM `torrents_mirrors` WHERE `GroupID` = '$GroupID' "); if ($DB->has_results()) { while ($Mirror = $DB->next_record(MYSQLI_ASSOC, true)) { $TorrentDetails['Mirrors'][] = $Mirror; } } // Fetch the individual torrents $DB->query(" SELECT t.ID, t.Media, t.Container, t.Codec, t.Resolution, t.Version, t.Censored, t.Anonymous, t.Archive, t.FileCount, t.Size, t.Seeders, t.Leechers, t.Snatched, t.FreeTorrent, t.FreeLeechType, t.Time, t.Description, t.FileList, t.FilePath, t.UserID, t.last_action, HEX(t.info_hash) AS InfoHash, tbt.TorrentID AS BadTags, tbf.TorrentID AS BadFolders, tfi.TorrentID AS BadFiles, t.LastReseedRequest, tln.TorrentID AS LogInDB, t.ID AS HasFile FROM torrents AS t LEFT JOIN torrents_bad_tags AS tbt ON tbt.TorrentID = t.ID LEFT JOIN torrents_bad_folders AS tbf ON tbf.TorrentID = t.ID LEFT JOIN torrents_bad_files AS tfi ON tfi.TorrentID = t.ID LEFT JOIN torrents_logs_new AS tln ON tln.TorrentID = t.ID WHERE t.GroupID = '".db_string($GroupID)."' GROUP BY t.ID ORDER BY t.Media ASC, t.ID"); $TorrentList = $DB->to_array('ID', MYSQLI_ASSOC); if (count($TorrentList) === 0 && $ApiCall == false) { header('Location: log.php?search='.(empty($_GET['torrentid']) ? "Group+$GroupID" : "Torrent+$_GET[torrentid]")); error(); } elseif (count($TorrentList) === 0 && $ApiCall == true) { return; } if (in_array(0, $DB->collect('Seeders'))) { $CacheTime = 600; } else { $CacheTime = 3600; } // Store it all in cache if (!$RevisionID) { $Cache->cache_value("torrents_details_$GroupID", array($TorrentDetails, $TorrentList), $CacheTime); } } else { // If we're reading from cache $TorrentDetails = $TorrentCache[0]; $TorrentList = $TorrentCache[1]; } if ($PersonalProperties) { // Fetch all user specific torrent and group properties $TorrentDetails['Flags'] = array('IsSnatched' => false, 'IsLeeching' => false, 'IsSeeding' => false); foreach ($TorrentList as &$Torrent) { Torrents::torrent_properties($Torrent, $TorrentDetails['Flags']); } } if ($Return) { return array($TorrentDetails, $TorrentList); } } function get_torrent_info($TorrentID, $Return = true, $RevisionID = 0, $PersonalProperties = true, $ApiCall = false) { global $Cache, $DB; $GroupID = (int)torrentid_to_groupid($TorrentID); $GroupInfo = get_group_info($GroupID, $Return, $RevisionID, $PersonalProperties, $ApiCall); if ($GroupInfo) { foreach ($GroupInfo[1] as &$Torrent) { // Remove unneeded entries if ($Torrent['ID'] !== $TorrentID) { unset($GroupInfo[1][$Torrent['ID']]); } if ($Return) { return $GroupInfo; } } } else { if ($Return) { return; } } } // Check if a givin string can be validated as a torrenthash function is_valid_torrenthash($Str) { // 6C19FF4C 6C1DD265 3B25832C 0F6228B2 52D743D5 $Str = str_replace(' ', '', $Str); if (preg_match('/^[0-9a-fA-F]{40}$/', $Str)) { return $Str; } return false; } // Functionality for the API to resolve input into other data function torrenthash_to_torrentid($Str) { global $Cache, $DB; $DB->query(" SELECT ID FROM torrents WHERE HEX(info_hash) = '".db_string($Str)."'"); $TorrentID = (int)array_pop($DB->next_record(MYSQLI_ASSOC)); if ($TorrentID) { return $TorrentID; } return; } function torrenthash_to_groupid($Str) { global $Cache, $DB; $DB->query(" SELECT GroupID FROM torrents WHERE HEX(info_hash) = '".db_string($Str)."'"); $GroupID = (int)array_pop($DB->next_record(MYSQLI_ASSOC)); if ($GroupID) { return $GroupID; } return; } function torrentid_to_groupid($TorrentID) { global $Cache, $DB; $DB->query(" SELECT GroupID FROM torrents WHERE ID = '".db_string($TorrentID)."'"); $GroupID = (int)array_pop($DB->next_record(MYSQLI_ASSOC)); if ($GroupID) { return $GroupID; } return; } // After adjusting / deleting logs, recalculate the score for the torrent function set_torrent_logscore($TorrentID) { global $DB; $DB->query(" UPDATE torrents SET LogScore = ( SELECT FLOOR(AVG(Score)) FROM torrents_logs_new WHERE TorrentID = $TorrentID ) WHERE ID = $TorrentID"); } function get_group_requests($GroupID) { if (empty($GroupID) || !is_number($GroupID)) { return []; } global $DB, $Cache; $Requests = $Cache->get_value("requests_group_$GroupID"); if ($Requests === false) { $DB->query(" SELECT ID FROM requests WHERE GroupID = $GroupID AND TimeFilled IS NULL"); $Requests = $DB->collect('ID'); $Cache->cache_value("requests_group_$GroupID", $Requests, 0); } return Requests::get_requests($Requests); } // Used by both sections/torrents/details.php and sections/reportsv2/report.php function build_torrents_table($Cache, $DB, $LoggedUser, $GroupID, $GroupName, $GroupCategoryID, $TorrentList, $Types, $Username) { function filelist($Str) { return "\n
This torrent has '.$NumReports.' active '.($NumReports === 1 ? 'report' : 'reports').": |
$ReportLinks ".time_diff($Report['ReportedTime'], 2, true, true).' for the reason "'.$ReportType['title'].'":
'.Text::full_format($Report['UserComment']).' |
File Names' . $RegenLink . '
' . ($FilePath ? "/$FilePath/" : '') . '
|
Size |
%s | %s |
%s | %s |