From 7ebfb9cb639a57bce57700eda59c1e0192c399e2 Mon Sep 17 00:00:00 2001 From: Philipp Urbschat Date: Sun, 13 Sep 2026 00:03:03 +0200 Subject: [PATCH] fix(admin): resolve colon-formatted project strings like plants:plants and storymachine:geschichtenmaschine --- home/app/models/Invitation.php | 6 ++-- home/app/models/User.php | 59 ++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/home/app/models/Invitation.php b/home/app/models/Invitation.php index 3891085..94ec987 100644 --- a/home/app/models/Invitation.php +++ b/home/app/models/Invitation.php @@ -31,7 +31,7 @@ class Invitation { $this->db->bind(':id', $id); $inv = $this->db->single(); if ($inv) { - $inv['assigned_projects'] = json_decode($inv['assigned_projects'] ?? '[]', true) ?? []; + $inv['assigned_projects'] = User::parseProjects($inv['assigned_projects'] ?? []); } return $inv ?: null; } @@ -60,7 +60,7 @@ class Invitation { } } - $invitation['assigned_projects'] = json_decode($invitation['assigned_projects'] ?? '[]', true) ?? []; + $invitation['assigned_projects'] = User::parseProjects($invitation['assigned_projects'] ?? []); return $invitation; } @@ -77,7 +77,7 @@ class Invitation { $invitations = $this->db->resultSet(); foreach ($invitations as &$inv) { - $inv['assigned_projects'] = json_decode($inv['assigned_projects'] ?? '[]', true) ?? []; + $inv['assigned_projects'] = User::parseProjects($inv['assigned_projects'] ?? []); $isExpired = false; if (!empty($inv['expires_at'])) { $isExpired = (new DateTime()) > (new DateTime($inv['expires_at'])); diff --git a/home/app/models/User.php b/home/app/models/User.php index 114b887..fdd8eb2 100644 --- a/home/app/models/User.php +++ b/home/app/models/User.php @@ -40,16 +40,24 @@ class User { } $slugMap['web audio synth'] = 'test'; $slugMap['webaudiosynth'] = 'test'; + $slugMap['synth'] = 'test'; + $slugMap['geschichtenmaschine'] = 'storymachine'; + $slugMap['geschichten-maschine'] = 'storymachine'; + $slugMap['pflanzen'] = 'plants'; + $slugMap['pflanzentracker'] = 'plants'; + + $ignore = ['on', 'off', 'true', 'false', '1', '0', 'null', 'undefined']; $clean = []; foreach ($projects as $key => $val) { $candidates = []; if (is_string($key) && !is_numeric($key)) { - if ($val === true || $val === 1 || $val === '1' || $val === 'on' || $val === 'true' || is_array($val)) { - $candidates[] = $key; + $candidates[] = $key; + if (is_string($val) && !in_array(strtolower(trim($val)), $ignore, true)) { + $candidates[] = $val; } } else { - if (is_string($val)) { + if (is_string($val) && !in_array(strtolower(trim($val)), $ignore, true)) { $candidates[] = $val; } elseif (is_array($val)) { if (!empty($val['slug'])) $candidates[] = $val['slug']; @@ -58,23 +66,46 @@ class User { elseif (!empty($val['project'])) $candidates[] = $val['project']; else { foreach ($val as $sub) { - if (is_string($sub)) $candidates[] = $sub; + if (is_string($sub) && !in_array(strtolower(trim($sub)), $ignore, true)) { + $candidates[] = $sub; + } } } } } foreach ($candidates as $cand) { - $sanitized = trim($cand, " \t\n\r\0\x0B[]\"'/"); - if (empty($sanitized)) continue; - $lower = strtolower($sanitized); - $normalized = str_replace([' ', '-', '_'], '', $lower); - if (isset($slugMap[$lower])) { - $clean[] = $slugMap[$lower]; - } elseif (isset($slugMap[$normalized])) { - $clean[] = $slugMap[$normalized]; - } else { - $clean[] = $sanitized; + $candSan = trim($cand, " \t\n\r\0\x0B[]\"'/"); + if (empty($candSan)) continue; + + // Check if candidate contains colon or equals, e.g. "plants:plants" or "storymachine:geschichtenmaschine" + $subParts = preg_split('/[:=]/', $candSan); + $matched = false; + foreach ($subParts as $part) { + $pSan = trim($part, " \t\n\r\0\x0B[]\"'/"); + if (empty($pSan)) continue; + $pLower = strtolower($pSan); + $pNorm = str_replace([' ', '-', '_'], '', $pLower); + if (isset($slugMap[$pLower])) { + $clean[] = $slugMap[$pLower]; + $matched = true; + break; + } elseif (isset($slugMap[$pNorm])) { + $clean[] = $slugMap[$pNorm]; + $matched = true; + break; + } + } + if (!$matched) { + $lower = strtolower($candSan); + $normalized = str_replace([' ', '-', '_'], '', $lower); + if (isset($slugMap[$lower])) { + $clean[] = $slugMap[$lower]; + } elseif (isset($slugMap[$normalized])) { + $clean[] = $slugMap[$normalized]; + } elseif (isset($allModules[$lower])) { + $clean[] = $lower; + } } } }