From 70656662332cbc51e8ec7c8076afc18d597a2c1a Mon Sep 17 00:00:00 2001 From: TheRON Date: Sun, 7 Jun 2026 07:48:21 -0400 Subject: [PATCH] Updated --- hubzilla/addon/vs01/Widget/CivicNav.php | 136 ++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 hubzilla/addon/vs01/Widget/CivicNav.php diff --git a/hubzilla/addon/vs01/Widget/CivicNav.php b/hubzilla/addon/vs01/Widget/CivicNav.php new file mode 100644 index 0000000..e05b446 --- /dev/null +++ b/hubzilla/addon/vs01/Widget/CivicNav.php @@ -0,0 +1,136 @@ +resolve_slug(); + if (!$slug) { + return ''; + } + + // Only render on registered association channels. + if (!$this->is_registered_association($slug)) { + return ''; + } + + $addons = $this->load_registry(); + if (empty($addons)) { + return ''; + } + + $module = \App::$module ?? ''; + $slug_safe = htmlspecialchars($slug, ENT_QUOTES, 'UTF-8'); + + if (function_exists('head_add_css')) { + head_add_css('/addon/vs01/view/css/civicnav.css'); + } + + $out = '
'; + $out .= '
Diagnostic Record
'; + $out .= ''; + $out .= '
'; + + return $out; + } + + // ------------------------------------------------------------------------- + // SLUG RESOLUTION + // ------------------------------------------------------------------------- + + private function resolve_slug() { + $module = \App::$module ?? ''; + + // On addon module pages (vs01, dsc01, scn01): slug is argv(1). + if (in_array($module, ['vs01', 'dsc01', 'scn01'], true)) { + return \argv(1) ?? ''; + } + + // On the channel page: slug is the local part of channel_address. + if ($module === 'channel') { + $addr = \App::$profile['channel_address'] ?? ''; + if ($addr) { + // channel_address may be bare (kingsrow-wdca) or full (kingsrow-wdca@node). + return explode('@', $addr)[0]; + } + } + + return ''; + } + + // ------------------------------------------------------------------------- + // ASSOCIATION GUARD + // ------------------------------------------------------------------------- + + private function is_registered_association($slug) { + $raw = @file_get_contents('addon/vs01/config.json'); + if ($raw === false) { + return false; + } + $config = json_decode($raw, true); + if (json_last_error() !== JSON_ERROR_NONE) { + return false; + } + return isset($config['associations'][$slug]); + } + + // ------------------------------------------------------------------------- + // REGISTRY LOADER + // ------------------------------------------------------------------------- + + private function load_registry() { + $raw = @file_get_contents('addon/vs01/civicnav.json'); + if ($raw === false) { + // Fall back to template defaults if runtime file not present. + $raw = @file_get_contents('addon/vs01/civicnav.json.template'); + } + if ($raw === false) { + return []; + } + $data = json_decode($raw, true); + if (json_last_error() !== JSON_ERROR_NONE) { + return []; + } + return $data['addons'] ?? []; + } +}