'Descending', 'ASC' => 'Ascending']; // The "order by x" links on columns headers function header_link($SortKey, $DefaultWay = 'DESC') { global $Order, $Way; if ($SortKey === $Order) { if ($Way === 'DESC') { $NewWay = 'ASC'; } else { $NewWay = 'DESC'; } } else { $NewWay = $DefaultWay; } return "torrents.php?way=$NewWay&order=$SortKey&" . Format::get_url(array('way','order')); } $UserID = $_GET['userid']; if (!is_number($UserID)) { error(0); } if (!empty($_GET['page']) && is_number($_GET['page']) && $_GET['page'] > 0) { $Page = $_GET['page']; $Limit = ($Page - 1) * TORRENTS_PER_PAGE.', '.TORRENTS_PER_PAGE; } else { $Page = 1; $Limit = TORRENTS_PER_PAGE; } if (!empty($_GET['order']) && in_array($_GET['order'], $Orders)) { $Order = $_GET['order']; } else { $Order = 'Time'; } if (!empty($_GET['way']) && array_key_exists($_GET['way'], $Ways)) { $Way = $_GET['way']; } else { $Way = 'DESC'; } $SearchWhere = []; if (!empty($_GET['format'])) { if (in_array($_GET['format'], $Formats)) { $SearchWhere[] = "t.`Format` = '".db_string($_GET['format'])."'"; } } # Get release specifics if (isset($_GET['container']) && in_array($_GET['container'], $ENV-flatten($ENV->META->Formats))) { $SearchWhere[] = "t.`Container` = '".db_string($_GET['container'])."'"; } if (isset($_GET['bitrate']) && in_array($_GET['bitrate'], $Bitrates)) { $SearchWhere[] = "t.`Encoding` = '".db_string($_GET['bitrate'])."'"; } if (isset($_GET['media']) && in_array($_GET['media'], $ENV-flatten($ENV->META->Platforms))) { $SearchWhere[] = "t.`Media` = '".db_string($_GET['media'])."'"; } if (isset($_GET['codec']) && in_array($_GET['codec'], $ENV->META->Licenses)) { $SearchWhere[] = "t.`Codec` = '".db_string($_GET['codec'])."'"; } if (isset($_GET['version'])) { $SearchWhere[] = "t.`Version` = '".db_string($_GET['version'])."'"; } if (isset($_GET['resolution']) && in_array($_GET['resolution'], $ENV->flatten($ENV->META->Scopes))) { $SearchWhere[] = "t.`Resolution` = '".db_string($_GET['resolution'])."'"; } if (isset($_GET['censored']) && in_array($_GET['censored'], array(1, 0))) { $SearchWhere[] = "t.`Censored` = '".db_string($_GET['censored'])."'"; } if (!empty($_GET['categories'])) { $Cats = []; foreach (array_keys($_GET['categories']) as $Cat) { if (!is_number($Cat)) { error(0); } $Cats[] = "tg.`category_id` = '".db_string($Cat)."'"; } $SearchWhere[] = '('.implode(' OR ', $Cats).')'; } if (!isset($_GET['tags_type'])) { $_GET['tags_type'] = '1'; } if (!empty($_GET['tags'])) { $Tags = explode(',', $_GET['tags']); $TagList = []; foreach ($Tags as $Tag) { $Tag = trim(str_replace('.', '_', $Tag)); if (empty($Tag)) { continue; } if ($Tag[0] === '!') { $Tag = ltrim(substr($Tag, 1)); if (empty($Tag)) { continue; } $TagList[] = "tg.`tag_list` NOT RLIKE '[[:<:]]".db_string($Tag)."(:[^ ]+)?[[:>:]]'"; } else { $TagList[] = "tg.`tag_list` RLIKE '[[:<:]]".db_string($Tag)."(:[^ ]+)?[[:>:]]'"; } } if (!empty($TagList)) { if (isset($_GET['tags_type']) && $_GET['tags_type'] !== '1') { $_GET['tags_type'] = '0'; $SearchWhere[] = '('.implode(' OR ', $TagList).')'; } else { $_GET['tags_type'] = '1'; $SearchWhere[] = '('.implode(' AND ', $TagList).')'; } } } $SearchWhere = implode(' AND ', $SearchWhere); if (!empty($SearchWhere)) { $SearchWhere = " AND $SearchWhere"; } $User = Users::user_info($UserID); $Perms = Permissions::get_permissions($User['PermissionID']); $UserClass = $Perms['Class']; switch ($_GET['type']) { case 'snatched': if (!check_paranoia('snatched', $User['Paranoia'], $UserClass, $UserID)) { error(403); } $Time = 'xs.`tstamp`'; $UserField = 'xs.`uid`'; $ExtraWhere = ''; $From = " `xbt_snatched` AS xs JOIN `torrents` AS t ON t.`ID` = xs.`fid`"; break; case 'seeding': if (!check_paranoia('seeding', $User['Paranoia'], $UserClass, $UserID)) { error(403); } $Time = '(xfu.`mtime` - xfu.`timespent`)'; $UserField = 'xfu.`uid`'; $ExtraWhere = ' AND xfu.`active` = 1 AND xfu.`Remaining` = 0'; $From = " `xbt_files_users` AS xfu JOIN `torrents` AS t ON t.`ID` = xfu.`fid`"; break; case 'contest': $Time = 'unix_timestamp(t.`Time`)'; $UserField = 't.`UserID`'; $ExtraWhere = " AND t.`ID` IN ( SELECT `TorrentID` FROM `library_contest` WHERE `UserID` = $UserID )"; $From = '`torrents` AS t'; break; case 'leeching': if (!check_paranoia('leeching', $User['Paranoia'], $UserClass, $UserID)) { error(403); } $Time = '(xfu.`mtime` - xfu.`timespent`)'; $UserField = 'xfu.`uid`'; $ExtraWhere = ' AND xfu.`active` = 1 AND xfu.`Remaining` > 0'; $From = " `xbt_files_users` AS xfu JOIN `torrents` AS t ON t.`ID` = xfu.`fid`"; break; case 'uploaded': if ((empty($_GET['filter']) || $_GET['filter'] !== 'perfectflac') && !check_paranoia('uploads', $User['Paranoia'], $UserClass, $UserID)) { error(403); } $Time = 'unix_timestamp(t.`Time`)'; $UserField = 't.`UserID`'; $ExtraWhere = ''; $From = "`torrents` AS t"; break; case 'downloaded': if (!check_perms('site_view_torrent_snatchlist')) { error(403); } $Time = 'unix_timestamp(ud.`Time`)'; $UserField = 'ud.`UserID`'; $ExtraWhere = ''; $From = " `users_downloads` AS ud JOIN `torrents` AS t ON t.`ID` = ud.`TorrentID`"; break; default: error(404); } if (empty($GroupBy)) { $GroupBy = 't.`ID`'; } if ((empty($_GET['search']) || trim($_GET['search']) === '')) { // && $Order !== 'Name') { $SQL = " SELECT SQL_CALC_FOUND_ROWS t.`GroupID`, t.`ID` AS TorrentID, $Time AS Time, COALESCE(NULLIF(tg.`title`, ''), NULLIF(tg. subject, ''), tg.`object`) AS Name, tg.`category_id` FROM $From JOIN `torrents_group` AS tg ON tg.`id` = t.`GroupID` WHERE $UserField = '$UserID' $ExtraWhere $SearchWhere GROUP BY $GroupBy ORDER BY $Order $Way LIMIT $Limit"; } else { $DB->query(" CREATE TEMPORARY TABLE `temp_sections_torrents_user` ( `GroupID` int(10) unsigned not null, `TorrentID` int(10) unsigned not null, `Time` int(12) unsigned not null, `CategoryID` int(3) unsigned, `Seeders` int(6) unsigned, `Leechers` int(6) unsigned, `Snatched` int(10) unsigned, `Name` mediumtext, `Size` bigint(12) unsigned, PRIMARY KEY (`TorrentID`)) CHARSET=utf8"); $DB->query(" INSERT IGNORE INTO `temp_sections_torrents_user` SELECT t.`GroupID`, t.`ID` AS TorrentID, $Time AS Time, tg.`category_id`, t.`Seeders`, t.`Leechers`, t.`Snatched`, CONCAT_WS(' ', GROUP_CONCAT(ag.`Name` SEPARATOR ' '), ' ', COALESCE(NULLIF(tg.`title`,''), NULLIF(tg.`subject`,''), tg.`object`), ' ', tg.`year`, ' ') AS Name, t.`Size` FROM $From JOIN `torrents_group` AS tg ON tg.`id` = t.`GroupID` LEFT JOIN `torrents_artists` AS ta ON ta.`GroupID` = tg.`id` LEFT JOIN `artists_group` AS ag ON ag.`ArtistID` = ta.`ArtistID` WHERE $UserField = '$UserID' $ExtraWhere $SearchWhere GROUP BY `TorrentID`, `Time`"); if (!empty($_GET['search']) && trim($_GET['search']) !== '') { $Words = array_unique(explode(' ', db_string($_GET['search']))); } $SQL = " SELECT SQL_CALC_FOUND_ROWS `GroupID`, `TorrentID`, `Time`, `CategoryID` FROM `temp_sections_torrents_user`"; if (!empty($Words)) { $SQL .= " WHERE `Name` LIKE '%".implode("%' AND `Name` LIKE '%", $Words)."%'"; } $SQL .= " ORDER BY $Order $Way LIMIT $Limit"; } $DB->query($SQL); $GroupIDs = $DB->collect('GroupID'); $TorrentsInfo = $DB->to_array('TorrentID', MYSQLI_ASSOC); $DB->query('SELECT FOUND_ROWS()'); list($TorrentCount) = $DB->next_record(); $Results = Torrents::get_groups($GroupIDs); $Action = display_str($_GET['type']); $User = Users::user_info($UserID); View::show_header($User['Username']."'s $Action torrents", 'browse'); $Pages = Format::get_pages($Page, $TorrentCount, TORRENTS_PER_PAGE); ?>
Torrent | Time | Size | ↻ | ↑ | ↓ | |
|
= time_diff($Time, 1) ?> | = Format::get_size($Torrent['Size']) ?> | = number_format($Torrent['Snatched']) ?> | = number_format($Torrent['Seeders']) ?> | = number_format($Torrent['Leechers']) ?> |