PageRenderTime 128ms CodeModel.GetById 28ms RepoModel.GetById 8ms app.codeStats 0ms

/sections/torrents/browse.php

https://github.com/opensciencefund/gazelle
PHP | 1041 lines | 921 code | 75 blank | 45 comment | 265 complexity | 04596e1a82a9b03b1ad6f65b76c8f03f MD5 | raw file
  1. <?
  2. /************************************************************************
  3. *-------------------- Browse page ---------------------------------------
  4. * Welcome to one of the most complicated pages in all of gazelle - the
  5. * browse page.
  6. *
  7. * This is the page that is displayed when someone visits torrents.php.
  8. *
  9. * It also handle snatch lists, and seeding/leeching/uploaded lists.
  10. *
  11. * It offers normal and advanced search, as well as enabled/disabled
  12. * grouping.
  13. *
  14. * Don't blink.
  15. *************************************************************************/
  16. $ErrorPage = true;
  17. define('EXPLAIN_HACK',false);
  18. if(EXPLAIN_HACK){
  19. $SCFR = '';
  20. } else {
  21. $SCFR = 'SQL_CALC_FOUND_ROWS';
  22. }
  23. // Function to build a SQL WHERE to search for a string
  24. // Offers exact searching, fulltext searching, and negative searching
  25. function build_search($SearchStr,$Field,$Exact=false,$SQLWhere='',$FullText=0,&$FilterString='') {
  26. if($SQLWhere!='') { $AddWhere=false; } else { $AddWhere=true; }
  27. if(!$Exact) {
  28. if ($FullText && preg_match('/[^a-zA-Z0-9 ]/i',$SearchStr)) { $FullText=0; }
  29. $SearchLength=strlen(trim($SearchStr));
  30. $SearchStr=preg_replace('/\s\s+/',' ',trim($SearchStr));
  31. $SearchStr=preg_replace_callback('/"(([^"])*)"/','quotes',$SearchStr);
  32. $SearchStr=explode(" ",$SearchStr);
  33. $FilterString="(.+?)";
  34. foreach($SearchStr as $SearchVal) {
  35. if(trim($SearchVal)!='') {
  36. $SearchVal=trim($SearchVal);
  37. $SearchVal=str_replace("{{SPACE}}"," ",$SearchVal);
  38. // Choose between fulltext or LIKE based off length of the string
  39. if ($FullText && strlen($SearchVal)>2) {
  40. if($SQLWhere!='') { $SQLWhere.=" AND "; }
  41. if (substr($SearchVal,0,1)=='-') {
  42. $SQLWhere.="MATCH (".$Field.") AGAINST ('".db_string($SearchVal)."' IN BOOLEAN MODE)";
  43. } else {
  44. $SQLWhere.="MATCH (".$Field.") AGAINST ('".db_string($SearchVal)."')";
  45. }
  46. } else {
  47. if($SQLWhere!='') { $SQLWhere.=" AND "; }
  48. if (substr($SearchVal,0,1)=="-") {
  49. $SQLWhere.=$Field." NOT LIKE '%".db_string(substr($SearchVal,1))."%'";
  50. } else {
  51. $SQLWhere.=$Field." LIKE '%".db_string($SearchVal)."%'";
  52. }
  53. }
  54. $FilterString.="(".$SearchVal.")(.+?)";
  55. }
  56. }
  57. } else {
  58. if($SQLWhere!='') { $SQLWhere.=" AND "; }
  59. $SQLWhere.=$Field." LIKE '".db_string($SearchStr)."'";
  60. $FilterString.="(.+?)(".$SearchStr.")(.+?)";
  61. }
  62. $Search = 1;
  63. $FilterString="/".$FilterString."/si";
  64. if($SQLWhere!='' && $AddWhere) { $SQLWhere="WHERE ".$SQLWhere; }
  65. return $SQLWhere;
  66. }
  67. function quotes($Str) {
  68. $Str = str_replace(' ','{{SPACE}}',trim($Str[1]));
  69. return ' '.$Str.' ';
  70. }
  71. // The "order by x" links on columns headers
  72. function header_link($SortKey,$DefaultWay="DESC") {
  73. global $OrderBy,$OrderWay;
  74. if($SortKey==$OrderBy) {
  75. if($OrderWay=="DESC") { $NewWay="ASC"; }
  76. else { $NewWay="DESC"; }
  77. } else { $NewWay=$DefaultWay; }
  78. return "torrents.php?order_way=".$NewWay."&amp;order_by=".$SortKey."&amp;".get_url(array('order_way','order_by'));
  79. }
  80. // Setting default search options
  81. if($_GET['setdefault']) {
  82. $UnsetList[]='/(&?page\=.+?&?)/i';
  83. $UnsetList[]='/(&?setdefault\=.+?&?)/i';
  84. $DB->query("SELECT SiteOptions FROM users_info WHERE UserID='".db_string($LoggedUser['ID'])."'");
  85. list($SiteOptions)=$DB->next_record(MYSQLI_NUM, true);
  86. $SiteOptions=unserialize($SiteOptions);
  87. $SiteOptions['DefaultSearch']=preg_replace($UnsetList,'',$_SERVER['QUERY_STRING']);
  88. $DB->query("UPDATE users_info SET SiteOptions='".db_string(serialize($SiteOptions))."' WHERE UserID='".db_string($LoggedUser['ID'])."'");
  89. $Cache->begin_transaction('user_info_heavy_'.$UserID);
  90. $Cache->update_row(false, array('DefaultSearch'=>preg_replace($UnsetList,'',$_SERVER['QUERY_STRING'])));
  91. $Cache->commit_transaction(0);
  92. // Clearing default search options
  93. } elseif($_GET['cleardefault']) {
  94. $DB->query("SELECT SiteOptions FROM users_info WHERE UserID='".db_string($LoggedUser['ID'])."'");
  95. list($SiteOptions)=$DB->next_record(MYSQLI_NUM, true);
  96. $SiteOptions=unserialize($SiteOptions);
  97. $SiteOptions['DefaultSearch']='';
  98. $DB->query("UPDATE users_info SET SiteOptions='".db_string(serialize($SiteOptions))."' WHERE UserID='".db_string($LoggedUser['ID'])."'");
  99. $Cache->begin_transaction('user_info_heavy_'.$UserID);
  100. $Cache->update_row(false, array('DefaultSearch'=>''));
  101. $Cache->commit_transaction(0);
  102. // Use default search options
  103. } elseif(!$_SERVER['QUERY_STRING'] && $LoggedUser['DefaultSearch']) {
  104. parse_str($LoggedUser['DefaultSearch'],$_GET);
  105. }
  106. // If a user is hammering the search page (either via a <script type="text/javascript">, or just general zeal)
  107. if($_SERVER['QUERY_STRING'] != '' && !check_perms('torrents_search_fast') && $_SERVER['QUERY_STRING'] != 'action=basic' && $_SERVER['QUERY_STRING'] != 'action=advanced') {
  108. if($LoggedUser['last_browse']>time()-1) {
  109. error('You can only search for torrents once every second.');
  110. } else {
  111. $_SESSION['logged_user']['last_browse'] = time();
  112. }
  113. }
  114. $OrderBy="s3"; // We order by GroupTime by default
  115. $OrderWay="DESC"; // We also order descending by default
  116. list($Page,$Limit) = page_limit(TORRENTS_PER_PAGE);
  117. if (preg_match('/^s[1-7]$/',$_GET['order_by'])) { $OrderBy=strtolower($_GET['order_by']); }
  118. if (in_array(strtolower($_GET['order_way']),array('desc','asc'))) { $OrderWay=strtoupper($_GET['order_way']); }
  119. // Uploaded, seeding, leeching, snatched lists
  120. if($_GET['userid'] && is_number($_GET['userid'])) {
  121. $UserID=ceil($_GET['userid']);
  122. $DB->query("SELECT Paranoia FROM users_main WHERE ID='".$UserID."'");
  123. list($Paranoia)=$DB->next_record();
  124. $TorrentWhere='';
  125. $TorrentJoin='';
  126. if($_GET['type']=="uploaded") {
  127. if(!check_perms('users_view_uploaded') && $UserID != $LoggedUser['ID'] && $Paranoia>=3) { error(403); }
  128. $TorrentWhere="WHERE t.UserID='".$UserID."'";
  129. $Title="Uploaded Torrents";
  130. } elseif($_GET['type']=="seeding") {
  131. if(!check_perms('users_view_seedleech') && $UserID!=$LoggedUser['ID'] && $Paranoia>=1) { error(403); }
  132. $TorrentJoin="JOIN xbt_files_users AS xfu ON xfu.fid=t.ID AND xfu.uid='$UserID' AND xfu.remaining=0";
  133. $Title="Seeding Torrents";
  134. $TimeField="xfu.mtime";
  135. $TimeLabel="Seeding Time";
  136. } elseif($_GET['type']=="leeching") {
  137. if(!check_perms('users_view_seedleech') && $UserID!=$LoggedUser['ID'] && $Paranoia>=1) { error(403); }
  138. $TorrentJoin="JOIN xbt_files_users AS xfu ON xfu.fid=t.ID AND xfu.uid='$UserID' AND xfu.remaining>0";
  139. $Title="Leeching Torrents";
  140. $TimeField="xfu.mtime";
  141. $TimeLabel="Leeching Time";
  142. } elseif($_GET['type']=="snatched") {
  143. if(!check_perms('users_view_seedleech') && $UserID!=$LoggedUser['ID'] && $Paranoia>=2) { error(403); }
  144. $TorrentJoin="JOIN xbt_snatched AS xs ON xs.fid=t.ID AND xs.uid='$UserID'";
  145. $Title="Snatched Torrents";
  146. $TimeField="xs.tstamp";
  147. $TimeLabel="Snatched Time";
  148. } else {
  149. // Something fishy in $_GET['type']
  150. unset($UserID);
  151. unset($_GET['userid']);
  152. }
  153. if ($TorrentJoin || $TorrentWhere) {
  154. $_GET['disablegrouping']=1; // We disable grouping on these lists
  155. }
  156. }
  157. $DisableGrouping = 0;
  158. // If grouping is disabled
  159. if (($LoggedUser['DisableGrouping'] && !$_GET['enablegrouping']) || $_GET['disablegrouping']=='1' || $_GET['artistname']!='') {
  160. $DisableGrouping=1;
  161. }
  162. // Advanced search
  163. if((strtolower($_GET['action'])=="advanced" || ($LoggedUser['SearchType'] && strtolower($_GET['action'])!="basic")) && check_perms('site_advanced_search')) {
  164. $TorrentSpecifics=0; // How many options are we searching by? (Disabled grouping only)
  165. if($DisableGrouping) {
  166. foreach($_GET as $SearchType=>$SearchStr) {
  167. switch($SearchType) {
  168. case 'bitrate':
  169. case 'format':
  170. case 'media':
  171. case 'haslog':
  172. case 'hascue':
  173. case 'scene':
  174. case 'remastered':
  175. case 'remastertitle':
  176. case 'freeleech':
  177. if($SearchStr!='') { $TorrentSpecifics+=1; }
  178. }
  179. }
  180. reset($_GET);
  181. } else {
  182. $TorrentSpecifics=1;
  183. }
  184. // And now we start building the mega SQL query
  185. if($_GET['artistname']!='') {
  186. $TorrentJoin .= ' LEFT JOIN torrents_artists AS ta ON g.ID = ta.GroupID LEFT JOIN artists AS a ON ta.ArtistID = a.ID';
  187. $TorrentWhere=build_search($_GET['artistname'],'a.Name',$_GET['exactartist'],$TorrentWhere);
  188. }
  189. if($_GET['torrentname']!='') {
  190. if(!$DisableGrouping) {
  191. $GroupWhere=build_search($_GET['torrentname'],'GroupName',$_GET['exacttorrent'],$GroupWhere);
  192. } else {
  193. $TorrentWhere=build_search($_GET['torrentname'],'g.Name',$_GET['exacttorrent'],$TorrentWhere);
  194. }
  195. }
  196. if($_GET['remastertitle']!='') {
  197. $RemasterTitle = $_GET['remastertitle'];
  198. if($_GET['exactremaster']){
  199. $RemasterTitle = '%'.$RemasterTitle.'%';
  200. }
  201. $GroupWhere=build_search($RemasterTitle,'RemasterTitleList',$_GET['exactremaster'],$GroupWhere,0,$RemasterRegEx);
  202. if($TorrentSpecifics>0) {
  203. $TorrentWhere=build_search($_GET['remastertitle'],'t.RemasterTitle',$_GET['exactremaster'],$TorrentWhere);
  204. }
  205. }
  206. if($_GET['year']!='' && is_numeric($_GET['year'])) {
  207. if(!$DisableGrouping) {
  208. if($GroupWhere=='') { $GroupWhere="WHERE "; } else { $GroupWhere.=" AND "; }
  209. $GroupWhere.="GroupYear='".db_string($_GET['year'])."'";
  210. } else {
  211. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  212. $TorrentWhere.="g.Year='".db_string($_GET['year'])."'";
  213. }
  214. }
  215. if($_GET['bitrate']!='') {
  216. if(in_array($_GET['bitrate'],$Bitrates)) {
  217. if($_GET['bitrate'] == 'Other') {
  218. if($_GET['other_bitrate']!='') {
  219. $GroupWhere=build_search(db_string($_GET['other_bitrate']),'EncodingList',false,$GroupWhere);
  220. if($TorrentSpecifics>0) {
  221. if($TorrentWhere=='') {
  222. $TorrentWhere="WHERE ";
  223. } else {
  224. $TorrentWhere.=" AND ";
  225. }
  226. }
  227. $TorrentWhere.="t.Encoding LIKE '%".db_string($_GET['other_bitrate'])."%'";
  228. }
  229. } else {
  230. $GroupWhere=build_search(db_string($_GET['bitrate']),'EncodingList',false,$GroupWhere);
  231. if($TorrentSpecifics>0) {
  232. if($TorrentWhere=='') {
  233. $TorrentWhere="WHERE ";
  234. } else {
  235. $TorrentWhere.=" AND ";
  236. }
  237. $TorrentWhere.="t.Encoding LIKE '".db_string($_GET['bitrate'])."'";
  238. }
  239. }
  240. }
  241. }
  242. if($_GET['format']!='' && in_array($_GET['format'],$Formats)) {
  243. $GroupWhere=build_search("%".$_GET['format']."%",'FormatList',f,$GroupWhere);
  244. if($TorrentSpecifics>0) {
  245. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  246. $TorrentWhere.="t.Format='".db_string($_GET['format'])."'";
  247. }
  248. }
  249. if($_GET['media']!='' && in_array($_GET['media'],$Media)) {
  250. $GroupWhere=build_search("%".$_GET['media']."%",'MediaList',false,$GroupWhere);
  251. if($TorrentSpecifics>0) {
  252. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  253. $TorrentWhere.="t.Media='".db_string($_GET['media'])."'";
  254. }
  255. }
  256. if($_GET['filelist']!='') {
  257. $TorrentWhere=build_search("%".$_GET['filelist']."%",'t.FileList',true,$TorrentWhere);
  258. }
  259. if($_GET['haslog']!='') {
  260. $HasLog = ceil($_GET['haslog']);
  261. if($_GET['haslog'] == '100' || $_GET['haslog'] == '-100') {
  262. $GroupWhere=build_search($_GET['haslog'],'LogScoreList',false,$GroupWhere);
  263. $HasLog = 1;
  264. }
  265. $GroupWhere=build_search("%".$HasLog."%",'LogList',true,$GroupWhere);
  266. if($TorrentSpecifics>0) {
  267. if($_GET['haslog'] == '100' || $_GET['haslog'] == '-100') {
  268. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  269. if($_GET['haslog'] == '-100') {
  270. $TorrentWhere.="t.LogScore!='100'";
  271. } else {
  272. $TorrentWhere.="t.LogScore='100'";
  273. }
  274. }
  275. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  276. $TorrentWhere.="t.HasLog='".$HasLog."'";
  277. }
  278. }
  279. if($_GET['hascue']!='') {
  280. $GroupWhere=build_search("%".$_GET['hascue']."%",'CueList',true,$GroupWhere);
  281. if($TorrentSpecifics>0) {
  282. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  283. $TorrentWhere.="t.HasCue='".ceil($_GET['hascue'])."'";
  284. }
  285. }
  286. if($_GET['scene']!='') {
  287. $GroupWhere=build_search("%".$_GET['scene']."%",'SceneList',true,$GroupWhere);
  288. if($TorrentSpecifics>0) {
  289. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  290. $TorrentWhere.="t.Scene='".ceil($_GET['scene'])."'";
  291. }
  292. }
  293. if($_GET['freeleech']!='') {
  294. $GroupWhere=build_search("%".$_GET['freeleech']."%",'FreeTorrentList',true,$GroupWhere);
  295. if($TorrentSpecifics>0) {
  296. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  297. $TorrentWhere.="t.FreeTorrent='".ceil($_GET['freeleech'])."'";
  298. }
  299. }
  300. if($_GET['remastered']!='') {
  301. $GroupWhere=build_search("%".$_GET['remastered']."%",'RemasterList',true,$GroupWhere);
  302. if($TorrentSpecifics>0) {
  303. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  304. $TorrentWhere.="t.Remastered='".ceil($_GET['remastered'])."'";
  305. }
  306. }
  307. } else {
  308. // Basic search
  309. if($_GET['searchstr']!='') {
  310. // Change special characters into 'normal' characters
  311. $SearchStr = strtr($_GET['searchstr'],$SpecialChars);
  312. if(!$DisableGrouping) {
  313. $GroupWhere=build_search($SearchStr,'SearchText',false,$GroupWhere,1);
  314. } else {
  315. $TorrentWhere=build_search($SearchStr,'g.SearchText',false,$TorrentWhere);
  316. }
  317. }
  318. }
  319. // Searching tags is the same for basic and advanced search
  320. if(isset($_GET['searchtags']) && $_GET['searchtags']!='') {
  321. if($DisableGrouping) { $TagField="g.TagList"; } else { $TagField="h.TagList"; }
  322. $Tags=explode(',',$_GET['searchtags']);
  323. foreach($Tags as $Key => $Tag) {
  324. if(trim($Tag)!='') {
  325. if($TagSearch!='') {
  326. if($_GET['tags_type']) { $TagSearch.=" AND "; }
  327. else { $TagSearch.=" OR "; }
  328. }
  329. $Tag = trim(str_replace('.','_',$Tag));
  330. if(!$DisableGrouping) {
  331. // Fulltext
  332. $TagSearch.=" MATCH (".$TagField.") AGAINST ('".db_string($Tag)."'";
  333. if(substr($Tag,0,1)=='-') {
  334. $TagSearch.=' IN BOOLEAN MODE';
  335. }
  336. $TagSearch.=")";
  337. } else {
  338. $TagSearch.=$TagField." LIKE '%".db_string($Tag)."%'";
  339. }
  340. }
  341. }
  342. if($TagSearch!='') {
  343. if($DisableGrouping) {
  344. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  345. $TorrentWhere.="(".$TagSearch.")";
  346. } else {
  347. if($GroupWhere=='') { $GroupWhere="WHERE "; } else { $GroupWhere.=" AND "; }
  348. $GroupWhere.="(".$TagSearch.")";
  349. }
  350. }
  351. }
  352. // Filtering categories is also the same for basic and advanced search
  353. if($_GET['filter_cat']!='') {
  354. if($DisableGrouping) { $CategoryField="g.CategoryID"; } else { $CategoryField="GroupCategoryID"; }
  355. foreach($_GET['filter_cat'] as $CatKey => $CatVal) {
  356. if($CatFilter!='') { $CatFilter.=" OR "; }
  357. $CatFilter.=$CategoryField."='".db_string(ceil($CatKey))."'";
  358. }
  359. if($DisableGrouping) {
  360. if($TorrentWhere=='') { $TorrentWhere="WHERE "; } else { $TorrentWhere.=" AND "; }
  361. $TorrentWhere.="(".$CatFilter.")";
  362. } else {
  363. if($GroupWhere=='') { $GroupWhere="WHERE "; } else { $GroupWhere.=" AND "; }
  364. $GroupWhere.="(".$CatFilter.")";
  365. }
  366. }
  367. // Label for the 'time' column - can also be "seeding time", "leeching time", or "snatched time"
  368. if (!$TimeLabel) { $TimeLabel="Added"; }
  369. if(!is_array($TorrentCache)) {
  370. if (!$DisableGrouping) {
  371. // Build SQL query for enabled grouping
  372. if($TorrentWhere!='') {
  373. if($GroupWhere=='') { $GroupWhere="WHERE "; } else { $GroupWhere.=" AND "; }
  374. $GroupWhere.="(SELECT t.GroupID FROM torrents AS t ".$TorrentWhere." AND t.GroupID=h.GroupID LIMIT 1)";
  375. }
  376. $DB->query("SELECT $SCFR
  377. h.GroupID,
  378. h.GroupName,
  379. h.GroupYear AS s2,
  380. h.GroupCategoryID,
  381. h.GroupTime AS s3,
  382. h.MaxTorrentSize AS s4,
  383. h.TotalSnatches AS s5,
  384. h.TotalSeeders AS s6,
  385. h.TotalLeechers AS s7,
  386. h.TorrentIDList,
  387. h.TagList,
  388. h.MediaList,
  389. h.FormatList,
  390. h.EncodingList,
  391. h.YearList,
  392. h.RemasterList,
  393. h.RemasterTitleList,
  394. h.SceneList,
  395. h.LogList,
  396. h.CueList,
  397. h.LogScoreList,
  398. h.FileCountList,
  399. h.FreeTorrentList,
  400. h.SizeList,
  401. h.LeechersList,
  402. h.SeedersList,
  403. h.SnatchedList,
  404. h.TimeList,
  405. h.SearchText AS s1
  406. FROM torrent_hash AS h
  407. $TorrentJoin
  408. $GroupWhere
  409. ORDER BY $OrderBy $OrderWay
  410. LIMIT $Limit");
  411. $TorrentList=$DB->to_array();
  412. if(EXPLAIN_HACK){
  413. $DB->query("EXPLAIN SELECT NULL FROM (SELECT NULL FROM torrent_hash AS h ".$TorrentJoin." ".$GroupWhere.") AS Count");
  414. list($Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$TorrentCount)=$DB->next_record();
  415. } else {
  416. $DB->query("SELECT FOUND_ROWS()");
  417. list($TorrentCount) = $DB->next_record();
  418. }
  419. } else {
  420. // Build SQL for disabled grouping
  421. if (!$TimeField) { $TimeField="t.Time"; }
  422. $DB->query("SELECT $SCFR
  423. g.ID,
  424. g.Name,
  425. g.Year AS s2,
  426. g.CategoryID,
  427. ".$TimeField." AS s3,
  428. t.Size AS s4,
  429. t.Snatched AS s5,
  430. t.Seeders AS s6,
  431. t.Leechers AS s7,
  432. t.ID,
  433. g.TagList,
  434. t.Media,
  435. t.Format,
  436. t.Encoding,
  437. t.RemasterYear,
  438. t.Remastered,
  439. t.RemasterTitle,
  440. t.Scene,
  441. t.HasLog,
  442. t.HasCue,
  443. t.LogScore,
  444. t.FileCount,
  445. t.FreeTorrent,
  446. g.SearchText AS s1
  447. FROM torrents AS t
  448. INNER JOIN torrents_group AS g ON g.ID=t.GroupID
  449. $TorrentJoin
  450. $TorrentWhere
  451. ORDER BY $OrderBy $OrderWay
  452. LIMIT $Limit");
  453. $TorrentList=$DB->to_array();
  454. if(EXPLAIN_HACK){
  455. $DB->query("EXPLAIN SELECT NULL FROM (SELECT NULL FROM torrent_hash AS h ".$TorrentJoin." ".$GroupWhere.") AS Count");
  456. list($Null,$Null,$Null,$Null,$Null,$Null,$Null,$Null,$TorrentCount)=$DB->next_record();
  457. } else {
  458. $DB->query("SELECT FOUND_ROWS()");
  459. list($TorrentCount) = $DB->next_record();
  460. }
  461. }
  462. if($UserID) {
  463. // Get the username, so we can display the title as "<user>'s snatched torrents", etc
  464. $DB->query("SELECT Username FROM users_main WHERE ID='".db_string($UserID)."'");
  465. list($TitleUser)=$DB->next_record();
  466. }
  467. } else {
  468. // We got the results from cache
  469. $TorrentCount=$TorrentCache[0];
  470. $TorrentList=$TorrentCache[1];
  471. if($UserID) { $TitleUser=$TorrentCache[2]; }
  472. }
  473. // List of pages
  474. $Pages=get_pages($Page,$TorrentCount,TORRENTS_PER_PAGE);
  475. // Gets tacked onto torrent download URLs
  476. $DownloadString="&amp;authkey=".$LoggedUser['AuthKey']."&amp;torrent_pass=".$LoggedUser['torrent_pass'];
  477. if($Title) { $Title=$TitleUser."'s ".$Title; } else { $Title="Browse Torrents"; }
  478. show_header($Title,'browse');
  479. ?>
  480. <form name="filter" method="get" action=''>
  481. <? if($UserID) { ?>
  482. <input type="hidden" name="type" value="<?=display_str($_GET['type'])?>" />
  483. <input type="hidden" name="userid" value="<?=display_str($_GET['userid'])?>" />
  484. <? } ?>
  485. <div class="filter_torrents">
  486. <h3>
  487. Filter
  488. <? if(strtolower($_GET['action'])!="advanced" && (!$LoggedUser['SearchType'] || strtolower($_GET['action'])=="basic") && check_perms('site_advanced_search')) { ?>
  489. (<a href="torrents.php?action=advanced&amp;<?=get_url(array('action'))?>">Advanced Search</a>)
  490. <? } elseif((strtolower($_GET['action'])=="advanced" || ($LoggedUser['SearchType'] && strtolower($_GET['action'])!="basic")) && check_perms('site_advanced_search')) { ?>
  491. (<a href="torrents.php?<? if($LoggedUser['SearchType']) { ?>action=basic&amp;<? } echo get_url(array('action')); ?>">Basic Search</a>)
  492. <? } ?>
  493. </h3>
  494. <div class="box pad">
  495. <table>
  496. <? $AdvancedSearch = false;
  497. if((strtolower($_GET['action'])=="advanced" || ($LoggedUser['SearchType'] && strtolower($_GET['action'])!="basic")) && check_perms('site_advanced_search')) {
  498. $AdvancedSearch = true;
  499. ?>
  500. <tr>
  501. <td class="label">Artist Name:</td>
  502. <td colspan="3">
  503. <input type="text" size="40" name="artistname" class="inputtext smaller" value="<?=display_str($_GET['artistname'])?>" />&nbsp;
  504. <input type="checkbox" name="exactartist" id="exactartist" value="1" <? if($_GET['exactartist']) { ?>checked="checked"<? } ?> /> <label for="exactartist">Exact Phrase</label>
  505. <input type="hidden" name="action" value="advanced" />
  506. </td>
  507. </tr>
  508. <tr>
  509. <td class="label">Album/Torrent Name:</td>
  510. <td colspan="3">
  511. <input type="text" size="40" name="torrentname" class="inputtext smaller" value="<?=display_str($_GET['torrentname'])?>" />&nbsp;
  512. <input type="checkbox" name="exacttorrent" id="exacttorrent" value="1" <? if($_GET['exacttorrent']) { ?>checked="checked"<? } ?> /> <label for="exacttorrent">Exact Phrase</label>
  513. </td>
  514. </tr>
  515. <tr>
  516. <td class="label">Edition Information:</td>
  517. <td colspan="3">
  518. <input type="text" size="40" name="remastertitle" class="inputtext smaller" value="<?=display_str($_GET['remastertitle'])?>" />&nbsp;
  519. <input type="checkbox" name="exactremaster" id="exactremaster" value="1" <? if($_GET['exactremaster']) { ?>checked="checked"<? } ?> /> <label for="exactremaster">Exact Phrase</label>
  520. </td>
  521. </tr>
  522. <tr>
  523. <td class="label">File List:</td>
  524. <td colspan="3"><input type="text" size="40" name="filelist" class="inputtext" value="<?=display_str($_GET['filelist']); ?>" /></td>
  525. </tr>
  526. <tr>
  527. <td class="label">Rip Specifics:</td>
  528. <td class="nobr">
  529. <select id=bitrate name="bitrate" style="width:auto;" onchange="Bitrate()">
  530. <option value="">Bitrate</option>
  531. <? if($_GET['bitrate'] && $_GET['bitrate'] == 'Other'){
  532. $OtherBitrate = true;
  533. } else {
  534. $OtherBitrate = false;
  535. }
  536. foreach($Bitrates as $BitrateName) { ?>
  537. <option value="<?=display_str($BitrateName); ?>" <? if($BitrateName==$_GET['bitrate']) { ?>selected="selected"<? } ?>><?=display_str($BitrateName); ?></option>
  538. <? } ?> </select>
  539. <span id="other_bitrate_span"<? if(!$OtherBitrate){ echo " style='display: none;'"; } ?> >
  540. <input type="text" name="other_bitrate" size="5" id="other_bitrate"<? if($OtherBitrate){ echo " value='".display_str($_GET['other_bitrate'])."'";} ?> />
  541. </span>
  542. <select name="format" style="width:auto;">
  543. <option value="">Format</option>
  544. <? foreach($Formats as $FormatName) { ?>
  545. <option value="<?=display_str($FormatName); ?>" <? if($FormatName==$_GET['format']) { ?>selected="selected"<? } ?>><?=display_str($FormatName); ?></option>
  546. <? } ?> </select>
  547. <select name="media" style="width:auto;">
  548. <option value="">Media</option>
  549. <? foreach($Media as $MediaName) { ?>
  550. <option value="<?=display_str($MediaName); ?>" <? if($MediaName==$_GET['media']) { ?>selected="selected"<? } ?>><?=display_str($MediaName); ?></option>
  551. <? } ?>
  552. </select>
  553. </td>
  554. <td class="label">Year:</td>
  555. <td><input type="text" name="year" class="inputtext smallest" value="<?=display_str($_GET['year']); ?>" size="4" /></td>
  556. </tr>
  557. <tr>
  558. <td class="label">Misc:</td>
  559. <td class="nobr" colspan="3">
  560. <select name="haslog" style="width:auto;">
  561. <option value="">Has Log</option>
  562. <option value="1" <? if($_GET['haslog']=="1") { ?>selected="selected"<? } ?>>Yes</option>
  563. <option value="0" <? if($_GET['haslog']=="0") { ?>selected="selected"<? } ?>>No</option>
  564. <option value="100" <? if($_GET['haslog']=="100") { ?>selected="selected"<? } ?>>100% only</option>
  565. <option value="-100" <? if($_GET['haslog']=="-100") { ?>selected="selected"<? } ?>>&lt;100%/Unscored</option>
  566. </select>
  567. <select name="hascue" style="width:auto;">
  568. <option value="">Has Cue</option>
  569. <option value="1" <? if($_GET['hascue']=="1") { ?>selected="selected"<? } ?>>Yes</option>
  570. <option value="0" <? if($_GET['hascue']=="0") { ?>selected="selected"<? } ?>>No</option>
  571. </select>
  572. <select name="scene" style="width:auto;">
  573. <option value="">Scene</option>
  574. <option value="1" <? if($_GET['scene']=="1") { ?>selected="selected"<? } ?>>Yes</option>
  575. <option value="0" <? if($_GET['scene']=="0") { ?>selected="selected"<? } ?>>No</option>
  576. </select>
  577. <select name="freeleech" style="width:auto;">
  578. <option value="">Freeleech</option>
  579. <option value="1" <? if($_GET['freeleech']=="1") { ?>selected="selected"<? } ?>>Yes</option>
  580. <option value="0" <? if($_GET['freeleech']=="0") { ?>selected="selected"<? } ?>>No</option>
  581. </select>
  582. <select name="remastered" style="width:auto;">
  583. <option value=''>Remastered</option>
  584. <option value="1" <? if($_GET['remastered']=="1") { ?>selected="selected"<? } ?>>Yes</option>
  585. <option value="0" <? if($_GET['remastered']=="0") { ?>selected="selected"<? } ?>>No</option>
  586. </select>
  587. </td>
  588. </tr>
  589. <? } else { ?>
  590. <tr>
  591. <td class="label">Search terms:</td>
  592. <td colspan="3">
  593. <input type="text" size="40" name="searchstr" class="inputtext" value="<?=display_str($_GET['searchstr'])?>" />
  594. <? if($LoggedUser['SearchType']) { ?>
  595. <input type="hidden" name="action" value="basic" />
  596. <? } ?>
  597. </td>
  598. </tr>
  599. <? } ?>
  600. <tr>
  601. <td class="label">Tags (comma-separated):</td>
  602. <td colspan="3">
  603. <input type="text" size="40" id="tags" name="searchtags" class="inputtext smaller" title="Use -tag to exclude tag" value="<?=display_str($_GET['searchtags'])?>" />&nbsp;
  604. <input type="radio" name="tags_type" id="tags_type0" value="0" <? if($_GET['tags_type']==0) { ?>checked="checked"<? } ?> /> <label for="tags_type0">Any</label>&nbsp;&nbsp;
  605. <input type="radio" name="tags_type" id="tags_type1" value="1" <? if($_GET['tags_type']==1) { ?>checked="checked"<? } ?> /> <label for="tags_type1">All</label>
  606. </td>
  607. </tr>
  608. <tr>
  609. <td class="label">Order by:</td>
  610. <td colspan="<?=($AdvancedSearch)?'3':'1'?>">
  611. <select name="order_by" style="width:auto;">
  612. <option value="s1" <? if($OrderBy=="s1") { ?>selected="selected"<? } ?>>Name</option>
  613. <option value="s2" <? if($OrderBy=="s2") { ?>selected="selected"<? } ?>>Year</option>
  614. <option value="s3" <? if($OrderBy=="s3") { ?>selected="selected"<? } ?>><?=$TimeLabel?></option>
  615. <option value="s4" <? if($OrderBy=="s4") { ?>selected="selected"<? } ?>>Size</option>
  616. <option value="s5" <? if($OrderBy=="s5") { ?>selected="selected"<? } ?>>Snatched</option>
  617. <option value="s6" <? if($OrderBy=="s6") { ?>selected="selected"<? } ?>>Seeders</option>
  618. <option value="s7" <? if($OrderBy=="s7") { ?>selected="selected"<? } ?>>Leechers</option>
  619. </select>
  620. <select name="order_way">
  621. <option value="desc" <? if($OrderWay=="DESC") { ?>selected="selected"<? } ?>>Descending</option>
  622. <option value="asc" <? if($OrderWay=="ASC") { ?>selected="selected"<? } ?>>Ascending</option>
  623. </select>&nbsp;&nbsp;&nbsp;&nbsp;
  624. <?/*
  625. <? if ($LoggedUser['DisableGrouping']) { ?>
  626. <input type="checkbox" name="enablegrouping" id="enablegrouping" value="1" <? if(!$DisableGrouping) { ?>checked="checked"<? } ?> /> <label for="enablegrouping"><strong>Enable grouping</strong></label>
  627. <? } else { ?>
  628. <input type="checkbox" name="disablegrouping" id="disablegrouping" value="1" <? if($DisableGrouping) { ?>checked="checked"<? } ?> /> <label for="disablegrouping"><strong>Disable grouping</strong></label>
  629. <? } ?>
  630. */?>
  631. </td>
  632. </tr>
  633. </table>
  634. <table class="cat_list">
  635. <?
  636. $x=1;
  637. reset($Categories);
  638. foreach($Categories as $CatKey => $CatName) {
  639. if($x%8==0 || $x==1) {
  640. ?>
  641. <tr>
  642. <? } ?>
  643. <td>
  644. <input type="checkbox" name="filter_cat[<?=($CatKey+1)?>]" id="cat_<?=($CatKey+1)?>" value="1" <? if(isset($_GET['filter_cat'][$CatKey+1])) { ?>checked="checked"<? } ?> />
  645. <label for="cat_<?=($CatKey+1)?>"><?=$CatName?></label>
  646. </td>
  647. <?
  648. if($x%7==0) {
  649. ?>
  650. </tr>
  651. <?
  652. }
  653. $x++;
  654. }
  655. ?>
  656. </table>
  657. <table class="cat_list <? if(!$LoggedUser['ShowTags']) { ?>hidden<? } ?>" id="taglist">
  658. <tr>
  659. <?
  660. $GenreTags = $Cache->get_value('genre_tags');
  661. if(!$GenreTags) {
  662. $DB->query('SELECT Name FROM tags WHERE TagType=\'genre\' ORDER BY Name');
  663. $GenreTags = $DB->collect('Name');
  664. $Cache->cache_value('genre_tags', $GenreTags, 3600*6);
  665. }
  666. $x = 0;
  667. foreach($GenreTags as $Tag) {
  668. ?>
  669. <td width="12.5%"><a href="#" onclick="add_tag('<?=$Tag?>');return false;"><?=$Tag?></a></td>
  670. <?
  671. $x++;
  672. if($x%7==0) {
  673. ?>
  674. </tr>
  675. <tr>
  676. <?
  677. }
  678. }
  679. if($x%7!=0) { // Padding
  680. ?>
  681. <td colspan="<?=7-($x%7)?>"> </td>
  682. <? } ?>
  683. </tr>
  684. </table>
  685. <table class="cat_list" width="100%">
  686. <tr>
  687. <td class="label"><a href="#" onclick="$('#taglist').toggle();return false;">(View Tags)</a></td>
  688. </tr>
  689. </table>
  690. <div class="submit">
  691. <span style="float:left;"><?=number_format($TorrentCount)?> Results</span>
  692. <input type="submit" value="Filter Torrents" />
  693. <input type="button" value="Reset" onclick="location.href='torrents.php<? if(isset($_GET['action']) && $_GET['action']=="advanced") { ?>?action=advanced<? } ?>'" />
  694. &nbsp;&nbsp;
  695. <? if (isset($TorrentWhere) || isset($GroupWhere) || $OrderBy!="s3" || $OrderWay!="DESC") { ?>
  696. <input type="submit" name="setdefault" value="Make Default" />
  697. <?
  698. }
  699. if ($LoggedUser['DefaultSearch']) {
  700. ?>
  701. <input type="submit" name="cleardefault" value="Clear Default" />
  702. <? } ?>
  703. </div>
  704. </div>
  705. </div>
  706. </form>
  707. <div class="linkbox"><?=$Pages?></div>
  708. <? if (count($TorrentList)>0) { ?>
  709. <table class="torrent_table <?=(($DisableGrouping)?'no_grouping':'grouping')?>" id="torrent_table">
  710. <tr class="colhead">
  711. <? if(!$DisableGrouping) { ?>
  712. <td class="small"></td>
  713. <? } ?>
  714. <td class="small cats_col"></td>
  715. <td width="100%"><a href="<?=header_link('s1','ASC')?>">Name</a> / <a href="<?=header_link('s2')?>">Year</a></td>
  716. <td>Files</td>
  717. <td><a href="<?=header_link('s3')?>"><?=$TimeLabel?></a></td>
  718. <td><a href="<?=header_link('s4')?>">Size</a></td>
  719. <td class="sign"><a href="<?=header_link('s5')?>"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/snatched.png" alt="Snatches" title="Snatches" /></a></td>
  720. <td class="sign"><a href="<?=header_link('s6')?>"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/seeders.png" alt="Seeders" title="Seeders" /></a></td>
  721. <td class="sign"><a href="<?=header_link('s7')?>"><img src="static/styles/<?=$LoggedUser['StyleName']?>/images/leechers.png" alt="Leechers" title="Leechers" /></a></td>
  722. </tr>
  723. <?
  724. if($LoggedUser['TorrentGrouping']==0) {
  725. $HideGroup='';
  726. $ActionTitle="Collapse";
  727. $ActionURL="hide";
  728. } elseif($LoggedUser['TorrentGrouping']==1) {
  729. $HideGroup="hide";
  730. $ActionTitle="Expand";
  731. $ActionURL="show";
  732. }
  733. // Start printing torrent list
  734. $GroupIDs = array();
  735. foreach($TorrentList as $Key => $Properties) {
  736. $GroupIDs[] = $Properties[0];
  737. }
  738. $Artists = get_artists($GroupIDs);
  739. foreach ($TorrentList as $Key => $Properties) {
  740. list($GroupID,$GroupName,$GroupYear,$GroupCategoryID,$GroupTime,$MaxSize,$TotalSnatched,$TotalSeeders,$TotalLeechers,$TorrentsID,$TorrentTags,$TorrentsMedia,$TorrentsFormat,$TorrentsEncoding,$TorrentsYear,$TorrentsRemastered,$TorrentsRemasterTitle,$TorrentsScene,$TorrentsLog,$TorrentsCue,$TorrentsLogScores,$TorrentsFileCount,$TorrentsFreeTorrent,$TorrentsSize,$TorrentsLeechers,$TorrentsSeeders,$TorrentsSnatched,$TorrentsTime) = $Properties;
  741. $Torrents['id'] =explode('|',$TorrentsID);
  742. $Torrents['media'] =explode('|',$TorrentsMedia);
  743. $Torrents['format'] =explode('|',$TorrentsFormat);
  744. $Torrents['encoding'] =explode('|',$TorrentsEncoding);
  745. $Torrents['year'] =explode('|',$TorrentsYear);
  746. $Torrents['remastered'] =explode('|',$TorrentsRemastered);
  747. $Torrents['remastertitle']=explode('|',$TorrentsRemasterTitle);
  748. $Torrents['scene'] =explode('|',$TorrentsScene);
  749. $Torrents['log'] =explode('|',$TorrentsLog);
  750. $Torrents['cue'] =explode('|',$TorrentsCue);
  751. $Torrents['score'] =explode('|',$TorrentsLogScores);
  752. $Torrents['filecount'] =explode('|',$TorrentsFileCount);
  753. $Torrents['size'] =explode('|',$TorrentsSize);
  754. $Torrents['leechers'] =explode('|',$TorrentsLeechers);
  755. $Torrents['seeders'] =explode('|',$TorrentsSeeders);
  756. $Torrents['snatched'] =explode('|',$TorrentsSnatched);
  757. $Torrents['freetorrent']=explode('|',$TorrentsFreeTorrent);
  758. $Torrents['time'] =explode('|',$TorrentsTime);
  759. if (!$DisableGrouping) {
  760. // Since these fields are surrounded by |s, we get extra elements added to the arrays
  761. array_pop($Torrents['media']);
  762. array_pop($Torrents['format']);
  763. array_pop($Torrents['encoding']);
  764. array_pop($Torrents['remastertitle']);
  765. array_pop($Torrents['log']);
  766. array_pop($Torrents['cue']);
  767. array_pop($Torrents['score']);
  768. array_pop($Torrents['freetorrent']);
  769. array_shift($Torrents['media']);
  770. array_shift($Torrents['format']);
  771. array_shift($Torrents['encoding']);
  772. array_shift($Torrents['remastertitle']);
  773. array_shift($Torrents['log']);
  774. array_shift($Torrents['cue']);
  775. array_shift($Torrents['score']);
  776. array_shift($Torrents['freetorrent']);
  777. } else {
  778. $Torrents['size'][0]=$MaxSize;
  779. $Torrents['leechers'][0]=$TotalLeechers;
  780. $Torrents['seeders'][0]=$TotalSeeders;
  781. $Torrents['snatched'][0]=$TotalSnatched;
  782. }
  783. $TagList=array();
  784. if($TorrentTags!='') {
  785. $TorrentTags=explode(' ',$TorrentTags);
  786. foreach ($TorrentTags as $TagKey => $TagName) {
  787. $TagName = str_replace('_','.',$TagName);
  788. $TagList[]='<a href="torrents.php?searchtags='.$TagName.'">'.$TagName.'</a>';
  789. }
  790. $PrimaryTag = $TorrentTags[0];
  791. $TagList = implode(', ', $TagList);
  792. $TorrentTags='<br /><div class="tags">'.$TagList.'</div>';
  793. }
  794. if ($GroupName=='') { $GroupName="- None -"; }
  795. $DisplayName = display_artists($Artists[$GroupID]);
  796. if((count($Torrents['id'])>1 || $GroupCategoryID==1) && !$DisableGrouping) {
  797. // These torrents are in a group
  798. $DisplayName.='<a href="torrents.php?id='.$GroupID.'" title="View Torrent">'.$GroupName.'</a>';
  799. if($GroupYear>0) { $DisplayName.=" [".$GroupYear."]"; }
  800. ?>
  801. <tr class="group">
  802. <td class="center"><div title="<?=$ActionTitle?>" id="showimg_<?=$GroupID?>" class="<?=$ActionURL?>_torrents"><a href="#" class="show_torrents_link" onclick="$('.groupid_<?=$GroupID?>').toggle(); return false;"></a></div></td>
  803. <td class="center cats_col"><div title="<?=ucfirst(str_replace('_',' ',$PrimaryTag))?>" class="cats_<?=strtolower(str_replace(array('-',' '),array('',''),$Categories[$GroupCategoryID-1]))?> tags_<?=str_replace('.','_',$PrimaryTag)?>"></div></td>
  804. <td colspan="2">
  805. <?=$DisplayName?>
  806. <span style="float:right;"><a href="#showimg_<?=$GroupID?>" onclick="Bookmark(<?=$GroupID?>);this.innerHTML='Bookmarked';return false;">Bookmark</a></span>
  807. <?=$TorrentTags?>
  808. </td>
  809. <td class="nobr"><?=time_diff($GroupTime,1)?></td>
  810. <td class="nobr"><?=get_size($MaxSize)?> (Max)</td>
  811. <td><?=number_format($TotalSnatched)?></td>
  812. <td<?=($TotalSeeders==0)?' class="r00"':''?>><?=number_format($TotalSeeders)?></td>
  813. <td><?=number_format($TotalLeechers)?></td>
  814. </tr>
  815. <?
  816. $Row = 'a';
  817. foreach($Torrents['id'] as $Key => $Val) {
  818. // All of the individual torrents in the group
  819. // If they're using the advanced search and have chosen enabled grouping, we just skip the torrents that don't check out
  820. if(!empty($_GET['bitrate']) && $Torrents['encoding'][$Key]!=$_GET['bitrate']) { continue; }
  821. if(!empty($_GET['format']) && $Torrents['format'][$Key]!=$_GET['format']) { continue; }
  822. if(!empty($_GET['media']) && $Torrents['media'][$Key]!=$_GET['media']) { continue; }
  823. if(!empty($_GET['haslog'])) {
  824. if($_GET['haslog'] == '100' && $Torrents['score'][$Key]!=100) {
  825. continue;
  826. }
  827. if($_GET['haslog'] == '-100' && $Torrents['score'][$Key]==100 || !$Torrents['log'][$Key]) {
  828. continue;
  829. }
  830. if(($_GET['haslog'] == '1' || $_GET['haslog'] == '0') && $Torrents['log'][$Key]!=$_GET['haslog']) {
  831. continue;
  832. }
  833. }
  834. if(!empty($_GET['hascue']) && $Torrents['cue'][$Key]!=$_GET['hascue']) { continue; }
  835. if(!empty($_GET['scene']) && $Torrents['scene'][$Key]!=$_GET['scene']) { continue; }
  836. if(!empty($_GET['freeleech']) && $Torrents['freetorrent'][$Key]!=$_GET['freeleech']) { continue; }
  837. if(!empty($_GET['remastered']) && $Torrents['remastered'][$Key]!=$_GET['remastered']) { continue; }
  838. if(!empty($_GET['exactremaster']) && !empty($_GET['remastertitle'])) {
  839. if(strtolower(trim($Torrents['remastertitle'][$Key])) != strtolower(trim($_GET['remastertitle']))) {
  840. continue;
  841. }
  842. } elseif(!empty($_GET['remastertitle'])) {
  843. $Continue = false;
  844. $RemasterParts = explode(' ', $_GET['remastertitle']);
  845. foreach($RemasterParts as $RemasterPart) {
  846. if(stripos($Torrents['remastertitle'][$Key],$RemasterPart) === false) {
  847. $Continue = true;
  848. }
  849. }
  850. if($Continue) {
  851. continue;
  852. }
  853. }
  854. $ExtraInfo='';
  855. $AddExtra='';
  856. if($Torrents['format'][$Key]) { $ExtraInfo.=$Torrents['format'][$Key]; $AddExtra=" / "; }
  857. if($Torrents['encoding'][$Key]) { $ExtraInfo.=$AddExtra.$Torrents['encoding'][$Key]; $AddExtra=" / "; }
  858. if($Torrents['log'][$Key]=="1") {
  859. $ExtraInfo.=$AddExtra."Log"; $AddExtra=" / ";
  860. if($Torrents['score'][$Key]) { $ExtraInfo.=' ('.$Torrents['score'][$Key].'%) '; }
  861. }
  862. if($Torrents['cue'][$Key]=="1") { $ExtraInfo.=$AddExtra."Cue"; $AddExtra=" / "; }
  863. if($Torrents['media'][$Key]) { $ExtraInfo.=$AddExtra.$Torrents['media'][$Key]; $AddExtra=" / "; }
  864. if($Torrents['scene'][$Key]=="1") { $ExtraInfo.=$AddExtra."Scene"; $AddExtra=" / "; }
  865. if(trim($Torrents['remastertitle'][$Key])) { $ExtraInfo.=$AddExtra.$Torrents['remastertitle'][$Key]; $AddExtra=" - "; }
  866. elseif($Torrents['remastered'][$Key]=="1") { $ExtraInfo.=$AddExtra."Remastered"; $AddExtra=" - "; }
  867. if($Torrents['year'][$Key]>"0") { $ExtraInfo.=$AddExtra.$Torrents['year'][$Key]; $AddExtra=" / "; }
  868. if($Torrents['freetorrent'][$Key]=="1") { $ExtraInfo.=$AddExtra."<strong>Freeleech!</strong>"; $AddExtra=" / "; }
  869. ?>
  870. <tr class="group_torrent groupid_<?=$GroupID?> <?=$HideGroup?>">
  871. <td colspan="3">
  872. <span>
  873. [<a href="torrents.php?action=download&amp;id=<?=$Torrents['id'][$Key]?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>" title="Download">DL</a>
  874. | <a href="reportsv2.php?action=report&amp;id=<?=$Torrents['id'][$Key]?>" title="Report">RP</a>]
  875. </span>
  876. &raquo; <a href="torrents.php?id=<?=$GroupID?>&amp;torrentid=<?=$Val?>"><?=$ExtraInfo?></a>
  877. </td>
  878. <td><?=$Torrents['filecount'][$Key]?></td>
  879. <td class="nobr"><?=time_diff($Torrents['time'][$Key],1)?></td>
  880. <td class="nobr"><?=get_size($Torrents['size'][$Key])?></td>
  881. <td><?=number_format($Torrents['snatched'][$Key])?></td>
  882. <td<?=($Torrents['seeders'][$Key]==0)?' class="r00"':''?>><?=number_format($Torrents['seeders'][$Key])?></td>
  883. <td><?=number_format($Torrents['leechers'][$Key])?></td>
  884. </tr>
  885. <?
  886. }
  887. } else {
  888. // Either grouping is disabled, or we're viewing a type that does not require grouping
  889. if ($GroupCategoryID==1) {
  890. $DisplayName.='<a href="torrents.php?id='.$GroupID.'&amp;torrentid='.$Torrents['id'][0].'" title="View Torrent">'.$GroupName.'</a>';
  891. } else {
  892. $DisplayName.='<a href="torrents.php?id='.$GroupID.'" title="View Torrent">'.$GroupName.'</a>';
  893. }
  894. $ExtraInfo='';
  895. $AddExtra='';
  896. if($Torrents['format'][0]) { $ExtraInfo.=$Torrents['format'][0]; $AddExtra=" / "; }
  897. if($Torrents['encoding'][0]) { $ExtraInfo.=$AddExtra.$Torrents['encoding'][0]; $AddExtra=" / "; }
  898. if($Torrents['log'][0]=="1") { $ExtraInfo.=$AddExtra."Log"; $AddExtra=" / "; }
  899. if($Torrents['score'][0]) { $ExtraInfo.=' ('.$Torrents['score'][0].'%) '; }
  900. if($Torrents['cue'][0]=="1") { $ExtraInfo.=$AddExtra."Cue"; $AddExtra=" / "; }
  901. if($Torrents['media'][0]) { $ExtraInfo.=$AddExtra.$Torrents['media'][0]; $AddExtra=" / "; }
  902. if($Torrents['scene'][0]=="1") { $ExtraInfo.=$AddExtra."Scene"; $AddExtra=" / "; }
  903. if(trim($Torrents['remastertitle'][0])) { $ExtraInfo.=$AddExtra.$Torrents['remastertitle'][0]; $AddExtra=" - "; }
  904. elseif($Torrents['remastered'][0]=="1") { $ExtraInfo.=$AddExtra."Remastered"; $AddExtra=" - "; }
  905. if($Torrents['year'][0]>"0") { $ExtraInfo.=$AddExtra.$Torrents['year'][0]; $AddExtra=" / "; }
  906. if($Torrents['freetorrent'][0]=="1") { $ExtraInfo.=$AddExtra."<strong>Freeleech!</strong>"; $AddExtra=" / "; }
  907. if($ExtraInfo!='') { $ExtraInfo="[".$ExtraInfo."]"; }
  908. if($GroupYear>0) { $ExtraInfo.=" [".$GroupYear."]"; }
  909. if (!isset($TimeField) || $TimeField=="t.Time") { $GroupTime=strtotime($GroupTime); }
  910. ?>
  911. <tr class="torrent">
  912. <? if(!$DisableGrouping) { ?>
  913. <td></td>
  914. <? } ?>
  915. <td class="center cats_col"><div title="<?=ucfirst(str_replace('.',' ',$PrimaryTag))?>" class="cats_<?=strtolower(str_replace(array('-',' '),array('',''),$Categories[$GroupCategoryID-1]))?> tags_<?=str_replace('.','_',$PrimaryTag)?>"></div></td>
  916. <td>
  917. <span>[<a href="torrents.php?action=download&amp;id=<?=$Torrents['id'][0].$DownloadString?>&amp;authkey=<?=$LoggedUser['AuthKey']?>&amp;torrent_pass=<?=$LoggedUser['torrent_pass']?>" title="Download">DL</a> | <a href="reportsv2.php?action=report&amp;id=<?=$Torrents['id'][0]?>" title="Report">RP</a>]</span>
  918. <?=$DisplayName?>
  919. <?=$ExtraInfo?>
  920. <?=$TorrentTags?>
  921. </td>
  922. <td><?=$Torrents['filecount'][0]?></td>
  923. <td class="nobr"><?=time_diff($GroupTime,1)?></td>
  924. <td class="nobr"><?=get_size($Torrents['size'][0])?></td>
  925. <td><?=number_format($TotalSnatched)?></td>
  926. <td<?=($TotalSeeders==0)?' class="r00"':''?>><?=number_format($TotalSeeders)?></td>
  927. <td><?=number_format($TotalLeechers)?></td>
  928. </tr>
  929. <?
  930. }
  931. }
  932. ?>
  933. </table>
  934. <? } else {
  935. $DB->query("SELECT
  936. tags.Name,
  937. ((COUNT(tags.Name)-2)*(SUM(tt.PositiveVotes)-SUM(tt.NegativeVotes)))/(tags.Uses*0.8) AS Score
  938. FROM xbt_snatched AS s
  939. INNER JOIN torrents AS t ON t.ID=s.fid
  940. INNER JOIN torrents_group AS g ON t.GroupID=g.ID
  941. INNER JOIN torrents_tags AS tt ON tt.GroupID=g.ID
  942. INNER JOIN tags ON tags.ID=tt.TagID
  943. WHERE s.uid='$LoggedUser[ID]'
  944. AND tt.TagID<>'13679'
  945. AND tt.TagID<>'4820'
  946. AND tt.TagID<>'2838'
  947. AND g.CategoryID='1'
  948. AND tags.Uses > '10'
  949. GROUP BY tt.TagID
  950. ORDER BY Score DESC
  951. LIMIT 8");
  952. ?>
  953. <div class="box pad" align="center">
  954. <h2>Your search did not match anything.</h2>
  955. <p>Make sure all names are spelled correctly, or try making your search less specific.</p>
  956. <p>You might like (Beta): <? while(list($Tag)=$DB->next_record()) { ?><a href="torrents.php?searchtags=<?=$Tag?>"><?=$Tag?></a> <? } ?></p>
  957. </div>
  958. <? } ?>
  959. <div class="linkbox"><?=$Pages?></div>
  960. <? show_footer(array('disclaimer'=>false)); ?>