diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67bfa000b..d9b254329 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@
- Bring back forum description in `viewforum.php` [\#1540](https://github.com/torrentpier/torrentpier/pull/1540) ([belomaxorka](https://github.com/belomaxorka))
- Some security improvements 🔑 [\#1503](https://github.com/torrentpier/torrentpier/pull/1503), [\#1505](https://github.com/torrentpier/torrentpier/pull/1505) ([belomaxorka](https://github.com/belomaxorka))
- Some improvements for integrity checker [\#1501](https://github.com/torrentpier/torrentpier/pull/1501) ([belomaxorka](https://github.com/belomaxorka))
+- Some improvements for ratio functionality [\#1552](https://github.com/torrentpier/torrentpier/pull/1552) ([belomaxorka](https://github.com/belomaxorka))
- Hide in topic: Added country hiding [\#1535](https://github.com/torrentpier/torrentpier/pull/1535) ([belomaxorka](https://github.com/belomaxorka))
- Hide vote button in topic for guests [\#1507](https://github.com/torrentpier/torrentpier/pull/1507) ([belomaxorka](https://github.com/belomaxorka))
- Word censor code optimization [\#1537](https://github.com/torrentpier/torrentpier/pull/1537) ([belomaxorka](https://github.com/belomaxorka))
diff --git a/bt/announce.php b/bt/announce.php
index 13e572f86..9a8648a35 100644
--- a/bt/announce.php
+++ b/bt/announce.php
@@ -225,8 +225,11 @@ if ($lp_info) {
}
// Ratio limits
- if ((TR_RATING_LIMITS || $bb_cfg['tracker']['limit_concurrent_ips']) && !$stopped) {
- $user_ratio = ($row['u_down_total'] && $row['u_down_total'] > MIN_DL_FOR_RATIO) ? ($row['u_up_total'] + $row['u_up_release'] + $row['u_up_bonus']) / $row['u_down_total'] : 1;
+ if ((RATIO_ENABLED || $bb_cfg['tracker']['limit_concurrent_ips']) && !$stopped) {
+ $user_ratio = get_bt_ratio($row);
+ if ($user_ratio === null) {
+ $user_ratio = 1;
+ }
$rating_msg = '';
if (!$seeder) {
diff --git a/common.php b/common.php
index baa74ce5f..c75cfa9ee 100644
--- a/common.php
+++ b/common.php
@@ -291,6 +291,20 @@ function make_rand_str(int $length = 10): string
return $randomString;
}
+/**
+ * Calculates user ratio
+ *
+ * @param array $btu
+ * @return float|null
+ */
+function get_bt_ratio(array $btu): ?float
+{
+ return
+ (!empty($btu['u_down_total']) && $btu['u_down_total'] > MIN_DL_FOR_RATIO)
+ ? round((($btu['u_up_total'] + $btu['u_up_release'] + $btu['u_up_bonus']) / $btu['u_down_total']), 2)
+ : null;
+}
+
function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false, $timeout = false)
{
if ($timeout) {
@@ -345,6 +359,11 @@ function sys(string $param)
}
}
+/**
+ * Some shared defines
+ */
+define('RATIO_ENABLED', TR_RATING_LIMITS && MIN_DL_FOR_RATIO > 0);
+
// Initialization
if (!defined('IN_TRACKER')) {
// Init board
diff --git a/library/ajax/index_data.php b/library/ajax/index_data.php
index 21de5d1bb..e619ff81c 100644
--- a/library/ajax/index_data.php
+++ b/library/ajax/index_data.php
@@ -90,7 +90,7 @@ switch ($mode) {
break;
case 'null_ratio':
- if (!$bb_cfg['ratio_null_enabled']) {
+ if (!$bb_cfg['ratio_null_enabled'] || !RATIO_ENABLED) {
$this->ajax_die($lang['MODULE_OFF']);
}
if (empty($this->request['confirmed'])) {
@@ -123,6 +123,10 @@ switch ($mode) {
break;
case 'get_traf_stats':
+ if (!RATIO_ENABLED) {
+ $this->ajax_die($lang['MODULE_OFF']);
+ }
+
$user_id = (int)$this->request['user_id'];
$btu = get_bt_userdata($user_id);
$profiledata = get_userdata($user_id);
diff --git a/library/includes/functions.php b/library/includes/functions.php
index 6a4ef5aae..aeb9e04d2 100644
--- a/library/includes/functions.php
+++ b/library/includes/functions.php
@@ -844,14 +844,6 @@ function get_bt_userdata($user_id)
return $btu;
}
-function get_bt_ratio($btu): ?float
-{
- return
- (!empty($btu['u_down_total']) && $btu['u_down_total'] > MIN_DL_FOR_RATIO)
- ? round((($btu['u_up_total'] + $btu['u_up_release'] + $btu['u_up_bonus']) / $btu['u_down_total']), 2)
- : null;
-}
-
function show_bt_userdata($user_id): void
{
global $template;
@@ -868,8 +860,8 @@ function show_bt_userdata($user_id): void
'DOWN_TOTAL' => humn_size($btu['u_down_total']),
'DOWN_TOTAL_BYTES' => $btu['u_down_total'],
'USER_RATIO' => get_bt_ratio($btu),
- 'MIN_DL_FOR_RATIO' => humn_size(MIN_DL_FOR_RATIO),
- 'MIN_DL_BYTES' => MIN_DL_FOR_RATIO,
+ 'MIN_DL_FOR_RATIO' => humn_size((int)MIN_DL_FOR_RATIO),
+ 'MIN_DL_BYTES' => (int)MIN_DL_FOR_RATIO,
'AUTH_KEY' => $btu['auth_key'],
'TD_DL' => humn_size($btu['down_today']),
diff --git a/styles/templates/default/usercp_viewprofile.tpl b/styles/templates/default/usercp_viewprofile.tpl
index 7b64e4d0b..a8387dd19 100644
--- a/styles/templates/default/usercp_viewprofile.tpl
+++ b/styles/templates/default/usercp_viewprofile.tpl
@@ -130,6 +130,7 @@ ajax.callback.group_membership = function(data) {
+
+