From 0eba082d414d0c2b731986065406f39a3fe8b99e Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Fri, 19 Jul 2024 14:25:47 +0700 Subject: [PATCH] Added ability to reset ratio (#1545) * Minor improvements * Update index_data.php * Updated * Update usercp_viewprofile.tpl * Update mysql.sql * Update main.php * Update CHANGELOG.md --- CHANGELOG.md | 1 + install/sql/mysql.sql | 1 + library/ajax/index_data.php | 33 +++++++++++++++++++ library/config.php | 4 +++ library/includes/ucp/viewprofile.php | 6 ++++ library/language/source/main.php | 8 +++++ .../templates/default/usercp_viewprofile.tpl | 8 ++++- tracker.php | 2 +- 8 files changed, 61 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7113e4c65..e0925a381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Release 2.4.4 🦩 ([belomaxorka](https://github.com/belomaxorka)) - CWE-502 Fixed: Deserialization of untrusted data ([belomaxorka](https://github.com/belomaxorka)) - Create tech stack docs (techstack.yml and techstack.md) [\#1521](https://github.com/torrentpier/torrentpier/pull/1521), [\#1522](https://github.com/torrentpier/torrentpier/pull/1522) ([belomaxorka](https://github.com/belomaxorka)) +- Added ability to reset ratio [\#1545](https://github.com/torrentpier/torrentpier/pull/1545) ([belomaxorka](https://github.com/belomaxorka)) - Fixed broken "Disable Board" function [\#1529](https://github.com/torrentpier/torrentpier/pull/1529) ([belomaxorka](https://github.com/belomaxorka)) - Fixed seed bonus accrual [\#1518](https://github.com/torrentpier/torrentpier/pull/1518) ([belomaxorka](https://github.com/belomaxorka)) - [BETA] Added emojis support 😄😁 [\#1514](https://github.com/torrentpier/torrentpier/pull/1514) ([belomaxorka](https://github.com/belomaxorka)) diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index f1d34711e..a618920d7 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -424,6 +424,7 @@ CREATE TABLE IF NOT EXISTS `bb_bt_users` `up_release_yesterday` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', `up_bonus_yesterday` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0', `points_yesterday` FLOAT(16, 2) UNSIGNED NOT NULL DEFAULT '0.00', + `ratio_nulled` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`user_id`), UNIQUE KEY `auth_key` (`auth_key`) ) diff --git a/library/ajax/index_data.php b/library/ajax/index_data.php index 93850db51..21de5d1bb 100644 --- a/library/ajax/index_data.php +++ b/library/ajax/index_data.php @@ -89,6 +89,39 @@ switch ($mode) { $datastore->rm('moderators'); break; + case 'null_ratio': + if (!$bb_cfg['ratio_null_enabled']) { + $this->ajax_die($lang['MODULE_OFF']); + } + if (empty($this->request['confirmed'])) { + $this->prompt_for_confirm($lang['BT_NULL_RATIO_ALERT']); + } + + $user_id = (int)$this->request['user_id']; + if (!IS_ADMIN && $user_id != $userdata['user_id']) { + $this->ajax_die($lang['NOT_AUTHORISED']); + } + + $btu = get_bt_userdata($user_id); + $ratio_nulled = (bool)$btu['ratio_nulled']; + $user_ratio = get_bt_ratio($btu); + + if (($user_ratio === null) && !IS_ADMIN) { + $this->ajax_die($lang['BT_NULL_RATIO_NONE']); + } + if ($ratio_nulled && !IS_ADMIN) { + $this->ajax_die($lang['BT_NULL_RATIO_AGAIN']); + } + if (($user_ratio >= $bb_cfg['ratio_to_null']) && !IS_ADMIN) { + $this->ajax_die(sprintf($lang['BT_NULL_RATIO_NOT_NEEDED'], $bb_cfg['ratio_to_null'])); + } + + $ratio_nulled_sql = !IS_ADMIN ? ', ratio_nulled = 1' : ''; + DB()->query("UPDATE " . BB_BT_USERS . " SET u_up_total = 0, u_down_total = 0, u_up_release = 0, u_up_bonus = 0 $ratio_nulled_sql WHERE user_id = " . $user_id); + CACHE('bb_cache')->rm('btu_' . $user_id); + $this->ajax_die($lang['BT_NULL_RATIO_SUCCESS']); + break; + case 'get_traf_stats': $user_id = (int)$this->request['user_id']; $btu = get_bt_userdata($user_id); diff --git a/library/config.php b/library/config.php index 5f27741ef..f1af7cae7 100644 --- a/library/config.php +++ b/library/config.php @@ -138,6 +138,10 @@ $bb_cfg['show_dl_status_in_forum'] = true; $bb_cfg['show_tor_info_in_dl_list'] = true; $bb_cfg['allow_dl_list_names_mode'] = true; +// Null ratio +$bb_cfg['ratio_null_enabled'] = true; +$bb_cfg['ratio_to_null'] = $bb_cfg['bt_min_ratio_allow_dl_tor']; // 0.3 + // Days to keep torrent registered $bb_cfg['seeder_last_seen_days_keep'] = 0; // Max time storing for the last seen peer status $bb_cfg['seeder_never_seen_days_keep'] = 0; // Max time for storing status - Never seen diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php index f3c0a1566..45d5a8ea9 100644 --- a/library/includes/ucp/viewprofile.php +++ b/library/includes/ucp/viewprofile.php @@ -74,6 +74,12 @@ if (bf($profiledata['user_opt'], 'user_opt', 'dis_sig')) { $signature = bbcode2html($signature); } +// Null ratio +if ($bb_cfg['ratio_null_enabled']) { + $btu = get_bt_userdata($profiledata['user_id']); + $template->assign_vars(array('NULLED_RATIO' => (bool)$btu['ratio_nulled'])); +} + // Ban information if ($banInfo = getBanInfo((int)$profiledata['user_id'])) { $template->assign_block_vars('ban', [ diff --git a/library/language/source/main.php b/library/language/source/main.php index 600b251e8..ca3fa10d9 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -3060,3 +3060,11 @@ $lang['EMAILER_SUBJECT'] = [ 'USER_WELCOME' => 'Welcome to the site %s', 'USER_WELCOME_INACTIVE' => 'Welcome to the site %s', ]; + +// Null ratio +$lang['BT_NULL_RATIO'] = 'Reset ratio'; +$lang['BT_NULL_RATIO_NONE'] = 'You don\'t have a ratio'; +$lang['BT_NULL_RATIO_ALERT'] = "Attention!\n\nAre you sure you want to reset your ratio?"; +$lang['BT_NULL_RATIO_AGAIN'] = 'You have already reset your ratio!'; +$lang['BT_NULL_RATIO_NOT_NEEDED'] = 'You have a good ratio. Reset is possible only with a ratio less than %s'; +$lang['BT_NULL_RATIO_SUCCESS'] = 'The ratio has been reset successfully!'; diff --git a/styles/templates/default/usercp_viewprofile.tpl b/styles/templates/default/usercp_viewprofile.tpl index 642847303..7b64e4d0b 100644 --- a/styles/templates/default/usercp_viewprofile.tpl +++ b/styles/templates/default/usercp_viewprofile.tpl @@ -130,7 +130,7 @@ ajax.callback.group_membership = function(data) { - +