Something I'm working on but have had in effect for a while, will post off here as i get items automatically updating speeds without refresh - next up.
ajax_update_torrentspeed.php
functions.php find
Add after
functions is old code as new one is different, but these changes pass over.
Problem I'm having is getting those speeds changing without refreshing, not sure if its a jQuery problem or a issue with asynch requests but I'm working on it. Once working I just make work on old torrenttable
ajax_update_torrentspeed.php
<?
// AJAX Dynamic Torrent Speeds - BETA - May 26, 2020
// Retrieve peers > calc downloaded/uploaded = byte sum > convert bytes > retrieve user in peer swarm by userid
require_once 'dbConfig.php';
$torrentid = isset($_GET['id'])?intval($_GET['id']):0;
try {
$conn = new PDO("mysql:host={$dbHost};dbname={$dbName};charset=utf8", $dbUsername, $dbPassword);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch (PDOException $e) {
die('Unable to connect to database');
}
$stmt = $conn->prepare("SELECT (SUM(peers.downloaded)) / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(peers.started)) AS totalspeed, users.avatar_thumb AS avatar, peers.seeder, users.username, users.id, peers.userid FROM peers LEFT JOIN users ON peers.userid = users.id WHERE peers.torrent = :torrentid AND peers.seeder = 'no' ORDER BY peers.started ASC");
$stmt->bindParam(":torrentid", $torrentid, PDO::PARAM_INT);
$stmt->execute();
$userData = array();
if ($stmt->rowCount() > 0) {
$usersactive = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($usersactive as $row => $data) {
$data['totalspeed'] = $row['totalspeed'];
$data['avatar'] = $row['avatar'];
$data['id'] = $row['id'];
$data['username'] = $row['username'];
array_push($userData, $usersactive);
}
}
echo str_replace('-', '', json_encode($usersactive, JSON_UNESCAPED_SLASHES)); // Bugfix: Removed dash in torrent speeds - July 4, 2020
?>
functions.php find
foreach ($cols as $col) {
switch ($col) {
case 'category':
Add after
// Get torrent speed - AJAX
if ($CURUSER) {
?>
<script>
$(document).ready(function () {
$.ajax({
url: "ajax_update_torrentspeed.php?id=<? echo $id; ?>",
method: "GET",
dataType: 'JSON',
success: function (data) {
var html_to_append = '';
$.each(data, function (i, item) {
html_to_append +=
'<span style="text-transform:capitalize">' +
formatBytesTorrentSpeed(item.totalspeed) +
'</span><a href="/user/?id=' +
item.id + '"><img src="' + item.avatar + '" style="height:45px;width:45px;border-radius:50%;margin-left:5px;vertical-align:middle;position:relative;z-index:10005;border: 2px solid #FFF;" /></a>';
});
// Append torrent ID to tag for loop
$("#torrentspeed-<? echo $id; ?>").html(html_to_append);
}
});
});
</script>
<?
// Get current peers for this torrent by Avatar - Restyled - New index item - July 4, 2020 - text-align works! float:right cuts off box
if ($result2["external"] != "yes" && $result2["leechers"] >= 1){
$getpeer = SQL_Query_exec("SELECT seeder, torrent, started FROM peers WHERE seeder = 'no' AND torrent = $id ORDER BY started ASC");
$a = mysql_fetch_assoc($getpeer);
if (empty($row['torrent']))
$totalspeed = "<div style='text-align:right;margin-top:-27px;position:relative;z-index:950000'>
<span id='torrentspeed-$id' style='box-shadow:inset 0 0 10px #D42128;color:#FFF;background:#ED2324;border-radius:4px;padding-left:7px;padding-right:6px;padding-top:4px;padding-bottom:3px'></span>
</div>";
} else {
$totalspeed = ""; // no active peer for this torrent
}
} // end if $CURUSER
functions is old code as new one is different, but these changes pass over.
Problem I'm having is getting those speeds changing without refreshing, not sure if its a jQuery problem or a issue with asynch requests but I'm working on it. Once working I just make work on old torrenttable