new feature: webring

This commit is contained in:
2026-05-25 12:39:40 +02:00
parent ea5e654c65
commit 169a1c1c4d
5 changed files with 86 additions and 0 deletions

40
webring/index.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
$members = require 'members.php';
$count = count($members);
$action = $_GET['action'] ?? '';
$ref = $_SERVER['HTTP_REFERER'];
if (preg_match('/https\:\/\/tylda\.org\/\~[a-zA-Z0-9\-\_]+.*/', $ref)) {
$site = substr(explode('/', $ref)[3], 1);
} else {
$site = $_GET['site'] ?? '';
}
$index = array_search($site, array_column($members, 'name'));
if ($index === false) {
http_response_code(404);
die('Nieznana strona!');
}
switch ($action) {
case 'prev':
$target = $members[($index - 1 + $count) % $count];
break;
case 'next':
$target = $members[($index + 1) % $count];
break;
case 'random':
$r = rand(0, $count - 1);
$target = $members[$r];
break;
default:
http_response_code(400);
die('Brak akcji (prev/next/random)');
}
header('Location: ' . $target['url']);
exit;
?>

19
webring/members.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
$members = [];
foreach (scandir("/home/") as $user) {
if (in_array($user, array('.', '..'))) continue;
$webring_file = "/home/$user/public_html/.webring";
if (is_file($webring_file)) {
array_push($members, ['name' => $user, 'url' => 'https://tylda.org/~'.$user]);
}
}
return $members;
?>