fix details page other version hr img

This commit is contained in:
xiaomlove
2022-10-01 18:26:18 +08:00
parent b234228264
commit ee00be3840
4 changed files with 51 additions and 35 deletions

View File

@@ -141,7 +141,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
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);
return apply_filter("hit_and_run_setting_schema", $default);
}
}

View File

@@ -134,6 +134,12 @@ class HitAndRun extends NexusModel
return apply_filter("nexus_setting_get", $default, $name, ['mode' => $searchBoxId]);
}
public static function diffInSection(): bool
{
$enableSpecialSection = Setting::get('main.spsct') == 'yes';
return $enableSpecialSection && apply_filter("hit_and_run_diff_in_section", false);
}
public function torrent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Torrent::class, 'torrent_id');

View File

@@ -92,19 +92,25 @@ class HitAndRunRepository extends BaseRepository
public function cronjobUpdateStatus($uid = null, $torrentId = null, $ignoreTime = false)
{
$enableSpecialSection = Setting::get('main.spsct') == 'yes';
$diffInSection = HitAndRun::diffInSection();
$browseMode = Setting::get('main.browsecat');
$setting = HitAndRun::getConfig('*', $browseMode);
$setting['diff_in_section'] = $diffInSection;
$setting['search_box_id'] = $browseMode;
$this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime);
$specialMode = Setting::get('main.specialcat');
$this->doCronjobUpdateStatus($browseMode, $uid, $torrentId, $ignoreTime);
if ($enableSpecialSection && $browseMode != $specialMode) {
$this->doCronjobUpdateStatus($specialMode, $uid, $torrentId, $ignoreTime, $specialMode);
if ($diffInSection && $browseMode != $specialMode) {
$setting = HitAndRun::getConfig('*', $specialMode);
$setting['diff_in_section'] = $diffInSection;
$setting['search_box_id'] = $specialMode;
$this->doCronjobUpdateStatus($setting, $uid, $torrentId, $ignoreTime);
}
}
private function doCronjobUpdateStatus($searchBoxId, $uid = null, $torrentId = null, $ignoreTime = false)
private function doCronjobUpdateStatus(array $setting, $uid = null, $torrentId = null, $ignoreTime = false)
{
do_log("searchBoxId: $searchBoxId, uid: $uid, torrentId: $torrentId, ignoreTime: " . var_export($ignoreTime, true));
$setting = HitAndRun::getConfig('*', $searchBoxId);
do_log("uid: $uid, torrentId: $torrentId, ignoreTime: " . var_export($ignoreTime, true));
$size = 1000;
$page = 1;
if (empty($setting['mode'])) {
@@ -136,9 +142,12 @@ 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);
});
if ($setting['diff_in_section']) {
$query->whereHas('torrent.basic_category', function (Builder $query) use ($setting) {
return $query->where('mode', $setting['search_box_id']);
});
}
$successCounts = 0;
$disabledUsers = [];
while (true) {
@@ -181,7 +190,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, $searchBoxId);
$result = $this->reachedBySeedTime($row, $setting);
if ($result) {
$successCounts++;
}
@@ -193,7 +202,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, $searchBoxId);
$result = $this->reachedByShareRatio($row, $setting);
if ($result) {
$successCounts++;
}
@@ -202,7 +211,7 @@ class HitAndRunRepository extends BaseRepository
//unreached
if ($row->created_at->addHours($setting['inspect_time'])->lte(Carbon::now())) {
$result = $this->unreached($row, $searchBoxId, !isset($disabledUsers[$row->uid]));
$result = $this->unreached($row, $setting, !isset($disabledUsers[$row->uid]));
if ($result) {
$successCounts++;
$disabledUsers[$row->uid] = true;
@@ -211,7 +220,7 @@ class HitAndRunRepository extends BaseRepository
}
$page++;
}
do_log("searchBoxId: $searchBoxId, [CRONJOB_UPDATE_HR_DONE]");
do_log("[CRONJOB_UPDATE_HR_DONE]");
return $successCounts;
}
@@ -229,15 +238,15 @@ class HitAndRunRepository extends BaseRepository
];
}
private function reachedByShareRatio(HitAndRun $hitAndRun, $searchBoxId): bool
private function reachedByShareRatio(HitAndRun $hitAndRun, array $setting): bool
{
do_log(__METHOD__);
$comment = nexus_trans('hr.reached_by_share_ratio_comment', [
'now' => Carbon::now()->toDateTimeString(),
'seed_time_minimum' => HitAndRun::getConfig('seed_time_minimum', $searchBoxId),
'seed_time_minimum' => $setting['seed_time_minimum'],
'seed_time' => bcdiv($hitAndRun->snatch->seedtime, 3600, 1),
'share_ratio' => get_hr_ratio($hitAndRun->snatch->uploaded, $hitAndRun->snatch->downloaded),
'ignore_when_ratio_reach' => HitAndRun::getConfig('ignore_when_ratio_reach', $searchBoxId),
'ignore_when_ratio_reach' => $setting['ignore_when_ratio_reach'],
], $hitAndRun->user->locale);
$update = [
'comment' => $comment
@@ -245,13 +254,13 @@ class HitAndRunRepository extends BaseRepository
return $this->inspectingToReached($hitAndRun, $update, __FUNCTION__);
}
private function reachedBySeedTime(HitAndRun $hitAndRun, $searchBoxId): bool
private function reachedBySeedTime(HitAndRun $hitAndRun, array $setting): 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' => HitAndRun::getConfig('seed_time_minimum', $searchBoxId)
'seed_time_minimum' => $setting['seed_time_minimum'],
], $hitAndRun->user->locale);
$update = [
'comment' => $comment
@@ -288,16 +297,16 @@ class HitAndRunRepository extends BaseRepository
return true;
}
private function unreached(HitAndRun $hitAndRun, $searchBoxId, $disableUser = true): bool
private function unreached(HitAndRun $hitAndRun, array $setting, $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' => HitAndRun::getConfig('seed_time_minimum', $searchBoxId),
'seed_time_minimum' => $setting['seed_time_minimum'],
'share_ratio' => get_hr_ratio($hitAndRun->snatch->uploaded, $hitAndRun->snatch->downloaded),
'torrent_size' => mksize($hitAndRun->torrent->size),
'ignore_when_ratio_reach' => HitAndRun::getConfig('ignore_when_ratio_reach', $searchBoxId)
'ignore_when_ratio_reach' => $setting['ignore_when_ratio_reach']
], $hitAndRun->user->locale);
$update = [
'status' => HitAndRun::STATUS_UNREACHED,
@@ -335,13 +344,14 @@ class HitAndRunRepository extends BaseRepository
//disable user
/** @var User $user */
$user = $hitAndRun->user;
$counts = $user->hitAndRuns()
->where('status', HitAndRun::STATUS_UNREACHED)
->whereHas('torrent.basic_category', function (Builder $query) use ($searchBoxId) {
return $query->where('mode', $searchBoxId);
})
->count();
$disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $searchBoxId);
$countsQuery = $user->hitAndRuns()->where('status', HitAndRun::STATUS_UNREACHED);
if ($setting['diff_in_section']) {
$countsQuery->whereHas('torrent.basic_category', function (Builder $query) use ($setting) {
return $query->where('mode', $setting['search_box_id']);
});
}
$counts = $countsQuery->count();
$disableCounts = HitAndRun::getConfig('ban_user_when_counts_reach', $setting['search_box_id']);
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');
@@ -369,8 +379,8 @@ class HitAndRunRepository extends BaseRepository
public function getStatusStats($uid, $formatted = true)
{
$enableSpecialSection = Setting::get('main.spsct') == 'yes';
if ($enableSpecialSection) {
$diffInSection = HitAndRun::diffInSection();
if ($diffInSection) {
$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";
@@ -379,7 +389,7 @@ class HitAndRunRepository extends BaseRepository
if (!$formatted) {
return $results;
}
if ($enableSpecialSection) {
if ($diffInSection) {
$grouped = [];
foreach ($results as $item) {
$grouped[$item['mode']][$item['status']] = $item['counts'];

View File

@@ -386,7 +386,7 @@ JS;
{
// $where_area = " url = " . sqlesc((int)$imdb_id) ." AND torrents.id != ".sqlesc($id);
$where_area = sprintf('torrents.id in (%s)', implode(',', $otherCopiesIdArr));
$copies_res = sql_query("SELECT torrents.id, torrents.name, torrents.sp_state, torrents.size, torrents.added, torrents.seeders, torrents.leechers, torrents.hr,categories.id AS catid, categories.name AS catname, categories.image AS catimage, sources.name AS source_name, media.name AS medium_name, codecs.name AS codec_name, standards.name AS standard_name, processings.name AS processing_name FROM torrents LEFT JOIN categories ON torrents.category=categories.id LEFT JOIN sources ON torrents.source = sources.id LEFT JOIN media ON torrents.medium = media.id LEFT JOIN codecs ON torrents.codec = codecs.id LEFT JOIN standards ON torrents.standard = standards.id LEFT JOIN processings ON torrents.processing = processings.id WHERE " . $where_area . " ORDER BY torrents.id DESC") or sqlerr(__FILE__, __LINE__);
$copies_res = sql_query("SELECT torrents.id, torrents.name, torrents.sp_state, torrents.size, torrents.added, torrents.seeders, torrents.leechers, torrents.hr,categories.id AS catid, categories.name AS catname, categories.image AS catimage, sources.name AS source_name, media.name AS medium_name, codecs.name AS codec_name, standards.name AS standard_name, processings.name AS processing_name, categories.mode as search_box_id FROM torrents LEFT JOIN categories ON torrents.category=categories.id LEFT JOIN sources ON torrents.source = sources.id LEFT JOIN media ON torrents.medium = media.id LEFT JOIN codecs ON torrents.codec = codecs.id LEFT JOIN standards ON torrents.standard = standards.id LEFT JOIN processings ON torrents.processing = processings.id WHERE " . $where_area . " ORDER BY torrents.id DESC") or sqlerr(__FILE__, __LINE__);
$copies_count = mysql_num_rows($copies_res);
if($copies_count > 0)
@@ -416,7 +416,7 @@ JS;
$sphighlight = get_torrent_bg_color($copy_row['sp_state']);
$sp_info = get_torrent_promotion_append($copy_row['sp_state'], '', false, '', 0, '', $copy_row['__ignore_global_sp_state'] ?? false);
$hrImg = get_hr_img($copy_row);
$hrImg = get_hr_img($copy_row, $copy_row['search_box_id']);
$s .= "<tr". $sphighlight."><td class=\"rowfollow nowrap\" valign=\"middle\" style='padding: 0px'>".return_category_image($copy_row["catid"], "torrents.php?allsec=1&amp;")."</td><td class=\"rowfollow\" align=\"left\"><a href=\"" . htmlspecialchars(get_protocol_prefix() . $BASEURL . "/details.php?id=" . $copy_row["id"]. "&hit=1")."\">" . $dispname ."</a>". $sp_info. $hrImg ."</td>" .
"<td class=\"rowfollow\" align=\"left\">" . rtrim(trim($other_source_info . $other_medium_info . $other_codec_info . $other_standard_info . $other_processing_info), ","). "</td>" .