diff options
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/_controller/bucket.php | 4 | ||||
| -rw-r--r-- | src/web/_model/bucket.php | 48 | ||||
| -rw-r--r-- | src/web/_views/bucket/main.php | 5 | ||||
| -rw-r--r-- | src/web/_views/footer.php | 8 | ||||
| -rw-r--r-- | src/web/_views/head.php | 2 |
5 files changed, 59 insertions, 8 deletions
diff --git a/src/web/_controller/bucket.php b/src/web/_controller/bucket.php index 460f862..1723f72 100644 --- a/src/web/_controller/bucket.php +++ b/src/web/_controller/bucket.php @@ -17,6 +17,10 @@ class Bucket_controller extends Controller { $this->error(400); return; } + + $data['before'] = $this->bucket_model->get_before($data['name']); + $data['after'] = $this->bucket_model->get_after($data['name']); + $this->view('bucket/main', $data); } } 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(); diff --git a/src/web/_views/bucket/main.php b/src/web/_views/bucket/main.php index b85c773..2842afc 100644 --- a/src/web/_views/bucket/main.php +++ b/src/web/_views/bucket/main.php @@ -1,6 +1,5 @@ <?php /* Copyright (c) 2024 Freya Murphy */ ?> <?php - $root='https://webring.bucketfish.me/redirect.html?to=%s&name=' . $name; $this->view('head', $data); if ($lightmode === 'true') { echo embed_css_ext('css/bucket_light.css'); @@ -34,8 +33,8 @@ 🏳️🌈 </span> </center> - <span class="left">⥼ <a href="<?=sprintf($root, 'prev')?>" class="prev">prev</a></span> - <span class="right"><a href="<?=sprintf($root, 'next')?>" class="next">next</a> ⥽</span> + <span class="left">⥼ <a href="<?=$before?>" class="prev">prev</a></span> + <span class="right"><a href="<?=$after?>" class="next">next</a> ⥽</span> </div> </body> </html> diff --git a/src/web/_views/footer.php b/src/web/_views/footer.php index 70b1b13..f4395dd 100644 --- a/src/web/_views/footer.php +++ b/src/web/_views/footer.php @@ -7,10 +7,10 @@ $footer_text = ''; } ?> - <div id="ad" class="section ad-slot" role="region"> - <span class="ad-slot"> - <?=lang('adblock_notice')?> - </span> + <div class="ad-slot"> + <div id="ad" class="section" role="region"> + <span><?=lang('adblock_notice')?></span> + </div> </div> </div> </div> diff --git a/src/web/_views/head.php b/src/web/_views/head.php index 4d16a1b..281ebc5 100644 --- a/src/web/_views/head.php +++ b/src/web/_views/head.php @@ -7,7 +7,7 @@ if (ENVIRONMENT == 'production' && !in_array($current_app, $non_cached_apps)) { $cache_seconds = 300; if ($current_app == 'bucket') { - $cache_seconds = 3600; + $cache_seconds = 86400; } header("Cache-Control: public, max-age=$cache_seconds"); header("Expires: " . gmdate('D, d M Y H:i:s', time() + $cache_seconds) . " UTC"); |