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

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