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
Site torrent catalog
Controls ·  Search New posts · Mark unread

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

2020-08-25 03:47:05
Hello and thank you storrents2020 I'm on torrent trader v.2.8 in mysqli, thank you in advance ;)
2020-08-25 04:05:52
I can't seem to locate the mod, but i can design by eye. Do you want that table in that design?
2020-08-25 14:11:33
yes thank you you can do it if possible :D
2020-08-26 06:14:13
Query is built, it didn't take too long. i went pure SQL on this one to learn a few things. Hope thats okay on your DB server if this is a busy page.

SELECT (SUM(p.downloaded)) / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(p.started)) AS totalspeed, (SELECT uploaded / downloaded FROM users LIMIT 1) AS ratio, (SELECT torrentid % 100 / userid FROM completed LIMIT 1) AS completed, u.username, u.uploaded, u.downloaded FROM peers p LEFT JOIN users u ON u.id = p.userid LEFT JOIN completed c ON u.id = c.userid ORDER BY ratio DESC LIMIT 5


That query will produce (for you different) results:

[ATTACH type="full" alt="Demo.png"]5805[/ATTACH]

Making code now
Demo.png
Demo.png
2020-08-26 07:32:31
Give this a try. Im not sure how your template is setup so this is barebones. I used SQL_Query_exec() in case you have mysqli enabled in mysql.class.php
I added some type casting to show what is doing what (string = mixed chars that are not INT or BOOL) (int = numbers) (bool = true/false, 1/0 etc)

For the inline CSS in the tags, adjust [color=rgb(226, 80, 65)]padding-right: 50px [/color][color=rgb(209, 213, 216)]to your page width. [/color]


<?php
// Top 5 Seeders
require_once("backend/functions.php");
dbconn(false); // Set to true to trigger clean interval check - it may help these stats
stdhead("Top 5 Seeders");

function formatBytes($bytes, $precision = 2) {
   $units = array('B/sec', 'KB/sec', 'MB/sec', 'GB/sec', 'TB/sec');
   $bytes = max($bytes, 0);
   $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
   $pow = min($pow, count($units) - 1);
   $bytes /= pow(1024, $pow);
   return round($bytes, $precision) . ' ' . $units[$pow];
}

$res = SQL_Query_exec("SELECT (SUM(p.downloaded)) / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(p.started)) AS totalspeed, (SELECT uploaded / downloaded FROM users LIMIT 1) AS ratio, (SELECT torrentid % 100 / userid FROM completed LIMIT 1) AS completed, u.username, u.uploaded, u.downloaded FROM peers p LEFT JOIN users u ON u.id = p.userid LEFT JOIN completed c ON u.id = c.userid WHERE (p.seeder = 'yes') ORDER BY ratio DESC LIMIT 5");

while ($row = mysqli_fetch_assoc($res)): ?>

<h1>Top 5 Seeders</h1>

<div style="float:left;padding-right:50px">
  <label style="font-weight:bold">Username</label>
  <p>          
     <?=(string)htmlspecialchars($row['username'])?>
  </p>
</div>
<div style="float:left;padding-right:50px">
  <label style="font-weight:bold">Uploaded</label>
  <p>          
     <?=(string)mksize($row['uploaded'])?>
  </p>
</div>
<div style="float:left;padding-right:50px">
  <label style="font-weight:bold">Speed</label>
  <p>          
     <?=(string)formatBytes($row['totalspeed'])?>
  </p>
</div>
<div style="float:left;padding-right:50px">
  <label style="font-weight:bold">Ratio</label>
  <p>          
     <?=(int)number_format($row['ratio'])?>
  </p>
</div>
<div style="float:left;padding-right:50px">
  <label style="font-weight:bold">Finished %</label>
  <p>          
     <?=(int)$row['completed']?>%
  </p>
</div>
<div style="clear:both"></div>

<?php endwhile; stdfoot(); ?>


