aboutsummaryrefslogtreecommitdiffstats
path: root/motd
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--motd/index.php150
-rw-r--r--motd/motd-data.php13
-rw-r--r--motd/motd.json14
3 files changed, 177 insertions, 0 deletions
diff --git a/motd/index.php b/motd/index.php
new file mode 100644
index 0000000..23e0a8d
--- /dev/null
+++ b/motd/index.php
@@ -0,0 +1,150 @@
+<?php
+require_once __DIR__ . '/../partials/asset_version.php';
+
+$motd = [
+ 'title' => '',
+ 'body' => '',
+ 'updated' => '',
+ 'rev' => 0,
+ 'history' => [],
+];
+$page_file = __DIR__ . '/motd-data.php';
+$json_file = __DIR__ . '/motd.json';
+if (is_file($page_file)) {
+ $data = require $page_file;
+ if (is_array($data)) $motd = array_merge($motd, $data);
+} elseif (is_file($json_file)) {
+ $raw = file_get_contents($json_file);
+ $data = is_string($raw) ? json_decode($raw, true) : null;
+ if (is_array($data)) $motd = array_merge($motd, $data);
+}
+
+$title = trim((string)($motd['title'] ?? ''));
+$heading = trim((string)($motd['heading'] ?? ''));
+if ($title === '') $title = $heading;
+$body = trim((string)($motd['body'] ?? ''));
+$live = $body !== '';
+$updated = trim((string)($motd['updated'] ?? ''));
+$rev = (int)($motd['rev'] ?? 0);
+$history = is_array($motd['history'] ?? null) ? $motd['history'] : [];
+
+$page_title = $live && $title !== ''
+ ? $title . ' — SillyLaird'
+ : 'MOTD — SillyLaird';
+$page_desc = $live
+ ? ($title !== '' ? $title . '. ' : '') . preg_replace('/\s+/', ' ', $body)
+ : 'Pinned message of the day for the SillyLaird XMPP room, posted by waifu.';
+if (strlen($page_desc) > 200) {
+ $page_desc = substr($page_desc, 0, 197) . '...';
+}
+
+$h = static fn(string $s): string => htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
+
+$link_body = static function (string $text) use ($h): string {
+ $esc = $h($text);
+ return preg_replace(
+ '~(https?://[^\s<]+)~',
+ '<a href="$1" rel="noopener noreferrer">$1</a>',
+ $esc
+ ) ?? $esc;
+};
+
+$fmt_when = static function (string $iso): string {
+ if ($iso === '') return '';
+ try {
+ $dt = new DateTimeImmutable($iso);
+ return $dt->format('Y-m-d H:i T');
+ } catch (Exception $e) {
+ return $iso;
+ }
+};
+
+$past = [];
+foreach ($history as $row) {
+ if (!is_array($row)) continue;
+ $pbody = trim((string)($row['body'] ?? ''));
+ if ($pbody === '') continue;
+ $past[] = $row;
+}
+?>
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
+ <title><?= $h($page_title) ?></title>
+<?php
+ $meta = [
+ 'lang' => 'en',
+ 'title' => $page_title,
+ 'desc' => $page_desc,
+ 'base' => 'motd/index',
+ 'self_url' => 'https://www.sillylaird.ca/motd/',
+ 'en_url' => 'https://www.sillylaird.ca/motd/',
+ 'ja_url' => 'https://www.sillylaird.ca/motd/',
+ 'zh_url' => 'https://www.sillylaird.ca/motd/',
+ 'x_default' => 'https://www.sillylaird.ca/motd/',
+ 'updated' => $updated !== '' ? substr($updated, 0, 10) : '',
+ ];
+ include __DIR__ . '/../partials/head_meta.php';
+?>
+ <link rel="stylesheet" href="/assets/css/fonts.css" />
+ <link rel="stylesheet" href="/assets/css/site.css" />
+ <link rel="stylesheet" href="/assets/css/skeleton.css" />
+ <link rel="stylesheet" href="/<?= $h(asset_v('assets/css/pages/motd.css')) ?>" />
+</head>
+<body>
+ <a class="skip-link" href="#main">Skip to content</a>
+ <?php include __DIR__ . '/../partials/header.php'; ?>
+
+ <main id="main" class="wrap">
+ <section aria-labelledby="motd-page-title">
+ <h1 id="motd-page-title">MOTD</h1>
+ <p class="muted">Pinned notice for the XMPP room. Type <code>!motd</code> to read it. waifu posts it to the room only when it is announced from admin.</p>
+
+ <h2 id="motd-current-title">Current notice</h2>
+ <?php if ($live): ?>
+ <div class="motd-current" aria-live="polite">
+ <?php if ($title !== ''): ?>
+ <div class="motd-heading"><?= $h($title) ?></div>
+ <?php endif; ?>
+ <p class="motd-body"><?= $link_body($body) ?></p>
+ <?php
+ $bits = [];
+ if ($updated !== '') $bits[] = 'posted ' . $fmt_when($updated);
+ if ($rev > 0) $bits[] = 'rev ' . $rev;
+ if ($bits):
+ ?>
+ <p class="muted"><?= $h(implode(' · ', $bits)) ?></p>
+ <?php endif; ?>
+ </div>
+ <?php else: ?>
+ <p class="muted">Nothing pinned right now.</p>
+ <?php endif; ?>
+
+ <h2>Room</h2>
+ <ul class="contact-list">
+ <li>XMPP: <a href="xmpp:based@conference.sillylaird.ca?join">based@conference.sillylaird.ca</a></li>
+ <li>Bot: waifu</li>
+ <li>Command: <code>!motd</code></li>
+ </ul>
+
+ <?php if ($past): ?>
+ <h2 id="motd-archive-title">Previous notices</h2>
+ <?php foreach ($past as $row):
+ $ptitle = trim((string)($row['title'] ?? ''));
+ $pbody = trim((string)($row['body'] ?? ''));
+ $pwhen = trim((string)($row['updated'] ?? ''));
+ ?>
+ <div class="entry">
+ <?php if ($pwhen !== ''): ?><time datetime="<?= $h($pwhen) ?>"><?= $h($fmt_when($pwhen)) ?></time><?php endif; ?>
+ <p><?php if ($ptitle !== ''): ?><strong><?= $h($ptitle) ?></strong> <?php endif; ?><?= $link_body($pbody) ?></p>
+ </div>
+ <?php endforeach; ?>
+ <?php endif; ?>
+ </section>
+ </main>
+
+ <?php include __DIR__ . '/../partials/footer.php'; ?>
+</body>
+</html>
diff --git a/motd/motd-data.php b/motd/motd-data.php
new file mode 100644
index 0000000..1240efc
--- /dev/null
+++ b/motd/motd-data.php
@@ -0,0 +1,13 @@
+<?php
+// motd-data.php — /motd/ page content, edited via /admin.php
+if (realpath(__FILE__) === realpath($_SERVER["SCRIPT_FILENAME"] ?? "")) { http_response_code(404); exit; }
+
+return array (
+ 'title' => '',
+ 'body' => 'watching baldy',
+ 'updated' => '2026-08-21T21:05:30+00:00',
+ 'rev' => 2,
+ 'history' =>
+ array (
+ ),
+);
diff --git a/motd/motd.json b/motd/motd.json
new file mode 100644
index 0000000..4322c6d
--- /dev/null
+++ b/motd/motd.json
@@ -0,0 +1,14 @@
+{
+ "enabled": true,
+ "title": "",
+ "emoji": "",
+ "heading": "MOTD",
+ "url": "https://www.sillylaird.ca/motd/",
+ "body": "watching baldy",
+ "updated": "2026-08-21T21:05:30+00:00",
+ "rev": 2,
+ "push": 0,
+ "announce_on_join": true,
+ "announce_on_change": true,
+ "history": []
+}