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
Bonus System (PDO)
Controls ·  Search New posts · Mark unread

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

2020-05-20 21:11:43
Converting old mod seedbonus, early test stuff. Template code included to speed up post updates.



<?
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]
NewPDOSeedBonuses-Recoded.png
NewPDOSeedBonuses-Recoded.png
2020-05-21 04:33:42
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 . "'");
}
2020-05-21 04:48:24
"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 . "'");
}



Good work! The mod is complete and can be seen live /bonus.php but I’m afraid a few objects in queries or at least the first UPDATE statement is failing to update user table. I gotta var_dump my way through, but there u have it lol
2020-05-21 08:01:11
Our current Bonus Exchange page looks like this >>

[ATTACH type="full"]5546[/ATTACH]
1590048058139.png
1590048058139.png

If It Ain't Dutch, It Ain't Much!!
2020-05-21 08:59:22
an attribute to use [url='https://www.torrenttrader.xyz/index.php?threads/disable-the-action-button.10030']Here[/url] ?
2020-05-21 09:52:06
"Propaganda, post: 68618, member: 60":

Our current Bonus Exchange page looks like this >>

[ATTACH=full]5546[/ATTACH]


This is great! I started looking around on Google (and logged into IPTorrents to see my own account), that is more organized and modular
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: 9
  • Members: 0
  • Guests online: 9
  • Comments: 3
  • Messages: 1,728