From ab28e9ec4f0bbf294d9f3c56e542ac6fc1ce6132 Mon Sep 17 00:00:00 2001 From: Rick Date: Tue, 21 Jul 2020 11:11:02 +0200 Subject: [PATCH] =?UTF-8?q?Modification=20getHours=20&=20suppression=20att?= =?UTF-8?q?ribut=20r=C3=A9ponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- getAchievements.php | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/getAchievements.php b/getAchievements.php index 659b935..0819bee 100644 --- a/getAchievements.php +++ b/getAchievements.php @@ -41,30 +41,23 @@ function getJson($url) */ function getHours($appid) { - $tempFile = tempnam(".", "tmp"); $url = "http://astats.astats.nl/astats/Steam_Game_Info.php?AppID="; // 813630"; - $html = file_get_contents($url.$appid); - file_put_contents($tempFile, $html); - $searchFor = 'Hours to 100'; - - $pattern = preg_quote($searchFor, '/'); - $pattern = "/^.*$pattern.*\$/m"; - $matches = array(); - if(preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)){ - $charpos = $matches[0][1]; - list($before) = str_split($html, $charpos); - $line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1; - $file = new SplFileObject($tempFile); - $file->seek($line_number); - $content = $file->current(); - $hours = preg_split('/ /', trim($content), 2); - unlink($tempFile); - return $hours[0]; - } - else{ - unlink($tempFile); - return null; + $html = new DOMDocument(); + $html->loadHTMLFile($url.$appid); + + $span = $html->getElementsByTagName('td'); + + $searchFor = 'Hours to 100%'; + $regex = '/(?<=\b'.$searchFor.'\s)(?:[\w|,|.]+)/is'; + foreach($span as $node) { + $text = $node->nodeValue; + $text = preg_replace('/\s+/', ' ',$text); + if (preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE)) { + return $matches[0][0]; + break; + } } + return null; } /** @@ -121,7 +114,7 @@ if (isset($_POST['steamid'])) { if ($listGames == NULL) { $ret = array('error' => 'User not found.', 'response' => $http_response_header); } elseif (empty($responseListGames)) { - $ret = array('error' => 'Private Account.', 'response' => $http_response_header, 'test' => $listGames); + $ret = array('error' => 'Private Account.', 'response' => $http_response_header); } else { $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".API_KEY."&steamids=".$steamid; $userInformations = getJson($url);