1 ? "s" : ""); } else if ($years == 0 && $days == 0 && $hours == 0) { return "$minutes minute" . ($minutes > 1 ? "s" : ""); } else if ($years == 0 && $days == 0) { return "$hours hour" . ($hours > 1 ? "s" : ""); } else if ($years == 0) { return "$days day" . ($days > 1 ? "s" : ""); } else { return "$years year" . ($years > 1 ? "s" : ""); } } function parse_lua_script($value) { if ($value instanceof \Raudius\Luar\Interpreter\LuarObject\Literal) { return $value->getValue(); } else if ($value instanceof \Raudius\Luar\Interpreter\LuarObject\Table) { return parse_lua_script($value->getValue()); } if (is_array($value)) { $out = []; foreach ($value as $k => $v) { if ($k == 'handle') { continue; } $out[$k] = parse_lua_script($v); } return $out; } return $value; } function build_script_metadata(string $folder_path) { $file_path = $_SERVER["DOCUMENT_ROOT"] . "/../scriptmetadata.json"; $should_create = is_dir($folder_path); $files = glob("$folder_path/*.lua"); if (file_exists($file_path)) { $file_last_change = filemtime($file_path); $script_last_change = 0; foreach ($files as $file) { $l = filemtime($file); if ($l > $script_last_change) { $l = $script_last_change; } } $should_create = $script_last_change > $file_last_change; } if ($should_create) { $scripts = []; $luar = new Luar(); $parsedown = new Parsedown(); foreach ($files as $file) { $contents = file_get_contents($file); $result = $luar->eval($contents); $script = parse_lua_script($result); if (!isset($script["description"])) { $script["description"] = "_No description provided._"; } $script['description_text'] = str_replace(PHP_EOL, ' ', $script['description']); $script['description_formatted'] = $parsedown->text($script['description']); array_push($scripts, $script); } file_put_contents($file_path, json_encode($scripts, JSON_UNESCAPED_SLASHES)); } return true; }