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 33KB

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