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
User Posts

Go to Profile

"m-jay, post: 69653, member: 20288":

heres a quick test i did on pdo that works fine on xampp but live server is not having non of it
controllers/Test.php
<?php
class Test extends Controller
{

   public function __construct()
   {
       $this->db = new Database;
   }

   public function index()
   {
       dbconn();
       try {
           $timeout = 12;
           $scraper = new Udptscraper($timeout);
           $ret = $scraper->scrape('udp://9.rarbg.to:2890/announce', '546d6aed41217195ed2c82e9c561b7badbd6b590');
           foreach ($ret as $array) {
               $keys = array_keys( $array);
               echo $array[ $keys[0] ].'&nbsp;seeders<br>';
               echo $array[ $keys[1] ].'&nbsp;completed<br>';
               echo $array[ $keys[2] ].'&nbsp;leechers<br>';
           }
       } catch (ScraperException $e) {
           echo ('Error: ' . $e->getMessage() . "<br />\n");
           echo ('Connection error: ' . ($e->isConnectionError() ? 'yes' : 'no') . "<br />\n");
       }
   }

}


had to use array keys for test setting value in foreach broke it for some strange reason
this is external so should work without edit, servers not having none of it, everything i try works on xampp


Nice!! That’s so cool seeing it plugged into a controller, very neat. That’s never done before as far as I know. You nailed it.

Your foreach contents is a bit wrong as I see it, your defining array keys when they are already defined by the loop itself (that’s why I don’t use while(), you have to tell it what to do too much, and often we ARE using arrays lol so while has a certain place.

try array_push() and push the keys to a empty array just before foreach(), like $blah = array()

then define like $blah = $row[‘something’] in the loop. I’ll fix it up shortly for you, I’m using php 7.4.12 so maybe they changed something there?
I don’t use torrenttrader anymore I’m on a custom platform that used to be torrenttrader, and 2 weeks of very hard work put us on our own code base (so I posted it as V4), some things are the same but mostly not. I use my own database class for example.

White page means success in my case, I never added a “scraping complete” message, I forgot to mention that.

Run the scraper on V3 (non-MySQLi), and check database or torrent detail page.

I’ll do this up as MySQLi tonight for those of you using that. M-jay can do it up for his db class (basically search and replace stuff).

Works fine
In progress.

/ajax/ajax_torrent_scrape_get.php?id=397

Current:

[{"torrent_id":397,"seeders":0,"leechers":0}]

Next step:

Use bdecode class to retrieve announce-list from BLOB data (in my case, as I dont use announce column for months now), this will otherwise be much easier for TT users. Once i grab that, the script should start working fine, as it turns out my query was incorrect at some point.


$announce = bdecode($db->decode_data($datatable['data'])) or die('bencoding error');
if (array_key_exists('info', $announce)) {
   if ($announce['info']['private'] === 1) {
       print("Private Tracker");
   } else {
       printf("Public Tracker", html_escape($announce['announce']));
   }
}


Great, we have our tracker URl - udp[url='http://p4p.arenabg.ch:1337/announce']://p4p.arenabg.ch:1337/announce[/url]

Now, we see that we are no longer even using torrents.seeders / torrents.leechers (because i personally use the peer table for stats instead for months now). So a way around that is to simply plug in my own bdecode class (its not from TT, its in-house).

Let's see if we get parsing and a result based on the first key in the 'announce' array and restart the scraping response for this torrent ID.

Lets just do this to get a head start on whats going on


$torrentid = isset($_GET['id'])?intval($_GET['id']):0; // Get torrent ID ?id=

$stmt = $conn->prepare("SELECT t.torrent_id, t.info_hash, b.data FROM torrents t LEFT JOIN torrents_blob b ON t.torrent_id = b.torrent_id WHERE t.torrent_id = :torrent_id LIMIT 1"); // NEW - BLOB
$stmt->bindValue(':torrent_id', $torrentid, PDO::PARAM_INT);
$stmt->execute();

   while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

       $announce = 'udp://p4p.arenabg.ch:1337/announce';

       // Work here
       $ret = $scraper->scrape($announce, $row['info_hash']);

   }
   foreach ($ret as $key => $value) {
       $stmt = $conn->prepare("UPDATE torrents SET leechers='" . $value['leechers'] . "', seeders='" . $value['seeders'] . "', times_completed='" . $value['completed'] . "', last_action=NOW(), visible='yes' WHERE torrent_id = :torrentid");
       $stmt->bindValue(':torrentid', $torrentid, PDO::PARAM_INT);
       $stmt->execute();
   }
}
catch (ScraperException $e) {
   echo ('Error: ' . $e->getMessage() . "<br />\n");
   echo ('Connection error: ' . ($e->isConnectionError() ? 'yes' : 'no') . "<br />\n");
}


Error: No connection response.
Connection error: yes


Interesting.. time to find out why. Whoops, i forgot to upload the file in the first place lol

BOOM! Scraped a UDP tracker and we have 27 seeders & 1 leecher

[ATTACH type="full" alt="Working-Scraper.png"]5989[/ATTACH]

Lets check our GET script:

[{"torrent_id":397,"seeders":27,"leechers":1}]

Yup! All good now.

Seeders and Leechers in the photo was set to 0 / 0 before i even started. So it was working for my site the entire time, the problem was I converted over to BLOB data and it never caught on.

Conclusion:

WE HAVE A WORKING UDP SCRAPER!!

This is just simply mysql (not mysqli) so keep that in mind. This is converted from PDO.

Save as udpscraper.php and upload to root /

<?php
// TT UDP Scraper - Nov 30, 2020
require_once 'backend/functions.php';
$torrentid = isset($_GET['id'])?intval($_GET['id']):0; // Get torrent ID ?id=
$limit     = 1;

