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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <?php
  2. #declare(strict_types=1);
  3. define('COLLAGES_PER_PAGE', 25);
  4. list($Page, $Limit) = Format::page_limit(COLLAGES_PER_PAGE);
  5. $OrderVals = array('Time', 'Name', 'Subscribers', 'Torrents', 'Updated');
  6. $WayVals = array('Ascending', 'Descending');
  7. $OrderTable = array('Time' => 'ID', 'Name' => 'c.Name', 'Subscribers' => 'c.Subscribers', 'Torrents' => 'NumTorrents', 'Updated' => 'c.Updated');
  8. $WayTable = array('Ascending' => 'ASC', 'Descending' => 'DESC');
  9. // Are we searching in bodies, or just names?
  10. if (!empty($_GET['type'])) {
  11. $Type = $_GET['type'];
  12. if (!in_array($Type, array('c.name', 'description'))) {
  13. $Type = 'c.name';
  14. }
  15. } else {
  16. $Type = 'c.name';
  17. }
  18. if (!empty($_GET['search'])) {
  19. // What are we looking for? Let's make sure it isn't dangerous
  20. $Search = db_string(trim($_GET['search']));
  21. // Break search string down into individual words
  22. $Words = explode(' ', $Search);
  23. }
  24. if (!empty($_GET['tags'])) {
  25. $Tags = explode(',', db_string(trim($_GET['tags'])));
  26. foreach ($Tags as $ID => $Tag) {
  27. $Tags[$ID] = Misc::sanitize_tag($Tag);
  28. }
  29. }
  30. if (!empty($_GET['cats'])) {
  31. $Categories = $_GET['cats'];
  32. foreach ($Categories as $Cat => $Accept) {
  33. if (empty($CollageCats[$Cat]) || !$Accept) {
  34. unset($Categories[$Cat]);
  35. }
  36. }
  37. $Categories = array_keys($Categories);
  38. } else {
  39. $Categories = array(1, 2, 3, 4, 5, 6, 7);
  40. }
  41. // Ordering
  42. if (!empty($_GET['order_by']) && !empty($OrderTable[$_GET['order_by']])) {
  43. $Order = $OrderTable[$_GET['order_by']];
  44. } else {
  45. $Order = 'ID';
  46. }
  47. if (!empty($_GET['order_way']) && !empty($WayTable[$_GET['order_way']])) {
  48. $Way = $WayTable[$_GET['order_way']];
  49. } else {
  50. $Way = 'DESC';
  51. }
  52. $BookmarkView = !empty($_GET['bookmarks']);
  53. if ($BookmarkView) {
  54. $Categories[] = 0;
  55. $BookmarkJoin = 'INNER JOIN bookmarks_collages AS bc ON c.ID = bc.CollageID';
  56. } else {
  57. $BookmarkJoin = '';
  58. }
  59. $BaseSQL = $SQL = "
  60. SELECT
  61. SQL_CALC_FOUND_ROWS
  62. c.ID,
  63. c.Name,
  64. c.NumTorrents,
  65. c.TagList,
  66. c.CategoryID,
  67. c.UserID,
  68. c.Subscribers,
  69. c.Updated
  70. FROM collages AS c
  71. $BookmarkJoin
  72. WHERE Deleted = '0'";
  73. if ($BookmarkView) {
  74. $SQL .= " AND bc.UserID = '" . $LoggedUser['ID'] . "'";
  75. }
  76. if (!empty($Search)) {
  77. $SQL .= " AND $Type LIKE '%";
  78. $SQL .= implode("%' AND $Type LIKE '%", $Words);
  79. $SQL .= "%'";
  80. }
  81. if (isset($_GET['tags_type']) && $_GET['tags_type'] === '0') { // Any
  82. $_GET['tags_type'] = '0';
  83. } else { // All
  84. $_GET['tags_type'] = '1';
  85. }
  86. if (!empty($Tags)) {
  87. $SQL.= " AND (TagList LIKE '%";
  88. if ($_GET['tags_type'] === '0') {
  89. $SQL .= implode("%' OR TagList LIKE '%", $Tags);
  90. } else {
  91. $SQL .= implode("%' AND TagList LIKE '%", $Tags);
  92. }
  93. $SQL .= "%')";
  94. }
  95. if (!empty($_GET['userid'])) {
  96. $UserID = $_GET['userid'];
  97. if (!is_number($UserID)) {
  98. error(404);
  99. }
  100. $User = Users::user_info($UserID);
  101. $Perms = Permissions::get_permissions($User['PermissionID']);
  102. $UserClass = $Perms['Class'];
  103. $UserLink = '<a href="user.php?id='.$UserID.'">'.$User['Username'].'</a>';
  104. if (!empty($_GET['contrib'])) {
  105. if (!check_paranoia('collagecontribs', $User['Paranoia'], $UserClass, $UserID)) {
  106. error(403);
  107. }
  108. $DB->query("
  109. SELECT DISTINCT CollageID
  110. FROM collages_torrents
  111. WHERE UserID = $UserID");
  112. $CollageIDs = $DB->collect('CollageID');
  113. if (empty($CollageIDs)) {
  114. $SQL .= " AND 0";
  115. } else {
  116. $SQL .= " AND c.ID IN(".db_string(implode(',', $CollageIDs)).')';
  117. }
  118. } else {
  119. if (!check_paranoia('collages', $User['Paranoia'], $UserClass, $UserID)) {
  120. error(403);
  121. }
  122. $SQL .= " AND UserID = '".$_GET['userid']."'";
  123. }
  124. $Categories[] = 0;
  125. }
  126. if (!empty($Categories)) {
  127. $SQL .= " AND CategoryID IN(".db_string(implode(',', $Categories)).')';
  128. }
  129. if (isset($_GET['action']) && $_GET['action'] === 'mine') {
  130. $SQL = $BaseSQL;
  131. $SQL .= "
  132. AND c.UserID = '".$LoggedUser['ID']."'
  133. AND c.CategoryID = 0";
  134. }
  135. $SQL .= "
  136. ORDER BY $Order $Way
  137. LIMIT $Limit";
  138. $DB->query($SQL);
  139. $Collages = $DB->to_array();
  140. $DB->query('SELECT FOUND_ROWS()');
  141. list($NumResults) = $DB->next_record();
  142. View::show_header(($BookmarkView) ? 'Your bookmarked collections' : 'Collections');
  143. ?>
  144. <div>
  145. <div class="header">
  146. <?php if ($BookmarkView) { ?>
  147. <h2>Your bookmarked collections</h2>
  148. <?php } else { ?>
  149. <h2>Collections<?=(!empty($UserLink) ? (isset($CollageIDs) ? " with contributions by $UserLink" : " started by $UserLink") : '')?>
  150. </h2>
  151. <?php } ?>
  152. </div>
  153. <?php if (!$BookmarkView) { ?>
  154. <div class="box pad">
  155. <form class="search_form" name="collages" action="" method="get">
  156. <div>
  157. <input type="hidden" name="action" value="search" />
  158. </div>
  159. <table cellpadding="6" cellspacing="1" border="0" class="layout torrent_search" width="100%">
  160. <tr id="search_terms">
  161. <td class="label"></td>
  162. <td>
  163. <input type="search" name="search" size="60" placeholder="Search terms"
  164. value="<?=(!empty($_GET['search']) ? display_str($_GET['search']) : '')?>" />
  165. </td>
  166. </tr>
  167. <tr id="tagfilter">
  168. <td class="label"></td>
  169. <td>
  170. <input type="text" id="tags" name="tags" size="60" placeholder="Tags (comma-separated)"
  171. value="<?=(!empty($_GET['tags']) ? display_str($_GET['tags']) : '')?>"
  172. <?php Users::has_autocomplete_enabled('other'); ?>
  173. />
  174. &ensp;
  175. <input type="radio" name="tags_type" id="tags_type0" value="0" <?Format::selected(
  176. 'tags_type',
  177. 0,
  178. 'checked'
  179. )?> />
  180. <label for="tags_type0"> Any</label>&nbsp;&nbsp;
  181. <input type="radio" name="tags_type" id="tags_type1" value="1" <?Format::selected(
  182. 'tags_type',
  183. 1,
  184. 'checked'
  185. )?> />
  186. <label for="tags_type1"> All</label>
  187. </td>
  188. </tr>
  189. <tr id="categories">
  190. <td class="label">Categories</td>
  191. <td>
  192. <?php foreach ($CollageCats as $ID => $Cat) { ?>
  193. <input type="checkbox" value="1" name="cats[<?=$ID?>]"
  194. id="cats_<?=$ID?>" <?php if (in_array($ID, $Categories)) {
  195. echo ' checked="checked"' ;
  196. } ?> />
  197. <label for="cats_<?=$ID?>"><?=$Cat?></label>&nbsp;&nbsp;
  198. <?php } ?>
  199. </td>
  200. </tr>
  201. <tr id="search_name_description">
  202. <td class="label">Search In</td>
  203. <td>
  204. <input type="radio" name="type" value="c.name" <?php if ($Type==='c.name') {
  205. echo 'checked="checked" ' ;
  206. }
  207. ?>/> Names&nbsp;&nbsp;
  208. <input type="radio" name="type" value="description" <?php if ($Type==='description') {
  209. echo 'checked="checked" ' ;
  210. } ?>/> Descriptions
  211. </td>
  212. </tr>
  213. <tr id="order_by">
  214. <td class="label">Order By</td>
  215. <td>
  216. <select name="order_by" class="ft_order_by">
  217. <?php foreach ($OrderVals as $Cur) { ?>
  218. <option value="<?=$Cur?>" <?php if (isset($_GET['order_by']) && $_GET['order_by']===$Cur || (!isset($_GET['order_by']) && $Cur==='Time')) {
  219. echo ' selected="selected"' ;
  220. } ?>><?=$Cur?>
  221. </option>
  222. <?php } ?>
  223. </select>
  224. <select name="order_way" class="ft_order_way">
  225. <?php foreach ($WayVals as $Cur) { ?>
  226. <option value="<?=$Cur?>" <?php if (isset($_GET['order_way']) && $_GET['order_way']===$Cur || (!isset($_GET['order_way']) &&
  227. $Cur==='Descending')) {
  228. echo ' selected="selected"' ;
  229. } ?>><?=$Cur?>
  230. </option>
  231. <?php } ?>
  232. </select>
  233. </td>
  234. </tr>
  235. <tr>
  236. <td colspan="2" class="center">
  237. <input type="submit" class="button-primary" value="Search" />
  238. </td>
  239. </tr>
  240. </table>
  241. </form>
  242. </div>
  243. <?php } // if (!$BookmarkView)?>
  244. <div class="linkbox">
  245. <?php
  246. if (!$BookmarkView) {
  247. if (check_perms('site_collages_create')) {
  248. ?>
  249. <a href="collages.php?action=new" class="brackets">New collection</a>
  250. <?php
  251. }
  252. if (check_perms('site_collages_personal')) {
  253. $DB->query("
  254. SELECT ID
  255. FROM collages
  256. WHERE UserID = '$LoggedUser[ID]'
  257. AND CategoryID = '0'
  258. AND Deleted = '0'");
  259. $CollageCount = $DB->record_count();
  260. if ($CollageCount === 1) {
  261. list($CollageID) = $DB->next_record(); ?>
  262. <a href="collages.php?id=<?=$CollageID?>"
  263. class="brackets">Personal collection</a>
  264. <?php
  265. } elseif ($CollageCount > 1) { ?>
  266. <a href="collages.php?action=mine" class="brackets">Personal collections</a>
  267. <?php
  268. }
  269. }
  270. if (check_perms('site_collages_subscribe')) {
  271. ?>
  272. <a href="userhistory.php?action=subscribed_collages" class="brackets">Subscribed collections</a>
  273. <?php
  274. } ?>
  275. <a href="bookmarks.php?type=collages" class="brackets">Bookmarked collections</a>
  276. <?php if (check_perms('site_collages_recover')) { ?>
  277. <a href="collages.php?action=recover" class="brackets">Recover collection</a>
  278. <?php
  279. }
  280. if (check_perms('site_collages_create') || check_perms('site_collages_personal') || check_perms('site_collages_recover')) {
  281. ?>
  282. <br />
  283. <?php
  284. } ?>
  285. <a href="collages.php?userid=<?=$LoggedUser['ID']?>"
  286. class="brackets">Collections you started</a>
  287. <a href="collages.php?userid=<?=$LoggedUser['ID']?>&amp;contrib=1"
  288. class="brackets">Collections you contributed to</a>
  289. <br /><br />
  290. <?php
  291. } else { ?>
  292. <a href="bookmarks.php?type=torrents" class="brackets">Torrents</a>
  293. <a href="bookmarks.php?type=artists" class="brackets">Artists</a>
  294. <a href="bookmarks.php?type=collages" class="brackets">Collections</a>
  295. <a href="bookmarks.php?type=requests" class="brackets">Requests</a>
  296. <br />
  297. <?php
  298. }
  299. $Pages = Format::get_pages($Page, $NumResults, COLLAGES_PER_PAGE, 9);
  300. echo $Pages;
  301. ?>
  302. </div>
  303. <?php if (count($Collages) === 0) { ?>
  304. <div class="box pad" align="center">
  305. <?php if ($BookmarkView) { ?>
  306. <h2>You have not bookmarked any collections.</h2>
  307. <?php } else { ?>
  308. <h2>Your search did not match anything.</h2>
  309. <p>Make sure all names are spelled correctly, or try making your search less specific.</p>
  310. <?php } ?>
  311. </div>
  312. <!--box-->
  313. </div>
  314. <!--content-->
  315. <?php View::show_footer();
  316. error();
  317. }
  318. ?>
  319. <table width="100%" id="collage_table" class="collage_table box">
  320. <tr class="colhead">
  321. <td>Category</td>
  322. <td>Collection</td>
  323. <td>Torrents</td>
  324. <td>Subscribers</td>
  325. <td>Updated</td>
  326. <td>Author</td>
  327. </tr>
  328. <?php
  329. foreach ($Collages as $Collage) {
  330. list($ID, $Name, $NumTorrents, $TagList, $CategoryID, $UserID, $Subscribers, $Updated) = $Collage;
  331. $TorrentTags = new Tags($TagList);
  332. // Print results?>
  333. <tr
  334. class="row<?=($BookmarkView) ? " bookmark_$ID" : ''; ?>">
  335. <td class="center">
  336. <a
  337. href="collages.php?action=search&amp;cats[<?=(int)$CategoryID?>]=1"><?=$CollageCats[(int)$CategoryID]?></a>
  338. </td>
  339. <td>
  340. <a class="torrent_title" id="collage_name"
  341. href="collages.php?id=<?=$ID?>"><?=$Name?></a>
  342. <?php if ($BookmarkView) { ?>
  343. <span class="float_right">
  344. <a href="#"
  345. onclick="Unbookmark('collage', <?=$ID?>, ''); return false;"
  346. class="brackets">Remove bookmark</a>
  347. </span>
  348. <?php } ?>
  349. <div class="tags"><?=$TorrentTags->format('collages.php?action=search&amp;tags=')?>
  350. </div>
  351. </td>
  352. <td class="number_column"><?=number_format((int)$NumTorrents)?>
  353. </td>
  354. <td class="number_column"><?=number_format((int)$Subscribers)?>
  355. </td>
  356. <td class="nobr"><?=time_diff($Updated)?>
  357. </td>
  358. <td><?=Users::format_username($UserID, false, false, false)?>
  359. </td>
  360. </tr>
  361. <?php
  362. }
  363. ?>
  364. </table>
  365. <div class="linkbox"><?=$Pages?>
  366. </div>
  367. </div>
  368. <?php View::show_footer();