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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. $DB->query("
  126. SELECT DISTINCTROW
  127. ta.`GroupID`,
  128. ta.`Importance`,
  129. tg.`year`
  130. FROM
  131. `torrents_artists` AS ta
  132. JOIN `torrents_group` AS tg
  133. ON
  134. tg.`id` = ta.`GroupID`
  135. WHERE
  136. ta.`ArtistID` = '$ArtistID'
  137. ORDER BY
  138. tg.`year`,
  139. tg.`Name`
  140. DESC
  141. ");
  142. $GroupIDs = $DB->collect('GroupID');
  143. $Importances = $DB->to_array(false, MYSQLI_BOTH, false);
  144. $Cache->cache_value("artist_groups_$ArtistID", $Importances, 0);
  145. } else {
  146. $GroupIDs = [];
  147. foreach ($Importances as $Group) {
  148. $GroupIDs[] = $Group['GroupID'];
  149. }
  150. }
  151. if (count($GroupIDs) > 0) {
  152. $TorrentList = Torrents::get_groups($GroupIDs, true, true);
  153. } else {
  154. $TorrentList = [];
  155. }
  156. $NumGroups = count($TorrentList);
  157. //Get list of used release types
  158. $UsedReleases = [];
  159. foreach ($TorrentList as $GroupID=>$Group) {
  160. if ($Importances[$GroupID]['Importance'] == '2') {
  161. $TorrentList[$GroupID]['ReleaseType'] = 1024;
  162. $GuestAlbums = true;
  163. }
  164. if ($Importances[$GroupID]['Importance'] == '3') {
  165. $TorrentList[$GroupID]['ReleaseType'] = 1023;
  166. $RemixerAlbums = true;
  167. }
  168. if ($Importances[$GroupID]['Importance'] == '4') {
  169. $TorrentList[$GroupID]['ReleaseType'] = 1022;
  170. $ComposerAlbums = true;
  171. }
  172. if ($Importances[$GroupID]['Importance'] == '7') {
  173. $TorrentList[$GroupID]['ReleaseType'] = 1021;
  174. $ProducerAlbums = true;
  175. }
  176. if (!in_array($TorrentList[$GroupID]['ReleaseType'], $UsedReleases)) {
  177. $UsedReleases[] = $TorrentList[$GroupID]['ReleaseType'];
  178. }
  179. }
  180. if (!empty($GuestAlbums)) {
  181. $ReleaseTypes[1024] = 'Guest Appearance';
  182. }
  183. if (!empty($RemixerAlbums)) {
  184. $ReleaseTypes[1023] = 'Remixed By';
  185. }
  186. if (!empty($ComposerAlbums)) {
  187. $ReleaseTypes[1022] = 'Composition';
  188. }
  189. if (!empty($ProducerAlbums)) {
  190. $ReleaseTypes[1021] = 'Produced By';
  191. }
  192. reset($TorrentList);
  193. $JsonTorrents = [];
  194. $Tags = [];
  195. $NumTorrents = $NumSeeders = $NumLeechers = $NumSnatches = 0;
  196. foreach ($GroupIDs as $GroupID) {
  197. if (!isset($TorrentList[$GroupID])) {
  198. continue;
  199. }
  200. $Group = $TorrentList[$GroupID];
  201. extract(Torrents::array_group($Group));
  202. foreach ($Artists as &$Artist) {
  203. $Artist['id'] = (int)$Artist['id'];
  204. $Artist['aliasid'] = (int)$Artist['aliasid'];
  205. }
  206. foreach ($ExtendedArtists as &$ArtistGroup) {
  207. foreach ($ArtistGroup as &$Artist) {
  208. $Artist['id'] = (int)$Artist['id'];
  209. $Artist['aliasid'] = (int)$Artist['aliasid'];
  210. }
  211. }
  212. $Found = Misc::search_array($Artists, 'id', $ArtistID);
  213. if (isset($OnlyArtistReleases) && empty($Found)) {
  214. continue;
  215. }
  216. $GroupVanityHouse = $Importances[$GroupID]['VanityHouse'];
  217. $TagList = explode(' ', str_replace('_', '.', $TagList));
  218. // $Tags array is for the sidebar on the right
  219. foreach ($TagList as $Tag) {
  220. if (!isset($Tags[$Tag])) {
  221. $Tags[$Tag] = array('name' => $Tag, 'count' => 1);
  222. } else {
  223. $Tags[$Tag]['count']++;
  224. }
  225. }
  226. $InnerTorrents = [];
  227. foreach ($Torrents as $Torrent) {
  228. $NumTorrents++;
  229. $NumSeeders += $Torrent['Seeders'];
  230. $NumLeechers += $Torrent['Leechers'];
  231. $NumSnatches += $Torrent['Snatched'];
  232. $InnerTorrents[] = array(
  233. 'id' => (int)$Torrent['ID'],
  234. 'groupId' => (int)$Torrent['GroupID'],
  235. 'media' => $Torrent['Media'],
  236. 'format' => $Torrent['Format'],
  237. 'encoding' => $Torrent['Encoding'],
  238. 'remasterYear' => (int)$Torrent['RemasterYear'],
  239. 'remastered' => $Torrent['Remastered'] == 1,
  240. 'remasterTitle' => $Torrent['RemasterTitle'],
  241. 'remasterRecordLabel' => $Torrent['RemasterRecordLabel'],
  242. 'scene' => $Torrent['Scene'] == 1,
  243. 'hasLog' => $Torrent['HasLog'] == 1,
  244. 'hasCue' => $Torrent['HasCue'] == 1,
  245. 'logScore' => (int)$Torrent['LogScore'],
  246. 'fileCount' => (int)$Torrent['FileCount'],
  247. 'freeTorrent' => $Torrent['FreeTorrent'] == 1,
  248. 'size' => (int)$Torrent['Size'],
  249. 'leechers' => (int)$Torrent['Leechers'],
  250. 'seeders' => (int)$Torrent['Seeders'],
  251. 'snatched' => (int)$Torrent['Snatched'],
  252. 'time' => $Torrent['Time'],
  253. 'hasFile' => (int)$Torrent['HasFile']
  254. );
  255. }
  256. $JsonTorrents[] = array(
  257. 'groupId' => (int)$GroupID,
  258. 'groupName' => $GroupName,
  259. 'groupYear' => (int)$GroupYear,
  260. 'groupRecordLabel' => $GroupRecordLabel,
  261. 'groupCatalogueNumber' => $GroupCatalogueNumber,
  262. 'groupCategoryID' => $GroupCategoryID,
  263. 'tags' => $TagList,
  264. 'releaseType' => (int)$ReleaseType,
  265. 'wikiImage' => $WikiImage,
  266. 'groupVanityHouse' => $GroupVanityHouse == 1,
  267. 'hasBookmarked' => Bookmarks::has_bookmarked('torrent', $GroupID),
  268. 'artists' => $Artists,
  269. 'extendedArtists' => $ExtendedArtists,
  270. 'torrent' => $InnerTorrents,
  271. );
  272. }
  273. $JsonRequests = [];
  274. foreach ($Requests as $RequestID => $Request) {
  275. $JsonRequests[] = array(
  276. 'requestId' => (int)$RequestID,
  277. 'categoryId' => (int)$Request['CategoryID'],
  278. 'title' => $Request['Title'],
  279. 'year' => (int)$Request['Year'],
  280. 'timeAdded' => $Request['TimeAdded'],
  281. 'votes' => (int)$Request['Votes'],
  282. 'bounty' => (int)$Request['Bounty']
  283. );
  284. }
  285. //notifications disabled by default
  286. $notificationsEnabled = false;
  287. if (check_perms('site_torrents_notify')) {
  288. if (($Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID'])) === false) {
  289. $DB->query("
  290. SELECT ID, Artists
  291. FROM users_notify_filters
  292. WHERE UserID = '$LoggedUser[ID]'
  293. AND Label = 'Artist notifications'
  294. LIMIT 1");
  295. $Notify = $DB->next_record(MYSQLI_ASSOC, false);
  296. $Cache->cache_value('notify_artists_'.$LoggedUser['ID'], $Notify, 0);
  297. }
  298. if (stripos($Notify['Artists'], "|$Name|") === false) {
  299. $notificationsEnabled = false;
  300. } else {
  301. $notificationsEnabled = true;
  302. }
  303. }
  304. // Cache page for later use
  305. if ($RevisionID) {
  306. $Key = "artist_$ArtistID"."_revision_$RevisionID";
  307. } else {
  308. $Key = "artist_$ArtistID";
  309. }
  310. $Data = array(array($Name, $Image, $Body));
  311. $Cache->cache_value($Key, $Data, 3600);
  312. json_die('success', array(
  313. 'id' => (int)$ArtistID,
  314. 'name' => $Name,
  315. 'notificationsEnabled' => $notificationsEnabled,
  316. 'hasBookmarked' => Bookmarks::has_bookmarked('artist', $ArtistID),
  317. 'image' => $Image,
  318. 'body' => Text::full_format($Body),
  319. 'vanityHouse' => $VanityHouseArtist == 1,
  320. 'tags' => array_values($Tags),
  321. 'statistics' => array(
  322. 'numGroups' => $NumGroups,
  323. 'numTorrents' => $NumTorrents,
  324. 'numSeeders' => $NumSeeders,
  325. 'numLeechers' => $NumLeechers,
  326. 'numSnatches' => $NumSnatches
  327. ),
  328. 'torrentgroup' => $JsonTorrents,
  329. 'requests' => $JsonRequests
  330. ));