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.

browse.php 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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="Artist 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 name" 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="Catalogue number" value="<?Format::form('cataloguenumber')?>" />
  168. </td>
  169. </tr>
  170. <tr id="dlsiteid" class="ftr_advanced<?=$HideAdvanced?>">
  171. <td class="label"><!--DLSite ID:--></td>
  172. <td class="ft_dlsiteid">
  173. <input type="search" size="12" name="dlsiteid" class="inputtext smallest fti_advanced" placeholder="DLSite ID" value="<?Format::form('dlsiteid')?>" />
  174. </td>
  175. </tr>
  176. <tr id="year" class="ftr_advanced<?=$HideAdvanced?>">
  177. <td class="label"><!--Year:--></td>
  178. <td class="ft_year">
  179. <input type="search" name="year" class="inputtext smallest fti_advanced" placeholder="Year" value="<?Format::form('year')?>" size="12" />
  180. </td>
  181. </tr>
  182. <tr id="file_list" class="ftr_advanced<?=$HideAdvanced?>">
  183. <td class="label"><!--File list:--></td>
  184. <td class="ft_filelist">
  185. <input type="search" spellcheck="false" size="65" name="filelist" class="inputtext fti_advanced" placeholder="File list" value="<?Format::form('filelist')?>" />
  186. </td>
  187. </tr>
  188. <tr id="torrent_description" class="ftr_advanced<?=$HideAdvanced?>">
  189. <td class="label"><!--<span title="Search torrent descriptions (not group information)" class="tooltip">Torrent description:</span>--></td>
  190. <td class="ft_description">
  191. <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')?>" />
  192. </td>
  193. </tr>
  194. <tr id="rip_specifics" class="ftr_advanced<?=$HideAdvanced?>">
  195. <td class="label">Release specifics:</td>
  196. <td class="nobr ft_ripspecifics">
  197. <select id="container" name="container" class="ft_container fti_advanced">
  198. <option value="">Container</option>
  199. <? foreach ($Containers as $Container) { ?>
  200. <option value="<?=display_str($Container);?>" <?Format::selected('container', $Container)?>><?=display_str($Container);?></option>
  201. <? } ?>
  202. <? foreach ($ContainersGames as $Container) { ?>
  203. <option value="<?=display_str($Container);?>" <?Format::selected('container', $Container)?>><?=display_str($Container);?></option>
  204. <? } ?>
  205. </select>
  206. <select name="codec" class="ft_codec fti_advanced">
  207. <option value="">Codec</option>
  208. <? foreach ($Codecs as $Codec) { ?>
  209. <option value="<?=display_str($Codec); ?>"<?Format::selected('codec', $Codec)?>><?=display_str($Codec); ?></option>
  210. <? } ?>
  211. </select>
  212. <select name="audioformat" class="ft_audioformat fti_advanced">
  213. <option value="">AudioFormat</option>
  214. <? foreach ($AudioFormats as $AudioFormat) { ?>
  215. <option value="<?=display_str($AudioFormat); ?>"<?Format::selected('audioformat', $AudioFormat)?>><?=display_str($AudioFormat); ?></option>
  216. <? } ?>
  217. </select>
  218. <select name="media" class="ft_media fti_advanced">
  219. <option value="">Media</option>
  220. <? foreach ($Media as $MediaName) { ?>
  221. <option value="<?=display_str($MediaName); ?>"<?Format::selected('media', $MediaName)?>><?=display_str($MediaName); ?></option>
  222. <? } ?>
  223. </select>
  224. <select name="resolution" class="ft_resolution fti_advanced">
  225. <option value="">Resolution</option>
  226. <? foreach ($Resolutions as $Resolution) { ?>
  227. <option value="<?=display_str($Resolution); ?>"<?Format::selected('resolution', $Resolution)?>><?=display_str($Resolution); ?></option>
  228. <? } ?>
  229. </select>
  230. <select name="language" class="ft_language fti_advanced">
  231. <option value="">Language</option>
  232. <? foreach ($Languages as $Language) { ?>
  233. <option value="<?=display_str($Language); ?>"<?Format::selected('language', $Language)?>><?=display_str($Language); ?></option>
  234. <? } ?>
  235. </select>
  236. <select name="subbing" class="ft_subbing fti_advanced">
  237. <option value="">Subs</option>
  238. <? foreach ($Subbing as $Sub) { ?>
  239. <option value="<?=display_str($Sub); ?>"<?Format::selected('subbing', $Sub)?>><?=display_str($Sub); ?></option>
  240. <? } ?>
  241. </select>
  242. </td>
  243. </tr>
  244. <tr id="subber" class="ftr_advanced<?=$HideAdvanced?>">
  245. <td class="label"><!--Translation Group:--></td>
  246. <td class="ft_subber">
  247. <input type="search" spellcheck="false" size="65" name="subber" class="inputtext smaller fti_advanced" placeholder="Translation Group" value="<?Format::form('subber')?>" />
  248. </td>
  249. </tr>
  250. <tr id="size" class="ftr_advanced<?=$HideAdvanced?>">
  251. <td class="label">Size:</td>
  252. <td class="ft_size">
  253. <input type="size_min" spellcheck="false" size="6" name="size_min" class="inputtext smaller fti_advanced" placeholder="Min" value="<?Format::form('size_min')?>" /> -
  254. <input type="size_max" spellcheck="false" size="6" name="size_max" class="inputtext smaller fti_advanced" placeholder="Max" value="<?Format::form('size_max')?>" />
  255. <select name="size_unit" class="ft_size fti_advanced">
  256. <option value="">Unit</option>
  257. <option value="0"<?Format::selected('size_unit', 0)?>>B</option>
  258. <option value="1"<?Format::selected('size_unit', 1)?>>KiB</option>
  259. <option value="2"<?Format::selected('size_unit', 2)?>>MiB</option>
  260. <option value="3"<?Format::selected('size_unit', 3)?>>GiB</option>
  261. <option value="4"<?Format::selected('size_unit', 4)?>>TiB</option>
  262. </select>
  263. </td>
  264. </tr>
  265. <tr id="misc" class="ftr_advanced<?=$HideAdvanced?>">
  266. <td class="label">Misc:</td>
  267. <td class="nobr ft_misc">
  268. <select name="freetorrent" class="ft_freetorrent fti_advanced">
  269. <option value="">Leech Status</option>
  270. <option value="1"<?Format::selected('freetorrent', 1)?>>Freeleech</option>
  271. <option value="2"<?Format::selected('freetorrent', 2)?>>Neutral Leech</option>
  272. <option value="3"<?Format::selected('freetorrent', 3)?>>Either</option>
  273. <option value="0"<?Format::selected('freetorrent', 0)?>>Normal</option>
  274. </select>
  275. <select name="censored" class="ft_censored fti_advanced">
  276. <option value="">Censored?</option>
  277. <option value="1"<?Format::selected('censored', 1)?>>Censored</option>
  278. <option value="0"<?Format::selected('censored', 0)?>>Uncensored</option>
  279. </select>
  280. </td>
  281. </tr>
  282. <tr id="search_terms" class="ftr_basic<?=$HideBasic?>">
  283. <td class="label"><!--Search terms:--></td>
  284. <td class="ftb_searchstr">
  285. <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">
  286. </td>
  287. </tr>
  288. <tr id="tagfilter">
  289. <td class="label"><!--<span title="Use !tag to exclude tag" class="tooltip">Tags (comma-separated):</span>--></td>
  290. <td class="ft_taglist">
  291. <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;
  292. <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;
  293. <input type="radio" name="tags_type" id="tags_type1" value="1"<?Format::selected('tags_type', 1, 'checked')?> /><label for="tags_type1"> All</label>
  294. </td>
  295. </tr>
  296. <tr id="order">
  297. <td class="label">Order by:</td>
  298. <td class="ft_order">
  299. <select name="order_by" style="width: auto;" class="ft_order_by" aria-label="Property to order by">
  300. <option value="time"<?Format::selected('order_by', 'time')?>>Time added</option>
  301. <option value="year"<?Format::selected('order_by', 'year')?>>Year</option>
  302. <option value="size"<?Format::selected('order_by', 'size')?>>Size</option>
  303. <option value="snatched"<?Format::selected('order_by', 'snatched')?>>Snatched</option>
  304. <option value="seeders"<?Format::selected('order_by', 'seeders')?>>Seeders</option>
  305. <option value="leechers"<?Format::selected('order_by', 'leechers')?>>Leechers</option>
  306. <option value="cataloguenumber"<?Format::selected('order_by', 'cataloguenumber')?>>Catalogue Number</option>
  307. <option value="random"<?Format::selected('order_by', 'random')?>>Random</option>
  308. </select>
  309. <select name="order_way" class="ft_order_way" aria-label="Direction to order">
  310. <option value="desc"<?Format::selected('order_way', 'desc')?>>Descending</option>
  311. <option value="asc"<?Format::selected('order_way', 'asc')?>>Ascending</option>
  312. </select>
  313. </td>
  314. </tr>
  315. <tr id="search_group_results">
  316. <td class="label">
  317. <label for="group_results">Group by release:</label>
  318. </td>
  319. <td class="ft_group_results">
  320. <input type="checkbox" value="1" name="group_results" id="group_results"<?=$GroupResults ? ' checked="checked"' : ''?> />
  321. </td>
  322. </tr>
  323. </table>
  324. <table class="layout cat_list ft_cat_list">
  325. <?
  326. $x = 0;
  327. reset($Categories);
  328. foreach ($Categories as $CatKey => $CatName) {
  329. if ($x % 7 == 0) {
  330. if ($x > 0) {
  331. ?>
  332. </tr>
  333. <? } ?>
  334. <tr>
  335. <?
  336. }
  337. $x++;
  338. ?>
  339. <td>
  340. <input type="checkbox" name="filter_cat[<?=($CatKey + 1)?>]" id="cat_<?=($CatKey + 1)?>" value="1"<? if (isset($_GET['filter_cat'][$CatKey + 1])) { ?> checked="checked"<? } ?> />
  341. <label for="cat_<?=($CatKey + 1)?>"><?=$CatName?></label>
  342. </td>
  343. <?
  344. }
  345. ?>
  346. </tr>
  347. </table>
  348. <table class="layout cat_list<? if (empty($LoggedUser['ShowTags'])) { ?> hidden<? } ?>" id="taglist">
  349. <tr>
  350. <?
  351. $GenreTags = $Cache->get_value('genre_tags');
  352. if (!$GenreTags) {
  353. $DB->query('
  354. SELECT Name
  355. FROM tags
  356. WHERE TagType = \'genre\'
  357. ORDER BY Name');
  358. $GenreTags = $DB->collect('Name');
  359. $Cache->cache_value('genre_tags', $GenreTags, 3600 * 6);
  360. }
  361. $x = 0;
  362. foreach ($GenreTags as $Tag) {
  363. ?>
  364. <td><a href="#" onclick="add_tag('<?=$Tag?>'); return false;"><?=$Tag?></a></td>
  365. <?
  366. $x++;
  367. if ($x % 7 == 0) {
  368. ?>
  369. </tr>
  370. <tr>
  371. <?
  372. }
  373. }
  374. if ($x % 7 != 0) { // Padding
  375. ?>
  376. <td colspan="<?=(7 - ($x % 7))?>"> </td>
  377. <? } ?>
  378. </tr>
  379. </table>
  380. <table class="layout cat_list">
  381. <tr>
  382. <td class="label">
  383. <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>
  384. </td>
  385. </tr>
  386. </table>
  387. <div class="submit ft_submit">
  388. <span class="float_left"><?=number_format($NumResults)?> Results</span>
  389. <input type="submit" value="Filter torrents" />
  390. <input type="hidden" name="action" id="ft_type" value="<?=($AdvancedSearch ? 'advanced' : 'basic')?>" />
  391. <input type="hidden" name="searchsubmit" value="1" />
  392. <input type="button" value="Reset" onclick="location.href = 'torrents.php<? if (isset($_GET['action']) && $_GET['action'] === 'advanced') { ?>?action=advanced<? } ?>'" />
  393. &nbsp;&nbsp;
  394. <? if ($Search->has_filters()) { ?>
  395. <input type="submit" name="setdefault" value="Make default" />
  396. <? }
  397. if (!empty($LoggedUser['DefaultSearch'])) { ?>
  398. <input type="submit" name="cleardefault" value="Clear default" />
  399. <? } ?>
  400. </div>
  401. </div>
  402. </div>
  403. </form>
  404. <? if ($NumResults == 0) { ?>
  405. <div class="torrents_nomatch box pad" align="center">
  406. <h2>Your search did not match anything.</h2>
  407. <p>Make sure all names are spelled correctly, or try making your search less specific.</p>
  408. </div>
  409. </div>
  410. <? View::show_footer();die();
  411. }
  412. if ($NumResults < ($Page - 1) * TORRENTS_PER_PAGE + 1) {
  413. $LastPage = ceil($NumResults / TORRENTS_PER_PAGE);
  414. $Pages = Format::get_pages(0, $NumResults, TORRENTS_PER_PAGE);
  415. ?>
  416. <div class="torrents_nomatch box pad" align="center">
  417. <h2>The requested page contains no matches.</h2>
  418. <p>You are requesting page <?=$Page?>, but the search returned only <?=number_format($LastPage) ?> pages.</p>
  419. </div>
  420. <div class="linkbox">Go to page <?=$Pages?></div>
  421. </div>
  422. <?
  423. View::show_footer();die();
  424. }
  425. // List of pages
  426. $Pages = Format::get_pages($Page, $NumResults, TORRENTS_PER_PAGE);
  427. $Bookmarks = Bookmarks::all_bookmarks('torrent');
  428. ?>
  429. <div class="linkbox"><?=$Pages?></div>
  430. <table class="box torrent_table cats <?=$GroupResults ? 'grouping' : 'no_grouping'?>" id="torrent_table">
  431. <tr class="colhead">
  432. <? if ($GroupResults) { ?>
  433. <td class="small"></td>
  434. <? } ?>
  435. <td class="small cats_col"></td>
  436. <td>Name / <a href="<?=header_link('year')?>">Year</a></td>
  437. <td>Files</td>
  438. <td><a href="<?=header_link('time')?>">Time</a></td>
  439. <td><a href="<?=header_link('size')?>">Size</a></td>
  440. <td class="sign snatches">
  441. <a href="<?=header_link('snatched')?>" aria-label="Sort by snatches">
  442. <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>
  443. </a>
  444. </td>
  445. <td class="sign seeders">
  446. <a href="<?=header_link('seeders')?>" aria-label="Sort by seeders">
  447. <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>
  448. </a>
  449. </td>
  450. <td class="sign leechers">
  451. <a href="<?=header_link('leechers')?>" aria-label="Sort by leechers">
  452. <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>
  453. </a>
  454. </td>
  455. </tr>
  456. <?
  457. // Start printing torrent list
  458. foreach ($Results as $Key => $GroupID) {
  459. $GroupInfo = $Groups[$GroupID];
  460. if (empty($GroupInfo['Torrents'])) {
  461. continue;
  462. }
  463. $CategoryID = $GroupInfo['CategoryID'];
  464. $GroupYear = $GroupInfo['Year'];
  465. $Artists = $GroupInfo['Artists'];
  466. $GroupCatalogueNumber = $GroupInfo['CatalogueNumber'];
  467. $GroupPages = $GroupInfo['Pages'];
  468. $GroupSeries = $GroupInfo['Series']
  469. $GroupStudio = $GroupInfo['Studio'];
  470. $GroupDLsiteID = $GroupInfo['DLSiteID'];
  471. $GroupName = empty($GroupInfo['Name']) ? (empty($GroupInfo['NameRJ']) ? $GroupInfo['NameJP'] : $GroupInfo['NameRJ']) : $GroupInfo['Name'];
  472. if ($GroupResults) {
  473. $Torrents = $GroupInfo['Torrents'];
  474. $GroupTime = $MaxSize = $TotalLeechers = $TotalSeeders = $TotalSnatched = 0;
  475. foreach ($Torrents as $T) {
  476. $GroupTime = max($GroupTime, strtotime($T['Time']));
  477. $MaxSize = max($MaxSize, $T['Size']);
  478. $TotalLeechers += $T['Leechers'];
  479. $TotalSeeders += $T['Seeders'];
  480. $TotalSnatched += $T['Snatched'];
  481. }
  482. } else {
  483. $TorrentID = $Key;
  484. $Torrents = [$TorrentID => $GroupInfo['Torrents'][$TorrentID]];
  485. }
  486. $TorrentTags = new Tags($GroupInfo['TagList']);
  487. if (isset($Artists)) {
  488. $DisplayName = '<div class="torrent_artists">'.Artists::display_artists($Artists).'</div> ';
  489. } else {
  490. $DisplayName = '';
  491. }
  492. $SnatchedGroupClass = $GroupInfo['Flags']['IsSnatched'] ? ' snatched_group' : '';
  493. if ($GroupResults && (count($Torrents) > 1 && isset($GroupedCategories[$CategoryID - 1]))) {
  494. // These torrents are in a group
  495. $CoverArt = $GroupInfo['WikiImage'];
  496. $DisplayName .= "<a class=\"torrent_title\" href=\"torrents.php?id=$GroupID\" ";
  497. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  498. $DisplayName .= 'data-cover="'.ImageTools::process($CoverArt, 'thumb').'" ';
  499. }
  500. $DisplayName .= "dir=\"ltr\">$GroupName</a>";
  501. if ($GroupYear) {
  502. $DisplayName .= " [$GroupYear]";
  503. }
  504. if ($GroupSeries) {
  505. $DisplayName .= " [$GroupSeries]";
  506. }
  507. if ($GroupStudio) {
  508. $DisplayName .= " [$GroupStudio]";
  509. }
  510. if ($GroupCatalogueNumber) {
  511. $DisplayName .= " [$GroupCatalogueNumber]";
  512. }
  513. if ($GroupPages) {
  514. $DisplayName .= " [{$GroupPages}p]";
  515. }
  516. if ($GroupDLsiteID) {
  517. $DisplayName .= " [$GroupDLsiteID]";
  518. }
  519. ?>
  520. <tr class="group<?=$SnatchedGroupClass?>">
  521. <?
  522. $ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1);
  523. ?>
  524. <td class="center">
  525. <div id="showimg_<?=$GroupID?>" class="<?=($ShowGroups ? 'hide' : 'show')?>_torrents">
  526. <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>
  527. </div>
  528. </td>
  529. <td class="center cats_col">
  530. <div title="<?=Format::pretty_category($CategoryID)?>" class="tooltip <?=Format::css_category($CategoryID)?>">
  531. </div>
  532. </td>
  533. <td colspan="2" class="big_info">
  534. <div class="group_info clear">
  535. <?=$DisplayName?>
  536. <? if (in_array($GroupID, $Bookmarks)) { ?>
  537. <span class="remove_bookmark float_right">
  538. <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="brackets" onclick="Unbookmark('torrent', <?=$GroupID?>, 'Bookmark'); return false;">Remove bookmark</a>
  539. </span>
  540. <? } else { ?>
  541. <span class="add_bookmark float_right">
  542. <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="brackets" onclick="Bookmark('torrent', <?=$GroupID?>, 'Remove bookmark'); return false;">Bookmark</a>
  543. </span>
  544. <? } ?>
  545. <br />
  546. <div class="tags"><?=$TorrentTags->format('torrents.php?'.$Action.'&amp;taglist=')?></div>
  547. </div>
  548. </td>
  549. <td class="nobr"><?=time_diff($GroupTime, 1)?></td>
  550. <td class="number_column nobr"><?=Format::get_size($MaxSize)?> (Max)</td>
  551. <td class="number_column"><?=number_format($TotalSnatched)?></td>
  552. <td class="number_column<?=($TotalSeeders == 0 ? ' r00' : '')?>"><?=number_format($TotalSeeders)?></td>
  553. <td class="number_column"><?=number_format($TotalLeechers)?></td>
  554. </tr>
  555. <?
  556. foreach ($Torrents as $TorrentID => $Data) {
  557. $Data['CategoryID'] = $CategoryID;
  558. // All of the individual torrents in the group
  559. //Get report info for each torrent, use the cache if available, if not, add to it.
  560. $Reported = false;
  561. $Reports = Torrents::get_reports($TorrentID);
  562. if (count($Reports) > 0) {
  563. $Reported = true;
  564. }
  565. $SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
  566. $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
  567. if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
  568. if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
  569. $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
  570. $Tor = new BencodeTorrent($TorrentFile, false, false);
  571. $TorrentFileName = $Tor->Dec['info']['name'];
  572. $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
  573. }
  574. $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'];
  575. }
  576. ?>
  577. <tr class="group_torrent groupid_<?=$GroupID?> <?=$SnatchedTorrentClass . $SnatchedGroupClass . (!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1 ? ' hidden' : '')?>">
  578. <td colspan="3">
  579. <span>
  580. [ <a href="<?=$TorrentDL?>" class="tooltip" title="Download"><?=$Data['HasFile'] ? 'DL' : 'Missing'?></a>
  581. <? if (isset($TorrentMG)) { ?>
  582. | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
  583. <? }
  584. if (Torrents::can_use_token($Data)) { ?>
  585. | <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>
  586. <? } ?>
  587. | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]
  588. </span>
  589. &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>
  590. </td>
  591. <td class="number_column"><?=$Data['FileCount']?></td>
  592. <td class="nobr"><?=time_diff($Data['Time'], 1)?></td>
  593. <td class="number_column nobr"><?=Format::get_size($Data['Size'])?></td>
  594. <td class="number_column"><?=number_format($Data['Snatched'])?></td>
  595. <td class="number_column<?=($Data['Seeders'] == 0) ? ' r00' : ''?>"><?=number_format($Data['Seeders'])?></td>
  596. <td class="number_column"><?=number_format($Data['Leechers'])?></td>
  597. </tr>
  598. <?
  599. }
  600. } else {
  601. // Viewing a type that does not require grouping
  602. $TorrentID = key($Torrents);
  603. $Data = current($Torrents);
  604. $Reported = false;
  605. $Reports = Torrents::get_reports($TorrentID);
  606. if (count($Reports) > 0) {
  607. $Reported = true;
  608. }
  609. $Data['CategoryID'] = $CategoryID;
  610. $CoverArt = $GroupInfo['WikiImage'];
  611. $DisplayName .= "<a class=\"torrent_name\" href=\"torrents.php?id=$GroupID&amp;torrentid=$TorrentID#torrent$TorrentID\" ";
  612. if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
  613. $DisplayName .= 'data-cover="'.ImageTools::process($CoverArt, 'thumb').'" ';
  614. }
  615. $DisplayName .= "dir=\"ltr\">$GroupName</a>";
  616. if (isset($GroupedCategories[$CategoryID - 1])) {
  617. if ($GroupYear) {
  618. $DisplayName .= " [$GroupYear]";
  619. }
  620. if ($GroupSeries) {
  621. $DisplayName .= " [$GroupSeries]";
  622. }
  623. if ($GroupStudio) {
  624. $DisplayName .= " [$GroupStudio]";
  625. }
  626. if ($GroupCatalogueNumber) {
  627. $DisplayName .= " [$GroupCatalogueNumber]";
  628. }
  629. if ($GroupPages) {
  630. $DisplayName .= " [{$GroupPages}p]";
  631. }
  632. if ($GroupDLsiteID) {
  633. $DisplayName .= " [$GroupDLsiteID]";
  634. }
  635. $ExtraInfo = Torrents::torrent_info($Data, true, true);
  636. } elseif ($Data['IsSnatched']) {
  637. $ExtraInfo = Format::torrent_label('Snatched!');
  638. } else {
  639. $ExtraInfo = '';
  640. }
  641. $SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
  642. $TorrentDL = "torrents.php?action=download&amp;id=".$TorrentID."&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
  643. if (!empty(G::$LoggedUser) && (G::$LoggedUser['ShowMagnets'] ?? false)) {
  644. if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
  645. $TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
  646. $Tor = new BencodeTorrent($TorrentFile, false, false);
  647. $TorrentFileName = $Tor->Dec['info']['name'];
  648. $Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
  649. }
  650. $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'];
  651. }
  652. ?>
  653. <tr class="torrent<?=$SnatchedTorrentClass . $SnatchedGroupClass?>">
  654. <? if ($GroupResults) { ?>
  655. <td></td>
  656. <? } ?>
  657. <td class="center cats_col">
  658. <div title="<?=Format::pretty_category($CategoryID)?>" class="tooltip <?=Format::css_category($CategoryID)?>"></div>
  659. </td>
  660. <td class="big_info">
  661. <div class="group_info clear">
  662. <div class="float_right">
  663. <span>
  664. [ <a href="<?=$TorrentDL?>" class="tooltip" title="Download">DL</a>
  665. <? if (isset($TorrentMG)) { ?>
  666. | <a href="<?=$TorrentMG?>" class="tooltip" title="Magnet Link">MG</a>
  667. <? }
  668. if (Torrents::can_use_token($Data)) { ?>
  669. | <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>
  670. <? } ?>
  671. | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" class="tooltip" title="Report">RP</a> ]
  672. </span>
  673. <br />
  674. <? if (in_array($GroupID, $Bookmarks)) { ?>
  675. <span class="remove_bookmark float_right">
  676. <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="brackets" onclick="Unbookmark('torrent', <?=$GroupID?>, 'Bookmark'); return false;">Remove bookmark</a>
  677. </span>
  678. <? } else { ?>
  679. <span class="add_bookmark float_right">
  680. <a href="#" id="bookmarklink_torrent_<?=$GroupID?>" class="brackets" onclick="Bookmark('torrent', <?=$GroupID?>, 'Remove bookmark'); return false;">Bookmark</a>
  681. </span>
  682. <? } ?>
  683. </div>
  684. <?=$DisplayName?>
  685. <br />
  686. <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>
  687. <div class="tags"><?=$TorrentTags->format("torrents.php?$Action&amp;taglist=")?></div>
  688. </div>
  689. </td>
  690. <td class="number_column"><?=$Data['FileCount']?></td>
  691. <td class="nobr"><?=time_diff($Data['Time'], 1)?></td>
  692. <td class="number_column nobr"><?=Format::get_size($Data['Size'])?></td>
  693. <td class="number_column"><?=number_format($Data['Snatched'])?></td>
  694. <td class="number_column<?=($Data['Seeders'] == 0) ? ' r00' : ''?>"><?=number_format($Data['Seeders'])?></td>
  695. <td class="number_column"><?=number_format($Data['Leechers'])?></td>
  696. </tr>
  697. <?
  698. }
  699. }
  700. ?>
  701. </table>
  702. <div class="linkbox"><?=$Pages?></div>
  703. </div>
  704. <? View::show_footer(); ?>