diff --git a/Readme-Abschnitts-Vorlagen-Editor.md b/Readme-Abschnitts-Vorlagen-Editor.md new file mode 100644 index 000000000..84371473a --- /dev/null +++ b/Readme-Abschnitts-Vorlagen-Editor.md @@ -0,0 +1,412 @@ +# Inline-Editor für Abschnitts-Vorlagen (ACE) + +Stand: 2026-11-29 · Eigene, nicht in den phpwcms-Kern eingecheckte Backend-Erweiterung. + +## Zweck + +Die Datei-Vorlagen eines Inhaltsabschnitts, einer Artikel-Vorlage (Listing/Detail) oder eines +Modul-Content-Parts (Glossar, Shop) lassen sich direkt im Backend bearbeiten, anlegen, +duplizieren und löschen – mit dem im System bereits vorhandenen ACE-Editor. Ein Download per +FTP, lokales Bearbeiten und erneutes Hochladen ist dafür nicht mehr nötig. + +## Funktionen + +Unterhalb des jeweiligen „Vorlage"-Dropdowns stehen vier Links (nur für Backend-Admins sichtbar, +`$_SESSION["wcs_user_admin"]`): + +1. **„ausgewählte Vorlage bearbeiten"** + Lädt den Code der aktuell im Dropdown gewählten Datei per Fetch/AJAX in eine ACE-Editor-Zeile + direkt unter dem Dropdown. Gespeichert wird über die normalen Formular-Buttons: *Aktualisieren* + speichert und hält den Editor offen (mit dem gespeicherten Inhalt neu befüllt), *Sichern* + speichert und schließt die Bearbeitung. Wechselt man die Vorlage im Dropdown, lädt der Editor + automatisch den Code der neuen Auswahl nach; bei „Standard" schließt er sich. Ein eigener + „Editor schließen"-Link im Hinweisbanner schließt ihn jederzeit ohne zu speichern. Ist + „Standard" gewählt, zeigt der Link einen Hinweis, dass dafür zuerst ein Duplikat erstellt + werden muss. Die Editor-Höhe ist per Maus frei ziehbar (`resize: vertical`, ab 320px, minimal + 120px, ohne Maximalhöhe). + +2. **„Vorlage erstellen"** + Fragt über das Eingabe-Modal `bsPrompt()` nach einem Namen und legt eine leere Datei mit der + Standard-Endung im Vorlagen-Verzeichnis des jeweiligen Typs an. Nach Erfolg wird die neue Datei + automatisch ins Dropdown eingefügt, ausgewählt und im Editor geöffnet. + +3. **„Vorlage duplizieren"** + Fragt über `bsPrompt()` nach einem Namen für die Kopie (Vorschlag: `-kopie`). Funktioniert + auch für „Standard": dafür wird die passende Datei aus `template/inc_default/` bzw. die + modul-/typspezifische Standarddatei als Quelle verwendet (sofern vorhanden, siehe Tabelle + unten). Bricht mit Fehlermeldung ab, falls der Zielname bereits existiert. + +4. **„Vorlage löschen"** + Prüft bei Typen mit zuverlässiger Verwendungsprüfung zuerst über die Aktion `cntusage`, ob die + Vorlage noch verwendet wird, und zeigt dann entweder die Liste der Fundstellen (Artikeltitel + als Link + Abschnitts-ID) oder die normale Löschbestätigung. Bei Typen ohne zuverlässige + Prüfung (siehe Tabelle) erscheint stattdessen direkt ein Warnhinweis, dass die Verwendung nicht + automatisch geprüft werden kann. „Standard" kann nicht gelöscht werden. Die serverseitige + Löschaktion (`cntdelete`) prüft bei den Typen mit zuverlässiger Prüfung zusätzlich unmittelbar + vor dem `unlink()` erneut, ob die Vorlage inzwischen anderswo in Verwendung genommen wurde. + +### Eingabe-Modal `bsPrompt()` + +`bsPrompt(type, message, defaultValue, callback, …)` in `include/inc_js/phpwcms.js` ist das +Pendant zu `bsConfirm()`/`bsAlert()` für Texteingaben: gleiches Bootstrap-Modal, gleiches +Icon-/Farbschema je `type`, zusätzlich ein Textfeld (Enter bestätigt, Autofokus beim Öffnen). +`bsAlert()` hat einen dritten Parameter `rawHtml`: ist er `true`, wird die übergebene Nachricht +unverändert als HTML eingefügt (für die Verwendungsliste beim Löschen), sonst wie gewohnt als +Text escaped. + +## Unterstützte Vorlagen-Typen + +| Typ-ID | Bezeichnung | Verzeichnis | Dropdown-Feld | Verwendungsprüfung | +|---|---|---|---|---| +| 0 | Einfacher Text | `plaintext` | `template` | zuverlässig | +| 1 | Bild + Text | `imagetext` | `template` | zuverlässig | +| 2 | Bilder | `imagetable` | `template` | zuverlässig | +| 3 | Link per E-Mail | `linkemail` | `template` | zuverlässig | +| 4 | Aufzählung | `bulletlist` | `template` | zuverlässig | +| 5 | Linkliste | `linklist` | `template` | zuverlässig | +| 6 | HTML | `html` | `template` | zuverlässig | +| 7 | Dateiliste | `filelist` | `cfile_template` | zuverlässig | +| 8 | Teaser/Artikellink | `teaser` | `calink_template` | nicht zuverlässig | +| 9 | Multimedia | `multimedia` | `template` | zuverlässig | +| 11 | Code | `code` | `template` | zuverlässig | +| 13 | Suche | `search` | `template` | zuverlässig | +| 14 | WYSIWYG HTML | `wysiwyg` | `template` | zuverlässig | +| 18 | Gästebuch/Kommentar | `guestbook` | `cguestbook_template` | nicht zuverlässig | +| 22 | RSS Feed | `rssfeed` | `crss_template` | nicht zuverlässig | +| 25 | Flash-/Mediaplayer | `flashplayer` | `fmp_template` | zuverlässig | +| 26 | Kochrezept | `recipe` | `recipe_template` | nicht zuverlässig | +| 27 | FAQ | `faq` | `faq_template` | nicht zuverlässig | +| 28 | Frontend-Login | `felogin` | `template` | zuverlässig | +| 29 | Bilder `
` | `images` | `template` | zuverlässig | +| 31 | Bilder speziell | `imagespecial` | `template` | zuverlässig | +| 32 | Register (Tabs) | `tabs` | `template` | zuverlässig | +| 33 | News | `news` | `template` | zuverlässig | +| 50 | Bilderwechsel | `reference` | `creference_tmpl` | nicht zuverlässig | +| 51 | Karte | `map` | `cmap_template` | nicht zuverlässig | +| 60 | Custom Content-Part | `custom` bzw. `custom/` | `template` (geteilt) | zuverlässig | +| 30 | Plug-in: Glossar | `module/glossary` | `glossary_template` | nicht zuverlässig | +| 30 | Plug-in: Shop Produkte | `module/shop` | `shop_template` | nicht zuverlässig | + +Zusätzlich, unabhängig von einzelnen Inhaltsabschnitten: die Artikel-Vorlagen „Listing" +(`article_tmpllist`, Verzeichnis `inc_cntpart/articlesummary/list/`) und „Detail" +(`article_tmplfull`, Verzeichnis `inc_cntpart/articlesummary/article/`), bearbeitbar im Reiter +„Artikeleigenschaften". Beide teilen sich einen gemeinsamen Editor (siehe Architektur unten); +Verwendungsprüfung ebenfalls nicht zuverlässig möglich. + +„Standard" (keine Datei ausgewählt) kann bei keinem Typ gelöscht werden. Für „Vorlage +duplizieren" im „Standard"-Fall gibt es nicht bei jedem Typ eine feste Quelldatei: ohne +passende `inc_default/*.tmpl`-Datei (`linkemail`, `felogin`, `recipe`, `faq`, `map`) bzw. ohne +feste Standarddatei im Modul (Shop) meldet die Aktion `source_missing`. Glossar hat eine feste +Standarddatei (`template/default/default.tmpl` im Modul-Verzeichnis). + +## Architektur + +Die komplette UI (4 Links + ACE-Editor-Zeile + Lade-/Erstell-/Duplizier-/Lösch-/ +Verwendungsprüfungs-Logik) liegt in drei parametrisierten, gemeinsam genutzten Funktionen in +`include/inc_lib/general.inc.php`: + +- `render_cnt_template_editor_links($dir, $usage_reliable, $field_id, $default_value, $label, $wrapper_class)` + – die 4 Links. `$usage_reliable = false` markiert Typen ohne automatische Verwendungsprüfung + (Warnhinweis statt `cntusage`-Check beim Löschen). +- `render_cnt_template_editor_panel($dir, $current_file, $field_id, $split, $default_value, $label, $extra_targets)` + – die ACE-Editor-Zeile samt JS. `$split = true` für Typ 60 (Dropdown-Wert enthält + `/`). `$extra_targets` erlaubt mehrere Vorlagen-Ziele auf einen gemeinsamen + Editor zu lenken (genutzt von den beiden Artikel-Vorlagen). +- `cnt_template_editor_save($dir, $post_field, $split, $default_value, $extra_targets)` – + speichert den bearbeiteten Inhalt zurück in die Datei; liest den POST-Wert eigenständig, + unabhängig davon, wie der jeweilige Typ den Vorlagennamen sonst in `$content` ablegt. + +Das Verdrahten im JavaScript läuft über Daten-Attribute (`data-tmpl-dir`, `data-tmpl-field-id`, +`data-tmpl-default-value`, `data-tmpl-label`, `data-usage-reliable`) und +`document.querySelectorAll('[data-tmpl-group]')` – jede Link-Gruppe bindet sich selbst an den +zugehörigen Editor. + +**Typ 60 (Custom Content-Part):** Die 4 Links hängen direkt am vorhandenen „Vorlage"-Feld. Der +Dropdown-Wert kodiert bei einem Unterverzeichnis-Treffer `/`. `cnt_tmpl_split_value()` +zerlegt diesen Wert serverseitig (und `splitDirFile()` im JS clientseitig) in Verzeichnis + +reinen Dateinamen, bevor der Dateiname durch `sanitize_template_name()` läuft (die keine +Schrägstriche zulässt). `cnt_tmpl_custom_dir_valid()`/`cnt_tmpl_custom_match_value()` validieren +das dynamische `custom/`-Verzeichnis. „Vorlage erstellen" legt neue Dateien immer im +gemeinsamen `inc_cntpart/custom/`-Wurzelverzeichnis an; Bearbeiten/Duplizieren/Löschen folgen dem +Verzeichnis der aktuell gewählten Datei. + +**Modul-Content-Parts (Glossar, Shop):** Beide sind Typ 30, unterschieden über die Spalte +`acontent_module`; ihr gewählter Vorlagenname steckt im serialisierten `acontent_form`-Feld, nicht +in `acontent_template` (daher keine zuverlässige Verwendungsprüfung möglich, wie bei den anderen +so markierten Typen). Ihre Vorlagen liegen nicht unter `template/inc_cntpart//`, sondern im +jeweiligen Modul-Ordner selbst (`include/inc_module/mod_glossary/template/`, +`include/inc_module/mod_shop/template/`). `cnt_tmpl_module_base($dir)` löst `module/glossary`/ +`module/shop` auf den jeweiligen Modul-Ordner auf – unabhängig von `$phpwcms['modules']`, da der +schlanke AJAX-Bootstrap in `ajax_template.php` die Modul-Registrierung (`modules.check.inc.php`) +nicht lädt. `cnt_tmpl_module_default_src($dir)` liefert die „Standard"-Quelldatei beim +Duplizieren (nur für Glossar vorhanden). + +**Artikel-Vorlagen (Listing/Detail):** Teilen sich einen Editor statt zweier gleichzeitiger +Instanzen. Welche der beiden gerade offen ist, zeigt eine Beschriftung im Hinweisbanner neben dem +Dateinamen. Wechselt man das Dropdown der gerade *nicht* offenen Vorlage, bleibt der Editor +unverändert. „Standard" ist hier kein leerer Wert, sondern der Options-Wert `"default"`. Das +„Editor bleibt nach Aktualisieren offen"-Verhalten merkt sich zusätzlich, welche der beiden +Vorlagen offen war (`tmpl_edit_field`-Parameter, befüllt aus dem Feld +`cnt_template_active_field`). + +## Sicherheitsmodell + +- Alle Aktionen in `ajax_template.php` prüfen `$_SESSION["wcs_user_admin"]`. +- Verzeichnis-Whitelist je Aktion statt freiem Pfad – kein beliebiges Verzeichnis ansprechbar. +- Dateinamen laufen durch `sanitize_template_name()` (verhindert Pfad-Traversal). +- Zusätzliche Pfad-Containment-Prüfung über `path_is_within()`. +- `cntduplicate` erlaubt für „Standard" nur fest einprogrammierte Quellen + (`$cnt_tmpl_default_src` bzw. `cnt_tmpl_module_default_src()`) – kein benutzergesteuerter Pfad. +- Lese-/Schreib-/Löschaktionen laufen über GET + `csrftoken`. +- `cntusage` liest nur, schreibt/löscht nichts – reine Information für die UI. +- Löschen prüft client- und serverseitig auf aktive Referenzen (bei Typen mit zuverlässiger + Prüfung); bei den übrigen Typen übernimmt ein Warnhinweis mit manueller Bestätigung diese + Rolle anstelle der automatischen Prüfung. + +## Bekannte Einschränkungen + +- Löschen ist endgültig – kein Papierkorb/Undo für gelöschte Vorlagendateien. +- Keine Versionierung/History der Vorlagen-Änderungen; „Duplizieren" ist die einzige Absicherung + gegen Datenverlust. +- Bei Typen ohne zuverlässige Verwendungsprüfung (siehe Tabelle) verhindert das System das + Löschen einer noch verwendeten Vorlage nicht automatisch – das liegt beim Warnhinweis in der + Verantwortung des Admins. +- `include/inc_js/phpwcms.min.js` muss nach Änderungen an `phpwcms.js` manuell neu gebaut werden + (`npm run build:js`); es gibt keinen automatischen Rebuild-Schritt. +- Verlässt man den ACE-Editor-Vollbildmodus nach manueller Höhenanpassung, fällt die Höhe auf + automatisches Mitwachsen zurück statt die gezogene Höhe zu behalten. +- Die Wechselwirkung mit Custom Fields (`cnt_fieldgroup_templates`) bei gleichzeitig zugeordneten + Feldgruppen ist nicht gesondert geprüft. +- Die Übersetzungen der `be_cnt_template_*`-Sprachschlüssel außerhalb von Deutsch und Englisch + sind maschinell erstellt und nicht von Muttersprachlern geprüft. +- Es existiert für diese Erweiterung kein automatischer Mechanismus für künftige, selbst + hinzugefügte Module – jedes weitere Modul braucht denselben manuellen Eintrag wie Glossar/Shop + (Modul-Key in `cnt_tmpl_module_base()`, Dir-String in den Whitelists von `ajax_template.php`, + zwei Zeilen in dessen `cnt.form.php`/`cnt.post.php`). + +## Geänderte / neue Dateien + +| Datei | Beschreibung | +|---|---| +| `include/inc_act/ajax_template.php` | AJAX-Endpunkt mit den Aktionen `cntform` (laden), `cntduplicate` (duplizieren, inkl. „Standard"-Quelle), `cntcreate` (neue leere Vorlage), `cntusage` (Verwendungs-Check), `cntdelete` (löschen); Verzeichnis-Whitelists je Aktion. | +| `include/inc_lib/general.inc.php` | Gemeinsame Helper-Funktionen: `render_cnt_template_editor_links()`, `render_cnt_template_editor_panel()`, `cnt_template_editor_save()`, `cnt_tmpl_custom_dir_valid()`, `cnt_tmpl_custom_match_value()`, `cnt_tmpl_split_value()`, `cnt_tmpl_module_base()`, `cnt_tmpl_module_default_src()`. | +| `include/inc_tmpl/content/cnt{0,1,2,3,4,5,6,7,8,9,11,13,14,18,22,25,26,27,28,29,31,32,33,50,51,60}.inc.php` | Je ein Aufruf von `render_cnt_template_editor_links()` + `render_cnt_template_editor_panel()` am „Vorlage"-Dropdown des jeweiligen Abschnittstyps. | +| `include/inc_lib/content/cnt{0,1,2,3,4,5,6,7,8,9,11,13,14,18,22,25,26,27,28,29,31,32,33,50,51,60}.readform.inc.php` | Je ein Aufruf von `cnt_template_editor_save()` beim Speichern des jeweiligen Abschnitts. | +| `include/inc_module/mod_glossary/inc/cnt.form.php` | Editor-Links + Panel am `glossary_template`-Dropdown (`module/glossary`). | +| `include/inc_module/mod_glossary/inc/cnt.post.php` | Aufruf von `cnt_template_editor_save('module/glossary', 'glossary_template')`. | +| `include/inc_module/mod_shop/inc/cnt.form.php` | Editor-Links + Panel am `shop_template`-Dropdown (`module/shop`). | +| `include/inc_module/mod_shop/inc/cnt.post.php` | Aufruf von `cnt_template_editor_save('module/shop', 'shop_template')`. | +| `include/inc_tmpl/article.editsummary.tmpl.php` | Editor-Links an beiden Artikel-Vorlagen-Dropdowns (`article_tmpllist`/`article_tmplfull`) plus ein gemeinsames Panel für beide (`$extra_targets`). | +| `include/inc_lib/article.editcontent.inc.php` | Aufruf von `cnt_template_editor_save()` für die Artikel-Vorlagen; Redirect-Parameter `tmpl_edit`/`tmpl_edit_field`, damit der Editor nach „Aktualisieren" (Abschnitt oder Artikel-Vorlage) geöffnet bleibt. | +| `include/inc_js/phpwcms.js` | Neue Funktion `bsPrompt()` (Eingabe-Modal im Stil von `bsConfirm()`); `bsAlert()` um Parameter `rawHtml` erweitert. | +| `include/inc_js/phpwcms.min.js` | Aus `phpwcms.js` gebaute, vom Backend tatsächlich geladene Datei. | +| `include/inc_lang/backend/*/lang.inc.php` (alle 47 Sprachen) | Sprachschlüssel `be_cnt_template_*` (siehe unten). | + +Sprachschlüssel (in allen 47 Backend-Sprachen vorhanden): `be_cnt_template_edit`, +`be_cnt_template_create`, `be_cnt_template_duplicate`, `be_cnt_template_delete`, +`be_cnt_template_edit_hint`, `be_cnt_template_edit_close`, `be_cnt_template_edit_none`, +`be_cnt_template_edit_error`, `be_cnt_template_edit_standard`, `be_cnt_template_create_prompt`, +`be_cnt_template_create_error`, `be_cnt_template_duplicate_prompt`, +`be_cnt_template_duplicate_error`, `be_cnt_template_duplicate_exists`, +`be_cnt_template_duplicate_invalid`, `be_cnt_template_delete_confirm`, +`be_cnt_template_delete_confirm_unverified`, `be_cnt_template_delete_error`, +`be_cnt_template_delete_inuse`, `be_cnt_template_delete_inuse_section`, +`be_cnt_template_delete_standard`. + +Das CSS für die Editor-Größenänderung liegt als `' . LF; + } + ?> + +/g, '>').replace(/"/g, '"'); + } + function notify(msg, raw) { + if (typeof bsAlert === 'function') { bsAlert(msg, null, raw); } else { window.alert(String(msg).replace(/<[^>]+>/g, '')); } + } + function api(query) { + return cfg.ajaxUrl + '?' + query + '&' + cfg.token; + } + function getJson(query) { + return fetch(api(query), { credentials: 'same-origin' }).then(function (r) { return r.json(); }); + } + function byField(id) { + for (var i = 0; i < cfg.targets.length; i++) { + if (cfg.targets[i].fieldId === id) { return cfg.targets[i]; } + } + return null; + } + function getSelect(tg) { return document.getElementById(tg.fieldId); } + + // current dropdown value -> directory / bare file / value prefix. + // Type 60 ("split") stores "/" for a per-CPT subfolder. + function resolve(tg) { + var sel = getSelect(tg); + var value = sel ? sel.value : (tg.currentFile || ''); + if (value === tg.defaultValue) { value = ''; } + var dir = tg.dir, file = value, prefix = ''; + if (tg.split && value.indexOf('/') > 0) { + var i = value.indexOf('/'); + prefix = value.substring(0, i + 1); + dir = tg.dir + '/' + value.substring(0, i); + file = value.substring(i + 1); + } + return { dir: dir, file: file, value: value, prefix: prefix }; + } + + function ensureEditor() { + if (ta._aceEditor) { return ta._aceEditor; } + if (!window.ace || typeof initAceForTextarea !== 'function') { return null; } + initAceForTextarea(ta); + var ed = ta._aceEditor; + if (ed) { + // fixed, user-resizable height instead of auto-grow (only this instance) + ed.setOptions({ minLines: null, maxLines: null }); + } + return ed || null; + } + + function openPanel(tg, content, filename) { + active = tg; + wrap.style.display = ''; + ta.disabled = false; + fldOpen.value = '1'; + fldActive.value = tg.fieldId; + fldFile.value = resolve(tg).value; + var label = cfg.multi ? (tg.label || '') : ''; + if (label && label.slice(-1) !== ':') { label += ':'; } + labelEl.textContent = label; + fileEl.textContent = filename; + var ed = ensureEditor(); + if (ed) { + ed.setValue(content, -1); + ed.resize(); + } else { + ta.value = content; + } + } + + function closePanel() { + active = null; + wrap.style.display = 'none'; + ta.disabled = true; + fldOpen.value = '0'; + fldActive.value = ''; + fldFile.value = ''; + } + + function loadAndOpen(tg) { + var r = resolve(tg); + if (r.file === '') { + notify(t(getSelect(tg) ? 'edit_standard' : 'edit_none')); + return; + } + fetch(api('action=cntform&dir=' + enc(r.dir) + '&file=' + enc(r.file)), { credentials: 'same-origin' }) + .then(function (res) { + if (!res.ok) { throw new Error('http'); } + return res.text(); + }) + .then(function (txt) { + if (txt === 'Sorry, access forbidden') { throw new Error('forbidden'); } + openPanel(tg, txt, r.file); + }) + .catch(function () { notify(t('edit_error')); }); + } + + function selectValue(tg, value, text) { + var sel = getSelect(tg); + if (!sel) { return; } + var found = false; + for (var i = 0; i < sel.options.length; i++) { + if (sel.options[i].value === value) { found = true; break; } + } + if (!found) { + var opt = document.createElement('option'); + opt.value = value; + opt.textContent = text; + sel.appendChild(opt); + } + sel.value = value; + } + + function removeValue(tg, value) { + var sel = getSelect(tg); + if (!sel) { return; } + for (var i = sel.options.length - 1; i >= 0; i--) { + if (sel.options[i].value === value) { sel.remove(i); } + } + sel.value = tg.defaultValue; + } + + function nameError(err, fallbackKey) { + if (err === 'exists') { return t('duplicate_exists'); } + if (err === 'invalid_name') { return t('duplicate_invalid'); } + return t(fallbackKey); + } + + function doCreate(tg) { + if (typeof bsPrompt !== 'function') { return; } + bsPrompt('info', t('create_prompt'), '', function (name) { + name = (name || '').trim(); + if (name === '') { return; } + getJson('action=cntcreate&dir=' + enc(tg.dir) + '&newname=' + enc(name)) + .then(function (j) { + if (j && j.success) { + selectValue(tg, j.file, j.file); + loadAndOpen(tg); + } else { + notify(nameError(j && j.error, 'create_error')); + } + }) + .catch(function () { notify(t('create_error')); }); + }); + } + + function doDuplicate(tg) { + if (typeof bsPrompt !== 'function') { return; } + var r = resolve(tg); + var base = r.file ? r.file.replace(/\.[^.]*$/, '') : 'standard'; + bsPrompt('info', t('duplicate_prompt'), base + '-kopie', function (name) { + name = (name || '').trim(); + if (name === '') { return; } + getJson('action=cntduplicate&dir=' + enc(r.dir) + '&file=' + enc(r.file) + '&newname=' + enc(name)) + .then(function (j) { + if (j && j.success) { + selectValue(tg, r.prefix + j.file, j.file); + loadAndOpen(tg); + } else { + notify(nameError(j && j.error, 'duplicate_error')); + } + }) + .catch(function () { notify(t('duplicate_error')); }); + }); + } + + // the actual deletion - shared by both confirmation paths + function doTemplateDelete(tg, r) { + getJson('action=cntdelete&dir=' + enc(r.dir) + '&file=' + enc(r.file)) + .then(function (j) { + if (j && j.success) { + removeValue(tg, r.value); + if (active === tg) { closePanel(); } + } else if (j && j.error === 'in_use') { + notify(t('delete_inuse')); + } else { + notify(t('delete_error')); + } + }) + .catch(function () { notify(t('delete_error')); }); + } + + function doDelete(tg, usageReliable) { + var r = resolve(tg); + if (r.file === '') { + notify(t('delete_standard')); + return; + } + if (!usageReliable) { + // usage can't be checked automatically for this type: warn instead + if (typeof bsConfirmWarning === 'function') { + bsConfirmWarning(t('delete_confirm_unverified'), function () { doTemplateDelete(tg, r); }); + } else if (window.confirm(t('delete_confirm_unverified'))) { + doTemplateDelete(tg, r); + } + return; + } + getJson('action=cntusage&dir=' + enc(r.dir) + '&file=' + enc(r.file)) + .then(function (j) { + if (!j || !j.success) { throw new Error('usage'); } + if (j.count > 0) { + var html = esc(t('delete_inuse')) + '
    '; + (j.items || []).forEach(function (it) { + html += '
  • ' + esc(it.article_title) + '' + + ' (' + esc(t('delete_inuse_section')) + ' ' + esc(it.acontent_id) + ')
  • '; + }); + html += '
