mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
feat: enhance torrent state scheduling and display
Signed-off-by: Qi HU <github@spcsky.com>
This commit is contained in:
+27
-8
@@ -2823,15 +2823,34 @@ print '<br/>';
|
||||
}
|
||||
if ($msgalert)
|
||||
{
|
||||
$spStateGlobal = get_global_sp_state();
|
||||
if ($spStateGlobal != \App\Models\Torrent::PROMOTION_NORMAL) {
|
||||
$torrentGlobalStateRow = \Nexus\Database\NexusDB::cache_get(\App\Models\Setting::TORRENT_GLOBAL_STATE_CACHE_KEY);
|
||||
$msg = sprintf($lang_functions['full_site_promotion_in_effect'], \App\Models\Torrent::$promotionTypes[$spStateGlobal]['text']);
|
||||
if (!empty($torrentGlobalStateRow['begin']) || !empty($torrentGlobalStateRow['deadline'])) {
|
||||
$timeRange = sprintf($lang_functions['full_site_promotion_time_range'], $torrentGlobalStateRow['begin'] ?? '-∞', $torrentGlobalStateRow['deadline'] ?? '∞');
|
||||
$msg .= $timeRange;
|
||||
$timeline = \App\Models\TorrentState::resolveTimeline();
|
||||
$currentPromotion = $timeline['current'] ?? null;
|
||||
$upcomingPromotion = $timeline['upcoming'] ?? null;
|
||||
$remarkTpl = $lang_functions['full_site_promotion_remark'] ?? 'Remark: %s';
|
||||
|
||||
if ($currentPromotion) {
|
||||
$promotionText = \App\Models\Torrent::$promotionTypes[$currentPromotion['global_sp_state']]['text'] ?? '';
|
||||
$msg = sprintf($lang_functions['full_site_promotion_in_effect'], $promotionText);
|
||||
if (!empty($currentPromotion['begin']) || !empty($currentPromotion['deadline'])) {
|
||||
$timeRange = sprintf($lang_functions['full_site_promotion_time_range'], $currentPromotion['begin'] ?? '-∞', $currentPromotion['deadline'] ?? '∞');
|
||||
$msg .= '<br/>' . $timeRange;
|
||||
}
|
||||
if (!empty($currentPromotion['remark'])) {
|
||||
$msg .= '<br/>' . sprintf($remarkTpl, $currentPromotion['remark']);
|
||||
}
|
||||
msgalert("torrents.php", $msg, "green");
|
||||
}
|
||||
if ($upcomingPromotion) {
|
||||
$promotionText = \App\Models\Torrent::$promotionTypes[$upcomingPromotion['global_sp_state']]['text'] ?? '';
|
||||
$msg = sprintf($lang_functions['full_site_promotion_upcoming'] ?? 'Upcoming full site [%s]', $promotionText);
|
||||
if (!empty($upcomingPromotion['begin']) || !empty($upcomingPromotion['deadline'])) {
|
||||
$timeRange = sprintf($lang_functions['full_site_promotion_time_range'], $upcomingPromotion['begin'] ?? '-∞', $upcomingPromotion['deadline'] ?? '∞');
|
||||
$msg .= '<br/>' . $timeRange;
|
||||
}
|
||||
if (!empty($upcomingPromotion['remark'])) {
|
||||
$msg .= '<br/>' . sprintf($remarkTpl, $upcomingPromotion['remark']);
|
||||
}
|
||||
msgalert("torrents.php", $msg, "blue");
|
||||
}
|
||||
if($CURUSER['leechwarn'] == 'yes')
|
||||
{
|
||||
@@ -5994,7 +6013,7 @@ function get_ip_location_from_geoip($ip): bool|array
|
||||
|
||||
function msgalert($url, $text, $bgcolor = "red")
|
||||
{
|
||||
print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"10\"><tr><td style='border: none; padding: 10px; background: ".$bgcolor."'>\n");
|
||||
print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"10\" style=\"margin: 0 auto;\"><tr><td style='border: none; padding: 10px; background: ".$bgcolor."; text-align: center;'>\n");
|
||||
if (!empty($url)) {
|
||||
print("<b><a href=\"".$url."\" target='_blank'><font color=\"white\">".$text."</font></a></b>");
|
||||
} else {
|
||||
|
||||
@@ -3,21 +3,14 @@
|
||||
function get_global_sp_state()
|
||||
{
|
||||
static $global_promotion_state;
|
||||
$cacheKey = \App\Models\Setting::TORRENT_GLOBAL_STATE_CACHE_KEY;
|
||||
if (is_null($global_promotion_state)) {
|
||||
$row = \Nexus\Database\NexusDB::remember($cacheKey, 600, function () use ($cacheKey) {
|
||||
return \Nexus\Database\NexusDB::getOne('torrents_state', 1);
|
||||
});
|
||||
if (is_array($row) && isset($row['deadline']) && $row['deadline'] < date('Y-m-d H:i:s')) {
|
||||
//expired
|
||||
$global_promotion_state = \App\Models\Torrent::PROMOTION_NORMAL;
|
||||
} elseif (is_array($row) && isset($row['begin']) && $row['begin'] > date('Y-m-d H:i:s')) {
|
||||
//Not begin
|
||||
$global_promotion_state = \App\Models\Torrent::PROMOTION_NORMAL;
|
||||
} elseif (is_array($row)) {
|
||||
$global_promotion_state = $row["global_sp_state"];
|
||||
$timeline = \App\Models\TorrentState::resolveTimeline();
|
||||
$current = $timeline['current'] ?? null;
|
||||
|
||||
if (is_array($current) && isset($current['global_sp_state'])) {
|
||||
$global_promotion_state = $current['global_sp_state'];
|
||||
} else {
|
||||
$global_promotion_state = $row;
|
||||
$global_promotion_state = \App\Models\Torrent::PROMOTION_NORMAL;
|
||||
}
|
||||
}
|
||||
return $global_promotion_state;
|
||||
|
||||
Reference in New Issue
Block a user