This commit is contained in:
2026-06-06 11:53:11 -04:00
parent 01e984c560
commit df88788890
4 changed files with 422 additions and 381 deletions

View File

@@ -0,0 +1,81 @@
<?php
/**
* Association Profile — View Hooks and Profile Renderer
* Renders the association profile on the public channel profile page.
* Called via require_once in assoc_profile.php.
*/
// ----------------------------------------------------------------------------
// PROFILE VIEW HOOK — fires on profile_advanced
// ----------------------------------------------------------------------------
function assoc_profile_view_hook(&$o) {
// Append the association diagnostic profile to the channel profile page.
$uid = intval(App::$profile['profile_uid'] ?? 0);
if (!$uid) return;
$r = q("SELECT channel_address FROM channel WHERE channel_id = %d LIMIT 1", intval($uid));
if (!$r) return;
$slug = assoc_slug_from_address($r[0]['channel_address']);
$entry = assoc_get($slug);
if (!$entry) return;
if (function_exists('head_add_css')) head_add_css('/addon/assoc_profile/view/css/assoc_profile.css');
$o .= assoc_render_view($entry);
}
// ----------------------------------------------------------------------------
// PROFILE EDIT HOOK
// ----------------------------------------------------------------------------
function assoc_profile_edit_hook(&$b) {
// Add a link to the manage interface in the profile edit form.
if (!assoc_is_operator()) return;
$channel = App::get_channel();
$slug = assoc_slug_from_address($channel['channel_address'] ?? '');
$entry = assoc_get($slug);
if (!$entry) return;
if (function_exists('head_add_css')) head_add_css('/addon/assoc_profile/view/css/assoc_profile.css');
$b['html'] .= '<div class="assoc-profile-edit-link mt-2">
<a href="' . z_root() . '/assoc_profile/manage/assoc/' . assoc_h($slug) . '" class="btn btn-sm btn-outline-secondary">
Edit Association Diagnostic Profile
</a></div>';
}
// ----------------------------------------------------------------------------
// PROFILE VIEW RENDERER
// ----------------------------------------------------------------------------
function assoc_render_view($entry) {
// Render all field groups as a read-only diagnostic profile block.
$def = assoc_load_fields();
$groups = $def['groups'] ?? [];
$fields = $def['fields'] ?? [];
$by_group = [];
foreach ($fields as $f) {
$by_group[$f['group']][] = $f;
}
$out = '<div class="assoc-profile-view">';
$out .= '<h4 class="assoc-profile-heading">Association Diagnostic Profile</h4>';
foreach ($groups as $group) {
$group_fields = $by_group[$group] ?? [];
if (empty($group_fields)) continue;
$out .= '<div class="assoc-profile-group">';
$out .= '<h5 class="assoc-group-label">' . assoc_h($group) . '</h5>';
foreach ($group_fields as $f) {
$nick = $f['nickname'];
$val = $entry[$nick] ?? '';
if ($val === '') $val = '—';
if ($val === 'UNK') $val = 'Unknown — not yet verified';
$out .= '<div class="assoc-profile-field">';
$out .= '<span class="assoc-field-label">' . assoc_h($f['label'] ?? $nick) . ':</span> ';
$out .= '<span class="assoc-field-value">' . assoc_h($val) . '</span>';
$out .= '</div>';
}
$out .= '</div>';
}
$out .= '</div>';
return $out;
}