156 lines
4.6 KiB
PHP
156 lines
4.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Name: VS-01 Vital Signs
|
|
* Description: Public civic diagnostic — the ten structural preconditions of an HOA association.
|
|
* Version: 0.1.0
|
|
* MinVersion: 11.0
|
|
* MaxVersion: 12.0
|
|
*/
|
|
|
|
use Zotlabs\Extend\Widget;
|
|
|
|
function vs01_module() {}
|
|
|
|
function vs01_load() {
|
|
register_hook('load_pdl', 'addon/vs01/vs01.php', 'vs01_load_pdl');
|
|
Widget::register('addon/vs01/Widget/Vs01.php', 'vs01');
|
|
}
|
|
|
|
function vs01_unload() {
|
|
unregister_hook('load_pdl', 'addon/vs01/vs01.php', 'vs01_load_pdl');
|
|
Widget::unregister('addon/vs01/Widget/Vs01.php', 'vs01');
|
|
}
|
|
|
|
function vs01_load_pdl(&$b) {
|
|
if (!is_array($b) || empty($b['module']) || $b['module'] !== 'vs01') {
|
|
return;
|
|
}
|
|
$layout = @file_get_contents('addon/vs01/mod_vs01.pdl');
|
|
if ($layout !== false) {
|
|
$b['layout'] = $layout;
|
|
}
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// HELPERS
|
|
// ----------------------------------------------------------------------------
|
|
|
|
function vs01_h($value) {
|
|
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ACCESS
|
|
// ----------------------------------------------------------------------------
|
|
|
|
function vs01_access_state() {
|
|
if (!local_channel()) {
|
|
return 'public';
|
|
}
|
|
|
|
$channel = App::get_channel();
|
|
|
|
if (local_channel() === intval($channel['channel_id'])) {
|
|
return 'operator';
|
|
}
|
|
|
|
$config = vs01_load_config();
|
|
$gid = intval($config['corpus_builder_group_id'] ?? 0);
|
|
|
|
if ($gid && in_array(get_observer_hash(), group_get_members_xchan($gid))) {
|
|
return 'participant';
|
|
}
|
|
|
|
return 'denied';
|
|
}
|
|
|
|
function vs01_access_wall() {
|
|
return '
|
|
<div class="vs01-content">
|
|
<div class="alert alert-info" role="alert">
|
|
<strong>HOA_MEMBER standing required to submit.</strong>
|
|
Vital Signs are public and readable by anyone.
|
|
To submit a Vital Signs record for your association, you must complete the SASE process.
|
|
Visit <a href="https://directory.diagnostics.kane-il.us/channel/theron">
|
|
directory.diagnostics.kane-il.us
|
|
</a> to begin.
|
|
</div>
|
|
</div>
|
|
';
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// CONTENT
|
|
// ----------------------------------------------------------------------------
|
|
|
|
function vs01_content() {
|
|
if (function_exists('head_add_css')) {
|
|
head_add_css('/addon/vs01/view/css/vs01.css');
|
|
}
|
|
if (function_exists('head_add_js')) {
|
|
head_add_js('/addon/vs01/view/js/vs01.js');
|
|
}
|
|
|
|
$access = vs01_access_state();
|
|
|
|
// vs01 is public — access wall only gates submission, not reading
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if ($access === 'public' || $access === 'denied') {
|
|
return vs01_access_wall();
|
|
}
|
|
// TODO: handle POST submission
|
|
return vs01_access_wall();
|
|
}
|
|
|
|
return vs01_render_main($access);
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// RENDER
|
|
// ----------------------------------------------------------------------------
|
|
|
|
function vs01_render_main($access) {
|
|
$out = '<div class="vs01-content">';
|
|
$out .= '<div class="vs01-header mb-3">';
|
|
$out .= '<h2>Vital Signs</h2>';
|
|
$out .= '<p class="text-muted">The ten structural preconditions of an HOA association.</p>';
|
|
$out .= '</div>';
|
|
|
|
// TODO: render the ten Vital Signs
|
|
|
|
$out .= '<div class="vs01-placeholder text-muted fst-italic">Content forthcoming.</div>';
|
|
$out .= '</div>';
|
|
|
|
return $out;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// CONFIG
|
|
// ----------------------------------------------------------------------------
|
|
|
|
function vs01_load_config() {
|
|
$path = 'addon/vs01/config.json';
|
|
$raw = @file_get_contents($path);
|
|
if ($raw === false) return [];
|
|
$data = json_decode($raw, true);
|
|
return (json_last_error() === JSON_ERROR_NONE) ? $data : [];
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// CSRF
|
|
// ----------------------------------------------------------------------------
|
|
|
|
function vs01_csrf_token() {
|
|
if (empty($_SESSION['vs01_csrf'])) {
|
|
$_SESSION['vs01_csrf'] = bin2hex(random_bytes(16));
|
|
}
|
|
return '<input type="hidden" name="vs01_csrf" value="'
|
|
. vs01_h($_SESSION['vs01_csrf']) . '">';
|
|
}
|
|
|
|
function vs01_verify_csrf() {
|
|
return isset($_POST['vs01_csrf'], $_SESSION['vs01_csrf'])
|
|
&& hash_equals($_SESSION['vs01_csrf'], $_POST['vs01_csrf']);
|
|
}
|