[], 'order' => [], 'ui' => []]; $lines = file($file, FILE_IGNORE_NEW_LINES); $defines = []; $order = []; $ui = []; // BOM entfernen, falls vorhanden if (isset($lines[0])) { $lines[0] = preg_replace('/^\xEF\xBB\xBF/', '', $lines[0]); } // Regex $reDefine = '/^\s*define\(\s*([\'"])([^\'"]+)\1\s*,\s*(.+?)\s*\)\s*;\s*(?:(?:\/\/|#)\s*(.*))?$/u'; $reSection = '/^\s*\/\/\s*@section\s*:\s*(.+)\s*$/iu'; $reHR = '/^\s*\/\/\s*@hr\s*$/iu'; $reNote = '/^\s*\/\/\s*@note\s*:\s*(.+)\s*$/iu'; foreach ($lines as $ln) { // Meta-Kommentare zuerst prüfen (UI-Struktur) if (preg_match($reSection, $ln, $m)) { $ui[] = ['kind' => 'section', 'title' => trim($m[1])]; continue; } if (preg_match($reHR, $ln)) { $ui[] = ['kind' => 'hr']; continue; } if (preg_match($reNote, $ln, $m)) { $ui[] = ['kind' => 'note', 'text' => trim($m[1])]; continue; } // define(…) Zeilen if (!preg_match($reDefine, $ln, $m)) { continue; } $name = $m[2]; $rawValueExpr = trim($m[3]); $inlineC = isset($m[4]) ? trim($m[4]) : ''; // Typ bestimmen $type = 'string'; $valForForm = ''; $raw = rtrim($rawValueExpr, ','); if (preg_match('/^(true|false)$/i', $raw)) { $type = 'bool'; $valForForm = (strtolower($raw) === 'true'); } elseif (preg_match('/^[+-]?\d+$/', $raw)) { $type = 'int'; $valForForm = (int)$raw; } elseif (preg_match('/^([\'"])(.*)\1$/s', $raw, $mm)) { $type = 'string'; $valForForm = stripcslashes($mm[2]); } else { $type = 'string'; $valForForm = $raw; } $defines[$name] = [ 'name' => $name, 'type' => $type, 'value' => $valForForm, 'raw' => $rawValueExpr, 'comment' => $inlineC, 'line' => $ln, ]; $order[] = $name; // Wichtig: define auch in die UI-Reihenfolge aufnehmen $ui[] = ['kind' => 'define', 'name' => $name]; } return ['defines' => $defines, 'order' => $order, 'ui' => $ui]; } function php_export_define_value(string $type, $value): string { // Baut den rechten Teil von define('X', ); if ($type === 'bool') { return $value ? 'true' : 'false'; } if ($type === 'int') { return (string)intval($value); } // String: // einfache Quotes nehmen und escapen $escaped = str_replace("'", "\\'", (string)$value); return "'" . $escaped . "'"; } function h(?string $s): string { return htmlspecialchars((string)$s ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } // ---- Dateien parsen ---- $example = parse_define_file($EXAMPLE_FILE); $current = parse_define_file($CONFIG_FILE); // Keys klassifizieren $exampleKeys = array_keys($example['defines']); $currentKeys = array_keys($current['defines']); $deprecatedKeys = array_values(array_diff($currentKeys, $exampleKeys)); // nur in config.php $newKeys = array_values(array_diff($exampleKeys, $currentKeys)); // nur in example (neu) $sharedKeys = array_values(array_intersect($exampleKeys, $currentKeys)); // Beim Rendern: Reihenfolge aus example beibehalten $renderKeys = $example['order']; // ---- POST: Speichern ---- $message = ''; $err = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['__save_config']) && isset($_POST['cfg']) && is_array($_POST['cfg'])) { $incoming = $_POST['cfg']; // ['NAME' => valueString/checkbox etc.] // Build neuer config.php Inhalt: $out = []; $out[] = ""; $content = implode("\n", $out) . "\n"; try { if (false === file_put_contents($CONFIG_FILE, $content)) { $err = "Konnte config.php nicht schreiben: " . h($CONFIG_FILE); } else { $message = "Konfiguration gespeichert."; // Nach dem Speichern neu parsen, damit UI aktuell ist $current = parse_define_file($CONFIG_FILE); $currentKeys = array_keys($current['defines']); $deprecatedKeys = array_values(array_diff($currentKeys, $exampleKeys)); $sharedKeys = array_values(array_intersect($exampleKeys, $currentKeys)); } } catch (Throwable $e) { $err = "Fehler beim Schreiben: " . h($e->getMessage()); } } // ---- Werte für Formular vorbereiten ---- // Für jeden example-Key: Formularwert = aus aktueller config (falls vorhanden), sonst example default function valueForForm(array $example, array $current, string $key) { $ex = $example['defines'][$key] ?? null; $cu = $current['defines'][$key] ?? null; $type = $ex ? $ex['type'] : ($cu ? $cu['type'] : 'string'); $comment = $ex && $ex['comment'] !== '' ? $ex['comment'] : ($cu['comment'] ?? ''); if ($cu) { $val = $cu['value']; } else { $val = $ex['value']; } return [$type, $val, $comment]; } ?> Konfiguration – Epi Webview

Konfiguration

Einstellungen ( Source: )
'.h($item['title']).''; continue; } if ($item['kind'] === 'hr') { echo '
'; continue; } if ($item['kind'] === 'note') { echo '

'.h($item['text']).'

'; continue; } if ($item['kind'] !== 'define') { continue; } $key = $item['name']; // Nur Keys rendern, die in example vorkommen if (!isset($example['defines'][$key])) continue; [$type, $val, $tooltip] = valueForForm($example, $current, $key); ?>
/>

Veraltete Parameter (nur in , nicht mehr in )
Dieser Parameter ist in der aktuellen Version nicht mehr vorgesehen.
Speichert nach