<?php

$tilde = $_GET["tilde"] ?? "tilde.team";
$json   = json_decode(file_get_contents("http://${tilde}/tilde.json"), true);
$tildes = json_decode(file_get_contents("https://tildeverse.org/members.json"), true);
foreach ($tildes["members"] as $member) {
    $domains[] = str_replace("http://", "", str_replace("https://", "", $member["link"]));
}
?>

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://tilde.team/css/hacker.css">
  <title>tilde.json explorer</title>
</head>

<body>
<div class="container">
    <h1>tilde.json explorer</h1>

    <div class="btn-group">
        <button type="button" class="btn btn-default dropdown-toggle" id="dropdown1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            tildeverse members <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" aria-labelledby="dropdown1">
            <?php foreach ($domains as $d) { ?>
            <li><a href="?tilde=<?=$d?>"><?=$d?></a></li>
            <?php } ?>
        </ul>
    </div>

    <hr>

    <p>here is the info for <?=$tilde?></p>
    <p>name: <?=$json["name"]?></p>
    <p>url: <a href="<?=$json["url"]?>"><?=$json["url"]?></a></p>
    <p>signup url: <a href="<?=$json["signup_url"]?>"><?=$json["signup_url"]?></a></p>
    <p>user count: <?=$json["user_count"]?></p>
    <p>accepting signups?: <?=$json["want_users"] ? "yes" : "no" ?></p>
    <p>admin email address: <a href="mailto:<?=$json["admin_email"]?>"><?=$json["admin_email"]?></a></p>
    <p>description: <?=$json["description"]?></p>

</div>
<script src="https://tilde.team/js/jquery.min.js"></script>
<script src="https://tilde.team/js/bootstrap.min.js"></script>
</body>
</html>

