diff --git a/config.php b/config.php index 7beda22..80aa5fd 100755 --- a/config.php +++ b/config.php @@ -19,6 +19,7 @@ $loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates'); $twig = new \Twig\Environment($loader, [ // 'cache' => __DIR__ . '/cache/twig', // Uncomment for production 'debug' => true, + 'max_recursion' => 100, ]); // --- Translation Setup --- @@ -52,7 +53,8 @@ try { $categories = App\Models\Category::getAll($db); $items = App\Models\Item::getAll($db); - function buildTree($categories, $items, $parentId = null, &$visited = []) { + function buildTree($categories, $items, $parentId = null, &$visited = [], $depth = 0) { + if ($depth > 10) return []; // Prevent deep recursion $tree = []; foreach ($categories as $cat) { if ($cat['parent_id'] == $parentId && !in_array($cat['id'], $visited)) { @@ -60,7 +62,7 @@ try { $node = [ 'id' => $cat['id'], 'name' => $cat['name'], - 'children' => buildTree($categories, $items, $cat['id'], $visited), + 'children' => buildTree($categories, $items, $cat['id'], $visited, $depth + 1), 'items' => [] ]; foreach ($items as $item) { @@ -75,8 +77,33 @@ try { } $categoryTree = buildTree($categories, $items); + + function renderTree($nodes, $depth = 0) { + if ($depth > 10) return ''; + $html = ''; + foreach ($nodes as $node) { + $html .= '