Modification getHours & suppression attribut réponse

This commit is contained in:
Rick 2020-07-21 11:11:02 +02:00
parent 4540543d80
commit ab28e9ec4f
Signed by: Rick
GPG key ID: 9570A7DB7CB2F436

View file

@ -41,30 +41,23 @@ function getJson($url)
*/ */
function getHours($appid) function getHours($appid)
{ {
$tempFile = tempnam(".", "tmp");
$url = "http://astats.astats.nl/astats/Steam_Game_Info.php?AppID="; // 813630"; $url = "http://astats.astats.nl/astats/Steam_Game_Info.php?AppID="; // 813630";
$html = file_get_contents($url.$appid); $html = new DOMDocument();
file_put_contents($tempFile, $html); $html->loadHTMLFile($url.$appid);
$searchFor = 'Hours to 100';
$span = $html->getElementsByTagName('td');
$pattern = preg_quote($searchFor, '/');
$pattern = "/^.*$pattern.*\$/m"; $searchFor = 'Hours to 100%';
$matches = array(); $regex = '/(?<=\b'.$searchFor.'\s)(?:[\w|,|.]+)/is';
if(preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)){ foreach($span as $node) {
$charpos = $matches[0][1]; $text = $node->nodeValue;
list($before) = str_split($html, $charpos); $text = preg_replace('/\s+/', ' ',$text);
$line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1; if (preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE)) {
$file = new SplFileObject($tempFile); return $matches[0][0];
$file->seek($line_number); break;
$content = $file->current(); }
$hours = preg_split('/ /', trim($content), 2);
unlink($tempFile);
return $hours[0];
}
else{
unlink($tempFile);
return null;
} }
return null;
} }
/** /**
@ -121,7 +114,7 @@ if (isset($_POST['steamid'])) {
if ($listGames == NULL) { if ($listGames == NULL) {
$ret = array('error' => 'User not found.', 'response' => $http_response_header); $ret = array('error' => 'User not found.', 'response' => $http_response_header);
} elseif (empty($responseListGames)) { } elseif (empty($responseListGames)) {
$ret = array('error' => 'Private Account.', 'response' => $http_response_header, 'test' => $listGames); $ret = array('error' => 'Private Account.', 'response' => $http_response_header);
} else { } else {
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".API_KEY."&steamids=".$steamid; $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".API_KEY."&steamids=".$steamid;
$userInformations = getJson($url); $userInformations = getJson($url);