X-Git-Url: http://git.shiar.nl/sc2-widget/blobdiff_plain/aa690a9c0c95e3121b747d77aa836fcd92654fb2..6ec9dc4ae5d48f32779c9d5029e937359c411104:/widget.php diff --git a/widget.php b/widget.php index ddf9cb8..c996111 100644 --- a/widget.php +++ b/widget.php @@ -17,16 +17,23 @@ function error($message, $status = 500) exit; } -$request = trim($_SERVER['PATH_INFO'], '/'); -$target = "$request.json"; -$last = file_exists($target) ? filemtime($target) : 0; +$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) { + 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); }