summaryrefslogtreecommitdiff
path: root/src/web/_model/bucket.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/web/_model/bucket.php48
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();