in BETA. Some useful code here for creative minds.
Learning shorter code, better counting methods, sub-queries to make things easier. Markup hand-written, no fancy frameworks just PHP and HTML.
Learning shorter code, better counting methods, sub-queries to make things easier. Markup hand-written, no fancy frameworks just PHP and HTML.
<?
if (session_status() == PHP_SESSION_NONE) { session_start(); }
require_once '../site.php';
$db->connect();
site_header();
// Account Profiles - New - June 7, 2021
if (isset($_GET['id'])) {
// Get user data
$profile_data = $db->query_params('SELECT * FROM users WHERE user_id = :user_id', array(
'user_id' => isset($_GET['id']) ? intval($_GET['id']) : 0
));
// Check & insert/update views
$checkrow = $db->query_params('SELECT userid FROM profileviews WHERE userid = :user_id', array(
'user_id' => isset($_GET['id']) ? intval($_GET['id']) : 0
));
/*
$db->query_params('INSERT INTO profileviews (userid, userviewed, viewed, times) VALUES (:user_id_cur, :user_id, NOW(), 1)', array(
'user_id_cur' => $account->getId(),
'user_id' => intval($_GET['id'])
));
*/
if (!$profile_data) {
echo 'Invalid User ID';
}
} else {
echo 'Invalid request';
}
if ($profile_data) {
foreach ($profile_data as $row):
// User country flag
$country_flag = $db->query_params('SELECT name, flagpic FROM countries WHERE id = :country', array(
'country' => intval($row['country'])
));
// User level
$groups = $db->query_params('SELECT g.level FROM users u LEFT JOIN groups g ON g.group_id = u.class WHERE u.user_id = :user_id', array(
'user_id' => intval($row['user_id'])
));
$ulevel = '';
if ($level = $groups->fetch()) {
$ulevel = strval($level['level']);
}
// Get user views
$profile_views = $db->query_params('SELECT p.userid, p.userviewed, p.times, u.user_id, u.avatar_thumb AS avatar FROM users u LEFT JOIN profileviews p ON p.userviewed = u.user_id WHERE p.userid = :user_id ORDER BY p.viewed DESC', array(
'user_id' => intval($row['user_id'])
));
// Get friends
$friends = $db->query_params('SELECT (SELECT COUNT(*) FROM friends WHERE userid = f.userid) AS total, u.user_id, u.avatar_thumb AS avatar, f.userid FROM friends f LEFT JOIN users u ON u.user_id = f.friendid WHERE f.userid = :user_id', array(
'user_id' => isset($_GET['id']) ? intval($_GET['id']) : 0
));
// Get users recent downloads
$recentdl = $db->query_params("SELECT (SELECT COUNT(torrentid) FROM users_downloaded WHERE userid = u.user_id) AS total, ud.userid, u.avatar_thumb AS avatar, t.torrent_id, t.cover1, t.name FROM users u LEFT JOIN users_downloaded ud ON ud.userid = u.user_id LEFT JOIN torrents t ON t.torrent_id = ud.torrentid WHERE ud.userid = :user_id AND torrent_id != 'NULL'", array(
'user_id' => $row['user_id']
));
// Get user ratio
$ratio = 0;
if ($row['downloaded'] > 0) {
$ratio = number_format($row['uploaded'] / $row['downloaded'], 2);
}
// Check blocked
if ($account->sessionLogin()) {
$blocked = $db->query_params('SELECT id FROM blocked WHERE userid = :user_id AND blockid = :user_id_cur', array(
'user_id' => $row['user_id'],
'user_id_cur' => $account->getId()
));
if ($blocked->fetchAll()) {
echo 'You are blocked by this user.';
}
}
// Get moods
$res = $db->query_params('SELECT name, moodspic FROM moods WHERE id = :user_mood LIMIT 1', array(
'user_mood' => $row['moods']
));
if ($arr = $res->fetch()) {
$moods = '';
}
?>
<!-- Profile buttons -->
<div style="display:inline;float:left;padding-top:17px">
<?
if ($account->sessionlogin()): ?>
<button type='button' class='btn btn-danger' onclick="location.href='/message/?compose&id=<?=intval($row['user_id'])?>'">Message</button>
<? endif;
if ($account->getId() !== $row['user_id']) {
$f = $db->query_params('SELECT id, userid FROM friends WHERE userid = :user_id_cur AND friendid = :friend_id', array(
'user_id_cur' => $account->getId(),
'friend_id' => $row['user_id']
));
$b = $db->query_params('SELECT id, userid FROM blocked WHERE userid = :user_id_cur AND blockid = :block_id', array(
'user_id_cur' => $account->getId(),
'block_id' => $row['user_id']
));
if ($friend = $f->fetch()) {
echo "<button type=\"button\" style=\"margin-right:5px\" class='btn btn-danger' onclick=\"location.href='/friends.php?action=delete&type=friend&targetid=$friend[userid]'\">Unfriend</button>";
}
if ($block = $b->fetch()) {
echo "<button type=\"button\" class='btn btn-danger' onclick=\"location.href='/friends.php?action=delete&type=block&targetid=$block[userid]'\">Unblock</button>";
} else {
echo "<button type=\"button\" style=\"margin-right:5px\" class=\"btn btn-danger\" onclick=\"location.href='/friends.php?action=add&type=friend&targetid=$row[user_id]'\">+ Friend</button>";
echo "<button type=\"button\" class=\"btn btn-danger\" onclick=\"location.href='/friends.php?action=add&type=block&targetid=$row[user_id]'\">Block</button>";
}
}
?>
<!-- Left side content -->
<div style="display:inline;float:left">
<h1 itemprop="name">
@<?=html_escape($row['username'])?>
</h1>
<div>
<!-- Left column -->
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card" style="max-width:300px">
<div class="card-action ng-scope" ng-if="item.comment_count">
<!-- Profile picture --><span itemprop="interactionCount" class="comments">
<span style="text-align:center;padding-bottom:23px">
<center><img class="responsive-img" src="/<?=$row['avatar_thumb']?>" style="border-radius:100%;width:150px;height:150px;border:5px solid #ECECEC" /></center>
</span></span>
<!-- Profile views -->
<div style="text-align:center;padding-top:15px;padding-bottom:20px;border-bottom:1px solid #ECECEC">
<div style="color:#D2D2D2;padding-bottom:7px">Profile Views:</div>
<?
$n = 0;
foreach ($profile_views as $vuser) {
$n++;
echo (!empty($vuser['avatar']) && file_exists($vuser['avatar']))
? printf('<a href="/user/?id=%s"><img src="/%s" style="width:23px;height:23px;border-radius:100px" /></a>', $vuser['user_id'], $vuser['avatar'])
: printf('<a href="/user/?id=%s"><img src="/images/noavatar.png" style="width:23px;height:23px;border-radius:100px" /></a>', $vuser['user_id'], $vuser['avatar']);
$total = count($row);
if ($n === 24) break;
}
?>
</div>
<div style="color:#242424;float:right;font-size:15px;padding-top:12px"><b><?=intval($n)?></b> out of <b><?=(isset($total) ? $total : 0)?></b> total visitors</div>
<div style="clear:both"></div>
<!-- User info -->
<div style="text-align:center;padding-top:15px;padding-bottom:20px;border-bottom:1px solid #ECECEC">
<div style="font-size:22px"><?=html_escape($row['username'])?>, <?=html_escape($row['gender'])?>
<?
if ($flag = $country_flag->fetch()) {
printf('<img title="%s" src="/images/countries/%s" style="width:20px;height:20px;vertical-align:middle" />', $flag['name'], $flag['flagpic']);
}
?>
</div>
<div style="color:#C0C0C0">Joined <?=time_ago($row['added'])?></div>
<div style="color:#C0C0C0">Last online: <?=time_ago($row['last_access'])?></div>
<div style="color:#242424;padding-top:7px">Total Ratio: <b><?=$ratio?></b></div>
<div style="background:#D2D2D2;padding:4px;text-align:center;color:#242424;border-radius:7px;margin-top:13px">Account: <?=$ulevel?></div>
</div>
</div>
</article>
</div>
</div>
<!-- Friends list -->
<div style="display:inline;float:left;padding-left:20px;padding-top:70px">
<h1 itemprop="name">
Friends (<?=($total = $friends->fetch()) ? $total['total'] : 0 ?>)
</h1>
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="_card" style="max-width:300px">
<div class="card-action ng-scope" ng-if="item.comment_count">
<!-- Friends -->
<div style="padding-top:15px;padding-bottom:20px;border-bottom:1px solid #ECECEC">
<?
$position = 'left';
$count = 0;
foreach ($friends as $fuser) {
$count++;
echo (!empty($fuser['avatar']) && file_exists($fuser['avatar']))
? printf('<a href="/user/?id=%s"><img src="/%s" style="border:2px solid #E3E3E3;margin:2px;width:45px;height:45px;border-radius:100px;float:%s" /></a>', $fuser['user_id'], $fuser['avatar'], $position, $fuser['user_id'])
: printf('<a href="/user/?id=%s"><img src="/images/noavatar.png" style="border:2px solid #E3E3E3;margin:2px;width:45px;height:45px;border-radius:100px;float:%s" /></a>', $fuser['user_id'], $position, $fuser['user_id']);
if ($count === 40) break;
}
if ($count === 0) printf('No recent friends.');
?>
</div>
</div>
</article>
<!-- BEGIN recents -->
<div style="display:inline;float:left;_padding-top:70px">
<h1 itemprop="name">
Recent's (<?=($title = $recentdl->fetch()) ? intval($title['total']) - 1 : 0 ?>)
</h1>
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="_card" style="max-width:450px">
<div class="card-action ng-scope" ng-if="item.comment_count">
<!-- Titles -->
<div style="padding-top:15px;padding-bottom:20px;border-bottom:1px solid #ECECEC">
<?
// Get item's recent downloads - June 10, 2021
$n=0;
foreach ($recentdl as $item) {
$n++;
printf('<a href="/details/%s/" title="%s"><img src="/%s" style="width:80px;height:120px;margin-right:10px" /></a>', $item['torrent_id'], html_escape($item['name']), file_exists('images/covers/'.$item['cover1']) ? 'images/covers/'.$item['cover1'] : 'images/switch_cover_none.png');
if ($n === 10) break;
$total = $item['total'];
}
if ($total > 0) {
printf('<span style="float:right;padding-right:10px"><a href="#">Browse all</a> - Showing %s of <b>%s</b></span>', $n, $total - 1);
} else {
printf('<span style="float:right;padding-right:10px">No recent titles.');
}
?>
</div>
</div>
</article>
</div>
<!-- END recents -->
</div>
<div style="clear:both"></div>
<!-- Profile bio -->
<div>
<h1 itemprop="name">
about me
</h1>
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article" class="card">
<div class="card-action ng-scope" ng-if="item.comment_count">
<p><?=(!empty($row['profile_bio'])) ? html_escape($row['profile_bio']) : 'No info has been added yet :(';?></p>
</div>
</article>
</div>
<!-- Uploads -->
<div>
<h1 itemprop="name">
uploads
</h1>
<article itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Article">
<div class="card-action ng-scope" ng-if="item.comment_count">
<p>Coming soon.</p>
</div>
</article>
</div>
<?
endforeach;
}
if ($account->sessionLogin()){
$db->query_params("UPDATE users SET page = 'Browsing User Profile', last_access = NOW() WHERE user_id = :user_id", array('user_id' => $account->getId()));
}
site_footer();
Last edited by STorrents2020 on 2021-06-11 05:46:41