Esempio n. 1
0
function get_group_info($GroupID, $Return = true, $RevisionID = 0, $PersonalProperties = true, $ApiCall = false)
{
    global $Cache, $DB;
    if (!$RevisionID) {
        $TorrentCache = $Cache->get_value("torrents_details_{$GroupID}");
    }
    if ($RevisionID || !is_array($TorrentCache)) {
        // Fetch the group details
        $SQL = 'SELECT ';
        if (!$RevisionID) {
            $SQL .= '
				g.WikiBody,
				g.WikiImage, ';
        } else {
            $SQL .= '
				w.Body,
				w.Image, ';
        }
        $SQL .= "\n\t\t\t\tg.ID,\n\t\t\t\tg.Name,\n\t\t\t\tg.Year,\n\t\t\t\tg.RecordLabel,\n\t\t\t\tg.CatalogueNumber,\n\t\t\t\tg.ReleaseType,\n\t\t\t\tg.CategoryID,\n\t\t\t\tg.Time,\n\t\t\t\tg.VanityHouse,\n\t\t\t\tGROUP_CONCAT(DISTINCT tags.Name SEPARATOR '|'),\n\t\t\t\tGROUP_CONCAT(DISTINCT tags.ID SEPARATOR '|'),\n\t\t\t\tGROUP_CONCAT(tt.UserID SEPARATOR '|'),\n\t\t\t\tGROUP_CONCAT(tt.PositiveVotes SEPARATOR '|'),\n\t\t\t\tGROUP_CONCAT(tt.NegativeVotes SEPARATOR '|')\n\t\t\tFROM torrents_group AS g\n\t\t\t\tLEFT JOIN torrents_tags AS tt ON tt.GroupID = g.ID\n\t\t\t\tLEFT JOIN tags ON tags.ID = tt.TagID";
        if ($RevisionID) {
            $SQL .= "\n\t\t\t\tLEFT JOIN wiki_torrents AS w ON w.PageID = '" . db_string($GroupID) . "'\n\t\t\t\t\t\tAND w.RevisionID = '" . db_string($RevisionID) . "' ";
        }
        $SQL .= "\n\t\t\tWHERE g.ID = '" . db_string($GroupID) . "'\n\t\t\tGROUP BY NULL";
        $DB->query($SQL);
        $TorrentDetails = $DB->next_record(MYSQLI_ASSOC);
        // Fetch the individual torrents
        $DB->query("\n\t\t\tSELECT\n\t\t\t\tt.ID,\n\t\t\t\tt.Media,\n\t\t\t\tt.Format,\n\t\t\t\tt.Encoding,\n\t\t\t\tt.Remastered,\n\t\t\t\tt.RemasterYear,\n\t\t\t\tt.RemasterTitle,\n\t\t\t\tt.RemasterRecordLabel,\n\t\t\t\tt.RemasterCatalogueNumber,\n\t\t\t\tt.Scene,\n\t\t\t\tt.HasLog,\n\t\t\t\tt.HasCue,\n\t\t\t\tt.LogScore,\n\t\t\t\tt.FileCount,\n\t\t\t\tt.Size,\n\t\t\t\tt.Seeders,\n\t\t\t\tt.Leechers,\n\t\t\t\tt.Snatched,\n\t\t\t\tt.FreeTorrent,\n\t\t\t\tt.Time,\n\t\t\t\tt.Description,\n\t\t\t\tt.FileList,\n\t\t\t\tt.FilePath,\n\t\t\t\tt.UserID,\n\t\t\t\tt.last_action,\n\t\t\t\tHEX(t.info_hash) AS InfoHash,\n\t\t\t\ttbt.TorrentID AS BadTags,\n\t\t\t\ttbf.TorrentID AS BadFolders,\n\t\t\t\ttfi.TorrentID AS BadFiles,\n\t\t\t\tca.TorrentID AS CassetteApproved,\n\t\t\t\tlma.TorrentID AS LossymasterApproved,\n\t\t\t\tlwa.TorrentID AS LossywebApproved,\n\t\t\t\tt.LastReseedRequest,\n\t\t\t\ttln.TorrentID AS LogInDB,\n\t\t\t\tt.ID AS HasFile\n\t\t\tFROM torrents AS t\n\t\t\t\tLEFT JOIN torrents_bad_tags AS tbt ON tbt.TorrentID = t.ID\n\t\t\t\tLEFT JOIN torrents_bad_folders AS tbf ON tbf.TorrentID = t.ID\n\t\t\t\tLEFT JOIN torrents_bad_files AS tfi ON tfi.TorrentID = t.ID\n\t\t\t\tLEFT JOIN torrents_cassette_approved AS ca ON ca.TorrentID = t.ID\n\t\t\t\tLEFT JOIN torrents_lossymaster_approved AS lma ON lma.TorrentID = t.ID\n\t\t\t\tLEFT JOIN torrents_lossyweb_approved AS lwa ON lwa.TorrentID = t.ID\n\t\t\t\tLEFT JOIN torrents_logs_new AS tln ON tln.TorrentID = t.ID\n\t\t\tWHERE t.GroupID = '" . db_string($GroupID) . "'\n\t\t\tGROUP BY t.ID\n\t\t\tORDER BY t.Remastered ASC,\n\t\t\t\t(t.RemasterYear != 0) DESC,\n\t\t\t\tt.RemasterYear ASC,\n\t\t\t\tt.RemasterTitle ASC,\n\t\t\t\tt.RemasterRecordLabel ASC,\n\t\t\t\tt.RemasterCatalogueNumber ASC,\n\t\t\t\tt.Media ASC,\n\t\t\t\tt.Format,\n\t\t\t\tt.Encoding,\n\t\t\t\tt.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']}"));
            die;
        } elseif (count($TorrentList) === 0 && $ApiCall == true) {
            return null;
        }
        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);
        foreach ($TorrentList as &$Torrent) {
            Torrents::torrent_properties($Torrent, $TorrentDetails['Flags']);
        }
    }
    if ($Return) {
        return array($TorrentDetails, $TorrentList);
    }
}