Gazelle/sections/ajax/better/single.php
2014-05-07 08:00:45 +00:00

57 lines
1.3 KiB
PHP

<?
if (($GroupIDs = $Cache->get_value('better_single_groupids')) === false) {
$DB->query("
SELECT
t.ID AS TorrentID,
t.GroupID AS GroupID
FROM xbt_files_users AS x
JOIN torrents AS t ON t.ID = x.fid
WHERE t.Format = 'FLAC'
GROUP BY x.fid
HAVING COUNT(x.uid) = 1
ORDER BY t.LogScore DESC, t.Time ASC
LIMIT 30");
$GroupIDs = $DB->to_array('GroupID');
$Cache->cache_value('better_single_groupids', $GroupIDs, 30 * 60);
}
$Results = Torrents::get_groups(array_keys($GroupIDs));
$JsonResults = array();
foreach ($GroupIDs as $GroupID) {
if (!isset($Results[$GroupID])) {
continue;
}
$Group = $Results[$GroupIDs];
extract(Torrents::array_group($Group));
$FlacID = $GroupIDs[$GroupID]['TorrentID'];
$JsonArtists = array();
if (count($Artists) > 0) {
foreach ($Artists as $Artist) {
$JsonArtists[] = array(
'id' => (int)$Artist['id'],
'name' => $Artist['name'],
'aliasId' => (int)$Artist['aliasid']
);
}
}
$JsonResults[] = array(
'torrentId' => (int)$FlacID,
'groupId' => (int)$GroupID,
'artist' => $JsonArtists,
'groupName' => $GroupName,
'groupYear' => (int)$GroupYear,
'downloadUrl' => "torrents.php?action=download&id=$FlacID&authkey=".$LoggedUser['AuthKey'].'&torrent_pass='.$LoggedUser['torrent_pass']
);
}
print json_encode(
array(
'status' => 'success',
'response' => $JsonResults
)
);