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

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