More can be done though, just so you know. Such as 'connectable yes/no', 'last announce time', etc etc tons of stuff.
2020-08-26 14:51:47
Hello and thank you for the support but when I put the code I have a blank page - perhaps badly place it in the file torrent-detail.php I join you my file torrent-detail.php
torrents-details.zip
Download
2020-08-26 22:18:35
Absolutely, I was wondering about that myself. I will turn on errors too for you in script, just in case. Do you have a style for this? It’s just a 10px radius border with 3 colours and border outlines with maybe 20px of padding in each “cell”.
2020-08-26 23:06:24
Slam this wherever you like. try it out. I tested this on a test machine with no users, so I may have missed something. Its most of the catalog code with some bits stripped out. pretty generic and could be cleaned up further. Lots of stuff that dont need to be there, but im limited right now on time, so I just copied this code and started stripping it apart.  if this dont work, I can try testing it against a live server this weekend and see what I can come up with.
begin_frame("TOP SEEDERS");
$ret = SQL_Query_exec("SELECT seeder, ip, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id AND seeder ='yes' ORDER BY to_go ASC LIMIT 5");
     $nul = mysqli_num_rows($ret);
if (!$nul)
     {
     $owner1 = "<b><i>".T_("TORRENT_NOT_ACTIVE")."</i></b>";
     $s = "<br /><table class=table_test width=100% border=1 cellpadding=3>";
     $s .= "<tr><td colspan=7 class=table_head align=center><b>".T_("SEED_INFO")."</b></td></tr>";
     $s .= "<tr><td class=table_col2><b>".T_("USERNAME")."</b></td><td class=table_col2 align=right><b>".T_("UPLOADED")."</b></td><td class=table_col2 align=right><b>".T_("SPEED")."</b></td><td class=table_col2 align=right><b>".T_("DOWNLOADED")."</b></td><td class=table_col2 align=right><b>".T_("SPEED")."</b></td>";
     $s .= "<td class=table_col2 align=right><b>".T_("RATIO")."</b></td></tr>";
     $s .= "<tr><td class=table_col1 class=outer>$owner1</td><td colspan=6 class=ttable_col1 align=center><b>".T_("NO_INFO")."</b></td></tr>";
     $s .= "</table><br /></fieldset><br /><br />";

     } else {
     $s = "<br /><table class=table_test width=100% border=1 cellpadding=3>";
     $s .= "<tr><td colspan=7 class=table_head align=center><b>".T_("SEED_INFO")."</b></td></tr>";
     $s .= "<tr><td class=table_col2><b>".T_("USERNAME")."</b></td><td class=table_col2 align=right><b>".T_("UPLOADED")."</b></td><td class=table_col2 align=right><b>".T_("SPEED")."</b></td><td class=table_col2 align=right><b>".T_("DOWNLOADED")."</b></td><td class=table_col2 align=right><b>".T_("SPEED")."</b></td>";
     $s .= "<td class=table_col2 align=right><b>".T_("RATIO")."</b></td></tr>";

     for ($m = 0; $m < $nul; ++$m)
     {
     $arrs = mysqli_fetch_assoc($ret);
     {
     $cres = SQL_Query_exec("SELECT id, username, privacy, donated, warned FROM users WHERE id='$arrs[userid]'");
     $cros = mysqli_fetch_assoc($cres);
     $privacylevel = $cros["privacy"];
    $donated = $cros["donated"];
    $warned = $cros["warned"];
    $now = time();
     $secs = max(1, ($now - $arrs["st"]) - ($now - $arrs["la"]));
     $revived = (isset($arrs["revived"])) == "yes";

if ($privacylevel == "strong"){
if (get_user_class() <= 5){
   $owner1 = "<i>".T_("ANONYMOUS")."</i>";
    }else{
if ($site_config["CLASS_USER"]) {
   $owner1 = "<a href='account-details.php?id=$cros[id]'>" . class_user($cros["username"]) . "</a>";
   }else{
   $owner1 = "<a href='account-details.php?id=$cros[id]'>" . $cros["username"] . "</a> " . ($donated > 0 ? "<img src='".$site_config['SITEURL']."/images/star.png' alt='".T_("DONATED")."' title='".T_("DONATED")."' />" : "") . " " . ($warned > 'no' ? "<img src='".$site_config['SITEURL']."/images/warned.png' alt='".T_("WARNED")."' title='".T_("WARNED")."' />" : "") . "";
   }
   }
    }else{
if ($site_config["CLASS_USER"]) {
   $owner1 = "<a href='account-details.php?id=$cros[id]'>" . class_user($cros["username"]) . "</a>";
   }else{
   $owner1 = "<a href='account-details.php?id=$cros[id]'>" . $cros["username"] . "</a> " . ($donated > 0 ? "<img src='".$site_config['SITEURL']."/images/star.png' alt='".T_("DONATED")."' title='".T_("DONATED")."' />" : "") . " " . ($warned > 'no' ? "<img src='".$site_config['SITEURL']."/images/warned.png' alt='".T_("WARNED")."' title='".T_("WARNED")."' />" : "") . "";                
   }
    }
    if (empty($cros["username"])) {
    $owner1 = "<i>".T_("UNKNOWN_USER")."</i>";
   }

     $bah = SQL_Query_exec("SELECT COUNT(*) FROM peers WHERE seeder = 'yes' AND torrent = $id");
     $count = mysqli_fetch_row($bah);
     $seeders = $count[0];
     $bah1 = SQL_Query_exec("SELECT COUNT(*) FROM peers WHERE seeder = 'no' AND torrent = $id");
     $count1 = mysqli_fetch_row($bah1);
     $leechers = $count1[0];

   $s .= "<tr><td class=table_col1 class=outer>".$owner1."</td>";
  $s .= "<td class=table_col1 align=right class=outer><nobr>" . mksize($arrs["uploaded"]) . "</nobr></td>";
  $s .= "<td class=table_col1 align=right class=outer><nobr>" . mksize(($arrs["uploaded"] - (isset($arrs["uploadoffset"]))) / $secs) . "/s</nobr></td>";
  $s .= "<td class=table_col1 align=right class=outer><nobr>" . mksize($arrs["downloaded"]) . "</nobr></td>";

if ($arrs["seeder"] == "no")
  $s .= "<td class=table_col1 align=right class=outer><nobr>" . mksize(($arrs["downloaded"] - $arrs["downloadoffset"]) / $secs) . "/s</nobr></td>";
  else
   $s .= "<td class=table_col1 align=right class=outer><nobr>" . mksize(($arrs["downloaded"] - (isset($arrs["downloadoffset"]))) / max(1, (isset($arrs["finishedat"])) - $arrs["st"])) . "/s</nobr></td>";

if ($arrs["downloaded"]) {
     $ratio = floor(($arrs["uploaded"] / $arrs["downloaded"]) * 1000) / 1000;
     $s .= "<td align=right class=outer><font color=" . get_ratio_color($ratio) . ">" . number_format($ratio, 3) . "</font></td>";
     }
     else

if ($arrs["uploaded"])
     $s .= "<td class=table_col1 align=right class=outer>Inf.</td>";
     else
     $s .= "<td class=table_col1 align=right class=outer>---</td>";
 //    $s .= "<td class=table_col1 align=right class=outer>" . sprintf("%.2f%%", 100 * (1 - ($arrs["to_go"] / $arr["size"]))) . "</td>";
     }
     }
     $s .= "</table><br /></fieldset><br /><br />";
     }

     $char1 = 50;
     $shortname = CutName(htmlspecialchars($arr["name"]), $char1);

     $image1 = (isset($row['image1']));
 
