improve torrents + torrentrss

This commit is contained in:
xiaomlove
2025-09-20 17:22:53 +07:00
parent ee4739fd8b
commit f675d4e2d4
7 changed files with 54 additions and 20 deletions
+1 -1
View File
@@ -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('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\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('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') ->defaultSort('added', 'desc')
->filters([ ->filters([
+4
View File
@@ -21,6 +21,10 @@ class Torrent extends NexusModel
const VISIBLE_YES = 'yes'; const VISIBLE_YES = 'yes';
const VISIBLE_NO = 'no'; 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_YES = 'yes';
const BANNED_NO = 'no'; const BANNED_NO = 'no';
+24 -6
View File
@@ -99,7 +99,7 @@ class TorrentRepository extends BaseRepository
$allowFilters = [ $allowFilters = [
'title', 'category', 'source', 'medium', 'codec', 'audiocodec', 'standard', 'processing', 'team', 'title', 'category', 'source', 'medium', 'codec', 'audiocodec', 'standard', 'processing', 'team',
'owner', 'visible', 'added', 'size', 'sp_state', 'leechers', 'seeders', 'times_completed', 'owner', 'visible', 'added', 'size', 'sp_state', 'leechers', 'seeders', 'times_completed',
'bookmark' 'bookmark',
]; ];
$allowSorts = ['id', 'comments', 'size', 'seeders', 'leechers', 'times_completed']; $allowSorts = ['id', 'comments', 'size', 'seeders', 'leechers', 'times_completed'];
$apiQueryBuilder = ApiQueryBuilder::for(TorrentResource::NAME, $query, $request) $apiQueryBuilder = ApiQueryBuilder::for(TorrentResource::NAME, $query, $request)
@@ -110,11 +110,21 @@ class TorrentRepository extends BaseRepository
->allowSorts($allowSorts) ->allowSorts($allowSorts)
->registerCustomFilter('title', function (Builder $query, Request $request) { ->registerCustomFilter('title', function (Builder $query, Request $request) {
$title = $request->input(ApiQueryBuilder::PARAM_NAME_FILTER.".title"); $title = $request->input(ApiQueryBuilder::PARAM_NAME_FILTER.".title");
$title = trim(str_replace('.', '', $title));
if ($title) { if ($title) {
$query->where(function (Builder $query) use ($title) { $titleParts = explode(" ", $title);
$query->where('name', 'like', '%' . $title . '%') $keywordCount = 1;
->orWhere('small_descr', 'like', '%' . $title . '%'); 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) { ->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(); $query = $apiQueryBuilder->build();
if (!$apiQueryBuilder->hasSort()) { if (!$apiQueryBuilder->hasSort() || !$apiQueryBuilder->hasSort('id')) {
$query->orderBy("id", "DESC"); $query->orderBy("id", "DESC");
} }
$torrents = $query->paginate($this->getPerPageFromRequest($request)); $torrents = $query->paginate($this->getPerPageFromRequest($request));
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.7'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.7');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-09-19'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-09-20');
defined('IN_TRACKER') || define('IN_TRACKER', false); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+1 -1
View File
@@ -312,7 +312,7 @@ class Imdb
if (!$enabled) { if (!$enabled) {
return ''; return '';
} }
return NexusDB::remember("imdb:cover:$imdbId", 3600, function() use($imdbId) { return NexusDB::remember("imdb:cover:$imdbId", 3600, function() use ($imdbId) {
if ($this->getCacheStatus($imdbId) != 1) { if ($this->getCacheStatus($imdbId) != 1) {
return ''; return '';
} }
+7 -4
View File
@@ -17,7 +17,7 @@ function hex_esc($matches) {
} }
$dllink = false; $dllink = false;
$where = "torrents.visible = 'yes'"; $where = "";
if ($passkey){ if ($passkey){
$res = sql_query("SELECT id, enabled, parked, passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1"); $res = sql_query("SELECT id, enabled, parked, passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
$user = mysql_fetch_array($res); $user = mysql_fetch_array($res);
@@ -96,8 +96,11 @@ if ($approvalStatusNoneVisible == 'no' && !user_can('staffmem', false, $user['id
$browseMode = get_setting('main.browsecat'); $browseMode = get_setting('main.browsecat');
$onlyBrowseSection = get_setting('main.spsct') != 'yes' || !user_can('view_special_torrent', false, $user['id']); $onlyBrowseSection = get_setting('main.spsct') != 'yes' || !user_can('view_special_torrent', false, $user['id']);
if ($onlyBrowseSection) { 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 //check price
if (isset($_GET['paid']) && in_array($_GET['paid'], ['0', '1', '2'], true)) { if (isset($_GET['paid']) && in_array($_GET['paid'], ['0', '1', '2'], true)) {
$paidFilter = $_GET['paid']; $paidFilter = $_GET['paid'];
@@ -174,12 +177,12 @@ if ($where) {
$sort = "id desc"; $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"; $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) { 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); $normalRows = \Nexus\Database\NexusDB::select($query);
} }
if (!empty($prependIdArr) && $startindex == 0) { if (!empty($prependIdArr) && $startindex == 0) {
$prependIdStr = implode(',', $prependIdArr); $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 = []; $list = [];
foreach ($prependRows as $row) { foreach ($prependRows as $row) {
+16 -7
View File
@@ -116,6 +116,7 @@ $wherestandardina = array();
$whereprocessingina = array(); $whereprocessingina = array();
$whereteamina = array(); $whereteamina = array();
$whereaudiocodecina = array(); $whereaudiocodecina = array();
$whereothera = [];
//----------------- start whether show torrents from all sections---------------------// //----------------- start whether show torrents from all sections---------------------//
if ($_GET) if ($_GET)
$allsec = intval($_GET["allsec"] ?? 0); $allsec = intval($_GET["allsec"] ?? 0);
@@ -161,11 +162,6 @@ elseif ($inclbookmarked == 2) //not bookmarked
} }
// ----------------- end bookmarked ---------------------// // ----------------- end bookmarked ---------------------//
if (!isset($CURUSER) || !user_can('seebanned')) {
$wherea[] = "banned = 'no'";
$searchParams["banned"] = 'no';
}
// ----------------- start include dead ---------------------// // ----------------- start include dead ---------------------//
if (isset($_GET["incldead"])) if (isset($_GET["incldead"]))
$include_dead = intval($_GET["incldead"] ?? 0); $include_dead = intval($_GET["incldead"] ?? 0);
@@ -192,14 +188,23 @@ if ($include_dead == 0) //all(active,dead)
elseif ($include_dead == 1) //active elseif ($include_dead == 1) //active
{ {
$addparam .= "incldead=1&"; $addparam .= "incldead=1&";
$wherea[] = "visible = 'yes'"; // $wherea[] = "visible = 'yes'";
$whereothera[] = "visible = 'yes'";
} }
elseif ($include_dead == 2) //dead elseif ($include_dead == 2) //dead
{ {
$addparam .= "incldead=2&"; $addparam .= "incldead=2&";
$wherea[] = "visible = 'no'"; // $wherea[] = "visible = 'no'";
$whereothera[] = "visible = 'no'";
} }
// ----------------- end include dead ---------------------// // ----------------- end include dead ---------------------//
if (!isset($CURUSER) || !user_can('seebanned')) {
// $wherea[] = "banned = 'no'";
$whereothera[] = "banned = 'no'";
$searchParams["banned"] = 'no';
}
$special_state = 0; $special_state = 0;
if ($_GET) if ($_GET)
$special_state = intval($_GET["spstate"] ?? 0); $special_state = intval($_GET["spstate"] ?? 0);
@@ -907,6 +912,10 @@ $where .= ($where ? " AND " : "") . "team IN(" . $whereteamin . ")";
if ($whereaudiocodecin) if ($whereaudiocodecin)
$where .= ($where ? " AND " : "") . "audiocodec IN(" . $whereaudiocodecin . ")"; $where .= ($where ? " AND " : "") . "audiocodec IN(" . $whereaudiocodecin . ")";
} }
//last
if (!empty($whereothera)) {
$where .= ($where ? " AND " : "") . implode(" AND ", $whereothera);
}
$tagFilter = ""; $tagFilter = "";
$tagId = intval($_REQUEST['tag_id'] ?? 0); $tagId = intval($_REQUEST['tag_id'] ?? 0);