From 62bf263b8e8dbc3eae02ae1e2cb1a2ba86e80ac6 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Thu, 22 Jan 2026 00:12:51 +0100 Subject: [PATCH] assdasd --- public/assets/js/bridge/library-api.js | 9 ++++++- src/ApiKernel.php | 33 +++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/public/assets/js/bridge/library-api.js b/public/assets/js/bridge/library-api.js index 345b2b0..1f6512e 100644 --- a/public/assets/js/bridge/library-api.js +++ b/public/assets/js/bridge/library-api.js @@ -172,7 +172,14 @@     B.fetchSections = () => B.fetchResource('sections');     B.fetchBlocks = () => B.fetchResource('blocks'); -    B.getApiItem = (kind, id) => fetchData(kind, 'get', { id: id });  +    B.getApiItem = (kind, id) => { +        const normalized = String(kind || '').toLowerCase(); +        const legacyKinds = ['templates', 'sections', 'blocks', 'snippets', 'content', 'sections_config', 'content_versions']; +        if (B.USE_DYNAMIC_SECTIONS && !legacyKinds.includes(normalized)) { +            return fetchData('content', 'get', { id: id, section_slug: normalized, active_only: 1 }); +       } +        return fetchData(normalized || kind, 'get', { id: id }); +    };     B.clearApiCache = () => {         B.ApiItemCache = {}; // Cache leeren diff --git a/src/ApiKernel.php b/src/ApiKernel.php index 0af95a2..710c57a 100644 --- a/src/ApiKernel.php +++ b/src/ApiKernel.php @@ -779,6 +779,7 @@ class ApiKernel $itemsTable = $this->contentItemsTable(); $sectionsTable = $this->contentSectionsTable(); + $versionsTable = $this->contentVersionsTable(); if (!$this->tableExists($itemsTable) || !$this->tableExists($sectionsTable)) { $this->fail('Content tables not available', null, 500); } @@ -787,6 +788,10 @@ class ApiKernel $jsonCol = $itemCols['json']; $craftCol = $itemCols['craft']; $editorCol = $itemCols['editor']; + $onlyActive = (int)$this->val($this->in, ['active_only', 'only_active', 'active'], 0) === 1; + $versionCols = $onlyActive && $this->tableExists($versionsTable) + ? $this->resolveContentVersionColumns($versionsTable) + : null; $section = $fixedSection ?: $this->resolveSectionFromInput($customerId); $params = [':cid' => $customerId, ':id' => $id]; @@ -796,9 +801,20 @@ class ApiKernel $params[':sid'] = (int)$section['id']; } - $sql = "SELECT i.*, s.`name` AS section_name, s.`slug` AS section_slug, s.`position` AS section_position, s.`is_template` AS section_is_template + $select = "i.*, s.`name` AS section_name, s.`slug` AS section_slug, s.`position` AS section_position, s.`is_template` AS section_is_template"; + $join = ''; + if ($onlyActive && $versionCols) { + $join = "LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` AND v.`is_active` = 1"; + if (!empty($versionCols['html'])) $select .= ", v.`{$versionCols['html']}` AS version_html"; + if (!empty($versionCols['json'])) $select .= ", v.`{$versionCols['json']}` AS version_json"; + if (!empty($versionCols['craft'])) $select .= ", v.`{$versionCols['craft']}` AS version_craft"; + if (!empty($versionCols['editor'])) $select .= ", v.`{$versionCols['editor']}` AS version_editor"; + $select .= ", v.`id` AS active_version_id, v.`version_no` AS active_version_no, v.`is_active` AS version_is_active, v.`was_active` AS version_was_active"; + } + $sql = "SELECT $select FROM `$itemsTable` i JOIN `$sectionsTable` s ON s.`id` = i.`section_id` + $join $where LIMIT 1"; $stmt = $this->pdo->prepare($sql); @@ -809,6 +825,10 @@ class ApiKernel $html = $htmlCol ? (string)($row[$htmlCol] ?? '') : ''; $json = $jsonCol ? ($row[$jsonCol] ?? null) : null; + if ($onlyActive && $versionCols) { + if (array_key_exists('version_html', $row)) $html = (string)($row['version_html'] ?? $html); + if (array_key_exists('version_json', $row)) $json = $row['version_json'] ?? $json; + } $gjsComponents = []; if ($json !== null) { $decoded = json_decode((string)$json, true); @@ -825,6 +845,13 @@ class ApiKernel $item['section_position'] = $row['section_position'] ?? null; $item['section_is_template'] = (int)($row['section_is_template'] ?? 0); + $editorType = $editorCol ? ($row[$editorCol] ?? null) : null; + $craftJson = $craftCol ? ($row[$craftCol] ?? null) : null; + if ($onlyActive && $versionCols) { + if (array_key_exists('version_editor', $row)) $editorType = $row['version_editor'] ?? $editorType; + if (array_key_exists('version_craft', $row)) $craftJson = $row['version_craft'] ?? $craftJson; + } + $this->respond([ 'ok' => true, 'kind' => 'content', @@ -834,8 +861,8 @@ class ApiKernel 'html' => $html, 'content' => $json, 'gjs_components' => $gjsComponents, - 'editor_type' => $editorCol ? ($row[$editorCol] ?? null) : null, - 'craft_json' => $craftCol ? ($row[$craftCol] ?? null) : null, + 'editor_type' => $editorType, + 'craft_json' => $craftJson, ]); }