change torrent pos_state to varchar, support more sticky level

This commit is contained in:
xiaomlove
2021-06-01 01:28:46 +08:00
parent 8e35dc0886
commit 5760adc0c4
17 changed files with 139 additions and 14 deletions

View File

@@ -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'];

View File

@@ -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 = "<img class=\"sticky\" src=\"pic/trans.gif\" alt=\"Sticky\" title=\"".$lang_functions['title_sticky']."\" />&nbsp;";
else $stickyicon = "";
if ($CURUSER['appendsticky'] == 'yes') {
$posStates = \App\Models\Torrent::listPosStates();
$stickyicon = str_repeat("<img class=\"sticky\" src=\"pic/trans.gif\" alt=\"Sticky\" title=\"".$posStates[$row['pos_state']]['text']."\" />&nbsp;", $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("<td class=\"rowfollow\" width=\"100%\" align=\"left\"><table class=\"torrentname\" width=\"100%\"><tr" . $sphighlight . "><td class=\"embedded\">".$stickyicon."<a $short_torrent_name_alt $mouseovertorrent href=\"details.php?id=".$id."&amp;hit=1\"><b>".htmlspecialchars($dispname)."</b></a>" . $sp_torrent);
$picked_torrent = "";

View File

@@ -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;
}

View File

@@ -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点魔力值",

View File

@@ -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點魔力值",

View File

@@ -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",

View File

@@ -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);
}
}
}
}

View File

@@ -127,7 +127,7 @@ if (!$row) {
else $download = "";
tr($lang_details['row_action'], $download. ($owned == 1 ? "<$editlink><img class=\"dt_edit\" src=\"pic/trans.gif\" alt=\"edit\" />&nbsp;<b><font class=\"small\">".$lang_details['text_edit_torrent'] . "</font></b></a>&nbsp;|&nbsp;" : ""). (get_user_class() >= $askreseed_class && $row['seeders'] == 0 ? "<a title=\"".$lang_details['title_ask_for_reseed']."\" href=\"takereseed.php?reseedid=$id\"><img class=\"dt_reseed\" src=\"pic/trans.gif\" alt=\"reseed\">&nbsp;<b><font class=\"small\">".$lang_details['text_ask_for_reseed'] ."</font></b></a>&nbsp;|&nbsp;" : "") . "<a title=\"".$lang_details['title_report_torrent']."\" href=\"report.php?torrent=$id\"><img class=\"dt_report\" src=\"pic/trans.gif\" alt=\"report\" />&nbsp;<b><font class=\"small\">".$lang_details['text_report_torrent']."</font></b></a>", 1);
tr($lang_details['torrent_dl_url'],sprintf('<b title="%s">%s/download.php?id=%u&passkey=%s</b>',$lang_details['torrent_dl_url_notice'], getSchemeAndHttpHost(),$id,$CURUSER['passkey']), 1);
tr($lang_details['torrent_dl_url'],sprintf('<a title="%s" href="%s/download.php?id=%u&passkey=%s">%s</a>',$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__);

View File

@@ -165,10 +165,11 @@ else {
if ($pickcontent) {
$pickcontent .= "<br />";
}
$pickcontent .= "<b>".$lang_edit['row_torrent_position'].":&nbsp;</b>"."<select name=\"sel_posstate\" style=\"width: 100px;\">" .
"<option" . (($row["pos_state"] == "normal") ? " selected=\"selected\"" : "" ) . " value=\"0\">".$lang_edit['select_normal']."</option>" .
"<option" . (($row["pos_state"] == "sticky") ? " selected=\"selected\"" : "" ) . " value=\"1\">".$lang_edit['select_sticky']."</option>" .
"</select>&nbsp;&nbsp;&nbsp;";
$options = [];
foreach (\App\Models\Torrent::listPosStates() as $key => $value) {
$options[] = "<option" . (($row["pos_state"] == $key) ? " selected=\"selected\"" : "" ) . " value=\"" . $key . "\">".$value['text']."</option>";
}
$pickcontent .= "<b>".$lang_edit['row_torrent_position'].":&nbsp;</b>"."<select name=\"sel_posstate\" style=\"width: 100px;\">" . implode('', $options) . "</select>&nbsp;&nbsp;&nbsp;";
}
if(get_user_class()>=$torrentmanage_class && $CURUSER["picker"] == 'yes')
{

View File

@@ -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 = "";

View File

@@ -0,0 +1,7 @@
<?php
return [
'index' => [
'page_title' => 'Peers',
],
];

View File

@@ -0,0 +1,7 @@
<?php
return [
'index' => [
'page_title' => 'Snatches',
],
];

View File

@@ -0,0 +1,27 @@
<?php
return [
'pos_state_normal' => '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',
]
];

View File

@@ -1,6 +1,10 @@
<?php
return [
'pos_state_normal' => '普通',
'pos_state_sticky' => '一级置顶',
'pos_state_r_sticky' => '二级置顶',
'index' => [
'page_title' => '种子列表',
],

View File

@@ -0,0 +1,7 @@
<?php
return [
'index' => [
'page_title' => '同伴列表',
],
];

View File

@@ -0,0 +1,7 @@
<?php
return [
'index' => [
'page_title' => '完成情況',
],
];

View File

@@ -0,0 +1,27 @@
<?php
return [
'pos_state_normal' => '普通',
'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' => '文件',
]
];