"m-jay, post: 68638, member: 20288":
Updating the theme has thrown a few little things out but this is been looked at. There is no style just bootstrap so these little things will be inline css
its just a case of fixing these as we notice them
here is a example - the seedbonus template with no css ( this mod is finished just doing hitnrun )
<center>
This page displays the options that you can redeem accumulated points against depending on the share of torrents. <font color=yellow><b><?php echo $data['usersbonus']; ?></font></b>
</center>
<br />
<div class='table-responsive'> <table class='table table-striped'><thead><tr>
<th>Option</th>
<th>What is it?</th>
<th>Points</th>
<th>Exchange</th>
</tr></thead>
<?php foreach ($data['bonus'] as $row): ?>
<form method="post" action="<?php echo TTURL; ?>/bonus">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
<tbody><tr>
<td><?php echo htmlspecialchars($row['title']); ?></td>
<td><?php echo htmlspecialchars($row['descr']); ?></td>
<td><?php echo $row['cost']; ?></td>
<td><input type="submit" value="Exchange"></td>
</tr></tbody>
</form>
<?php endforeach; ?>
</table>
<ul>
<li>You recieve <font color=red><?php echo $data['configbonuspertime']; ?></font> points per <?php echo $data['configautoclean_interval']; ?> minutes the system registers you as a seeder by torrent.</li>
</ul>
<ul>
<li><a href=<?php echo TTURL; ?>/usercp>Return to profile</a></li>
</ul>
</div>
"spiritblue, post: 68631, member: 401":
thank you very much, i will add it to my next theme (stargate) ?
"m-jay, post: 68627, member: 20288":
yes this is a prepared statement all values are escaped as there are used with place holders ? or you can use :var
the way you use pdo is through a connection
connect->prepare->bind->execute this is perfectly fine and is the common way
its used this way because people wrap pdo with a class like the old TT mysql where you have a count function (rowCount) a query function (prepare) a insert function all sorts of functions to do what pdo does any way.
this can be a pain because its harder to write i think its easier just to chain everything and keep it simple this was a life saver when updating
Now knowing the above we write one simple function that is the same for everything so we have a pdo wrapper but it just says the way id like to format my queries passing them as arguments
public function run($sql, $args = NULL)
{
if (!$args)
{
return $this->pdo->query($sql);
}
$stmt = $this->pdo->prepare($sql);
$stmt->execute($args);
return $stmt;
}
i do not use prepare, excecute anywhere in my code except this function
from this excellent guide https://phpdelusions.net/pdo/pdo_wrapper
ill remove this in few days cause codes off topic but heres the seedbonus with this class ichavent used prepared statements yet
$userid = $CURUSER['id'];
$tid = $_POST["torrentid"];
$uid = $CURUSER["class"] == "1" ? (int) $_POST["userid"] : (int) $CURUSER["id"];
$retrieve = DB::run("SELECT * FROM bonus");
$usertable = DB::run("SELECT * FROM users");
if (is_valid_id($_POST['id'])) {
if (!$row || $CURUSER['seedbonus'] < $row->cost) {
autolink("bonus.php", "Demand not valid.");
}
$updateuser = DB::run("UPDATE users SET seedbonus = seedbonus - '$row->cost' WHERE id = $userid");
$row = $retrieve->fetch(PDO::FETCH_OBJ);
switch ($row->type) {
case 'invite':
DB::run("UPDATE users SET invites = invites + '$row->value' WHERE id = $userid");
break;
case 'traffic':
DB::run("UPDATE users SET uploaded = uploaded + '$row->value' WHERE id = $userid");
break;
case 'HnR':
if (empty($tid))
autolink("bonus.php", "You must fill the box with the id of the torrent.");
if (isset($uid) && isset($tid)) {
$res = DB::run("SELECT * FROM snatched WHERE tid = $userid AND uid = $uid AND hnr = 'yes'");
if ($res->rowCount() < 0)
autolink("mybonus.php", "No HnR found with this information.");
$res1 = DB::run("SELECT username, class FROM users WHERE id = $uid");
$row1 = $res1->fetch(PDO::FETCH_OBJ);
$res2 = DB::run("SELECT name FROM torrents WHERE id = $tid");
$row2 = $res2->fetch(PDO::FETCH_OBJ);
$username = htmlspecialchars($row1->username);
$torname = htmlspecialchars($row2->name);
$new_modcomment = gmdate("M d Y H:i:s") . " - ";
if ($uid == $CURUSER["id"])
$new_modcomment .= "H&R on the torrent " . htmlspecialchars($row2->name) . " cleared against " . $row->cost . " points \n";
else
$new_modcomment .= "H&R on the torrent " . $row2->name . " cleared by " . $row1->username . " \n";
$modcom = sqlesc($new_modcomment);
DB::run("UPDATE users SET modcomment = CONCAT($modcom,modcomment) WHERE id = :uid");
DB::run("UPDATE snatched SET ltime = '129600', hnr = 'no' WHERE tid = $userid AND uid = $uid");
}
break;
case 'other':
break;
case 'VIP':
$days = $row->value;
$class = $row1->class;
$vipuntil = ($CURUSER["vipuntil"] > "0000-00-00 00:00:00") ? $vipuntil = get_date_time(strtotime($CURUSER["vipuntil"]) + ($days * 86400)) : $vipuntil = get_date_time(gmtime() + ($days * 86400));
$oldclass = ($CURUSER["vipuntil"] > "0000-00-00 00:00:00") ? $oldclass = $CURUSER["oldclass"] : $oldclass = $CURUSER["class"];
$stmt->prepare("UPDATE users SET class = $class, oldclass = $oldclass, vipuntil = $vipuntil WHERE id = $userid");
break;
}
}
while ($row = $retrieve->fetch(PDO::FETCH_OBJ)) {
echo '<class="card">';
echo '<form method="post" action="/bonus.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '" />';
echo '<div class="card-action ng-scope" style="font-size:22px">';
echo "<span style=\"font-size:27px;font-weight:400;padding: 7px 5px 5px 10px;border-radius:7px;background:#C0C0C0;text-align:center;color:#FFF;box-shadow: inset 1px 5px 7px -6px #000000;margin-right:15px\">" . str_replace('Uploaded', '', $row->title) . "</span>";
echo $row->descr;
$disabled = '';
$inputmsg = 'Exchange';
if ($CURUSER['seedbonus'] < $row->cost) {
$inputmsg = 'Not Enough';
$disabled = 'disabled';
}
echo '<span>';
echo "<button class=\"btn btn-danger\" onclick=\"this.form.submit();\" style=\"font-size:15px\" $disabled>$inputmsg</button></span>";
echo '</div></form></article>';
}
?>
<div>
You receive
<?php echo $site_config['bonuspertime']; ?>
points per
<?php echo floor($site_config['autoclean_interval'] / 10); ?>
minutes the system registers you as a seeder by torrent.
</div>
<?
// Grab user Ratio, Download, Upload & Slot details dynamically
// Auto updates as they download and browse
require_once 'backend/functions.php';
$userid = isset($_GET['id'])?intval($_GET['id']):0;
try {
$conn = new PDO("mysql:host={$dbHost};dbname={$dbName}", $dbUsername, $dbPassword);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
die('Unable to connect to database');
}
if ($CURUSER["uploaded"] > 0 && $CURUSER["downloaded"] == 0)
$userratio = "Inf.";
elseif ($CURUSER["downloaded"] > 0)
$userratio = number_format($CURUSER["uploaded"] / $CURUSER["downloaded"], 2);
else
$userratio = "---";
$stmt = $conn->prepare("SELECT users.downloaded, users.uploaded, users.invites, users.id, COUNT(DISTINCT peers.torrent) AS slots FROM peers LEFT JOIN users ON peers.userid = users.id WHERE peers.userid = $userid");
$stmt->execute();
$array = array();
if ($stmt->rowCount() > 0) {
$userlivestats = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($userlivestats as $link => $row) {
$row['downloaded'] = $link['downloaded']; // Downloaded
$row['uploaded'] = $link['uploaded']; // Uploaded
$row['invites'] = $link['invites']; // Invites
$row['slots'] = $link['slots']; // Download Slots
$row['class'] = $link['class']; // User class
array_push($array, $link);
}
}
echo json_encode($userlivestats);
?>
<? if ($CURUSER) { ?>
<script>
function formatBytes(bytes, decimals = 2) {
if (bytes === null) return '0.00 Bytes'; // null in place of 0 - new user byte stats fix
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
function fetchUserUsage() {
$(document).ready(function () {
$.ajax({
url: 'ajax_stats.php?id=<?=$CURUSER["id"]; ?>',
method: "GET",
dataType: 'JSON',
success: function (data) {
var html_to_append = '';
var ratio = '<? echo number_format($CURUSER["uploaded"] / $CURUSER["downloaded"], 2); ?>';
var slots = '<? $maxslot = avail_slots($CURUSER["id"], $CURUSER["class"]); echo number_format($maxslot) . "/0"; ?>';
$.each(data, function (i, item) {
html_to_append +=
'<div style="padding-left:15px;padding-top:20px"><span style="font-size:25px"><i class="material-icons" style="color:#E72225;font-size:35px;vertical-align:bottom;padding-right:10px">cloud_download</i>' +
formatBytes(item.downloaded) +
'</span><span style="font-size:25px;padding-left:30px"><i class="material-icons" style="color:rgba(46,168,4,1);font-size:35px;vertical-align:bottom;padding-right:10px">cloud_upload</i>' +
formatBytes(item.uploaded) +
'</span><span style="font-size:25px"><span style="font-size:25px;padding-left:50px"><i class="material-icons" style="color:#C0C0C0;font-size:35px;vertical-align:bottom;padding-right:10px">timelapse</i>' +
ratio +
'</span><span style="display:none;font-size:25px;padding-left:50px"><i class="material-icons" style="color:#F4964E;font-size:35px;vertical-align:bottom;padding-right:10px">reply</i> <a href="/invite.php" style="color:#000;text-decoration:underline">' +
item.invites +
'</a></span><span style="font-size:25px;padding-left:50px"><i class="material-icons" style="color:#0079FE;font-size:35px;vertical-align:bottom;padding-right:10px">widgets</i>' +
slots +
'</span></div>';
});
$("#userusage").html(html_to_append);
}
});
});
}
fetchUserUsage();
setInterval(function () {
fetchUserUsage()
}, 5000);
</script>
<? } ?>
<?
if (stripos($_SERVER['PHP_SELF'],'index.php') && $CURUSER) {
// AJAX User usage - May 21, 2020
print("My Ratio to Members will go here..");
print("<div id=\"userusage\"></div>");
}
?>
<?
if ($CURUSER) {
// AJAX User usage - May 21, 2020
print("My Ratio to Members will go here..");
print("<div id=\"userusage\"></div>");
}
?>
"Propaganda, post: 68618, member: 60":
Our current Bonus Exchange page looks like this >>
[ATTACH=full]5546[/ATTACH]
"m-jay, post: 68615, member: 20288":
nice (y) seedbonus has been on my todo list so ill follow post :D
on v3 i had it linked to everything lol comments, upload, posts, hitnrun, vip - all through config ill start digging all little bits out
trying to pick out all the whiles and replace with foreach to update code heres one in cleanup for seedbonus
// Seedbonus
$res = DB::run("SELECT DISTINCT userid as peer, (
SELECT DISTINCT COUNT( torrent )
FROM peers
WHERE seeder = 'yes' AND userid = peer) AS count
FROM peers WHERE seeder = 'yes'")->fetch();
foreach ( $res as $row )
{
DB::run("UPDATE users SET seedbonus = seedbonus + '" . ($site_config["bonuspertime"] * $row->count) . "' WHERE id = '" . $row->peer . "'");
}
<?php
require_once('backend/functions.php');
dbconn();
error_reporting(E_ALL); // E_ALL => 0 : off
stdhead("Runner");
// Code all in here
stdfoot();
?>
<?
try {
$stmt = new PDO("mysql:host={$dbHost};dbname={$dbName}", $dbUsername, $dbPassword);
$stmt->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
die('Unable to connect to database');
}
$userid = $CURUSER['id'];
$tid = $_POST["torrentid"];
$uid = $CURUSER["class"] == "1" ? (int) $_POST["userid"] : (int) $CURUSER["id"];
$retrieve = $stmt->prepare("SELECT * FROM bonus");
$retrieve->execute();
$usertable = $stmt->prepare("SELECT * FROM users");
$usertable->execute();
if (is_valid_id($_POST['id'])) {
if (!$row || $CURUSER['seedbonus'] < $row->cost) {
autolink("bonus.php", "Demand not valid.");
}
$updateuser = $stmt->query("UPDATE users SET seedbonus = seedbonus - '$row->cost' WHERE id = :id");
$updateuser->bindValue(':id', $userid, PDO::PARAM_INT);
$updateuser->execute();
$row = $retrieve->fetch(PDO::FETCH_OBJ);
switch ($row->type) {
case 'invite':
$stmt->query("UPDATE users SET invites = invites + '$row->value' WHERE id = :id");
$stmt->bindValue(':id', $userid, PDO::PARAM_INT);
$stmt->execute();
break;
case 'traffic':
$stmt->query("UPDATE users SET uploaded = uploaded + '$row->value' WHERE id = :id");
$stmt->bindValue(':id', $userid, PDO::PARAM_INT);
$stmt->execute();
break;
case 'HnR':
if (empty($tid))
autolink("bonus.php", "You must fill the box with the id of the torrent.");
if (isset($uid) && isset($tid)) {
$res = $stmt->prepare("SELECT * FROM snatched WHERE tid = :tid AND uid = :uid AND hnr = 'yes'");
$res->bindValue(':tid', $userid, PDO::PARAM_INT);
$res->bindValue(':uid', $uid, PDO::PARAM_INT);
$res->execute();
if ($res->rowCount() < 0)
autolink("mybonus.php", "No HnR found with this information.");
$res1 = $stmt->prepare("SELECT username, class FROM users WHERE id = :uid");
$res1->bindValue(':uid', $uid, PDO::PARAM_INT);
$res1->execute();
$row1 = $res1->fetch(PDO::FETCH_OBJ);
$res2 = $stmt->prepare("SELECT name FROM torrents WHERE id = :tid");
$res2->bindValue(':tid', $tid, PDO::PARAM_INT);
$res2->execute();
$row2 = $res2->fetch(PDO::FETCH_OBJ);
$username = htmlspecialchars($row1->username);
$torname = htmlspecialchars($row2->name);
$new_modcomment = gmdate("M d Y H:i:s") . " - ";
if ($uid == $CURUSER["id"])
$new_modcomment .= "H&R on the torrent " . htmlspecialchars($row2->name) . " cleared against " . $row->cost . " points \n";
else
$new_modcomment .= "H&R on the torrent " . $row2->name . " cleared by " . $row1->username . " \n";
$modcom = sqlesc($new_modcomment);
$stmt->prepare("UPDATE users SET modcomment = CONCAT($modcom,modcomment) WHERE id = :uid");
$stmt->prepare("UPDATE snatched SET ltime = '129600', hnr = 'no' WHERE tid = :tid AND uid = :uid");
$stmt->bindValue(':tid', $userid, PDO::PARAM_INT);
$stmt->bindValue(':uid', $uid, PDO::PARAM_INT);
$stmt->execute();
}
break;
case 'other':
break;
case 'VIP':
$days = $row->value;
$class = $row1->class;
$vipuntil = ($CURUSER["vipuntil"] > "0000-00-00 00:00:00") ? $vipuntil = get_date_time(strtotime($CURUSER["vipuntil"]) + ($days * 86400)) : $vipuntil = get_date_time(gmtime() + ($days * 86400));
$oldclass = ($CURUSER["vipuntil"] > "0000-00-00 00:00:00") ? $oldclass = $CURUSER["oldclass"] : $oldclass = $CURUSER["class"];
$stmt->prepare("UPDATE users SET class = :class, oldclass = :oldclass, vipuntil = :vipuntil WHERE id = :id");
$stmt->bindValue(':class', $class, PDO::PARAM_INT);
$stmt->bindValue(':oldclass', $oldclass, PDO::PARAM_STR);
$stmt->bindValue(':vipuntil', $vipuntil, PDO::PARAM_STR);
$stmt->bindValue(':id', $userid, PDO::PARAM_INT);
$stmt->execute();
break;
}
}
while ($row = $retrieve->fetch(PDO::FETCH_OBJ)) {
echo '<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card">';
echo '<form method="post" class="cd-form floating-labels" action="/bonus.php">';
echo '<input type="hidden" name="id" value="' . $row->id . '" />';
echo '<div class="card-action ng-scope" style="font-size:22px">';
echo "<span style=\"font-size:27px;font-weight:400;padding: 7px 5px 5px 10px;border-radius:7px;background:#C0C0C0;text-align:center;color:#FFF;box-shadow: inset 1px 5px 7px -6px #000000;margin-right:15px\">" . str_replace('Uploaded', '', $row->title) . "</span>";
echo $row->descr;
$disabled = '';
$inputmsg = 'Exchange';
if ($CURUSER['seedbonus'] < $row->cost) {
$inputmsg = 'Not Enough';
$disabled = 'disabled';
}
echo '<span style="float:right;margin-right:-125px">';
echo "<button class=\"btn btn-danger\" onclick=\"this.form.submit();\" style=\"font-size:15px\" $disabled>$inputmsg</button></span>";
echo '</div></form></article>';
}
?>
<div>You receive <?
echo $site_config['bonuspertime'];
?> points per <?
echo floor($site_config['autoclean_interval'] / 10);
?> minutes the system registers you as a seeder by torrent.</div>
<?
stdfoot();
?>
[ATTACH type="full"]5545[/ATTACH] "spiritblue, post: 66899, member: 401":
small complement ...
5 seedbonus points for commenting on a torrent.
[color=rgb(41, 105, 176)](it's up to you to change the number 5 to Luis himself) [/color]
Search in [color=rgb(251, 160, 38)]torrents-details.php[/color] :
SQL_Query_exec("UPDATE torrents SET comments = comments + 1 WHERE id = $id");
Add after :
// Points Seedbonus By spiritblue
$commentaire = get_row_count("comments", "WHERE torrent = $id AND user = $CURUSER[id]");
if ($commentaire < 1) {
SQL_Query_exec("UPDATE users SET seedbonus = seedbonus+5.0 WHERE id = ".$CURUSER["id"]."") ;
}
// End Points Seedbonus
Note: this line could also be used on another page, change the variable (y)
ALTER TABLE users;
ALTER seedbonus SET DEFAULT 0.0;
<? while ($row = mysql_fetch_object($res)): ?>
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card">
<form method="post" class="cd-form floating-labels" action="/seedbonus/">
<input type="hidden" name="id" value="<? echo $row->id; ?>" />
<div class="card-action ng-scope" style="font-size:22px">
<!-- Seeder exchange -->
<span style="font-size:27px;font-weight:400;padding: 7px 5px 5px 10px;border-radius:7px;background:#C0C0C0;text-align:center;color:#FFF;box-shadow: inset 1px 5px 7px -6px #000000;margin-right:15px">
<? echo str_replace('Uploaded', ' ', htmlspecialchars($row->title)); ?>
</span>
<? echo htmlspecialchars($row->descr); ?>
<? echo htmlspecialchars($row->cost); ?>
<span style="float:right;margin-right:-125px">
<button class="btn btn-danger" onclick="this.form.submit();" style="font-size:15px" <? echo ($CURUSER['seedbonus'] < $row->cost ? 'disabled' : null); ?>>
<? if ($CURUSER['seedbonus'] < $row->cost){ echo "Not Enough"; } else { echo "Exchange"; } ?>
</button>
</span>
</div>
</form>
</article>
<? endwhile; ?>