aboutsummaryrefslogtreecommitdiffstats
path: root/partials/site_status.php
diff options
context:
space:
mode:
Diffstat (limited to 'partials/site_status.php')
-rw-r--r--partials/site_status.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/partials/site_status.php b/partials/site_status.php
new file mode 100644
index 0000000..c758186
--- /dev/null
+++ b/partials/site_status.php
@@ -0,0 +1,70 @@
+<?php
+
+function site_latest_update_timestamp(): int
+{
+ static $latest = null;
+ if ($latest !== null) {
+ return $latest;
+ }
+
+ $root = dirname(__DIR__);
+ $latest = 0;
+ $extensions = ['php' => true, 'html' => true, 'css' => true, 'js' => true, 'txt' => true];
+ $skipDirs = ['.git' => true, '.agents' => true, 'node_modules' => true, 'vendor' => true];
+
+ $iterator = new RecursiveIteratorIterator(
+ new RecursiveCallbackFilterIterator(
+ new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS),
+ static function (SplFileInfo $current) use ($skipDirs): bool {
+ if ($current->isDir()) {
+ return !isset($skipDirs[$current->getFilename()]);
+ }
+ return true;
+ }
+ )
+ );
+
+ foreach ($iterator as $file) {
+ if (!$file->isFile()) {
+ continue;
+ }
+ $extension = strtolower($file->getExtension());
+ if (!isset($extensions[$extension])) {
+ continue;
+ }
+ $mtime = @filemtime($file->getPathname());
+ if ($mtime && $mtime > $latest) {
+ $latest = $mtime;
+ }
+ }
+
+ return $latest;
+}
+
+function site_update_status(): array
+{
+ $timezone = new DateTimeZone('America/New_York');
+ $latest = site_latest_update_timestamp();
+ $date = $latest
+ ? (new DateTimeImmutable('@' . $latest))->setTimezone($timezone)->format('Y-m-d')
+ : (new DateTimeImmutable('now', $timezone))->format('Y-m-d');
+ $today = (new DateTimeImmutable('now', $timezone))->format('Y-m-d');
+
+ return [
+ 'date' => $date,
+ 'updated_today' => $date === $today,
+ ];
+}
+
+function render_site_update_status(string $class = 'site-status-row'): void
+{
+ $status = site_update_status();
+ $date = htmlspecialchars($status['date'], ENT_QUOTES, 'UTF-8');
+ $label = $status['updated_today'] ? 'Updated today: check the changelog' : 'View changelog';
+ ?>
+ <div class="<?= htmlspecialchars($class, ENT_QUOTES, 'UTF-8') ?>" aria-label="Site status">
+ <span>Last updated: <time datetime="<?= $date ?>"><?= $date ?></time></span>
+ <a href="https://www.sillylaird.ca/changelog/"><?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8') ?></a>
+ </div>
+ <?php
+}