From 6de5cb2f2167cecc236b0c3229ab3bac3d51d52c Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 1 Oct 2022 00:11:22 +0800 Subject: [PATCH] support plugin nexusphp-hit-and-run --- app/Console/Commands/Test.php | 4 +- .../SettingResource/Pages/EditSetting.php | 23 ++-- app/Models/HitAndRun.php | 53 +++++++- app/Models/SearchBox.php | 23 ++++ app/Models/Torrent.php | 3 +- app/Repositories/HitAndRunRepository.php | 114 +++++++++++++----- app/Repositories/TrackerRepository.php | 3 +- include/constants.php | 2 +- include/functions.php | 9 +- nexus/Imdb/Imdb.php | 3 +- public/announce.php | 9 +- public/details.php | 2 +- public/edit.php | 9 +- public/myhr.php | 7 +- public/takeedit.php | 15 +-- public/takeupload.php | 4 +- public/upload.php | 8 +- resources/lang/en/searchbox.php | 4 + resources/lang/zh_CN/searchbox.php | 4 + resources/lang/zh_TW/searchbox.php | 4 + 20 files changed, 222 insertions(+), 81 deletions(-) diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index b84d6d05..13b3ba74 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -14,6 +14,7 @@ use App\Models\HitAndRun; use App\Models\Medal; use App\Models\Peer; use App\Models\SearchBox; +use App\Models\Setting; use App\Models\Snatch; use App\Models\Tag; use App\Models\Torrent; @@ -88,8 +89,7 @@ class Test extends Command */ public function handle() { - $rep = new ToolRepository(); - $r = $rep->transfer('C:\Users\CHENYU~1\AppData\Local\Temp/nexusphp.v1.5.beta5.20120707.web.20220918.053953.zip', 0); + $r = strstr('hr.*', '.', true); dd($r); } diff --git a/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php b/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php index 95b8f914..3993aa59 100644 --- a/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php +++ b/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php @@ -76,6 +76,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms } } Setting::query()->upsert($data, ['name'], ['value']); + do_action("nexus_setting_update"); clear_setting_cache(); Filament::notify('success', __('filament::resources/pages/edit-record.messages.saved'), true); } @@ -85,13 +86,9 @@ class EditSetting extends Page implements Forms\Contracts\HasForms $tabs = []; $tabs[] = Forms\Components\Tabs\Tab::make(__('label.setting.hr.tab_header')) ->id('hr') - ->schema([ - Forms\Components\Radio::make('hr.mode')->options(HitAndRun::listModes(true))->inline(true)->label(__('label.setting.hr.mode')), - Forms\Components\TextInput::make('hr.inspect_time')->helperText(__('label.setting.hr.inspect_time_help'))->label(__('label.setting.hr.inspect_time'))->integer(), - Forms\Components\TextInput::make('hr.seed_time_minimum')->helperText(__('label.setting.hr.seed_time_minimum_help'))->label(__('label.setting.hr.seed_time_minimum'))->integer(), - Forms\Components\TextInput::make('hr.ignore_when_ratio_reach')->helperText(__('label.setting.hr.ignore_when_ratio_reach_help'))->label(__('label.setting.hr.ignore_when_ratio_reach'))->integer(), - Forms\Components\TextInput::make('hr.ban_user_when_counts_reach')->helperText(__('label.setting.hr.ban_user_when_counts_reach_help'))->label(__('label.setting.hr.ban_user_when_counts_reach'))->integer(), - ])->columns(2); + ->schema($this->getHitAndRunSchema()) + ->columns(2) + ; $tabs[] = Forms\Components\Tabs\Tab::make(__('label.setting.backup.tab_header')) ->id('backup') @@ -135,4 +132,16 @@ class EditSetting extends Page implements Forms\Contracts\HasForms return $tabs; } + private function getHitAndRunSchema() + { + $default = [ + Forms\Components\Radio::make('hr.mode')->options(HitAndRun::listModes(true))->inline(true)->label(__('label.setting.hr.mode')), + Forms\Components\TextInput::make('hr.inspect_time')->helperText(__('label.setting.hr.inspect_time_help'))->label(__('label.setting.hr.inspect_time'))->integer(), + Forms\Components\TextInput::make('hr.seed_time_minimum')->helperText(__('label.setting.hr.seed_time_minimum_help'))->label(__('label.setting.hr.seed_time_minimum'))->integer(), + Forms\Components\TextInput::make('hr.ignore_when_ratio_reach')->helperText(__('label.setting.hr.ignore_when_ratio_reach_help'))->label(__('label.setting.hr.ignore_when_ratio_reach'))->integer(), + Forms\Components\TextInput::make('hr.ban_user_when_counts_reach')->helperText(__('label.setting.hr.ban_user_when_counts_reach_help'))->label(__('label.setting.hr.ban_user_when_counts_reach'))->integer(), + ]; + return apply_filter("nexus_hit_and_run_setting_schema", $default); + } + } diff --git a/app/Models/HitAndRun.php b/app/Models/HitAndRun.php index 96c948f5..19d9f219 100644 --- a/app/Models/HitAndRun.php +++ b/app/Models/HitAndRun.php @@ -2,6 +2,8 @@ namespace App\Models; +use Carbon\Carbon; +use Carbon\Exceptions\InvalidArgumentException; use Illuminate\Database\Eloquent\Casts\Attribute; class HitAndRun extends NexusModel @@ -17,7 +19,7 @@ class HitAndRun extends NexusModel const STATUS_UNREACHED = 3; const STATUS_PARDONED = 4; - public static $status = [ + public static array $status = [ self::STATUS_INSPECTING => ['text' => 'Inspecting'], self::STATUS_REACHED => ['text' => 'Reached'], self::STATUS_UNREACHED => ['text' => 'Unreached'], @@ -39,17 +41,37 @@ class HitAndRun extends NexusModel protected function seedTimeRequired(): Attribute { return new Attribute( - get: fn($value, $attributes) => $this->status == self::STATUS_INSPECTING ? mkprettytime(3600 * Setting::get('hr.seed_time_minimum') - $this->snatch->seedtime) : '---' + get: fn($value, $attributes) => $this->doGetSeedTimeRequired() ); } protected function inspectTimeLeft(): Attribute { return new Attribute( - get: fn($value, $attributes) => $this->status == self::STATUS_INSPECTING ? mkprettytime(\Carbon\Carbon::now()->diffInSeconds($this->snatch->completedat->addHours(Setting::get('hr.inspect_time')))) : '---' + get: fn($value, $attributes) => $this->doGetInspectTimeLeft() ); } + private function doGetInspectTimeLeft(): string + { + if ($this->status != self::STATUS_INSPECTING) { + return '---'; + } + $inspectTime = HitAndRun::getConfig('inspect_time', $this->torrent->basic_category->mode); + $diffInSeconds = Carbon::now()->diffInSeconds($this->snatch->completedat->addHours($inspectTime)); + return mkprettytime($diffInSeconds); + } + + private function doGetSeedTimeRequired(): string + { + if ($this->status != self::STATUS_INSPECTING) { + return '---'; + } + $seedTimeMinimum = HitAndRun::getConfig('seed_time_minimum', $this->torrent->basic_category->mode); + $diffInSeconds = 3600 * $seedTimeMinimum - $this->snatch->seedtime; + return mkprettytime($diffInSeconds); + } + public function getStatusTextAttribute() { return nexus_trans('hr.status_' . $this->status); @@ -87,8 +109,29 @@ class HitAndRun extends NexusModel public static function getIsEnabled(): bool { - $result = Setting::get('hr.mode'); - return $result && in_array($result, [self::MODE_GLOBAL, self::MODE_MANUAL]); + $enableSpecialSection = Setting::get('main.spsct') == 'yes'; + $browseMode = self::getConfig('mode', Setting::get('main.browsecat')); + $browseEnabled = $browseMode && in_array($browseMode, [self::MODE_GLOBAL, self::MODE_MANUAL]); + if (!$enableSpecialSection) { + do_log("Not enable special section, browseEnabled: $browseEnabled"); + return $browseEnabled; + } + $specialMode = self::getConfig('mode', Setting::get('main.specialcat')); + $specialEnabled = $specialMode && in_array($specialMode, [self::MODE_GLOBAL, self::MODE_MANUAL]); + $result = $browseEnabled || $specialEnabled; + do_log("Enable special section, browseEnabled: $browseEnabled, specialEnabled: $specialEnabled, result: $result"); + return $result; + } + + public static function getConfig($name, $searchBoxId) + { + if ($name == '*') { + $key = "hr"; + } else { + $key = "hr.$name"; + } + $default = Setting::get($key); + return apply_filter("nexus_setting_get", $default, $name, ['mode' => $searchBoxId]); } public function torrent(): \Illuminate\Database\Eloquent\Relations\BelongsTo diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php index 5a5ddff7..74d0e28d 100644 --- a/app/Models/SearchBox.php +++ b/app/Models/SearchBox.php @@ -18,6 +18,14 @@ class SearchBox extends NexusModel 'extra' => 'object' ]; + const SECTION_BROWSE = 'browse'; + const SECTION_SPECIAL = 'special'; + + public static array $sections = [ + self::SECTION_BROWSE => ['text' => 'Browse'], + self::SECTION_SPECIAL => ['text' => 'Special'], + ]; + 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'; @@ -35,6 +43,21 @@ class SearchBox extends NexusModel return $result; } + public static function listSections($field = null): array + { + $result = []; + foreach (self::$sections as $key => $value) { + $value['text'] = nexus_trans("searchbox.sections.$key"); + $value['mode'] = Setting::get("main.{$key}cat"); + if ($field !== null && isset($value[$field])) { + $result[$key] = $value[$field]; + } else { + $result[$key] = $value; + } + } + return $result; + } + public function getCustomFieldsAttribute($value): array { if (!is_array($value)) { diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index 5f259a8b..6a040b24 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -289,7 +289,8 @@ class Torrent extends NexusModel public function getHrAttribute(): string { - $hrMode = Setting::get('hr.mode'); +// $hrMode = Setting::get('hr.mode'); + $hrMode = HitAndRun::getConfig('mode', $this->basic_category->mode); if ($hrMode == HitAndRun::MODE_GLOBAL) { return self::HR_YES; } diff --git a/app/Repositories/HitAndRunRepository.php b/app/Repositories/HitAndRunRepository.php index 25448b28..2c20f091 100644 --- a/app/Repositories/HitAndRunRepository.php +++ b/app/Repositories/HitAndRunRepository.php @@ -3,13 +3,16 @@ namespace App\Repositories; use App\Models\HitAndRun; use App\Models\Message; +use App\Models\SearchBox; use App\Models\Setting; use App\Models\User; use App\Models\UserBanLog; use Carbon\Carbon; +use Elasticsearch\Endpoints\Search; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; +use Nexus\Database\NexusDB; class HitAndRunRepository extends BaseRepository { @@ -87,12 +90,23 @@ class HitAndRunRepository extends BaseRepository return $query; } - public function cronjobUpdateStatus($uid = null, $torrentId = null, $ignoreTime = false): bool|int + public function cronjobUpdateStatus($uid = null, $torrentId = null, $ignoreTime = false) { - do_log("uid: $uid, torrentId: $torrentId, ignoreTime: " . var_export($ignoreTime, true)); + $enableSpecialSection = Setting::get('main.spsct') == 'yes'; + $browseMode = Setting::get('main.browsecat'); + $specialMode = Setting::get('main.specialcat'); + $this->doCronjobUpdateStatus($browseMode, $uid, $torrentId, $ignoreTime); + if ($enableSpecialSection && $browseMode != $specialMode) { + $this->doCronjobUpdateStatus($specialMode, $uid, $torrentId, $ignoreTime, $specialMode); + } + } + + private function doCronjobUpdateStatus($searchBoxId, $uid = null, $torrentId = null, $ignoreTime = false) + { + do_log("searchBoxId: $searchBoxId, uid: $uid, torrentId: $torrentId, ignoreTime: " . var_export($ignoreTime, true)); + $setting = HitAndRun::getConfig('*', $searchBoxId); $size = 1000; $page = 1; - $setting = Setting::get('hr'); if (empty($setting['mode'])) { do_log("H&R not set."); return false; @@ -108,7 +122,7 @@ class HitAndRunRepository extends BaseRepository $query = HitAndRun::query() ->where('status', HitAndRun::STATUS_INSPECTING) ->with([ - 'torrent' => function ($query) {$query->select(['id', 'size', 'name']);}, + 'torrent' => function ($query) {$query->select(['id', 'size', 'name', 'category']);}, 'snatch', 'user' => function ($query) {$query->select(['id', 'username', 'lang', 'class', 'donoruntil', 'enabled']);}, 'user.language', @@ -122,6 +136,9 @@ class HitAndRunRepository extends BaseRepository if (!$ignoreTime) { $query->where('created_at', '<', Carbon::now()->subHours($setting['inspect_time'])); } + $query->whereHas('torrent.basic_category', function (Builder $query) use ($searchBoxId) { + return $query->where('mode', $searchBoxId); + }); $successCounts = 0; $disabledUsers = []; while (true) { @@ -164,7 +181,7 @@ class HitAndRunRepository extends BaseRepository $requireSeedTime = bcmul($setting['seed_time_minimum'], 3600); do_log("$currentLog, targetSeedTime: $targetSeedTime, requireSeedTime: $requireSeedTime"); if ($targetSeedTime >= $requireSeedTime) { - $result = $this->reachedBySeedTime($row); + $result = $this->reachedBySeedTime($row, $searchBoxId); if ($result) { $successCounts++; } @@ -176,7 +193,7 @@ class HitAndRunRepository extends BaseRepository $requireShareRatio = $setting['ignore_when_ratio_reach']; do_log("$currentLog, targetShareRatio: $targetShareRatio, requireShareRatio: $requireShareRatio"); if ($targetShareRatio >= $requireShareRatio) { - $result = $this->reachedByShareRatio($row); + $result = $this->reachedByShareRatio($row, $searchBoxId); if ($result) { $successCounts++; } @@ -185,7 +202,7 @@ class HitAndRunRepository extends BaseRepository //unreached if ($row->created_at->addHours($setting['inspect_time'])->lte(Carbon::now())) { - $result = $this->unreached($row, !isset($disabledUsers[$row->uid])); + $result = $this->unreached($row, $searchBoxId, !isset($disabledUsers[$row->uid])); if ($result) { $successCounts++; $disabledUsers[$row->uid] = true; @@ -194,7 +211,7 @@ class HitAndRunRepository extends BaseRepository } $page++; } - do_log("[CRONJOB_UPDATE_HR_DONE]"); + do_log("searchBoxId: $searchBoxId, [CRONJOB_UPDATE_HR_DONE]"); return $successCounts; } @@ -212,15 +229,15 @@ class HitAndRunRepository extends BaseRepository ]; } - private function reachedByShareRatio(HitAndRun $hitAndRun): bool + private function reachedByShareRatio(HitAndRun $hitAndRun, $searchBoxId): bool { do_log(__METHOD__); $comment = nexus_trans('hr.reached_by_share_ratio_comment', [ 'now' => Carbon::now()->toDateTimeString(), - 'seed_time_minimum' => Setting::get('hr.seed_time_minimum'), + 'seed_time_minimum' => HitAndRun::getConfig('seed_time_minimum', $searchBoxId), 'seed_time' => bcdiv($hitAndRun->snatch->seedtime, 3600, 1), 'share_ratio' => get_hr_ratio($hitAndRun->snatch->uploaded, $hitAndRun->snatch->downloaded), - 'ignore_when_ratio_reach' => Setting::get('hr.ignore_when_ratio_reach'), + 'ignore_when_ratio_reach' => HitAndRun::getConfig('ignore_when_ratio_reach', $searchBoxId), ], $hitAndRun->user->locale); $update = [ 'comment' => $comment @@ -228,13 +245,13 @@ class HitAndRunRepository extends BaseRepository return $this->inspectingToReached($hitAndRun, $update, __FUNCTION__); } - private function reachedBySeedTime(HitAndRun $hitAndRun): bool + private function reachedBySeedTime(HitAndRun $hitAndRun, $searchBoxId): bool { do_log(__METHOD__); $comment = nexus_trans('hr.reached_by_seed_time_comment', [ 'now' => Carbon::now()->toDateTimeString(), 'seed_time' => bcdiv($hitAndRun->snatch->seedtime, 3600, 1), - 'seed_time_minimum' => Setting::get('hr.seed_time_minimum') + 'seed_time_minimum' => HitAndRun::getConfig('seed_time_minimum', $searchBoxId) ], $hitAndRun->user->locale); $update = [ 'comment' => $comment @@ -271,16 +288,16 @@ class HitAndRunRepository extends BaseRepository return true; } - private function unreached(HitAndRun $hitAndRun, $disableUser = true): bool + private function unreached(HitAndRun $hitAndRun, $searchBoxId, $disableUser = true): bool { do_log(sprintf('hitAndRun: %s, disableUser: %s', $hitAndRun->toJson(), var_export($disableUser, true))); $comment = nexus_trans('hr.unreached_comment', [ 'now' => Carbon::now()->toDateTimeString(), 'seed_time' => bcdiv($hitAndRun->snatch->seedtime, 3600, 1), - 'seed_time_minimum' => Setting::get('hr.seed_time_minimum'), + 'seed_time_minimum' => HitAndRun::getConfig('seed_time_minimum', $searchBoxId), 'share_ratio' => get_hr_ratio($hitAndRun->snatch->uploaded, $hitAndRun->snatch->downloaded), 'torrent_size' => mksize($hitAndRun->torrent->size), - 'ignore_when_ratio_reach' => Setting::get('hr.ignore_when_ratio_reach') + 'ignore_when_ratio_reach' => HitAndRun::getConfig('ignore_when_ratio_reach', $searchBoxId) ], $hitAndRun->user->locale); $update = [ 'status' => HitAndRun::STATUS_UNREACHED, @@ -319,7 +336,7 @@ class HitAndRunRepository extends BaseRepository /** @var User $user */ $user = $hitAndRun->user; $counts = $user->hitAndRuns()->where('status', HitAndRun::STATUS_UNREACHED)->count(); - $disableCounts = Setting::get('hr.ban_user_when_counts_reach'); + $disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $searchBoxId); do_log("user: {$user->id}, H&R counts: $counts, disableCounts: $disableCounts", 'notice'); if ($counts >= $disableCounts) { do_log("[DISABLE_USER_DUE_TO_H&R_UNREACHED]", 'notice'); @@ -347,23 +364,48 @@ class HitAndRunRepository extends BaseRepository public function getStatusStats($uid, $formatted = true) { - $results = HitAndRun::query()->where('uid', $uid) - ->selectRaw('status, count(*) as counts') - ->groupBy('status') - ->get() - ->pluck('counts', 'status'); - if ($formatted) { - return sprintf( - '%s/%s/%s', - $results->get(HitAndRun::STATUS_INSPECTING, 0), - $results->get(HitAndRun::STATUS_UNREACHED, 0), - Setting::get('hr.ban_user_when_counts_reach') - ); + $enableSpecialSection = Setting::get('main.spsct') == 'yes'; + if ($enableSpecialSection) { + $sql = "select hit_and_runs.status, categories.mode, count(*) as counts from hit_and_runs left join torrents on torrents.id = hit_and_runs.torrent_id left join categories on categories.id = torrents.category where hit_and_runs.uid = $uid group by hit_and_runs.status, categories.mode"; + } else { + $sql = "select hit_and_runs.status, count(*) as counts from hit_and_runs where uid = $uid group by status"; + } + $results = NexusDB::select($sql); + if (!$formatted) { + return $results; + } + if ($enableSpecialSection) { + $grouped = []; + foreach ($results as $item) { + $grouped[$item['mode']][$item['status']] = $item['counts']; + } + $out = []; + foreach (SearchBox::listSections() as $key => $info) { + $out[] = sprintf( + '%s: %s/%s/%s', + $info['text'], + $grouped[$info['mode']][HitAndRun::STATUS_INSPECTING] ?? 0, + $grouped[$info['mode']][HitAndRun::STATUS_UNREACHED] ?? 0, + HitAndRun::getConfig('ban_user_when_counts_reach', $info['mode']) + ); + } + return implode(" ", $out); + } else { + foreach (SearchBox::listSections() as $key => $info) { + if ($key == SearchBox::SECTION_BROWSE) { + return sprintf( + '%s/%s/%s', + $results[HitAndRun::STATUS_INSPECTING] ?? 0, + $results[HitAndRun::STATUS_UNREACHED] ?? 0, + HitAndRun::getConfig('ban_user_when_counts_reach', $info['mode']) + ); + } + } } - return $results; - } + + public function listStatus(): array { $results = []; @@ -409,4 +451,14 @@ class HitAndRunRepository extends BaseRepository { return [HitAndRun::STATUS_INSPECTING, HitAndRun::STATUS_UNREACHED]; } + + public function renderOnUploadPage($value, $searchBoxId): string + { + if (HitAndRun::getConfig('mode', $searchBoxId) == \App\Models\HitAndRun::MODE_MANUAL && user_can('torrent_hr')) { + $hrRadio = sprintf('', $searchBoxId, $value == 0 ? ' checked' : ''); + $hrRadio .= sprintf('', $searchBoxId, $value == 1 ? ' checked' : ''); + return tr('H&R', $hrRadio, 1, "mode_$searchBoxId", true); + } + return ''; + } } diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index 251151be..85f8795c 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -1092,7 +1092,8 @@ class TrackerRepository extends BaseRepository if ($user->isDonating()) { return; } - $hrMode = Setting::get('hr.mode'); +// $hrMode = Setting::get('hr.mode'); + $hrMode = HitAndRun::getConfig('mode', $torrent->basic_category->mode); if ($hrMode == HitAndRun::MODE_DISABLED) { return; } diff --git a/include/constants.php b/include/constants.php index c16d9eb8..3be91f9e 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ '; @@ -5178,7 +5179,7 @@ function saveSetting($prefix, $nameAndValue, $autoload = 'yes') $sql .= implode(",", $data) . " on duplicate key update value = values(value)"; \Nexus\Database\NexusDB::statement($sql); clear_setting_cache(); - do_action("nexus_setting_update", $prefix, $nameAndValue); + do_action("nexus_setting_update"); } function getFullDirectory($dir) diff --git a/nexus/Imdb/Imdb.php b/nexus/Imdb/Imdb.php index baad02f9..78fe2bd5 100644 --- a/nexus/Imdb/Imdb.php +++ b/nexus/Imdb/Imdb.php @@ -34,7 +34,8 @@ class Imdb public static function listSupportLanguages(): array { - $data = require_once sprintf('%s/resources/lang/%s/imdb.php', ROOT_PATH, get_langfolder_cookie(true)); + $file = sprintf('%s/resources/lang/%s/imdb.php', ROOT_PATH, get_langfolder_cookie(true)); + $data = include $file; return $data['languages']; } diff --git a/public/announce.php b/public/announce.php index 02737e76..c93ca683 100644 --- a/public/announce.php +++ b/public/announce.php @@ -121,7 +121,7 @@ if (!$az) err("Invalid passkey! Re-download the .torrent from $BASEURL"); $userid = intval($az['id'] ?? 0); unset($GLOBALS['CURUSER']); $CURUSER = $GLOBALS["CURUSER"] = $az; -$isDonor = $az['donor'] == 'yes' && ($az['donoruntil'] === null || $az['donoruntil'] == '0000-00-00 00:00:00' || $az['donoruntil'] > date('Y-m-d H:i:s')); +$isDonor = is_donor($az); $az['__is_donor'] = $isDonor; $log = "user: $userid, isDonor: $isDonor, seeder: $seeder, ip: $ip, ipv4: $ipv4, ipv6: $ipv6"; @@ -156,7 +156,7 @@ elseif ($az['showclienterror'] == 'yes'){ } // check torrent based on info_hash -$checkTorrentSql = "SELECT id, size, owner, sp_state, seeders, leechers, UNIX_TIMESTAMP(added) AS ts, banned, hr, approval_status FROM torrents WHERE " . hash_where("info_hash", $info_hash); +$checkTorrentSql = "SELECT torrents.id, size, owner, sp_state, seeders, leechers, UNIX_TIMESTAMP(added) AS ts, banned, hr, approval_status, categories.mode FROM torrents left join categories on torrents.category = categories.id WHERE " . hash_where("info_hash", $info_hash); if (!$torrent = $Cache->get_value('torrent_hash_'.$info_hash.'_content')){ $res = sql_query($checkTorrentSql); $torrent = mysql_fetch_array($res); @@ -553,9 +553,10 @@ elseif(isset($self)) if (!empty($snatchInfo)) { sql_query("UPDATE snatched SET uploaded = uploaded + $trueupthis, downloaded = downloaded + $truedownthis, to_go = $left, $announcetime, last_action = ".$dt." $finished_snatched WHERE torrentid = $torrentid AND userid = $userid") or err("SL Err 2"); do_action('snatched_saved', $torrent, $snatchInfo); - if ($event == 'completed' && $az['class'] < \App\Models\HitAndRun::MINIMUM_IGNORE_USER_CLASS && !$isDonor) { + if ($event == 'completed' && $az['class'] < \App\Models\HitAndRun::MINIMUM_IGNORE_USER_CLASS && !$isDonor && isset($torrent['mode'])) { //think about H&R - $hrMode = get_setting('hr.mode'); +// $hrMode = get_setting('hr.mode'); + $hrMode = \App\Models\HitAndRun::getConfig('mode', $torrent['mode']); if ($hrMode == \App\Models\HitAndRun::MODE_GLOBAL || ($hrMode == \App\Models\HitAndRun::MODE_MANUAL && $torrent['hr'] == \App\Models\Torrent::HR_YES)) { $sql = "insert into hit_and_runs (uid, torrent_id, snatched_id) values ($userid, $torrentid, {$snatchInfo['id']}) on duplicate key update updated_at = " . sqlesc(date('Y-m-d H:i:s')); $affectedRows = sql_query($sql); diff --git a/public/details.php b/public/details.php index 9aa204f6..8694fc99 100644 --- a/public/details.php +++ b/public/details.php @@ -70,7 +70,7 @@ if (!$row) { $banned_torrent = ($row["banned"] == 'yes' ? " (".$lang_functions['text_banned'].")" : ""); $sp_torrent = get_torrent_promotion_append($row['sp_state'],'word', false, '', 0, '', $row['__ignore_global_sp_state'] ?? false); $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); - $hrImg = get_hr_img($row); + $hrImg = get_hr_img($row, $row['search_box_id']); $approvalStatusIcon = $torrentRep->renderApprovalStatus($row["approval_status"]); $s=htmlspecialchars($row["name"]).$banned_torrent.($sp_torrent ? "   ".$sp_torrent : "").($sp_torrent_sub) . $hrImg . $approvalStatusIcon; print("

".$s."

\n"); diff --git a/public/edit.php b/public/edit.php index a2a64a57..b9d63d52 100644 --- a/public/edit.php +++ b/public/edit.php @@ -17,6 +17,7 @@ if (!$row) die(); * @since v1.6 */ $customField = new \Nexus\Field\Field(); +$hitAndRunRep = new \App\Repositories\HitAndRunRepository(); $tagIdArr = \App\Models\TorrentTag::query()->where('torrent_id', $id)->get()->pluck('tag_id')->toArray(); @@ -145,10 +146,11 @@ else { tr($lang_edit['row_content'],$team_select,1); } - echo $customField->renderOnUploadPage($id, $browsecatmode); + echo $hitAndRunRep->renderOnUploadPage($row['hr'], $browsecatmode); if ($enablespecial) { $customField->renderOnUploadPage($id, $specialcatmode); + echo $hitAndRunRep->renderOnUploadPage($row['hr'], $specialcatmode); } tr($lang_functions['text_tags'], (new \App\Repositories\TagRepository())->renderCheckbox($tagIdArr), 1); @@ -201,11 +203,6 @@ else { } tr($lang_edit['row_pick'], $pickcontent, 1); } - if (get_setting('hr.mode') == \App\Models\HitAndRun::MODE_MANUAL && user_can('torrent_hr')) { - $hrRadio = sprintf('', (string)$row['hr'] === '0' ? ' checked' : ''); - $hrRadio .= sprintf('', (string)$row['hr'] === '1' ? ' checked' : ''); - tr('H&R', $hrRadio, 1); - } print(" \n"); print("\n"); diff --git a/public/myhr.php b/public/myhr.php index 1df8fa02..1da91f1b 100644 --- a/public/myhr.php +++ b/public/myhr.php @@ -67,7 +67,8 @@ if ($rescount) { $query = (clone $baseQuery) ->with([ - 'torrent' => function ($query) {$query->select(['id', 'size', 'name']);}, + 'torrent' => function ($query) {$query->select(['id', 'size', 'name', 'category']);}, + 'torrent.basic_category', 'snatch', 'user' => function ($query) {$query->select(['id', 'lang']);}, 'user.language', @@ -92,9 +93,9 @@ if ($rescount) { " . mksize($row->snatch->uploaded) . " " . mksize($row->snatch->downloaded) . " " . get_hr_ratio($row->snatch->uploaded, $row->snatch->downloaded) . " - " . ($row->status == \App\Models\HitAndRun::STATUS_INSPECTING ? mkprettytime(3600 * get_setting('hr.seed_time_minimum') - $row->snatch->seedtime) : '---') . " + " . $row->seedTimeRequired . " " . format_datetime($row->snatch->completedat) . " - " . ($row->status == \App\Models\HitAndRun::STATUS_INSPECTING ? mkprettytime(\Carbon\Carbon::now()->diffInSeconds($row->snatch->completedat->addHours(get_setting('hr.inspect_time')))) : '---') . " + " . $row->inspectTimeLeft . " " . nl2br(trim($row->comment)) . " {$columnAction} "); diff --git a/public/takeedit.php b/public/takeedit.php index 56f8cf1d..ad310b0f 100644 --- a/public/takeedit.php +++ b/public/takeedit.php @@ -53,13 +53,6 @@ if (!empty($_POST['pt_gen'])) { $updateset[] = "technical_info = " . sqlesc($_POST['technical_info'] ?? ''); $torrentOperationLog = []; -/** - * hr - * @since 1.6.0-beta12 - */ -if (isset($_POST['hr']) && isset(\App\Models\Torrent::$hrStatus[$_POST['hr']]) && user_can('torrent_hr')) { - $updateset[] = "hr = " . sqlesc($_POST['hr']); -} if ($enablenfo_main=='yes'){ @@ -215,6 +208,14 @@ $descriptionArr = format_description($descr); $cover = get_image_from_description($descriptionArr, true, false); $updateset[] = "cover = " . sqlesc($cover); +/** + * hr + * @since 1.6.0-beta12 + */ +if (isset($_POST['hr'][$newcatmode]) && isset(\App\Models\Torrent::$hrStatus[$_POST['hr'][$newcatmode]]) && user_can('torrent_hr')) { + $updateset[] = "hr = " . sqlesc($_POST['hr'][$newcatmode]); +} + $sql = "UPDATE torrents SET " . join(",", $updateset) . " WHERE id = $id"; do_log("[UPDATE_TORRENT]: $sql"); $affectedRows = sql_query($sql) or sqlerr(__FILE__, __LINE__); diff --git a/public/takeupload.php b/public/takeupload.php index 70830baf..1deef989 100644 --- a/public/takeupload.php +++ b/public/takeupload.php @@ -339,8 +339,8 @@ $insert = [ 'technical_info' => $_POST['technical_info'] ?? '', 'cover' => $cover, ]; -if (isset($_POST['hr']) && isset(\App\Models\Torrent::$hrStatus[$_POST['hr']]) && user_can('torrent_hr')) { - $insert['hr'] = $_POST['hr']; +if (isset($_POST['hr'][$catmod]) && isset(\App\Models\Torrent::$hrStatus[$_POST['hr'][$catmod]]) && user_can('torrent_hr')) { + $insert['hr'] = $_POST['hr'][$catmod]; } if(user_can('torrentsticky')) { if (isset($_POST['pos_state']) && isset(\App\Models\Torrent::$posStates[$_POST['pos_state']])) { diff --git a/public/upload.php b/public/upload.php index 633cd7c0..0c33a17d 100644 --- a/public/upload.php +++ b/public/upload.php @@ -149,9 +149,12 @@ stdhead($lang_upload['head_upload']); tr($lang_upload['row_content'],$team_select,1); } $customField = new \Nexus\Field\Field(); + $hitAndRunRep = new \App\Repositories\HitAndRunRepository(); echo $customField->renderOnUploadPage(0, $browsecatmode); + echo $hitAndRunRep->renderOnUploadPage('', $browsecatmode); if ($enablespecial) { echo $customField->renderOnUploadPage(0, $specialcatmode); + echo $hitAndRunRep->renderOnUploadPage('', $specialcatmode); } //==== offer dropdown for offer mod from code by S4NE @@ -218,11 +221,6 @@ JS; tr($lang_upload['row_show_uploader'], "".$lang_upload['checkbox_hide_uploader_note'], 1); } tr($lang_functions['text_tags'], (new \App\Repositories\TagRepository())->renderCheckbox(), 1); - if (get_setting('hr.mode') == \App\Models\HitAndRun::MODE_MANUAL && user_can('torrent_hr')) { - $hrRadio = sprintf('', ''); - $hrRadio .= sprintf('', ''); - tr('H&R', $hrRadio, 1); - } ?> diff --git a/resources/lang/en/searchbox.php b/resources/lang/en/searchbox.php index ceb08948..0fb6d6eb 100644 --- a/resources/lang/en/searchbox.php +++ b/resources/lang/en/searchbox.php @@ -13,4 +13,8 @@ return [ \App\Models\SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => 'Display cover on torrent list', \App\Models\SearchBox::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST => 'Display seed box icon on torrent list', ], + 'sections' => [ + 'browse' => 'Torrents section', + 'special' => 'Special section', + ], ]; diff --git a/resources/lang/zh_CN/searchbox.php b/resources/lang/zh_CN/searchbox.php index 69344bbe..501d36ca 100644 --- a/resources/lang/zh_CN/searchbox.php +++ b/resources/lang/zh_CN/searchbox.php @@ -13,4 +13,8 @@ return [ \App\Models\SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => '种子列表页展示封面', \App\Models\SearchBox::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST => '种子列表页展示 SeedBox 图标', ], + 'sections' => [ + 'browse' => '种子区', + 'special' => '特别区', + ], ]; diff --git a/resources/lang/zh_TW/searchbox.php b/resources/lang/zh_TW/searchbox.php index e053f2b7..73558bae 100644 --- a/resources/lang/zh_TW/searchbox.php +++ b/resources/lang/zh_TW/searchbox.php @@ -13,4 +13,8 @@ return [ \App\Models\SearchBox::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => '種子列表頁展示封面', \App\Models\SearchBox::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST => '種子列表頁展示 SeedBox 圖標', ], + 'sections' => [ + 'browse' => '種子區', + 'special' => '特別區', + ], ];