X-Git-Url: http://git.shiar.nl/sc2-widget/blobdiff_plain/aaceaa1177cdd850334513701913eefebc6fcfaa..7ac9d226cdfca989f06609ef4fa0aa51b3a131b7:/widget.php diff --git a/widget.php b/widget.php index e5aa326..c996111 100644 --- a/widget.php +++ b/widget.php @@ -1,12 +1,50 @@ '; } + print "

$message

\n"; + print "\n\n"; + exit; +} + +$request = trim($_GET['clan'] ?? $_SERVER['PATH_INFO'], '/'); +$target = "data/$request.json"; +$last = file_exists($target) ? lstat($target)['mtime'] : 0; + +if ($last < time() - 3600) { + $recipe = NULL; + if (is_numeric($request)) { + $recipe = $request; + } + elseif ($last) { + if ($data = json_decode(file_get_contents($target), true)) { + $profiles = array_column($data['members'], 'profileId'); + #TODO: reduce profiles by checking ladder presence + $recipe = join(' ', array_merge([$request], $profiles)); + } + } + else { + error("Unknown profile request $request", 400); + } + + if ($recipe) { + system("./getsc2clan $recipe | sponge $target", $exitcode); + if ($exitcode and !$last) { + error("No results for profile $request from Blizzard", 503); + } + } +} +if (!filesize($target)) { + error("No clan data for $request", 404); } require('widget.html');