if ($arr["image1"] == '')
     $image1 = "<div class='cursor'><img src=images/no_poster.png width=175 height=255></div>";
     else
     $image1 = "<a href=".$site_config["SITEURL"]."/uploads/images/$arr[image1] rel='prettyPhoto'><img src=".$site_config["SITEURL"]."/uploads/images/$arr[image1] width=175 height=255 border=0 title='".T_("CLICK_ENLARGE")."'></a>";


 $ret = SQL_Query_exec("SELECT torrents.anon, torrents.seeders, torrents.banned, torrents.leechers, torrents.info_hash, torrents.filename, torrents.nfo, torrents.last_action, torrents.numratings, torrents.name, torrents.owner, torrents.save_as, torrents.descr, torrents.visible, torrents.size, torrents.added, torrents.views, torrents.hits, torrents.times_completed, torrents.id, torrents.type, torrents.external, torrents.image1, torrents.image2, torrents.announce, torrents.numfiles, torrents.freeleech, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.numratings, categories.name AS cat_name, torrentlang.name AS lang_name, torrentlang.image AS lang_image, categories.parent_cat as cat_parent, users.username, users.donated, users.warned, users.privacy FROM torrents LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN torrentlang ON torrents.torrentlang = torrentlang.id LEFT JOIN users ON torrents.owner = users.id WHERE torrents.id = $id");
   $catarr =  mysqli_fetch_assoc($ret);
   $donated = $catarr["donated"];
   $warned = $catarr["warned"];
if ($site_config["CLASS_USER"]) {
   $ca = "<a href='account-details.php?id=$catarr[owner]'>".class_user($catarr['username'])."</a>";
   }else{
   $ca = "<a href='account-details.php?id=$catarr[owner]'>" . $catarr['username']."</a> " . ($donated > 0 ? "<img src='".$site_config["SITEURL"]."/images/star.png' alt='".T_("DONATED")."' title='".T_("DONATED")."' />" : "") . " " . ($warned > 'no' ? "<img src='".$site_config['SITEURL']."/images/warned.png' alt='".T_("WARNED")."' title='".T_("WARNED")."' />" : "") . "";
   }

if (($arr["anon"] == "yes" || $catarr["privacy"] == "strong") && $CURUSER["id"] != $catarr["owner"] && $CURUSER["edit_torrents"] != "yes")
    $owner2 = "<b>" .T_("ADDED_BY"). ": </b><i>".T_("ANONYMOUS")."</i>";
     else
    $owner2 = "<b>" .T_("ADDED_BY"). ": </b>".$ca."";
if (empty($catarr["username"])) {
    $owner1 = "<i>".T_("UNKNOWN_USER")."</i>";
   }



     $flagname = $catarr["lang_name"];
if (empty($catarr["lang_name"]))
     $catarr["lang_name"] = "Unknown/NA";
     $lang = "<td class=ttable_col2 align='center'><b>" .T_("LANG"). " : </b>" . $catarr["lang_name"] . "";

if (empty($catarr["lang_image"]))
     $catarr["lang_image"] = "unknown.gif";
     $flag = "&nbsp;<img border=\"0\" src=\"" . $site_config['SITEURL'] . "/images/languages/" . $catarr["lang_image"] . "\" alt=\"".$flagname."\" /></td>";

     print("<fieldset class='download'><legend ><!--<a style='text-decoration:none' title='".$arr["name"]."' href=torrents-details.php?id=$id&hit=1>--><b>" . $shortname . "</b><!--</a>--></legend>");
     print("$s");
end_frame();

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)
2020-08-27 00:55:03
nice work. is SQL_Query_exec mysqli enabled for you guys? I've never used the mysqli edition so its mysterious to me still. Thats a ton of code ?
2020-08-27 21:24:03
"STorrents2020, post: 69203, member: 20382":

nice work. is SQL_Query_exec mysqli enabled for you guys? I've never used the mysqli edition so its mysterious to me still. Thats a ton of code ?

Yes, it works fine. The function is below
function &SQL_Query_exec ($query) {
   $sql = new SQL_Query ($query);
   return $sql->execute();
}

class SQL_Query {
   private $query = "";
   private $params = array();

   function &__construct ($query) {
       $this->query = $query;
       return $this;
   }

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)
2020-08-28 03:44:24
You guys can cut out all the JOIN work and just declare clause conditions, which do the same thing. I do this for now on.

SELECT (SUM(peers.downloaded)) / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(peers.started)) AS totalspeed FROM peers, users WHERE (users.id = 1 [color=rgb(44, 130, 201)]AND[/color] peers.userid = 1)

Throw as many AND/OR in there as you like, as long as you defined the desired table with a comma.
2021-11-26 16:23:19
thanks for sharing mod, good mod this  :thumb

you dont need all the query's through i did it with one and then looped through the array, converting took some time just need to do top seeders part  - https://imgur.com/rGXolvP
2021-11-26 17:04:14
awesome. Post your code when you are finished  :smile
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-11-26 17:06:06
2021-11-26 21:48:37
i ended up scraping most of code, using snatched to show top sharers instead of peers not fully sure what to do there yet  :unsure peers get deleted so wasnt sure if snatched would be a better option,  but you can see everything been joined in one query, i added multi word search as well, i have my html separate but here is the php code to show the query results

in the file you can search  // haha letter t  the page expects you to have a torrent beginning with t but you can change this - its just to show results, easy to test

for v3 then it would be a case of using $i++ to count through the foreach loop - if it works ill play around with the loop mines bootstrap but should be possible in html

create catalog.php then visit SITEURL/catalog.php or SITEURL/catalog.php?letter=x or SITEURL/catalog.php?search=x
<?php
require_once "backend/functions.php";
dbconn();
loggedinonly();

$search = $_GET['search'] ?? '';
$url = "?";
if ($search != '') {
   $keys = explode(" ", $search);
   foreach ($keys as $k) {
       $ssa[] = " torrents.name LIKE '%$k%' ";
   }
   $query = '(' . implode(' OR ', $ssa) . ')';
   $url .= "search=" . urlencode($search);
} else {
   // haha letter t
$letter = $_GET["letter"] ?? 't';
   if (strlen($letter) > 1) {
       die;
   }
   if ($letter == "" || strpos("abcdefghijklmnopqrstuvwxyz", $letter) === false) {
       // haha letter t
$letter = "t";
   }
   $query = "torrents.name LIKE '$letter%'";
   $url = "?letter=$letter";
}
$result = SQL_Query_exec("SELECT count(id) FROM torrents WHERE $query AND visible != 'no'");
$count = mysqli_num_rows($result);
list($pagertop, $pagerbottom, $limit) = pager(28, $count, $site_config["SITEURL"] . "/catalog$url&");
$stmt = SQL_Query_exec("SELECT torrents.anon, torrents.seeders, torrents.banned, torrents.leechers, torrents.info_hash, torrents.filename, torrents.nfo, torrents.last_action, torrents.numratings, torrents.name, torrents.owner, torrents.save_as, torrents.descr, torrents.visible, torrents.size, torrents.added, torrents.views, torrents.hits, torrents.times_completed, torrents.id, torrents.type, torrents.external, torrents.image1, torrents.image2, torrents.announce, torrents.numfiles, torrents.freeleech,
       IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.numratings,
        categories.name AS cat_name,
        torrentlang.name AS lang_name,
        torrentlang.image AS lang_image,
        categories.parent_cat as cat_parent,
        users.username, users.donated, users.warned, users.privacy, snatched.tid, snatched.uid, snatched.uload, snatched.dload, snatched.stime, snatched.utime, snatched.ltime
        FROM torrents
        LEFT JOIN categories ON torrents.category = categories.id
        LEFT JOIN torrentlang ON torrents.torrentlang = torrentlang.id
        LEFT JOIN users ON torrents.owner = users.id
        LEFT JOIN snatched ON users.id = snatched.uid
        WHERE $query AND visible != 'no'
        ORDER BY name ASC $limit");
$res = mysqli_fetch_all($stmt);

stdhead(T_("test"));
begin_frame(T_("test"));
foreach ($res as $arr) {
   var_dump($arr);
   echo "<br>################<br>";
}
end_frame();
stdfoot();
Last edited by M-jay warn on 2021-11-26 22:45:31
2022-12-29 19:33:37
New project is soon finished (inspiration from M-BiTsy):










www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
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: 1
  • Members: 0
  • Guests online: 1
  • Comments: 3
  • Messages: 1,728