Gazelle/sections/ajax/artist.php

363 lines
9.7 KiB
PHP
Raw Normal View History

<?
//For sorting tags
2013-05-04 08:00:48 +00:00
function compare($X, $Y) {
return($Y['count'] - $X['count']);
}
2013-06-16 08:01:11 +00:00
if (!empty($_GET['artistreleases'])) {
$OnlyArtistReleases = true;
}
2013-04-24 08:00:23 +00:00
if ($_GET['id'] && $_GET['artistname']) {
2013-05-14 08:00:34 +00:00
json_die("failure", "bad parameters");
2013-04-24 08:00:23 +00:00
}
$ArtistID = $_GET['id'];
2013-04-24 08:00:23 +00:00
if ($ArtistID && !is_number($ArtistID)) {
2013-05-14 08:00:34 +00:00
json_die("failure");
}
if (empty($ArtistID)) {
if (!empty($_GET['artistname'])) {
$Name = db_string(trim($_GET['artistname']));
2013-07-10 00:08:53 +00:00
$DB->query("
SELECT ArtistID
FROM artists_alias
WHERE Name LIKE '$Name'");
if (!(list($ArtistID) = $DB->next_record(MYSQLI_NUM, false))) {
2013-05-14 08:00:34 +00:00
json_die("failure");
}
// If we get here, we got the ID!
}
}
2013-04-19 08:00:55 +00:00
if (!empty($_GET['revisionid'])) { // if they're viewing an old revision
2013-07-10 00:08:53 +00:00
$RevisionID = $_GET['revisionid'];
2012-11-20 08:00:19 +00:00
if (!is_number($RevisionID)) {
error(0);
}
$Data = $Cache->get_value("artist_$ArtistID"."_revision_$RevisionID");
} else { // viewing the live version
2013-07-10 00:08:53 +00:00
$Data = $Cache->get_value("artist_$ArtistID");
$RevisionID = false;
}
2013-04-19 08:00:55 +00:00
if ($Data) {
2012-11-20 08:00:19 +00:00
list($K, list($Name, $Image, $Body, $NumSimilar, $SimilarArray, , , $VanityHouseArtist)) = each($Data);
} else {
if ($RevisionID) {
2013-04-19 08:00:55 +00:00
$sql = "
SELECT
a.Name,
wiki.Image,
wiki.body,
a.VanityHouse
2012-10-11 08:00:15 +00:00
FROM wiki_artists AS wiki
2013-07-10 00:08:53 +00:00
LEFT JOIN artists_group AS a ON wiki.RevisionID = a.RevisionID
WHERE wiki.RevisionID = '$RevisionID' ";
} else {
2013-04-19 08:00:55 +00:00
$sql = "
SELECT
a.Name,
wiki.Image,
wiki.body,
a.VanityHouse
FROM artists_group AS a
2013-07-10 00:08:53 +00:00
LEFT JOIN wiki_artists AS wiki ON wiki.RevisionID = a.RevisionID
WHERE a.ArtistID = '$ArtistID' ";
}
$sql .= " GROUP BY a.ArtistID";
$DB->query($sql);
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2013-05-14 08:00:34 +00:00
json_die("failure");
}
list($Name, $Image, $Body, $VanityHouseArtist) = $DB->next_record(MYSQLI_NUM, array(0));
}
// Requests
2013-09-13 08:00:53 +00:00
$Requests = array();
if (empty($LoggedUser['DisableRequests'])) {
$Requests = $Cache->get_value("artists_requests_$ArtistID");
if (!is_array($Requests)) {
$DB->query("
SELECT
r.ID,
r.CategoryID,
r.Title,
r.Year,
r.TimeAdded,
COUNT(rv.UserID) AS Votes,
SUM(rv.Bounty) AS Bounty
FROM requests AS r
LEFT JOIN requests_votes AS rv ON rv.RequestID = r.ID
LEFT JOIN requests_artists AS ra ON r.ID = ra.RequestID
WHERE ra.ArtistID = $ArtistID
AND r.TorrentID = 0
GROUP BY r.ID
ORDER BY Votes DESC");
if ($DB->has_results()) {
$Requests = $DB->to_array('ID', MYSQLI_ASSOC, false);
} else {
$Requests = array();
}
$Cache->cache_value("artists_requests_$ArtistID", $Requests);
}
}
$NumRequests = count($Requests);
2013-07-10 00:08:53 +00:00
if (($Importances = $Cache->get_value("artist_groups_$ArtistID")) === false) {
2013-04-19 08:00:55 +00:00
$DB->query("
SELECT
2012-11-20 08:00:19 +00:00
DISTINCTROW ta.GroupID, ta.Importance, tg.VanityHouse, tg.Year
2013-04-19 08:00:55 +00:00
FROM torrents_artists AS ta
2013-07-10 00:08:53 +00:00
JOIN torrents_group AS tg ON tg.ID = ta.GroupID
WHERE ta.ArtistID = '$ArtistID'
2013-04-19 08:00:55 +00:00
ORDER BY tg.Year DESC, tg.Name DESC");
$GroupIDs = $DB->collect('GroupID');
2012-11-20 08:00:19 +00:00
$Importances = $DB->to_array(false, MYSQLI_BOTH, false);
2013-07-10 00:08:53 +00:00
$Cache->cache_value("artist_groups_$ArtistID", $Importances, 0);
2012-11-20 08:00:19 +00:00
} else {
$GroupIDs = array();
foreach ($Importances as $Group) {
$GroupIDs[] = $Group['GroupID'];
}
}
2012-11-20 08:00:19 +00:00
if (count($GroupIDs) > 0) {
2013-07-10 00:08:53 +00:00
$TorrentList = Torrents::get_groups($GroupIDs, true, true);
2012-11-20 08:00:19 +00:00
} else {
$TorrentList = array();
}
$NumGroups = count($TorrentList);
//Get list of used release types
$UsedReleases = array();
2013-04-19 08:00:55 +00:00
foreach ($TorrentList as $GroupID=>$Group) {
if ($Importances[$GroupID]['Importance'] == '2') {
$TorrentList[$GroupID]['ReleaseType'] = 1024;
$GuestAlbums = true;
}
2013-04-19 08:00:55 +00:00
if ($Importances[$GroupID]['Importance'] == '3') {
$TorrentList[$GroupID]['ReleaseType'] = 1023;
$RemixerAlbums = true;
}
2013-04-19 08:00:55 +00:00
if ($Importances[$GroupID]['Importance'] == '4') {
2012-02-19 08:00:19 +00:00
$TorrentList[$GroupID]['ReleaseType'] = 1022;
$ComposerAlbums = true;
}
2013-04-19 08:00:55 +00:00
if ($Importances[$GroupID]['Importance'] == '7') {
2012-02-19 08:00:19 +00:00
$TorrentList[$GroupID]['ReleaseType'] = 1021;
$ProducerAlbums = true;
}
2013-04-19 08:00:55 +00:00
if (!in_array($TorrentList[$GroupID]['ReleaseType'], $UsedReleases)) {
$UsedReleases[] = $TorrentList[$GroupID]['ReleaseType'];
}
}
2013-04-19 08:00:55 +00:00
if (!empty($GuestAlbums)) {
2013-06-17 08:01:02 +00:00
$ReleaseTypes[1024] = 'Guest Appearance';
}
2013-04-19 08:00:55 +00:00
if (!empty($RemixerAlbums)) {
2013-06-17 08:01:02 +00:00
$ReleaseTypes[1023] = 'Remixed By';
}
2013-04-19 08:00:55 +00:00
if (!empty($ComposerAlbums)) {
2013-06-17 08:01:02 +00:00
$ReleaseTypes[1022] = 'Composition';
2012-02-19 08:00:19 +00:00
}
2013-04-19 08:00:55 +00:00
if (!empty($ProducerAlbums)) {
2013-06-17 08:01:02 +00:00
$ReleaseTypes[1021] = 'Produced By';
2012-02-19 08:00:19 +00:00
}
reset($TorrentList);
$JsonTorrents = array();
2012-11-20 08:00:19 +00:00
$Tags = array();
2013-09-13 08:00:53 +00:00
$NumTorrents = $NumSeeders = $NumLeechers = $NumSnatches = 0;
2013-02-25 21:16:55 +00:00
foreach ($TorrentList as $GroupID => $Group) {
extract(Torrents::array_group($Group));
2013-06-17 08:01:02 +00:00
foreach ($Artists as &$Artist) {
2013-09-13 08:00:53 +00:00
$Artist['id'] = (int)$Artist['id'];
$Artist['aliasid'] = (int)$Artist['aliasid'];
2013-06-16 08:01:11 +00:00
}
2013-06-17 08:01:02 +00:00
foreach ($ExtendedArtists as &$ArtistGroup) {
foreach ($ArtistGroup as &$Artist) {
2013-09-13 08:00:53 +00:00
$Artist['id'] = (int)$Artist['id'];
$Artist['aliasid'] = (int)$Artist['aliasid'];
2013-06-16 08:01:11 +00:00
}
}
$Found = Misc::search_array($Artists, 'id', $ArtistID);
if (isset($OnlyArtistReleases) && empty($Found)) {
continue;
}
$GroupVanityHouse = $Importances[$GroupID]['VanityHouse'];
2013-07-10 00:08:53 +00:00
$TagList = explode(' ',str_replace('_', '.', $TagList));
// $Tags array is for the sidebar on the right
2013-04-19 08:00:55 +00:00
foreach ($TagList as $Tag) {
if (!isset($Tags[$Tag])) {
2013-07-10 00:08:53 +00:00
$Tags[$Tag] = array('name' => $Tag, 'count' => 1);
} else {
$Tags[$Tag]['count']++;
}
}
$InnerTorrents = array();
2012-11-20 08:00:19 +00:00
foreach ($Torrents as $Torrent) {
$NumTorrents++;
2012-11-20 08:00:19 +00:00
$NumSeeders += $Torrent['Seeders'];
$NumLeechers += $Torrent['Leechers'];
$NumSnatches += $Torrent['Snatched'];
2012-01-19 08:00:18 +00:00
$InnerTorrents[] = array(
2013-09-13 08:00:53 +00:00
'id' => (int)$Torrent['ID'],
'groupId' => (int)$Torrent['GroupID'],
2012-01-19 08:00:18 +00:00
'media' => $Torrent['Media'],
'format' => $Torrent['Format'],
'encoding' => $Torrent['Encoding'],
2013-09-13 08:00:53 +00:00
'remasterYear' => (int)$Torrent['RemasterYear'],
2012-01-19 08:00:18 +00:00
'remastered' => $Torrent['Remastered'] == 1,
'remasterTitle' => $Torrent['RemasterTitle'],
'remasterRecordLabel' => $Torrent['RemasterRecordLabel'],
'scene' => $Torrent['Scene'] == 1,
'hasLog' => $Torrent['HasLog'] == 1,
'hasCue' => $Torrent['HasCue'] == 1,
2013-09-13 08:00:53 +00:00
'logScore' => (int)$Torrent['LogScore'],
'fileCount' => (int)$Torrent['FileCount'],
2012-01-19 08:00:18 +00:00
'freeTorrent' => $Torrent['FreeTorrent'] == 1,
2013-09-13 08:00:53 +00:00
'size' => (int)$Torrent['Size'],
'leechers' => (int)$Torrent['Leechers'],
'seeders' => (int)$Torrent['Seeders'],
'snatched' => (int)$Torrent['Snatched'],
2012-01-19 08:00:18 +00:00
'time' => $Torrent['Time'],
2013-09-13 08:00:53 +00:00
'hasFile' => (int)$Torrent['HasFile']
2012-01-19 08:00:18 +00:00
);
}
$JsonTorrents[] = array(
2013-09-13 08:00:53 +00:00
'groupId' => (int)$GroupID,
'groupName' => $GroupName,
2013-09-13 08:00:53 +00:00
'groupYear' => (int)$GroupYear,
'groupRecordLabel' => $GroupRecordLabel,
'groupCatalogueNumber' => $GroupCatalogueNumber,
2013-02-25 21:16:55 +00:00
'groupCategoryID' => $GroupCategoryID,
'tags' => $TagList,
2013-09-13 08:00:53 +00:00
'releaseType' => (int)$ReleaseType,
2013-02-25 21:16:55 +00:00
'wikiImage' => $WikiImage,
2012-01-19 08:00:18 +00:00
'groupVanityHouse' => $GroupVanityHouse == 1,
2013-05-11 08:00:29 +00:00
'hasBookmarked' => Bookmarks::has_bookmarked('torrent', $GroupID),
2013-06-16 08:01:11 +00:00
'artists' => $Artists,
'extendedArtists' => $ExtendedArtists,
'torrent' => $InnerTorrents,
);
}
$JsonSimilar = array();
2013-04-19 08:00:55 +00:00
if (empty($SimilarArray)) {
$DB->query("
SELECT
2013-04-19 08:00:55 +00:00
s2.ArtistID,
a.Name,
ass.Score,
ass.SimilarID
FROM artists_similar AS s1
2013-07-10 00:08:53 +00:00
JOIN artists_similar AS s2 ON s1.SimilarID = s2.SimilarID AND s1.ArtistID != s2.ArtistID
JOIN artists_similar_scores AS ass ON ass.SimilarID = s1.SimilarID
JOIN artists_group AS a ON a.ArtistID = s2.ArtistID
WHERE s1.ArtistID = '$ArtistID'
ORDER BY ass.Score DESC
LIMIT 30
");
$SimilarArray = $DB->to_array();
foreach ($SimilarArray as $Similar) {
$JsonSimilar[] = array(
2013-09-13 08:00:53 +00:00
'artistId' => (int)$Similar['ArtistID'],
2012-01-19 08:00:18 +00:00
'name' => $Similar['Name'],
2013-09-13 08:00:53 +00:00
'score' => (int)$Similar['Score'],
'similarId' => (int)$Similar['SimilarID']
);
}
$NumSimilar = count($SimilarArray);
2013-04-24 08:00:23 +00:00
} else {
2013-05-14 08:00:34 +00:00
//If data already exists, use it
foreach ($SimilarArray as $Similar) {
2013-04-24 08:00:23 +00:00
$JsonSimilar[] = array(
2013-09-13 08:00:53 +00:00
'artistId' => (int)$Similar['ArtistID'],
2013-04-24 08:00:23 +00:00
'name' => $Similar['Name'],
2013-09-13 08:00:53 +00:00
'score' => (int)$Similar['Score'],
'similarId' => (int)$Similar['SimilarID']
2013-04-24 08:00:23 +00:00
);
}
}
$JsonRequests = array();
2013-09-13 08:00:53 +00:00
foreach ($Requests as $RequestID => $Request) {
$JsonRequests[] = array(
2013-09-13 08:00:53 +00:00
'requestId' => (int)$RequestID,
'categoryId' => (int)$Request['CategoryID'],
'title' => $Request['Title'],
'year' => (int)$Request['Year'],
'timeAdded' => $Request['TimeAdded'],
'votes' => (int)$Request['Votes'],
'bounty' => (int)$Request['Bounty']
);
}
//notifications disabled by default
2012-11-20 08:00:19 +00:00
$notificationsEnabled = false;
if (check_perms('site_torrents_notify')) {
2012-11-20 08:00:19 +00:00
if (($Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID'])) === false) {
2013-07-10 00:08:53 +00:00
$DB->query("
SELECT ID, Artists
FROM users_notify_filters
WHERE UserID = '$LoggedUser[ID]'
AND Label = 'Artist notifications'
LIMIT 1");
2012-11-20 08:00:19 +00:00
$Notify = $DB->next_record(MYSQLI_ASSOC, false);
$Cache->cache_value('notify_artists_'.$LoggedUser['ID'], $Notify, 0);
}
2013-07-10 00:08:53 +00:00
if (stripos($Notify['Artists'], "|$Name|") === false) {
2012-11-20 08:00:19 +00:00
$notificationsEnabled = false;
} else {
$notificationsEnabled = true;
}
}
2012-11-20 08:00:19 +00:00
// Cache page for later use
if ($RevisionID) {
$Key = "artist_$ArtistID"."_revision_$RevisionID";
} else {
2013-07-10 00:08:53 +00:00
$Key = "artist_$ArtistID";
2012-11-20 08:00:19 +00:00
}
$Data = array(array($Name, $Image, $Body, $NumSimilar, $SimilarArray, array(), array(), $VanityHouseArtist));
$Cache->cache_value($Key, $Data, 3600);
2013-04-24 08:00:23 +00:00
json_die("success", array(
2013-09-13 08:00:53 +00:00
'id' => (int)$ArtistID,
2013-05-14 08:00:34 +00:00
'name' => $Name,
'notificationsEnabled' => $notificationsEnabled,
'hasBookmarked' => Bookmarks::has_bookmarked('artist', $ArtistID),
'image' => $Image,
2013-12-12 08:01:01 +00:00
'body' => Text::full_format($Body),
2013-05-14 08:00:34 +00:00
'vanityHouse' => $VanityHouseArtist == 1,
'tags' => array_values($Tags),
'similarArtists' => $JsonSimilar,
'statistics' => array(
'numGroups' => $NumGroups,
'numTorrents' => $NumTorrents,
'numSeeders' => $NumSeeders,
'numLeechers' => $NumLeechers,
'numSnatches' => $NumSnatches
),
'torrentgroup' => $JsonTorrents,
'requests' => $JsonRequests
2013-04-24 08:00:23 +00:00
));
?>