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 11KB

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