Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

artist.php 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?
  2. //For sorting tags
  3. function compare($X, $Y) {
  4. return($Y['count'] - $X['count']);
  5. }
  6. if (!empty($_GET['artistreleases'])) {
  7. $OnlyArtistReleases = true;
  8. }
  9. if ($_GET['id'] && $_GET['artistname']) {
  10. json_die("failure", "bad parameters");
  11. }
  12. $ArtistID = $_GET['id'];
  13. if ($ArtistID && !is_number($ArtistID)) {
  14. json_die("failure");
  15. }
  16. if (empty($ArtistID)) {
  17. if (!empty($_GET['artistname'])) {
  18. $Name = db_string(trim($_GET['artistname']));
  19. $DB->query("
  20. SELECT ArtistID
  21. FROM artists_alias
  22. WHERE Name LIKE '$Name'");
  23. if (!(list($ArtistID) = $DB->next_record(MYSQLI_NUM, false))) {
  24. json_die("failure");
  25. }
  26. // If we get here, we got the ID!
  27. }
  28. }
  29. if (!empty($_GET['revisionid'])) { // if they're viewing an old revision
  30. $RevisionID = $_GET['revisionid'];
  31. if (!is_number($RevisionID)) {
  32. error(0);
  33. }
  34. $Data = $Cache->get_value("artist_$ArtistID"."_revision_$RevisionID");
  35. } else { // viewing the live version
  36. $Data = $Cache->get_value("artist_$ArtistID");
  37. $RevisionID = false;
  38. }
  39. if ($Data) {
  40. list($Name, $Image, $Body) = current($Data);
  41. } else {
  42. if ($RevisionID) {
  43. /*
  44. $sql = "
  45. SELECT
  46. a.Name,
  47. wiki.Image,
  48. wiki.body,
  49. a.VanityHouse
  50. FROM wiki_artists AS wiki
  51. LEFT JOIN artists_group AS a ON wiki.RevisionID = a.RevisionID
  52. WHERE wiki.RevisionID = '$RevisionID' ";
  53. */
  54. $sql = "
  55. SELECT
  56. a.Name,
  57. wiki.Image,
  58. wiki.body
  59. FROM wiki_artists AS wiki
  60. LEFT JOIN artists_group AS a ON wiki.RevisionID = a.RevisionID
  61. WHERE wiki.RevisionID = '$RevisionID' ";
  62. } else {
  63. /*
  64. $sql = "
  65. SELECT
  66. a.Name,
  67. wiki.Image,
  68. wiki.body,
  69. a.VanityHouse
  70. FROM artists_group AS a
  71. LEFT JOIN wiki_artists AS wiki ON wiki.RevisionID = a.RevisionID
  72. WHERE a.ArtistID = '$ArtistID' ";
  73. */
  74. $sql = "
  75. SELECT
  76. a.Name,
  77. wiki.Image,
  78. wiki.body
  79. FROM artists_group AS a
  80. LEFT JOIN wiki_artists AS wiki ON wiki.RevisionID = a.RevisionID
  81. WHERE a.ArtistID = '$ArtistID' ";
  82. }
  83. $sql .= " GROUP BY a.ArtistID";
  84. $DB->query($sql);
  85. if (!$DB->has_results()) {
  86. json_die("failure");
  87. }
  88. // list($Name, $Image, $Body, $VanityHouseArtist) = $DB->next_record(MYSQLI_NUM, array(0));
  89. list($Name, $Image, $Body) = $DB->next_record(MYSQLI_NUM, array(0));
  90. }
  91. // Requests
  92. $Requests = [];
  93. if (empty($LoggedUser['DisableRequests'])) {
  94. $Requests = $Cache->get_value("artists_requests_$ArtistID");
  95. if (!is_array($Requests)) {
  96. $DB->query("
  97. SELECT
  98. r.ID,
  99. r.CategoryID,
  100. r.Title,
  101. r.Year,
  102. r.TimeAdded,
  103. COUNT(rv.UserID) AS Votes,
  104. SUM(rv.Bounty) AS Bounty
  105. FROM requests AS r
  106. LEFT JOIN requests_votes AS rv ON rv.RequestID = r.ID
  107. LEFT JOIN requests_artists AS ra ON r.ID = ra.RequestID
  108. WHERE ra.ArtistID = $ArtistID
  109. AND r.TorrentID = 0
  110. GROUP BY r.ID
  111. ORDER BY Votes DESC");
  112. if ($DB->has_results()) {
  113. $Requests = $DB->to_array('ID', MYSQLI_ASSOC, false);
  114. } else {
  115. $Requests = [];
  116. }
  117. $Cache->cache_value("artists_requests_$ArtistID", $Requests);
  118. }
  119. }
  120. $NumRequests = count($Requests);
  121. if (($Importances = $Cache->get_value("artist_groups_$ArtistID")) === false) {
  122. /*
  123. $DB->query("
  124. SELECT
  125. DISTINCTROW ta.GroupID, ta.Importance, tg.VanityHouse, tg.Year
  126. FROM torrents_artists AS ta
  127. JOIN torrents_group AS tg ON tg.ID = ta.GroupID
  128. WHERE ta.ArtistID = '$ArtistID'
  129. ORDER BY tg.Year DESC, tg.Name DESC");
  130. */
  131. $DB->query("
  132. SELECT
  133. DISTINCTROW ta.GroupID, ta.Importance, tg.Year
  134. FROM torrents_artists AS ta
  135. JOIN torrents_group AS tg ON tg.ID = ta.GroupID
  136. WHERE ta.ArtistID = '$ArtistID'
  137. ORDER BY tg.Year DESC, tg.Name DESC");
  138. $GroupIDs = $DB->collect('GroupID');
  139. $Importances = $DB->to_array(false, MYSQLI_BOTH, false);
  140. $Cache->cache_value("artist_groups_$ArtistID", $Importances, 0);
  141. } else {
  142. $GroupIDs = [];
  143. foreach ($Importances as $Group) {
  144. $GroupIDs[] = $Group['GroupID'];
  145. }
  146. }
  147. if (count($GroupIDs) > 0) {
  148. $TorrentList = Torrents::get_groups($GroupIDs, true, true);
  149. } else {
  150. $TorrentList = [];
  151. }
  152. $NumGroups = count($TorrentList);
  153. //Get list of used release types
  154. $UsedReleases = [];
  155. foreach ($TorrentList as $GroupID=>$Group) {
  156. if ($Importances[$GroupID]['Importance'] == '2') {
  157. $TorrentList[$GroupID]['ReleaseType'] = 1024;
  158. $GuestAlbums = true;
  159. }
  160. if ($Importances[$GroupID]['Importance'] == '3') {
  161. $TorrentList[$GroupID]['ReleaseType'] = 1023;
  162. $RemixerAlbums = true;
  163. }
  164. if ($Importances[$GroupID]['Importance'] == '4') {
  165. $TorrentList[$GroupID]['ReleaseType'] = 1022;
  166. $ComposerAlbums = true;
  167. }
  168. if ($Importances[$GroupID]['Importance'] == '7') {
  169. $TorrentList[$GroupID]['ReleaseType'] = 1021;
  170. $ProducerAlbums = true;
  171. }
  172. if (!in_array($TorrentList[$GroupID]['ReleaseType'], $UsedReleases)) {
  173. $UsedReleases[] = $TorrentList[$GroupID]['ReleaseType'];
  174. }
  175. }
  176. if (!empty($GuestAlbums)) {
  177. $ReleaseTypes[1024] = 'Guest Appearance';
  178. }
  179. if (!empty($RemixerAlbums)) {
  180. $ReleaseTypes[1023] = 'Remixed By';
  181. }
  182. if (!empty($ComposerAlbums)) {
  183. $ReleaseTypes[1022] = 'Composition';
  184. }
  185. if (!empty($ProducerAlbums)) {
  186. $ReleaseTypes[1021] = 'Produced By';
  187. }
  188. reset($TorrentList);
  189. $JsonTorrents = [];
  190. $Tags = [];
  191. $NumTorrents = $NumSeeders = $NumLeechers = $NumSnatches = 0;
  192. foreach ($GroupIDs as $GroupID) {
  193. if (!isset($TorrentList[$GroupID])) {
  194. continue;
  195. }
  196. $Group = $TorrentList[$GroupID];
  197. extract(Torrents::array_group($Group));
  198. foreach ($Artists as &$Artist) {
  199. $Artist['id'] = (int)$Artist['id'];
  200. $Artist['aliasid'] = (int)$Artist['aliasid'];
  201. }
  202. foreach ($ExtendedArtists as &$ArtistGroup) {
  203. foreach ($ArtistGroup as &$Artist) {
  204. $Artist['id'] = (int)$Artist['id'];
  205. $Artist['aliasid'] = (int)$Artist['aliasid'];
  206. }
  207. }
  208. $Found = Misc::search_array($Artists, 'id', $ArtistID);
  209. if (isset($OnlyArtistReleases) && empty($Found)) {
  210. continue;
  211. }
  212. $GroupVanityHouse = $Importances[$GroupID]['VanityHouse'];
  213. $TagList = explode(' ',str_replace('_', '.', $TagList));
  214. // $Tags array is for the sidebar on the right
  215. foreach ($TagList as $Tag) {
  216. if (!isset($Tags[$Tag])) {
  217. $Tags[$Tag] = array('name' => $Tag, 'count' => 1);
  218. } else {
  219. $Tags[$Tag]['count']++;
  220. }
  221. }
  222. $InnerTorrents = [];
  223. foreach ($Torrents as $Torrent) {
  224. $NumTorrents++;
  225. $NumSeeders += $Torrent['Seeders'];
  226. $NumLeechers += $Torrent['Leechers'];
  227. $NumSnatches += $Torrent['Snatched'];
  228. $InnerTorrents[] = array(
  229. 'id' => (int)$Torrent['ID'],
  230. 'groupId' => (int)$Torrent['GroupID'],
  231. 'media' => $Torrent['Media'],
  232. 'format' => $Torrent['Format'],
  233. 'encoding' => $Torrent['Encoding'],
  234. 'remasterYear' => (int)$Torrent['RemasterYear'],
  235. 'remastered' => $Torrent['Remastered'] == 1,
  236. 'remasterTitle' => $Torrent['RemasterTitle'],
  237. 'remasterRecordLabel' => $Torrent['RemasterRecordLabel'],
  238. 'scene' => $Torrent['Scene'] == 1,
  239. 'hasLog' => $Torrent['HasLog'] == 1,
  240. 'hasCue' => $Torrent['HasCue'] == 1,
  241. 'logScore' => (int)$Torrent['LogScore'],
  242. 'fileCount' => (int)$Torrent['FileCount'],
  243. 'freeTorrent' => $Torrent['FreeTorrent'] == 1,
  244. 'size' => (int)$Torrent['Size'],
  245. 'leechers' => (int)$Torrent['Leechers'],
  246. 'seeders' => (int)$Torrent['Seeders'],
  247. 'snatched' => (int)$Torrent['Snatched'],
  248. 'time' => $Torrent['Time'],
  249. 'hasFile' => (int)$Torrent['HasFile']
  250. );
  251. }
  252. $JsonTorrents[] = array(
  253. 'groupId' => (int)$GroupID,
  254. 'groupName' => $GroupName,
  255. 'groupYear' => (int)$GroupYear,
  256. 'groupRecordLabel' => $GroupRecordLabel,
  257. 'groupCatalogueNumber' => $GroupCatalogueNumber,
  258. 'groupCategoryID' => $GroupCategoryID,
  259. 'tags' => $TagList,
  260. 'releaseType' => (int)$ReleaseType,
  261. 'wikiImage' => $WikiImage,
  262. 'groupVanityHouse' => $GroupVanityHouse == 1,
  263. 'hasBookmarked' => Bookmarks::has_bookmarked('torrent', $GroupID),
  264. 'artists' => $Artists,
  265. 'extendedArtists' => $ExtendedArtists,
  266. 'torrent' => $InnerTorrents,
  267. );
  268. }
  269. $JsonRequests = [];
  270. foreach ($Requests as $RequestID => $Request) {
  271. $JsonRequests[] = array(
  272. 'requestId' => (int)$RequestID,
  273. 'categoryId' => (int)$Request['CategoryID'],
  274. 'title' => $Request['Title'],
  275. 'year' => (int)$Request['Year'],
  276. 'timeAdded' => $Request['TimeAdded'],
  277. 'votes' => (int)$Request['Votes'],
  278. 'bounty' => (int)$Request['Bounty']
  279. );
  280. }
  281. //notifications disabled by default
  282. $notificationsEnabled = false;
  283. if (check_perms('site_torrents_notify')) {
  284. if (($Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID'])) === false) {
  285. $DB->query("
  286. SELECT ID, Artists
  287. FROM users_notify_filters
  288. WHERE UserID = '$LoggedUser[ID]'
  289. AND Label = 'Artist notifications'
  290. LIMIT 1");
  291. $Notify = $DB->next_record(MYSQLI_ASSOC, false);
  292. $Cache->cache_value('notify_artists_'.$LoggedUser['ID'], $Notify, 0);
  293. }
  294. if (stripos($Notify['Artists'], "|$Name|") === false) {
  295. $notificationsEnabled = false;
  296. } else {
  297. $notificationsEnabled = true;
  298. }
  299. }
  300. // Cache page for later use
  301. if ($RevisionID) {
  302. $Key = "artist_$ArtistID"."_revision_$RevisionID";
  303. } else {
  304. $Key = "artist_$ArtistID";
  305. }
  306. $Data = array(array($Name, $Image, $Body));
  307. $Cache->cache_value($Key, $Data, 3600);
  308. json_die("success", array(
  309. 'id' => (int)$ArtistID,
  310. 'name' => $Name,
  311. 'notificationsEnabled' => $notificationsEnabled,
  312. 'hasBookmarked' => Bookmarks::has_bookmarked('artist', $ArtistID),
  313. 'image' => $Image,
  314. 'body' => Text::full_format($Body),
  315. 'vanityHouse' => $VanityHouseArtist == 1,
  316. 'tags' => array_values($Tags),
  317. 'statistics' => array(
  318. 'numGroups' => $NumGroups,
  319. 'numTorrents' => $NumTorrents,
  320. 'numSeeders' => $NumSeeders,
  321. 'numLeechers' => $NumLeechers,
  322. 'numSnatches' => $NumSnatches
  323. ),
  324. 'torrentgroup' => $JsonTorrents,
  325. 'requests' => $JsonRequests
  326. ));
  327. ?>