Advertisement
Guest User

code

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