/************************************************************************ *-------------------- Browse page --------------------------------------- * Welcome to one of the most complicated pages in all of gazelle - the * browse page. * * This is the page that is displayed when someone visits torrents.php * * It offers normal and advanced search, as well as enabled/disabled * grouping. * * For an outdated non-Sphinx version, use /sections/torrents/browse.php. * * Don't blink. * Blink and you're dead. * Don't turn your back. * Don't look away. * And don't blink. * Good Luck. * *************************************************************************/ include(SERVER_ROOT.'/sections/bookmarks/functions.php'); include(SERVER_ROOT.'/sections/torrents/functions.php'); // The "order by x" links on columns headers function header_link($SortKey,$DefaultWay="desc") { global $OrderBy,$OrderWay; if($SortKey==$OrderBy) { if($OrderWay=="desc") { $NewWay="asc"; } else { $NewWay="desc"; } } else { $NewWay=$DefaultWay; } return "torrents.php?order_way=".$NewWay."&order_by=".$SortKey."&".get_url(array('order_way','order_by')); } $TokenTorrents = $Cache->get_value('users_tokens_'.$UserID); if (empty($TokenTorrents)) { $DB->query("SELECT TorrentID FROM users_freeleeches WHERE UserID=$UserID AND Expired=FALSE"); $TokenTorrents = $DB->collect('TorrentID'); $Cache->cache_value('users_tokens_'.$UserID, $TokenTorrents); } // Search by infohash if(!empty($_GET['searchstr']) || !empty($_GET['groupname'])) { if(!empty($_GET['searchstr'])) { $InfoHash = $_GET['searchstr']; } else { $InfoHash = $_GET['groupname']; } if($InfoHash = is_valid_torrenthash($InfoHash)) { $InfoHash = db_string(pack("H*", $InfoHash)); $DB->query("SELECT ID,GroupID FROM torrents WHERE info_hash='$InfoHash'"); if($DB->record_count() > 0) { list($ID, $GroupID) = $DB->next_record(); header('Location: torrents.php?id='.$GroupID.'&torrentid='.$ID); die(); } } } // Setting default search options if(!empty($_GET['setdefault'])) { $UnsetList = array('page','setdefault'); $UnsetRegexp = '/(&|^)('.implode('|',$UnsetList).')=.*?(&|$)/i'; $DB->query("SELECT SiteOptions FROM users_info WHERE UserID='".db_string($LoggedUser['ID'])."'"); list($SiteOptions)=$DB->next_record(MYSQLI_NUM, false); if(!empty($SiteOptions)) { $SiteOptions = unserialize($SiteOptions); } else { $SiteOptions = array(); } $SiteOptions['DefaultSearch'] = preg_replace($UnsetRegexp,'',$_SERVER['QUERY_STRING']); $DB->query("UPDATE users_info SET SiteOptions='".db_string(serialize($SiteOptions))."' WHERE UserID='".db_string($LoggedUser['ID'])."'"); $Cache->begin_transaction('user_info_heavy_'.$UserID); $Cache->update_row(false, array('DefaultSearch'=>$SiteOptions['DefaultSearch'])); $Cache->commit_transaction(0); // Clearing default search options } elseif(!empty($_GET['cleardefault'])) { $DB->query("SELECT SiteOptions FROM users_info WHERE UserID='".db_string($LoggedUser['ID'])."'"); list($SiteOptions)=$DB->next_record(MYSQLI_NUM, false); $SiteOptions=unserialize($SiteOptions); $SiteOptions['DefaultSearch']=''; $DB->query("UPDATE users_info SET SiteOptions='".db_string(serialize($SiteOptions))."' WHERE UserID='".db_string($LoggedUser['ID'])."'"); $Cache->begin_transaction('user_info_heavy_'.$UserID); $Cache->update_row(false, array('DefaultSearch'=>'')); $Cache->commit_transaction(0); // Use default search options } elseif((empty($_SERVER['QUERY_STRING']) || (count($_GET) == 1 && isset($_GET['page']))) && !empty($LoggedUser['DefaultSearch'])) { if(!empty($_GET['page'])) { $Page = $_GET['page']; parse_str($LoggedUser['DefaultSearch'],$_GET); $_GET['page'] = $Page; } else { parse_str($LoggedUser['DefaultSearch'],$_GET); } } array_pop($Bitrates); // remove 'other' $SearchBitrates = array_merge($Bitrates, array('v0','v1','v2','24bit')); foreach($SearchBitrates as $ID=>$Val) { $SearchBitrates[$ID]=strtolower($Val); } foreach($Formats as $ID=>$Val) { $SearchFormats[$ID]=strtolower($Val); } $Queries = array(); $EnableNegation = false; // Sphinx needs at least one positive search condition to support the NOT operator // Filelist searches makes use of the proximity operator to ensure that all keywords match the same file if(!empty($_GET['filelist'])) { $SearchString = trim($_GET['filelist']); if($SearchString != '') { $Queries[] = '@filelist "'.$SS->EscapeString($_GET['filelist']).'"~20'; $EnableNegation = true; } } // Collect all entered search terms to find out whether to enable the NOT operator foreach(array('artistname','groupname', 'recordlabel', 'cataloguenumber', 'remastertitle', 'remasteryear', 'remasterrecordlabel', 'remastercataloguenumber', 'format', 'media', 'taglist') as $Search) { if(!empty($_GET[$Search])) { $SearchString = trim($_GET[$Search]); if($SearchString != '') { $SearchWords[$Search] = array('include' => array(), 'exclude' => array()); if($Search == 'taglist') { $SearchString = strtr($SearchString, '.', '_'); $Words = explode(',', $SearchString); } else { $Words = explode(' ', $SearchString); } foreach($Words as $Word) { $Word = trim($Word); if($Word[0] == '!' && strlen($Word) >= 2) { if(strpos($Word,'!',1) === false) { $SearchWords[$Search]['exclude'][] = $Word; } else { $SearchWords[$Search]['include'][] = $Word; $EnableNegation = true; } } elseif($Word != '') { $SearchWords[$Search]['include'][] = $Word; $EnableNegation = true; } } } } } //Simple search if(!empty($_GET['searchstr'])) { $SearchString = trim($_GET['searchstr']); $Words = explode(' ',strtolower($SearchString)); if(!empty($Words)) { $FilterBitrates = $FilterFormats = array(); $BasicSearch = array('include' => array(), 'exclude' => array()); foreach($Words as $Word) { $Word = trim($Word); if($Word[0] == '!' && strlen($Word) >= 2) { if($Word == '!100%') { $_GET['haslog'] = '-1'; } elseif(strpos($Word,'!',1) === false) { $BasicSearch['exclude'][] = $Word; } else { $BasicSearch['include'][] = $Word; $EnableNegation = true; } } elseif(in_array($Word, $SearchBitrates)) { $FilterBitrates[] = $Word; $EnableNegation = true; } elseif(in_array($Word, $SearchFormats)) { $FilterFormats[] = $Word; $EnableNegation = true; } elseif($Word == '100%') { $_GET['haslog'] = '100'; } elseif($Word != '') { $BasicSearch['include'][] = $Word; $EnableNegation = true; } } if(!$EnableNegation && !empty($BasicSearch['exclude'])) { $BasicSearch['include'] = array_merge($BasicSearch['include'], $BasicSearch['exclude']); unset($BasicSearch['exclude']); } $QueryParts = array(); foreach($BasicSearch['include'] as $Word) { $QueryParts[] = $SS->EscapeString($Word); } if(!empty($BasicSearch['exclude'])) { foreach($BasicSearch['exclude'] as $Word) { $QueryParts[] = '!'.$SS->EscapeString(substr($Word,1)); } } if(!empty($FilterBitrates)) { $Queries[] = "@encoding ".implode(' ', $FilterBitrates); } if(!empty($FilterFormats)) { $Queries[] = "@format ".implode(' ', $FilterFormats); } if(!empty($QueryParts)) { $Queries[] = "@(groupname,artistname,yearfulltext) ".implode(' ', $QueryParts); } } } // Tag list if(!empty($SearchWords['taglist'])) { $Tags = $SearchWords['taglist']; if(!$EnableNegation && !empty($Tags['exclude'])) { $Tags['include'] = array_merge($Tags['include'], $Tags['exclude']); unset($Tags['exclude']); } foreach($Tags['include'] as &$Tag) { $Tag = $SS->EscapeString($Tag); } if(!empty($Tags['exclude'])) { foreach($Tags['exclude'] as &$Tag) { $Tag = '!'.$SS->EscapeString(substr($Tag,1)); } } $QueryParts = array(); // 'All' tags if(!isset($_GET['tags_type']) || $_GET['tags_type'] == 1) { $_GET['tags_type'] = '1'; $Tags = array_merge($Tags['include'], $Tags['exclude']); if(!empty($Tags)) { $QueryParts[] = implode(' ', $Tags); } } // 'Any' tags else { $_GET['tags_type'] = '0'; if(!empty($Tags['include'])) { $QueryParts[] = '( '.implode(' | ', $Tags['include']).' )'; } if(!empty($Tags['exclude'])) { $QueryParts[] = implode(' ', $Tags['exclude']); } } if(!empty($QueryParts)) { $Queries[] = "@taglist ".implode(' ', $QueryParts); } unset($SearchWords['taglist']); } elseif(!isset($_GET['tags_type'])) { $_GET['tags_type'] = '1'; } foreach($SearchWords as $Search => $Words) { $QueryParts = array(); if(!$EnableNegation && !empty($Words['exclude'])) { $Words['include'] = array_merge($Words['include'], $Words['exclude']); unset($Words['exclude']); } foreach($Words['include'] as $Word) { $QueryParts[] = $SS->EscapeString($Word); } if(!empty($Words['exclude'])) { foreach($Words['exclude'] as $Word) { $QueryParts[] = '!'.$SS->EscapeString(substr($Word,1)); } } if(!empty($QueryParts)) { $Queries[] = "@$Search ".implode(' ', $QueryParts); } } if(!empty($_GET['year'])) { $Years = explode('-', $_GET['year']); if(is_number($Years[0]) || (empty($Years[0]) && !empty($Years[1]) && is_number($Years[1]))) { if(count($Years) == 1) { $SS->set_filter('year', array((int)$Years[0])); } else { if(empty($Years[1]) || !is_number($Years[1])) { $Years[1] = PHP_INT_MAX; } elseif($Years[0] > $Years[1]) { $Years = array_reverse($Years); } $SS->set_filter_range('year', (int)$Years[0], (int)$Years[1]); } } } if(!empty($_GET['encoding'])) { $Queries[]='@encoding "'.$SS->EscapeString(strtr($_GET['encoding'], '.', ' ')).'"'; // Conversion from period to space is necessary due to a sphinx limitation/bug } if(isset($_GET['haslog']) && $_GET['haslog']!=='') { if($_GET['haslog'] == 100) { $SS->set_filter('logscore', array(100)); } elseif ($_GET['haslog'] < 0) { // Exclude torrents with log score equal to 100 $SS->set_filter('logscore', array(100), true); $SS->set_filter('haslog', array(1)); } else { $SS->set_filter('haslog', array(1)); } } foreach(array('hascue','scene','vanityhouse','freetorrent','releasetype') as $Search) { if(isset($_GET[$Search]) && $_GET[$Search]!=='') { if($Search == 'freetorrent') { switch($_GET[$Search]) { case 0: $SS->set_filter($Search, array(0)); break; case 1: $SS->set_filter($Search, array(1)); break; case 2: $SS->set_filter($Search, array(2)); break; case 3: $SS->set_filter($Search, array(0), true); break; } } else { $SS->set_filter($Search, array($_GET[$Search])); } } } if(!empty($_GET['filter_cat'])) { $SS->set_filter('categoryid', array_keys($_GET['filter_cat'])); } if(!empty($_GET['page']) && is_number($_GET['page']) && $_GET['page'] > 0) { if(check_perms('site_search_many')) { $Page = $_GET['page']; } else { $Page = min(SPHINX_MAX_MATCHES/TORRENTS_PER_PAGE, $_GET['page']); } $SS->limit(($Page-1)*TORRENTS_PER_PAGE, TORRENTS_PER_PAGE); } else { $Page = 1; $SS->limit(0, TORRENTS_PER_PAGE); } if(!empty($_GET['order_way']) && $_GET['order_way'] == 'asc') { $Way = SPH_SORT_ATTR_ASC; $OrderWay = 'asc'; // For header links } else { $Way = SPH_SORT_ATTR_DESC; $_GET['order_way'] = 'desc'; $OrderWay = 'desc'; } if(empty($_GET['order_by']) || !in_array($_GET['order_by'], array('year','time','size','seeders','leechers','snatched','random'))) { $_GET['order_by'] = 'time'; $OrderBy = 'time'; // For header links } elseif($_GET['order_by'] == 'random') { $OrderBy = '@random'; $Way = SPH_SORT_EXTENDED; $SS->limit(0, TORRENTS_PER_PAGE); } else { $OrderBy = $_GET['order_by']; } $SS->SetSortMode($Way, $OrderBy); if(count($Queries)>0) { $Query = implode(' ',$Queries); } else { $Query=''; if(empty($SS->Filters)) { $SS->set_filter('size', array(0), true); } } $SS->set_index(SPHINX_INDEX.' delta'); $Results = $SS->search($Query, '', 0, array(), '', ''); if(check_perms('site_search_many')) { $TorrentCount = $SS->TotalResults; } else { $TorrentCount = min($SS->TotalResults, SPHINX_MAX_MATCHES); } /* // If some were fetched from memcached, get their artists if(!empty($Results['matches'])) { // Fetch the artists for groups $GroupIDs = array_keys($Results['matches']); $Artists = get_artists($GroupIDs); foreach($Artists as $GroupID=>$Data) { if(!empty($Data[1])) { $Results['matches'][$GroupID]['Artists']=$Data[1]; // Only use main artists } ksort($Results['matches'][$GroupID]); } } */ // These ones were not found in the cache, run SQL if(!empty($Results['notfound'])) { $SQLResults = get_groups($Results['notfound']); if(is_array($SQLResults['notfound'])) { // Something wasn't found in the db, remove it from results reset($SQLResults['notfound']); foreach($SQLResults['notfound'] as $ID) { unset($SQLResults['matches'][$ID]); unset($Results['matches'][$ID]); } } // Merge SQL results with sphinx/memcached results foreach($SQLResults['matches'] as $ID=>$SQLResult) { $Results['matches'][$ID] = array_merge($Results['matches'][$ID], $SQLResult); ksort($Results['matches'][$ID]); } } $Results = $Results['matches']; $AdvancedSearch = false; $Action = 'action=basic'; if(((!empty($_GET['action']) && strtolower($_GET['action'])=="advanced") || (!empty($LoggedUser['SearchType']) && ((!empty($_GET['action']) && strtolower($_GET['action'])!="basic") || empty($_GET['action'])))) && check_perms('site_advanced_search')) { $AdvancedSearch = true; $Action = 'action=advanced'; } show_header('Browse Torrents','browse'); ?>
if($TorrentCount == 0) { $DB->query("SELECT tags.Name, ((COUNT(tags.Name)-2)*(SUM(tt.PositiveVotes)-SUM(tt.NegativeVotes)))/(tags.Uses*0.8) AS Score FROM xbt_snatched AS s INNER JOIN torrents AS t ON t.ID=s.fid INNER JOIN torrents_group AS g ON t.GroupID=g.ID INNER JOIN torrents_tags AS tt ON tt.GroupID=g.ID INNER JOIN tags ON tags.ID=tt.TagID WHERE s.uid='$LoggedUser[ID]' AND tt.TagID<>'13679' AND tt.TagID<>'4820' AND tt.TagID<>'2838' AND g.CategoryID='1' AND tags.Uses > '10' GROUP BY tt.TagID ORDER BY Score DESC LIMIT 8"); ?>Make sure all names are spelled correctly, or try making your search less specific.
You might like (Beta): while(list($Tag)=$DB->next_record()) { ?>=$Tag?> } ?>
You are requesting page =$Page?>, but the search returned only =$LastPage?> pages.
Name / Year | Files | Time | Size | |||||
=$DisplayName?>
if(in_array($GroupID, $Bookmarks)) { ?>
Unbookmark
} else { ?>
Bookmark
} ?>
|
=time_diff($GroupTime,1)?> | =get_size($MaxSize*1024)?> (Max) | =number_format($TotalSnatched)?> | >=number_format($TotalSeeders)?> | =number_format($TotalLeechers)?> | |||
[ DL
if (($LoggedUser['FLTokens'] > 0) && $Data['HasFile'] && ($Data['Size'] < 1073741824)
&& !in_array($TorrentID, $TokenTorrents) && empty($Data['FreeTorrent']) && ($LoggedUser['CanLeech'] == '1')) { ?>
| FL
} ?>
| RP ]
=$DisplayName?>
|
=$Data['FileCount']?> | =time_diff($GroupTime,1)?> | =get_size($Data['Size'])?> | =number_format($TotalSnatched)?> | >=number_format($TotalSeeders)?> | =number_format($TotalLeechers)?> |