diff --git a/.gitignore b/.gitignore index ebe2464..914b7b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +config.ini + # ---> Vim # Swap [._]*.s[a-v][a-z] diff --git a/config.ini.example b/config.ini.example new file mode 100644 index 0000000..5b2a8a3 --- /dev/null +++ b/config.ini.example @@ -0,0 +1,2 @@ +# set your beautiful steam api key +steam_api_key = "" \ No newline at end of file diff --git a/getAchievements.php b/getAchievements.php new file mode 100644 index 0000000..a2815be --- /dev/null +++ b/getAchievements.php @@ -0,0 +1,128 @@ +seek($line_number); + $content = $file->current(); + $hours = preg_split('/ /', trim($content), 2); + unlink($tempFile); + return $hours[0]; + } + else{ + unlink($tempFile); + return null; + } +} + +/** + * check si un jeu a des succès + */ +function hasAchievements($appid) +{ + file_get_contents("http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?gameid=".$appid); + $pattern = preg_quote(' 403 ', '/'); + $pattern = "/^.*$pattern.*\$/m"; + if(preg_match($pattern, $http_response_header[0])){ + return false; + } else { + return true; + } +} + + +/** + * verifie si le jeu est fini à 100% + */ +function checkComplete($appid, $steamid) +{ + $gameInfo = getJson("http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?key=".API_KEY."&steamid=".$steamid."&appid=" . $appid); + $listAchievements = $gameInfo["playerstats"]["achievements"]; + foreach ($listAchievements as $key => $value) { + if ($value["achieved"] == 0) { + return false; + } + } + return true; + +} + + +/** + * affiche un tableau HTML contenant les jeux triés par ordre croissant de temps de fin + */ +if (isset($_POST['steamid'])) { + $ret = array(); + $steamid = $_POST['steamid']; + $url = "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=".API_KEY."&steamid=".$steamid; + $listGames = file_get_contents($url); + if ($listGames == NULL) { + $ret = array('error' => 'User not found.', 'response' => $http_response_header); + } else { + $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".API_KEY."&steamids=".$steamid; + $userInformations = getJson($url); + $ret["username"] = $userInformations["response"]["players"][0]["personaname"]; + + $listGamesJson = json_decode($listGames, true); + $listGamesJson = $listGamesJson["response"]; + $url = "http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?key=".API_KEY."&steamid=".$steamid."&appid="; + + foreach ($listGamesJson["games"] as $key => $value) { + $appid = $value["appid"]; + if (hasAchievements($appid)) { + if (!checkComplete($appid, $steamid)) { + $gameName = getJson($url.$appid); + $gameName = $gameName["playerstats"]["gameName"]; + $hours = getHours($appid); + + if ($hours == null) { + $ret["gameWithoutTime"][] = array('gamename' => $gameName, 'hours' => $hours); + } else { + $ret["gameWithTime"][] = array('gamename' => $gameName, 'hours' => $hours); + } + + + } + } + } + } + //$fileJson = fopen('result.json', 'w'); + //fwrite($fileJson, json_encode($ret)); + //fclose($fileJson); + $retJson = json_encode($ret); + $_POST["game"] = $retJson; + header('Content-Type: application/json'); + echo $retJson; +} +?> \ No newline at end of file diff --git a/getinformations.js b/getinformations.js new file mode 100644 index 0000000..2c53b06 --- /dev/null +++ b/getinformations.js @@ -0,0 +1,50 @@ +document.getElementById("box").innerHTML = ""; +function makeHtml(jsonData) { + jsonData.forEach(element => { + console.log(element); + box = document.createElement("div"); + gameName = document.createElement("p"); + hours = document.createElement("p"); + text = document.createTextNode(element["gamename"]); + gameName.appendChild(text); + text = document.createTextNode(element["hours"]); + hours.appendChild(text); + box.appendChild(gameName); + box.appendChild(hours); + bigbox.appendChild(box); + }); +} +function makeArray(jsonData) { + document.getElementById("box").innerHTML = ""; + bigbox = document.getElementById("box"); + console.log(jsonData); + if (jsonData.hasOwnProperty('error')) { + console.log("error"); + error = document.createElement("div"); + error.id="error"; + text = document.createTextNode(jsonData["error"]); + error.appendChild(text); + bigbox.appendChild(error); + } else { + document.getElementById("username").innerHTML = jsonData["username"]; + jsonData["gameWithTime"].sort((a, b) => parseFloat(a.hours) - parseFloat(b.hours)); + makeHtml(jsonData["gameWithTime"]); + makeHtml(jsonData["gameWithoutTime"]); + } + } +function sendData() { + text = document.createTextNode("Chargement en cours...."); + document.getElementById("box").innerHTML = ""; + loading = document.createElement("div"); + loading.id = "loading"; + loading.appendChild(text); + document.getElementById("box").appendChild(loading); + var xhr = new XMLHttpRequest(); + xhr.open("POST", "getAchievements.php"); + xhr.onload=function(event){ + makeArray(event.target.response); + }; + var formData = new FormData(document.getElementById("myform")); + xhr.responseType = 'json'; + xhr.send(formData); +} \ No newline at end of file diff --git a/index.css b/index.css new file mode 100644 index 0000000..57ecece --- /dev/null +++ b/index.css @@ -0,0 +1,34 @@ +body { + background-color: aquamarine; +} + + #box { + border: 1px solid black; + background-color: aqua; +} + +#box div { + border-bottom: 1px solid black; +} + +#error { + padding: 30px; + border: 10px solid #c94c4c; + background-color:#eca1a6; +} + + #loading { + text-align: center; + background-color: red; + padding: 50px; + animation: loadingScreen 2s alternate infinite; + } + + @keyframes loadingScreen { + 0% { + transform: scale(1); + } + 100% { + transform: scale(1.5); + } + } \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..8c1121c --- /dev/null +++ b/index.html @@ -0,0 +1,35 @@ + + + + + + Document + + +
+ A propros +
+ +
+ + +
+ +

Compte de

+ +
+
+ Activez le JavaScript et vérifiez si le fichier JS est au bon endroit. +
+
+ + + + + + \ No newline at end of file