prepare($query); $stmt->bindParam(':id', $userID, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC); } public static function getUserSheetByIDForum($userID) { $query = "SELECT id, username, rank, imgTime FROM users WHERE id = :id"; $stmt = $GLOBALS['dbcon']->prepare($query); $stmt->bindParam(':id', $userID, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC); } public static function jsonToSingle($json) { $jsonNew = substr($json, 1); $jsonNew = substr_replace($jsonNew, "", -1); return $jsonNew; } public static function getTimeSince($timeFrom) { $to_time = strtotime(context::getCurrentTime()); $from_time = strtotime($timeFrom); return round(abs($to_time - $from_time) / 60,2); } public static function IDToUsername($userID) { $stmt = $GLOBALS['dbcon']->prepare('SELECT username FROM users WHERE id = :userId'); $stmt->bindParam(':userId', $userID, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); return $result['username']; } public static function getUserImage($userSheet) { if ($userSheet['imgTime'] == 0 || $userSheet['imgTime'] == null) { return 'https://api.xdiscuss.net/imageServer/user/def2.png?v=2'; }else{ return 'https://api.xdiscuss.net/imageServer/user/'.$userSheet['id'].'.png?time='.$userSheet['imgTime']; } } public static function getGroupImage($userID) { $query = "SELECT imgTime, id FROM users WHERE id = :id"; $stmt = $GLOBALS['dbcon']->prepare($query); $stmt->bindParam(':id', $userID, PDO::PARAM_INT); $stmt->execute(); $userSheet = $stmt->fetch(PDO::FETCH_ASSOC); if ($userSheet['imgTime'] == 0 || $userSheet['imgTime'] == null) { return 'https://api.xdiscuss.net/imageServer/user/def2.png'; }else{ return 'https://api.xdiscuss.net/imageServer/user/'.$userSheet['id'].'.png?time='.$userSheet['imgTime']; } } public static function getOnline($userSheet) { $from_time = strtotime($userSheet['lastSeen']); $to_time = strtotime(context::getCurrentTime()); $timeSince = round(abs($to_time - $from_time) / 60,2); if ($timeSince > 5) { return '● '; }else{ return '● '; } } public static function humanTiming ($time) { $time = time()-$time; $time = 86400-$time; $time = ($time<1)? 1 : $time; $tokens = array ( 31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($tokens as $unit => $text) { if ($time < $unit) continue; $numberOfUnits = floor($time / $unit); return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); } } public static function humanTimingSince($time) { $time = time() - $time; // to get the time since that moment $time = ($time<1)? 1 : $time; $tokens = array ( 31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($tokens as $unit => $text) { if ($time < $unit) continue; $numberOfUnits = floor($time / $unit); return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); } } public static function getItemThumbnail($type, $id, $datafile, $fileHash) { if ($type == "hats") return 'https://api.xdiscuss.net/imageServer/hats/'.$datafile.'.png'; if ($type == "heads") return 'https://api.xdiscuss.net/imageServer/heads/'.$datafile.'.png'; if ($type == "faces") return '/data/assets/faces/thumbnail/'.$datafile.'.png'; if ($type == "gear") return 'https://api.xdiscuss.net/imageServer/gear/'.$datafile.'.png'; if ($type == "decals") return "/data/assets/uploads/".$fileHash; if ($type == "tshirts") return 'https://api.xdiscuss.net/imageServer/tshirts/'.$id.'.png'; if ($type == "pants") return 'https://api.xdiscuss.net/imageServer/pants/'.$id.'.png'; if ($type == "shirts") return 'https://api.xdiscuss.net/imageServer/shirts/'.$id.'.png'; } public static function getItemThumbnailC($type, $id, $datafile, $fileHash, $time) { if ($type == "hats") return 'https://api.xdiscuss.net/imageServer/hats/'.$datafile.'.png?tick='.strtotime($time).'hat'; if ($type == "heads") return 'https://api.xdiscuss.net/imageServer/heads/'.$datafile.'.png?tick='.strtotime($time); if ($type == "faces") return '/data/assets/faces/thumbnail/'.$datafile.'.png?tick='.strtotime($time); if ($type == "gear") return 'https://api.xdiscuss.net/imageServer/gear/'.$datafile.'.png?tick='.strtotime($time); if ($type == "decals") return "/data/assets/uploads/".$fileHash; if ($type == "tshirts") return 'https://api.xdiscuss.net/imageServer/tshirts/'.$id.'.png?tick='.strtotime($time); if ($type == "pants") return 'https://api.xdiscuss.net/imageServer/pants/'.$id.'.png?tick='.strtotime($time); if ($type == "shirts") return 'https://api.xdiscuss.net/imageServer/shirts/'.$id.'.png?tick='.strtotime($time); } public static function requestImage($ID, $type) { $query = "INSERT INTO renders (`render_id`, `type`) VALUES (:ID, :type);"; $stmt = $GLOBALS['dbcon']->prepare($query); $stmt->bindParam(':ID', $ID, PDO::PARAM_INT); $stmt->bindParam(':type', $type, PDO::PARAM_STR); $stmt->execute(); } public static function checkTopPoster($userID) { $query = "SELECT id, posts FROM users ORDER BY posts DESC LIMIT 15"; $stmt = $GLOBALS['dbcon']->prepare($query); $stmt->execute(); foreach ($stmt as $result) { if ($userID == $result['id']) { echo '
Top 15 Poster
'; } } } public static function buildFriendButton($userID) { if ($GLOBALS['loggedIn'] == true) { echo ''; $query = "SELECT * FROM `friends` WHERE `userId1` = :id AND `userId2` = :sid"; $stmt = $GLOBALS['dbcon']->prepare($query); $stmt->bindParam(':id', $GLOBALS['userTable']['id'], PDO::PARAM_INT); $stmt->bindParam(':sid', $userID, PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount() > 0) { $friend = true; }else{ $friend = false; } $query = "SELECT * FROM `friendRequests` WHERE `senduid` = :id AND `recvuid` = :sid"; $stmt = $GLOBALS['dbcon']->prepare($query); $stmt->bindParam(':id', $GLOBALS['userTable']['id'], PDO::PARAM_INT); $stmt->bindParam(':sid', $userID, PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount() > 0) { $requestSent = true; }else{ $requestSent = false; } $query = "SELECT * FROM `friendRequests` WHERE `senduid` = :id AND `recvuid` = :sid"; $stmt = $GLOBALS['dbcon']->prepare($query); $stmt->bindParam(':id', $userID, PDO::PARAM_INT); $stmt->bindParam(':sid', $GLOBALS['userTable']['id'], PDO::PARAM_INT); $stmt->execute(); if ($stmt->rowCount() > 0) { $requestSenta = true; }else{ $requestSenta = false; } if ($friend == false) { if ($requestSent == true or $requestSenta == true) { echo ' Pending'; }else{ echo ' Add'; } }else{ echo ' Remove'; } } } public static function showBBcodes($text) { // BBcode array $find = array( '~\[b\](.*?)\[/b\]~s', '~\[i\](.*?)\[/i\]~s', '~\[u\](.*?)\[/u\]~s', '~\[quote\](.*?)\[/quote\]~s', '~\[red\](.*?)\[/red\]~s', '~\[blue\](.*?)\[/blue\]~s', '~\[s\](.*?)\[/s\]~s', '~\[code\](.*?)\[/code\]~s' ); // HTML tags to replace BBcode $replace = array( '$1', '$1', '$1', '$1'.'pre>',
'$1'.'span>',
'$1'.'span>',
'$1'.'s>',
'$1'.'code>'
);
// Replacing the BBcodes with corresponding HTML tags
return preg_replace($find,$replace,$text);
}
public static function getImageRequestCount() {
$query = "SELECT id FROM `renders`;";
$stmt = $GLOBALS['dbcon']->prepare($query);
$stmt->execute();
return $stmt->rowCount();
}
public static function getUserCount() {
$query = "SELECT COUNT(*) FROM users;";
$stmt = $GLOBALS['dbcon']->prepare($query);
$stmt->execute();
$result = $stmt->fetchColumn(0);
return $result;
}
public static function getRouterCount() {
$query = "SELECT id FROM `serverRequests`;";
$stmt = $GLOBALS['dbcon']->prepare($query);
$stmt->execute();
return $stmt->rowCount();
}
public static function sendDiscordMessage($message) {
$url = "https://discordapp.com/api/webhooks/x/x";
$dataArray = array('content' => $message,
'username' => "Graphictoria");
$httpOptions = array(
'http' => array (
'header' => "Graphictoria-Server",
'content-type' => 'multipart/form-data',
'method' => "POST",
'content' => http_build_query($dataArray)
)
);
$context = stream_context_create($httpOptions);
$result = @file_get_contents($url, false, $context);
}
public static function parseEmoticon($content) {
$content = str_replace(":afro:",'
', $content);
$content = str_replace(":afro-1:",'
', $content);
$content = str_replace(":agent:",'
', $content);
$content = str_replace(":alien:",'
', $content);
$content = str_replace(":alien-1:",'
', $content);
$content = str_replace(":angel:",'
', $content);
$content = str_replace(":angry:",'
', $content);
$content = str_replace(":angry-1:",'
', $content);
$content = str_replace(":angry-2:",'
', $content);
$content = str_replace(":angry-3:",'
', $content);
$content = str_replace(":angry-4:",'
', $content);
$content = str_replace(":angry-5:",'
', $content);
$content = str_replace(":arguing:",'
', $content);
$content = str_replace(":arrogant:",'
', $content);
$content = str_replace(":asian:",'
', $content);
$content = str_replace(":asian-1:",'
', $content);
$content = str_replace(":avatar:",'
', $content);
$content = str_replace(":skeleton:",'
', $content);
$content = str_replace(":superhero:",'
', $content);
$content = str_replace(":vampire:",'
', $content);
$content = str_replace(":zombie:",'
', $content);
return $content;
}
}
?>