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.

browse.php 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <?
  2. include(SERVER_ROOT.'/sections/torrents/functions.php');
  3. // The "order by x" links on columns headers
  4. function header_link($SortKey, $DefaultWay = 'desc') {
  5. global $OrderBy, $OrderWay;
  6. if ($SortKey == $OrderBy) {
  7. if ($OrderWay == 'desc') {
  8. $NewWay = 'asc';
  9. } else {
  10. $NewWay = 'desc';
  11. }
  12. } else {
  13. $NewWay = $DefaultWay;
  14. }
  15. return "torrents.php?order_way=$NewWay&amp;order_by=$SortKey&amp;".Format::get_url(['order_way', 'order_by']);
  16. }
  17. if (!empty($_GET['searchstr']) || !empty($_GET['groupname'])) {
  18. if (!empty($_GET['searchstr'])) {
  19. $InfoHash = $_GET['searchstr'];
  20. } else {
  21. $InfoHash = $_GET['groupname'];
  22. }
  23. // Search by infohash
  24. if ($InfoHash = is_valid_torrenthash($InfoHash)) {
  25. $InfoHash = db_string(pack('H*', $InfoHash));
  26. $DB->query("
  27. SELECT ID, GroupID
  28. FROM torrents
  29. WHERE info_hash = '$InfoHash'");
  30. if ($DB->has_results()) {
  31. list($ID, $GroupID) = $DB->next_record();
  32. header("Location: torrents.php?id=$GroupID&torrentid=$ID");
  33. die();
  34. }
  35. }
  36. }
  37. // Setting default search options
  38. if (!empty($_GET['setdefault'])) {
  39. $UnsetList = ['page', 'setdefault'];
  40. $UnsetRegexp = '/(&|^)('.implode('|', $UnsetList).')=.*?(&|$)/i';
  41. $DB->query("
  42. SELECT SiteOptions
  43. FROM users_info
  44. WHERE UserID = ?", $LoggedUser['ID']);
  45. list($SiteOptions) = $DB->next_record(MYSQLI_NUM, false);
  46. $SiteOptions = json_decode($SiteOptions, true) ?? [];
  47. $SiteOptions['DefaultSearch'] = preg_replace($UnsetRegexp, '', $_SERVER['QUERY_STRING']);
  48. $DB->query("
  49. UPDATE users_info
  50. SET SiteOptions = ?
  51. WHERE UserID = ?", json_encode($SiteOptions), $LoggedUser['ID']);
  52. $Cache->begin_transaction("user_info_heavy_$UserID");
  53. $Cache->update_row(false, ['DefaultSearch' => $SiteOptions['DefaultSearch']]);
  54. $Cache->commit_transaction(0);
  55. // Clearing default search options
  56. } elseif (!empty($_GET['cleardefault'])) {
  57. $DB->query("
  58. SELECT SiteOptions
  59. FROM users_info
  60. WHERE UserID = ?", $LoggedUser['ID']);
  61. list($SiteOptions) = $DB->next_record(MYSQLI_NUM, false);
  62. $SiteOptions = json_decode($SiteOptions, true) ?? [];
  63. $SiteOptions['DefaultSearch'] = '';
  64. $DB->query("
  65. UPDATE users_info
  66. SET SiteOptions = ?
  67. WHERE UserID = ?", json_encode($SiteOptions), $LoggedUser['ID']);
  68. $Cache->begin_transaction("user_info_heavy_$UserID");
  69. $Cache->update_row(false, ['DefaultSearch' => '']);
  70. $Cache->commit_transaction(0);
  71. // Use default search options
  72. } elseif (empty($_SERVER['QUERY_STRING']) || (count($_GET) === 1 && isset($_GET['page']))) {
  73. if (!empty($LoggedUser['DefaultSearch'])) {
  74. if (!empty($_GET['page'])) {
  75. $Page = $_GET['page'];
  76. parse_str($LoggedUser['DefaultSearch'], $_GET);
  77. $_GET['page'] = $Page;
  78. } else {
  79. parse_str($LoggedUser['DefaultSearch'], $_GET);
  80. }
  81. }
  82. }
  83. // Terms were not submitted via the search form
  84. if (isset($_GET['searchsubmit'])) {
  85. $GroupResults = !empty($_GET['group_results']);
  86. } else {
  87. $GroupResults = !$LoggedUser['DisableGrouping2'];
  88. }
  89. if (!empty($_GET['order_way']) && $_GET['order_way'] == 'asc') {
  90. $OrderWay = 'asc';
  91. } else {
  92. $OrderWay = 'desc';
  93. }
  94. if (empty($_GET['order_by']) || !isset(TorrentSearch::$SortOrders[$_GET['order_by']])) {
  95. $OrderBy = 'time'; // For header links
  96. } else {
  97. $OrderBy = $_GET['order_by'];
  98. }
  99. $Page = !empty($_GET['page']) ? (int) $_GET['page'] : 1;
  100. $Search = new TorrentSearch($GroupResults, $OrderBy, $OrderWay, $Page, TORRENTS_PER_PAGE);
  101. if (isset($LoggedUser['HideLolicon']) && $LoggedUser['HideLolicon'] == 1) {
  102. $Search->insert_hidden_tags('!lolicon !shotacon !toddlercon');
  103. }
  104. if (isset($LoggedUser['HideScat']) && $LoggedUser['HideScat'] == 1) {
  105. $Search->insert_hidden_tags('!scat');
  106. }
  107. if (isset($LoggedUser['HideSnuff']) && $LoggedUser['HideSnuff'] == 1) {
  108. $Search->insert_hidden_tags('!snuff');
  109. }
  110. $Results = $Search->query($_GET);
  111. $Groups = $Search->get_groups();
  112. $NumResults = $Search->record_count();
  113. $HideFilter = isset($LoggedUser['ShowTorFilter']) && $LoggedUser['ShowTorFilter'] == 0;
  114. // This is kinda ugly, but the enormous if paragraph was really hard to read
  115. $AdvancedSearch = !empty($_GET['action']) && $_GET['action'] == 'advanced';
  116. $AdvancedSearch |= !empty($LoggedUser['SearchType']) && (empty($_GET['action']) || $_GET['action'] == 'advanced');
  117. $AdvancedSearch &= check_perms('site_advanced_search');
  118. if ($AdvancedSearch) {
  119. $Action = 'action=advanced';
  120. $HideBasic = ' hidden';
  121. $HideAdvanced = '';
  122. } else {
  123. $Action = 'action=basic';
  124. $HideBasic = '';
  125. $HideAdvanced = ' hidden';
  126. }
  127. View::show_header('Browse Torrents', 'browse');
  128. ?>
  129. <div class="thin widethin">
  130. <div class="header">
  131. <h2>Torrents</h2>
  132. </div>
  133. <form class="search_form" name="torrents" method="get" onsubmit="$(this).disableUnset();">
  134. <div class="box filter_torrents">
  135. <div class="head">
  136. <strong>
  137. <span id="ft_basic" class="<?=$HideBasic?>">Basic Search (<a class="clickable" onclick="toggleTorrentSearch('advanced')">Advanced</a>)</span>
  138. <span id="ft_advanced" class="<?=$HideAdvanced?>">Advanced Search (<a class="clickable" onclick="toggleTorrentSearch('basic')">Basic</a>)</span>
  139. </strong>
  140. <span class="float_right">
  141. <a onclick="return toggleTorrentSearch(0);" id="ft_toggle" class="brackets"><?=$HideFilter ? 'Show' : 'Hide'?></a>
  142. </span>
  143. </div>
  144. <div id="ft_container" class="pad<?=$HideFilter ? ' hidden' : ''?>">
  145. <? if((isset($LoggedUser['HideLolicon']) && $LoggedUser['HideLolicon'] == 1)
  146. || (isset($LoggedUser['HideScat']) && $LoggedUser['HideScat'] == 1)
  147. || (isset($LoggedUser['HideSnuff']) && $LoggedUser['HideSnuff'] == 1)
  148. ) { ?>
  149. <svg title="Your profile settings exclude some results" class="search_warning tooltip" width="10" height="15"><rect x=3 width="4" height="10" rx="2" ry="2"/><circle cx="5" cy="13" r="2"/></svg>
  150. <? } ?>
  151. <table class="layout">
  152. <tr id="artist_name" class="ftr_advanced<?=$HideAdvanced?>">
  153. <td class="label"><!--Artist name:--></td>
  154. <td class="ft_artistname">
  155. <input type="search" spellcheck="false" size="65" name="artistname" class="inputtext smaller fti_advanced" placeholder="Author Name" value="<?Format::form('artistname')?>" />
  156. </td>
  157. </tr>
  158. <tr id="album_torrent_name" class="ftr_advanced<?=$HideAdvanced?>">
  159. <td class="label"><!--Torrent name:--></td>
  160. <td class="ft_groupname">
  161. <input type="search" spellcheck="false" size="65" name="advgroupname" class="inputtext smaller fti_advanced" placeholder="Torrent Title" value="<?Format::form('advgroupname')?>" />
  162. </td>
  163. </tr>
  164. <tr id="catalogue_number" class="ftr_advanced<?=$HideAdvanced?>">
  165. <td class="label"><!--Catalogue number:--></td>
  166. <td class="ft_cataloguenumber">
  167. <input type="search" size="19" name="cataloguenumber" class="inputtext smallest fti_advanced" placeholder="Accession Number" value="<?Format::form('cataloguenumber')?>" />
  168. </td>
  169. </tr>
  170. <tr id="year" class="ftr_advanced<?=$HideAdvanced?>">
  171. <td class="label"><!--Year:--></td>
  172. <td class="ft_year">
  173. <input type="search" name="year" class="inputtext smallest fti_advanced" placeholder="Year" value="<?Format::form('year')?>" size="12" />
  174. </td>
  175. </tr>
  176. <tr id="file_list" class="ftr_advanced<?=$HideAdvanced?>">
  177. <td class="label"><!--File list:--></td>
  178. <td class="ft_filelist">
  179. <input type="search" spellcheck="false" size="65" name="filelist" class="inputtext fti_advanced" placeholder="File List" value="<?Format::form('filelist')?>" />
  180. </td>
  181. </tr>
  182. <tr id="torrent_description" class="ftr_advanced<?=$HideAdvanced?>">
  183. <td class="label"><!--<span title="Search torrent descriptions (not group information)" class="tooltip">Torrent description:</span>--></td>
  184. <td class="ft_description">
  185. <input type="search" spellcheck="false" size="65" name="description" class="inputtext fti_advanced tooltip_left" placeholder="Torrent Description" title="Search torrent descriptions (not group information)" value="<?Format::form('description')?>" />
  186. </td>
  187. </tr>
  188. <tr id="rip_specifics" class="ftr_advanced<?=$HideAdvanced?>">
  189. <td class="label">Release Specifics</td>
  190. <td class="nobr ft_ripspecifics">
  191. <select id="container" name="container" class="ft_container fti_advanced">
  192. <option value="">Format</option>
  193. <? foreach ($Containers as $Container) { ?>
  194. <option value="<?=display_str($Container);?>" <?Format::selected('container', $Container)?>><?=display_str($Container);?></option>
  195. <? } ?>
  196. </select>
  197. <select name="codec" class="ft_codec fti_advanced">
  198. <option value="">License</option>
  199. <? foreach ($Codecs as $Codec) { ?>
  200. <option value="<?=display_str($Codec); ?>"<?Format::selected('codec', $Codec)?>><?=display_str($Codec); ?></option>
  201. <? } ?>
  202. </select>
  203. <select name="media" class="ft_media fti_advanced">
  204. <option value="">Platform</option>
  205. <? foreach ($Media as $MediaName) { ?>
  206. <option value="<?=display_str($MediaName); ?>"<?Format::selected('media', $MediaName)?>><?=display_str($MediaName); ?></option>
  207. <? } ?>
  208. </select>
  209. <select name="resolution" class="ft_resolution fti_advanced">
  210. <option value="">Assembly Level</option>
  211. <? foreach ($Resolutions as $Resolution) { ?>
  212. <option value="<?=display_str($Resolution); ?>"<?Format::selected('resolution', $Resolution)?>><?=display_str($Resolution); ?></option>
  213. <? } ?>
  214. </select>
  215. </td>
  216. </tr>
  217. <tr id="size" class="ftr_advanced<?=$HideAdvanced?>">
  218. <td class="label">Size</td>
  219. <td class="ft_size">
  220. <input type="size_min" spellcheck="false" size="6" name="size_min" class="inputtext smaller fti_advanced" placeholder="Min" value="<?Format::form('size_min')?>" /> -
  221. <input type="size_max" spellcheck="false" size="6" name="size_max" class="inputtext smaller fti_advanced" placeholder="Max" value="<?Format::form('size_max')?>" />
  222. <select name="size_unit" class="ft_size fti_advanced">
  223. <option value="">Unit</option>
  224. <option value="0"<?Format::selected('size_unit', 0)?>>B</option>
  225. <option value="1"<?Format::selected('size_unit', 1)?>>KiB</option>
  226. <option value="2"<?Format::selected('size_unit', 2)?>>MiB</option>
  227. <option value="3"<?Format::selected('size_unit', 3)?>>GiB</option>
  228. <option value="4"<?Format::selected('size_unit', 4)?>>TiB</option>
  229. </select>
  230. </td>
  231. </tr>
  232. <tr id="misc" class="ftr_advanced<?=$HideAdvanced?>">
  233. <td class="label">Misc</td>
  234. <td class="nobr ft_misc">
  235. <select name="freetorrent" class="ft_freetorrent fti_advanced">
  236. <option value="">Leech Status</option>
  237. <option value="1"<?Format::selected('freetorrent', 1)?>>Freeleech</option>
  238. <option value="2"<?Format::selected('freetorrent', 2)?>>Neutral Leech</option>
  239. <option value="3"<?Format::selected('freetorrent', 3)?>>Either</option>
  240. <option value="0"<?Format::selected('freetorrent', 0)?>>Normal</option>
  241. </select>
  242. <select name="censored" class="ft_censored fti_advanced">
  243. <option value="">Aligned Sequence?</option>
  244. <option value="1"<?Format::selected('censored', 1)?>>Aligned</option>
  245. <option value="0"<?Format::selected('censored', 0)?>>Unaligned</option>
  246. </select>
  247. </td>
  248. </tr>
  249. <tr id="search_terms" class="ftr_basic<?=$HideBasic?>">
  250. <td class="label"><!--Search terms:--></td>
  251. <td class="ftb_searchstr">
  252. <input type="search" spellcheck="false" size="48" name="searchstr" class="inputtext fti_basic" placeholder="Search Terms" value="<?Format::form('searchstr')?>" aria-label="Terms to search">
  253. </td>
  254. </tr>
  255. <tr id="tagfilter">
  256. <td class="label"><!--<span title="Use !tag to exclude tag" class="tooltip">Tags (comma-separated):</span>--></td>
  257. <td class="ft_taglist">
  258. <input type="search" size="37" id="tags" name="taglist" class="inputtext smaller tooltip_left" title="Use !tag to exclude tag" placeholder="Tags (comma-separated)" value="<?=display_str($Search->get_terms('taglist'))?>"<? Users::has_autocomplete_enabled('other'); ?> aria-label="Tags to search">&nbsp;
  259. <input type="radio" name="tags_type" id="tags_type0" value="0"<?Format::selected('tags_type', 0, 'checked')?> /><label for="tags_type0"> Any</label>&nbsp;&nbsp;
  260. <input type="radio" name="tags_type" id="tags_type1" value="1"<?Format::selected('tags_type', 1, 'checked')?> /><label for="tags_type1"> All</label>
  261. </td>
  262. </tr>
  263. <tr id="order">
  264. <td class="label">Order By</td>
  265. <td class="ft_order">
  266. <select name="order_by" style="width: auto;" class="ft_order_by" aria-label="Property to order by">
  267. <option value="time"<?Format::selected('order_by', 'time')?>>Time Added</option>
  268. <option value="year"<?Format::selected('order_by', 'year')?>>Year</option>
  269. <option value="size"<?Format::selected('order_by', 'size')?>>Size</option>
  270. <option value="snatched"<?Format::selected('order_by', 'snatched')?>>Snatched</option>
  271. <option value="seeders"<?Format::selected('order_by', 'seeders')?>>Seeders</option>
  272. <option value="leechers"<?Format::selected('order_by', 'leechers')?>>Leechers</option>
  273. <option value="cataloguenumber"<?Format::selected('order_by', 'cataloguenumber')?>>Accession Number</option>
  274. <option value="random"<?Format::selected('order_by', 'random')?>>Random</option>
  275. </select>
  276. <select name="order_way" class="ft_order_way" aria-label="Direction to order">
  277. <option value="desc"<?Format::selected('order_way', 'desc')?>>Descending</option>
  278. <option value="asc"<?Format::selected('order_way', 'asc')?>>Ascending</option>
  279. </select>
  280. </td>
  281. </tr>
  282. <tr id="search_group_results">
  283. <td class="label">
  284. <label for="group_results">Group by Release?</label>
  285. </td>
  286. <td class="ft_group_results">
  287. <input type="checkbox" value="1" name="group_results" id="group_results"<?=$GroupResults ? ' checked="checked"' : ''?> />
  288. </td>
  289. </tr>
  290. </table>
  291. <table class="layout cat_list ft_cat_list">
  292. <?
  293. $x = 0;
  294. reset($Categories);
  295. foreach ($Categories as $CatKey => $CatName) {
  296. if ($x % 7 == 0) {
  297. if ($x > 0) {
  298. ?>
  299. </tr>
  300. <? } ?>
  301. <tr>
  302. <?
  303. }
  304. $x++;
  305. ?>
  306. <td>
  307. <input type="checkbox" name="filter_cat[<?=($CatKey + 1)?>]" id="cat_<?=($CatKey + 1)?>" value="1"<? if (isset($_GET['filter_cat'][$CatKey + 1])) { ?> checked="checked"<? } ?> />
  308. <label for="cat_<?=($CatKey + 1)?>"><?=$CatName?></label>
  309. </td>
  310. <?
  311. }
  312. ?>
  313. </tr>
  314. </table>
  315. <table class="layout cat_list<? if (empty($LoggedUser['ShowTags'])) { ?> hidden<? } ?>" id="taglist">
  316. <tr>
  317. <?
  318. $GenreTags = $Cache->get_value('genre_tags');
  319. if (!$GenreTags) {
  320. $DB->query('
  321. SELECT Name
  322. FROM tags
  323. WHERE TagType = \'genre\'
  324. ORDER BY Name');
  325. $GenreTags = $DB->collect('Name');
  326. $Cache->cache_value('genre_tags', $GenreTags, 3600 * 6);
  327. }
  328. $x = 0;
  329. foreach ($GenreTags as $Tag) {
  330. ?>
  331. <td><a href="#" onclick="add_tag('<?=$Tag?>'); return false;"><?=$Tag?></a></td>
  332. <?
  333. $x++;
  334. if ($x % 7 == 0) {
  335. ?>
  336. </tr>
  337. <tr>
  338. <?
  339. }
  340. }
  341. if ($x % 7 != 0) { // Padding
  342. ?>
  343. <td colspan="<?=(7 - ($x % 7))?>"> </td>
  344. <? } ?>
  345. </tr>
  346. </table>
  347. <table class="layout cat_list">
  348. <tr>
  349. <td class="label">
  350. <a class="brackets" data-toggle-target="#taglist" data-toggle-replace="<?=(empty($LoggedUser['ShowTags']) ? 'Hide tags' : 'View tags')?>"><?=(empty($LoggedUser['ShowTags']) ? 'View tags' : 'Hide tags')?></a>
  351. </td>
  352. </tr>
  353. </table>
  354. <div class="submit ft_submit">
  355. <span class="float_left"><?=number_format($NumResults)?> Results</span>
  356. <input type="submit" value="Filter torrents" />
  357. <input type="hidden" name="action" id="ft_type" value="<?=($AdvancedSearch ? 'advanced' : 'basic')?>" />
  358. <input type="hidden" name="searchsubmit" value="1" />
  359. <input type="button" value="Reset" onclick="location.href = 'torrents.php<? if (isset($_GET['action']) && $_GET['action'] === 'advanced') { ?>?action=advanced<? } ?>'" />
  360. &nbsp;&nbsp;
  361. <? if ($Search->has_filters()) { ?>
  362. <input type="submit" name="setdefault" value="Make default" />
  363. <? }
  364. if (!empty($LoggedUser['DefaultSearch'])) { ?>
  365. <input type="submit" name="cleardefault" value="Clear default" />
  366. <? } ?>
  367. </div>
  368. </div>
  369. </div>
  370. </form>
  371. <? if ($NumResults == 0) { ?>
  372. <div class="torrents_nomatch box pad" align="center">
  373. <h2>Your search did not match anything.</h2>
  374. <p>Make sure all names are spelled correctly, or try making your search less specific.</p>
  375. </div>
  376. </div>
  377. <? View::show_footer();die();
  378. }
  379. if ($NumResults < ($Page - 1) * TORRENTS_PER_PAGE + 1) {
  380. $LastPage = ceil($NumResults / TORRENTS_PER_PAGE);
  381. $Pages = Format::get_pages(0, $NumResults, TORRENTS_PER_PAGE);
  382. ?>
  383. <div class="torrents_nomatch box pad" align="center">
  384. <h2>The requested page contains no matches.</h2>
  385. <p>You are requesting page <?=$Page?>, but the search returned only <?=number_format($LastPage) ?> pages.</p>
  386. </div>
  387. <div class="linkbox">Go to page <?=$Pages?></div>
  388. </div>
  389. <?
  390. View::show_footer();die();
  391. }
  392. // List of pages
  393. $Pages = Format::get_pages($Page, $NumResults, TORRENTS_PER_PAGE);
  394. $Bookmarks = Bookmarks::all_bookmarks('torrent');
  395. ?>
  396. <div class="linkbox"><?=$Pages?></div>
  397. <table class="box torrent_table cats <?=$GroupResults ? 'grouping' : 'no_grouping'?>" id="torrent_table">
  398. <tr class="colhead">
  399. <? if ($GroupResults) { ?>
  400. <td class="small"></td>
  401. <? } ?>
  402. <td class="small cats_col"></td>
  403. <td>Name / <a href="<?=header_link('year')?>">Year</a></td>
  404. <td>Files</td>
  405. <td><a href="<?=header_link('time')?>">Time</a></td>
  406. <td><a href="<?=header_link('size')?>">Size</a></td>
  407. <td class="sign snatches">
  408. <a href="<?=header_link('snatched')?>" aria-label="Sort by snatches">
  409. <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>
  410. </a>
  411. </td>
  412. <td class="sign seeders">
  413. <a href="<?=header_link('seeders')?>" aria-label="Sort by seeders">
  414. <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>
  415. </a>
  416. </td>
  417. <td class="sign leechers">
  418. <a href="<?=header_link('leechers')?>" aria-label="Sort by leechers">
  419. <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>
  420. </a>
  421. </td>
  422. </tr>
  423. <?
  424. // Start printing torrent list
  425. foreach ($Results as $Key => $GroupID) {
  426. $GroupInfo = $Groups[$GroupID];
  427. if (empty($GroupInfo['Torrents'])) {
  428. continue;
  429. }
  430. $CategoryID = $GroupInfo['CategoryID'];
  431. $GroupYear = $GroupInfo['Year'];
  432. $Artists = $GroupInfo['Artists'];
  433. $GroupCatalogueNumber = $GroupInfo['CatalogueNumber'];
  434. $GroupPages = $GroupInfo['Pages'];
  435. $GroupStudio = $GroupInfo['Studio'];
  436. $GroupDLsiteID = $GroupInfo['DLSiteID'];
  437. $GroupName = empty($GroupInfo['Name']) ? (empty($GroupInfo['NameRJ']) ? $GroupInfo['NameJP'] : $GroupInfo['NameRJ']) : $GroupInfo['Name'];
  438. if ($GroupResults) {
  439. $Torrents = $GroupInfo['Torrents'];
  440. $GroupTime = $MaxSize = $TotalLeechers = $TotalSeeders = $TotalSnatched = 0;
  441. foreach ($Torrents as $T) {
  442. $GroupTime = max($GroupTime, strtotime($T['Time']));
  443. $MaxSize = max($MaxSize, $T['Size']);
  444. $TotalLeechers += $T['Leechers'];
  445. $TotalSeeders += $T['Seeders'];
  446. $TotalSnatched += $T['Snatched'];
  447. }
  448. } else {
  449. $TorrentID = $Key;
  450. $Torrents = [$TorrentID => $GroupInfo['Torrents'][$TorrentID]];
  451. }
  452. $TorrentTags = new Tags($GroupInfo['TagList']);
  453. if (isset($Artists)) {
  454. $DisplayName = '<div class="torrent_artists">'.Artists::display_artists($Artists).'</div> ';
  455. } else {
  456. $DisplayName = '';
  457. }
  458. $SnatchedGroupClass = $GroupInfo['Flags']['IsSnatched'] ? ' snatched_group' : '';
  459. if ($GroupResults && (count($Torrents) > 1 && isset($GroupedCategories[$CategoryID - 1]))) {
  460. // These torrents are in a group
  461. $CoverArt = $GroupInfo['WikiImage'];
  462. $DisplayName .= "<a class=\"torrent_title\" href=\"torrents.php?id=$GroupID\" ";
  463. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  464. $DisplayName .= 'data-cover="'.ImageTools::process($CoverArt, 'thumb').'" ';
  465. }
  466. $DisplayName .= "dir=\"ltr\">$GroupName</a>";
  467. if ($GroupYear) {
  468. $DisplayName .= " [$GroupYear]";
  469. }
  470. if ($GroupStudio) {
  471. $DisplayName .= " [$GroupStudio]";
  472. }
  473. if ($GroupCatalogueNumber) {
  474. $DisplayName .= " [$GroupCatalogueNumber]";
  475. }
  476. if ($GroupPages) {
  477. $DisplayName .= " [{$GroupPages}p]";
  478. }
  479. if ($GroupDLsiteID) {
  480. $DisplayName .= " [$GroupDLsiteID]";
  481. }
  482. ?>
  483. <tr class="group<?=$SnatchedGroupClass?>">
  484. <?
  485. $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1);
  486. ?>
  487. <td class="center">
  488. <div id="showimg_<?=$GroupID?>" class="<?=($ShowGroups ? 'hide' : 'show')?>_torrents">
  489. <a class="tooltip show_torrents_link" onclick="toggle_group(<?=$GroupID?>, this, event)" title="Toggle this group (Hold &quot;Shift&quot; to toggle all groups)"></a>
  490. </div>
  491. </td>
  492. <td class="center cats_col">
  493. <div title="<?=Format::pretty_category($CategoryID)?>" class="tooltip <?=Format::css_category($CategoryID)?>">
  494. </div>
  495. </td>
  496. <td colspan="2" class="big_info">
  497. <div class="group_info clear">
  498. <?=$DisplayName?>
  499. <? if (in_array($GroupID, $Bookmarks)) { ?>
  500. <span class="remove_bookmark float_right">
  501. <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="brackets" onclick="Unbookmark('torrent', <?=$GroupID?>, 'Bookmark'); return false;">Remove bookmark</a>
  502. </span>
  503. <? } else { ?>
  504. <span class="add_bookmark float_right">
  505. <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="brackets" onclick="Bookmark('torrent', <?=$GroupID?>, 'Remove bookmark'); return false;">Bookmark</a>
  506. </span>
  507. <? } ?>
  508. <br />
  509. <div class="tags"><?=$TorrentTags->format('torrents.php?'.$Action.'&amp;taglist=')?></div>
  510. </div>
  511. </td>
  512. <td class="nobr"><?=time_diff($GroupTime, 1)?></td>
  513. <td class="number_column nobr"><?=Format::get_size($MaxSize)?> (Max)</td>
  514. <td class="number_column"><?=number_format($TotalSnatched)?></td>
  515. <td class="number_column<?=($TotalSeeders == 0 ? ' r00' : '')?>"><?=number_format($TotalSeeders)?></td>
  516. <td class="number_column"><?=number_format($TotalLeechers)?></td>
  517. </tr>
  518. <?
  519. foreach ($Torrents as $TorrentID => $Data) {
  520. $Data['CategoryID'] = $CategoryID;
  521. // All of the individual torrents in the group
  522. //Get report info for each torrent, use the cache if available, if not, add to it.
  523. $Reported = false;
  524. $Reports = Torrents::get_reports($TorrentID);
  525. if (count($Reports) > 0) {
  526. $Reported = true;
  527. }
  528. $SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
  529. $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
  530. if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
  531. if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
  532. $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
  533. $Tor = new BencodeTorrent($TorrentFile, false, false);
  534. $TorrentFileName = $Tor->Dec['info']['name'];
  535. $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
  536. }
  537. $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
  538. }
  539. ?>
  540. <tr class="group_torrent groupid_<?=$GroupID?> <?=$SnatchedTorrentClass . $SnatchedGroupClass . (!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1 ? ' hidden' : '')?>">
  541. <td colspan="3">
  542. <span>
  543. [ <a href="<?=$TorrentDL?>" class="tooltip" title="Download"><?=$Data['HasFile'] ? 'DL' : 'Missing'?></a>
  544. <? if (isset($TorrentMG)) { ?>
  545. | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
  546. <? }
  547. if (Torrents::can_use_token($Data)) { ?>
  548. | <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>
  549. <? } ?>
  550. | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]
  551. </span>
  552. &raquo; <a href="torrents.php?id=<?=$GroupID?>&amp;torrentid=<?=$TorrentID?>"><?=Torrents::torrent_info($Data)?><? if ($Reported) { ?> / <strong class="torrent_label tl_reported tooltip" title="Type: <?=ucfirst($Reports[0]['Type'])?><br>Comment: <?=htmlentities(htmlentities($Reports[0]['UserComment']))?>">Reported</strong><? } ?></a>
  553. </td>
  554. <td class="number_column"><?=$Data['FileCount']?></td>
  555. <td class="nobr"><?=time_diff($Data['Time'], 1)?></td>
  556. <td class="number_column nobr"><?=Format::get_size($Data['Size'])?></td>
  557. <td class="number_column"><?=number_format($Data['Snatched'])?></td>
  558. <td class="number_column<?=($Data['Seeders'] == 0) ? ' r00' : ''?>"><?=number_format($Data['Seeders'])?></td>
  559. <td class="number_column"><?=number_format($Data['Leechers'])?></td>
  560. </tr>
  561. <?
  562. }
  563. } else {
  564. // Viewing a type that does not require grouping
  565. $TorrentID = key($Torrents);
  566. $Data = current($Torrents);
  567. $Reported = false;
  568. $Reports = Torrents::get_reports($TorrentID);
  569. if (count($Reports) > 0) {
  570. $Reported = true;
  571. }
  572. $Data['CategoryID'] = $CategoryID;
  573. $CoverArt = $GroupInfo['WikiImage'];
  574. $DisplayName .= "<a class=\"torrent_name\" href=\"torrents.php?id=$GroupID&amp;torrentid=$TorrentID#torrent$TorrentID\" ";
  575. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  576. $DisplayName .= 'data-cover="'.ImageTools::process($CoverArt, 'thumb').'" ';
  577. }
  578. $DisplayName .= "dir=\"ltr\">$GroupName</a>";
  579. if (isset($GroupedCategories[$CategoryID - 1])) {
  580. if ($GroupYear) {
  581. $DisplayName .= " [$GroupYear]";
  582. }
  583. if ($GroupStudio) {
  584. $DisplayName .= " [$GroupStudio]";
  585. }
  586. if ($GroupCatalogueNumber) {
  587. $DisplayName .= " [$GroupCatalogueNumber]";
  588. }
  589. if ($GroupPages) {
  590. $DisplayName .= " [{$GroupPages}p]";
  591. }
  592. if ($GroupDLsiteID) {
  593. $DisplayName .= " [$GroupDLsiteID]";
  594. }
  595. $ExtraInfo = Torrents::torrent_info($Data, true, true);
  596. } elseif ($Data['IsSnatched']) {
  597. $ExtraInfo = Format::torrent_label('Snatched!');
  598. } else {
  599. $ExtraInfo = '';
  600. }
  601. $SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
  602. $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
  603. if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
  604. if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
  605. $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
  606. $Tor = new BencodeTorrent($TorrentFile, false, false);
  607. $TorrentFileName = $Tor->Dec['info']['name'];
  608. $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
  609. }
  610. $TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&amp;','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
  611. }
  612. ?>
  613. <tr class="torrent<?=$SnatchedTorrentClass . $SnatchedGroupClass?>">
  614. <? if ($GroupResults) { ?>
  615. <td></td>
  616. <? } ?>
  617. <td class="center cats_col">
  618. <div title="<?=Format::pretty_category($CategoryID)?>" class="tooltip <?=Format::css_category($CategoryID)?>"></div>
  619. </td>
  620. <td class="big_info">
  621. <div class="group_info clear">
  622. <div class="float_right">
  623. <span>
  624. [ <a href="<?=$TorrentDL?>" class="tooltip" title="Download">DL</a>
  625. <? if (isset($TorrentMG)) { ?>
  626. | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
  627. <? }
  628. if (Torrents::can_use_token($Data)) { ?>
  629. | <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>
  630. <? } ?>
  631. | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]
  632. </span>
  633. <br />
  634. <? if (in_array($GroupID, $Bookmarks)) { ?>
  635. <span class="remove_bookmark float_right">
  636. <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="brackets" onclick="Unbookmark('torrent', <?=$GroupID?>, 'Bookmark'); return false;">Remove bookmark</a>
  637. </span>
  638. <? } else { ?>
  639. <span class="add_bookmark float_right">
  640. <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="brackets" onclick="Bookmark('torrent', <?=$GroupID?>, 'Remove bookmark'); return false;">Bookmark</a>
  641. </span>
  642. <? } ?>
  643. </div>
  644. <?=$DisplayName?>
  645. <br />
  646. <div style="display: inline;" class="torrent_info"><?=$ExtraInfo?><? if ($Reported) { ?> / <strong class="torrent_label tl_reported tooltip" title="Type: <?=ucfirst($Reports[0]['Type'])?><br>Comment: <?=htmlentities(htmlentities($Reports[0]['UserComment']))?>">Reported</strong><? } ?></div>
  647. <div class="tags"><?=$TorrentTags->format("torrents.php?$Action&amp;taglist=")?></div>
  648. </div>
  649. </td>
  650. <td class="number_column"><?=$Data['FileCount']?></td>
  651. <td class="nobr"><?=time_diff($Data['Time'], 1)?></td>
  652. <td class="number_column nobr"><?=Format::get_size($Data['Size'])?></td>
  653. <td class="number_column"><?=number_format($Data['Snatched'])?></td>
  654. <td class="number_column<?=($Data['Seeders'] == 0) ? ' r00' : ''?>"><?=number_format($Data['Seeders'])?></td>
  655. <td class="number_column"><?=number_format($Data['Leechers'])?></td>
  656. </tr>
  657. <?
  658. }
  659. }
  660. ?>
  661. </table>
  662. <div class="linkbox"><?=$Pages?></div>
  663. </div>
  664. <? View::show_footer(); ?>