Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Active Transfers Block [TTv3]
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Mods in Progress

2020-12-01 05:36:01
Active Transfers. This is a back-port of a AJAX feature I rolled out to my community in the summer. See if this works for you and post the results in a comment.

What this does is displays current downloads for the current logged-in user. It displays:

- Torrent link
- Client Speed
- File Size

While this is actually interactive and automatically updates, you simply wont get that ability with a plain old block, but this should work for you anyway.

Save as activetransfers_block.php and upload to /blocks


<?php
// TTv3 Active Transfers - Block
function calc_speed($b) {
   if ($b < 1024) return round($b,2) . 'B/Sec';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'KB/Sec';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'MB/Sec';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'GB/Sec';
   $b /= 1024.0;
   return round($b,2) . 'TB';
}
function calc_size($b) {
   if ($b < 1024) return round($b,2) . 'B';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'KB';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'MB';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'GB';
   $b /= 1024.0;
   return round($b,2) . 'TB';
}
if (get_user_class() >= 7) {
   begin_block(T_("ACTIVE_TRANSFERS"));
   $expires = 1200;
   if (($rows = $TTCache->Get("activetransfers_block", $expires)) === false) {
       $res = SQL_Query_exec("SELECT (SUM(peers.downloaded)) / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(peers.started)) AS speed, peers.seeder, peers.id, peers.connectable, users.id, peers.started, torrents.id AS torrentid, torrents.name, torrents.size, peers.to_go FROM peers LEFT JOIN torrents ON torrents.id = peers.id LEFT JOIN users ON peers.id = users.id WHERE peers.id = $CURUSER[id] AND peers.seeder = 'no' GROUP BY peers.started DESC LIMIT 6");
       foreach (mysqli_fetch_assoc($res) as $row) {
           $rows = $row;
           if (array_key_exists('torrentid', $row)) {
               print("Active Transfers: <div><a href='torrents-details.php?id=$row[torrentid]'>$row[name]</a></div><div>Speed: " . calc_speed($row['speed']) . ", Size: " . calc_size($row['size']) . "</div>");
           } else {
               echo T_("NO_ACTIVE_TRANSFERS");
           }
       }
       $TTCache->Set("activetransfers_block", $rows, $expires);
   }
   end_block();
}
?>


Add to /languages/english.php


$LANG["NO_ACTIVE_TRANSFERS"] = "No current transfers.";
$LANG["ACTIVE_TRANSFERS"] = "Active Transfers.";
2020-12-05 16:12:01
Hello and thank you for sharing but the block doesn't show anything ???


[ATTACH type="full"]5990[/ATTACH]
1607184633199.png
1607184633199.png
2020-12-05 17:53:54
"niki, post: 69658, member: 20338":

Hello and thank you for sharing but the block doesn't show anything ???


[ATTACH type="full" alt="1607184633199.png"]5990[/ATTACH]


[ATTACH type="full"]5992[/ATTACH]

Try this


<?php
// TTv3 Active Transfers - Block
function calc_speed($b) {
   if ($b < 1024) return round($b,2) . 'B/Sec';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'KB/Sec';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'MB/Sec';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'GB/Sec';
   $b /= 1024.0;
   return round($b,2) . 'TB';
}
function calc_size($b) {
   if ($b < 1024) return round($b,2) . 'B';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'KB';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'MB';
   $b /= 1024.0;
   if ($b < 1024) return round($b,2) . 'GB';
   $b /= 1024.0;
   return round($b,2) . 'TB';
}
if (get_user_class() >= 7) {
   begin_block(T_("ACTIVE_TRANSFERS"));
   $expires = 1200;
   if (($rows = $TTCache->Get("activetransfers_block", $expires)) === false) {
       $res = SQL_Query_exec("SELECT (SUM(peers.downloaded)) / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(peers.started)) AS speed, peers.seeder, peers.id, peers.connectable, users.id, peers.started, torrents.id AS torrentid, torrents.name, torrents.size, peers.to_go FROM peers LEFT JOIN torrents ON torrents.id = peers.id LEFT JOIN users ON peers.id = users.id WHERE peers.id = $CURUSER[id] AND peers.seeder = 'no' GROUP BY peers.started DESC LIMIT 6");
       while ($row = mysqli_fetch_assoc($res)) {
           $rows = $row;
           if (array_key_exists('torrentid', $row)) {
               print("Active Transfers: <div><a href='torrents-details.php?id=$row[torrentid]'>$row[name]</a></div><div>Speed: " . calc_speed($row['speed']) . ", Size: " . calc_size($row['size']) . "</div>");
           } else {
               echo T_("NO_ACTIVE_TRANSFERS");
           }
       }
       $TTCache->Set("activetransfers_block", $rows, $expires);
   }
   end_block();
}
?>
speed.png
speed.png
2020-12-05 18:36:42
I've just changed and the block still doesn't show anything, sorry.
2020-12-05 19:15:12
Works for me, i dunno. Maybe that cache stuff is issue?
2020-12-06 09:37:25
Is this file in the cache folder might help locate the problem niki
activetransfers_block.cache

You can always try the query at top of index.php to test results are coming through I would of thought it would throw a error if not
$res = SQL_Query_exec("SELECT (SUM(peers.downloaded)) / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(peers.started)) AS speed, peers.seeder, peers.id, peers.connectable, users.id, peers.started, torrents.id AS torrentid, torrents.name, torrents.size, peers.to_go FROM peers LEFT JOIN torrents ON torrents.id = peers.id LEFT JOIN users ON peers.id = users.id WHERE peers.id = $CURUSER[id] AND peers.seeder = 'no' GROUP BY peers.started DESC LIMIT 6");
       while ($row = mysqli_fetch_assoc($res)) {
           $rows = $row;
           if (array_key_exists('torrentid', $row)) {
               echo 'something happened';
           } else {
               echo T_("NO_ACTIVE_TRANSFERS");
           }
       }
2020-12-06 12:17:23
I've just changed and the block still doesn't show anything, sorry.
2020-12-06 17:33:03
Try changing peers.seeder = ‘no’

to

peers.seeder = ‘yes’

Now you are showing all torrents you are currently seeding, with speeds etc.

If that fails, tell us or screenshot what HeidiSQL says.
2021-01-22 02:15:38
II played with this and all I get in the cache file is  b:0;. Not sure why, but I cant make this work either, hmmmm
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2021-01-22 02:17:26
2021-01-23 02:39:09
Turns out foreach() needs to be replaced with while() and i would get rid of that silly file caching, when FPM or opcache will handle it properly. Do you guys need a rewrite?
2021-04-05 14:14:10
Obsolete. This is very outdated and has been improved with progress bar % and client-like transfer list with users with new SQL queries
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728