Gazelle/sections/ajax/user.php

391 lines
11 KiB
PHP
Raw Permalink Normal View History

2011-10-31 08:00:12 +00:00
<?php
2013-04-24 08:00:23 +00:00
if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
2013-05-14 08:00:34 +00:00
json_die("failure", "bad id parameter");
2013-04-24 08:00:23 +00:00
}
2011-10-31 08:00:12 +00:00
$UserID = $_GET['id'];
2013-05-04 08:00:48 +00:00
if ($UserID == $LoggedUser['ID']) {
2011-10-31 08:00:12 +00:00
$OwnProfile = true;
} else {
$OwnProfile = false;
}
// Always view as a normal user.
2013-05-04 08:00:48 +00:00
$DB->query("
SELECT
m.Username,
m.Email,
m.LastAccess,
m.IP,
p.Level AS Class,
m.Uploaded,
m.Downloaded,
m.RequiredRatio,
m.Enabled,
m.Paranoia,
m.Invites,
m.Title,
m.torrent_pass,
m.can_leech,
i.JoinDate,
i.Info,
i.Avatar,
i.Donor,
i.Warned,
COUNT(posts.id) AS ForumPosts,
i.Inviter,
i.DisableInvites,
inviter.username
2011-10-31 08:00:12 +00:00
FROM users_main AS m
2013-05-04 08:00:48 +00:00
JOIN users_info AS i ON i.UserID = m.ID
2013-06-24 08:00:28 +00:00
LEFT JOIN permissions AS p ON p.ID = m.PermissionID
2013-05-04 08:00:48 +00:00
LEFT JOIN users_main AS inviter ON i.Inviter = inviter.ID
LEFT JOIN forums_posts AS posts ON posts.AuthorID = m.ID
WHERE m.ID = $UserID
GROUP BY AuthorID");
2011-10-31 08:00:12 +00:00
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) { // If user doesn't exist
2013-05-14 08:00:34 +00:00
json_die("failure", "no such user");
2011-10-31 08:00:12 +00:00
}
2013-08-28 23:08:41 +00:00
list($Username, $Email, $LastAccess, $IP, $Class, $Uploaded, $Downloaded, $RequiredRatio, $Enabled, $Paranoia, $Invites, $CustomTitle, $torrent_pass, $DisableLeech, $JoinDate, $Info, $Avatar, $Donor, $Warned, $ForumPosts, $InviterID, $DisableInvites, $InviterName, $RatioWatchEnds, $RatioWatchDownload) = $DB->next_record(MYSQLI_NUM, array(9, 11));
2011-10-31 08:00:12 +00:00
$Paranoia = unserialize($Paranoia);
2013-05-04 08:00:48 +00:00
if (!is_array($Paranoia)) {
2011-10-31 08:00:12 +00:00
$Paranoia = array();
}
$ParanoiaLevel = 0;
2013-05-04 08:00:48 +00:00
foreach ($Paranoia as $P) {
2011-10-31 08:00:12 +00:00
$ParanoiaLevel++;
2013-06-24 08:00:28 +00:00
if (strpos($P, '+') !== false) {
2011-10-31 08:00:12 +00:00
$ParanoiaLevel++;
}
}
// Raw time is better for JSON.
//$JoinedDate = time_diff($JoinDate);
//$LastAccess = time_diff($LastAccess);
function check_paranoia_here($Setting) {
global $Paranoia, $Class, $UserID;
return check_paranoia($Setting, $Paranoia, $Class, $UserID);
}
$Friend = false;
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT FriendID
FROM friends
2013-06-24 08:00:28 +00:00
WHERE UserID = '$LoggedUser[ID]'
AND FriendID = '$UserID'");
2013-07-10 00:08:53 +00:00
if ($DB->has_results()) {
2011-10-31 08:00:12 +00:00
$Friend = true;
}
if (check_paranoia_here('requestsfilled_count') || check_paranoia_here('requestsfilled_bounty')) {
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT COUNT(DISTINCT r.ID), SUM(rv.Bounty)
FROM requests AS r
2013-06-24 08:00:28 +00:00
LEFT JOIN requests_votes AS rv ON r.ID = rv.RequestID
2013-06-04 08:00:34 +00:00
WHERE r.FillerID = $UserID");
2011-10-31 08:00:12 +00:00
list($RequestsFilled, $TotalBounty) = $DB->next_record();
2013-06-04 08:00:34 +00:00
$DB->query("
2013-11-17 08:00:47 +00:00
SELECT COUNT(RequestID), SUM(Bounty)
FROM requests_votes
WHERE UserID = $UserID");
2011-10-31 08:00:12 +00:00
list($RequestsVoted, $TotalSpent) = $DB->next_record();
2013-06-04 08:00:34 +00:00
$DB->query("
SELECT COUNT(ID)
FROM torrents
2013-06-24 08:00:28 +00:00
WHERE UserID = '$UserID'");
2011-10-31 08:00:12 +00:00
list($Uploads) = $DB->next_record();
} else {
2015-01-28 08:00:26 +00:00
$RequestsFilled = null;
$TotalBounty = null;
$RequestsVoted = null;
$TotalSpent = null;
2011-10-31 08:00:12 +00:00
}
2013-05-04 08:00:48 +00:00
if (check_paranoia_here('uploads+')) {
2013-06-04 08:00:34 +00:00
$DB->query("
SELECT COUNT(ID)
FROM torrents
2013-06-24 08:00:28 +00:00
WHERE UserID = '$UserID'");
2011-10-31 08:00:12 +00:00
list($Uploads) = $DB->next_record();
} else {
2012-01-30 08:00:24 +00:00
$Uploads = null;
2011-10-31 08:00:12 +00:00
}
if (check_paranoia_here('artistsadded')) {
2013-05-27 08:00:58 +00:00
$DB->query("
2013-11-17 08:00:47 +00:00
SELECT COUNT(ArtistID)
FROM torrents_artists
WHERE UserID = $UserID");
2011-10-31 08:00:12 +00:00
list($ArtistsAdded) = $DB->next_record();
} else {
2015-01-28 08:00:26 +00:00
$ArtistsAdded = null;
2011-10-31 08:00:12 +00:00
}
// Do the ranks.
if (check_paranoia_here('uploaded')) {
2013-06-19 08:01:09 +00:00
$UploadedRank = UserRank::get_rank('uploaded', $Uploaded);
2012-01-30 08:00:24 +00:00
} else {
$UploadedRank = null;
2011-10-31 08:00:12 +00:00
}
if (check_paranoia_here('downloaded')) {
2013-06-19 08:01:09 +00:00
$DownloadedRank = UserRank::get_rank('downloaded', $Downloaded);
2012-01-30 08:00:24 +00:00
} else {
$DownloadedRank = null;
2011-10-31 08:00:12 +00:00
}
if (check_paranoia_here('uploads+')) {
2013-06-19 08:01:09 +00:00
$UploadsRank = UserRank::get_rank('uploads', $Uploads);
2012-01-30 08:00:24 +00:00
} else {
$UploadsRank = null;
2011-10-31 08:00:12 +00:00
}
if (check_paranoia_here('requestsfilled_count')) {
2013-06-19 08:01:09 +00:00
$RequestRank = UserRank::get_rank('requests', $RequestsFilled);
2012-01-30 08:00:24 +00:00
} else {
$RequestRank = null;
2011-10-31 08:00:12 +00:00
}
2013-06-19 08:01:09 +00:00
$PostRank = UserRank::get_rank('posts', $ForumPosts);
2011-10-31 08:00:12 +00:00
if (check_paranoia_here('requestsvoted_bounty')) {
2013-06-19 08:01:09 +00:00
$BountyRank = UserRank::get_rank('bounty', $TotalSpent);
2012-01-30 08:00:24 +00:00
} else {
$BountyRank = null;
2011-10-31 08:00:12 +00:00
}
if (check_paranoia_here('artistsadded')) {
2013-06-19 08:01:09 +00:00
$ArtistsRank = UserRank::get_rank('artists', $ArtistsAdded);
2012-01-30 08:00:24 +00:00
} else {
$ArtistsRank = null;
2011-10-31 08:00:12 +00:00
}
2013-05-04 08:00:48 +00:00
if ($Downloaded == 0) {
2011-10-31 08:00:12 +00:00
$Ratio = 1;
2013-05-04 08:00:48 +00:00
} elseif ($Uploaded == 0) {
2011-10-31 08:00:12 +00:00
$Ratio = 0.5;
} else {
2013-06-04 08:00:34 +00:00
$Ratio = round($Uploaded / $Downloaded, 2);
2011-10-31 08:00:12 +00:00
}
2012-01-30 08:00:24 +00:00
if (check_paranoia_here(array('uploaded', 'downloaded', 'uploads+', 'requestsfilled_count', 'requestsvoted_bounty', 'artistsadded'))) {
2013-06-19 08:01:09 +00:00
$OverallRank = floor(UserRank::overall_score($UploadedRank, $DownloadedRank, $UploadsRank, $RequestRank, $PostRank, $BountyRank, $ArtistsRank, $Ratio));
2012-01-30 08:00:24 +00:00
} else {
$OverallRank = null;
2011-10-31 08:00:12 +00:00
}
// Community section
2014-09-17 08:00:29 +00:00
if (check_paranoia_here('snatched+')) {
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT COUNT(x.uid), COUNT(DISTINCT x.fid)
FROM xbt_snatched AS x
2013-06-24 08:00:28 +00:00
INNER JOIN torrents AS t ON t.ID = x.fid
WHERE x.uid = '$UserID'");
2011-10-31 08:00:12 +00:00
list($Snatched, $UniqueSnatched) = $DB->next_record();
2012-01-30 08:00:24 +00:00
}
2011-10-31 08:00:12 +00:00
2014-09-17 08:00:29 +00:00
if (check_paranoia_here('torrentcomments+')) {
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT COUNT(ID)
2013-08-28 23:08:41 +00:00
FROM comments
WHERE Page = 'torrents'
AND AuthorID = '$UserID'");
2011-10-31 08:00:12 +00:00
list($NumComments) = $DB->next_record();
}
2015-01-28 08:00:26 +00:00
if (check_paranoia_here('torrentcomments+')) {
$DB->query("
SELECT COUNT(ID)
FROM comments
WHERE Page = 'artist'
AND AuthorID = '$UserID'");
list($NumArtistComments) = $DB->next_record();
}
if (check_paranoia_here('torrentcomments+')) {
$DB->query("
SELECT COUNT(ID)
FROM comments
WHERE Page = 'collages'
AND AuthorID = '$UserID'");
list($NumCollageComments) = $DB->next_record();
}
if (check_paranoia_here('torrentcomments+')) {
$DB->query("
SELECT COUNT(ID)
FROM comments
WHERE Page = 'requests'
AND AuthorID = '$UserID'");
list($NumRequestComments) = $DB->next_record();
}
2014-09-17 08:00:29 +00:00
if (check_paranoia_here('collages+')) {
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT COUNT(ID)
FROM collages
2013-06-24 08:00:28 +00:00
WHERE Deleted = '0'
AND UserID = '$UserID'");
2011-10-31 08:00:12 +00:00
list($NumCollages) = $DB->next_record();
}
2014-09-17 08:00:29 +00:00
if (check_paranoia_here('collagecontribs+')) {
2013-05-27 08:00:58 +00:00
$DB->query("
2013-11-17 08:00:47 +00:00
SELECT COUNT(DISTINCT ct.CollageID)
2013-05-27 08:00:58 +00:00
FROM collages_torrents AS ct
2013-11-17 08:00:47 +00:00
JOIN collages AS c ON ct.CollageID = c.ID
WHERE c.Deleted = '0'
2013-06-24 08:00:28 +00:00
AND ct.UserID = '$UserID'");
2011-10-31 08:00:12 +00:00
list($NumCollageContribs) = $DB->next_record();
}
2014-09-17 08:00:29 +00:00
if (check_paranoia_here('uniquegroups+')) {
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT COUNT(DISTINCT GroupID)
FROM torrents
WHERE UserID = '$UserID'");
2011-10-31 08:00:12 +00:00
list($UniqueGroups) = $DB->next_record();
}
2014-09-17 08:00:29 +00:00
if (check_paranoia_here('perfectflacs+')) {
2013-05-04 08:00:48 +00:00
$DB->query("
SELECT COUNT(ID)
FROM torrents
WHERE (
(LogScore = 100 AND Format = 'FLAC')
OR (Media = 'Vinyl' AND Format = 'FLAC')
OR (Media = 'WEB' AND Format = 'FLAC')
OR (Media = 'DVD' AND Format = 'FLAC')
OR (Media = 'Soundboard' AND Format = 'FLAC')
OR (Media = 'Cassette' AND Format = 'FLAC')
OR (Media = 'SACD' AND Format = 'FLAC')
OR (Media = 'Blu-ray' AND Format = 'FLAC')
OR (Media = 'DAT' AND Format = 'FLAC')
)
AND UserID = '$UserID'");
2011-10-31 08:00:12 +00:00
list($PerfectFLACs) = $DB->next_record();
}
if (check_paranoia_here('seeding+')) {
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT COUNT(x.uid)
FROM xbt_files_users AS x
2013-06-24 08:00:28 +00:00
INNER JOIN torrents AS t ON t.ID = x.fid
WHERE x.uid = '$UserID'
AND x.remaining = 0");
2011-10-31 08:00:12 +00:00
list($Seeding) = $DB->next_record();
}
if (check_paranoia_here('leeching+')) {
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT COUNT(x.uid)
FROM xbt_files_users AS x
2013-06-24 08:00:28 +00:00
INNER JOIN torrents AS t ON t.ID = x.fid
WHERE x.uid = '$UserID'
AND x.remaining > 0");
2011-10-31 08:00:12 +00:00
list($Leeching) = $DB->next_record();
}
2013-05-04 08:00:48 +00:00
if (check_paranoia_here('invitedcount')) {
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT COUNT(UserID)
FROM users_info
2013-06-24 08:00:28 +00:00
WHERE Inviter = '$UserID'");
2011-10-31 08:00:12 +00:00
list($Invited) = $DB->next_record();
}
if (!$OwnProfile) {
2013-05-04 08:00:48 +00:00
$torrent_pass = '';
2011-10-31 08:00:12 +00:00
}
// Run through some paranoia stuff to decide what we can send out.
if (!check_paranoia_here('lastseen')) {
2013-05-04 08:00:48 +00:00
$LastAccess = '';
2011-10-31 08:00:12 +00:00
}
2013-08-28 23:08:41 +00:00
if (check_paranoia_here('ratio')) {
$Ratio = Format::get_ratio($Uploaded, $Downloaded, 5);
} else {
$Ratio = null;
}
2011-10-31 08:00:12 +00:00
if (!check_paranoia_here('uploaded')) {
2012-01-30 08:00:24 +00:00
$Uploaded = null;
2011-10-31 08:00:12 +00:00
}
if (!check_paranoia_here('downloaded')) {
2012-01-30 08:00:24 +00:00
$Downloaded = null;
2011-10-31 08:00:12 +00:00
}
if (isset($RequiredRatio) && !check_paranoia_here('requiredratio')) {
2012-01-30 08:00:24 +00:00
$RequiredRatio = null;
2011-10-31 08:00:12 +00:00
}
2013-05-04 08:00:48 +00:00
if ($ParanoiaLevel == 0) {
2011-10-31 08:00:12 +00:00
$ParanoiaLevelText = 'Off';
2013-05-04 08:00:48 +00:00
} elseif ($ParanoiaLevel == 1) {
2011-10-31 08:00:12 +00:00
$ParanoiaLevelText = 'Very Low';
2013-05-04 08:00:48 +00:00
} elseif ($ParanoiaLevel <= 5) {
2011-10-31 08:00:12 +00:00
$ParanoiaLevelText = 'Low';
2013-05-04 08:00:48 +00:00
} elseif ($ParanoiaLevel <= 20) {
2011-10-31 08:00:12 +00:00
$ParanoiaLevelText = 'High';
} else {
$ParanoiaLevelText = 'Very high';
}
2013-04-24 08:00:23 +00:00
//Bugfix for no access time available
2013-05-04 08:00:48 +00:00
if ($LastAccess == '0000-00-00 00:00:00') {
2013-05-14 08:00:34 +00:00
$LastAccess = '';
2013-04-24 08:00:23 +00:00
}
2011-10-31 08:00:12 +00:00
header('Content-Type: text/plain; charset=utf-8');
2015-01-28 08:00:26 +00:00
json_print("success", array(
2013-05-14 08:00:34 +00:00
'username' => $Username,
'avatar' => $Avatar,
'isFriend' => $Friend,
2013-12-12 08:01:01 +00:00
'profileText' => Text::full_format($Info),
2013-05-14 08:00:34 +00:00
'stats' => array(
'joinedDate' => $JoinDate,
'lastAccess' => $LastAccess,
2013-10-30 08:01:19 +00:00
'uploaded' => (($Uploaded == null) ? null : (int)$Uploaded),
'downloaded' => (($Downloaded == null) ? null : (int)$Downloaded),
2013-05-14 08:00:34 +00:00
'ratio' => $Ratio,
2013-10-30 08:01:19 +00:00
'requiredRatio' => (($RequiredRatio == null) ? null : (float)$RequiredRatio)
2013-05-14 08:00:34 +00:00
),
'ranks' => array(
'uploaded' => $UploadedRank,
'downloaded' => $DownloadedRank,
'uploads' => $UploadsRank,
'requests' => $RequestRank,
'bounty' => $BountyRank,
'posts' => $PostRank,
'artists' => $ArtistsRank,
2013-06-04 08:00:34 +00:00
'overall' => (($OverallRank == null) ? 0 : $OverallRank)
2013-05-14 08:00:34 +00:00
),
'personal' => array(
'class' => $ClassLevels[$Class]['Name'],
'paranoia' => $ParanoiaLevel,
'paranoiaText' => $ParanoiaLevelText,
2013-06-04 08:00:34 +00:00
'donor' => ($Donor == 1),
2013-05-14 08:00:34 +00:00
'warned' => ($Warned != '0000-00-00 00:00:00'),
'enabled' => ($Enabled == '1' || $Enabled == '0' || !$Enabled),
'passkey' => $torrent_pass
),
'community' => array(
2013-10-30 08:01:19 +00:00
'posts' => (int)$ForumPosts,
2015-01-28 08:00:26 +00:00
'torrentComments' => (($NumComments == null) ? null : (int)$NumComments),
'artistComments' => (($NumArtistComments == null) ? null : (int)$NumArtistComments),
'collageComments' => (($NumCollageComments == null) ? null : (int)$NumCollageComments),
'requestComments' => (($NumRequestComments == null) ? null : (int)$NumRequestComments),
2013-10-30 08:01:19 +00:00
'collagesStarted' => (($NumCollages == null) ? null : (int)$NumCollages),
'collagesContrib' => (($NumCollageContribs == null) ? null : (int)$NumCollageContribs),
'requestsFilled' => (($RequestsFilled == null) ? null : (int)$RequestsFilled),
2015-01-28 08:00:26 +00:00
'bountyEarned' => (($TotalBounty == null) ? null : (int)$TotalBounty),
2013-10-30 08:01:19 +00:00
'requestsVoted' => (($RequestsVoted == null) ? null : (int)$RequestsVoted),
2015-01-28 08:00:26 +00:00
'bountySpent' => (($TotalSpent == null) ? null : (int)$TotalSpent),
2013-10-30 08:01:19 +00:00
'perfectFlacs' => (($PerfectFLACs == null) ? null : (int)$PerfectFLACs),
'uploaded' => (($Uploads == null) ? null : (int)$Uploads),
'groups' => (($UniqueGroups == null) ? null : (int)$UniqueGroups),
'seeding' => (($Seeding == null) ? null : (int)$Seeding),
'leeching' => (($Leeching == null) ? null : (int)$Leeching),
'snatched' => (($Snatched == null) ? null : (int)$Snatched),
2015-01-28 08:00:26 +00:00
'invited' => (($Invited == null) ? null : (int)$Invited),
'artistsAdded' => (($ArtistsAdded == null) ? null : (int)$ArtistsAdded)
2013-05-14 08:00:34 +00:00
)
2013-04-24 08:00:23 +00:00
));
2011-10-31 08:00:12 +00:00
?>