(.*?)<\/h1>/i", $html, $m)) { return strip_tags($m[1]); } return null; } function insertOrUpdate($slug, $label) { global $pdo; $stmt = $pdo->prepare("SELECT id FROM nav_items WHERE url = ?"); $stmt->execute([$slug]); if ($stmt->fetch()) { $pdo->prepare("UPDATE nav_items SET label = ? WHERE url = ?") ->execute([$label, $slug]); return "Updated '$slug' with label '$label'"; } else { $pdo->prepare("INSERT INTO nav_items (label, url, icon_class, parent_id, sort_order) VALUES (?, ?, NULL, NULL, 0)") ->execute([$label, $slug]); return "Inserted '$slug' → '$label'"; } } $folders = scanFolders(__DIR__); foreach ($folders as $folder) { $slug = basename($folder); $h1 = extractH1("$folder/index.php") ?? ucfirst(str_replace('-', ' ', $slug)); echo insertOrUpdate($slug, $h1) . "
"; } ?>