-$request = trim($_SERVER['PATH_INFO'], '/');
-if (!file_exists("$request.json")) {
- if (!is_numeric($request)) {
+$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 {