Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # en.php
- require_once("phpfastcache/phpfastcache.php");
- function getSteamAPIKey() {
- $fileLoc = $_SERVER['DOCUMENT_ROOT'] . '/../passwords.txt';
- if (file_exists($fileLoc)) {
- $fh = fopen($fileLoc, 'r');
- $jsonStr = fgets($fh);
- $arr = json_decode($jsonStr, true);
- $key = $arr['steamAPIKey'];
- fclose($fh);
- return $key;
- } else {
- die('no file found');
- }
- }
- function getUserStr($steamId) {
- $cache = phpFastCache("files");
- $chatAPIKey = getSteamAPIKey();
- $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$chatAPIKey&steamids=$steamId";
- $usersInfoStr = $cache->get($steamId);
- if($usersInfoStr == null) {
- $usersInfoStr = file_get_contents($url);
- $cache->set($steamId, $usersInfoStr, 3600);
- }
- return $usersInfoStr;
- }
- function getUserInfo($steamId) {
- return getSteamProfileInfoForSteamID(getUserStr($steamId), $steamId);
- }
- function getItemPrice($itemname) {
- $url = "http://csgobackpack.net/api/GetItemPrice/?id=" . $itemname . "&time=7&key=8rvpzrxnn7s95wd6";
- return file_get_contents($url);;
- }
- function getDB() {
- $dbHost = "localhost";
- $db = "db2";
- $dbUser = "root";
- # Get database password from outside of web root
- $fileLoc = $_SERVER['DOCUMENT_ROOT'] . '/../passwords.txt';
- if (file_exists($fileLoc)) {
- $fh = fopen($fileLoc, 'r');
- $jsonStr = fgets($fh);
- $arr = json_decode($jsonStr, true);
- $dbPass = $arr['default-password'];
- fclose($fh);
- } else {
- die('no file found');
- }
- $db = new PDO("mysql:host=$dbHost;dbname=$db;charset=utf8mb4", $dbUser, "fgFDGH%^%$^FGHFGFG");
- return $db;
- }
- function getSteamProfileInfoForSteamID($allUsersInfoStr, $steamIDToFind) {
- $allUsersInfo = json_decode($allUsersInfoStr, true);
- $players = $allUsersInfo['response']['players'];
- foreach ($players as $player) {
- $steamID = $player['steamid'];
- $player['personaname'] = htmlentities($player['personaname']);
- if ($steamIDToFind === $steamID) {
- return $player;
- }
- }
- # If the user is not found, then return false
- return false;
- }
- function getChatSteamProfileInfoForSteamID($allUsersInfoStr, $steamIDToFind) {
- $allUsersInfo = json_decode($allUsersInfoStr, true);
- $players = $allUsersInfo['response']['players'];
- foreach ($players as $player) {
- $steamID = $player['steamid'];
- $player['personaname'] = htmlentities($player['personaname']);
- if ($steamIDToFind === $steamID) {
- $p1 = array();
- $p1["personaname"] = $player["personaname"];
- $p1["avatarfull"] = $player["avatarfull"];
- $p1["profileurl"] = $player["profileurl"];
- $p1["steamid"] = $player["steamid"];
- return $p1;
- }
- }
- # If the user is not found, then return false
- return false;
- }
- function jsonSuccess($data) {
- echo json_encode(array('success' => 1, 'data' => $data));
- }
- function jsonErr($errMsg) {
- return json_encode(array('success' => 0, 'errMsg' => $errMsg));
- }
- function postVar($varName) {
- $var = isset($_POST[$varName]) ? $_POST[$varName] : null;
- if (is_null($var) || strlen($var) === 0) {
- return null;
- } else {
- return $var;
- }
- }
- function getVar($varName) {
- $var = isset($_GET[$varName]) ? $_GET[$varName] : null;
- if (is_null($var) || strlen($var) === 0) {
- return null;
- } else {
- return $var;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement