Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $set = set_time_limit(0);
- function api_fetch($gt) {
- $xUID = validate_user($gt);
- if(!isset($xUID))
- { return array(); }
- $ch = curl_init();
- $rehab = 2533274795705427; // xUID for 'xX rehab Xx'
- $authKey = "a178e5d5479f1e80e2980e7a451652e435dc40e1";
- $xAuth = array("X-AUTH: $authKey");
- $url_xuid = "https://xboxapi.com/v2/xuid/$gt"; // first API endpoint to convert gamertag -> xUID
- // set URL and other appropriate options
- curl_setopt($ch, CURLOPT_HTTPHEADER, $xAuth); // insert the authentication token into the header
- curl_setopt($ch, CURLOPT_URL, $url_xuid); // set the API endpoint
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return variable
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects
- curl_setopt($ch, CURLOPT_AUTOREFERER, true); // set referrer on redirect
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // do not verify SSL cert
- curl_setopt($ch, CURLINFO_HEADER_OUT, true); // track the handle's request string
- // curl_exec($ch) returns the xUID for the enter gamertag
- // insert the returned xUID into the API endpoints for future calls
- return curl_exec($ch);
- $url_360 = "https://xboxapi.com/v2/" . $xUID . "/xbox360games";
- $url_XBONE = "https://xboxapi.com/v2/" . $xUID . "/xboxonegames";
- // prepare the API call for the library of Xbox 360 games gamertag owns
- curl_setopt($ch, CURLOPT_URL, $url_360);
- // execute API call and convert the JSON string returned by the API into a PHP variable
- // $titles is the subarray of the returned API string, could probably be removed and swapped into the foreach loops
- $data = json_decode(curl_exec($ch), true);
- $titles = $data['titles'];
- // loop through the returned JSON string and print out the name of each game in the library
- //echo "<h2>XBOX 360</h2></br>";
- foreach ($titles as $t) {
- //echo "Title: " . $t['name'] . "</br>";
- get_info($ch, $t, 'X-Box 360');
- echo "</br>";
- }
- // prepare the API call for the library of XBONE games gamertag owns
- curl_setopt($ch, CURLOPT_URL, $url_XBONE);
- // execute API call and convert the JSON string returned by the API into a PHP variable
- $data = json_decode(curl_exec($ch), true);
- $titles = $data['titles'];
- // loop through the returned JSON string and print out the name of each game in the library
- //echo "</br><h2>XBOX ONE</h2></br>";
- foreach ($titles as $t) {
- //echo "Title: " . $t['name'];
- get_info($ch, $t, 'X-Box One');
- echo "</br>";
- }
- // close cURL resource, and free up system resources
- curl_close($ch);
- }
- function validate_user($gt) {
- // create a new cURL resource
- // initialize required authentication tokens
- $ch = curl_init();
- $rehab = 2533274795705427; // xUID for 'xX rehab Xx'
- $authKey = "a178e5d5479f1e80e2980e7a451652e435dc40e1";
- $xAuth = array("X-AUTH: $authKey");
- $url_xuid = "https://xboxapi.com/v2/xuid/$gt"; // first API endpoint to convert gamertag -> xUID
- // set URL and other appropriate options
- curl_setopt($ch, CURLOPT_HTTPHEADER, $xAuth); // insert the authentication token into the header
- curl_setopt($ch, CURLOPT_URL, $url_xuid); // set the API endpoint
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return variable
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects
- curl_setopt($ch, CURLOPT_AUTOREFERER, true); // set referrer on redirect
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // do not verify SSL cert
- curl_setopt($ch, CURLINFO_HEADER_OUT, true); // track the handle's request string
- // curl_exec($ch) returns the xUID for the enter gamertag
- // insert the returned xUID into the API endpoints for future calls
- return curl_exec($ch);
- }
- function check_user($gt) {
- //CHECK USER TABLE FOR USER
- $servername = "localhost";
- $username = "root";
- $password = "password";
- $dbname = "gamessite";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- //echo "Connected successfully";
- //check is user already exists in user table
- $sql = "INSERT IGNORE INTO demousers
- VALUES
- ('".$gt."')";
- //check if insert was successful
- if ($conn->query($sql) === TRUE)
- {
- //echo "New record created successfully";
- }
- else
- {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- // Push user's games to demolibrary
- $lib = api_fetch()
- //*****start of loop
- //*****set these equal to title and platfrom from api_fetch()
- $uTitle =
- $uPlat =
- $uGID = $sql = "SELECT GID
- FROM games
- WHERE Title = '".$uTitle."' AND Platform = '".$uPlat."';"
- $sql = "INSERT IGNORE INTO demolibrary
- VALUES
- ('".$gt."', '".$uGID."')";
- //check if insert was successful
- if ($conn->query($sql) === TRUE)
- {
- //echo "New record created successfully";
- }
- else
- {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- //*****end of loop
- //close connection
- $conn->close();
- }
- function DB_intersection_print($gt1 , $gt2)
- {
- $servername = "localhost";
- $username = "root";
- $password = "password";
- $dbname = "gamessite";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- //echo "Connected successfully";
- //sql query call for the intersection
- $sql = "SELECT *
- FROM games
- WHERE GID = ((SELECT GID
- FROM demolibrary
- WHERE gamertag = '".$gt1."')
- INTERSECT
- (SELECT GID
- FROM demolibrary
- WHERE gamertag = '".$gt2"')
- )";
- //close connection
- $conn->close();
- }
- /*
- THIS IS THE SCRIPT TO PULL THE GAME INFO FOR A SPECIFIED GAME
- STILL NEED TO TURN THIS INTO A LOOP TO ITERATE THROUGH ALL GAMES IN A LIBRARY
- DO NOT UNCOMMENT AND EXPECT IT TO FULLY FUNCTION
- */
- function get_info(&$ch, $titles, $platform) {
- $url_gameinfo = "https://xboxapi.com/v2/game-details-hex/"; // API endpoint to pull game info; append dechex(#titleId#)
- $check = $titles['titleId'];
- $check = dechex($check);
- curl_setopt($ch, CURLOPT_URL, $url_gameinfo . $check);
- $gameinfo = json_decode(curl_exec($ch), true);
- $game_item = $gameinfo['Items'][0];
- //$game_img = $game_item['Images'];
- $info = array (try_info($game_item['Name']),
- try_info($game_item['Description']),
- /*try_info($game_item['ReleaseDate']),*/
- try_info($game_item['DeveloperName']),
- try_info($game_item['PublisherName']),
- /*try_info($game_item['AllTimeAverageRating'])*/
- );
- $servername = "localhost";
- $username = "root";
- $password = "password";
- $dbname = "gamessite";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- //echo "Connected successfully";
- //create escape strings for use of " ' " in the sql query
- $title_pass = $info[0];
- $title_pass = $conn->real_escape_string($title_pass);
- $pub_pass = $info[3];
- $pub_pass = $conn->real_escape_string($pub_pass);
- $dev_pass = $info[2];
- $dev_pass = $conn->real_escape_string($dev_pass);
- $sql = "INSERT IGNORE INTO games
- VALUES
- (0, '".$title_pass."' , '".$platform."', '".$pub_pass."', '".$dev_pass."')";
- //check if insert was successful
- if ($conn->query($sql) === TRUE) {
- //echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- //close connection
- $conn->close();
- //print_r($info);
- //echo "</br>Banner IMG: <img src='" . $game_img[0]['Url'] . "'></br>";
- //echo "</br>BoxArt IMG: <img src='" . $game_img[1]['Url'] . "'></br>";
- }
- function info_failed($errno, $errstr) {
- return "N/A";
- }
- // error handler if the API can't return the proper info
- function try_info($get) {
- return $get;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement