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.

torrents.php 15KB

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