'; + notify(html, true); + } else if (typeof bsConfirmDanger === 'function') { + bsConfirmDanger(t('delete_confirm').replace('%s', r.file), function () { doTemplateDelete(tg, r); }); + } else if (window.confirm(t('delete_confirm').replace('%s', r.file))) { + doTemplateDelete(tg, r); + } + }) + .catch(function () { notify(t('delete_error')); }); + } + + // wire up every link group (there can be several per page, one panel) + document.querySelectorAll('[data-tmpl-group]').forEach(function (group) { + var tg = byField(group.getAttribute('data-tmpl-field-id')); + if (!tg) { return; } + var reliable = group.getAttribute('data-usage-reliable') !== '0'; + group.querySelectorAll('[data-tmpl-action]').forEach(function (a) { + a.addEventListener('click', function (e) { + e.preventDefault(); + var action = a.getAttribute('data-tmpl-action'); + if (action === 'edit') { loadAndOpen(tg); } + else if (action === 'create') { doCreate(tg); } + else if (action === 'duplicate') { doDuplicate(tg); } + else if (action === 'delete') { doDelete(tg, reliable); } + }); + }); + }); + + // switching the dropdown of the target that is currently open reloads the + // editor ("Standard" closes it); the other targets' dropdowns don't touch it + cfg.targets.forEach(function (tg) { + var sel = getSelect(tg); + if (!sel) { return; } + sel.addEventListener('change', function () { + if (active !== tg) { return; } + if (resolve(tg).file === '') { closePanel(); } else { loadAndOpen(tg); } + }); + }); + + if (closeLink) { + closeLink.addEventListener('click', function (e) { + e.preventDefault(); + closePanel(); + }); + } + + if (cfg.autoOpen) { + window.addEventListener('load', function () { + var tg = byField(cfg.autoOpenField) || cfg.targets[0]; + if (tg && resolve(tg).file !== '') { loadAndOpen(tg); } + }); + } +})(); +JSEOF; + + echo '' . LF; +} + +/** + * Write the template source edited in the inline editor back to its file. + * Call from the matching *.readform.inc.php right after the template name + * is read from $_POST. Re-reads $_POST[$post_field] itself (the type may + * keep the name in a nested/serialized $content array). A no-op unless the + * editor was open, the active target is this one, "Standard" isn't selected + * and the dropdown still names the file that was loaded into the editor. + * + * @param string $dir template directory below inc_cntpart/ + * @param string $post_field $_POST name of the template dropdown + * @param bool $split true for Type 60's "/" values + * @param string $default_value the dropdown's "Standard" value + * @param array $extra_targets more targets sharing the editor, each: + * ['dir','post_field','split','default_value'] + * + * @return bool true if a file was written + */ +function cnt_template_editor_save($dir, $post_field = 'template', $split = false, $default_value = '', $extra_targets = array()) { + if (empty($_SESSION['wcs_user_admin']) + || empty($_POST['cnt_template_editor_open']) + || !isset($_POST['cnt_template_editor_content'])) { + return false; + } + + $targets = array(array( + 'dir' => (string) $dir, + 'post_field' => (string) $post_field, + 'split' => (bool) $split, + 'default_value' => (string) $default_value, + )); + foreach ((array) $extra_targets as $extra) { + $targets[] = array( + 'dir' => (string) ($extra['dir'] ?? ''), + 'post_field' => (string) ($extra['post_field'] ?? ''), + 'split' => !empty($extra['split']), + 'default_value' => (string) ($extra['default_value'] ?? ''), + ); + } + + $target = null; + if (count($targets) === 1) { + $target = $targets[0]; + } else { + $active = isset($_POST['cnt_template_active_field']) ? (string) $_POST['cnt_template_active_field'] : ''; + foreach ($targets as $candidate) { + if ($candidate['post_field'] === $active) { + $target = $candidate; + break; + } + } + } + if ($target === null) { + return false; + } + + $value = isset($_POST[$target['post_field']]) ? (string) $_POST[$target['post_field']] : ''; + if ($value === '' || $value === $target['default_value']) { + return false; + } + + // the dropdown must still name the file that was loaded into the editor + if (!isset($_POST['cnt_template_editor_file']) || (string) $_POST['cnt_template_editor_file'] !== $value) { + return false; + } + + if ($target['split']) { + $parts = cnt_tmpl_split_value($target['dir'], $value); + $tmpl_dir = $parts['dir']; + $file = $parts['file']; + } else { + $tmpl_dir = $target['dir']; + $file = sanitize_template_name($value); + } + if ($file === '') { + return false; + } + + $base = cnt_tmpl_module_base($tmpl_dir) ?? (PHPWCMS_TEMPLATE . 'inc_cntpart/' . $tmpl_dir); + $full = $base . '/' . $file; + if (!path_is_within($full, $base) || !is_file($full)) { + return false; + } + + // browsers submit textareas with CRLF: keep the file's own line ending style + $content = str_replace(array("\r\n", "\r"), "\n", (string) $_POST['cnt_template_editor_content']); + $current = read_textfile($full); + if (is_string($current) && strpos($current, "\r\n") !== false) { + $content = str_replace("\n", "\r\n", $content); + } + if ($current === $content) { + return false; + } + + return write_textfile($full, $content); +} + function saveUploadedFile($file, $target, $exttype = '', $imgtype = '', $rename = 0, $maxsize = 0) { // imgtype can be all exif_imagetype supported by your PHP install // see http://www.php.net/exif_imagetype diff --git a/include/inc_module/mod_glossary/inc/cnt.form.php b/include/inc_module/mod_glossary/inc/cnt.form.php index 96d78847b..5a27fe3f1 100644 --- a/include/inc_module/mod_glossary/inc/cnt.form.php +++ b/include/inc_module/mod_glossary/inc/cnt.form.php @@ -59,8 +59,12 @@ ?>
+ + + +
diff --git a/include/inc_module/mod_glossary/inc/cnt.post.php b/include/inc_module/mod_glossary/inc/cnt.post.php index 1dfdddc0d..75f1dd0d5 100644 --- a/include/inc_module/mod_glossary/inc/cnt.post.php +++ b/include/inc_module/mod_glossary/inc/cnt.post.php @@ -27,6 +27,7 @@ ) !== '') { $content['glossary']['glossary_template'] = $glossary_template; } +cnt_template_editor_save('module/glossary', 'glossary_template'); $content['glossary']['glossary_filter'] = clean_slweg($_POST['glossary_filter']); $content['glossary']['glossary_maxwords'] = intval($_POST['glossary_maxwords']); if(empty($content['glossary']['glossary_maxwords'])) { diff --git a/include/inc_module/mod_shop/inc/cnt.form.php b/include/inc_module/mod_shop/inc/cnt.form.php index 1504712aa..e552a9cb3 100644 --- a/include/inc_module/mod_shop/inc/cnt.form.php +++ b/include/inc_module/mod_shop/inc/cnt.form.php @@ -80,8 +80,12 @@ ?>
+ +
+ +
diff --git a/include/inc_module/mod_shop/inc/cnt.post.php b/include/inc_module/mod_shop/inc/cnt.post.php index 0b60c88d4..d4bf1b553 100644 --- a/include/inc_module/mod_shop/inc/cnt.post.php +++ b/include/inc_module/mod_shop/inc/cnt.post.php @@ -23,6 +23,7 @@ $content['shop']['shop_action'] = clean_slweg($_POST['shop_action'] ?? ''); $content['shop']['shop_category'] = abs(intval($_POST['shop_category'] ?? 0)); $content['shop']['shop_template'] = sanitize_template_name(clean_slweg($_POST['shop_template'] ?? '')); +cnt_template_editor_save('module/shop', 'shop_template'); $content['shop']['shop_config'] = slweg($_POST['shop_config'] ?? ''); $content['shop']['options'] = array(); diff --git a/include/inc_tmpl/article.editsummary.tmpl.php b/include/inc_tmpl/article.editsummary.tmpl.php index cb6206e70..3bf9d7567 100644 --- a/include/inc_tmpl/article.editsummary.tmpl.php +++ b/include/inc_tmpl/article.editsummary.tmpl.php @@ -694,6 +694,36 @@
+
+
+
+ +
+
+ +
+
+ + 'articlesummary/article', + 'field_id' => 'article_tmplfull', + 'current_file' => $article['image']['tmplfull'] ?? '', + 'default_value' => 'default', + 'label' => $BL['be_article_forfull'], + ), + ) +); +?> +
diff --git a/include/inc_tmpl/content/cnt0.inc.php b/include/inc_tmpl/content/cnt0.inc.php index 961a17f40..68279484c 100644 --- a/include/inc_tmpl/content/cnt0.inc.php +++ b/include/inc_tmpl/content/cnt0.inc.php @@ -44,8 +44,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt1.inc.php b/include/inc_tmpl/content/cnt1.inc.php index ad05d6ea6..e507021df 100644 --- a/include/inc_tmpl/content/cnt1.inc.php +++ b/include/inc_tmpl/content/cnt1.inc.php @@ -53,8 +53,11 @@ ?>
+
+ +
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt13.inc.php b/include/inc_tmpl/content/cnt13.inc.php index fd0e98339..8a847e0be 100644 --- a/include/inc_tmpl/content/cnt13.inc.php +++ b/include/inc_tmpl/content/cnt13.inc.php @@ -88,8 +88,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt14.inc.php b/include/inc_tmpl/content/cnt14.inc.php index de84e7894..83afd33e0 100644 --- a/include/inc_tmpl/content/cnt14.inc.php +++ b/include/inc_tmpl/content/cnt14.inc.php @@ -62,8 +62,11 @@ ?>
+
+ +
diff --git a/include/inc_tmpl/content/cnt18.inc.php b/include/inc_tmpl/content/cnt18.inc.php index e09f3ae01..b5d320adc 100644 --- a/include/inc_tmpl/content/cnt18.inc.php +++ b/include/inc_tmpl/content/cnt18.inc.php @@ -38,8 +38,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt2.inc.php b/include/inc_tmpl/content/cnt2.inc.php index acb92bb48..d9d3adae8 100644 --- a/include/inc_tmpl/content/cnt2.inc.php +++ b/include/inc_tmpl/content/cnt2.inc.php @@ -81,8 +81,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt22.inc.php b/include/inc_tmpl/content/cnt22.inc.php index b8a2ac1a2..10c94e06e 100644 --- a/include/inc_tmpl/content/cnt22.inc.php +++ b/include/inc_tmpl/content/cnt22.inc.php @@ -48,8 +48,12 @@ ?>
+ + + +
diff --git a/include/inc_tmpl/content/cnt25.inc.php b/include/inc_tmpl/content/cnt25.inc.php index 82e096219..17ca81ccf 100644 --- a/include/inc_tmpl/content/cnt25.inc.php +++ b/include/inc_tmpl/content/cnt25.inc.php @@ -133,6 +133,13 @@
+
+
+ +
+ + +
diff --git a/include/inc_tmpl/content/cnt26.inc.php b/include/inc_tmpl/content/cnt26.inc.php index 5f5b9e863..a5ba82710 100644 --- a/include/inc_tmpl/content/cnt26.inc.php +++ b/include/inc_tmpl/content/cnt26.inc.php @@ -88,8 +88,12 @@ ?>
+ + + +
diff --git a/include/inc_tmpl/content/cnt27.inc.php b/include/inc_tmpl/content/cnt27.inc.php index 9e76d962f..28ced47fd 100644 --- a/include/inc_tmpl/content/cnt27.inc.php +++ b/include/inc_tmpl/content/cnt27.inc.php @@ -39,8 +39,11 @@ ?>
+ + +
diff --git a/include/inc_tmpl/content/cnt28.inc.php b/include/inc_tmpl/content/cnt28.inc.php index 7cd77df88..e641492ad 100644 --- a/include/inc_tmpl/content/cnt28.inc.php +++ b/include/inc_tmpl/content/cnt28.inc.php @@ -68,8 +68,12 @@ ?>
+ + + +
diff --git a/include/inc_tmpl/content/cnt29.inc.php b/include/inc_tmpl/content/cnt29.inc.php index f450ca18c..fecc21c43 100644 --- a/include/inc_tmpl/content/cnt29.inc.php +++ b/include/inc_tmpl/content/cnt29.inc.php @@ -112,8 +112,11 @@ ?>
+
+ +
diff --git a/include/inc_tmpl/content/cnt3.inc.php b/include/inc_tmpl/content/cnt3.inc.php index f2a635583..5f88011ee 100644 --- a/include/inc_tmpl/content/cnt3.inc.php +++ b/include/inc_tmpl/content/cnt3.inc.php @@ -41,8 +41,12 @@ ?>
+ +
+ +
+
diff --git a/include/inc_tmpl/content/cnt32.inc.php b/include/inc_tmpl/content/cnt32.inc.php index d929a665b..92277fff4 100644 --- a/include/inc_tmpl/content/cnt32.inc.php +++ b/include/inc_tmpl/content/cnt32.inc.php @@ -79,6 +79,10 @@
+ +
+ +
@@ -88,6 +92,8 @@
+ +
diff --git a/include/inc_tmpl/content/cnt33.inc.php b/include/inc_tmpl/content/cnt33.inc.php index c0c87ff90..972ea28e3 100644 --- a/include/inc_tmpl/content/cnt33.inc.php +++ b/include/inc_tmpl/content/cnt33.inc.php @@ -56,8 +56,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt4.inc.php b/include/inc_tmpl/content/cnt4.inc.php index fc3eafb08..c716c856d 100644 --- a/include/inc_tmpl/content/cnt4.inc.php +++ b/include/inc_tmpl/content/cnt4.inc.php @@ -39,8 +39,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt5.inc.php b/include/inc_tmpl/content/cnt5.inc.php index 3b5c54094..30f0e69d2 100644 --- a/include/inc_tmpl/content/cnt5.inc.php +++ b/include/inc_tmpl/content/cnt5.inc.php @@ -36,8 +36,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt50.inc.php b/include/inc_tmpl/content/cnt50.inc.php index b1174f0ca..5d74c5f50 100644 --- a/include/inc_tmpl/content/cnt50.inc.php +++ b/include/inc_tmpl/content/cnt50.inc.php @@ -58,8 +58,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt51.inc.php b/include/inc_tmpl/content/cnt51.inc.php index 07620ff85..26c185470 100644 --- a/include/inc_tmpl/content/cnt51.inc.php +++ b/include/inc_tmpl/content/cnt51.inc.php @@ -43,8 +43,11 @@ ?>
+
+ +
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt60.inc.php b/include/inc_tmpl/content/cnt60.inc.php index 17d9e46d4..5bf7eb58c 100644 --- a/include/inc_tmpl/content/cnt60.inc.php +++ b/include/inc_tmpl/content/cnt60.inc.php @@ -120,16 +120,23 @@ ?>
- -
- - () - - — - -
- + +
+ + +
+
+
+ + () + + — + +
+ + + diff --git a/include/inc_tmpl/content/cnt7.inc.php b/include/inc_tmpl/content/cnt7.inc.php index c49e7533e..4b09a0fe7 100644 --- a/include/inc_tmpl/content/cnt7.inc.php +++ b/include/inc_tmpl/content/cnt7.inc.php @@ -55,8 +55,12 @@ ?>
+ + + +
diff --git a/include/inc_tmpl/content/cnt8.inc.php b/include/inc_tmpl/content/cnt8.inc.php index e8661413a..6ac83479f 100644 --- a/include/inc_tmpl/content/cnt8.inc.php +++ b/include/inc_tmpl/content/cnt8.inc.php @@ -103,8 +103,12 @@ ?>
+ +
+ +
diff --git a/include/inc_tmpl/content/cnt9.inc.php b/include/inc_tmpl/content/cnt9.inc.php index c83403562..7306985ea 100644 --- a/include/inc_tmpl/content/cnt9.inc.php +++ b/include/inc_tmpl/content/cnt9.inc.php @@ -65,8 +65,12 @@ ?>
+ +
+ +