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,31 +41,24 @@ 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';
$html = new DOMDocument();
$html->loadHTMLFile($url.$appid);
$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];
$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;
}
}
else{
unlink($tempFile);
return null;
}
}
/**
* check si un jeu a des succès
@ -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);