fix(admin): resolve colon-formatted project strings like plants:plants and storymachine:geschichtenmaschine
This commit is contained in:
parent
50b4a70045
commit
7ebfb9cb63
2 changed files with 48 additions and 17 deletions
|
|
@ -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']));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue