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&".Format::get_url(array('order_way', 'order_by'));
}
if (!empty($_GET['searchstr']) || !empty($_GET['groupname'])) {
if (!empty($_GET['searchstr'])) {
$InfoHash = $_GET['searchstr'];
} else {
$InfoHash = $_GET['groupname'];
}
// Search by infohash
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->has_results()) {
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']))) {
if (!empty($LoggedUser['DefaultSearch'])) {
if (!empty($_GET['page'])) {
$Page = $_GET['page'];
parse_str($LoggedUser['DefaultSearch'], $_GET);
$_GET['page'] = $Page;
} else {
parse_str($LoggedUser['DefaultSearch'], $_GET);
}
}
}
// Terms were not submitted via the search form
if (isset($_GET['searchsubmit'])) {
$GroupResults = !empty($_GET['group_results']);
} else {
$GroupResults = !$LoggedUser['DisableGrouping2'];
}
if (!empty($_GET['order_way']) && $_GET['order_way'] == 'asc') {
$OrderWay = 'asc';
} else {
$OrderWay = 'desc';
}
if (empty($_GET['order_by']) || !isset(TorrentSearch::$SortOrders[$_GET['order_by']])) {
$OrderBy = 'time'; // For header links
} else {
$OrderBy = $_GET['order_by'];
}
$Page = !empty($_GET['page']) ? (int) $_GET['page'] : 1;
$Search = new TorrentSearch($GroupResults, $OrderBy, $OrderWay, $Page, TORRENTS_PER_PAGE);
if (isset($LoggedUser['HideLolicon']) && $LoggedUser['HideLolicon'] == 1) {
$Search->insert_hidden_tags('!lolicon !shotacon !toddlercon');
}
if (isset($LoggedUser['HideScat']) && $LoggedUser['HideScat'] == 1) {
$Search->insert_hidden_tags('!scat');
}
if (isset($LoggedUser['HideSnuff']) && $LoggedUser['HideSnuff'] == 1) {
$Search->insert_hidden_tags('!snuff');
}
$Results = $Search->query($_GET);
$Groups = $Search->get_groups();
$NumResults = $Search->record_count();
$HideFilter = isset($LoggedUser['ShowTorFilter']) && $LoggedUser['ShowTorFilter'] == 0;
// This is kinda ugly, but the enormous if paragraph was really hard to read
$AdvancedSearch = !empty($_GET['action']) && $_GET['action'] == 'advanced';
$AdvancedSearch |= !empty($LoggedUser['SearchType']) && (empty($_GET['action']) || $_GET['action'] == 'advanced');
$AdvancedSearch &= check_perms('site_advanced_search');
if ($AdvancedSearch) {
$Action = 'action=advanced';
$HideBasic = ' hidden';
$HideAdvanced = '';
} else {
$Action = 'action=basic';
$HideBasic = '';
$HideAdvanced = ' hidden';
}
View::show_header('Browse Torrents', 'browse');
?>
if ($NumResults == 0) { ?>
Your search did not match anything.
Make sure all names are spelled correctly, or try making your search less specific.
View::show_footer();die();
}
if ($NumResults < ($Page - 1) * TORRENTS_PER_PAGE + 1) {
$LastPage = ceil($NumResults / TORRENTS_PER_PAGE);
$Pages = Format::get_pages(0, $NumResults, TORRENTS_PER_PAGE);
?>
The requested page contains no matches.
You are requesting page =$Page?>, but the search returned only =number_format($LastPage) ?> pages.
Go to page =$Pages?>
View::show_footer();die();
}
// List of pages
$Pages = Format::get_pages($Page, $NumResults, TORRENTS_PER_PAGE);
$Bookmarks = Bookmarks::all_bookmarks('torrent');
?>
=$Pages?>
if ($GroupResults) { ?>
} ?>
Name / Year
Files
Time
Size
// Start printing torrent list
foreach ($Results as $Key => $GroupID) {
$GroupInfo = $Groups[$GroupID];
if (empty($GroupInfo['Torrents'])) {
continue;
}
$CategoryID = $GroupInfo['CategoryID'];
$GroupYear = $GroupInfo['Year'];
$Artists = $GroupInfo['Artists'];
$GroupCatalogueNumber = $GroupInfo['CatalogueNumber'];
$GroupPages = $GroupInfo['Pages'];
$GroupStudio = $GroupInfo['Studio'];
$GroupDLsiteID = $GroupInfo['DLSiteID'];
$GroupName = $GroupInfo['Name'];
if ($GroupResults) {
$Torrents = $GroupInfo['Torrents'];
$GroupTime = $MaxSize = $TotalLeechers = $TotalSeeders = $TotalSnatched = 0;
foreach ($Torrents as $T) {
$GroupTime = max($GroupTime, strtotime($T['Time']));
$MaxSize = max($MaxSize, $T['Size']);
$TotalLeechers += $T['Leechers'];
$TotalSeeders += $T['Seeders'];
$TotalSnatched += $T['Snatched'];
}
} else {
$TorrentID = $Key;
$Torrents = array($TorrentID => $GroupInfo['Torrents'][$TorrentID]);
}
$TorrentTags = new Tags($GroupInfo['TagList']);
if (isset($Artists)) {
$DisplayName = ''.Artists::display_artists($Artists).'
';
} else {
$DisplayName = '';
}
$SnatchedGroupClass = $GroupInfo['Flags']['IsSnatched'] ? ' snatched_group' : '';
if ($GroupResults && (count($Torrents) > 1 && isset($GroupedCategories[$CategoryID - 1]))) {
// These torrents are in a group
$CoverArt = $GroupInfo['WikiImage'];
$DisplayName .= "$GroupName ";
if ($GroupYear) {
$DisplayName .= " [$GroupYear]";
}
if ($GroupStudio) {
$DisplayName .= " [$GroupStudio]";
}
if ($GroupCatalogueNumber) {
$DisplayName .= " [$GroupCatalogueNumber]";
}
if ($GroupPages) {
$DisplayName .= " [{$GroupPages}p]";
}
if ($GroupDLsiteID) {
$DisplayName .= " [$GroupDLsiteID]";
}
?>
$ShowGroups = !(!empty($LoggedUser['TorrentGrouping']) && $LoggedUser['TorrentGrouping'] == 1);
?>
=$DisplayName?>
if (in_array($GroupID, $Bookmarks)) { ?>
Remove bookmark
} else { ?>
Bookmark
} ?>
=$TorrentTags->format('torrents.php?'.$Action.'&taglist=')?>
=time_diff($GroupTime, 1)?>
=Format::get_size($MaxSize)?> (Max)
=number_format($TotalSnatched)?>
=number_format($TotalSeeders)?>
=number_format($TotalLeechers)?>
foreach ($Torrents as $TorrentID => $Data) {
$Data['CategoryID'] = $CategoryID;
// All of the individual torrents in the group
//Get report info for each torrent, use the cache if available, if not, add to it.
$Reported = false;
$Reports = Torrents::get_reports($TorrentID);
if (count($Reports) > 0) {
$Reported = true;
}
$SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
$TorrentDL = "torrents.php?action=download&id=".$TorrentID."&authkey=".$LoggedUser['AuthKey']."&torrent_pass=".$LoggedUser['torrent_pass'];
if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
$TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
$Tor = new BencodeTorrent($TorrentFile);
$TorrentFileName = $Tor->Dec['info']['name'];
$Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
}
$TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
?>
[ =$Data['HasFile'] ? 'DL' : 'Missing'?>
| MG
if (Torrents::can_use_token($Data)) { ?>
| FL
} ?>
| RP ]
» =Torrents::torrent_info($Data)?> if ($Reported) { ?> / Reported } ?>
=$Data['FileCount']?>
=time_diff($Data['Time'], 1)?>
=Format::get_size($Data['Size'])?>
=number_format($Data['Snatched'])?>
=number_format($Data['Seeders'])?>
=number_format($Data['Leechers'])?>
}
} else {
// Viewing a type that does not require grouping
list($TorrentID, $Data) = each($Torrents);
$Reported = false;
$Reports = Torrents::get_reports($TorrentID);
if (count($Reports) > 0) {
$Reported = true;
}
$Data['CategoryID'] = $CategoryID;
$CoverArt = $GroupInfo['WikiImage'];
$DisplayName .= "$GroupName ";
if (isset($GroupedCategories[$CategoryID - 1])) {
if ($GroupYear) {
$DisplayName .= " [$GroupYear]";
}
if ($GroupStudio) {
$DisplayName .= " [$GroupStudio]";
}
if ($GroupCatalogueNumber) {
$DisplayName .= " [$GroupCatalogueNumber]";
}
if ($GroupPages) {
$DisplayName .= " [{$GroupPages}p]";
}
if ($GroupDLsiteID) {
$DisplayName .= " [$GroupDLsiteID]";
}
$ExtraInfo = Torrents::torrent_info($Data, true, true);
} elseif ($Data['IsSnatched']) {
$ExtraInfo = Format::torrent_label('Snatched!');
} else {
$ExtraInfo = '';
}
$SnatchedTorrentClass = $Data['IsSnatched'] ? ' snatched_torrent' : '';
$TorrentDL = "torrents.php?action=download&id=".$TorrentID."&authkey=".$LoggedUser['AuthKey']."&torrent_pass=".$LoggedUser['torrent_pass'];
if (!($TorrentFileName = $Cache->get_value('torrent_file_name_'.$TorrentID))) {
$TorrentFile = file_get_contents(TORRENT_STORE.$TorrentID.'.torrent');
$Tor = new BencodeTorrent($TorrentFile);
$TorrentFileName = $Tor->Dec['info']['name'];
$Cache->cache_value('torrent_file_name_'.$TorrentID, $TorrentFileName);
}
$TorrentMG = "magnet:?dn=".rawurlencode($TorrentFileName)."&xt=urn:btih:".$Data['info_hash']."&as=https://".SITE_DOMAIN."/".str_replace('&','%26',$TorrentDL)."&tr=".implode("/".$LoggedUser['torrent_pass']."/announce&tr=",ANNOUNCE_URLS[0])."/".$LoggedUser['torrent_pass']."/announce&xl=".$Data['Size'];
?>
if ($GroupResults) { ?>
} ?>
=$DisplayName?>
=$ExtraInfo?> if ($Reported) { ?> / Reported } ?>
=$TorrentTags->format("torrents.php?$Action&taglist=")?>
=$Data['FileCount']?>
=time_diff($Data['Time'], 1)?>
=Format::get_size($Data['Size'])?>
=number_format($Data['Snatched'])?>
=number_format($Data['Seeders'])?>
=number_format($Data['Leechers'])?>
}
}
?>
=$Pages?>
View::show_footer(); ?>