$query = SQL_Query_exec("SELECT id, announce, info_hash FROM torrents WHERE external = 'yes' AND id = '$torrentid' LIMIT 1");
class ScraperException extends Exception
{
   private $connectionerror;
   public function __construct($message, $code = 0, $connectionerror = false)
   {
       $this->connectionerror = $connectionerror;
       parent::__construct($message, $code);
   }
   public function isConnectionError()
   {
       return ($this->connectionerror);
   }
}
abstract class tscraper
{
   protected $timeout;
   public function __construct($timeout = 2)
   {
       $this->timeout = $timeout;
   }
}
class udptscraper extends tscraper
{
   public function scrape($url, $infohash)
   {
       if (!is_array($infohash)) {
           $infohash = array(
               $infohash
           );
       }
       foreach ($infohash as $hash) {
           if (!preg_match('#^[a-f0-9]{40}$#i', $hash)) {
               throw new ScraperException('Invalid infohash: ' . $hash . '.');
           }
       }
       if (count($infohash) > 74) {
           throw new ScraperException('Too many infohashes provided.');
       }
       if (!preg_match('%udp://([^:/]*)(?::([0-9]*))?(?:/)?%si', $url, $m)) {
           throw new ScraperException('Invalid tracker url.');
       }
       $tracker        = 'udp://' . $m[1];
       $port           = isset($m[2]) ? $m[2] : 80;
       $transaction_id = mt_rand(0, 65535);
       $fp             = fsockopen($tracker, $port, $errno, $errstr);
       if (!$fp) {
           throw new ScraperException('Could not open UDP connection: ' . $errno . ' - ' . $errstr, 0, true);
       }
       stream_set_timeout($fp, $this->timeout);
       $current_connid = "\x00\x00\x04\x17\x27\x10\x19\x80";
       $packet         = $current_connid . pack("N", 0) . pack("N", $transaction_id);
       fwrite($fp, $packet);
       $ret = fread($fp, 16);
       if (strlen($ret) < 1) {
           throw new ScraperException('No connection response.', 0, true);
       }
       if (strlen($ret) < 16) {
           throw new ScraperException('Too short connection response.');
       }
       $retd = unpack("Naction/Ntransid", $ret);
       if ($retd['action'] != 0 || $retd['transid'] != $transaction_id) {
           throw new ScraperException('Invalid connection response.');
       }
       $current_connid = substr($ret, 8, 8);
       $hashes         = '';
       foreach ($infohash as $hash) {
           $hashes .= pack('H*', $hash);
       }
       $packet = $current_connid . pack("N", 2) . pack("N", $transaction_id) . $hashes;
       fwrite($fp, $packet);
       $readlength = 8 + (12 * count($infohash));
       $ret        = fread($fp, $readlength);
       if (strlen($ret) < 1) {
           throw new ScraperException('No scrape response.', 0, true);
       }
       if (strlen($ret) < 8) {
           throw new ScraperException('Too short scrape response.');
       }
       $retd = unpack("Naction/Ntransid", $ret);
       if ($retd['action'] != 2 || $retd['transid'] != $transaction_id) {
           throw new ScraperException('Invalid scrape response.');
       }
       if (strlen($ret) < $readlength) {
           throw new ScraperException('Too short scrape response.');
       }
       $torrents = array();
       $index    = 8;
       foreach ($infohash as $hash) {
           $retd             = unpack("Nseeders/Ncompleted/Nleechers", substr($ret, $index, 12));
           $retd['infohash'] = $hash;
           $torrents[$hash]  = $retd;
           $index            = $index + 12;
       }
       return ($torrents);
   }
}
try {
   $timeout = 2;
   $scraper = new udptscraper($timeout);
   while ($row = mysql_fetch_assoc($query)) {
       $ret = $scraper->scrape($row['announce'], $row['info_hash']);
   }
   foreach ($ret as $key => $value) {
       SQL_Query_exec("UPDATE torrents SET leechers='" . $value['leechers'] . "', seeders='" . $value['seeders'] . "', times_completed='" . $value['completed'] . "', last_action=NOW(), visible='yes' WHERE id = '$torrentid'");
   }
}
catch (ScraperException $e) {
   echo ('Error: ' . $e->getMessage() . "<br />\n");
   echo ('Connection error: ' . ($e->isConnectionError() ? 'yes' : 'no') . "<br />\n");
}
?>


Now point your site to

yoursite.com/udpscraper.php?id=TORRENT_ID

----


My situation is different, as this is what I have to do to pull from BLOB data

require_once '../../bencoding.php';
require_once '../../site.php';
try {
   $timeout = 2;
   $scraper = new udptscraper($timeout);
   while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
       
       // Added support for reading announce url from BLOB data - Nov 30, 2020
       $blobdata  = bdecode($db->decode_data($row['data'])) or die('bencoding error');
       if (array_key_exists('announce', $blobdata)) {
           $announce = $blobdata['announce'];
       }else{
           throw new ScraperException('No announce url found in BLOB data.', 0, true);
       }
       
       $ret = $scraper->scrape($announce, $row['info_hash']);        
   }
   foreach ($ret as $key => $value) {
       $stmt = $conn->prepare("UPDATE torrents SET leechers='" . $value['leechers'] . "', seeders='" . $value['seeders'] . "', times_completed='" . $value['completed'] . "', last_action=NOW(), visible='yes' WHERE torrent_id = :torrent_id");
       $stmt->bindValue(':torrent_id', $torrentid, PDO::PARAM_INT);
       $stmt->execute();
   }
}


And that code above, for my BLOB data works beautifully ;) both problems solved today.
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.";
No need to use PHP to calculate row count, you can use this query to do that and reduce extra code.

This shows the last logged in (15 minutes). You can keep the old query if you need, but be sure to add COUNT(id) AS totalcount in your old query

SELECT COUNT(id) AS totalcount, username FROM users WHERE last_access >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)


So you call 'totalcount' and you get your online count. This is also easier to understand and compatible for most versions.

Also, the use of referential assignment operator:
[color=rgb(84, 172, 210)]=&[/color]
is depreciated and will throw warnings. Easy to fix. This was a PHP 4 thing back in the day.

Try this:


<?php
if (get_user_class() >= 7) {
   begin_block(T_("ONLINE_USERS"));
   $expires = 1200;
   if (($rows = $TTCache->Get("usersonline_block", $expires)) === false) {
       $res = SQL_Query_exec("SELECT COUNT(id) AS totalcount, id, username FROM users WHERE enabled = 'yes' AND status = 'confirmed' AND privacy !='strong' AND last_access >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)");
       foreach (mysqli_fetch_assoc($res) as $row) {
           $rows = $row;
           if (array_key_exists('id', $row)) {
               print("<div id='uOnline' class='bMenu'> - Total: " . $row['totalcount']); // Count the total online
               print("<span style='text-align:center'><a href='account-details.php?id=$row[id]'>" . class_user($row['username']) . "</a></span>");
           } else {
               echo T_("NO_USERS_ONLINE");
           }
       }
       $TTCache->Set("usersonline_block", $rows, $expires);
   }
   end_block();
}
?>
Poster from iMDB — 2020-11-30 15:21:00 in M-BiTsy Support
It’s possible to stream movie content from any other tracker by capturing piece data and buffering towards a mime-type while also downloading the file in question for the users account, can even limit 1 stream until they “upgrade” or gain enough reputation to access more bit streams. I could do wonders in this area but too wigged out by copyright bs
Poster from iMDB — 2020-11-30 07:39:56 in M-BiTsy Support
Dedicated server 100% (in your possession). Never used any paid type of hosting, it will be slow, unpredictable, lack of control, account flagged by the connections observed by the hosting companies IT etc etc. Plus, the hosting company will know all about you and your institution, IP and god knows what else readily available with a typical subpoena.

Simply isn’t worth it when you can just invest roughly $1200 for a rack mount box and put it in your living room or elsewhere, plus if it ever has issues, your just 15 feet away from it. Plug up a VGA monitor and keyboard, or if it’s not too bad of shape just SSH from across the room from your desktop.

Also ensure you are behind a reverse proxy 100% because it will bite you in the rump very quickly depending on your traffic score. Private or not, it just takes 1 user to snoop around in the peer list with some client, nab your seeding IP and report it, so buy a seedbox! Seedbox.io - $27 USD / month.

Never download your own torrents to see if ”their connecting” from your home IP, you could use a VPN but their under fire too lately. Instead, rely on user feedback such as comments or ratings.

Cover that and they really have no idea who is operating and distributing without domain seizure.

Movies and streaming is seriously heated business and I wish I could contribute but I will stay as far away from that as possible. But this is the total solution to do that under wraps.

Be sure your seedbox service resides in the Netherlands! Do not use a US-based seedbox for high volume distribution, jurisdiction is way too risky.

