X-Git-Url: http://git.shiar.nl/sc2-widget/blobdiff_plain/1a98a84619e7737def6d8d15e6d278e34ff5447a..7f3d75fcd1ed43c99397a99bda9c14f18b7e068c:/widget.php diff --git a/widget.php b/widget.php index 78f0ab2..c996111 100644 --- a/widget.php +++ b/widget.php @@ -17,20 +17,23 @@ function error($message, $status = 500) exit; } -$request = trim($_SERVER['PATH_INFO'], '/'); +$request = trim($_GET['clan'] ?? $_SERVER['PATH_INFO'], '/'); $target = "data/$request.json"; -$last = file_exists($target) ? filemtime($target) : 0; +$last = file_exists($target) ? lstat($target)['mtime'] : 0; if ($last < time() - 3600) { $recipe = NULL; if (is_numeric($request)) { $recipe = $request; } - elseif ($request == 'inno') { - #TODO: get ids from existing data - $recipe = "$request 2138280 6531490"; + 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)); + } } - elseif (!$last) { + else { error("Unknown profile request $request", 400); }