Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.30 KB | None | 0 0
  1. <?php
  2. $set = set_time_limit(0);
  3. function api_fetch($gt) {
  4.  
  5. $xUID = validate_user($gt);
  6. if(!isset($xUID))
  7. { return array(); }
  8.  
  9. $ch = curl_init();
  10. $rehab = 2533274795705427; // xUID for 'xX rehab Xx'
  11. $authKey = "a178e5d5479f1e80e2980e7a451652e435dc40e1";
  12. $xAuth = array("X-AUTH: $authKey");
  13. $url_xuid = "https://xboxapi.com/v2/xuid/$gt"; // first API endpoint to convert gamertag -> xUID
  14.  
  15.  
  16. // set URL and other appropriate options
  17. curl_setopt($ch, CURLOPT_HTTPHEADER, $xAuth); // insert the authentication token into the header
  18. curl_setopt($ch, CURLOPT_URL, $url_xuid); // set the API endpoint
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return variable
  20. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects
  21. curl_setopt($ch, CURLOPT_AUTOREFERER, true); // set referrer on redirect
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // do not verify SSL cert
  23. curl_setopt($ch, CURLINFO_HEADER_OUT, true); // track the handle's request string
  24.  
  25.  
  26. // curl_exec($ch) returns the xUID for the enter gamertag
  27. // insert the returned xUID into the API endpoints for future calls
  28. return curl_exec($ch);
  29.  
  30.  
  31. $url_360 = "https://xboxapi.com/v2/" . $xUID . "/xbox360games";
  32. $url_XBONE = "https://xboxapi.com/v2/" . $xUID . "/xboxonegames";
  33.  
  34.  
  35. // prepare the API call for the library of Xbox 360 games gamertag owns
  36. curl_setopt($ch, CURLOPT_URL, $url_360);
  37.  
  38.  
  39. // execute API call and convert the JSON string returned by the API into a PHP variable
  40. // $titles is the subarray of the returned API string, could probably be removed and swapped into the foreach loops
  41. $data = json_decode(curl_exec($ch), true);
  42. $titles = $data['titles'];
  43.  
  44.  
  45. // loop through the returned JSON string and print out the name of each game in the library
  46. //echo "<h2>XBOX 360</h2></br>";
  47. foreach ($titles as $t) {
  48. //echo "Title: " . $t['name'] . "</br>";
  49. get_info($ch, $t, 'X-Box 360');
  50. echo "</br>";
  51. }
  52.  
  53.  
  54. // prepare the API call for the library of XBONE games gamertag owns
  55. curl_setopt($ch, CURLOPT_URL, $url_XBONE);
  56.  
  57.  
  58. // execute API call and convert the JSON string returned by the API into a PHP variable
  59. $data = json_decode(curl_exec($ch), true);
  60. $titles = $data['titles'];
  61.  
  62.  
  63. // loop through the returned JSON string and print out the name of each game in the library
  64. //echo "</br><h2>XBOX ONE</h2></br>";
  65. foreach ($titles as $t) {
  66. //echo "Title: " . $t['name'];
  67. get_info($ch, $t, 'X-Box One');
  68. echo "</br>";
  69. }
  70.  
  71. // close cURL resource, and free up system resources
  72. curl_close($ch);
  73. }
  74.  
  75.  
  76. function validate_user($gt) {
  77. // create a new cURL resource
  78. // initialize required authentication tokens
  79. $ch = curl_init();
  80. $rehab = 2533274795705427; // xUID for 'xX rehab Xx'
  81. $authKey = "a178e5d5479f1e80e2980e7a451652e435dc40e1";
  82. $xAuth = array("X-AUTH: $authKey");
  83. $url_xuid = "https://xboxapi.com/v2/xuid/$gt"; // first API endpoint to convert gamertag -> xUID
  84.  
  85.  
  86. // set URL and other appropriate options
  87. curl_setopt($ch, CURLOPT_HTTPHEADER, $xAuth); // insert the authentication token into the header
  88. curl_setopt($ch, CURLOPT_URL, $url_xuid); // set the API endpoint
  89. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return variable
  90. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects
  91. curl_setopt($ch, CURLOPT_AUTOREFERER, true); // set referrer on redirect
  92. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // do not verify SSL cert
  93. curl_setopt($ch, CURLINFO_HEADER_OUT, true); // track the handle's request string
  94.  
  95.  
  96. // curl_exec($ch) returns the xUID for the enter gamertag
  97. // insert the returned xUID into the API endpoints for future calls
  98. return curl_exec($ch);
  99. }
  100.  
  101.  
  102. function check_user($gt) {
  103. //CHECK USER TABLE FOR USER
  104. $servername = "localhost";
  105. $username = "root";
  106. $password = "password";
  107. $dbname = "gamessite";
  108.  
  109. // Create connection
  110. $conn = new mysqli($servername, $username, $password, $dbname);
  111.  
  112. // Check connection
  113. if ($conn->connect_error) {
  114. die("Connection failed: " . $conn->connect_error);
  115. }
  116. //echo "Connected successfully";
  117.  
  118. //check is user already exists in user table
  119. $sql = "INSERT IGNORE INTO demousers
  120. VALUES
  121. ('".$gt."')";
  122.  
  123. //check if insert was successful
  124. if ($conn->query($sql) === TRUE)
  125. {
  126. //echo "New record created successfully";
  127. }
  128. else
  129. {
  130. echo "Error: " . $sql . "<br>" . $conn->error;
  131. }
  132.  
  133.  
  134. // Push user's games to demolibrary
  135. $lib = api_fetch()
  136.  
  137.  
  138. //*****start of loop
  139. //*****set these equal to title and platfrom from api_fetch()
  140. $uTitle =
  141. $uPlat =
  142.  
  143. $uGID = $sql = "SELECT GID
  144. FROM games
  145. WHERE Title = '".$uTitle."' AND Platform = '".$uPlat."';"
  146.  
  147. $sql = "INSERT IGNORE INTO demolibrary
  148. VALUES
  149. ('".$gt."', '".$uGID."')";
  150.  
  151. //check if insert was successful
  152. if ($conn->query($sql) === TRUE)
  153. {
  154. //echo "New record created successfully";
  155. }
  156. else
  157. {
  158. echo "Error: " . $sql . "<br>" . $conn->error;
  159. }
  160.  
  161. //*****end of loop
  162.  
  163.  
  164. //close connection
  165. $conn->close();
  166. }
  167.  
  168.  
  169. function DB_intersection_print($gt1 , $gt2)
  170. {
  171. $servername = "localhost";
  172. $username = "root";
  173. $password = "password";
  174. $dbname = "gamessite";
  175.  
  176. // Create connection
  177. $conn = new mysqli($servername, $username, $password, $dbname);
  178.  
  179. // Check connection
  180. if ($conn->connect_error) {
  181. die("Connection failed: " . $conn->connect_error);
  182. }
  183. //echo "Connected successfully";
  184.  
  185. //sql query call for the intersection
  186. $sql = "SELECT *
  187. FROM games
  188. WHERE GID = ((SELECT GID
  189. FROM demolibrary
  190. WHERE gamertag = '".$gt1."')
  191. INTERSECT
  192. (SELECT GID
  193. FROM demolibrary
  194. WHERE gamertag = '".$gt2"')
  195. )";
  196.  
  197. //close connection
  198. $conn->close();
  199. }
  200.  
  201.  
  202.  
  203.  
  204. /*
  205. THIS IS THE SCRIPT TO PULL THE GAME INFO FOR A SPECIFIED GAME
  206. STILL NEED TO TURN THIS INTO A LOOP TO ITERATE THROUGH ALL GAMES IN A LIBRARY
  207. DO NOT UNCOMMENT AND EXPECT IT TO FULLY FUNCTION
  208. */
  209. function get_info(&$ch, $titles, $platform) {
  210.  
  211. $url_gameinfo = "https://xboxapi.com/v2/game-details-hex/"; // API endpoint to pull game info; append dechex(#titleId#)
  212. $check = $titles['titleId'];
  213. $check = dechex($check);
  214.  
  215.  
  216. curl_setopt($ch, CURLOPT_URL, $url_gameinfo . $check);
  217. $gameinfo = json_decode(curl_exec($ch), true);
  218.  
  219. $game_item = $gameinfo['Items'][0];
  220. //$game_img = $game_item['Images'];
  221.  
  222. $info = array (try_info($game_item['Name']),
  223. try_info($game_item['Description']),
  224. /*try_info($game_item['ReleaseDate']),*/
  225. try_info($game_item['DeveloperName']),
  226. try_info($game_item['PublisherName']),
  227. /*try_info($game_item['AllTimeAverageRating'])*/
  228. );
  229.  
  230.  
  231. $servername = "localhost";
  232. $username = "root";
  233. $password = "password";
  234. $dbname = "gamessite";
  235.  
  236. // Create connection
  237. $conn = new mysqli($servername, $username, $password, $dbname);
  238.  
  239. // Check connection
  240. if ($conn->connect_error) {
  241. die("Connection failed: " . $conn->connect_error);
  242. }
  243. //echo "Connected successfully";
  244.  
  245.  
  246. //create escape strings for use of " ' " in the sql query
  247. $title_pass = $info[0];
  248. $title_pass = $conn->real_escape_string($title_pass);
  249. $pub_pass = $info[3];
  250. $pub_pass = $conn->real_escape_string($pub_pass);
  251. $dev_pass = $info[2];
  252. $dev_pass = $conn->real_escape_string($dev_pass);
  253.  
  254.  
  255. $sql = "INSERT IGNORE INTO games
  256. VALUES
  257. (0, '".$title_pass."' , '".$platform."', '".$pub_pass."', '".$dev_pass."')";
  258.  
  259.  
  260. //check if insert was successful
  261. if ($conn->query($sql) === TRUE) {
  262. //echo "New record created successfully";
  263. } else {
  264. echo "Error: " . $sql . "<br>" . $conn->error;
  265. }
  266.  
  267. //close connection
  268. $conn->close();
  269.  
  270.  
  271. //print_r($info);
  272.  
  273. //echo "</br>Banner IMG: <img src='" . $game_img[0]['Url'] . "'></br>";
  274. //echo "</br>BoxArt IMG: <img src='" . $game_img[1]['Url'] . "'></br>";
  275.  
  276. }
  277.  
  278. function info_failed($errno, $errstr) {
  279. return "N/A";
  280. }
  281.  
  282. // error handler if the API can't return the proper info
  283. function try_info($get) {
  284. return $get;
  285. }
  286.  
  287.  
  288.  
  289. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement