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`, `thumbnailHash`, `headshotHash` 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 getCDNUrl($hash) { $st = 31; for($i = 0; $i < 32; $i++) { $st ^= ord($hash[$i]); } return 'https://t' . strval($st % 8) . '.gtoria.net/' . $hash; } public static function getUserImage($userSheet) { if(!isset($userSheet['thumbnailHash'])) { $uid = $userSheet['id']; $stmt = $GLOBALS['dbcon']->prepare("SELECT `id`, `charap` AS `pose` FROM `users` WHERE `id`=:uid;"); $stmt->bindParam(':uid', $uid, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); $pose = $result['pose']; $stmt = $GLOBALS['dbcon']->prepare("SELECT `id` FROM `wearing` WHERE `uid`=:uid AND `type`=\"gear\";"); $stmt->bindParam(':uid', $uid, PDO::PARAM_INT); $stmt->execute(); $hasGear = (($stmt->rowCount() > 0) ? 1 : 0); context::requestImage($uid, "character", $pose, $hasGear); return 'https://gtoria.net/html/img/characters/busy.png'; } return context::getCDNUrl($userSheet['thumbnailHash']); } public static function getUserHeadshotImage($userSheet) { if(!isset($userSheet['headshotHash'])) { $uid = $userSheet['id']; $stmt = $GLOBALS['dbcon']->prepare("SELECT `id`, `charap` AS `pose` FROM `users` WHERE `id`=:uid;"); $stmt->bindParam(':uid', $uid, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); $pose = $result['pose']; $stmt = $GLOBALS['dbcon']->prepare("SELECT `id` FROM `wearing` WHERE `uid`=:uid AND `type`=\"gear\";"); $stmt->bindParam(':uid', $uid, PDO::PARAM_INT); $stmt->execute(); $hasGear = (($stmt->rowCount() > 0) ? 1 : 0); context::requestImage($uid, "headshot", $pose, $hasGear); return 'https://gtoria.net/html/img/characters/busy.png'; } return context::getCDNUrl($userSheet['headshotHash']); } public static function getGroupImage($userID) { $query = "SELECT thumbnailHash, username 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); return context::getUserImage($userSheet); } 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 == "faces") return '/data/assets/faces/thumbnail/'.$datafile.'.png'; if ($type == "decals") return "/data/assets/uploads/".$fileHash; $stmt = $GLOBALS['dbcon']->prepare('SELECT `id`, `thumbnailHash` FROM `catalog` WHERE `id`=:id'); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); if(!isset($result['thumbnailHash'])) { context::requestImage($id, $type); return 'https://gtoria.net/html/img/hats/busy.png'; } return context::getCDNUrl($result['thumbnailHash']); } public static function getItemThumbnailC($type, $id, $datafile, $fileHash, $time) { if ($type == "faces") return '/data/assets/faces/thumbnail/'.$datafile.'.png?tick='.strtotime($time); if ($type == "decals") return "/data/assets/uploads/".$fileHash; $stmt = $GLOBALS['dbcon']->prepare('SELECT `id`, `thumbnailHash` FROM `catalog` WHERE `id`=:id'); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); if(!isset($result['thumbnailHash'])) { context::requestImage($id, $type); return 'https://gtoria.net/html/img/hats/busy.png'; } return context::getCDNUrl($result['thumbnailHash']); } public static function requestImage($ID, $type, $pose = null, $hasgear = null) { return render::render($ID, $type, $pose, $hasgear); } 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://canary.discord.com/api/webhooks/826812837041143859/SpKZ-evqHCKrpyELzPAiGONbxiHcJVY0kxC7v0k4yL6NheV3SAld5NX89KUJPI1g0dGH";
$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;
}
}
?>