Otherwise, all of these code requests is fairly easy and can be completed in very short time with DOM and cURL. Problem again, is remote domain blacklisting (like imgur, photobucket, etc) then it’s even more difficult as you now have to proxy every request to the remote media and that’s no fun.

Just a lot of advice if things fly high on Alexa. I follow all of this entirely and learned on my own. It’s a different time since I started (in 2009).
Code Journel — 2020-11-29 23:03:16 in Support & Suggestions
User Passkey IP limit checking


// Peer Passkey IP limit check
$ipcheck = $db->query_params('SELECT DISTINCT(ip) AS ip FROM peers WHERE user_id = :user_id', array('user_id' => $user_row['user_id'])) or fail('Unable to select peer IP');
$count = 0;
$found = false;
foreach ($ipcheck->fetch() as $row) {
   $count++;
   if ($row['ip'] == $data['ip']) {
       $found = true;
   }
}
if (!$found && $count >= $CONFIG['max_passkey_ips']) fail('You have reached your IP limit for this passkey.');


Config

'max_passkey_ips'  =>  2,
Code Journel — 2020-11-29 21:50:10 in Support & Suggestions
Happy Hour - announce.php

The idea behind this, is to turn OFF download slot limits, peer limits and open the "doors" wide open for Saturday & Sunday.

This will allow a full peer burst for the following week, allowing a great boost on the weekly downloads while doing the same burst again the following weekend. This will incorperate a banner in the sidebar that advertises "Happy Hour Access".

Max Slot / Peer limits resume Monday @ 12:00 AM

Full code (PHP 5 - 7+ compatible)


// Happy Hour - No Slot Limits, No peer limits - PHP 5/7+ compatible : Saturday/Sunday - Nov 29, 2020
if (!in_array(date('l'), ['Saturday', 'Sunday'])) {
   $maxslots = $db->query_params("SELECT COUNT(DISTINCT torrent_id) AS total, last_announce FROM peers WHERE user_id = :user_id AND seeder = 'no'", array('user_id' => $user_row['user_id']));
   $current  = $maxslots->fetch();
       if ($current['total'] > $user_row['slots']) {
           $checklast   = $db->query_params('SELECT user, date, message FROM shoutbox WHERE user = :username', array('username' => $user_row['username']));
           $lastmessage = $checklast->fetch();
               if ($lastmessage['date'] < $current['last_announce']) {
                   $event = "[url=$CONFIG[base_url]/user/?id=$user_row[user_id] ] $user_row[username][/url] reached their maximum download slot $current[total]/$user_row[slots]";
                   $reason = "You have reached your max download slots of 4 (out of 3 available). You can visit Seed Bonus to upgrade to more slots.";
                   $db->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array('receiver' => $user_row['username'], 'event' => $event));
                   $db->query_params("INSERT INTO messages (sender, receiver, added, msg, poster, subject) VALUES (0, :user_id, NOW(), :reason, 0, 'Max Download Slots Reached')", array('user_id' => $user_row['user_id'], 'reason' => $reason)); // Sep 23, 2020
               }
               fail("$current[total]/$user_row[slots] download slots exceeded! Finish current transfers to reclaim slots.");
       }
} else {
   $event = "Today is Happy Hour! No slot limits, No peer limits - Full Speeds!";
   $db->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array('receiver' => 'NerbBot', 'event' => $event));
}
Error upload torrent — 2020-11-29 07:17:11 in M-BiTsy Support
And everyone, for the sake of simplicity, speed and security (and not using 6 functions to achieve a simple check case), this is super good to memorise

