Thanks to M-Jay and mostvotedplaya for this mod. Here is an updated version for PHP 8, following the same steps as the first post. Please take a backup of your files and database first.
Files pass a PHP syntax check and the pages load on PHP 8.5 with MariaDB 10.10. Point awards and exchanges have only had light testing so far, so please try it on a test account first.
What changed from the first post
- mysql_fetch_assoc() no longer exists in PHP 8 and crashed the HnR option
- Undefined $_POST keys and null values no longer give warnings
- Points are charged in one query, only after all checks pass, so a double click cannot spend them twice
- The HnR option clears only your own HnR (it could clear another member's), and now has its Torrent ID box
- VIP set class 7, which is Administrator on a default install. It now uses the VIP class and never lowers Uploaders or staff
- The manager no longer uses extract() on $_POST
- seedbonus gets a default of 0, which fixes the signup error in strict mode reported in this topic
SQL:
(If you have a NULL or missing default on seedbonus from the old version, the last two lines fix it. On MySQL remove IF NOT EXISTS.)
CREATE TABLE IF NOT EXISTS `bonus` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`cost` decimal(10,1) unsigned NOT NULL DEFAULT '0.0',
`value` bigint(20) unsigned NOT NULL DEFAULT '0',
`descr` varchar(100) NOT NULL,
`type` varchar(20) NOT NULL DEFAULT 'other',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
INSERT IGNORE INTO `bonus` (`id`, `title`, `cost`, `value`, `descr`, `type`) VALUES
(1, '1 GB Uploaded', '70.0', 1073741824, 'Exchange 70 points for 1 GB upload.', 'traffic'),
(2, '2 GB Uploaded', '100.0', 2147483648, 'Exchange 100 points for 2 GB upload.', 'traffic'),
(3, '5 GB Uploaded', '250.0', 5368709120, 'Exchange 250 points for 5 GB upload.', 'traffic'),
(4, '10 GB Uploaded', '500.0', 10737418240, 'Exchange 500 points for 10 GB upload.', 'traffic'),
(5, 'Invitations', '1000.0', 2, 'Receive 2 Invites for 1000.00 seedbonus points.', 'invite');
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `seedbonus` decimal(10,1) NOT NULL DEFAULT '0.0';
UPDATE `users` SET `seedbonus` = 0 WHERE `seedbonus` IS NULL;
ALTER TABLE `users` MODIFY `seedbonus` decimal(10,1) NOT NULL DEFAULT '0.0';
blocks/login_block.php find
$privacylevel = T_($CURUSER["privacy"]);
Add after
$bonus = number_format((float) ($CURUSER["seedbonus"] ?? 0), 1);
Search (at end of line)
". T_("RATIO") .": $userratio
Add after :
<br>Seedbonus : <b><a href=mybonus.php>".$bonus."</a></b>
backend/cleanup.php find
//LOCAL TORRENTS - MAKE NON-ACTIVE/OLD TORRENTS INVISIBLE
$deadtime = gmtime() - $site_config["max_dead_torrent_time"];
SQL_Query_exec("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME($deadtime) AND seeders = '0' AND leechers = '0' AND external !='yes'");
Add after :
// Seedbonus: points per torrent each member is seeding
$res = SQL_Query_exec("SELECT userid, COUNT(DISTINCT torrent) AS seeding FROM peers WHERE seeder = 'yes' GROUP BY userid");
while ($row = mysqli_fetch_object($res)) {
$points = (float) $site_config["bonuspertime"] * (int) $row->seeding;
SQL_Query_exec("UPDATE users SET seedbonus = seedbonus + $points WHERE id = " . (int) $row->userid);
}
// End Seedbonus
backend/config.php find
$site_config['blocks_dir'] = getcwd().'/blocks';
After add
$site_config["bonuspertime"] = 0.5;
account.php find
<?php print("<a href='mailbox.php'><b>".T_("YOUR_MESSAGES")."</b></a>");?>
|
Add below
|
<?php print("<a href='mybonus.php'><b>My Seedbonus</b></a>");?>
admincp.php find
<td align="center"><a href="admincp.php?action=sqlerr"><img src="images/admin/sql_error.png" border="0" width="32" height="32" alt="" /><br />SQL Error<br /></a></td>
Add below
<td colspan="5"> </td>
</tr>
<tr>
<td align="center"><a href="admincp.php?action=seedbonus"><img src="images/admin/seedbonus.png" border="0" width="32" height="32" alt="" /><br />Management of Seed Bonus</a></td>
</tr>
Search
} // End Forum management
Add after
#======================================================================#
# Seedbonus Manager
#======================================================================#
if ($action == "seedbonus" && $do != "change")
{
if ($do == "del")
{
$ids = array_map("intval", (array) ($_POST["ids"] ?? array()));
if (!$ids) show_error_msg(T_("ERROR"), "Nothing selected.", 1);
SQL_Query_exec("DELETE FROM `bonus` WHERE `id` IN (" . implode(", ", $ids) . ")");
autolink("admincp.php?action=seedbonus", "Deleted entries");
}
$count = get_row_count("bonus");
list($pagertop, $pagerbottom, $limit) = pager(25, $count, 'admincp.php?action=seedbonus&');
$res = SQL_Query_exec("SELECT id, title, cost, value, descr, type FROM `bonus` ORDER BY `type` $limit");
stdhead("Seedbonus Manager");
navmenu();
begin_frame("Management of Seed Bonus");
?>
<center>
This page displays all available options which users can exchange for seedbonus: <?php echo number_format($count); ?><br /><br />
<a href="admincp.php?action=seedbonus&do=change">Add</a> a new option?
</center>
<?php if ($count > 0): ?>
<br />
<form id="seedbonus" method="post" action="admincp.php?action=seedbonus">
<input type="hidden" name="do" value="del" />
<table border="0" cellpadding="3" cellspacing="0" width="100%" align="center" class="table_table">
<tr>
<th class="table_head">Title</th>
<th class="table_head">Description</th>
<th class="table_head">Points</th>
<th class="table_head">Value</th>
<th class="table_head">Type</th>
<th class="table_head">Edit</th>
<th class="table_head"><input type="checkbox" name="checkall" onclick="checkAll(this.form.id);" /></th>
</tr>
<?php while ($row = mysqli_fetch_object($res)):
$shown_value = ($row->type == "traffic") ? mksize($row->value) : (int) $row->value;
?>
<tr>
<td class="table_col1" align="center"><?php echo htmlspecialchars((string) $row->title); ?></td>
<td class="table_col2"><?php echo htmlspecialchars((string) $row->descr); ?></td>
<td class="table_col1" align="center"><?php echo htmlspecialchars((string) $row->cost); ?></td>
<td class="table_col2" align="center"><?php echo $shown_value; ?></td>
<td class="table_col1" align="center"><?php echo htmlspecialchars((string) $row->type); ?></td>
<td class="table_col2" align="center"><a href="admincp.php?action=seedbonus&do=change&id=<?php echo (int) $row->id; ?>">Edit</a></td>
<td class="table_col1" align="center"><input type="checkbox" name="ids[]" value="<?php echo (int) $row->id; ?>" /></td>
</tr>
<?php endwhile; ?>
<tr>
<td colspan="7" align="right"><input type="submit" value="Remove Selected" /></td>
</tr>
</table>
</form>
<?php
endif;
if ($count > 25) echo $pagerbottom;
end_frame();
stdfoot();
}
if ($action == "seedbonus" && $do == "change")
{
$bonus_types = array('invite', 'traffic', 'VIP', 'HnR', 'other');
$bonus_id = (int) ($_REQUEST['id'] ?? 0);
$row = null;
if ($bonus_id > 0)
{
$row = mysqli_fetch_object(SQL_Query_exec("SELECT id, title, cost, value, descr, type FROM `bonus` WHERE `id` = $bonus_id"));
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$title = trim((string) ($_POST['title'] ?? ''));
$descr = trim((string) ($_POST['descr'] ?? ''));
$type = (string) ($_POST['type'] ?? '');
$cost = $_POST['cost'] ?? '';
$raw_value = trim((string) ($_POST['value'] ?? ''));
if ($title === '' || $descr === '' || !in_array($type, $bonus_types, true) || !is_numeric($cost) || $cost < 0)
{
autolink("admincp.php?action=seedbonus&do=change&id=$bonus_id", "Missing information.");
}
$value = ($type == "traffic" && !ctype_digit($raw_value)) ? strtobytes($raw_value) : $raw_value;
$value = sprintf("%.0f", (float) $value);
$cost = (float) $cost;
$title_sql = "'" . mysqli_real_escape_string($GLOBALS["DBconnector"], $title) . "'";
$descr_sql = "'" . mysqli_real_escape_string($GLOBALS["DBconnector"], $descr) . "'";
if ($row == null)
{
SQL_Query_exec("INSERT INTO `bonus` (`title`, `descr`, `cost`, `value`, `type`) VALUES ($title_sql, $descr_sql, $cost, $value, '$type')");
}
else
{
SQL_Query_exec("UPDATE `bonus` SET `title` = $title_sql, `descr` = $descr_sql, `cost` = $cost, `value` = $value, `type` = '$type' WHERE `id` = $bonus_id");
}
autolink("admincp.php?action=seedbonus", "Seed bonus option saved.");
}
stdhead("Seedbonus Management");
navmenu();
begin_frame("Seedbonus Management");
$field = function ($name) use ($row) {
return $row != null ? htmlspecialchars((string) $row->$name, ENT_QUOTES) : '';
};
?>
<form method="post" action="admincp.php?action=seedbonus&do=change">
<?php if ($row != null): ?>
<input type="hidden" name="id" value="<?php echo (int) $row->id; ?>" />
<?php endif; ?>
<table border="0" class="table_table" width="90%" cellpadding="3" align="center">
<tr>
<th class="table_head" colspan="2">Seedbonus Management</th>
</tr>
<tr>
<td class="table_col1"><b>Title:</b></td>
<td class="table_col2"><input type="text" name="title" value="<?php echo $field('title'); ?>" size="50" maxlength="50" /></td>
</tr>
<tr>
<td class="table_col1"><b>Points:</b></td>
<td class="table_col2"><input type="text" name="cost" value="<?php echo $field('cost'); ?>" size="5" /></td>
</tr>
<tr>
<td class="table_col1"><b>Type:</b></td>
<td class="table_col2">
<select name="type">
<?php foreach ($bonus_types as $bonus_type): ?>
<option value="<?php echo $bonus_type; ?>" <?php echo ($row != null && $row->type == $bonus_type ? 'selected="selected"' : ''); ?>><?php echo $bonus_type; ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td class="table_col1"><b>Value:</b></td>
<td class="table_col2"><input type="text" name="value" value="<?php echo $field('value'); ?>" size="14" /> Traffic: bytes or a size such as 5 GB. VIP: days. Invite: number.</td>
</tr>
<tr>
<td class="table_col1" valign="top"><b>Description:</b></td>
<td class="table_col2"><textarea name="descr" rows="5" cols="38" maxlength="100"><?php echo $field('descr'); ?></textarea></td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="reset" value="Cancel" />
<input type="submit" value="Save" />
</td>
</tr>
</table>
</form>
<?php
end_frame();
stdfoot();
}
Use seedbonus.png from bonus.zip in the first post (images/admin folder).
Replace mybonus.php in the root with:
<?php
/**
* @package Seedbonus
* @version TorrentTrader v3 MicroMonkey
* @author mostvotedplaya
* Updated for PHP 8.
*/
require_once("backend/functions.php");
dbconn();
loggedinonly();
// group_id of VIP in your groups table (3 on a default install)
const BONUS_VIP_CLASS = 3;
if (is_valid_id($_POST['id'] ?? 0)) {
$item = mysqli_fetch_object(SQL_Query_exec("SELECT `type`, `value`, `cost` FROM `bonus` WHERE `id` = " . (int) $_POST['id']));
if (!$item || (float) $CURUSER['seedbonus'] < (float) $item->cost) {
autolink("mybonus.php", "Demand not valid.");
}
$uid = (int) $CURUSER['id'];
$cost = (float) $item->cost;
$value = (int) $item->value;
$tid = (int) ($_POST["torrentid"] ?? 0);
// checked before anything is charged
if ($item->type == 'HnR') {
if (!$tid) {
autolink("mybonus.php", "You must fill the box with the id of the torrent.");
}
$check = SQL_Query_exec("SELECT 1 FROM `snatched` WHERE `tid` = $tid AND `uid` = $uid AND `hnr` = 'yes'");
if (mysqli_num_rows($check) == 0) {
autolink("mybonus.php", "No HnR found with this information.");
}
}
// charged in one statement, so a double click cannot spend the points twice
if ($cost > 0) {
SQL_Query_exec("UPDATE `users` SET `seedbonus` = `seedbonus` - $cost WHERE `id` = $uid AND `seedbonus` >= $cost");
if (mysqli_affected_rows($GLOBALS["DBconnector"]) < 1) {
autolink("mybonus.php", "Demand not valid.");
}
}
switch ($item->type) {
case 'invite':
SQL_Query_exec("UPDATE `users` SET `invites` = `invites` + $value WHERE `id` = $uid");
break;
case 'traffic':
SQL_Query_exec("UPDATE `users` SET `uploaded` = `uploaded` + $value WHERE `id` = $uid");
break;
case 'HnR':
$torrent = mysqli_fetch_assoc(SQL_Query_exec("SELECT `name` FROM `torrents` WHERE `id` = $tid"));
$torname = $torrent ? $torrent["name"] : "ID $tid";
write_log("The HnR of " . $CURUSER['username'] . " on the torrent " . htmlspecialchars($torname) . " has been cleared with seed bonus points.");
$modcom = sqlesc(gmdate("d-m-Y H:i") . " - H&R on the torrent $torname cleared against $cost points\n");
SQL_Query_exec("UPDATE `users` SET `modcomment` = CONCAT($modcom, IFNULL(`modcomment`, '')) WHERE `id` = $uid");
SQL_Query_exec("UPDATE `snatched` SET `ltime` = '129600', `hnr` = 'no' WHERE `tid` = $tid AND `uid` = $uid");
break;
case 'VIP':
// Uploaders and staff keep their higher class
SQL_Query_exec("UPDATE `users` SET `class` = " . BONUS_VIP_CLASS . " WHERE `id` = $uid AND `class` < " . BONUS_VIP_CLASS);
break;
case 'other':
break;
}
autolink("mybonus.php", "Your account has been credited.");
}
$my_points = (float) ($CURUSER['seedbonus'] ?? 0);
$items = array();
$res = SQL_Query_exec("SELECT * FROM `bonus` ORDER BY `type`");
while ($row = mysqli_fetch_object($res)) {
$items[] = $row;
}
stdhead("Seedbonus");
begin_frame("Bonus Exchange");
// one form per item; the fields in the table refer to it with the form attribute
foreach ($items as $row) {
echo "<form id='bonus-form-" . (int) $row->id . "' method='post' action='mybonus.php'><input type='hidden' name='id' value='" . (int) $row->id . "' /></form>\n";
}
?>
<center>
This page displays the options that you can redeem your accumulated points for.<br />
Your points: <b><?php echo number_format($my_points, 1); ?></b>
</center>
<br />
<table border="0" cellpadding="3" class="table_table" width="100%">
<tr>
<th class="table_head">Option</th>
<th class="table_head">What is it?</th>
<th class="table_head">Points</th>
<th class="table_head">Exchange</th>
</tr>
<?php foreach ($items as $row): $form = "bonus-form-" . (int) $row->id; ?>
<tr>
<td class="table_col1">
<?php echo htmlspecialchars((string) $row->title); ?>
<?php if ($row->type == 'HnR'): ?>
<br /><input type="text" name="torrentid" form="<?php echo $form; ?>" placeholder="Enter Torrent ID" required />
<?php endif; ?>
</td>
<td class="table_col2"><?php echo htmlspecialchars((string) $row->descr); ?></td>
<td class="table_col1" align="center"><?php echo number_format((float) $row->cost, 1); ?></td>
<td class="table_col2" align="center"><input type="submit" form="<?php echo $form; ?>" value="Exchange" <?php echo ($my_points < (float) $row->cost ? 'disabled="disabled"' : ''); ?> /></td>
</tr>
<?php endforeach; ?>
</table>
<ul>
<li>You receive <b><?php echo htmlspecialchars((string) $site_config['bonuspertime']); ?></b> points per torrent you are seeding, every <?php echo (int) floor($site_config['autoclean_interval'] / 60); ?> minutes.</li>
</ul>
<ul>
<li><a href="account.php">Return to profile</a></li>
</ul>
<?php
end_frame();
stdfoot();
?>
Notes: the HnR option needs the snatched table from the HnR mod. VIP only raises the class and does not expire by itself.
If It Ain't Dutch, It Ain't Much!!