Gazelle/sections/ajax/collage.php

171 lines
5.9 KiB
PHP
Raw Normal View History

2013-07-04 08:00:56 +00:00
<?
2013-07-30 08:00:51 +00:00
define('ARTIST_COLLAGE', 'Artists');
2013-11-10 08:00:49 +00:00
if (empty($_GET['id']) || !is_number($_GET['id'])) {
2013-07-04 08:00:56 +00:00
json_die("failure", "bad parameters");
}
$CollageID = $_GET['id'];
2013-11-10 08:00:49 +00:00
$Text = new TEXT;
2013-07-04 08:00:56 +00:00
$CacheKey = "collage_$CollageID";
2013-11-10 08:00:49 +00:00
$CollageData = $Cache->get_value($CacheKey);
if ($CollageData) {
list($Name, $Description, $CommentList, $Deleted, $CollageCategoryID, $CreatorID, $Locked, $MaxGroups, $MaxGroupsPerUser, $Updated, $Subscribers) = $CollageData;
2013-07-04 08:00:56 +00:00
} else {
2013-10-29 08:01:29 +00:00
$DB->query("
2013-07-04 08:00:56 +00:00
SELECT
Name,
Description,
UserID,
Deleted,
CategoryID,
Locked,
MaxGroups,
MaxGroupsPerUser,
2013-11-10 08:00:49 +00:00
Updated,
2013-07-04 08:00:56 +00:00
Subscribers
FROM collages
2013-10-29 08:01:29 +00:00
WHERE ID = '$CollageID'");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-07-04 08:00:56 +00:00
json_die("failure");
}
2013-11-10 08:00:49 +00:00
list($Name, $Description, $CreatorID, $Deleted, $CollageCategoryID, $Locked, $MaxGroups, $MaxGroupsPerUser, $Updated, $Subscribers) = $DB->next_record(MYSQLI_NUM);
$CommentList = null;
$SetCache = true;
2013-10-29 08:01:29 +00:00
}
2013-11-10 08:00:49 +00:00
// TODO: Cache this
$DB->query("
SELECT GroupID
FROM collages_torrents
WHERE CollageID = $CollageID");
$TorrentGroups = $DB->collect('GroupID');
2013-07-04 08:00:56 +00:00
2013-07-30 08:00:51 +00:00
$JSON = array(
'id' => (int)$CollageID,
'name' => $Name,
'description' => $Text->full_format($Description),
'creatorID' => (int)$CreatorID,
'deleted' => (bool)$Deleted,
'collageCategoryID' => (int)$CollageCategoryID,
'collageCategoryName' => $CollageCats[(int)$CollageCategoryID],
'locked' => (bool)$Locked,
'maxGroups' => (int)$MaxGroups,
'maxGroupsPerUser' => (int)$MaxGroupsPerUser,
2013-10-29 08:01:29 +00:00
'hasBookmarked' => Bookmarks::has_bookmarked('collage', $CollageID),
'subscriberCount' => (int)$Subscribers,
'torrentGroupIDList' => $TorrentGroups
2013-07-30 08:00:51 +00:00
);
if ($CollageCategoryID != array_search(ARTIST_COLLAGE, $CollageCats)) {
// torrent collage
$TorrentGroups = array();
$DB->query("
SELECT
ct.GroupID
FROM collages_torrents AS ct
JOIN torrents_group AS tg ON tg.ID = ct.GroupID
WHERE ct.CollageID = '$CollageID'
ORDER BY ct.Sort");
$GroupIDs = $DB->collect('GroupID');
$GroupList = Torrents::get_groups($GroupIDs);
foreach ($GroupIDs as $GroupID) {
2013-09-13 08:00:53 +00:00
if (!empty($GroupList[$GroupID])) {
2013-07-30 08:00:51 +00:00
$GroupDetails = Torrents::array_group($GroupList[$GroupID]);
if ($GroupDetails['GroupCategoryID'] > 0 && $Categories[$GroupDetails['GroupCategoryID'] - 1] == 'Music') {
$ArtistForm = $GroupDetails['ExtendedArtists'];
$JsonMusicInfo = array(
2013-09-13 08:00:53 +00:00
'composers' => isset($ArtistForm[4]) ? pullmediainfo($ArtistForm[4]) : array(),
'dj' => isset($ArtistForm[6]) ? pullmediainfo($ArtistForm[6]) : array(),
'artists' => isset($ArtistForm[1]) ? pullmediainfo($ArtistForm[1]) : array(),
'with' => isset($ArtistForm[2]) ? pullmediainfo($ArtistForm[2]) : array(),
'conductor' => isset($ArtistForm[5]) ? pullmediainfo($ArtistForm[5]) : array(),
'remixedBy' => isset($ArtistForm[3]) ? pullmediainfo($ArtistForm[3]) : array(),
'producer' => isset($ArtistForm[7]) ? pullmediainfo($ArtistForm[7]) : array()
2013-07-30 08:00:51 +00:00
);
} else {
$JsonMusicInfo = null;
}
$TorrentList = array();
foreach ($GroupDetails['Torrents'] as $Torrent) {
$TorrentList[] = array(
'torrentid' => (int)$Torrent['ID'],
'media' => $Torrent['Media'],
'format' => $Torrent['Format'],
'encoding' => $Torrent['Encoding'],
'remastered' => ($Torrent['Remastered'] == 1),
'remasterYear' => (int)$Torrent['RemasterYear'],
'remasterTitle' => $Torrent['RemasterTitle'],
'remasterRecordLabel' => $Torrent['RemasterRecordLabel'],
'remasterCatalogueNumber' => $Torrent['RemasterCatalogueNumber'],
'scene' => ($Torrent['Scene'] == 1),
'hasLog' => ($Torrent['HasLog'] == 1),
'hasCue' => ($Torrent['HasCue'] == 1),
'logScore' => (int)$Torrent['LogScore'],
'fileCount' => (int)$Torrent['FileCount'],
'size' => (int)$Torrent['Size'],
'seeders' => (int)$Torrent['Seeders'],
'leechers' => (int)$Torrent['Leechers'],
'snatched' => (int)$Torrent['Snatched'],
'freeTorrent' => ($Torrent['FreeTorrent'] == 1),
2013-08-12 08:00:44 +00:00
'reported' => (count(Torrents::get_reports((int)$Torrent['ID'])) > 0),
2013-07-30 08:00:51 +00:00
'time' => $Torrent['Time']
);
}
$TorrentGroups[] = array(
'id' => $GroupDetails['GroupID'],
'name' => $GroupDetails['GroupName'],
'year' => $GroupDetails['GroupYear'],
'categoryId' => $GroupDetails['GroupCategoryID'],
'recordLabel' => $GroupDetails['GroupRecordLabel'],
'catalogueNumber' => $GroupDetails['GroupCatalogueNumber'],
'vanityHouse' => $GroupDetails['GroupVanityHouse'],
'tagList' => $GroupDetails['TagList'],
'releaseType' => $GroupDetails['ReleaseType'],
'wikiImage' => $GroupDetails['WikiImage'],
'musicInfo' => $JsonMusicInfo,
'torrents' => $TorrentList
);
}
}
$JSON['torrentgroups'] = $TorrentGroups;
} else {
// artist collage
$DB->query("
SELECT
ca.ArtistID,
ag.Name,
aw.Image
FROM collages_artists AS ca
JOIN artists_group AS ag ON ag.ArtistID=ca.ArtistID
LEFT JOIN wiki_artists AS aw ON aw.RevisionID = ag.RevisionID
WHERE ca.CollageID='$CollageID'
ORDER BY ca.Sort");
$Artists = array();
while (list($ArtistID, $ArtistName, $ArtistImage) = $DB->next_record()) {
$Artists[] = array(
'id' => (int)$ArtistID,
'name' => $ArtistName,
'image' => $ArtistImage
);
}
$JSON['artists'] = $Artists;
}
2013-07-04 08:00:56 +00:00
2013-11-10 08:00:49 +00:00
if (isset($SetCache)) {
$CollageData = array(
$Name,
$Description,
$CommentList,
(bool)$Deleted,
(int)$CollageCategoryID,
(int)$CreatorID,
(bool)$Locked,
(int)$MaxGroups,
(int)$MaxGroupsPerUser,
$Updated,
(int)$Subscribers);
$Cache->cache_value($CacheKey, $CollageData, 3600);
}
2013-07-04 08:00:56 +00:00
2013-11-10 08:00:49 +00:00
json_print("success", $JSON);