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.

torrents.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <?php
  2. #declare(strict_types = 1);
  3. # todo: Go through line by line
  4. $ENV = ENV::go();
  5. ini_set('max_execution_time', 600);
  6. set_time_limit(0);
  7. //~~~~~~~~~~~ Main bookmarks page ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
  8. function compare($X, $Y)
  9. {
  10. return($Y['count'] - $X['count']);
  11. }
  12. if (!empty($_GET['userid'])) {
  13. if (!check_perms('users_override_paranoia')) {
  14. error(403);
  15. }
  16. $UserID = $_GET['userid'];
  17. if (!is_number($UserID)) {
  18. error(404);
  19. }
  20. $DB->query("
  21. SELECT Username
  22. FROM users_main
  23. WHERE ID = '$UserID'");
  24. list($Username) = $DB->next_record();
  25. } else {
  26. $UserID = $LoggedUser['ID'];
  27. }
  28. $Sneaky = $UserID != $LoggedUser['ID'];
  29. $Title = $Sneaky ? "$Username's bookmarked torrent groups" : 'Your bookmarked torrent groups';
  30. // Loop through the result set, building up $Collage and $TorrentTable
  31. // Then we print them.
  32. $Collage = [];
  33. $TorrentTable = '';
  34. $NumGroups = 0;
  35. $ArtistCount = [];
  36. list($GroupIDs, $CollageDataList, $TorrentList) = Users::get_bookmarks($UserID);
  37. foreach ($GroupIDs as $GroupID) {
  38. if (!isset($TorrentList[$GroupID])) {
  39. continue;
  40. }
  41. $Group = $TorrentList[$GroupID];
  42. extract(Torrents::array_group($Group));
  43. list(, $Sort, $AddedTime) = array_values($CollageDataList[$GroupID]);
  44. // Handle stats and stuff
  45. $NumGroups++;
  46. if ($Artists) {
  47. foreach ($Artists as $Artist) {
  48. if (!isset($ArtistCount[$Artist['id']])) {
  49. $ArtistCount[$Artist['id']] = array('name' => $Artist['name'], 'count' => 1);
  50. } else {
  51. $ArtistCount[$Artist['id']]['count']++;
  52. }
  53. }
  54. }
  55. $TorrentTags = new Tags($TagList);
  56. $DisplayName = Artists::display_artists($Artists);
  57. $GroupName = empty($GroupName) ? (empty($GroupTitle2) ? $GroupNameJP : $GroupTitle2) : $GroupName;
  58. $DisplayName .= '<a href="torrents.php?id='.$GroupID.'" ';
  59. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  60. $DisplayName .= 'data-cover="'.ImageTools::process($WikiImage, 'thumb').'" ';
  61. }
  62. $DisplayName .= ' class="tooltip" title="View torrent group" dir="ltr">'.$GroupName.'</a>';
  63. if ($GroupYear > 0) {
  64. $DisplayName = "$DisplayName [$GroupYear]";
  65. }
  66. $SnatchedGroupClass = $GroupFlags['IsSnatched'] ? ' snatched_group' : '';
  67. // Start an output buffer, so we can store this output in $TorrentTable
  68. ob_start();
  69. if (count($Torrents) > 1) {
  70. // Grouped torrents
  71. $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] === 1); ?>
  72. <tr class="group" id="group_<?=$GroupID?>">
  73. <td class="center">
  74. <div id="showimg_<?=$GroupID?>"
  75. class="<?=($ShowGroups ? 'hide' : 'show')?>_torrents">
  76. <a class="tooltip show_torrents_link"
  77. onclick="toggle_group(<?=$GroupID?>, this, event);"
  78. title="Collapse this group. Hold &quot;Ctrl&quot; while clicking to collape all groups on this page."></a>
  79. </div>
  80. </td>
  81. <td class="center">
  82. <div title="<?=$TorrentTags->title()?>"
  83. class="tooltip <?=Format::css_category($GroupCategoryID)?>">
  84. </div>
  85. </td>
  86. <td colspan="5">
  87. <?=$DisplayName?>
  88. <span style="text-align: right;" class="float_right">
  89. <?=time_diff($AddedTime); ?>
  90. <?php if (!$Sneaky) { ?>
  91. <br />
  92. <a href="#group_<?=$GroupID?>" class="brackets remove_bookmark"
  93. onclick="Unbookmark('torrent', <?=$GroupID?>, ''); return false;">Remove
  94. bookmark</a>
  95. <?php } ?>
  96. </span>
  97. <div class="tags"><?=$TorrentTags->format()?>
  98. </div>
  99. </td>
  100. </tr>
  101. <?php
  102. foreach ($Torrents as $TorrentID => $Torrent) {
  103. $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : ''; ?>
  104. <tr
  105. class="group_torrent torrent_row groupid_<?=$GroupID?> <?=$SnatchedTorrentClass . $SnatchedGroupClass . (!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] === 1 ? ' hidden' : '')?>">
  106. <td colspan="3">
  107. <span>[ <a
  108. href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>"
  109. class="tooltip" title="Download">DL</a>
  110. <?php if (Torrents::can_use_token($Torrent)) { ?>
  111. | <a
  112. href="torrents.php?action=download&amp;id=<?=$TorrentID ?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1"
  113. class="tooltip" title="Use a FL Token"
  114. onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
  115. <?php } ?>
  116. | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>"
  117. class="tooltip" title="Report">RP</a> ]
  118. </span>
  119. <a
  120. href="torrents.php?id=<?=$GroupID?>&amp;torrentid=<?=$TorrentID?>"><?=Torrents::torrent_info($Torrent)?></a>
  121. </td>
  122. <td class="number_column nobr"><?=Format::get_size($Torrent['Size'])?>
  123. </td>
  124. <td class="number_column"><?=number_format($Torrent['Snatched'])?>
  125. </td>
  126. <td
  127. class="number_column<?=(($Torrent['Seeders'] == 0) ? ' r00' : '')?>">
  128. <?=number_format($Torrent['Seeders'])?>
  129. </td>
  130. <td class="number_column"><?=number_format($Torrent['Leechers'])?>
  131. </td>
  132. </tr>
  133. <?php
  134. }
  135. } else {
  136. // Viewing a type that does not require grouping
  137. $TorrentID = key($Torrents);
  138. $Torrent = current($Torrents);
  139. $DisplayName = Artists::display_artists(Artists::get_artist($GroupID));
  140. $DisplayName .= '<a href="torrents.php?id='.$GroupID.'" ';
  141. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  142. $DisplayName .= 'data-cover="'.ImageTools::process($WikiImage, 'thumb').'" ';
  143. }
  144. $DisplayName .=' class="tooltip" title="View torrent group" dir="ltr">'.$GroupName.'</a>';
  145. if ($Torrent['IsSnatched']) {
  146. $DisplayName .= ' ' . Format::torrent_label('Snatched', 'bold');
  147. }
  148. if ($Torrent['FreeTorrent'] === '1') {
  149. $DisplayName .= ' ' . Format::torrent_label('Freeleech', 'important_text_alt');
  150. } elseif ($Torrent['FreeTorrent'] === '2') {
  151. $DisplayName .= ' ' . Format::torrent_label('Neutral Leech', 'bold');
  152. } elseif ($Torrent['PersonalFL']) {
  153. $DisplayName .= ' ' . Format::torrent_label('Personal Freeleech', 'important_text_alt');
  154. }
  155. $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : ''; ?>
  156. <tr
  157. class="torrent torrent_row<?=$SnatchedTorrentClass . $SnatchedGroupClass?>"
  158. id="group_<?=$GroupID?>">
  159. <td></td>
  160. <td class="center">
  161. <div title="<?=$TorrentTags->title()?>"
  162. class="tooltip <?=Format::css_category($GroupCategoryID)?>">
  163. </div>
  164. </td>
  165. <td>
  166. <span>
  167. [ <a
  168. href="torrents.php?action=download&amp;id=<?=$TorrentID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>"
  169. class="tooltip" title="Download">DL</a>
  170. <?php if (Torrents::can_use_token($Torrent)) { ?>
  171. | <a
  172. href="torrents.php?action=download&amp;id=<?=$TorrentID ?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>&amp;usetoken=1"
  173. class="tooltip" title="Use a FL Token"
  174. onclick="return confirm('Are you sure you want to use a freeleech token here?');">FL</a>
  175. <?php } ?>
  176. | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>"
  177. class="tooltip" title="Report">RP</a> ]
  178. </span>
  179. <span class="float_right float_clear"><?=time_diff($AddedTime); ?></span>
  180. <?php if (!$Sneaky) { ?>
  181. <span class="float_right float_clear"><a
  182. href="#group_<?=$GroupID?>" class="brackets remove_bookmark"
  183. onclick="Unbookmark('torrent', <?=$GroupID?>, ''); return false;">Remove
  184. bookmark</a></span>
  185. <?php } ?>
  186. <?=$DisplayName?>
  187. <div class="tags"><?=$TorrentTags->format()?>
  188. </div>
  189. </td>
  190. <td class="number_column nobr"><?=Format::get_size($Torrent['Size'])?>
  191. </td>
  192. <td class="number_column"><?=number_format($Torrent['Snatched'])?>
  193. </td>
  194. <td
  195. class="number_column<?=(($Torrent['Seeders'] == 0) ? ' r00' : '')?>">
  196. <?=number_format($Torrent['Seeders'])?>
  197. </td>
  198. <td class="number_column"><?=number_format($Torrent['Leechers'])?>
  199. </td>
  200. </tr>
  201. <?php
  202. }
  203. $TorrentTable .= ob_get_clean();
  204. // Album art
  205. ob_start();
  206. $DisplayName = '';
  207. #$DisplayName .= Artists::display_artists($Artists, false);
  208. $DisplayName .= $GroupName;
  209. if ($GroupYear > 0) {
  210. $DisplayName = "$DisplayName [$GroupYear]";
  211. }
  212. $Tags = display_str($TorrentTags->format());
  213. $PlainTags = implode(', ', $TorrentTags->get_tags()); ?>
  214. <div class='collage_image image_group_<?=$GroupID?>'>
  215. <a href="torrents.php?id=<?=$GroupID?>"
  216. class="bookmark_<?=$GroupID?>">
  217. <?php if (!$WikiImage) {
  218. $WikiImage = STATIC_SERVER.'common/noartwork/music.png';
  219. } ?>
  220. <img class="tooltip"
  221. src="<?=ImageTools::process($WikiImage, 'thumb')?>"
  222. alt="<?=$DisplayName?>"
  223. title="<?=$DisplayName?>"
  224. data-title-plain="<?=$DisplayName?>" width="100%" />
  225. </a>
  226. </div>
  227. <?php
  228. $Collage[] = ob_get_clean();
  229. }
  230. $CollageCovers = isset($LoggedUser['CollageCovers']) ? (int)$LoggedUser['CollageCovers'] : 10;
  231. $CollagePages = [];
  232. if ($CollageCovers > 0) {
  233. for ($i = 0; $i < $NumGroups / $CollageCovers; $i++) {
  234. $Groups = array_slice($Collage, $i * $CollageCovers, $CollageCovers);
  235. $CollagePage = '';
  236. foreach ($Groups as $Group) {
  237. $CollagePage .= $Group;
  238. }
  239. $CollagePages[] = $CollagePage;
  240. }
  241. }
  242. View::show_header($Title, 'browse,collage,wall');
  243. ?>
  244. <div>
  245. <div class="header">
  246. <h2><?php if (!$Sneaky) { ?><a
  247. href="feeds.php?feed=torrents_bookmarks_t_<?=$LoggedUser['torrent_pass']?>&amp;user=<?=$LoggedUser['ID']?>&amp;auth=<?=$LoggedUser['RSS_Auth']?>&amp;passkey=<?=$LoggedUser['torrent_pass']?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;name=<?=urlencode($ENV->SITE_NAME.': Bookmarked Torrents')?>"><img
  248. src="<?=STATIC_SERVER?>/common/symbols/rss.png"
  249. alt="RSS feed" /></a>&nbsp;<?php } ?><?=$Title?>
  250. </h2>
  251. <div class="linkbox">
  252. <a href="bookmarks.php?type=torrents" class="brackets">Torrents</a>
  253. <a href="bookmarks.php?type=artists" class="brackets">Artists</a>
  254. <a href="bookmarks.php?type=collages" class="brackets">Collections</a>
  255. <a href="bookmarks.php?type=requests" class="brackets">Requests</a>
  256. <?php if (count($TorrentList) > 0) { ?>
  257. <br /><br />
  258. <a href="bookmarks.php?action=remove_snatched&amp;auth=<?=$LoggedUser['AuthKey']?>"
  259. class="brackets"
  260. onclick="return confirm('Are you sure you want to remove the bookmarks for all items you\'ve snatched?');">Remove
  261. snatched</a>
  262. <a href="bookmarks.php?action=edit&amp;type=torrents" class="brackets">Manage torrents</a>
  263. <?php } ?>
  264. </div>
  265. </div>
  266. <?php if (count($TorrentList) === 0) { ?>
  267. <div class="box pad" align="center">
  268. <h2>You have not bookmarked any torrents.</h2>
  269. </div>
  270. </div>
  271. <!--content-->
  272. <?php
  273. View::show_footer();
  274. } ?>
  275. <div class="sidebar">
  276. <div class="box box_info box_statistics_bookmarked_torrents">
  277. <div class="head"><strong>Stats</strong></div>
  278. <ul class="stats nobullet">
  279. <li>Torrent groups: <?=$NumGroups?>
  280. </li>
  281. <li>Artists: <?=count($ArtistCount)?>
  282. </li>
  283. </ul>
  284. </div>
  285. <div class="box box_tags">
  286. <div class="head"><strong>Top Tags</strong></div>
  287. <div class="pad">
  288. <ol style="padding-left: 5px;">
  289. <?php Tags::format_top(5) ?>
  290. </ol>
  291. </div>
  292. </div>
  293. <div class="box box_artists">
  294. <div class="head"><strong>Top Artists</strong></div>
  295. <div class="pad">
  296. <?php
  297. $Indent = "\t\t\t\t";
  298. if (count($ArtistCount) > 0) {
  299. echo "$Indent<ol style=\"padding-left: 5px;\">\n";
  300. uasort($ArtistCount, 'compare');
  301. $i = 0;
  302. foreach ($ArtistCount as $ID => $Artist) {
  303. $i++;
  304. if ($i > 10) {
  305. break;
  306. } ?>
  307. <li><a href="artist.php?id=<?=$ID?>"><?=display_str($Artist['name'])?></a> (<?=$Artist['count']?>)</li>
  308. <?php
  309. }
  310. echo "$Indent</ol>\n";
  311. } else {
  312. echo "$Indent<ul class=\"nobullet\" style=\"padding-left: 5px;\">\n";
  313. echo "$Indent\t<li>There are no artists to display.</li>\n";
  314. echo "$Indent</ul>\n";
  315. }
  316. ?>
  317. </div>
  318. </div>
  319. </div>
  320. <div class="main_column">
  321. <?php
  322. if ($CollageCovers !== 0) { ?>
  323. <div id="coverart" class="box">
  324. <div class="head" id="coverhead"><strong>Cover art</strong></div>
  325. <div class="collage_images" id="collage_page0" data-wall-child=".collage_image" data-wall-size="4" ,
  326. data-wall-min="2">
  327. <?php
  328. $Page1 = array_slice($Collage, 0, $CollageCovers);
  329. foreach ($Page1 as $Group) {
  330. echo $Group;
  331. }
  332. ?>
  333. </div>
  334. </div>
  335. <?php if ($NumGroups > $CollageCovers) { ?>
  336. <div class="linkbox pager" style="clear: left;" id="pageslinksdiv">
  337. <span id="firstpage" class="invisible">
  338. <a href="#" class="pageslink" onclick="collageShow.page(0, this); return false;">&lsaquo;&nbsp;First</a> |
  339. </span>
  340. <span id="prevpage" class="invisible">
  341. <a href="#" id="prevpage" class="pageslink" onclick="collageShow.prevPage(); return false;">&lsaquo;&nbsp;Prev</a>
  342. |
  343. </span>
  344. <?php for ($i = 0; $i < $NumGroups / $CollageCovers; $i++) { ?>
  345. <span id="pagelink<?=$i?>"
  346. class="<?=(($i > 4) ? 'hidden' : '')?><?=(($i === 0) ? ' selected' : '')?>">
  347. <a href="#" class="pageslink"
  348. onclick="collageShow.page(<?=$i?>, this); wall('.collage_images', '.collage_image', 4); return false;"><?=($CollageCovers * $i + 1)?>-<?=min($NumGroups, $CollageCovers * ($i + 1))?></a>
  349. <?=(($i !== ceil($NumGroups / $CollageCovers) - 1) ? ' | ' : '')?>
  350. </span>
  351. <?php } ?>
  352. <span id="nextbar"
  353. class="<?=(($NumGroups / $CollageCovers > 5) ? 'hidden' : '')?>">
  354. | </span>
  355. <span id="nextpage">
  356. <a href="#" class="pageslink"
  357. onclick="collageShow.nextPage(); wall('.collage_images', '.collage_image', 4); return false;">Next&nbsp;&rsaquo;</a>
  358. </span>
  359. <span id="lastpage"
  360. class="<?=(ceil($NumGroups / $CollageCovers) === 2 ? 'invisible' : '')?>">
  361. | <a href="#" id="lastpage" class="pageslink"
  362. onclick="collageShow.page(<?=(ceil($NumGroups / $CollageCovers) - 1)?>, this); return false;">Last&nbsp;&raquo;</a>
  363. </span>
  364. </div>
  365. <script type="text/javascript">
  366. $(() => collageShow.init( <?=json_encode($CollagePages)?> ));
  367. </script>
  368. <?php
  369. }
  370. }
  371. ?>
  372. <table class="torrent_table grouping cats" id="torrent_table">
  373. <tr class="colhead_dark">
  374. <td>
  375. <!-- Expand/Collapse -->
  376. </td>
  377. <td>
  378. <!-- Category -->
  379. </td>
  380. <td width="70%"><strong>Torrents</strong></td>
  381. <td>Size</td>
  382. <td class="sign snatches">
  383. </td>
  384. <td class="sign seeders">
  385. &uarr;
  386. </td>
  387. <td class="sign leechers">
  388. &darr;
  389. </td>
  390. </tr>
  391. <?=$TorrentTable?>
  392. </table>
  393. </div>
  394. </div>
  395. <?php View::show_footer();