Some improvements for ratio functionality (#1552)

* Some improvements for ratio functionality

* Update usercp_viewprofile.tpl

* Update functions.php

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2024-07-22 15:02:54 +07:00 committed by GitHub
commit 4a16ad2c51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 38 additions and 15 deletions

View file

@ -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))

View file

@ -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) {

View file

@ -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

View file

@ -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);

View file

@ -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']),

View file

@ -130,6 +130,7 @@ ajax.callback.group_membership = function(data) {
</script>
<!-- ENDIF / IS_AM -->
<!-- IF #RATIO_ENABLED -->
<!-- IF TRAF_STATS || $bb_cfg['ratio_null_enabled'] -->
<script type="text/javascript">
ajax.index_data = function(mode) {
@ -151,6 +152,7 @@ ajax.callback.index_data = function(data) {
};
</script>
<!-- ENDIF -->
<!-- ENDIF -->
<!-- IF SHOW_PASSKEY -->
<script type="text/javascript">
@ -384,6 +386,7 @@ ajax.callback.index_data = function(data) {
</td>
</tr>
<!-- IF #RATIO_ENABLED -->
<tr id="bt_user_ratio" <!-- IF TRAF_STATS -->style="display: none;"<!-- ENDIF -->>
<th>{L_USER_RATIO}:</th>
<td>
@ -415,6 +418,7 @@ ajax.callback.index_data = function(data) {
</td>
</tr>
<!-- ENDIF -->
<!-- ENDIF -->
<!-- IF LOCATION -->
<tr>