Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $set = set_time_limit(0);
- //$rehab = 2533274795705427; // xUID for 'xX rehab Xx' | may not even need this anymore
- // function to set standard parameters of API connection
- function api_set_conn(&$ch) {
- $authKey = "a178e5d5479f1e80e2980e7a451652e435dc40e1";
- $xAuth = array("X-AUTH: $authKey");
- // set URL and other appropriate options
- curl_setopt($ch, CURLOPT_HTTPHEADER, $xAuth); // insert the authentication token into the header
- 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
- }
- function api_fetch_lib($gt, $plat) {
- //@@@@@@@@@@@
- // Pretty sure we can remove this and the !isset() since we validate before ever calling api_fetch();
- // make sure we have a valid id before making expensive API calls
- $xUID = validate_user($gt);
- // if it was an invalid ID, end the function and return an empty array which will be ignored by functions using it
- if(!isset($xUID) || $xUID == 0)
- { return array(); }
- // establish a new API connection
- $ch = curl_init();
- api_set_conn($ch);
- // prepare the API endpoints for specified user
- $url_X360 = "https://xboxapi.com/v2/" . $xUID . "/xbox360games";
- $url_XBONE = "https://xboxapi.com/v2/" . $xUID . "/xboxonegames";
- $url_lib;
- if ($plat == 'X360')
- $url_lib = $url_X360;
- else
- $url_lib = $url_XBONE;
- // set endpoint for API request
- curl_setopt($ch, CURLOPT_URL, $url_lib);
- // execute API call and convert the JSON string returned by the API into a PHP variable
- // $titles is the sub-array of the returned API string
- $data = json_decode(curl_exec($ch), true);
- // close cURL resource, and free up system resources
- curl_close($ch);
- return $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>";
- }
- function validate_user($gt) {
- // establish a new API connection
- $ch = curl_init();
- api_set_conn($ch);
- $url_xuid = "https://xboxapi.com/v2/xuid/$gt"; // API endpoint to convert gamertag -> xUID
- curl_setopt($ch, CURLOPT_URL, $url_xuid); // set the API endpoint
- // return the xUID for the enter gamertag
- 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";
- // I read this as de-mousers more times than I care to admit
- //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;
- }
- // @@@@@@@@@
- // $lib will be an array of a user's X360 games; it is equivalent to the old $titles
- // probably should turn everything from ln126 to ln142 into a function for reuse
- $uPlat = 'X360';
- $lib = api_fetch_lib($gt, $uPlat);
- foreach ($lib as $uTitle) {
- // Push user's games to demolibrary
- $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;
- }
- }
- // @@@@@@@@@
- // $lib will be an array of a user's XBONE games; it is equivalent to the old $titles
- $uPlat = 'XONE';
- $lib = api_fetch_lib($gt, $uPlat);
- foreach ($lib as $uTitle) {
- // Push user's games to demolibrary
- $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
- */
- //@@@@@@@@@@@@@@@@@@
- // NOTE: AS OF NOW THIS FUNCTION IS NOT USED IN ANY OTHER 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