instead of
isset($_POST['name'] or !empty or ! or whatever..

start using
array_key_exists('name', $_REQUEST)

$_REQUEST means _GET, _SERVER, _POST, etc etc

Its easy to get confused, like "why cant I just use in_array() ?" because most of the time, these functions expect additional parameters passed to actually utilize the function properly for those certain cases. Here, we are talking about server request checking.

name in this case is array a array [color=rgb(44, 130, 201)]key

You are simply checking if that key is in the request.
[/color]

Your interpreter (the PHP binary) will thank you, and your code comes out clean, easy to read & easy to maintain.

Focus on array data exclusively. Its a life saver and its CPU light. All versions welcome it, and so should we. I see a lot of code posted that is ??? but this will drop in place and fix "what should I use here?". I can repost code posted that is clean and fixed up but its good if we all start using this logic across the board. Cheers!
Error upload torrent — 2020-11-27 15:09:53 in M-BiTsy Support
"m-jay, post: 69633, member: 20288":

Thanks for sharing [USER=20382]@STorrents2020[/USER]  I'll have a play with that at some point, got the input logic separated for upload just need to go through it
For the scraper from what I've seen there is only two possible options the current one and the scrapeer class. I've got the current one running perfect on 2 out of 3 servers so its just pinpointing the server issue
Might be worth asking the host if you can do a support ticket there and I'll contact my host and ask them as well something is preventing it from scraping externally - its defo not allow_url_fopen


Sounds good I might have a weekend dedicated solely so just waiting on word for that.

This is preventable with cURL correct? That old function has been blocked on free / paid web hosting since way back in the day, often encouraging people to upgrade to “paid hosting” to enable that function.

— they will bitch about the number of outbound connections, and ask if you are using a BitTorrent script (UDP protocol will not be possible). Pain in the ass since 2005

If your testing on public hosting, they will wipe the tracker immediately. Get a dedicated box in your house and dump Linux on it and LAN it up to your router, DMZ the IP and update the IP for a DNS serve (like FreeDNS or Cloudflare) and you should have zero problems testing that script on a default stack installation.

My baby is flawless and purrs all day with maximum settings, I can throw anything at it so maybe I have much more leverage here...
Error upload torrent — 2020-11-27 05:49:27 in M-BiTsy Support
"Botanicar, post: 69626, member: 19833":

Error
       

Oops somwthing went wrong, Admin have been notified if this continues please contact a member of staff. Thank you



Uncaught Exception: 2020-11-25 21:59:18 - syntax error, unexpected 'public' (T_PUBLIC) in file /home/tt-m-jay/public_html/controllers/Torrents.php on line 752

Call Stack

[0] File: /home/tt-m-jay/public_html/index.php Line: 3
Function: Router->__construct
Uncaught Exception: 2020-11-25 21:59:26 - syntax error, unexpected 'public' (T_PUBLIC) in file /home/tt-m-jay/public_html/controllers/Torrents.php on line 752

Call Stack

[0] File: /home/tt-m-jay/public_html/index.php Line: 3
Function: Router->__construct



Doesn't this imply a language global is missing? Also a bit misleading, because it references "public" in plain text, which then explains that its a public function when it expects a private function, just my two cents. This upload script is terrible from the beginning to be honest, I had nothing but problems with it for a long time.

PHP 5 / 7 / 8 - 100% working


<?
if (session_status() == PHP_SESSION_NONE) { session_start(); }  
require_once '../site.php';
require_once '../classes/class.bencoding.php';
require_once '../classes/class.imageresizer.php';
$db->connect();

$errors = array();

if ($account->sessionLogin()) {

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
   check_csrf();

   $description = $_POST['description'];
   if (strlen($description) > 10000) {
       die('description too long');
   }

   if (!array_key_exists('torrent', $_FILES)) {
       die;
   }

   if ($_FILES['torrent']['size'] > $CONFIG['max_torrent_size']) {
       die('torrent too big');
   }

   $name = $_FILES['torrent']['name'];
   if (strlen($name) > 512) {
       die('torrent name too long');
   }
 
   //Added
   $tags = $_POST['tags'];
   if (strlen($tags) > 50) {
       die('tags are too long');
   }
   $version = $_POST['version'];
   if (strlen($version) > 15) {
       die('version is too long');
   }
 
   $dlc = $_POST['dlc'] ? 'yes' : 'no';
 
   $youtube = $_POST['youtube'];
   if (strlen($youtube) > 100) {
       die('YouTube url is too long');
   }
   //
 
   $ext = '.torrent';
   if (strlen($name) <= strlen($ext) || strpos($name, $ext, strlen($name) - strlen($ext)) === false) {
       die('not a .torrent file');
   }

   $fp = fopen($_FILES['torrent']['tmp_name'], 'rb');
   $data = '';
   while (!feof($fp)) {
       $data .= fread($fp, 8192);
   }
   fclose($fp);

   $arr = bdecode($data);
   if ($arr === false) {
       die('invalid torrent');
   }

   // TODO: more validity checks for torrent?

   if (!array_key_exists('info', $arr)) {
       die('invalid torrent');
   }
 
   if (array_key_exists('cover', $_FILES)) {

       $uploadedFile     = $_FILES['cover']['tmp_name'];
       $sourceProperties = getimagesize($uploadedFile);
       $newFileName      = sha1_file($uploadedFile);
       $dirPath          = 'images/covers/';
       $ext              = pathinfo($_FILES['cover']['name'], PATHINFO_EXTENSION);
       $imageType        = $sourceProperties[2];

       switch ($imageType)
       {
           case IMAGETYPE_PNG:
               $imageSrc = imagecreatefrompng($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagepng($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           case IMAGETYPE_JPEG:
               $imageSrc = imagecreatefromjpeg($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagejpeg($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           case IMAGETYPE_GIF:
               $imageSrc = imagecreatefromgif($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagegif($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           default:
               die('invalid image.');
           break;
       }

       move_uploaded_file($uploadedFile, $dirPath . $newFileName . "." . $ext);  
       $cover_full  = $newFileName . "." . $ext;
       $cover_thumb = $newFileName . "_thumb." . $ext;  
   }
 
   if (array_key_exists('image1', $_FILES)) {

       $uploadedFile     = $_FILES['image1']['tmp_name'];
       $sourceProperties = getimagesize($uploadedFile);
       $newFileName      = sha1_file($uploadedFile);
       $dirPath          = 'uploads/images/';
       $ext              = pathinfo($_FILES['image1']['name'], PATHINFO_EXTENSION);
       $imageType        = $sourceProperties[2];

       switch ($imageType)
       {
           case IMAGETYPE_PNG:
               $imageSrc = imagecreatefrompng($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagepng($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           case IMAGETYPE_JPEG:
               $imageSrc = imagecreatefromjpeg($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagejpeg($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           case IMAGETYPE_GIF:
               $imageSrc = imagecreatefromgif($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagegif($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           default:
               die('invalid image.');
           break;
       }

       move_uploaded_file($uploadedFile, $dirPath . $newFileName . "." . $ext);  
       $image1_full  = $newFileName . "." . $ext;
       $image1_thumb = $newFileName . "_thumb." . $ext;  
   }
 
   if (array_key_exists('image2', $_FILES)) {

       $uploadedFile     = $_FILES['image2']['tmp_name'];
       $sourceProperties = getimagesize($uploadedFile);
       $newFileName      = sha1_file($uploadedFile);
       $dirPath          = 'uploads/images/';
       $ext              = pathinfo($_FILES['image2']['name'], PATHINFO_EXTENSION);
       $imageType        = $sourceProperties[2];

       switch ($imageType)
       {
           case IMAGETYPE_PNG:
               $imageSrc = imagecreatefrompng($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagepng($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           case IMAGETYPE_JPEG:
               $imageSrc = imagecreatefromjpeg($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagejpeg($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           case IMAGETYPE_GIF:
               $imageSrc = imagecreatefromgif($uploadedFile);
               $tmp      = imageResize($imageSrc, $sourceProperties[0], $sourceProperties[1]);
               imagegif($tmp, $dirPath . $newFileName . "_thumb." . $ext);
           break;

           default:
               die('invalid image.');
           break;
       }

       move_uploaded_file($uploadedFile, $dirPath . $newFileName . "." . $ext);  
       $image2_full  = $newFileName . "." . $ext;
       $image2_thumb = $newFileName . "_thumb." . $ext;  
   }

   $infobc = bencode($arr['info']);
   if ($infobc === false) {
       die('bencoding error');
   }

   $info_hash = sha1($infobc);
   $total_size = 0;

   if ($checktype['info']['private'] = 1) { // Added - Check if torrent is private (this changes info_hash) - Sep 1, 2020
   if (array_key_exists('files', $arr['info'])) {
       foreach ($arr['info']['files'] as $file) {
           if (array_key_exists('length', $file)) {
               $total_size += $file['length'];
           }
       }
   } else if (array_key_exists('length', $arr['info'])) {
       $total_size += $arr['info']['length'];
   }
       $data = bencode($arr);
   }else{
       $data = bdecode($data); // Public torrent (does not change info_hash)
   }

   $an = array_key_exists('anonymous', $_POST);
   $torrent_id = $db->query_params("INSERT INTO torrents (user_id, name, descr, anon, info_hash, size, tags, version, dlc, youtube, cover1, cover2, image1, image2) VALUES (:user_id, :name, :description, :anonymous, :info_hash, :total_size, :tags, :version, :dlc, :youtube, :cover1, :cover2, :image1, :image2)", array('user_id' => $account->getId(), 'name' => $name, 'description' => $description, 'anonymous' => $db->encode_bool($an), 'info_hash' => $info_hash, 'total_size' => $total_size, 'tags' => $tags, 'version' => $version, 'dlc' => $dlc, 'youtube' => $youtube, 'cover1' => $cover_full, 'cover2' => $cover_thumb, 'image1' => $image1_full, 'image2' => $image2_full), 'torrent_id') or die('db error');
 
   // Updated for new torrents_blob table - Performance - Sep 2, 2020
   $db->query_params('INSERT INTO torrents_blob (torrent_id, user_id, data) VALUES (:last_id, :user_id, :data)', array('last_id' => $torrent_id, 'data' => $data, 'user_id' => $account->getId())); // array('data' => $data, 'last_id' => $torrent_id));

   header(sprintf('Location: %s/details/%s/', $CONFIG['base_url'], $torrent_id));
   die;
   }

}else{
   header(sprintf('Location: %s/login.php', $CONFIG['base_url']));
   die;
}

// Get users passkey
$passkey = $db->query_params('SELECT passkey FROM users WHERE user_id = :user_id', array('user_id' => $account->getId())) or die('db error');
$getkey = $passkey->fetch();

site_header();
?>
rating — 2020-11-22 18:22:16 in v3 Support
It’s CSS3, you can’t go wrong. I’ll post in shortly
rating — 2020-11-22 17:31:06 in v3 Support
I have a pure CSS solution that using a ACII star character, it’s 100% cross-compatible and just requires the ratingpic() function. Easy to drop in as it’s just HTML and a few CSS properties. Very customizable and no-images.
Template help — 2020-11-22 17:28:59 in M-BiTsy Support
Yah coffee and iPhone don’t work for me too lol I agree I want to learn this too and reduce looping, I know I can get the array keys without looping and break after x amount of results, but again I’ve travelled too far lol
Template help — 2020-11-22 16:47:36 in M-BiTsy Support
He is correct but it’s a chore to restructure it all to rely on JOINED queries, and you want to really optimize your caches and other settings in my.cnf to properly read/write efficiently in this case, table overhead is in mind. This is now assuming you want to reduce your code now to single-query calls.
rating — 2020-11-22 03:15:14 in v3 Support
Mine (and im overriding star colour by users current theme):


function ratingpic($num)
{
   global $CONFIG;
   $r = round($num * 2) / 2;
   if ($r != $num) {
       $n = $num - $r;
       if ($n < .25)
           $n = 0;
       elseif ($n >= .25 && $n < .75)
           $n = .5;
       $r += $n;
   }
   if ($r < 1 || $r > 5)
       return;
   
   return "<div class=\"stars-rating\" style=\"--rating: $num;padding-bottom:7px\" aria-label=\"Rating is $num / 5\"></div>";
}
Here I am writing user profiles from scratch (user details) and logging efforts here. This aims to be a full social profile system offering bio, comments, friends list, uploads, bookmarks, widgets, active transfers, and much more!

Logging progress as I tie into my user class and pull user data and perform on-the-fly AJAX field updating (edit profile), photos and comments, & torrent ratings. This will offer a spawn of code to replace the entire comment system by using AJAX developed first for profiles, effectively and finally, killing off the old TT comments out (last of the few chunks of V3 code nested throughout a clean system of code).

Here, we are simply plugging a query into the user class with a "getter" function viewUsers() by determining permissions with this query:

SELECT *, u.username FROM groups g LEFT JOIN users u ON u.class = g.group_id;


Now we use "Edit in Place" jquery plugin, that allows for on-the-fly field editing and updating in place. All mouse-over and click events as the photo below.


<!-- jQuery-inlineEdit-0.2.1 -->
   <script type="text/javascript" src="/js/jquery-inlineedit-0.2.1/jquery.inlineEdit.js"></script>

   <style type="text/css">
       .hover { background-color: #ffC }
       .inlineEdit-placeholder { font-style: italic; color: #555; }
   </style>

   <script>
       $(function () {}); $('.editable2').inlineEdit();
   </script>


We simply assign the class .editable2 to any body element of our choice, like a div

[ATTACH type="full" alt="editinplace.png"]5969[/ATTACH]

ajax_profile_live_update.php

<?
// Profile Bio : Live-Edit - Nov 22, 2020
// GET: retrieve profile bio
// Save: Update database with edited in-place field value
require_once 'dbConfig.php';
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');
}
error_reporting(0);
$action  = isset($_POST) && $_POST['action'] ? $_POST['action'] : 'get';
$value   = isset($_POST) && $_POST['value'] ? $_POST['value'] : '';
$user_id = intval($_GET['id']);
$stmt    = $conn->prepare('SELECT * FROM users WHERE user_id = :user_id');
$stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($data as $row) {
   $field_bio  = $row['profile_bio'];
}
switch ($action) {
   case 'get':
       echo $field_bio;
       break;
   case 'save':
       if ($value != '') {
           $stmt = $conn->prepare('UPDATE users SET profile_bio = :post_data WHERE user_id = :user_id');
           $stmt->bindParam(':post_data', $value, PDO::PARAM_STR);
           $stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
           $stmt->execute();
           echo "OK";
       } else {
           echo "ERROR: no value received.";
       }
       break;
   default:
       echo "ERROR: no action specified.";
       break;
}



user.php

<?
if (session_status() == PHP_SESSION_NONE) { session_start(); }
 
// New rewritten user profiles/details - Nov 21, 2020

require_once '../site.php';
$db->connect();

site_header();

error_reporting(0); // Debug

if ($account->sessionLogin()) {

// User fields - $user
$r = $db->query_params('SELECT * FROM users WHERE user_id = :id', array('id' => intval($_GET['id'])));
$user = $r->fetch() or die('<h1 itemprop="name"><span class="card-title">User not found.</span></h1>');

// Log location
if ($account->getId() != $user['user_id']) {
   $db->query_params("UPDATE users SET page = 'Viewing Users Profile', last_access = NOW() WHERE user_id = :user_id", array('user_id' => $account->getId()));
}elseif ($account->getId() == $user['user_id']) {
   $db->query_params("UPDATE users SET page = 'Viewing Their Profile', last_access = NOW() WHERE user_id = :user_id", array('user_id' => $account->getId()));
}

// Post comment - Nov 22, 2020
if ($_SERVER['REQUEST_METHOD'] === 'POST' && array_key_exists('profile', $_POST)) {
csrf_html();

   if (!array_key_exists('profile', $_POST)) {
       die;
   }
 
   $body = html_escape($_POST['profile']);
   $id = $_GET['id'];
   if (strlen($body) > 500) {
       die('Comment too long.');
   }
 
   if (strlen($body) < 5) {
       die('Comment too short.');
   }

   $postcomment = $db->query_params("INSERT INTO comments (user, userprofile, added, text) VALUES (:current_user, :user_id, now(), :body)", array('current_user' => $account->getId(), 'user_id' => $user['user_id'], 'body' => $body));
   //$db->query_params("UPDATE torrents SET comments = comments + 1 WHERE torrent_id = :torrent_id", array('torrent_id' => $id));
   header(sprintf('Location: %s/details/%s/#comments', $CONFIG['base_url'], $row['torrentid']));  
}


// Update profile views except self
if ($account->sessionLogin() && $user['user_id'] != $account->getId()) {
   $db->query_params('INSERT INTO profileviews (userid, userviewed) VALUES (:current_id, :id) ON DUPLICATE KEY UPDATE viewed = NOW()', array('current_id' => $account->getId(), 'id' => $user['user_id']));
   $db->query_params('UPDATE profileviews SET times = times + 1, viewed = NOW() WHERE userid = :current_id AND userviewed = :id', array('current_id' => $account->getId(), 'id' => $user['user_id']));
}

//var_dump($user); // Dev testing

// User view
if ($account->viewUsers() == 'no' && $account->getId() != $user['user_id'])
   die('No permission to view user.');
     
// Enabled
if (($user['enabled'] == 'no' || ($user['status'] == 'pending')) && $account->getUserRole() == 'Regular')
   die('No access. Account disabled.');

// Country
$res = $db->query_params('SELECT flagpic, name FROM countries WHERE id = :country LIMIT 1', array('country' => $user['country']));
if ($res) {
   $arr     = $res->fetch();
   $country = " <img src='/images/countries/$arr[flagpic]' style='width:25;height:25px;vertical-align:middle' />";
}

// Total friends
$friends = $db->query_params('SELECT COUNT(*) as totalfriends FROM friends WHERE userid = :user_id', array('user_id' => $user['user_id']));
$totalf = $friends->fetch();

// Stored media
$stored = $db->query_params('SELECT u.avatar, u.avatar_thumb, t.image1, t.image2, t.added, u.added AS added_avatar, t.cover1 AS cover, t.name FROM users u LEFT JOIN torrents t ON u.user_id = t.user_id WHERE u.user_id = :user_id ORDER BY t.added DESC LIMIT 12', array('user_id' => $user['user_id']));
$totals = $stored->fetch();

// Total uploads
$uploads = $db->query_params('SELECT COUNT(*) as totaluploads FROM torrents t LEFT JOIN users u ON u.user_id = t.user_id WHERE u.user_id = :user_id', array('user_id' => $user['user_id']));
$totalu = $uploads->fetch();

// Profile comments
$comments = $db->query_params('SELECT c.user AS sender_id, c.text AS comment, u.user_id AS receiver_id, u.avatar_thumb AS avatar FROM comments c LEFT JOIN users u ON u.user_id = c.user WHERE c.userprofile = :user_id ORDER BY c.added DESC', array('user_id' => $user['user_id']));
$totalc = $comments->fetch();

// Total bookmarks
$bookmarks = $db->query_params('SELECT COUNT(*) as totalbkmarks FROM bookmarks b LEFT JOIN users u ON u.user_id = b.userid WHERE u.user_id = :user_id', array('user_id' => $user['user_id']));
$totalb = $bookmarks->fetch();

if (!$country)
   $country = ' Country Unknown';
 
// Moods
$res = $db->query_params('SELECT name, moodspic FROM moods WHERE id = :moods LIMIT 1', array('moods' => $user['moods']));
if ($res) {
   $arr   = $res->fetch();
   $moods = '';
}

// Ratio conditions
if ($user['downloaded'] > 0) {
   $ratio = $user['uploaded'] / $user['downloaded'];
} else {
   $ratio = 'N/A';
}

// Profile photo
$avatar = htmlspecialchars($user['avatar_thumb']);
if (is_null($avatar)) $avatar = 'images/noavatar.png';

// Begin profile
?>

<!-- BEGIN layout -->

<h1 itemprop="name">
   <span class="card-title">@<?=html_escape($user['username'])?></span>
</h1>

<?
// Buttons according to users privacy setting
if ($account->getId() != $user['user_id']) {
   $r      = $db->query_params("SELECT id FROM friends WHERE userid = :user_id AND friendid = :friendid", array('user_id' => $account->getId(), 'friendid' => intval($_GET['id'])));
   $friend = $r->fetch();
   $r      = $db->query_params("SELECT id FROM blocked WHERE userid = :user_id AND blockid = :friendid", array('user_id' => $account->getId(), 'friendid' => intval($_GET['id'])));
   $block  = $r->fetch();
   if ($user['privacy'] != 'strong' || ($account->getId() == $user['user_id'])) {
       print("<button type=\"button\" style=\"font-weight:normal\" class=\"btn btn-danger\" onclick=\"location.href='/message/?compose&id=$user[user_id]'\"><i class=\"material-icons\" style=\"vertical-align:bottom;padding-right:5px\">message</i> Message</button>");
       if ($friend)
           print("<button type=\"button\" style=\"font-weight:normal;margin-left:5px\" class=\"btn btn-danger\" onclick=\"location.href='/friends.php?action=delete&type=friend&targetid=$_GET[id]\"><i class=\"material-icons\" style=\"vertical-align:bottom;padding-right:5px\">remove_circle</i> Unfriend</button>");
       elseif ($block)
           print("<button type=\"button\" style=\"font-weight:normal;margin-left:5px\" class=\"btn btn-danger\" onclick=\"location.href='/friends.php?action=delete&type=block&targetid=$_GET[id]'\"><i class=\"material-icons\" style=\"vertical-align:bottom;padding-right:5px\">remove_circle_outline</i> Unblock</button>");
       else {
           print("<button type=\"button\" style=\"font-weight:normal;margin-left:5px\" class=\"btn btn-danger\" onclick=\"location.href='/friends.php?action=add&type=friend&targetid=$_GET[id]'\"><i class=\"material-icons\" style=\"vertical-align:bottom;padding-right:5px\">face</i> + Friend</button>
                     <button type=\"button\" style=\"font-weight:normal;margin-left:5px\" class=\"btn btn-danger\" onclick=\"location.href='/friends.php?action=add&type=block&targetid=$_GET[id]'\"><i class=\"material-icons\" style=\"vertical-align:bottom;padding-right:5px\">block</i> Block</button>");
       }
   }
}

// Check users privacy settings
if ($user['privacy'] != 'strong' || $account->getId() == $user['user_id']) { ?>

<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card" style="width:57%;text-align:center">

<!-- User photo -->
<img src="<?=$CONFIG['base_url'] . "/" . $avatar; ?>" alt="<?=html_escape($user['username'])?>" style="border-radius:50%;width:250px;height:250px;margin-top:25px;border:7px solid #ECECEC" />

<!-- Profile views -->  
<div style="color:#C0C0C0;padding:10px 0px 5px 0;text-align:center">Profile views</div>
<?
$res = $db->query_params('SELECT DISTINCT profileviews.userid, profileviews.userviewed, users.avatar_thumb AS avatar, users.user_id FROM profileviews LEFT JOIN users ON users.user_id = profileviews.userid WHERE profileviews.userviewed = :userviewed ORDER BY profileviews.viewed DESC LIMIT 30', array('userviewed' => intval($_GET['id'])));
while ($arr = $res->fetch()) {
   if (!$arr['avatar']) {
       echo "<a href=\"" . $CONFIG['base_url'] . "/user.php?id=" . $arr['user_id'] . "\">
           <img style='width:45px;height:45px;border-radius:50%;margin-right:5px;' src='" . $CONFIG['base_url'] . "/images/noavatar.png' /></a>";
   } else if ($arr['avatar']) {
       echo "<a href=\"" . $CONFIG['base_url'] . "/user.php?id=" . $arr['user_id'] . "\">
           <img itemprop=\"image\" class=\"responsive-img\" src=\"" . $CONFIG['base_url'] . "/" . htmlspecialchars($arr["avatar"]) . "\" style='width:30px;height:30px;border-radius:50%;margin-right:5px;' /></a>";
   }
}
?>
</div>

<!-- Begin Fields: Username, Gender, Join Date, Online -->
<h2 style="font-size:19px">
   <?=html_escape($user['username']) . ', ' . $user['gender'] . ' ' . $country; ?>
   <div style="font-size:16px"><span style='color:#C0C0C0'>Joined <?=$user['added']?></span>
   <div>Online <?=str_replace('< 1 min', '<span><i class="material-icons" style="color:green;vertical-align:middle">check_circle_outline</i> now</span>', time_ago($user['last_access'])); ?></div>
</h2>

<!-- Begin User Class Name -->
<h2>
   <center>      
<?
if ($user['class'] == 7) {
   echo '<div style="border-radius:5px;background:#c0c0c0;padding:5px;color:#FFF;width:200px;padding-bottom:10px">Administrator</div>';
} elseif ($user['class'] == 4) {
   echo '<div style="border-radius:5px;background:#c0c0c0;padding:5px;color:#FFF;width:200px;padding-bottom:10px">Uploader</div>';
} elseif ($user['class'] == 1) {
   echo '<div style="text-align:center;padding-bottom:10px">Regular User</div>';
}
?>
   </center>
</h2>

<div>          
<?
if ($user['class'] >= 7) {
$r2 = $db->query_params('SELECT id FROM bookmarkuser WHERE userid = :user_id AND bkid = :bkid', array('user_id' => $account->getId(), 'bkid' => intval($_GET['id'])));
$bookmarkuser = $r2->fetch();
   if ($bookmarkuser) {
       print("<center><button type='button' style='font-weight:normal' class='btn btn-danger' onclick=\"location.href='" . $CONFIG["base_url"] . "/watch/?action=delete&type=bookmarkuser&targetid=$_GET[id]'\">Remove from Watchlist</button></center>\n");
   } else {
       print("<center><button type='button' style='font-weight:normal' class='btn btn-danger' onclick=\"location.href='" . $CONFIG["base_url"] . "/watch/?action=add&type=bookmarkuser&targetid=$_GET[id]'\">Add to Watchlist</button></center></a>&nbsp;<br />");
   }
}
?>    
</div>

</article>

<!-- User Friends -->
<div style="position:absolute;top:150px;right:120px;width:41%">

<h1 itemprop="name">
   <i class="material-icons">face</i> <?=$totalf['totalfriends']; ?> Friends
</h1>

<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article">
 
<? if ($account->getId() == $user['user_id']) { ?>
   <div style="padding-bottom:25px">
       <button type='button' style='font-weight:normal' class='btn btn-danger' onclick="location.href='/findfriends.php'">Find Friends</button>
   </div>
<? } ?>

<?
$res = $db->query_params('SELECT DISTINCT (SELECT COUNT(*) FROM friends WHERE userid = :user_id) as totalfriends, f.id, f.userid, f.friendid, u.user_id, u.avatar_thumb AS avatar FROM friends f LEFT JOIN users u ON u.user_id = f.friendid WHERE f.userid = :friend_id ORDER BY f.userid DESC LIMIT 50', array('friend_id' => $user['user_id'], 'user_id' => $user['user_id']));
while ($arr = $res->fetch()) {
   if (!$arr['avatar']) {
       echo "<a href=\"" . $CONFIG['base_url'] . "/user.php?id=" . $arr['user_id'] . "\">
           <img style='width:45px;height:45px;border-radius:50%;margin-right:5px;' src='" . $CONFIG['base_url'] . "/images/noavatar.png' /></a>";
   } else if ($arr['avatar']) {
       echo "<a href=\"" . $CONFIG['base_url'] . "/user.php?id=" . $arr['user_id'] . "\">
           <img itemprop=\"image\" class=\"responsive-img\" src=\"" . $CONFIG['base_url'] . "/" . htmlspecialchars($arr["avatar"]) . "\" style='width:45px;height:45px;border-radius:50%;margin-right:5px;' /></a>";
   }
}
?>

<!-- Total Torrent Bookmarks -->
<h1 itemprop="name">
   <i class="material-icons">bookmarks</i> <?=$totalb['totalbkmarks']; ?> Bookmarks
</h1>
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article">
   Coming soon.
</article>

<!-- Total Torrents -->
<h1 itemprop="name">
   <i class="material-icons">list</i> <?=$totalu['totaluploads']; ?> Torrents
</h1>
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article">
   Coming soon.
</article>

<!-- End side content -->
</article>
</div>

<!-- Profile Bio -->
<h1 itemprop="name">
   my bio
   <span style="float:right;font-size:17px;padding-right:10px">
       <a href="#"><i class="material-icons" style="vertical-align:middle;padding-right:5px;font-size:16px;color:orange">edit</i>Edit Bio</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="#"><i class="material-icons" style="vertical-align:middle;padding-right:5px;font-size:16px;color:red;">color_lens</i>Style</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="#"><i class="material-icons" style="vertical-align:middle;padding-right:5px;font-size:16px;color:purple">share</i>Share</a>
   </span>
</h1>
<!-- Content -->
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card" style="width:96%; padding:10px; font-size:17px">
   <?=html_escape($user['profile_bio'])?>
</article>



<!-- Profile Comments -->
<h1 itemprop="name">
   comments
</h1>
<!-- Comments -->
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card" style="width:96%; padding:10px; font-size:17px">
   <div>
<?
// Begin comments
foreach ($totalc as $person): //var_dump($person); // USE THIS TO TEST DIFFERENT THINGS FOR UI/features ?>
 
<!-- Begin profile comments - Sep 2, 2020 -->
<div ng-repeat="item in items" class="col" style="margin-left:7px;padding-bottom:10px;width:698px">
        <article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card" style="padding:0px;margin:0px">
           <table class="responsive-table">
              <tr>
                 <th scope='row' style='color:#FFF;background:#ED2324;text-align:left;height:0px;box-shadow: inset 1px 5px 7px -6px #000000;padding-bottom:2px;padding-top:5px;width:180px'>
                     <a href="/user/?id=<?=$person['userid']?>"><img src="/<?=$person['avatar']?>" style="width:65px;height:65px;border-radius:50%" /></a>
                 </th>
                 <td style='background:#e6e6e6;border-bottom:1px solid #FFF;text-align:left;color:#000;padding-left:10px'><?=html_escape($person['text'])?></td>
              </tr>
           </table>
        </article>
</div>          
               
<? endforeach;
printf('<form class="cd-form floating-labels" name="comment" method="post" action="">');
csrf_html();
?>
  <div class='b-border' style="margin-left: 5px; margin-top:-10px">
     <table border='0' cellpadding='6' cellspacing='0' class='responsive-table'>
        <tr class='b-title'>
           <th colspan="2" align='center' valign="middle">
              <table border="0" align="center" cellpadding="4" cellspacing="0">
                 <!--<span style='font-weight:normal;color:#c0c0c0;padding-left:4px'>bbcode - HTML turned <i>off</i><span style='text-align:right;float:right'>Images, links - <a href='/community/?action=viewtopic&topicid=48' target='_new'>see posting rules</a></span></span>-->
                 <tr>
                    <td align="center"><button type="button" style="font-weight:bold" class="btn btn-danger" onclick="javascript: BBTag('[b]','bold','body','comment'); FocusAfter('textarea_css');">B</button></td>
                    <td align="center">
                       <button type="button" style="font-weight:normal;font-style:italic" class="btn btn-danger" onclick="javascript: BBTag('[i]','italic','body','comment'); FocusAfter('textarea_css');">
                          i
                    </td>
                    <td align="center"><button type="button" style="font-weight:normal;text-decoration:underline" class="btn btn-danger" onclick="javascript: BBTag('[u]','underline','body','comment'); FocusAfter('textarea_css');">u</td>
                    <td align="center"><button type="button" style="font-weight:normal" class="btn btn-danger" onclick="javascript: BBTag('
  • ','li','body','comment'); FocusAfter('textarea_css');">*</td>
                        <td align="center"><button type="button" style="font-weight:normal" class="btn btn-danger" onclick="javascript: BBTag('[quote]','quote','body','comment'); FocusAfter('textarea_css');">" "</td>
                        <td align="center"><button type="button" style="font-weight:normal" class="btn btn-danger" onclick="javascript: BBTag('[url]','url','body','comment'); FocusAfter('textarea_css');">URL</td>
                        <td align="center"><button type="button" style="font-weight:normal" class="btn btn-danger" onclick="javascript: BBTag('[img]','img','body','comment'); FocusAfter('textarea_css');">IMG</td>
                     </tr>
                  </table>
               </th>
            </tr>
            <tr class='b-row'>
            <td class='bb-comment' align='center' valign='top'>
            <textarea name="profile" id="textarea_css" rows="10" cols="50" style="width: 654px; margin-top:-40px" placeholder="Say something..." /></textarea>
            <table border="0" cellpadding="3" cellspacing="3" align="center">
            <tr>
            <td width="55"><a href="javascript:SmileIT(':)','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/smile.png" border="0" alt=':)' title=':)' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':(','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/sad.png" border="0" alt=':(' title=':(' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':D','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/grin.png" border="0" alt=':D' title=':D' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':P','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/razz.png" border="0" alt=':P' title=':P' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':-)','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/smile-big.png" border="0" alt=':-)' title=':-)' /></a></td>
            <td width="55"><a href="javascript:SmileIT('B)','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/cool.png" border="0" alt='B)' title='B)' /></a></td>
            <td width="55"><a href="javascript:SmileIT('8o','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/eek.png" border="0" alt='8o' title='8o' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':?','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/confused.png" border="0" alt=':?' title=':?' /></a></td>  
            <td width="55"><a href="javascript:SmileIT('8)','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/glasses.png" border="0" alt='8)' title='8)' /></a></td>
            <td width="55"><a href="javascript:SmileIT(';)','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/wink.png" border="0" alt=';)' title=';)' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':-*','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/kiss.png" border="0" alt=':-*' title=':-*' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':-(','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/crying.png" border="0" alt=':-(' title=':-(' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':|','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/plain.png" border="0" alt=':|' title=':|' /></a></td>
            <td width="55"><a href="javascript:SmileIT('O:-D','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/angel.png" border="0" alt='O:-D' title='0:-D' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':-@','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/devilish.png" border="0" alt=':-@' title=':-@' /></a></td>
            </tr><tr>
            <td width="55"><a href="javascript:SmileIT(':o)','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/monkey.png" border="0" alt=':o)' title=':o)' /></a></td>
            <td width="55"><a href="javascript:SmileIT('brb','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/brb.png" border="0" alt='brb' title='brb' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':warn','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/warn.png" border="0" alt=':warn' title=':warn' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':help','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/help.png" border="0" alt=':help' title=':help' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':bad','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/bad.png" border="0" alt=':bad' title=':bad' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':love','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/love.png" border="0" alt=':love' title=':love' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':idea','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/idea.png" border="0" alt=':idea' title=':idea' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':bomb','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/bomb.png" border="0" alt=':bomb' title=':bomb' /></a></td>
            <td width="55"><a href="javascript:SmileIT(':!','comment','body'); FocusAfter('textarea_css');"><img style="width:24px;height:24px" src="/images/smilies/important.png" border="0" alt=':!' title=':!' /></a></td>
            </tr>
            </table>
            </td>
            </tr>
         </table>
      </div>
      <br><button class="btn btn-danger" onclick="this.form.submit()" style='margin-top:-125px;float:right;position:absolute;right: 37px'>Post</button>
       </form>
       </div>
    </article>

    <!-- Stored Media -->
    <h1 itemprop="name">
       stored media
       <span style="float:right;font-size:17px;padding-right:10px">
           <a href="#"><i class="material-icons" style="vertical-align:middle;padding-right:5px;font-size:16px;color:lightblue">insert_photo</i>Manage</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="#"><i class="material-icons" style="vertical-align:middle;padding-right:5px;font-size:16px;color:red;">get_app</i>Save All</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="#"><i class="material-icons" style="vertical-align:middle;padding-right:5px;font-size:16px;color:green">tab_unselected</i>Torrents</a>
       </span>
    </h1>
    <!-- Content -->
    <article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card" style="height: 300px; width:96%; padding:10px; font-size:17px">
    <?
    while ($row = $stored->fetch()) {
       print("<div style='display:inline;float:left;width:220px;height:220px;margin:5px;'><img style=\"width:220px;height:220px\" src='" . $CONFIG['base_url'] . "/uploads/images/" . $row['image1'] . "' /><br>Uploaded: " . time_ago($row['added']) . "<br>Location: <b>" . str_replace('.torrent', '', $row['name']) . "</b></div>"); break;
    }
    while ($row = $stored->fetch()) {
       print("<div style='display:inline;float:left;width:220px;height:220px;margin:5px;'><img style=\"width:220px;height:220px\" src='" . $CONFIG['base_url'] . "/uploads/images/" . $row['image2'] . "' /><br>Uploaded: " . time_ago($row['added']) . "<br>Location: <b>" . str_replace('.torrent', '', $row['name'])  . "</b></div>"); break;
    }
    while ($row = $stored->fetch()) {
       print("<div style='display:inline;float:left;width:220px;height:220px;margin:5px;'><img style=\"border-radius:100%;width:220px;height:220px\" src='" . $CONFIG['base_url'] . "/" . $row['avatar_thumb'] . "' /><br>Uploaded: " . time_ago($row['added_avatar']) . "<br>Location: <i>Profile</i></div>");  break;

    }
    /*
    while ($row = $stored->fetch()) {
       print("<div style='display:inline;float:left;width:220px;height:220px;margin:5px;'><img style=\"width: 107px;height:176px;\" src='" . $row['image1'] . "/images/covers/" . $row['cover'] . "' /><br>Uploaded: " . time_ago($row['added']) . "</div>");  break;

    }
    */
    ?>
    <div style="clear:both"></div>
    </article>

    <?
    // End profile

    } // End privacy check - line 95

    site_footer();

    } else { // check session
       header(sprintf('Location: %s/signin/', $CONFIG['base_url']));
       die;
    }
  • Template help — 2020-11-21 02:04:09 in M-BiTsy Support
    Should be fairly simple to determine the functions logic, and assign type-casting for PHP 7/8, been wanting to do that for a while now
    Template help — 2020-11-21 01:37:55 in M-BiTsy Support
    "m-jay, post: 69585, member: 20288":

    you can try this m8 if your interested in templates, i know your using smarty at the minute but this can remove 3 party stuff

    create file called Views.php and place in backend, in functions.php include the Views.php file near where include config and tz.php are (bottom of the include list may be best for test)

    <?php

    class Views
    {    // Load View (we add data with array $data[] )
       public static function view($file, $data = [], $inc = false)
       {
           dbconn();
           global $config, $THEME, $LANGUAGE;
           // Check for view file
           if (file_exists(' . $file . '.php')) {
               if ($inc) {
                  stdhead('test');
                   require_once " . $file . ".php";
                   stdfoot();
               } else {
                   require_once " . $file . ".php";
               }
           } else {
               // View does not exist
               die('View does not exist');
           }
       }
    }


    create file called test.php and place in root
    ####################### TEST #############################


    then anywhere on index.php try call the template

    $data = []
    Views::view('test', $data, false);



    I removed Smarty in June in favor of raw markup and array calls, its super fast this way. I didnt like the 3ms overhead with a bloated library like Smarty, so im exploring TT classes => ST. I look forward to plugging this in! I can strip the MVC and use it as is, as I have no model. I just call my styles.min.css and raw HTML in the script itself. Thanks for your hard work, it looks excellent!
    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: 3
    • Members: 0
    • Guests online: 3
    • Comments: 3
    • Messages: 1,728