diff options
| author | Freya Murphy <freya@freyacat.org> | 2026-02-28 01:03:17 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2026-02-28 01:03:17 -0500 |
| commit | 0dfa656c70d70581ab4cd2ddf393cb432cd16517 (patch) | |
| tree | e3f0396a65c854fa1da91c69bab08631b6cf8710 /src/web/_model/bucket.php | |
| parent | fix even more css (for ie4) (diff) | |
| download | website-0dfa656c70d70581ab4cd2ddf393cb432cd16517.tar.gz website-0dfa656c70d70581ab4cd2ddf393cb432cd16517.tar.bz2 website-0dfa656c70d70581ab4cd2ddf393cb432cd16517.zip | |
bucket webring: pull links from local json file
Diffstat (limited to 'src/web/_model/bucket.php')
| -rw-r--r-- | src/web/_model/bucket.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/web/_model/bucket.php b/src/web/_model/bucket.php index 7c426b7..3075ac3 100644 --- a/src/web/_model/bucket.php +++ b/src/web/_model/bucket.php @@ -1,6 +1,54 @@ <?php /* Copyright (c) 2024 Freya Murphy */ class Bucket_model extends Model { + private $bucket_json; + private $bucket_map; + + function __construct() + { + $this->bucket_json = array(); + if (file_exists('/var/run/crimson/bucket.json')) { + $this->bucket_json = file_get_contents('/var/run/crimson/bucket.json'); + $this->bucket_json = json_decode($this->bucket_json) ?? array(); + } + + $this->bucket_map = array(); + foreach ($this->bucket_json as $idx => $entry) { + $this->bucket_map[$entry->name ?? ''] = $idx; + } + } + + public function get_before(string $name): string + { + $default = "https://webring.bucketfish.me/redirect.html?to=prev&name={$name}"; + + $idx = $this->bucket_map[$name ?? ''] ?? null; + if (!$idx) + return $default; + + if ($idx) + $idx--; + else + $idx = count($this->bucket_json) - 1; + + return $this->bucket_json[$idx]->url ?? $default; + } + + public function get_after(string $name): string + { + $default = "https://webring.bucketfish.me/redirect.html?to=next&name={$name}"; + + $idx = $this->bucket_map[$name ?? ''] ?? null; + if (!$idx) + return $default; + + $idx++; + if ($idx == count($this->bucket_json)) + $idx = 0; + + return $this->bucket_json[$idx]->url ?? $default; + } + public function get_data(): ?array { $data = parent::get_data(); |