dev auf main #68
+58
-26
@@ -5,10 +5,25 @@ if (!isset($_SESSION["user"])) {
|
||||
exit();
|
||||
}
|
||||
include_once 'php/controller/showArticle-controller.php';
|
||||
|
||||
// Aktuelle Blockliste ermitteln:
|
||||
$rawContent = '[]';
|
||||
if (isset($_SESSION['old_content']) && !empty($_SESSION['old_content'])) {
|
||||
$rawContent = $_SESSION['old_content'];
|
||||
unset($_SESSION['old_content']);
|
||||
} elseif (isset($content) && !empty($content)) {
|
||||
$rawContent = $content;
|
||||
}
|
||||
|
||||
$blocks = json_decode($rawContent, true);
|
||||
if (!is_array($blocks)) {
|
||||
$blocks = [];
|
||||
}
|
||||
$blocks = array_values($blocks);
|
||||
?>
|
||||
<!--
|
||||
Seite: Beitrag erstellen
|
||||
Inhalt: Formular für die Erstellung eines neuen Beitrags
|
||||
Seite: Beitrag bearbeiten
|
||||
Inhalt: Formular für die Bearbeitung eines Beitrags
|
||||
-->
|
||||
<form method="post" action="php/controller/updateArticle-controller.php?id=<?php if(isset($id) && !empty($id)){echo htmlspecialchars($id);}else{$_SESSION["message"] = "missing_id";} ?>" id="editor-form" enctype="multipart/form-data" class="article-editor-scope.editor-container article-editor-scope editor-container">
|
||||
|
||||
@@ -27,32 +42,49 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
?>"
|
||||
placeholder="Titel hier eingeben" required>
|
||||
|
||||
<!-- Hier werden die dynamischen divs via JavaScript eingefügt -->
|
||||
<div id="block-container"></div>
|
||||
<!--
|
||||
Content-Blöcke: werden serverseitig als echte, benannte Formularfelder gerendert
|
||||
(blocks[i][type]...). Dadurch funktioniert das Hinzufügen/Entfernen von Blöcken und
|
||||
der Bild-Upload auch ganz ohne JavaScript über einen normalen Formular-Submit.
|
||||
Ist JavaScript aktiv, fängt js/editor.js diese Submits ab und erledigt dieselbe
|
||||
Änderung lokal im DOM, ohne den Server zu belasten.
|
||||
-->
|
||||
<div id="block-container">
|
||||
<?php foreach ($blocks as $i => $block): ?>
|
||||
<?php
|
||||
$blockType = $block['type'] ?? '';
|
||||
if ($blockType !== 'text' && $blockType !== 'image') {
|
||||
continue; // unbekannter/kaputter Block wird übersprungen
|
||||
}
|
||||
?>
|
||||
<div class="editor-block article-editor-scope" data-index="<?php echo (int)$i; ?>">
|
||||
<input type="hidden" name="blocks[<?php echo (int)$i; ?>][type]" value="<?php echo htmlspecialchars($blockType); ?>">
|
||||
|
||||
<!-- Plus-Button und das Pop-up-Menü -->
|
||||
<div id="add-block-control" class="article-editor-scope add-block-control">
|
||||
<button type="button" id="plus-button" class="article-editor-scope plus-button">+</button>
|
||||
<div id="block-popup" class="article-editor-scope block-popup hidden">
|
||||
<button type="button" data-type="text">Textblock</button>
|
||||
<button type="button" data-type="image">Bild einfügen</button>
|
||||
</div>
|
||||
<?php if ($blockType === 'text'): ?>
|
||||
<textarea name="blocks[<?php echo (int)$i; ?>][text]"
|
||||
placeholder="Schreibe deinen Textblock..."><?php echo htmlspecialchars($block['value'] ?? ''); ?></textarea>
|
||||
<?php else: /* image */ ?>
|
||||
<?php if (!empty($block['value'])): ?>
|
||||
<img src="<?php echo htmlspecialchars($block['value']); ?>"
|
||||
class="block-image-preview"
|
||||
style="max-width:200px;display:block;margin-top:10px;">
|
||||
<input type="hidden" name="blocks[<?php echo (int)$i; ?>][existing_image]" value="<?php echo htmlspecialchars($block['value']); ?>">
|
||||
<?php endif; ?>
|
||||
<input type="file" name="blocks[<?php echo (int)$i; ?>][image]" accept="image/*">
|
||||
<?php endif; ?>
|
||||
|
||||
<button type="submit" name="editor_action" value="delete_block:<?php echo (int)$i; ?>" class="delete-block-btn">✕</button>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<!-- Unsichtbares Textfeld, das die JSON-Daten hält und an den Controller postet -->
|
||||
<textarea id="content" name="content" style="display:none;"><?php
|
||||
if (isset($_SESSION['old_content']) && !empty($_SESSION['old_content'])){
|
||||
echo htmlspecialchars($_SESSION['old_content']);
|
||||
unset($_SESSION['old_content']);
|
||||
}elseif (isset($content) && !empty($content)){
|
||||
echo htmlspecialchars($content);
|
||||
} else {
|
||||
echo '[]';
|
||||
}
|
||||
?></textarea>
|
||||
|
||||
<!-- unsichtbares Input, um die zu löschenden Bilder zu übergeben-->
|
||||
<input type="hidden" id="deleted-images" name="deleted_images" value="[]">
|
||||
<div id="add-block-control" class="article-editor-scope add-block-control">
|
||||
<button type="button" id="plus-button" class="article-editor-scope plus-button">+</button>
|
||||
<div id="block-popup" class="article-editor-scope block-popup">
|
||||
<button type="submit" name="editor_action" value="add_text" data-type="text">Textblock</button>
|
||||
<button type="submit" name="editor_action" value="add_image" data-type="image">Bild einfügen</button>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- Seitenleiste -->
|
||||
@@ -289,4 +321,4 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
|
||||
</aside>
|
||||
|
||||
</form>
|
||||
</form>
|
||||
Reference in New Issue
Block a user