From 5760adc0c433938f0f7c16b6ee0257b379deb674 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Tue, 1 Jun 2021 01:28:46 +0800 Subject: [PATCH] change torrent pos_state to varchar, support more sticky level --- app/Models/Torrent.php | 23 +++++++++++++++++++++++ include/functions.php | 10 ++++++---- include/globalfunctions.php | 1 + lang/chs/lang_details.php | 1 + lang/cht/lang_details.php | 1 + lang/en/lang_details.php | 1 + nexus/Install/Update.php | 12 ++++++++++++ public/details.php | 2 +- public/edit.php | 9 +++++---- public/takeedit.php | 7 ++----- resources/lang/en/peer.php | 7 +++++++ resources/lang/en/snatch.php | 7 +++++++ resources/lang/en/torrent.php | 27 +++++++++++++++++++++++++++ resources/lang/zh_CN/torrent.php | 4 ++++ resources/lang/zh_TW/peer.php | 7 +++++++ resources/lang/zh_TW/snatch.php | 7 +++++++ resources/lang/zh_TW/torrent.php | 27 +++++++++++++++++++++++++++ 17 files changed, 139 insertions(+), 14 deletions(-) create mode 100644 resources/lang/en/peer.php create mode 100644 resources/lang/en/snatch.php create mode 100644 resources/lang/en/torrent.php create mode 100644 resources/lang/zh_TW/peer.php create mode 100644 resources/lang/zh_TW/snatch.php create mode 100644 resources/lang/zh_TW/torrent.php diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index 622ae3e4..8b0788f9 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -27,6 +27,20 @@ class Torrent extends NexusModel 'basic_source', 'basic_standard', 'basic_team', ]; + const POS_STATE_STICKY_NONE = 'normal'; + const POS_STATE_STICKY_ONE = 'sticky'; + /** + * alphabet 'r' is after 'n' and before 's', so it will fit: order by pos_state desc, + * first sticky, then r_sticky, then normal + */ + const POS_STATE_STICKY_SECOND = 'r_sticky'; + + public static $posStates = [ + self::POS_STATE_STICKY_NONE => ['text' => 'Normal', 'icon_counts' => 0], + self::POS_STATE_STICKY_SECOND => ['text' => 'Sticky second level', 'icon_counts' => 1], + self::POS_STATE_STICKY_ONE => ['text' => 'Sticky top level', 'icon_counts' => 2], + ]; + public static function getBasicInfo(): array { $result = []; @@ -36,6 +50,15 @@ class Torrent extends NexusModel return $result; } + public static function listPosStates(): array + { + $result = self::$posStates; + foreach ($result as $key => &$value) { + $value['text'] = nexus_trans('torrent.pos_state_' . $key); + } + return $result; + } + public static function getFieldLabels(): array { $fields = ['comments', 'times_completed', 'peers_count', 'thank_users_count', 'numfiles']; diff --git a/include/functions.php b/include/functions.php index 64cedb2c..6f5091b1 100644 --- a/include/functions.php +++ b/include/functions.php @@ -3225,10 +3225,12 @@ foreach ($rows as $row) if($count_dispname > $max_length_of_torrent_name) $dispname=mb_substr($dispname, 0, $max_length_of_torrent_name-2,"UTF-8") . ".."; - - if ($row['pos_state'] == 'sticky' && $CURUSER['appendsticky'] == 'yes') - $stickyicon = "\"Sticky\" "; - else $stickyicon = ""; + if ($CURUSER['appendsticky'] == 'yes') { + $posStates = \App\Models\Torrent::listPosStates(); + $stickyicon = str_repeat("\"Sticky\" ", $posStates[$row['pos_state']]['icon_counts'] ?? 0); + } else { + $stickyicon = ""; + } $sp_torrent = get_torrent_promotion_append($row['sp_state'],"",true,$row["added"], $row['promotion_time_type'], $row['promotion_until']); print("
".$stickyicon."".htmlspecialchars($dispname)."" . $sp_torrent); $picked_torrent = ""; diff --git a/include/globalfunctions.php b/include/globalfunctions.php index e5cd3d42..58aa6246 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -568,5 +568,6 @@ function nexus_trans($key, $replace = [], $locale = null) $search = array_map(function ($value) {return ":$value";}, array_keys($replace)); $result = str_replace($search, array_values($replace), $result); } + do_log("key: $key, replace: " . nexus_json_encode($replace) . ", locale: $locale, getKey: $getKey, result: $result"); return $result; } diff --git a/lang/chs/lang_details.php b/lang/chs/lang_details.php index 99e27ae4..2849d8e1 100644 --- a/lang/chs/lang_details.php +++ b/lang/chs/lang_details.php @@ -221,6 +221,7 @@ $lang_details = array 'text_users_in_total' => "个用户表示了感谢)", 'torrent_dl_url' => "种子链接", 'torrent_dl_url_notice' => "可在BT客户端使用,请保护好Passkey,谨防泄露。", + 'torrent_dl_url_text' => "右键查看。", 'span_description_have_given' =>'你已经赠送魔力值', 'text_no_magic_added' => "暂无魔力值奖励", 'magic_value_number' => "已赠送Number点魔力值", diff --git a/lang/cht/lang_details.php b/lang/cht/lang_details.php index ba2d203b..b8152a2d 100644 --- a/lang/cht/lang_details.php +++ b/lang/cht/lang_details.php @@ -220,6 +220,7 @@ $lang_details = array 'text_users_in_total' => "個用戶表示了感謝)", 'torrent_dl_url' => "種子連結", 'torrent_dl_url_notice' => "可在BT用戶端使用,請保護好Passkey,謹防洩露。", + 'torrent_dl_url_text' => "右鍵查看。", 'span_description_have_given' =>'你已經贈送魔力值', 'text_no_magic_added' => "暫無魔力值獎勵", 'magic_value_number' => "已贈送Number點魔力值", diff --git a/lang/en/lang_details.php b/lang/en/lang_details.php index 5c6fcdf6..7fd4c486 100644 --- a/lang/en/lang_details.php +++ b/lang/en/lang_details.php @@ -220,6 +220,7 @@ $lang_details = array 'text_users_in_total' => " users in total)", 'torrent_dl_url' => "Torrent URL", 'torrent_dl_url_notice' => "You can copy it to your BT Client. Take care since it contains your passkey.", + 'torrent_dl_url_text' => "Right click to view.", 'span_description_have_given' =>'You have given the magic of the value', 'text_no_magic_added' => "No magic value of the award", 'magic_value_number' => "Number Magic point value has been presented", diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index 98ff1b23..f7c0a915 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -65,11 +65,23 @@ class Update extends Install $this->doLog("[ADD CUSTOM FIELD MENU] insert: " . json_encode($insert) . " to table: $table, id: $id"); } if (WITH_LARAVEL && DB::schema()->hasColumn('categories', 'icon_id')) { + $this->doLog('[INIT CATEGORY ICON_ID]'); $icon = Icon::query()->orderBy('id', 'asc')->first(); if ($icon) { Category::query()->where('icon_id', 0)->update(['icon_id' => $icon->id]); } } + //torrent support sticky second level + if (WITH_LARAVEL) { + $columnType = DB::schema()->getColumnType('torrents', 'pos_state'); + $this->doLog("[TORRENT POS_STATE], column type: $columnType"); + if ($columnType == 'enum') { + $sql = "alter table torrents modify `pos_state` varchar(32) NOT NULL DEFAULT 'normal'"; + $this->doLog("[ALTER TORRENT POS_STATE TYPE TO VARCHAR], $sql"); + sql_query($sql); + } + } + } } diff --git a/public/details.php b/public/details.php index 075001b6..6c492b37 100644 --- a/public/details.php +++ b/public/details.php @@ -127,7 +127,7 @@ if (!$row) { else $download = ""; tr($lang_details['row_action'], $download. ($owned == 1 ? "<$editlink>\"edit\" ".$lang_details['text_edit_torrent'] . " | " : ""). (get_user_class() >= $askreseed_class && $row['seeders'] == 0 ? "\"reseed\" ".$lang_details['text_ask_for_reseed'] ." | " : "") . "\"report\" ".$lang_details['text_report_torrent']."", 1); - tr($lang_details['torrent_dl_url'],sprintf('%s/download.php?id=%u&passkey=%s',$lang_details['torrent_dl_url_notice'], getSchemeAndHttpHost(),$id,$CURUSER['passkey']), 1); + tr($lang_details['torrent_dl_url'],sprintf('%s',$lang_details['torrent_dl_url_notice'],getSchemeAndHttpHost(),$id,$CURUSER['passkey'], $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__); diff --git a/public/edit.php b/public/edit.php index abe76cfd..ae0528a3 100644 --- a/public/edit.php +++ b/public/edit.php @@ -165,10 +165,11 @@ else { if ($pickcontent) { $pickcontent .= "
"; } - $pickcontent .= "".$lang_edit['row_torrent_position'].": "."   "; + $options = []; + foreach (\App\Models\Torrent::listPosStates() as $key => $value) { + $options[] = "".$value['text'].""; + } + $pickcontent .= "".$lang_edit['row_torrent_position'].": "."   "; } if(get_user_class()>=$torrentmanage_class && $CURUSER["picker"] == 'yes') { diff --git a/public/takeedit.php b/public/takeedit.php index a3667b1c..07ddee35 100644 --- a/public/takeedit.php +++ b/public/takeedit.php @@ -147,12 +147,9 @@ if(get_user_class()>=$torrentonpromotion_class) } } } -if(get_user_class()>=$torrentsticky_class) +if(get_user_class()>=$torrentsticky_class && isset($_POST['sel_posstate']) && isset(\App\Models\Torrent::$posStates[$_POST['sel_posstate']])) { - if(intval($_POST["sel_posstate"] ?? 0) == 0) - $updateset[] = "pos_state = 'normal'"; - elseif(intval($_POST["sel_posstate"] ?? 0) == 1) - $updateset[] = "pos_state = 'sticky'"; + $updateset[] = "pos_state = '" . $_POST['sel_posstate'] . "'"; } $pick_info = ""; diff --git a/resources/lang/en/peer.php b/resources/lang/en/peer.php new file mode 100644 index 00000000..f261dc84 --- /dev/null +++ b/resources/lang/en/peer.php @@ -0,0 +1,7 @@ + [ + 'page_title' => 'Peers', + ], +]; diff --git a/resources/lang/en/snatch.php b/resources/lang/en/snatch.php new file mode 100644 index 00000000..59ab447c --- /dev/null +++ b/resources/lang/en/snatch.php @@ -0,0 +1,7 @@ + [ + 'page_title' => 'Snatches', + ], +]; diff --git a/resources/lang/en/torrent.php b/resources/lang/en/torrent.php new file mode 100644 index 00000000..479f7b15 --- /dev/null +++ b/resources/lang/en/torrent.php @@ -0,0 +1,27 @@ + 'Normal', + 'pos_state_sticky' => 'Sticky top level', + 'pos_state_r_sticky' => 'Sticky second level', + + 'index' => [ + 'page_title' => 'Torrent list', + ], + 'show' => [ + 'page_title' => 'Torrent detail', + 'basic_category' => 'Category', + 'basic_audio_codec' => 'Audio codec', + 'basic_codec' => 'Video codec', + 'basic_media' => 'Media', + 'basic_source' => 'Source', + 'basic_standard' => 'Standard', + 'basic_team' => 'Team', + 'size' => 'Size', + 'comments_label' => 'Comments', + 'times_completed_label' => 'Times completed', + 'peers_count_label' => 'Peers', + 'thank_users_count_label' => 'Thank user counts', + 'numfiles_label' => 'Files counts', + ] +]; diff --git a/resources/lang/zh_CN/torrent.php b/resources/lang/zh_CN/torrent.php index f0dc4975..b549fe86 100644 --- a/resources/lang/zh_CN/torrent.php +++ b/resources/lang/zh_CN/torrent.php @@ -1,6 +1,10 @@ '普通', + 'pos_state_sticky' => '一级置顶', + 'pos_state_r_sticky' => '二级置顶', + 'index' => [ 'page_title' => '种子列表', ], diff --git a/resources/lang/zh_TW/peer.php b/resources/lang/zh_TW/peer.php new file mode 100644 index 00000000..5763c557 --- /dev/null +++ b/resources/lang/zh_TW/peer.php @@ -0,0 +1,7 @@ + [ + 'page_title' => '同伴列表', + ], +]; diff --git a/resources/lang/zh_TW/snatch.php b/resources/lang/zh_TW/snatch.php new file mode 100644 index 00000000..4a9c59ff --- /dev/null +++ b/resources/lang/zh_TW/snatch.php @@ -0,0 +1,7 @@ + [ + 'page_title' => '完成情況', + ], +]; diff --git a/resources/lang/zh_TW/torrent.php b/resources/lang/zh_TW/torrent.php new file mode 100644 index 00000000..096d136d --- /dev/null +++ b/resources/lang/zh_TW/torrent.php @@ -0,0 +1,27 @@ + '普通', + 'pos_state_sticky' => '一級置頂', + 'pos_state_r_sticky' => '二級置頂', + + 'index' => [ + 'page_title' => '種子列表', + ], + 'show' => [ + 'page_title' => '種子詳情', + 'basic_category' => '類型', + 'basic_audio_codec' => '音頻編碼', + 'basic_codec' => '視頻編碼', + 'basic_media' => '媒介', + 'basic_source' => '來源', + 'basic_standard' => '分辨率', + 'basic_team' => '製作組', + 'size' => '大小', + 'comments_label' => '評論', + 'times_completed_label' => '完成', + 'peers_count_label' => '同伴', + 'thank_users_count_label' => '謝謝', + 'numfiles_label' => '文件', + ] +];