BioTorrents.de’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 10KB

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