hajime/public/profile.php

182 lines
7.7 KiB
PHP
Raw Normal View History

2023-08-11 22:16:32 +00:00
<?php
// profile.php
// Last update: 2015-02-21
// Require core components
require_once __DIR__ . '/../startup.php';
// If ?u= isn't set redirect to index
if(!isset($_GET['u'])) {
header('Location: /');
exit;
}
// Get data from URL and Database
$user = $database->real_escape_string($_GET['u']);
$userQuery = $database->query("SELECT * FROM `flashii_users` WHERE `username_clean`='".$user."' OR `id`='".$user."' AND `userrole`!='0' LIMIT 1");
$userArray = $userQuery->fetch_array(MYSQLI_ASSOC);
$groupQuery = $database->query("SELECT * FROM `flashii_groups` WHERE `gid`='".$userArray['userrole']."' LIMIT 1");
$groupArray = $groupQuery->fetch_array(MYSQLI_ASSOC);
$warnQuery = $database->query("SELECT * FROM `flashii_warnings` WHERE `userid`='".$userArray['id']."'");
$warnArray = $warnQuery->fetch_all(MYSQLI_ASSOC);
// Check if the user exists
$userExists = $userArray ? true : false;
// Check if profile markdown is set
$userPage = $userArray['profilemarkdown'] ? true : false;
// Check the standing of the account
$standing = $warnArray ? true : false;
// Assign certain data to their own variable
$userVar = array();
$userVar['title'] = $userExists ? 'Profile of '.$userArray['username'] : 'User does not exist.';
$userVar['avatar'] = '/a/' . $userArray['id'];
$userVar['uTitle'] = $userArray['usertitle'] ? $userArray['usertitle'] : $groupArray['name'] ;
$userVar['profileBg'] = empty($userArray['profilebg']) ? null : '<style>body {background: url("/bg/'.$userArray['id'].'") no-repeat fixed center center / cover #000 !important;} .profile {background: rgba(211, 191, 255, .8) !important;}</style>';
$userVar['sideBar'] = '';
// Set sideBar values
if($flashii->loggedIn()) {
if(!empty($userArray['birthdate'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Age</b></td><td style="text-align: right;">'
. date_diff(date_create(date('Y-m-d', $userArray['birthdate'])), date_create(date('Y-m-d')))->format('%Y')
. '</td></tr>';
}
if(!empty($userArray['gender'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Gender</b></td><td style="text-align: right;">'
. ($gaytumblrshit[$userArray['gender']] ?? 'Undiscovered')
. '</td></tr>';
}
if(!empty($userArray['website'])) {
$website = preg_match("~^(?:f|ht)tps?://~i", $userArray['website']) ? $userArray['website'] : 'http://' . $userArray['website'];
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Website</b></td><td style="text-align: right;"><a class="default" href="'
. $website
. '" target="_blank">'
. $userArray['website']
. '</a></td></tr>';
}
if(!empty($userArray['twitter'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Twitter</b></td><td style="text-align: right;"><a class="default" href="http://twitter.com/'
. $userArray['twitter']
. '" target="_blank">@'
. $userArray['twitter']
. '</a></td></tr>';
}
if(!empty($userArray['github'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>GitHub</b></td><td style="text-align: right;"><a class="default" href="http://github.com/'
. $userArray['github']
. '" target="_blank">'
. $userArray['github']
. '</a></td></tr>';
}
if(!empty($userArray['skype'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Skype</b></td><td style="text-align: right;"><a class="default" href="skype:'
. $userArray['skype']
. '?userinfo">'
. $userArray['skype']
. '</a></td></tr>';
}
if(!empty($userArray['youtube'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>YouTube</b></td><td style="text-align: right;"><a class="default" href="http://youtube.com/'
. ($userArray['youtube_type'] ? 'channel' : 'user') . '/' . $userArray['youtube'] .'" target="_blank">' . ($userArray['youtube_type'] ? $userArray['username'] . '\'s Channel' : $userArray['youtube'])
. '</a></td></tr>';
}
if(!empty($userArray['soundcloud'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>SoundCloud</b></td><td style="text-align: right;"><a class="default" href="http://soundcloud.com/'
. $userArray['soundcloud']
. '" target="_blank">'
. $userArray['soundcloud']
. '</a></td></tr>';
}
if(!empty($userArray['steam'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Steam</b></td><td style="text-align: right;"><a class="default" href="http://steamcommunity.com/id/'
. $userArray['steam']
. '" target="_blank">'
. $userArray['steam']
. '</a></td></tr>';
}
if(!empty($userArray['osu'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>osu!</b></td><td style="text-align: right;"><a class="default" href="http://osu.ppy.sh/u/'
. $userArray['osu']
. '" target="_blank">'
. $userArray['osu']
. '</a></td></tr>';
}
if(!empty($userArray['eaorigin'])) { // Fuck this one
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Origin</b></td><td style="text-align: right;">'
. $userArray['eaorigin']
. '</td></tr>';
}
if(!empty($userArray['xboxlive'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Xbox live</b></td><td style="text-align: right;"><a class="default" href="https://account.xbox.com/en-GB/Profile?Gamertag='
. $userArray['xboxlive']
. '" target="_blank">'
. $userArray['xboxlive']
. '</a></td></tr>';
}
if(!empty($userArray['playstation'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>PSN</b></td><td style="text-align: right;"><a class="default" href="http://psnprofiles.com/'
. $userArray['playstation']
. '" target="_blank">'
. $userArray['playstation']
. '</a></td></tr>';
}
if($flashii->checkRank($fwSettings['staffRanks'])) {
if(!empty($userArray['register_ip'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Registered from IP</b></td><td style="text-align: right;">'
. $userArray['register_ip']
. '</td></tr>';
}
if(!empty($userArray['last_ip'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>Last seen on IP</b></td><td style="text-align: right;">'
. $userArray['last_ip']
. '</td></tr>';
}
if(!empty($userArray['email'])) {
$userVar['sideBar'] .= '<tr><td style="text-align: left;"><b>E-mail Address</b></td><td style="text-align: right;"><a class="default" href="mailto:'
. $userArray['email']
. '" target="_blank">'
. $userArray['email']
. '</a></td></tr>';
}
}
} else {
$userVar['sideBar'] = '<tr><td colspan="2"><b>Please login to view the full profile of this user.</b></td></tr>';
}
// Profile Read-Only "API"
if(isset($_GET['data'])) {
header('Content-Type: text/plain; charset=utf-8');
header('Access-Control-Allow-Origin: *');
$userData = array();
if($userExists) {
$userData['userID'] = $userArray['id'];
$userData['userName'] = $userArray['username'];
$userData['userAvatar'] = 'http://' . $_SERVER['HTTP_HOST'] . '/a/'. $userArray['id'];
$userData['userBackground'] = 'http://' . $_SERVER['HTTP_HOST'] . '/bg/'. $userArray['id'];
$userData['userTitle'] = $userVar['uTitle'];
$userData['groupID'] = $groupArray['gid'];
$userData['groupName'] = $groupArray['name'];
$userData['groupColour'] = $groupArray['colour'];
$userData['joinTimeStamp'] = $userArray['join_date'];
$userData['lastTimeStamp'] = $userArray['last_seen'] ? $userArray['last_seen'] : 0;
$userData['markdown'] = base64_encode(strip_tags($userArray['profilemarkdown']));
$userData['error'] = false;
} else {
$userData['error'] = true;
}
print_r(json_encode($userData));
exit;
}
// Initialise Markdown parser
$mdparser = new Parsedown();
require_once fiiSwitch_path();