From c9c16bc5bde8bcadfcadf5a51e085bbfbc35f362 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Wed, 14 Sep 2022 19:05:29 +0800 Subject: [PATCH] finish searchbox build + upload/edit form quality render --- app/Console/Commands/Test.php | 3 +- .../Resources/System/SectionResource.php | 7 +- .../SectionResource/Pages/EditSection.php | 5 + .../CategoriesRelationManager.php | 21 ++-- .../TaxonomyAudioCodecsRelationManager.php | 2 +- .../TaxonomyCodecsRelationManager.php | 2 +- .../TaxonomySourcesRelationManager.php | 16 ++- .../TaxonomyStandardsRelationManager.php | 2 +- .../TaxonomyTeamsRelationManager.php | 2 +- app/Models/SearchBox.php | 32 +++--- app/Repositories/SearchBoxRepository.php | 63 +++++++++-- include/functions.php | 101 ++++++++++++++++-- include/globalfunctions.php | 6 ++ public/edit.php | 16 ++- public/getrss.php | 24 +++-- public/js/ptgen.js | 27 ++++- public/styles/sprites.css | 3 + public/torrents.php | 16 +-- public/upload.php | 19 +++- public/usercp.php | 10 +- resources/lang/zh_CN/label.php | 14 ++- resources/lang/zh_CN/nexus.php | 1 + 22 files changed, 313 insertions(+), 79 deletions(-) diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index a5223644..6167ef95 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -87,7 +87,8 @@ class Test extends Command */ public function handle() { - + $rep = new SearchBoxRepository(); + $rep->migrateToModeRelated(); } diff --git a/app/Filament/Resources/System/SectionResource.php b/app/Filament/Resources/System/SectionResource.php index 62a2c1a1..7a70c2e8 100644 --- a/app/Filament/Resources/System/SectionResource.php +++ b/app/Filament/Resources/System/SectionResource.php @@ -45,7 +45,6 @@ class SectionResource extends Resource { return $form ->schema([ - Forms\Components\TextInput::make('section_name')->label(__('label.search_box.section_name'))->required(), Forms\Components\TextInput::make('name')->label(__('label.search_box.name'))->rules('alpha_dash')->required(), Forms\Components\TextInput::make('catsperrow') ->label(__('label.search_box.catsperrow')) @@ -61,6 +60,10 @@ class SectionResource extends Resource ->required() ->default(3) , + Forms\Components\TextInput::make('section_name') + ->label(__('label.search_box.section_name')) + ->helperText(__('label.search_box.section_name_help')) + , Forms\Components\CheckboxList::make('custom_fields') ->options(TorrentCustomField::getCheckboxOptions()) ->label(__('label.search_box.custom_fields')) @@ -109,8 +112,8 @@ class SectionResource extends Resource return $table ->columns([ Tables\Columns\TextColumn::make('id'), - Tables\Columns\TextColumn::make('section_name')->label(__('label.search_box.section_name')), Tables\Columns\TextColumn::make('name')->label(__('label.search_box.name')), + Tables\Columns\TextColumn::make('section_name')->label(__('label.search_box.section_name')), Tables\Columns\BooleanColumn::make('is_default')->label(__('label.search_box.is_default')), Tables\Columns\BooleanColumn::make('showsubcat')->label(__('label.search_box.showsubcat')), Tables\Columns\BooleanColumn::make('showsource'), diff --git a/app/Filament/Resources/System/SectionResource/Pages/EditSection.php b/app/Filament/Resources/System/SectionResource/Pages/EditSection.php index 6f586813..ceab0684 100644 --- a/app/Filament/Resources/System/SectionResource/Pages/EditSection.php +++ b/app/Filament/Resources/System/SectionResource/Pages/EditSection.php @@ -23,4 +23,9 @@ class EditSection extends EditRecord return SearchBox::formatTaxonomyExtra($data); } + protected function afterSave() + { + clear_search_box_cache($this->record->id); + } + } diff --git a/app/Filament/Resources/System/SectionResource/RelationManagers/CategoriesRelationManager.php b/app/Filament/Resources/System/SectionResource/RelationManagers/CategoriesRelationManager.php index 63813339..acd38859 100644 --- a/app/Filament/Resources/System/SectionResource/RelationManagers/CategoriesRelationManager.php +++ b/app/Filament/Resources/System/SectionResource/RelationManagers/CategoriesRelationManager.php @@ -26,15 +26,16 @@ class CategoriesRelationManager extends RelationManager { return $form ->schema([ - Forms\Components\TextInput::make('name')->required()->label(__('label.search_box.taxonomy.name')), + Forms\Components\TextInput::make('name')->required()->label(__('label.search_box.taxonomy.name'))->required(), Forms\Components\TextInput::make('image') - ->rule('alpha_dash') ->label(__('label.search_box.taxonomy.image')) ->helperText(__('label.search_box.taxonomy.image_help')) + ->required() , Forms\Components\Select::make('icon_id') ->options(Icon::query()->pluck('name', 'id')->toArray()) ->label(__('label.search_box.taxonomy.icon_id')) + ->required() , Forms\Components\TextInput::make('class_name') ->label(__('label.search_box.taxonomy.class_name')) @@ -57,19 +58,27 @@ class CategoriesRelationManager extends RelationManager Tables\Columns\TextColumn::make('icon.name')->label(__('label.search_box.taxonomy.icon_id')), Tables\Columns\TextColumn::make('image')->label(__('label.search_box.taxonomy.image')), Tables\Columns\TextColumn::make('class_name')->label(__('label.search_box.taxonomy.class_name')), + Tables\Columns\TextColumn::make('sort_index')->label(__('label.search_box.taxonomy.sort_index'))->sortable(), ]) + ->defaultSort('sort_index') ->filters([ // ]) ->headerActions([ - Tables\Actions\CreateAction::make(), + Tables\Actions\CreateAction::make()->after(function ($record) { + clear_search_box_cache($record->mode); + }), ]) ->actions([ - Tables\Actions\EditAction::make(), - Tables\Actions\DeleteAction::make(), + Tables\Actions\EditAction::make()->after(function ($record) { + clear_search_box_cache($record->mode); + }), + Tables\Actions\DeleteAction::make()->after(function ($record) { + clear_search_box_cache($record->mode); + }), ]) ->bulkActions([ - Tables\Actions\DeleteBulkAction::make(), + ]); } } diff --git a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyAudioCodecsRelationManager.php b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyAudioCodecsRelationManager.php index 915c8810..a2650cd4 100644 --- a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyAudioCodecsRelationManager.php +++ b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyAudioCodecsRelationManager.php @@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope; class TaxonomyAudioCodecsRelationManager extends TaxonomySourcesRelationManager { - protected static string $relationship = 'taxonomy_audio_codecs'; + protected static string $relationship = 'taxonomy_audiocodec'; protected static ?string $recordTitleAttribute = 'name'; diff --git a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyCodecsRelationManager.php b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyCodecsRelationManager.php index b6ed7ba8..9dd2f7ea 100644 --- a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyCodecsRelationManager.php +++ b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyCodecsRelationManager.php @@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope; class TaxonomyCodecsRelationManager extends TaxonomySourcesRelationManager { - protected static string $relationship = 'taxonomy_codecs'; + protected static string $relationship = 'taxonomy_codec'; protected static ?string $recordTitleAttribute = 'name'; diff --git a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomySourcesRelationManager.php b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomySourcesRelationManager.php index 85a36d41..c862c635 100644 --- a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomySourcesRelationManager.php +++ b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomySourcesRelationManager.php @@ -15,7 +15,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope; class TaxonomySourcesRelationManager extends RelationManager { - protected static string $relationship = 'taxonomy_sources'; + protected static string $relationship = 'taxonomy_source'; protected static ?string $recordTitleAttribute = 'name'; @@ -94,14 +94,20 @@ class TaxonomySourcesRelationManager extends RelationManager // ]) ->headerActions([ - Tables\Actions\CreateAction::make(), + Tables\Actions\CreateAction::make()->after(function ($record) { + clear_search_box_cache($record->mode); + }), ]) ->actions([ - Tables\Actions\EditAction::make(), - Tables\Actions\DeleteAction::make(), + Tables\Actions\EditAction::make()->after(function ($record) { + clear_search_box_cache($record->mode); + }), + Tables\Actions\DeleteAction::make()->after(function ($record) { + clear_search_box_cache($record->mode); + }), ]) ->bulkActions([ - Tables\Actions\DeleteBulkAction::make(), + ]); } diff --git a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyStandardsRelationManager.php b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyStandardsRelationManager.php index 25d950ca..6c1d2adf 100644 --- a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyStandardsRelationManager.php +++ b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyStandardsRelationManager.php @@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope; class TaxonomyStandardsRelationManager extends TaxonomySourcesRelationManager { - protected static string $relationship = 'taxonomy_standards'; + protected static string $relationship = 'taxonomy_standard'; protected static ?string $recordTitleAttribute = 'name'; diff --git a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyTeamsRelationManager.php b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyTeamsRelationManager.php index 71ec7b97..7dbec40a 100644 --- a/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyTeamsRelationManager.php +++ b/app/Filament/Resources/System/SectionResource/RelationManagers/TaxonomyTeamsRelationManager.php @@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope; class TaxonomyTeamsRelationManager extends TaxonomySourcesRelationManager { - protected static string $relationship = 'taxonomy_teams'; + protected static string $relationship = 'taxonomy_team'; protected static ?string $recordTitleAttribute = 'name'; diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php index 40cd1746..57871d39 100644 --- a/app/Models/SearchBox.php +++ b/app/Models/SearchBox.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Support\Str; class SearchBox extends NexusModel { @@ -27,8 +28,8 @@ class SearchBox extends NexusModel const EXTRA_DISPLAY_COVER_ON_TORRENT_LIST = 'display_cover_on_torrent_list'; const EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST = 'display_seed_box_icon_on_torrent_list'; - public static array $subCategories = [ - 'source' => 'surces', + public static array $taxonomies = [ + 'source' => 'sources', 'medium' => 'media', 'codec' => 'codecs', 'audiocodec' => 'audiocodecs', @@ -53,7 +54,7 @@ class SearchBox extends NexusModel public static function formatTaxonomyExtra(array $data): array { - foreach (self::$subCategories as $field => $table) { + foreach (self::$taxonomies as $field => $table) { $data["show{$field}"] = 0; foreach ($data['extra'][self::EXTRA_TAXONOMY_LABELS] ?? [] as $item) { if ($field == $item['torrent_field']) { @@ -65,6 +66,16 @@ class SearchBox extends NexusModel return $data; } + public function getTaxonomyLabel($torrentField) + { + foreach ($this->extra[self::EXTRA_TAXONOMY_LABELS] ?? [] as $item) { + if ($item['torrent_field'] == $torrentField) { + return $item['display_text']; + } + } + return nexus_trans('label.torrent.' . $torrentField) ?: ucfirst($torrentField); + } + protected function customFields(): Attribute { return new Attribute( @@ -75,7 +86,7 @@ class SearchBox extends NexusModel public static function getSubCatOptions(): array { - return array_combine(array_keys(self::$subCategories), array_keys(self::$subCategories)); + return array_combine(array_keys(self::$taxonomies), array_keys(self::$taxonomies)); } public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany @@ -88,7 +99,7 @@ class SearchBox extends NexusModel return $this->hasMany(SearchBoxField::class, 'searchbox_id'); } - public function taxonomy_sources(): \Illuminate\Database\Eloquent\Relations\HasMany + public function taxonomy_source(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Source::class, 'mode'); } @@ -98,22 +109,22 @@ class SearchBox extends NexusModel return $this->hasMany(Media::class, 'mode'); } - public function taxonomy_standards(): \Illuminate\Database\Eloquent\Relations\HasMany + public function taxonomy_standard(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Standard::class, 'mode'); } - public function taxonomy_codecs(): \Illuminate\Database\Eloquent\Relations\HasMany + public function taxonomy_codec(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Codec::class, 'mode'); } - public function taxonomy_audio_codecs(): \Illuminate\Database\Eloquent\Relations\HasMany + public function taxonomy_audiocodec(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(AudioCodec::class, 'mode'); } - public function taxonomy_teams(): \Illuminate\Database\Eloquent\Relations\HasMany + public function taxonomy_team(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Team::class, 'mode'); } @@ -129,7 +140,4 @@ class SearchBox extends NexusModel } - - - } diff --git a/app/Repositories/SearchBoxRepository.php b/app/Repositories/SearchBoxRepository.php index b265e2cf..00119d0e 100644 --- a/app/Repositories/SearchBoxRepository.php +++ b/app/Repositories/SearchBoxRepository.php @@ -7,6 +7,7 @@ use App\Models\NexusModel; use App\Models\SearchBox; use App\Models\SearchBoxField; use App\Models\Setting; +use Elasticsearch\Endpoints\Search; use Illuminate\Support\Arr; use Nexus\Database\NexusDB; @@ -102,13 +103,14 @@ class SearchBoxRepository extends BaseRepository return Icon::query()->find(array_keys($iconIdArr)); } - public static function migrateToModeRelated() + public function migrateToModeRelated() { $secondIconTable = 'secondicons'; $normalId = Setting::get('main.browsecat'); $specialId = Setting::get('main.specialcat'); $searchBoxList = SearchBox::query()->get(); - $tables = array_values(SearchBox::$subCategories); + $tables = array_values(SearchBox::$taxonomies); + foreach ($searchBoxList as $searchBox) { if ($searchBox->id == $normalId) { //all sub categories add `mode` field @@ -129,17 +131,56 @@ class SearchBoxRepository extends BaseRepository NexusDB::statement($sql); do_log("copy table $table, $sql"); } - $fields = array_keys(SearchBox::$subCategories); - $fields = array_merge($fields, ['name', 'class_name', 'image']); - $fieldStr = implode(', ', $fields); - $sql = sprintf( - "insert into `%s` (%s, mode) select %s, '%s' from `%s`", - $secondIconTable, $fieldStr, $fieldStr, $specialId, $secondIconTable - ); - NexusDB::statement($sql); - do_log("copy table $secondIconTable, $sql"); +// $fields = array_keys(SearchBox::$taxonomies); +// $fields = array_merge($fields, ['name', 'class_name', 'image']); +// $fieldStr = implode(', ', $fields); +// $sql = sprintf( +// "insert into `%s` (%s, mode) select %s, '%s' from `%s`", +// $secondIconTable, $fieldStr, $fieldStr, $specialId, $secondIconTable +// ); +// NexusDB::statement($sql); +// do_log("copy table $secondIconTable, $sql"); } + $taxonomies = []; + foreach (SearchBox::$taxonomies as $field => $taxonomyTable) { + $showField = "show" . $field; + if ($searchBox->{$showField}) { + $taxonomies[] = [ + 'torrent_field' => $field, + 'display_text' => $field, + ]; + } + } + $searchBox->update(["extra->" . SearchBox::EXTRA_TAXONOMY_LABELS => $taxonomies]); } } + public function renderQualitySelect($searchBox, array $torrentInfo = []): string + { + if (!$searchBox instanceof SearchBox) { + $searchBox = SearchBox::query()->findOrFail(intval($searchBox)); + } + $results = []; + foreach (SearchBox::$taxonomies as $torrentField => $table) { + $searchBoxField = "show" . $torrentField; + if ($searchBox->{$searchBoxField}) { + $select = sprintf("%s:", $searchBox->getTaxonomyLabel($torrentField)); + $select .= sprintf(''; + $results[] = $select; + } + } + return implode('  ', $results); + } + } diff --git a/include/functions.php b/include/functions.php index 1858044e..74d6900b 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2181,7 +2181,7 @@ function tr($x,$y,$noesc=0,$relation='', $return = false) { // $result = ("$x".$a."\n"); $result = sprintf( '%s%s', - $relation ? sprintf(' relation="%s"', $relation) : '', + $relation ? sprintf(' relation="%s" class="%s"', $relation, $relation) : '', $x, $a ); if ($return) { @@ -2291,15 +2291,17 @@ function menu ($selected = "home") { if ($menu) { print $menu; } else { + $normalSectionName = get_searchbox_value(get_setting('main.browsecat'), 'section_name'); + $specialSectionName = get_searchbox_value(get_setting('main.specialcat'), 'section_name'); print ("
    "); print ("" . $lang_functions['text_home'] . ""); if ($enableextforum != 'yes') print ("".$lang_functions['text_forums'].""); else print ("".$lang_functions['text_forums'].""); - print ("".$lang_functions['text_torrents'].""); + print ("".($normalSectionName ?: $lang_functions['text_torrents']).""); if ($enablespecial == 'yes' && user_can('view_special_torrent')) - print ("".$lang_functions['text_special'].""); + print ("".($specialSectionName ?: $lang_functions['text_special']).""); if ($enableoffer == 'yes') print ("".$lang_functions['text_offers'].""); if ($enablerequest == 'yes') @@ -3213,14 +3215,15 @@ function genrelist($catmode = 1) { return $ret; } -function searchbox_item_list($table = "sources"){ +function searchbox_item_list($table, $mode){ global $Cache; - if (!$ret = $Cache->get_value($table.'_list')){ + $cacheKey = "{$table}_list_mode_{$mode}"; + if (!$ret = $Cache->get_value($cacheKey)){ $ret = array(); - $res = sql_query("SELECT * FROM ".$table." ORDER BY sort_index, id"); + $res = sql_query("SELECT * FROM $table where mode = '$mode' ORDER BY sort_index, id"); while ($row = mysql_fetch_array($res)) $ret[] = $row; - $Cache->cache_value($table.'_list', $ret, 152800); + $Cache->cache_value($cacheKey, $ret, 152800); } return $ret; } @@ -4750,7 +4753,8 @@ function get_plain_username($id){ function get_searchbox_value($mode = 1, $item = 'showsubcat'){ global $Cache; static $rows; - if (!$rows && !$rows = $Cache->get_value('searchbox_content')){ + $cacheKey = "search_box_content_{$mode}"; + if (!$rows && !$rows = $Cache->get_value($cacheKey)){ $rows = array(); $res = sql_query("SELECT * FROM searchbox ORDER BY id ASC"); while ($row = mysql_fetch_array($res)) { @@ -4759,7 +4763,7 @@ function get_searchbox_value($mode = 1, $item = 'showsubcat'){ } $rows[$row['id']] = $row; } - $Cache->cache_value('searchbox_content', $rows, 100500); + $Cache->cache_value($cacheKey, $rows, 100500); } return $rows[$mode][$item] ?? ''; } @@ -4864,11 +4868,11 @@ function user_can_upload($where = "torrents"){ return false; } -function torrent_selection($name,$selname,$listname,$selectedid = 0) +function torrent_selection($name,$selname,$listname,$selectedid = 0, $mode = 0) { global $lang_functions; $selection = "".$name."    \n"; @@ -5872,4 +5876,79 @@ function calculate_harem_addition($uid) return $addition; } + +function build_search_box_category_table($mode, $checkboxValue, $categoryHrefPrefix, $taxonomyHrefPrefix, $taxonomyNameLength, $checkedValues = '') +{ + $searchBox = \App\Models\SearchBox::query()->with(['categories', 'categories.icon'])->findOrFail($mode); + $withTaxonomies = []; + foreach (\App\Models\SearchBox::$taxonomies as $torrentField => $taxonomyTable) { + $showField = "show" . $torrentField; + if ($searchBox->{$showField}) { + $withTaxonomies[] = "taxonomy_{$torrentField}"; + } + } + $searchBox->load($withTaxonomies); + + $html = ''; + $html .= sprintf('', $searchBox->section_name); + //Category + $html .= sprintf('', nexus_trans('label.search_box.category')); + $categoryChunks = $searchBox->categories->chunk($searchBox->catsperrow); + $lang = get_langfolder_cookie(); + foreach ($categoryChunks as $chunk) { + $html .= ''; + foreach ($chunk as $item) { + $checked = ''; + if (str_contains($checkedValues, "[cat{$item->id}]")) { + $checked = " checked"; + } + $icon = $item->icon; + $backgroundImagePath = sprintf('pic/category/%s/%s/%s%s', $searchBox->name, trim($icon->folder, '/'), $icon->multilang == 'yes' ? "$lang/" : "", $item->image); + $td = << +TD; + $html .= $td; + } + $html .= ''; + } + //Taxonomy + foreach ($withTaxonomies as $relation) { + $torrentField = str_replace("taxonomy_", '', $relation); + if ($taxonomyNameLength > 0) { + $namePrefix = substr($torrentField, 0, $taxonomyNameLength); + } else { + $namePrefix = $torrentField; + } + $html .= sprintf('', $searchBox->getTaxonomyLabel($torrentField)); + $taxonomyChunks = $searchBox->{$relation}->chunk($searchBox->catsperrow); + foreach ($taxonomyChunks as $chunk) { + $html .= ''; + foreach ($chunk as $item) { + if ($taxonomyHrefPrefix) { + $afterInput = sprintf('%s', $taxonomyHrefPrefix, $namePrefix, $item->id, $item->name); + } else { + $afterInput = $item->name; + } + $checked = ''; + if (str_contains($checkedValues, "[{$namePrefix}{$item->id}]")) { + $checked = ' checked'; + } + $td = << +TD; + $html .= $td; + } + $html .= ''; + } + $html .= ''; + } + $html .= '
    %s
    %s
    + + {$item->name} +
    %s
    + +
    '; + return $html; +} + ?> diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 242256f7..52700dfd 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -983,6 +983,12 @@ function clear_staff_message_cache() \App\Repositories\MessageRepository::updateStaffMessageCountCache(false); } +function clear_search_box_cache($id) +{ + do_log("clear_search_box_cache: $id"); + \Nexus\Database\NexusDB::cache_del("search_box_content_{$id}"); +} + function user_can($permission, $fail = false, $uid = 0): bool { $log = "permission: $permission, fail: $fail, user: $uid"; diff --git a/public/edit.php b/public/edit.php index ae6720c1..adf57b6b 100644 --- a/public/edit.php +++ b/public/edit.php @@ -19,7 +19,7 @@ if (!$row) die(); $customField = new \Nexus\Field\Field(); $tagIdArr = \App\Models\TorrentTag::query()->where('torrent_id', $id)->get()->pluck('tag_id')->toArray(); - +$searchBoxRep = new \App\Repositories\SearchBoxRepository(); if ($enablespecial == 'yes' && user_can('movetorrent')) $allowmove = true; //enable moving torrent to other section else $allowmove = false; @@ -35,7 +35,7 @@ else $othermode = $browsecatmode; $movenote = $lang_edit['text_move_to_browse']; } - +/* $showsource = (get_searchbox_value($sectionmode, 'showsource') || ($allowmove && get_searchbox_value($othermode, 'showsource'))); //whether show sources or not $showmedium = (get_searchbox_value($sectionmode, 'showmedium') || ($allowmove && get_searchbox_value($othermode, 'showmedium'))); //whether show media or not $showcodec = (get_searchbox_value($sectionmode, 'showcodec') || ($allowmove && get_searchbox_value($othermode, 'showcodec'))); //whether show codecs or not @@ -43,6 +43,7 @@ $showstandard = (get_searchbox_value($sectionmode, 'showstandard') || ($allowmov $showprocessing = (get_searchbox_value($sectionmode, 'showprocessing') || ($allowmove && get_searchbox_value($othermode, 'showprocessing'))); //whether show processings or not $showteam = (get_searchbox_value($sectionmode, 'showteam') || ($allowmove && get_searchbox_value($othermode, 'showteam'))); //whether show teams or not $showaudiocodec = (get_searchbox_value($sectionmode, 'showaudiocodec') || ($allowmove && get_searchbox_value($othermode, 'showaudiocodec'))); //whether show audio codecs or not +*/ $settingMain = get_setting('main'); stdhead($lang_edit['head_edit_torrent'] . "\"". $row["name"] . "\""); @@ -105,6 +106,7 @@ else { $movecheckbox = ""; } tr($lang_edit['row_type']."*", $s.($allowmove ? "  ".$movecheckbox.$movenote.$s2 : ""), 1); +/* if ($showsource || $showmedium || $showcodec || $showaudiocodec || $showstandard || $showprocessing){ if ($showsource){ $source_select = torrent_selection($lang_edit['text_source'],"source_sel","sources",$row["source"]); @@ -147,6 +149,16 @@ else { tr($lang_edit['row_content'],$team_select,1); } +*/ + + $sectionCurrent = $searchBoxRep->renderQualitySelect($sectionmode); + tr($lang_edit['row_quality'], $sectionCurrent, 1, "hide mode mode_$sectionmode"); + + if ($allowmove && $othermode) { + $selectOther = $searchBoxRep->renderQualitySelect($othermode); + tr($lang_edit['row_quality'], $selectOther, 1, "hide mode mode_$othermode"); + } + tr($lang_functions['text_tags'], (new \App\Repositories\TagRepository())->renderCheckbox($tagIdArr), 1); $rowChecks = []; diff --git a/public/getrss.php b/public/getrss.php index c76f095e..18b83fb6 100644 --- a/public/getrss.php +++ b/public/getrss.php @@ -6,7 +6,7 @@ loggedinorreturn(); $brsectiontype = $browsecatmode; $spsectiontype = $specialcatmode; -if ($enablespecial == 'yes' && get_user_class() >= get_setting('authority.view_special_torrent')) +if ($enablespecial == 'yes' && user_can('view_special_torrent')) $allowspecial = true; else $allowspecial = false; $showsubcat = (get_searchbox_value($brsectiontype, 'showsubcat') || ($allowspecial && get_searchbox_value($spsectiontype, 'showsubcat'))); @@ -29,13 +29,13 @@ $brcats = genrelist($brsectiontype); $spcats = genrelist($spsectiontype); if ($showsubcat){ -if ($showsource) $sources = searchbox_item_list("sources"); -if ($showmedium) $media = searchbox_item_list("media"); -if ($showcodec) $codecs = searchbox_item_list("codecs"); -if ($showstandard) $standards = searchbox_item_list("standards"); -if ($showprocessing) $processings = searchbox_item_list("processings"); -if ($showteam) $teams = searchbox_item_list("teams"); -if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs"); +if ($showsource) $sources = searchbox_item_list("sources", $brsectiontype); +if ($showmedium) $media = searchbox_item_list("media", $brsectiontype); +if ($showcodec) $codecs = searchbox_item_list("codecs", $brsectiontype); +if ($showstandard) $standards = searchbox_item_list("standards", $brsectiontype); +if ($showprocessing) $processings = searchbox_item_list("processings", $brsectiontype); +if ($showteam) $teams = searchbox_item_list("teams", $brsectiontype); +if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs", $brsectiontype); } stdhead($lang_getrss['head_rss_feeds']); $query = []; @@ -177,6 +177,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { stdfoot(); die(); } + ?>

    @@ -186,6 +187,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { ".$lang_getrss['text_category'].""; $i = 0; foreach ($brcats as $cat)//print category list of Torrents section @@ -296,7 +298,13 @@ if ($allowspecial) //print category list of Special section } } $categories .= ""; +*/ + +$categories = build_search_box_category_table($browsecatmode, 'yes', 'torrents.php?allsec=1', false, 3); print($categories); +print '
    '; +$categoriesSpecial = build_search_box_category_table($specialcatmode, 'yes', 'torrents.php?allsec=1', false, 3); +print($categoriesSpecial); ?> diff --git a/public/js/ptgen.js b/public/js/ptgen.js index 8dba6876..99d57a71 100644 --- a/public/js/ptgen.js +++ b/public/js/ptgen.js @@ -28,7 +28,7 @@ jQuery('.btn-get-pt-gen').on('click', function () { }, 'json') }) - +//auto fill quality function autoSelect(value) { // console.log(`autoSelect: ${value}`) value = value.replace(/[-\/\.]+/ig, '').toUpperCase(); @@ -36,6 +36,10 @@ function autoSelect(value) { for (let i = 0; i < names.length; i++) { const name = names[i]; const select = jQuery("select[name="+name+"]") + if (select.prop('disabled')) { + console.log("name: " + name + " is disabled, skip") + continue + } // console.log("check name: " + name) select.children("option").each(function (index, option) { let _option = jQuery(option) @@ -71,3 +75,24 @@ jQuery("#compose").on("click", ".nexus-action-btn",function () { } } }) + +//change section +function showHideQuality(activeSelect) { + let mode = activeSelect.getAttribute("data-mode") + let value = activeSelect.value + console.log(mode, value) + if (value == 0) { + //enable all section + jQuery("select[name=type]").prop("disabled", false); + //disable all quality tr + jQuery("tr.mode").hide().find("select").prop("disabled", true); + } else { + jQuery("select[name=type]").prop("disabled", true); + activeSelect.disabled = false + //active current section quality tr + jQuery("tr.mode_" + mode).show().find("select").prop("disabled", false); + } +} +jQuery("#compose").on("change", "select[name=type]", function () { + showHideQuality(this) +}); diff --git a/public/styles/sprites.css b/public/styles/sprites.css index e975e89a..0c51de22 100644 --- a/public/styles/sprites.css +++ b/public/styles/sprites.css @@ -530,3 +530,6 @@ img.hitandrun { background-position: 100% 0; } } +.hide { + display: none; +} diff --git a/public/torrents.php b/public/torrents.php index ace249b1..32377e3d 100644 --- a/public/torrents.php +++ b/public/torrents.php @@ -23,7 +23,7 @@ switch (nexus()->getScript()) { if (get_setting('main.spsct') != 'yes') { httperr(); } - if (get_user_class() < get_setting('authority.view_special_torrent')) { + if (!user_can('view_special_torrent')) { stderr($lang_special['std_sorry'],$lang_special['std_permission_denied_only'].get_user_class_name(get_setting('authority.view_special_torrent'),false,true,true).$lang_special['std_or_above_can_view'],false); } $sectiontype = $specialcatmode; @@ -44,13 +44,13 @@ $catpadding = get_searchbox_value($sectiontype, 'catpadding'); //padding space b $cats = genrelist($sectiontype); if ($showsubcat){ - if ($showsource) $sources = searchbox_item_list("sources"); - if ($showmedium) $media = searchbox_item_list("media"); - if ($showcodec) $codecs = searchbox_item_list("codecs"); - if ($showstandard) $standards = searchbox_item_list("standards"); - if ($showprocessing) $processings = searchbox_item_list("processings"); - if ($showteam) $teams = searchbox_item_list("teams"); - if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs"); + if ($showsource) $sources = searchbox_item_list("sources", $sectiontype); + if ($showmedium) $media = searchbox_item_list("media", $sectiontype); + if ($showcodec) $codecs = searchbox_item_list("codecs", $sectiontype); + if ($showstandard) $standards = searchbox_item_list("standards", $sectiontype); + if ($showprocessing) $processings = searchbox_item_list("processings", $sectiontype); + if ($showteam) $teams = searchbox_item_list("teams", $sectiontype); + if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs", $sectiontype); } $searchstr_ori = htmlspecialchars(trim($_GET["search"] ?? '')); diff --git a/public/upload.php b/public/upload.php index ba97179f..54a36406 100644 --- a/public/upload.php +++ b/public/upload.php @@ -23,6 +23,7 @@ $allowtwosec = ($allowtorrents && $allowspecial); $brsectiontype = $browsecatmode; $spsectiontype = $specialcatmode; +/* $showsource = (($allowtorrents && get_searchbox_value($brsectiontype, 'showsource')) || ($allowspecial && get_searchbox_value($spsectiontype, 'showsource'))); //whether show sources or not $showmedium = (($allowtorrents && get_searchbox_value($brsectiontype, 'showmedium')) || ($allowspecial && get_searchbox_value($spsectiontype, 'showmedium'))); //whether show media or not $showcodec = (($allowtorrents && get_searchbox_value($brsectiontype, 'showcodec')) || ($allowspecial && get_searchbox_value($spsectiontype, 'showcodec'))); //whether show codecs or not @@ -30,9 +31,10 @@ $showstandard = (($allowtorrents && get_searchbox_value($brsectiontype, 'showsta $showprocessing = (($allowtorrents && get_searchbox_value($brsectiontype, 'showprocessing')) || ($allowspecial && get_searchbox_value($spsectiontype, 'showprocessing'))); //whether show processings or not $showteam = (($allowtorrents && get_searchbox_value($brsectiontype, 'showteam')) || ($allowspecial && get_searchbox_value($spsectiontype, 'showteam'))); //whether show teams or not $showaudiocodec = (($allowtorrents && get_searchbox_value($brsectiontype, 'showaudiocodec')) || ($allowspecial && get_searchbox_value($spsectiontype, 'showaudiocodec'))); //whether show languages or not - +*/ $settingMain = get_setting('main'); $torrentRep = new \App\Repositories\TorrentRepository(); +$searchBoxRep = new \App\Repositories\SearchBoxRepository(); stdhead($lang_upload['head_upload']); ?> @@ -84,7 +86,7 @@ stdhead($lang_upload['head_upload']); if ($allowtorrents){ $disablespecial = " onchange=\"disableother('browsecat','specialcat')\""; - $s = "\n\n"; $cats = genrelist($browsecatmode); foreach ($cats as $row) $s .= "\n"; @@ -93,7 +95,7 @@ stdhead($lang_upload['head_upload']); else $s = ""; if ($allowspecial){ $disablebrowse = " onchange=\"disableother('specialcat','browsecat')\""; - $s2 = "\n\n"; $cats2 = genrelist($specialcatmode); foreach ($cats2 as $row) $s2 .= "\n"; @@ -101,7 +103,7 @@ stdhead($lang_upload['head_upload']); } else $s2 = ""; tr($lang_upload['row_type']."*", ($allowtwosec ? $lang_upload['text_to_browse_section'] : "").$s.($allowtwosec ? $lang_upload['text_to_special_section'] : "").$s2.($allowtwosec ? $lang_upload['text_type_note'] : ""),1); - +/* if ($showsource || $showmedium || $showcodec || $showaudiocodec || $showstandard || $showprocessing){ if ($showsource){ $source_select = torrent_selection($lang_upload['text_source'],"source_sel","sources"); @@ -144,6 +146,15 @@ stdhead($lang_upload['head_upload']); tr($lang_upload['row_content'],$team_select,1); } +*/ + if ($allowtorrents) { + $selectNormal = $searchBoxRep->renderQualitySelect($browsecatmode); + tr($lang_upload['row_quality'], $selectNormal, 1, "hide mode mode_$browsecatmode"); + } + if ($allowspecial) { + $selectNormal = $searchBoxRep->renderQualitySelect($specialcatmode); + tr($lang_upload['row_quality'], $selectNormal, 1, "hide mode mode_$specialcatmode"); + } //==== offer dropdown for offer mod from code by S4NE $offerres = sql_query("SELECT id, name FROM offers WHERE userid = ".sqlesc($CURUSER['id'])." AND allowed = 'allowed' ORDER BY name ASC") or sqlerr(__FILE__, __LINE__); diff --git a/public/usercp.php b/public/usercp.php index 813120da..22a9c79c 100644 --- a/public/usercp.php +++ b/public/usercp.php @@ -367,6 +367,7 @@ $spsectiontype = $specialcatmode; if ($enablespecial == 'yes' && get_user_class() >= get_setting('authority.view_special_torrent')) $allowspecial = true; else $allowspecial = false; +/* $showsubcat = (get_searchbox_value($brsectiontype, 'showsubcat') || ($allowspecial && get_searchbox_value($spsectiontype, 'showsubcat'))); $showsource = (get_searchbox_value($brsectiontype, 'showsource') || ($allowspecial && get_searchbox_value($spsectiontype, 'showsource'))); //whether show sources or not $showmedium = (get_searchbox_value($brsectiontype, 'showmedium') || ($allowspecial && get_searchbox_value($spsectiontype, 'showmedium'))); //whether show media or not @@ -395,6 +396,7 @@ if ($showprocessing) $processings = searchbox_item_list("processings"); if ($showteam) $teams = searchbox_item_list("teams"); if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs"); } +*/ print (""); form ("tracker"); if ($type == 'saved') @@ -403,6 +405,7 @@ if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs"); tr_small($lang_usercp['row_email_notification'], " ".$lang_usercp['checkbox_notification_received_pm']."
    \n ".$lang_usercp['checkbox_notification_default_categories'], 1); //no this option $brenablecatrow = false; +/* $categories = "
    ".($allowspecial ? "
    ".$lang_usercp['text_at_browse_page']."
    " : "").""; $i = 0; foreach ($brcats as $cat)//print category list of Torrents section @@ -536,7 +539,12 @@ if ($showaudiocodec) $audiocodecs = searchbox_item_list("audiocodecs"); $categories .= ""; $categories .= "
    ".($brenablecatrow == true ? $brcatrow[0] : $lang_usercp['text_category'])."
    ".$lang_usercp['text_show_dead_active']."
    ".$lang_usercp['text_show_special_torrents']."
    ".$lang_usercp['text_show_bookmarked']."
    "; - tr_small($lang_usercp['row_browse_default_categories'],$categories,1); +*/ + $categories = build_search_box_category_table($browsecatmode, 'yes','torrents.php?allsec=1', false, 3, $CURUSER['notifs']); + $delimiter = '
    '; + $categoriesSpecial = build_search_box_category_table($specialcatmode, 'yes','torrents.php?allsec=1', false, 3, $CURUSER['notifs']); + $extra = "
    {$lang_usercp['text_additional_selection']}
    ".$lang_usercp['text_show_dead_active']."
    ".$lang_usercp['text_show_special_torrents']."
    ".$lang_usercp['text_show_bookmarked']."
    "; + tr_small($lang_usercp['row_browse_default_categories'],$categories . $delimiter . $categoriesSpecial . $delimiter . $extra,1); $ss_r = sql_query("SELECT * FROM stylesheets") or die; $ss_sa = array(); while ($ss_a = mysql_fetch_array($ss_r)) diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index 08b0a17c..6d9b96f6 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -147,6 +147,13 @@ return [ 'pos_state' => '置顶', 'sp_state' => '优惠', 'visible' => '活种', + 'source' => '来源', + 'codec' => '编码', + 'audiocodec' => '音频编码', + 'medium' => '媒介', + 'team' => '制作组', + 'processing' => '处理', + 'standard' => '分辨率', ], 'hit_and_run' => [ 'label' => '用户 H&R', @@ -231,8 +238,9 @@ return [ ], 'search_box' => [ 'label' => '分区', - 'name' => '别名', - 'section_name' => '名称', + 'name' => '名称', + 'section_name' => '分区名称', + 'section_name_help' => '若设置,显示在菜单上', 'is_default' => '是否默认', 'showsubcat' => '次分类', 'taxonomies' => '分类法', @@ -246,7 +254,7 @@ return [ 'custom_fields_display_name' => '自定义字段展示名称', 'custom_fields_display' => '自定义字段展示', 'custom_fields_display_help' => '使用特殊的标签代表字段的名称和值,如某字段其 Name 为 artist,则它的名称为:<%artist.label%>,它的值为:<%artist.value%>', - 'category' => '主分类', + 'category' => '分类', 'torrent_field_duplicate' => '种子表字段::field 不能重复使用!', 'taxonomy' => [ 'name' => '名称', diff --git a/resources/lang/zh_CN/nexus.php b/resources/lang/zh_CN/nexus.php index f3e30b88..e142c245 100644 --- a/resources/lang/zh_CN/nexus.php +++ b/resources/lang/zh_CN/nexus.php @@ -2,4 +2,5 @@ return [ 'invalid_argument' => '参数错误', + 'select_one_please' => '请选择', ];