diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index a91a9dc8..7d629dd5 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -86,9 +86,7 @@ class Test extends Command */ public function handle() { - $role = Role::query()->first(); - $r = $role->permissions()->createMany([['permission' => 'sss']]); - dd($r); + } diff --git a/app/Filament/Resources/Torrent/TagResource.php b/app/Filament/Resources/Torrent/TagResource.php index 43f66759..bd008994 100644 --- a/app/Filament/Resources/Torrent/TagResource.php +++ b/app/Filament/Resources/Torrent/TagResource.php @@ -44,7 +44,7 @@ class TagResource extends Resource Forms\Components\TextInput::make('margin')->required()->label(__('label.tag.margin')), Forms\Components\TextInput::make('padding')->required()->label(__('label.tag.padding')), Forms\Components\TextInput::make('border_radius')->required()->label(__('label.tag.border_radius')), - Forms\Components\TextInput::make('priority')->integer()->label(__('label.priority')), + Forms\Components\TextInput::make('priority')->integer()->required()->label(__('label.priority'))->default(0), ]); } diff --git a/app/Filament/Resources/Torrent/TagResource/Pages/CreateTag.php b/app/Filament/Resources/Torrent/TagResource/Pages/CreateTag.php index ff583cc6..e607498e 100644 --- a/app/Filament/Resources/Torrent/TagResource/Pages/CreateTag.php +++ b/app/Filament/Resources/Torrent/TagResource/Pages/CreateTag.php @@ -10,4 +10,8 @@ class CreateTag extends CreateRecord { protected static string $resource = TagResource::class; + protected function getRedirectUrl(): string + { + return $this->getResource()::getUrl('index'); + } } diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php index 692197d9..2fab2971 100644 --- a/app/Models/SearchBox.php +++ b/app/Models/SearchBox.php @@ -9,9 +9,28 @@ class SearchBox extends NexusModel protected $fillable = [ 'name', 'catsperrow', 'catpadding', 'showsubcat', 'showsource', 'showmedium', 'showcodec', 'showstandard', 'showprocessing', 'showteam', 'showaudiocodec', - 'custom_fields', 'custom_fields_display_name', 'custom_fields_display' + 'custom_fields', 'custom_fields_display_name', 'custom_fields_display', 'extra' ]; + protected $casts = [ + 'extra' => 'object' + ]; + + const EXTRA_DISPLAY_COVER_ON_TORRENT_LIST = 'display_cover_on_torrent_list'; + + public static array $extras = [ + self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => ['text' => 'Display cover on torrent list'], + ]; + + public static function listExtraText(): array + { + $result = []; + foreach (self::$extras as $extra => $info) { + $result[$extra] = nexus_trans("searchbox.extras.$extra"); + } + return $result; + } + public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Category::class, 'mode'); diff --git a/app/Repositories/SeedBoxRepository.php b/app/Repositories/SeedBoxRepository.php index ead82f04..a29a8d7f 100644 --- a/app/Repositories/SeedBoxRepository.php +++ b/app/Repositories/SeedBoxRepository.php @@ -130,13 +130,18 @@ class SeedBoxRepository extends BaseRepository }); } - public function renderIcon($ip, $uid): string + public function renderIcon($ipArr, $uid): string { - $result = ''; - if ((isIPV4($ip) || isIPV6($ip)) && get_setting('seed_box.enabled') == 'yes' && isIPSeedBox($ip, $uid)) { - $result = ''; + static $enableSeedBox; + if ($enableSeedBox === null) { + $enableSeedBox = get_setting('seed_box.enabled') == 'yes'; } - return $result; + foreach (Arr::wrap($ipArr) as $ip) { + if ((isIPV4($ip) || isIPV6($ip)) && $enableSeedBox && isIPSeedBox($ip, $uid)) { + return ''; + } + } + return ''; } private function clearCache() diff --git a/database/migrations/2022_09_02_031539_add_extra_to_searchbox_table.php b/database/migrations/2022_09_02_031539_add_extra_to_searchbox_table.php new file mode 100644 index 00000000..7ea19c5d --- /dev/null +++ b/database/migrations/2022_09_02_031539_add_extra_to_searchbox_table.php @@ -0,0 +1,32 @@ +text('extra')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('searchbox', function (Blueprint $table) { + $table->dropColumn('extra'); + }); + } +}; diff --git a/database/seeders/SearchboxTableSeeder.php b/database/seeders/SearchboxTableSeeder.php index 7dc83e23..7ebeff19 100644 --- a/database/seeders/SearchboxTableSeeder.php +++ b/database/seeders/SearchboxTableSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\SearchBox; use Illuminate\Database\Seeder; class SearchboxTableSeeder extends Seeder @@ -14,12 +15,12 @@ class SearchboxTableSeeder extends Seeder */ public function run() { - + \DB::table('searchbox')->delete(); - + \DB::table('searchbox')->insert(array ( - 0 => + 0 => array ( 'id' => 4, 'name' => 'chd', @@ -36,9 +37,12 @@ class SearchboxTableSeeder extends Seeder 'custom_fields' => '', 'custom_fields_display_name' => '', 'custom_fields_display' => '', + 'extra' => json_encode([ + SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => 1, + ]) ), )); - - + + } -} \ No newline at end of file +} diff --git a/include/functions.php b/include/functions.php index 5f64dc26..76759136 100644 --- a/include/functions.php +++ b/include/functions.php @@ -3291,7 +3291,7 @@ function get_torrent_bookmark_state($userid, $torrentid, $text = false) return $act; } -function torrenttable($rows, $variant = "torrent") { +function torrenttable($rows, $variant = "torrent", $searchBoxId = 0) { global $Cache; global $lang_functions; global $CURUSER, $waitsystem; @@ -3302,7 +3302,13 @@ function torrenttable($rows, $variant = "torrent") { $torrent = new Nexus\Torrent\Torrent(); $torrentRep = new \App\Repositories\TorrentRepository(); $imdb = new \Nexus\Imdb\Imdb(); - $torrentIdArr = array_column($rows, 'id'); + $torrentIdArr = $ownerIdArr = []; + foreach($rows as $row) { + $torrentIdArr[] = $row['id']; + $ownerIdArr[] = $row['owner']; + } + unset($row); + $torrentSeedingLeechingStatus = $torrent->listLeechingSeedingStatus($CURUSER['id'], $torrentIdArr); $tagRep = new \App\Repositories\TagRepository(); $tagCollection = $tagRep->createBasicQuery()->get(); @@ -3310,6 +3316,25 @@ function torrenttable($rows, $variant = "torrent") { $torrentTagCollection = \App\Models\TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->orderByRaw("field(tag_id,$tagIdStr)")->get(); $tagKeyById = $tagCollection->keyBy('id'); $torrentTagResult = $torrentTagCollection->groupBy('torrent_id'); + $showCover = false; + if ($searchBoxId) { + $searchBoxExtra = get_searchbox_value($searchBoxId, "extra"); + if (!empty($searchBoxExtra[\App\Models\SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST])) { + $showCover = true; + } + } + //seedBoxIcon + $showSeedBoxIcon = get_setting('seed_box.enabled') == 'yes'; + if ($showSeedBoxIcon) { + $seedBoxRep = new \App\Repositories\SeedBoxRepository(); + $ownerPeerInfo = \App\Models\Peer::query() + ->whereIn('torrent', $torrentIdArr) + ->whereIn('userid', array_unique($ownerIdArr)) + ->where('seeder', 'yes') + ->get(['torrent', 'ipv4', 'ipv6']) + ->keyBy('torrent'); + } + $last_browse = $CURUSER['last_browse']; // if ($variant == "torrent"){ @@ -3489,20 +3514,23 @@ foreach ($rows as $row) $hrImg = get_hr_img($row); //cover - $coverSrc = ''; - if ($imdb_id = parse_imdb_id($row["url"])) { - try { - if ($imdb->getCacheStatus($imdb_id) == 1) { - $coverSrc = $imdb->getMovie($imdb_id)->photo(false); + $coverSrc = $tdCover = ''; + if ($showCover) { + if ($imdb_id = parse_imdb_id($row["url"])) { + try { + if ($imdb->getCacheStatus($imdb_id) == 1) { + $coverSrc = $imdb->getMovie($imdb_id)->photo(false); + } + } catch (\Exception $exception) { + do_log("torrent: {$row['id']} get cover from imdb error: ".$exception->getMessage() . "\n[stacktrace]\n" . $exception->getTraceAsString(), 'error'); } - } catch (\Exception $exception) { - do_log("torrent: {$row['id']} get cover from imdb error: ".$exception->getMessage() . "\n[stacktrace]\n" . $exception->getTraceAsString(), 'error'); } + if (empty($coverSrc) && !empty($row['cover'])) { + $coverSrc = $row['cover']; + } + $tdCover = sprintf('', $coverSrc); } - if (empty($coverSrc) && !empty($row['cover'])) { - $coverSrc = $row['cover']; - } - $tdCover = sprintf('', $coverSrc); + print("$tdCover"); print("
".$stickyicon."".htmlspecialchars($dispname).""); $picked_torrent = ""; if ($CURUSER['appendpicked'] != 'no'){ @@ -3519,7 +3547,13 @@ foreach ($rows as $row) $banned_torrent = ($row["banned"] == 'yes' ? " (".$lang_functions['text_banned'].")" : ""); $sp_torrent_sub = get_torrent_promotion_append_sub($row['sp_state'],"",true,$row['added'], $row['promotion_time_type'], $row['promotion_until'], $row['__ignore_global_sp_state'] ?? false); $approvalStatusIcon = $torrentRep->renderApprovalStatus($row['approval_status']); - $titleSuffix = $banned_torrent.$picked_torrent.$sp_torrent.$sp_torrent_sub. $hrImg . $approvalStatusIcon; + if ($showSeedBoxIcon && $ownerPeerInfo->has($row['id'])) { + $ownerPeer = $ownerPeerInfo->get($row['id']); + $seedBoxIcon = $seedBoxRep->renderIcon([$ownerPeer->ipv4, $ownerPeer->ipv6], $row['owner']); + } else { + $seedBoxIcon = ''; + } + $titleSuffix = $banned_torrent.$picked_torrent.$sp_torrent.$sp_torrent_sub. $hrImg . $seedBoxIcon . $approvalStatusIcon; $titleSuffix = apply_filter('torrent_title_suffix', $titleSuffix, $row); print($titleSuffix); //$tags = torrentTags($row['tags'], 'span'); @@ -4707,6 +4741,9 @@ function get_searchbox_value($mode = 1, $item = 'showsubcat'){ $rows = array(); $res = sql_query("SELECT * FROM searchbox ORDER BY id ASC"); while ($row = mysql_fetch_array($res)) { + if (isset($row['extra'])) { + $row['extra'] = json_decode($row['extra'], true); + } $rows[$row['id']] = $row; } $Cache->cache_value('searchbox_content', $rows, 100500); diff --git a/lang/chs/lang_catmanage.php b/lang/chs/lang_catmanage.php index b7667522..71464b67 100644 --- a/lang/chs/lang_catmanage.php +++ b/lang/chs/lang_catmanage.php @@ -80,6 +80,7 @@ $lang_catmanage = array 'row_custom_field_display_name' => '自定义字段展示名称', 'row_custom_field_display' => '自定义字段展示', 'row_custom_field_display_help' => '使用特殊的标签代表字段的名称和值,如某字段其 Name 为 artist,则它的名称为:<%artist.label%>,它的值为:<%artist.value%>', + 'row_searchbox_extras' => '其他', ); ?> diff --git a/lang/cht/lang_catmanage.php b/lang/cht/lang_catmanage.php index 9c88ada3..141aaf9c 100644 --- a/lang/cht/lang_catmanage.php +++ b/lang/cht/lang_catmanage.php @@ -80,6 +80,7 @@ $lang_catmanage = array 'row_custom_field_display_name' => '自定義字段展示名稱', 'row_custom_field_display' => '自定義字段展示', 'row_custom_field_display_help' => '使用特殊的標簽代表字段的名稱和值,如某字段其 Name 為 artist,則它的名稱為:<%artist.label%>,它的值為:<%artist.value%>', + 'row_searchbox_extras' => '其他', ); ?> diff --git a/lang/en/lang_catmanage.php b/lang/en/lang_catmanage.php index 598edd68..a834ac63 100644 --- a/lang/en/lang_catmanage.php +++ b/lang/en/lang_catmanage.php @@ -80,6 +80,7 @@ $lang_catmanage = array 'row_custom_field_display_name' => 'Custom field display name', 'row_custom_field_display' => 'Custom field display', 'row_custom_field_display_help' => "Use 'specific label' to represent custom field's label and value,such as one custom field's name is 'artist',
then it's label:<%artist.label%>,it's value:<%artist.value%>", + 'row_searchbox_extras' => 'Extras', ); ?> diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index 497faaad..0f454cc7 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -9,6 +9,7 @@ use App\Models\Exam; use App\Models\ExamUser; use App\Models\HitAndRun; use App\Models\Icon; +use App\Models\SearchBox; use App\Models\Setting; use App\Models\Tag; use App\Models\Torrent; @@ -243,8 +244,14 @@ class Update extends Install NexusDB::cache_del('nexus_is_ip_seed_box'); /** - * @since 1.7.23 + * @since 1.7.24 */ + if (!NexusDB::hasColumn('searchbox', 'extra')) { + $this->runMigrate('database/migrations/2022_09_02_031539_add_extra_to_searchbox_table.php'); + SearchBox::query()->update(['extra' => [ + SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => 1, + ]]); + } } diff --git a/public/catmanage.php b/public/catmanage.php index c6bdd483..d0db9a55 100644 --- a/public/catmanage.php +++ b/public/catmanage.php @@ -217,6 +217,9 @@ function print_category_editor($type, $row='') $showaudiocodec = $row['showaudiocodec']; $catsperrow = $row['catsperrow']; $catpadding = $row['catpadding']; + if (!empty($row['extra'])) { + $row['extra'] = json_decode($row['extra'], true); + } } else { @@ -233,6 +236,17 @@ function print_category_editor($type, $row='') } tr($lang_catmanage['row_searchbox_name']."*", " " . $lang_catmanage['text_searchbox_name_note'], 1); tr($lang_catmanage['row_show_sub_category'], " " . $lang_catmanage['text_sources'] . " " . $lang_catmanage['text_media'] . " " . $lang_catmanage['text_codecs'] . " " . $lang_catmanage['text_standards'] . " " . $lang_catmanage['text_processings'] . " " . $lang_catmanage['text_teams'] . " " . $lang_catmanage['text_audio_codecs']."
".$lang_catmanage['text_show_sub_category_note'], 1); + + //extra + $extraCheckbox = ""; + foreach (\App\Models\SearchBox::listExtraText() as $name => $text) { + $extraCheckbox .= sprintf( + '', + $name, !empty($row['extra'][$name]) ? ' checked' : '', $text + ); + } + tr($lang_catmanage['row_searchbox_extras'], $extraCheckbox, 1); + tr($lang_catmanage['row_items_per_row']."*", " " . $lang_catmanage['text_items_per_row_note'], 1); tr($lang_catmanage['row_padding_between_items']."*", " " . $lang_catmanage['text_padding_between_items_note'], 1); $field = new \Nexus\Field\Field(); @@ -715,6 +729,8 @@ elseif($action == 'submit') $updateset[] = "custom_fields=" . sqlesc(implode(',', $_POST['custom_fields'] ?? [])); $updateset[] = "custom_fields_display_name=" . sqlesc($_POST['custom_fields_display_name'] ?? ''); $updateset[] = "custom_fields_display=" . sqlesc($_POST['custom_fields_display'] ?? ''); + $updateset[] = "extra=" . sqlesc(json_encode($_POST['extra'] ?? [])); + if ($showsource || $showmedium || $showcodec || $showstandard || $showprocessing || $showteam || $showaudiocodec) $updateset[] = "showsubcat=1"; else diff --git a/public/details.php b/public/details.php index 0c09e93f..60151f82 100644 --- a/public/details.php +++ b/public/details.php @@ -221,7 +221,13 @@ JS; tr($lang_details['torrent_dl_url'],sprintf('%s',$lang_details['torrent_dl_url_notice'], getSchemeAndHttpHost(), $CURUSER['id'], $torrentRep->encryptDownHash($row['id'], $CURUSER), $lang_details['torrent_dl_url_text']),1); // ---------------- start subtitle block -------------------// - $r = sql_query("SELECT subs.*, language.flagpic, language.lang_name FROM subs LEFT JOIN language ON subs.lang_id=language.id WHERE torrent_id = " . sqlesc($row["id"]). " ORDER BY subs.lang_id ASC") or sqlerr(__FILE__, __LINE__); + $subTorrentIdArr = [$row['id']]; + $otherCopiesIdArr = []; + if ($imdb_id) { + $otherCopiesIdArr = \App\Models\Torrent::query()->where('url', $imdb_id)->where('id', '!=', $row['id'])->pluck('id')->toArray(); + $subTorrentIdArr = array_merge($subTorrentIdArr, $otherCopiesIdArr); + } + $r = sql_query("SELECT subs.*, language.flagpic, language.lang_name FROM subs LEFT JOIN language ON subs.lang_id=language.id WHERE torrent_id in(" . implode(',', $subTorrentIdArr). ") ORDER BY subs.lang_id ASC") or sqlerr(__FILE__, __LINE__); print("
".$lang_details['row_subtitles'].""); print(""); @@ -366,9 +372,10 @@ JS; $ptGen = new \Nexus\PTGen\PTGen(); $ptGen->updateTorrentPtGen($row); } - if ($imdb_id) + if (!empty($otherCopiesIdArr)) { - $where_area = " url = " . sqlesc((int)$imdb_id) ." AND torrents.id != ".sqlesc($id); +// $where_area = " url = " . sqlesc((int)$imdb_id) ." AND torrents.id != ".sqlesc($id); + $where_area = sprintf('torrents.id in (%s)', implode(',', $otherCopiesIdArr)); $copies_res = sql_query("SELECT torrents.id, torrents.name, torrents.sp_state, torrents.size, torrents.added, torrents.seeders, torrents.leechers, torrents.hr,categories.id AS catid, categories.name AS catname, categories.image AS catimage, sources.name AS source_name, media.name AS medium_name, codecs.name AS codec_name, standards.name AS standard_name, processings.name AS processing_name FROM torrents LEFT JOIN categories ON torrents.category=categories.id LEFT JOIN sources ON torrents.source = sources.id LEFT JOIN media ON torrents.medium = media.id LEFT JOIN codecs ON torrents.codec = codecs.id LEFT JOIN standards ON torrents.standard = standards.id LEFT JOIN processings ON torrents.processing = processings.id WHERE " . $where_area . " ORDER BY torrents.id DESC") or sqlerr(__FILE__, __LINE__); $copies_count = mysql_num_rows($copies_res); diff --git a/public/getusertorrentlistajax.php b/public/getusertorrentlistajax.php index b3087439..d0a9adae 100644 --- a/public/getusertorrentlistajax.php +++ b/public/getusertorrentlistajax.php @@ -46,7 +46,7 @@ function maketable($res, $mode = 'seeding') $showuploaded = true; $showdownloaded = true; $showratio = true; - $showsetime = false; + $showsetime = true; $showletime = false; $showcotime = false; $showanonymous = false; diff --git a/public/torrents.php b/public/torrents.php index bb4ec2c5..ace249b1 100644 --- a/public/torrents.php +++ b/public/torrents.php @@ -1187,10 +1187,10 @@ if ($count) { $rows = apply_filter('torrent_list', $rows, $page, $sectiontype); print($pagertop); if ($sectiontype == $browsecatmode) - torrenttable($rows, "torrents"); + torrenttable($rows, "torrents", $sectiontype); elseif ($sectiontype == $specialcatmode) - torrenttable($rows, "music"); - else torrenttable($rows, "bookmarks"); + torrenttable($rows, "music", $sectiontype); + else torrenttable($rows, "bookmarks", $sectiontype); print($pagerbottom); } else { diff --git a/resources/lang/en/searchbox.php b/resources/lang/en/searchbox.php index 8b2711d4..e9c077e6 100644 --- a/resources/lang/en/searchbox.php +++ b/resources/lang/en/searchbox.php @@ -9,4 +9,7 @@ return [ 'sub_category_processing_label' => 'Processing', 'sub_category_codec_label' => 'Codec', 'sub_category_audio_codec_label' => 'AudioCodec', + 'extras' => [ + \App\Models\SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => 'Display cover on torrent list', + ], ]; diff --git a/resources/lang/zh_CN/searchbox.php b/resources/lang/zh_CN/searchbox.php index fa76a25b..114ce9cf 100644 --- a/resources/lang/zh_CN/searchbox.php +++ b/resources/lang/zh_CN/searchbox.php @@ -8,5 +8,8 @@ return [ 'sub_category_team_label' => '制作组', 'sub_category_processing_label' => '处理', 'sub_category_codec_label' => '编码', - 'sub_category_audio_codec_label' => '音频编码', + 'sub_category_audio_codec_label' => '音频编码', + 'extras' => [ + \App\Models\SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => '种子列表页展示封面', + ], ]; diff --git a/resources/lang/zh_TW/searchbox.php b/resources/lang/zh_TW/searchbox.php index 1d2e9a56..9c062526 100644 --- a/resources/lang/zh_TW/searchbox.php +++ b/resources/lang/zh_TW/searchbox.php @@ -9,4 +9,7 @@ return [ 'sub_category_processing_label' => '處理', 'sub_category_codec_label' => '編碼', 'sub_category_audio_codec_label' => '音頻編碼', + 'extras' => [ + \App\Models\SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => '種子列表頁展示封面', + ], ];