tilde/ring/index.php

70 lines
2.1 KiB
PHP

<?php
$action = $_GET["action"] ?? "index";
if ($action !== "index") {
$users = [];
foreach (glob("/home/*/.ring") as $path)
$users[] = basename(dirname($path));
$me = $_GET["me"] ?? "";
$i = array_search($me, $users) ?? 0;
switch ($action) {
case "random":
$notme = array_diff($users, [$me]);
$user = $notme[array_rand($notme)];
break;
case "next":
$user = $users[$i + 1] ?? $users[0];
break;
case "prev":
$user = $users[$i - 1] ?? $users[count($users) - 1];
break;
default:
die("invalid action");
}
header("Location: https://tilde.team/~$user/");
die();
}
else {
$snippet = '<!-- Begin Tilde.Team Ring Fragment-->
<div id="newring">
<center>
[<a href="https://tilde.team/~ben/ring/?action=prev&me=USERNAME">previous</a>]
[<a href="https://tilde.team/~ben/ring/?action=random&me=USERNAME">random</a>]
[<a href="https://tilde.team/~ben/ring/?action=next&me=USERNAME">next</a>]
<br>
<a href="https://tilde.team/~ben/ring/">how to join this webring</a>
</center>
</div>';
?>
<!DOCTYPE html>
<html>
<head>
<title>webring - how to join</title>
<link rel="stylesheet" href="https://tilde.team/~ben/gruvbox/gruvbox.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body id="top">
<main>
<h1>how to join the webring</h1>
<p>This webring can be joined by any user on tilde.team.</p>
<p>First, add the following code to your page, replacing USERNAME by your username (no ~):</p>
<pre><?=htmlspecialchars($snippet)?></pre>
<p>You may edit the code however you want. It should work as long as the URLs are kept in place and have your user in them.</p>
<p>Then create a .ring file in your ~ to be added in the webring:</p>
<pre>$ touch ~/.ring</pre>
<p>see webring source <a href="index.php.txt">here</a></p>
<p>it will probably work if you copy it to your <code>~/public_html</code></p>
</main>
</body>
</html>
<?php }