Modification getHours & suppression attribut réponse
This commit is contained in:
parent
4540543d80
commit
ab28e9ec4f
1 changed files with 16 additions and 23 deletions
|
@ -41,31 +41,24 @@ 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';
|
|
||||||
|
|
||||||
$pattern = preg_quote($searchFor, '/');
|
$span = $html->getElementsByTagName('td');
|
||||||
$pattern = "/^.*$pattern.*\$/m";
|
|
||||||
$matches = array();
|
$searchFor = 'Hours to 100%';
|
||||||
if(preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)){
|
$regex = '/(?<=\b'.$searchFor.'\s)(?:[\w|,|.]+)/is';
|
||||||
$charpos = $matches[0][1];
|
foreach($span as $node) {
|
||||||
list($before) = str_split($html, $charpos);
|
$text = $node->nodeValue;
|
||||||
$line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1;
|
$text = preg_replace('/\s+/', ' ',$text);
|
||||||
$file = new SplFileObject($tempFile);
|
if (preg_match($regex, $text, $matches, PREG_OFFSET_CAPTURE)) {
|
||||||
$file->seek($line_number);
|
return $matches[0][0];
|
||||||
$content = $file->current();
|
break;
|
||||||
$hours = preg_split('/ /', trim($content), 2);
|
}
|
||||||
unlink($tempFile);
|
|
||||||
return $hours[0];
|
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
unlink($tempFile);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check si un jeu a des succès
|
* check si un jeu a des succès
|
||||||
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue