From 66b9b7bdc4bba7821a6279e00717c68136bd3279 Mon Sep 17 00:00:00 2001
From: Roman Kelesidis
Date: Sat, 27 Jan 2024 11:04:10 +0700
Subject: [PATCH] Fixed download counter for torrents (#1346)
* Fixed download counter for torrents
* Updated
* Updated
* Update CHANGELOG.md
---
CHANGELOG.md | 1 +
admin/admin_ug_auth.php | 5 +++--
library/includes/functions.php | 9 +++++----
styles/templates/default/tracker.tpl | 4 ++--
styles/templates/default/viewforum.tpl | 4 ++--
tracker.php | 7 +++++--
viewforum.php | 6 ++++--
7 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ced704431..adfeeff10 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@
- Some enhancements in default template (Part 2) [\#1322](https://github.com/torrentpier/torrentpier/pull/1322) ([belomaxorka](https://github.com/belomaxorka))
- Set response code in some cases [\#1319](https://github.com/torrentpier/torrentpier/pull/1319) ([belomaxorka](https://github.com/belomaxorka))
- Fixed auth(): empty $f_access [\#1329](https://github.com/torrentpier/torrentpier/pull/1329) ([belomaxorka](https://github.com/belomaxorka))
+- Fixed download counter for torrents [\#1346](https://github.com/torrentpier/torrentpier/pull/1346) ([belomaxorka](https://github.com/belomaxorka))
- Fixed HTTP 500 while cron running in server-side [\#1321](https://github.com/torrentpier/torrentpier/pull/1321) ([belomaxorka](https://github.com/belomaxorka))
- Sending debug errors to us 🌚 via Telegram bot [\#1323](https://github.com/torrentpier/torrentpier/pull/1323) ([belomaxorka](https://github.com/belomaxorka))
- Don't update downloads counter if attachment not exists [\#1345](https://github.com/torrentpier/torrentpier/pull/1345) ([belomaxorka](https://github.com/belomaxorka))
diff --git a/admin/admin_ug_auth.php b/admin/admin_ug_auth.php
index 06c8286b1..0964a66a2 100644
--- a/admin/admin_ug_auth.php
+++ b/admin/admin_ug_auth.php
@@ -166,12 +166,13 @@ elseif ($submit && $mode == 'group' && (!empty($_POST['auth']) && is_array($_POS
if ($mode == 'user' && (!empty($_POST['username']) || $user_id)) {
$page_cfg['quirks_mode'] = true;
+ $this_userdata = false;
if (!empty($_POST['username'])) {
$this_userdata = get_userdata($_POST['username'], true);
- $user_id = $this_userdata ? $this_userdata['user_id'] : false;
- } else {
+ } elseif (!empty($user_id)) {
$this_userdata = get_userdata($user_id);
}
+
if (!$this_userdata) {
bb_die($lang['NO_SUCH_USER']);
}
diff --git a/library/includes/functions.php b/library/includes/functions.php
index 35d3b10c3..0c0172a8a 100644
--- a/library/includes/functions.php
+++ b/library/includes/functions.php
@@ -957,20 +957,21 @@ function clean_username($username)
* @param bool $allow_guest
* @return mixed
*/
-function get_userdata($u, bool $is_name = false, bool $allow_guest = false, bool $profile_view = false)
+function get_userdata(int|string $u, bool $is_name = false, bool $allow_guest = false, bool $profile_view = false)
{
if (empty($u)) {
return false;
}
if (!$is_name) {
- if ((int)$u === GUEST_UID && $allow_guest) {
+ $u = (int)$u;
+ if ($u === GUEST_UID && $allow_guest) {
if ($u_data = CACHE('bb_cache')->get('guest_userdata')) {
return $u_data;
}
}
- $where_sql = "WHERE user_id = " . (int)$u;
+ $where_sql = "WHERE user_id = " . $u;
} else {
$where_sql = "WHERE username = '" . DB()->escape(clean_username($u)) . "'";
}
@@ -993,7 +994,7 @@ function get_userdata($u, bool $is_name = false, bool $allow_guest = false, bool
return $u_data;
}
-function make_jumpbox()
+function make_jumpbox(): void
{
global $datastore, $template, $bb_cfg;
diff --git a/styles/templates/default/tracker.tpl b/styles/templates/default/tracker.tpl
index 5c467009d..2952a80a6 100644
--- a/styles/templates/default/tracker.tpl
+++ b/styles/templates/default/tracker.tpl
@@ -415,8 +415,8 @@ ajax.callback.view_post = function(data) {
|
{tor.VIEWS}
-
- {tor.COMPLETED}
+
+ {tor.DOWNLOADED}
diff --git a/styles/templates/default/viewforum.tpl b/styles/templates/default/viewforum.tpl
index 293de020f..ea45123e6 100644
--- a/styles/templates/default/viewforum.tpl
+++ b/styles/templates/default/viewforum.tpl
@@ -480,8 +480,8 @@ td.topic_id { cursor: pointer; }
{t.VIEWS}
-
- {t.tor.COMPL_CNT}
+
+ {t.tor.DOWNLOADED}
diff --git a/tracker.php b/tracker.php
index e84715f73..3c38198b4 100644
--- a/tracker.php
+++ b/tracker.php
@@ -62,6 +62,7 @@ $users_tbl = BB_USERS . ' u';
$tracker_tbl = BB_BT_TRACKER . ' tr';
$tr_snap_tbl = BB_BT_TRACKER_SNAP . ' sn';
$dl_stat_tbl = BB_BT_DLSTATUS . ' dl';
+$attach_desc_tbl = BB_ATTACHMENTS_DESC . ' ad';
//
// Search options
@@ -654,7 +655,7 @@ if ($allowed_forums) {
$select = "
SELECT
tor.topic_id, tor.post_id, tor.attach_id, tor.size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.tor_status, tor.tor_type,
- t.topic_title, t.topic_time, t.topic_replies, t.topic_views, sn.seeders, sn.leechers, tor.info_hash, tor.info_hash_v2
+ t.topic_title, t.topic_time, t.topic_replies, t.topic_views, sn.seeders, sn.leechers, tor.info_hash, tor.info_hash_v2, ad.download_count
";
$select .= (!$hide_speed) ? ", sn.speed_up, sn.speed_down" : '';
$select .= (!$hide_forum) ? ", tor.forum_id" : '';
@@ -677,6 +678,7 @@ if ($allowed_forums) {
LEFT JOIN $dl_stat_tbl ON(dl.topic_id = tor.topic_id AND dl.user_id = $user_id)
" : '';
$from .= "LEFT JOIN $tr_snap_tbl ON(sn.topic_id = tor.topic_id)";
+ $from .= "LEFT JOIN $attach_desc_tbl ON(ad.attach_id = tor.attach_id)";
// WHERE
$where = "
@@ -757,7 +759,8 @@ if ($allowed_forums) {
'SEEDS' => $seeds ?: 0,
'SEEDS_TITLE' => $seeds ? $lang['SEEDERS'] : ($lang['SEED_NOT_SEEN'] . ":\n " . (($s_last) ? bb_date($s_last, $date_format) : $lang['NEVER'])),
'LEECHS' => $leechs ?: 0,
- 'COMPLETED' => $compl ?: 0,
+ 'COMPLETED' => declension($compl ?: 0, 'times'),
+ 'DOWNLOADED' => $tor['download_count'],
'REPLIES' => $tor['topic_replies'],
'VIEWS' => $tor['topic_views'],
'ADDED_RAW' => $tor['reg_time'],
diff --git a/viewforum.php b/viewforum.php
index c24bc109a..60655cd9a 100644
--- a/viewforum.php
+++ b/viewforum.php
@@ -287,7 +287,7 @@ if ($forum_data['allow_reg_tracker']) {
$select_tor_sql = ',
bt.auth_key, tor.info_hash, tor.info_hash_v2, tor.size AS tor_size, tor.reg_time, tor.complete_count, tor.seeder_last_seen, tor.attach_id, tor.tor_status, tor.tor_type,
- sn.seeders, sn.leechers
+ sn.seeders, sn.leechers, ad.download_count
';
$select_tor_sql .= ($join_dl) ? ', dl.user_status AS dl_status' : '';
@@ -295,6 +295,7 @@ if ($forum_data['allow_reg_tracker']) {
LEFT JOIN " . BB_BT_TORRENTS . " tor ON(t.topic_id = tor.topic_id)
LEFT JOIN " . BB_BT_USERS . " bt ON(bt.user_id = {$userdata['user_id']})
LEFT JOIN " . BB_BT_TRACKER_SNAP . " sn ON(tor.topic_id = sn.topic_id)
+ LEFT JOIN " . BB_ATTACHMENTS_DESC . " ad ON(tor.attach_id = ad.attach_id)
";
$join_tor_sql .= ($join_dl) ? " LEFT JOIN " . BB_BT_DLSTATUS . " dl ON(dl.user_id = {$userdata['user_id']} AND dl.topic_id = t.topic_id)" : '';
}
@@ -477,7 +478,8 @@ foreach ($topic_rowset as $topic) {
'SEEDERS' => (int)$topic['seeders'],
'LEECHERS' => (int)$topic['leechers'],
'TOR_SIZE' => humn_size($topic['tor_size'], 1),
- 'COMPL_CNT' => (int)$topic['complete_count'],
+ 'COMPL_CNT' => declension((int)$topic['complete_count'], 'times'),
+ 'DOWNLOADED' => (int)$topic['download_count'],
'ATTACH_ID' => $topic['attach_id'],
'MAGNET' => $tor_magnet,
]);