123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- <?php
- #declare(strict_types = 1);
-
- $ENV = ENV::go();
-
- $Orders = ['Time', 'Name', 'Seeders', 'Leechers', 'Snatched', 'Size'];
- $Ways = ['DESC' => '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);
- ?>
-
- <div>
- <div class="header">
- <h2>
- <a href="user.php?id=<?= $UserID ?>"><?= $User['Username'] ?></a>
- <?= "'s $Action torrents" ?>
- </h2>
- </div>
-
- <div class="box pad">
- <form class="search_form" name="torrents" action="" method="get">
- <table class="layout">
-
- <!-- Terms -->
- <tr>
- <td class="label"><strong>Search Terms</strong></td>
- <td>
- <input type="hidden" name="type"
- value="<?= $_GET['type'] ?>" />
- <input type="hidden" name="userid"
- value="<?= $UserID ?>" />
- <input type="search" name="search" size="60"
- value="<?php Format::form('search') ?>" />
- </td>
- </tr>
-
- <!--
- Specifics
- todo: Make like the Seq/Img Format fields in browse.php
- -->
- <tr>
- <td class="label"><strong>Specifics</strong></td>
- <td class="nobr" colspan="3">
- <select id="container" name="container" class="ft_container">
- <option value="">Format</option>
- <?php foreach ($Containers as $Key => $ContainerName) { ?>
- <option value="<?= display_str($Key); ?>" <?php Format::selected('container', $Key) ?>><?= display_str($Key); ?>
- </option>
- <?php } ?>
- </select>
-
- <select id="codec" name="codec" class="ft_codec">
- <option value="">License</option>
- <?php foreach ($ENV->META->Licenses as $License) { ?>
- <option value="<?= display_str($License); ?>" <?php Format::selected('codec', $License) ?>><?= display_str($License); ?>
- </option>
- <?php } ?>
- </select>
-
- <select id="resolution" name="resolution" class="ft_resolution">
- <option value="">Scope</option>
- <?php foreach ($Resolutions as $ResolutionName) { ?>
- <option value="<?= display_str($ResolutionName); ?>"
- <?php Format::selected('resolution', $ResolutionName) ?>><?= display_str($ResolutionName); ?>
- </option>
- <?php } ?>
- </select>
-
- <select name="media" class="ft_media">
- <option value="">Platform</option>
- <?php foreach ($Media as $MediaName) { ?>
- <option value="<?= display_str($MediaName); ?>" <?php Format::selected('media', $MediaName) ?>><?= display_str($MediaName); ?>
- </option>
- <?php } ?>
- </select>
- </td>
- </tr>
-
- <!-- Misc -->
- <tr>
- <td class="label"><strong>Misc</strong></td>
- <td class="nobr" colspan="3">
- <select name="censored" class="ft_censored">
- <option value="3">Alignment</option>
- <option value="1" <?Format::selected('censored', 1)?>>
- Aligned
- </option>
- <option value="0" <?Format::selected('censored', 0)?>>
- Not Aligned
- </option>
- </select>
- </td>
- </tr>
-
- <!-- Tags -->
- <tr>
- <td class="label"><strong>Tags</strong></td>
- <td>
- <input type="search" name="tags" size="60"
- value="<?php Format::form('tags') ?>" />
- <input type="radio" name="tags_type" id="tags_type0" value="0" <?php Format::selected('tags_type', 0, 'checked') ?>
- /><label for="tags_type0"> Any</label>
- <input type="radio" name="tags_type" id="tags_type1" value="1" <?php Format::selected('tags_type', 1, 'checked') ?>
- /><label for="tags_type1"> All</label><br />
- Use !tag to exclude tags
- </td>
- </tr>
-
- <!-- Order By -->
- <tr>
- <td class="label"><strong>Order By</strong></td>
- <td>
- <select name="order" class="ft_order_by">
- <?php foreach ($Orders as $OrderText) { ?>
- <option value="<?= $OrderText ?>" <?php Format::selected('order', $OrderText) ?>><?= $OrderText ?>
- </option>
- <?php } ?>
- </select>
-
- <select name="way" class="ft_order_way">
- <?php foreach ($Ways as $WayKey=>$WayText) { ?>
- <option value="<?= $WayKey ?>" <?php Format::selected('way', $WayKey) ?>><?= $WayText ?>
- </option>
- <?php } ?>
- </select>
- </td>
- </tr>
- </table>
-
- <!-- Categories -->
- <table class="layout cat_list">
- <?php
- $x = 0;
- reset($Categories);
- foreach ($Categories as $CatKey => $CatName) {
- if ($x % 7 === 0) {
- if ($x > 0) { ?>
- </tr>
- <?php } ?>
- <tr>
- <?php
- }
- $x++; ?>
- <td>
- <input type="checkbox"
- name="categories[<?= ($CatKey+1) ?>]"
- id="cat_<?= ($CatKey+1) ?>" value="1" <?php if (isset($_GET['categories'][$CatKey + 1])) { ?>
- checked="checked"<?php } ?> />
- <label for="cat_<?= ($CatKey + 1) ?>"><?= $CatName ?></label>
- </td>
- <?php
- } ?>
- </tr>
- </table>
-
- <!-- Submit -->
- <div class="submit">
- <span class="float_left">
- <?= number_format($TorrentCount) ?>
- Results
- </span>
- <input type="submit" class="button-primary" value="Search" />
- </div>
- </form>
- </div>
-
- <!-- Results table -->
- <?php if (count($GroupIDs) === 0) { ?>
- <div class="center">
- Nothing found!
- </div>
- <?php } else { ?>
- <div class="linkbox">
- <?=$Pages?>
- </div>
-
- <div class="box">
- <table class="torrent_table cats" width="100%">
- <tr class="colhead">
- <td class="cats_col"></td>
-
- <td>
- <a
- href="<?= header_link('Name', 'ASC') ?>">Torrent</a>
- </td>
-
- <td>
- <a
- href="<?= header_link('Time') ?>">Time</a>
- </td>
-
- <td>
- <a
- href="<?= header_link('Size') ?>">Size</a>
- </td>
-
- <td class="sign snatches">
- <a
- href="<?= header_link('Snatched') ?>">↻</a>
- </td>
-
- <td class="sign seeders">
- <a
- href="<?= header_link('Seeders') ?>">↑</a>
- </td>
-
- <td class="sign leechers">
- <a
- href="<?= header_link('Leechers') ?>">↓</a>
- </td>
- </tr>
-
- <!-- Results list -->
- <?php
- $PageSize = 0;
- foreach ($TorrentsInfo as $TorrentID => $Info) {
- list($GroupID, , $Time) = array_values($Info);
- extract(Torrents::array_group($Results[$GroupID]));
- $Torrent = $Torrents[$TorrentID];
- $TorrentTags = new Tags($TagList);
-
- # This is the torrent list formatting!
- $DisplayName = '';
- $DisplayName .= '<a class="torrent_title" href="torrents.php?id='.$GroupID.'&torrentid='.$TorrentID.'" ';
-
- # No cover art
- if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
- $DisplayName .= 'data-cover="'.ImageTools::process($WikiImage, 'thumb').'" ';
- }
-
- # Old concatenated title: EN, JP, RJ
- #$GroupName = empty($GroupName) ? (empty($GroupTitle2) ? $GroupNameJP : $GroupTitle2) : $GroupName;
- $DisplayName .= 'dir="ltr">'.$GroupName.'</a>';
-
- # Year
- if ($GroupYear) {
- $Label = '<br />📅 ';
- $DisplayName .= $Label."<a href='torrents.php?action=search&year=$GroupYear'>$GroupYear</a>";
- }
-
- # Studio
- if ($GroupStudio) {
- $Label = ' 📍 ';
- $DisplayName .= $Label."<a href='torrents.php?action=search&location=$GroupStudio'>$GroupStudio</a>";
- }
-
- # Catalogue Number
- if ($GroupCatalogueNumber) {
- $Label = ' 🔑 ';
- $DisplayName .= $Label."<a href='torrents.php?action=search&numbers=$GroupCatalogueNumber'>$GroupCatalogueNumber</a>";
- }
-
- # Organism
- if ($GroupTitle2) {
- $Label = ' 🦠 ';
- $DisplayName .= $Label."<a href='torrents.php?action=search&advgroupname=$GroupTitle2'><em>$GroupTitle2</em></a>";
- }
-
- # Strain/Variety
- if ($GroupNameJP) {
- $Label = ' ';
- $DisplayName .= $Label."<a href='torrents.php?action=search&advgroupname=$GroupNameJP'>$GroupNameJP</a>";
- }
-
- # Authors
- if (isset($Artists)) {
- # Emoji in classes/astists.class.php
- $Label = ' ';
- $DisplayName .= $Label.'<div class="torrent_artists">'.Artists::display_artists($Artists).'</div>';
- }
- ?>
-
- <tr
- class="torrent torrent_row<?= ($Torrent['IsSnatched'] ? ' snatched_torrent' : '') . ($GroupFlags['IsSnatched'] ? ' snatched_group' : '') ?>">
- <td class="center cats_col">
- <div
- title="<?= Format::pretty_category($GroupCategoryID) ?>"
- class="tooltip <?= Format::css_category($GroupCategoryID) ?>">
- </div>
- </td>
-
- <td class="big_info">
- <div class="group_info clear">
- <span class="torrent_links_block">
- [ <a
- href="torrents.php?action=download&id=<?= $TorrentID ?>&authkey=<?= $LoggedUser['AuthKey'] ?>&torrent_pass=<?= $LoggedUser['torrent_pass'] ?>"
- class="tooltip" title="Download">DL</a>
- | <a
- href="reportsv2.php?action=report&id=<?= $TorrentID ?>"
- class="tooltip" title="Report">RP</a> ]
- </span>
-
- <?= "$DisplayName\n"; ?>
- <?php
- $ExtraInfo = Torrents::torrent_info($Torrent);
- if ($ExtraInfo) {
- echo "<br />$ExtraInfo";
- } ?>
- <div class="tags"><?= $TorrentTags->format('torrents.php?type='.$Action.'&userid='.$UserID.'&tags=') ?>
- </div>
- </div>
- </td>
- <td class="nobr"><?= time_diff($Time, 1) ?>
- </td>
- <td class="number_column nobr"><?= Format::get_size($Torrent['Size']) ?>
- </td>
- <td class="number_column"><?= number_format($Torrent['Snatched']) ?>
- </td>
- <td
- class="number_column<?= (($Torrent['Seeders'] === 0) ? ' r00' : '') ?>">
- <?= number_format($Torrent['Seeders']) ?>
- </td>
- <td class="number_column"><?= number_format($Torrent['Leechers']) ?>
- </td>
- </tr>
- <?php
- } ?>
- </table>
- </div>
- <?php } ?>
- <div class="linkbox"><?= $Pages ?>
- </div>
- </div>
- <?php View::show_footer();
|