From f675d4e2d445f090041678b1be7de64bb8a160a2 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 20 Sep 2025 17:22:53 +0700 Subject: [PATCH] improve torrents + torrentrss --- app/Filament/Resources/User/UserResource.php | 2 +- app/Models/Torrent.php | 4 +++ app/Repositories/TorrentRepository.php | 30 ++++++++++++++++---- include/constants.php | 2 +- nexus/Imdb/Imdb.php | 2 +- public/torrentrss.php | 11 ++++--- public/torrents.php | 23 ++++++++++----- 7 files changed, 54 insertions(+), 20 deletions(-) diff --git a/app/Filament/Resources/User/UserResource.php b/app/Filament/Resources/User/UserResource.php index fd6493bd..380bacf9 100644 --- a/app/Filament/Resources/User/UserResource.php +++ b/app/Filament/Resources/User/UserResource.php @@ -91,7 +91,7 @@ class UserResource extends Resource Tables\Columns\BadgeColumn::make('downloadpos')->colors(['success' => 'yes', 'danger' => 'no'])->label(__("label.user.downloadpos")), Tables\Columns\BadgeColumn::make('parked')->colors(['success' => 'yes', 'danger' => 'no'])->label(__("label.user.parked")), Tables\Columns\TextColumn::make('added')->sortable()->dateTime('Y-m-d H:i')->label(__("label.added")), - Tables\Columns\TextColumn::make('last_access')->dateTime()->label(__("label.last_access")), + Tables\Columns\TextColumn::make('last_access')->dateTime('Y-m-d H:i')->label(__("label.last_access")), ]) ->defaultSort('added', 'desc') ->filters([ diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index eb276e5e..bfaca0a3 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -21,6 +21,10 @@ class Torrent extends NexusModel const VISIBLE_YES = 'yes'; const VISIBLE_NO = 'no'; + const FILTER_VISIBLE_ALL = '0'; + const FILTER_VISIBLE_YES = '1'; + const FILTER_VISIBLE_NO = '2'; + const BANNED_YES = 'yes'; const BANNED_NO = 'no'; diff --git a/app/Repositories/TorrentRepository.php b/app/Repositories/TorrentRepository.php index 536be15f..604e0e5d 100644 --- a/app/Repositories/TorrentRepository.php +++ b/app/Repositories/TorrentRepository.php @@ -99,7 +99,7 @@ class TorrentRepository extends BaseRepository $allowFilters = [ 'title', 'category', 'source', 'medium', 'codec', 'audiocodec', 'standard', 'processing', 'team', 'owner', 'visible', 'added', 'size', 'sp_state', 'leechers', 'seeders', 'times_completed', - 'bookmark' + 'bookmark', ]; $allowSorts = ['id', 'comments', 'size', 'seeders', 'leechers', 'times_completed']; $apiQueryBuilder = ApiQueryBuilder::for(TorrentResource::NAME, $query, $request) @@ -110,11 +110,21 @@ class TorrentRepository extends BaseRepository ->allowSorts($allowSorts) ->registerCustomFilter('title', function (Builder $query, Request $request) { $title = $request->input(ApiQueryBuilder::PARAM_NAME_FILTER.".title"); + $title = trim(str_replace('.', '', $title)); if ($title) { - $query->where(function (Builder $query) use ($title) { - $query->where('name', 'like', '%' . $title . '%') - ->orWhere('small_descr', 'like', '%' . $title . '%'); - }); + $titleParts = explode(" ", $title); + $keywordCount = 1; + foreach ($titleParts as $titlePart) { + if ($keywordCount > 3) { + break; + } + $titlePart = trim($titlePart); + $query->where(function (Builder $query) use ($titlePart) { + $query->where('name', 'like', '%' . $titlePart . '%') + ->orWhere('small_descr', 'like', '%' . $titlePart . '%'); + }); + $keywordCount++; + } } }) ->registerCustomFilter('bookmark', function (Builder $query, Request $request) use ($user) { @@ -129,9 +139,17 @@ class TorrentRepository extends BaseRepository }); } }) + ->registerCustomFilter('visible', function (Builder $query, Request $request) use ($user) { + $filterVisible = $request->input(ApiQueryBuilder::PARAM_NAME_FILTER.".visible", Torrent::FILTER_VISIBLE_YES); + if ($filterVisible === Torrent::FILTER_VISIBLE_YES) { + $query->where('visible', Torrent::VISIBLE_YES); + } elseif ($filterVisible === Torrent::FILTER_VISIBLE_NO) { + $query->where('visible', Torrent::VISIBLE_NO); + } + }) ; $query = $apiQueryBuilder->build(); - if (!$apiQueryBuilder->hasSort()) { + if (!$apiQueryBuilder->hasSort() || !$apiQueryBuilder->hasSort('id')) { $query->orderBy("id", "DESC"); } $torrents = $query->paginate($this->getPerPageFromRequest($request)); diff --git a/include/constants.php b/include/constants.php index 935046a2..7a29c5e8 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ getCacheStatus($imdbId) != 1) { return ''; } diff --git a/public/torrentrss.php b/public/torrentrss.php index c8ccee2c..ade339cb 100644 --- a/public/torrentrss.php +++ b/public/torrentrss.php @@ -17,7 +17,7 @@ function hex_esc($matches) { } $dllink = false; -$where = "torrents.visible = 'yes'"; +$where = ""; if ($passkey){ $res = sql_query("SELECT id, enabled, parked, passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1"); $user = mysql_fetch_array($res); @@ -96,8 +96,11 @@ if ($approvalStatusNoneVisible == 'no' && !user_can('staffmem', false, $user['id $browseMode = get_setting('main.browsecat'); $onlyBrowseSection = get_setting('main.spsct') != 'yes' || !user_can('view_special_torrent', false, $user['id']); if ($onlyBrowseSection) { - $where .= ($where ? " AND " : "") . "categories.mode = $browseMode"; + $allBrowseCategoryId = \App\Models\SearchBox::listCategoryId($browseMode); + $where .= ($where ? " AND " : "") . sprintf("torrents.category in (%s)", implode(",", $allBrowseCategoryId)); } +//visible +$where .= ($where ? " AND " : "") . "torrents.visible = 'yes'"; //check price if (isset($_GET['paid']) && in_array($_GET['paid'], ['0', '1', '2'], true)) { $paidFilter = $_GET['paid']; @@ -174,12 +177,12 @@ if ($where) { $sort = "id desc"; $fieldStr = "torrents.id, torrents.category, torrents.name, torrents.small_descr, torrent_extras.descr, torrents.info_hash, torrents.size, torrents.added, torrents.anonymous, torrents.owner, categories.name AS category_name"; if (!$noNormalResults) { - $query = "SELECT $fieldStr FROM torrents LEFT JOIN categories ON category = categories.id left join torrent_extras on torrent_extras.torrent_id = torrents.id $normalWhere ORDER BY $sort LIMIT $limit"; + $query = "SELECT $fieldStr FROM torrents LEFT JOIN categories ON torrents.category = categories.id left join torrent_extras on torrent_extras.torrent_id = torrents.id $normalWhere ORDER BY $sort LIMIT $limit"; $normalRows = \Nexus\Database\NexusDB::select($query); } if (!empty($prependIdArr) && $startindex == 0) { $prependIdStr = implode(',', $prependIdArr); - $prependRows = \Nexus\Database\NexusDB::select("SELECT $fieldStr FROM torrents LEFT JOIN categories ON category = categories.id left join torrent_extras on torrent_extras.torrent_id = torrents.id where torrents.id in ($prependIdStr) and $where ORDER BY field(torrents.id, $prependIdStr)"); + $prependRows = \Nexus\Database\NexusDB::select("SELECT $fieldStr FROM torrents LEFT JOIN categories ON torrents.category = categories.id left join torrent_extras on torrent_extras.torrent_id = torrents.id where torrents.id in ($prependIdStr) and $where ORDER BY field(torrents.id, $prependIdStr)"); } $list = []; foreach ($prependRows as $row) { diff --git a/public/torrents.php b/public/torrents.php index 0c71c16f..e8c3f299 100644 --- a/public/torrents.php +++ b/public/torrents.php @@ -116,6 +116,7 @@ $wherestandardina = array(); $whereprocessingina = array(); $whereteamina = array(); $whereaudiocodecina = array(); +$whereothera = []; //----------------- start whether show torrents from all sections---------------------// if ($_GET) $allsec = intval($_GET["allsec"] ?? 0); @@ -161,11 +162,6 @@ elseif ($inclbookmarked == 2) //not bookmarked } // ----------------- end bookmarked ---------------------// -if (!isset($CURUSER) || !user_can('seebanned')) { - $wherea[] = "banned = 'no'"; - $searchParams["banned"] = 'no'; -} - // ----------------- start include dead ---------------------// if (isset($_GET["incldead"])) $include_dead = intval($_GET["incldead"] ?? 0); @@ -192,14 +188,23 @@ if ($include_dead == 0) //all(active,dead) elseif ($include_dead == 1) //active { $addparam .= "incldead=1&"; - $wherea[] = "visible = 'yes'"; +// $wherea[] = "visible = 'yes'"; + $whereothera[] = "visible = 'yes'"; } elseif ($include_dead == 2) //dead { $addparam .= "incldead=2&"; - $wherea[] = "visible = 'no'"; +// $wherea[] = "visible = 'no'"; + $whereothera[] = "visible = 'no'"; } // ----------------- end include dead ---------------------// + +if (!isset($CURUSER) || !user_can('seebanned')) { +// $wherea[] = "banned = 'no'"; + $whereothera[] = "banned = 'no'"; + $searchParams["banned"] = 'no'; +} + $special_state = 0; if ($_GET) $special_state = intval($_GET["spstate"] ?? 0); @@ -907,6 +912,10 @@ $where .= ($where ? " AND " : "") . "team IN(" . $whereteamin . ")"; if ($whereaudiocodecin) $where .= ($where ? " AND " : "") . "audiocodec IN(" . $whereaudiocodecin . ")"; } +//last +if (!empty($whereothera)) { + $where .= ($where ? " AND " : "") . implode(" AND ", $whereothera); +} $tagFilter = ""; $tagId = intval($_REQUEST['tag_id'] ?? 0);