Advertisement
Guest User

dsaads

a guest
Jan 18th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. <?php
  2. # en.php
  3.  
  4. require_once("phpfastcache/phpfastcache.php");
  5. function getSteamAPIKey() {
  6. $fileLoc = $_SERVER['DOCUMENT_ROOT'] . '/../passwords.txt';
  7. if (file_exists($fileLoc)) {
  8. $fh = fopen($fileLoc, 'r');
  9. $jsonStr = fgets($fh);
  10. $arr = json_decode($jsonStr, true);
  11. $key = $arr['steamAPIKey'];
  12. fclose($fh);
  13. return $key;
  14. } else {
  15. die('no file found');
  16. }
  17. }
  18.  
  19. function getUserStr($steamId) {
  20. $cache = phpFastCache("files");
  21. $chatAPIKey = getSteamAPIKey();
  22. $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$chatAPIKey&steamids=$steamId";
  23. $usersInfoStr = $cache->get($steamId);
  24. if($usersInfoStr == null) {
  25. $usersInfoStr = file_get_contents($url);
  26. $cache->set($steamId, $usersInfoStr, 3600);
  27. }
  28. return $usersInfoStr;
  29. }
  30.  
  31. function getUserInfo($steamId) {
  32. return getSteamProfileInfoForSteamID(getUserStr($steamId), $steamId);
  33. }
  34.  
  35. function getItemPrice($itemname) {
  36. $url = "http://csgobackpack.net/api/GetItemPrice/?id=" . $itemname . "&time=7&key=8rvpzrxnn7s95wd6";
  37. return file_get_contents($url);;
  38. }
  39.  
  40. function getDB() {
  41. $dbHost = "localhost";
  42. $db = "db2";
  43. $dbUser = "root";
  44.  
  45. # Get database password from outside of web root
  46. $fileLoc = $_SERVER['DOCUMENT_ROOT'] . '/../passwords.txt';
  47. if (file_exists($fileLoc)) {
  48. $fh = fopen($fileLoc, 'r');
  49. $jsonStr = fgets($fh);
  50. $arr = json_decode($jsonStr, true);
  51. $dbPass = $arr['default-password'];
  52. fclose($fh);
  53. } else {
  54. die('no file found');
  55. }
  56.  
  57. $db = new PDO("mysql:host=$dbHost;dbname=$db;charset=utf8mb4", $dbUser, "fgFDGH%^%$^FGHFGFG");
  58. return $db;
  59. }
  60.  
  61. function getSteamProfileInfoForSteamID($allUsersInfoStr, $steamIDToFind) {
  62. $allUsersInfo = json_decode($allUsersInfoStr, true);
  63. $players = $allUsersInfo['response']['players'];
  64.  
  65. foreach ($players as $player) {
  66. $steamID = $player['steamid'];
  67. $player['personaname'] = htmlentities($player['personaname']);
  68.  
  69. if ($steamIDToFind === $steamID) {
  70. return $player;
  71. }
  72. }
  73.  
  74. # If the user is not found, then return false
  75. return false;
  76. }
  77.  
  78. function getChatSteamProfileInfoForSteamID($allUsersInfoStr, $steamIDToFind) {
  79. $allUsersInfo = json_decode($allUsersInfoStr, true);
  80. $players = $allUsersInfo['response']['players'];
  81.  
  82. foreach ($players as $player) {
  83. $steamID = $player['steamid'];
  84. $player['personaname'] = htmlentities($player['personaname']);
  85.  
  86. if ($steamIDToFind === $steamID) {
  87. $p1 = array();
  88. $p1["personaname"] = $player["personaname"];
  89. $p1["avatarfull"] = $player["avatarfull"];
  90. $p1["profileurl"] = $player["profileurl"];
  91. $p1["steamid"] = $player["steamid"];
  92. return $p1;
  93. }
  94. }
  95.  
  96. # If the user is not found, then return false
  97. return false;
  98. }
  99.  
  100. function jsonSuccess($data) {
  101. echo json_encode(array('success' => 1, 'data' => $data));
  102. }
  103.  
  104. function jsonErr($errMsg) {
  105. return json_encode(array('success' => 0, 'errMsg' => $errMsg));
  106. }
  107.  
  108. function postVar($varName) {
  109. $var = isset($_POST[$varName]) ? $_POST[$varName] : null;
  110.  
  111. if (is_null($var) || strlen($var) === 0) {
  112. return null;
  113. } else {
  114. return $var;
  115. }
  116. }
  117.  
  118. function getVar($varName) {
  119. $var = isset($_GET[$varName]) ? $_GET[$varName] : null;
  120.  
  121. if (is_null($var) || strlen($var) === 0) {
  122. return null;
  123. } else {
  124. return $var;
  125. }
  126. }
  127. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement