Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 87e595b13d | |||
| aae78bf479 | |||
| 1f7a2a77f6 | |||
| 9269465f6b | |||
| 883adfd242 | |||
| 1e890f9a28 | |||
| 2bb13d2e8c | |||
| cb02e05d55 | |||
| 05777f6109 | |||
| f3f042b3b9 | |||
| dfb13b1f96 | |||
| 6fa5038589 | |||
| 55f53e3346 | |||
| f36037d36d | |||
| 500bca80c1 | |||
| fc0361ed3a | |||
| df1485ce49 | |||
| b8bceb31c6 | |||
| f0308c3505 | |||
| e7ece1ed13 | |||
| 8ed7f7ec8f | |||
| feaef4a624 | |||
| 7d9aae2a59 | |||
| a88f8ca638 | |||
| be6a5f9add | |||
| ed4498578d | |||
| 118be50b3c | |||
| 1e2184ae20 | |||
| 8c1e1a64bf | |||
| b9c28968fe | |||
| 703d8d7519 | |||
| 8e52d99ba4 | |||
| d4020671c1 | |||
| 5c432e5801 | |||
| aac13297de | |||
| f60a4a4f60 | |||
| 0ed4de74b0 | |||
| 48bd26342a | |||
| b8e884a5aa | |||
| 1dbef5ca4b | |||
| e43ae7f96a | |||
| eab256d17f | |||
| bbdcbbf0ce | |||
| ec9bc3fe1f | |||
| 80f92a384e | |||
| f9c1c67a38 |
@@ -7,7 +7,7 @@
|
||||
|
||||
## Login-Informationen für Dummy-User
|
||||
`Anmeldename, Passwort, Mailadresse`:
|
||||
- `max.mustermann, test12345, mustermann@web.de`
|
||||
- `max.mustermann, test12345, max.mustermann@web.de`
|
||||
|
||||
## Weitere Voraussetzungen zur Nutzung
|
||||
- Per Klick auf das Logo gelangt man auf die Home-Seite.
|
||||
@@ -18,6 +18,7 @@
|
||||
- Bitte auf die gesetzten TODO's achten. Wenn Inhalte fehlen, sind sie i.d.R. als TODO kommentiert.
|
||||
- Die Suchseite und Kategorieseite packen momentan alle passenden Beiträge untereinander. Später sollen zunächst 10
|
||||
Ergebnisse auf einer Seite angezeigt werden.
|
||||
- Wenn ein Bild aus einem Beitrag entfernt wird, dann wird noch nicht die Datei im Pfad /uploads gelöscht.
|
||||
|
||||
## Besonderheiten des Projektes
|
||||
- Es wurde ein einfacher Beitrags-Editor erstellt. Mit diesem können Beiträge erstellt oder bearbeitet werden.
|
||||
|
||||
@@ -17,8 +17,28 @@ if (!isset($_SESSION["user"])) {
|
||||
<input type="text" id="title" name="title"
|
||||
value="<?php echo htmlspecialchars($_SESSION['old_title'] ?? ''); unset($_SESSION['old_title']); ?>"
|
||||
placeholder="Titel hier eingeben" required>
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag..."><?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);}?></textarea>
|
||||
|
||||
<!-- Hier werden die dynamischen divs via JavaScript eingefügt -->
|
||||
<div id="block-container"></div>
|
||||
|
||||
<!-- 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>
|
||||
</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']);
|
||||
} else {
|
||||
echo '[]'; // Standardmäßig ein leeres JSON-Array
|
||||
}
|
||||
?></textarea>
|
||||
</main>
|
||||
|
||||
<!-- Seitenleiste -->
|
||||
|
||||
+28
-26
@@ -8,30 +8,7 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
|
||||
<!-- Hauptcontainer für die Beitragsansicht (Ausschließlich der Content-Bereich) -->
|
||||
<main class="article-view-container">
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein interner Fehler aufgetreten. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_id"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Es ist ein Fehler aufgetreten. Die ID konnte nicht ausgelesen werden. Bitte versuche es erneut.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "missing_parameters"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Jeder Beitrag muss einen Titel, Kategorie und Inhalt besitzen.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "article_updated"): ?>
|
||||
<p class="alert-message is-success">
|
||||
Dein Beitrag wurde erfolgreich bearbeitet!
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
<?php include_once "includes/alertMessages.php"?>
|
||||
|
||||
<!-- Metadaten & Titel -->
|
||||
<div class="article-view-top-section">
|
||||
@@ -54,8 +31,33 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
<!-- Beitrags-Inhalt -->
|
||||
<div class="article-view-content">
|
||||
<?php if (isset($content)): ?>
|
||||
<!-- nl2br für Zeilenumbrüche -->
|
||||
<div class="article-view-body"><?php echo nl2br(htmlspecialchars($content)); ?></div>
|
||||
<?php
|
||||
// Versuchen, den Inhalt von JSON in ein PHP-Array umzuwandeln
|
||||
$blocks = json_decode($content, true);
|
||||
|
||||
// Wenn das JSON valide ist und Blöcke enthält
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($blocks)):
|
||||
foreach ($blocks as $block):
|
||||
if (isset($block['type']) && isset($block['value'])):
|
||||
if ($block['type'] === 'text'): ?>
|
||||
<!-- Textblock mit XSS-Schutz und Erhalt von Zeilenumbrüchen -->
|
||||
<div class="article-view-body block-text">
|
||||
<?php echo nl2br(htmlspecialchars($block['value'])); ?>
|
||||
</div>
|
||||
<?php elseif ($block['type'] === 'image'): ?>
|
||||
<!-- Bildblock, der auf den relativen Pfad im uploads-Ordner verweist -->
|
||||
<div class="article-view-body block-image">
|
||||
<img src="<?php echo htmlspecialchars($block['value']); ?>" alt="Beitragsbild">
|
||||
</div>
|
||||
<?php endif;
|
||||
endif;
|
||||
endforeach;
|
||||
else: ?>
|
||||
<!-- Fallback: Wenn der Beitrag alten Reintext aus der DB enthält -->
|
||||
<div class="article-view-body block-text">
|
||||
<?php echo nl2br(htmlspecialchars($content)); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
|
||||
+220
-29
@@ -10,7 +10,7 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
Seite: Beitrag erstellen
|
||||
Inhalt: Formular für die Erstellung eines neuen 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" class="article-editor-scope.editor-container article-editor-scope editor-container">
|
||||
<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">
|
||||
|
||||
<main class="editor-main">
|
||||
<?php include_once "includes/alertMessages.php"?>
|
||||
@@ -26,8 +26,33 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
|
||||
?>"
|
||||
placeholder="Titel hier eingeben" required>
|
||||
<textarea id="content" name="content" placeholder="Schreibe deinen Beitrag..."><?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);}?></textarea>
|
||||
|
||||
<!-- Hier werden die dynamischen divs via JavaScript eingefügt -->
|
||||
<div id="block-container"></div>
|
||||
|
||||
<!-- 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>
|
||||
</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="[]">
|
||||
</main>
|
||||
|
||||
<!-- Seitenleiste -->
|
||||
@@ -40,45 +65,211 @@ include_once 'php/controller/showArticle-controller.php';
|
||||
<div class="sidebar-block">
|
||||
<label for="category">Kategorie <span class="required">*</span></label>
|
||||
<select id="category" name="category" required>
|
||||
<option disabled selected>Kategorie wählen...</option>
|
||||
<option disabled <?php
|
||||
if ((!isset($_SESSION['old_category']) || empty($_SESSION['old_category'])) && (!isset($category) || empty($category))) {
|
||||
echo 'selected';
|
||||
}
|
||||
?>>Kategorie wählen...</option>
|
||||
|
||||
<optgroup label="Sprachen">
|
||||
<option value="deutsch">Deutsch</option>
|
||||
<option value="englisch">Englisch</option>
|
||||
<option value="franzoesisch">Französisch</option>
|
||||
<option value="latein">Latein</option>
|
||||
<option value="literatur">Literatur</option>
|
||||
<option value="deutsch" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'deutsch') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'deutsch') { echo 'selected'; }
|
||||
}
|
||||
?>>Deutsch</option>
|
||||
<option value="englisch" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'englisch') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'englisch') { echo 'selected'; }
|
||||
}
|
||||
?>>Englisch</option>
|
||||
<option value="franzoesisch" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'franzoesisch') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'franzoesisch') { echo 'selected'; }
|
||||
}
|
||||
?>>Französisch</option>
|
||||
<option value="latein" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'latein') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'latein') { echo 'selected'; }
|
||||
}
|
||||
?>>Latein</option>
|
||||
<option value="literatur" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'literatur') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'literatur') { echo 'selected'; }
|
||||
}
|
||||
?>>Literatur</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="MINT">
|
||||
<option value="mathe">Mathematik</option>
|
||||
<option value="biologie">Biologie</option>
|
||||
<option value="chemie">Chemie</option>
|
||||
<option value="physik">Physik</option>
|
||||
<option value="informatik">Informatik</option>
|
||||
<option value="astronomie">Astronomie</option>
|
||||
<option value="mathe" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'mathe') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'mathe') { echo 'selected'; }
|
||||
}
|
||||
?>>Mathematik</option>
|
||||
<option value="biologie" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'biologie') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'biologie') { echo 'selected'; }
|
||||
}
|
||||
?>>Biologie</option>
|
||||
<option value="chemie" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'chemie') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'chemie') { echo 'selected'; }
|
||||
}
|
||||
?>>Chemie</option>
|
||||
<option value="physik" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'physik') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'physik') { echo 'selected'; }
|
||||
}
|
||||
?>>Physik</option>
|
||||
<option value="informatik" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'informatik') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'informatik') { echo 'selected'; }
|
||||
}
|
||||
?>>Informatik</option>
|
||||
<option value="astronomie" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'astronomie') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'astronomie') { echo 'selected'; }
|
||||
}
|
||||
?>>Astronomie</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="Gesellschaft & Werte">
|
||||
<option value="geschichte">Geschichte</option>
|
||||
<option value="erdkunde">Erdkunde</option>
|
||||
<option value="sozialkunde">Sozialkunde</option>
|
||||
<option value="wirtschaft">Wirtschaftskunde</option>
|
||||
<option value="religion">Religion</option>
|
||||
<option value="ethik">Ethikunterricht</option>
|
||||
<option value="philosophie">Philosophie</option>
|
||||
<option value="psychologie">Psychologie</option>
|
||||
<option value="kunst">Kunst</option>
|
||||
<option value="musik">Musik</option>
|
||||
<option value="theater">Theater</option>
|
||||
<option value="geschichte" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'geschichte') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'geschichte') { echo 'selected'; }
|
||||
}
|
||||
?>>Geschichte</option>
|
||||
<option value="erdkunde" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'erdkunde') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'erdkunde') { echo 'selected'; }
|
||||
}
|
||||
?>>Erdkunde</option>
|
||||
<option value="sozialkunde" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'sozialkunde') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'sozialkunde') { echo 'selected'; }
|
||||
}
|
||||
?>>Sozialkunde</option>
|
||||
<option value="wirtschaft" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'wirtschaft') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'wirtschaft') { echo 'selected'; }
|
||||
}
|
||||
?>>Wirtschaftskunde</option>
|
||||
<option value="religion" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'religion') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'religion') { echo 'selected'; }
|
||||
}
|
||||
?>>Religion</option>
|
||||
<option value="ethik" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'ethik') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'ethik') { echo 'selected'; }
|
||||
}
|
||||
?>>Ethikunterricht</option>
|
||||
<option value="philosophie" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'philosophie') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'philosophie') { echo 'selected'; }
|
||||
}
|
||||
?>>Philosophie</option>
|
||||
<option value="psychologie" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'psychologie') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'psychologie') { echo 'selected'; }
|
||||
}
|
||||
?>>Psychologie</option>
|
||||
<option value="kunst" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'kunst') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'kunst') { echo 'selected'; }
|
||||
}
|
||||
?>>Kunst</option>
|
||||
<option value="musik" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'musik') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'musik') { echo 'selected'; }
|
||||
}
|
||||
?>>Musik</option>
|
||||
<option value="theater" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'theater') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'theater') { echo 'selected'; }
|
||||
}
|
||||
?>>Theater</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="Technik & Praxis">
|
||||
<option value="technik">Technik</option>
|
||||
<option value="werken">Werken</option>
|
||||
<option value="hauswirtschaft">Hauswirtschaft</option>
|
||||
<option value="sport">Sport</option>
|
||||
<option value="technik" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'technik') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'technik') { echo 'selected'; }
|
||||
}
|
||||
?>>Technik</option>
|
||||
<option value="werken" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'werken') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'werken') { echo 'selected'; }
|
||||
}
|
||||
?>>Werken</option>
|
||||
<option value="hauswirtschaft" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'hauswirtschaft') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'hauswirtschaft') { echo 'selected'; }
|
||||
}
|
||||
?>>Hauswirtschaft</option>
|
||||
<option value="sport" <?php
|
||||
if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
|
||||
if ($_SESSION['old_category'] === 'sport') { echo 'selected'; }
|
||||
} elseif (isset($category) && !empty($category)) {
|
||||
if ($category === 'sport') { echo 'selected'; }
|
||||
}
|
||||
?>>Sport</option>
|
||||
</optgroup>
|
||||
|
||||
<?php
|
||||
if (isset($_SESSION['old_category'])) {
|
||||
unset($_SESSION['old_category']);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -90,6 +90,135 @@
|
||||
padding: 18px 12px;
|
||||
}
|
||||
|
||||
/* Container für die dynamisch per JS eingefügten Blöcke */
|
||||
.article-editor-scope #block-container {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
/* Styling für jeden einzelnen dynamisch generierten Block */
|
||||
.article-editor-scope .editor-block {
|
||||
position: relative; /* Wichtig für die absolute Positionierung des Lösch-Buttons */
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
background-color: #fafafa;
|
||||
border: 1px dashed #cccccc;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
/* Textarea innerhalb eines dynamischen Textblocks */
|
||||
.article-editor-scope .editor-block textarea {
|
||||
width: 100%;
|
||||
min-height: 120px;
|
||||
padding: 10px;
|
||||
border: 1px solid #dddddd;
|
||||
border-radius: 4px;
|
||||
font-family: inherit;
|
||||
font-size: 1.1rem;
|
||||
line-height: 1.6;
|
||||
resize: vertical;
|
||||
outline: none;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
/* Komfort-Löschbutton oben rechts an jedem Block */
|
||||
.article-editor-scope .delete-block-btn {
|
||||
position: absolute;
|
||||
top: -10px;
|
||||
right: -10px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
background-color: #e74c3c;
|
||||
color: #ffffff;
|
||||
border: none;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.article-editor-scope .delete-block-btn:hover {
|
||||
background-color: #c0392b;
|
||||
}
|
||||
|
||||
/* Steuerungselement für den Plus-Button und das Pop-up */
|
||||
.article-editor-scope .add-block-control {
|
||||
position: relative; /* Dient als Anker für das absolut positionierte Pop-up */
|
||||
margin-top: 10px;
|
||||
display: inline-block;
|
||||
align-self: flex-start; /* Verhindert, dass der Button die volle Breite spannt */
|
||||
}
|
||||
|
||||
/* Der runde Plus-Button */
|
||||
.article-editor-scope .plus-button {
|
||||
width: 45px;
|
||||
height: 45px;
|
||||
border-radius: 50%;
|
||||
background-color: #3498db;
|
||||
color: #ffffff;
|
||||
border: none;
|
||||
font-size: 26px;
|
||||
font-weight: 300;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
|
||||
transition: background-color 0.2s ease, transform 0.2s ease;
|
||||
}
|
||||
|
||||
.article-editor-scope .plus-button:hover {
|
||||
background-color: #2980b9;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
/* Das Pop-up Menü */
|
||||
.article-editor-scope .block-popup {
|
||||
position: absolute;
|
||||
left: 60px; /* Platziert das Menü rechts neben dem Plus-Button */
|
||||
top: 50%;
|
||||
transform: translateY(-50%); /* Zentriert das Menü vertikal zum Button */
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
padding: 8px;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
|
||||
z-index: 999;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Die entscheidende Klasse zum Ausblenden */
|
||||
.article-editor-scope .block-popup.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Buttons im Pop-up (Textblock / Bild einfügen) */
|
||||
.article-editor-scope .block-popup button {
|
||||
background-color: #f8f9fa;
|
||||
border: 1px solid #dcdde1;
|
||||
padding: 8px 16px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #2f3640;
|
||||
transition: background-color 0.15s ease, border-color 0.15s ease;
|
||||
}
|
||||
|
||||
.article-editor-scope .block-popup button:hover {
|
||||
background-color: #f1f2f6;
|
||||
border-color: #b2bec3;
|
||||
}
|
||||
|
||||
/* Responsive Anpassungen unter 760px (für z.B. Smartphones) */
|
||||
@media (max-width: 760px) {
|
||||
.article-editor-scope.editor-container {
|
||||
@@ -113,4 +242,8 @@
|
||||
border-left: none;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.article-editor-scope .editor-block textarea {
|
||||
min-height: 150px;
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,37 @@
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.article-view-content {
|
||||
margin-bottom: 3rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem; /* Erzeugt einen sauberen Abstand zwischen den einzelnen Blöcken */
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.article-view-body {
|
||||
font-size: 1.125rem;
|
||||
color: #2d3748;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.article-view-body.block-text {
|
||||
white-space: pre-line;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.article-view-body.block-image {
|
||||
display: flex;
|
||||
justify-content: center; /* Zentriert das Bild horizontal */
|
||||
}
|
||||
|
||||
.article-view-body.block-image img {
|
||||
max-width: 100%; /* Verhindert das Ausbrechen aus der Lesebreite */
|
||||
height: auto; /* Behält das originale Seitenverhältnis bei */
|
||||
border-radius: 6px; /* Optionale leichte Rundung für ein moderneres Layout */
|
||||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03); /* Minimaler, eleganter Schatten */
|
||||
}
|
||||
|
||||
/* Responsive Anpassungen unter 760px (für z.B. Smarticlephones) */
|
||||
@media (max-width: 760px) {
|
||||
.article-view-container {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_content"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Der Text erlaubt eine Länge von 10 bis maximal 7.000 Zeichen (ca. 1.000 Wörter).
|
||||
Ein Beitrag muss Inhalt besitzen. Text- und Bildelemente dürfen nicht leer sein!
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_category"): ?>
|
||||
@@ -63,6 +63,11 @@
|
||||
Dein Beitrag wurde erfolgreich veröffentlicht!
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "image_upload_error"): ?>
|
||||
<p class="alert-message is-error">
|
||||
Das Bild konnte nicht hochgeladen werden. Bitte versuche es erneut oder verwende ein anderes Bildformat.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
unset($_SESSION["message"]);
|
||||
?>
|
||||
|
||||
@@ -42,6 +42,7 @@ if ($pfad === "deleteAccount") {
|
||||
<meta name="author" content="Niklas Ortmann">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="icon" type="image/x-icon" href="images/logos/logo_icon.ico">
|
||||
|
||||
<link rel="stylesheet" href="css/main.css">
|
||||
<link rel="stylesheet" href="css/navbar.css">
|
||||
<link rel="stylesheet" href="css/footer.css">
|
||||
@@ -50,6 +51,8 @@ if ($pfad === "deleteAccount") {
|
||||
<link rel="stylesheet" href="css/profile.css">
|
||||
<link rel="stylesheet" href="css/showArticle.css">
|
||||
<link rel="stylesheet" href="css/message.css">
|
||||
|
||||
<script src="js/editor.js" async></script>
|
||||
<title>EduForge</title>
|
||||
</head>
|
||||
|
||||
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
console.log("Die JavaScript-Datei wurde erfolgreich geladen!");
|
||||
|
||||
function initEditor() {
|
||||
const form = document.getElementById("editor-form");
|
||||
|
||||
if (!form) {
|
||||
console.error("Skript abgebrochen: Formular nicht gefunden!");
|
||||
return;
|
||||
} else {
|
||||
console.log("Formular gefunden und Editor initialisiert:", form);
|
||||
}
|
||||
|
||||
const container = document.getElementById("block-container");
|
||||
const plusButton = document.getElementById("plus-button");
|
||||
const popup = document.getElementById("block-popup");
|
||||
const hiddenContentInput = document.getElementById("content");
|
||||
|
||||
const initialImages = [];
|
||||
|
||||
// Pop-up umschalten bei Klick auf das Plus
|
||||
plusButton.addEventListener("click", () => {
|
||||
popup.classList.toggle("hidden");
|
||||
});
|
||||
|
||||
// Klick auf eine Block-Option im Pop-up
|
||||
popup.querySelectorAll("button").forEach(btn => {
|
||||
btn.addEventListener("click", function() {
|
||||
const type = this.getAttribute("data-type");
|
||||
addBlockElement(type, "");
|
||||
popup.classList.add("hidden");
|
||||
});
|
||||
});
|
||||
|
||||
// Erstellt ein visuelles HTML-Element im Editor
|
||||
function addBlockElement(type, value = "") {
|
||||
const blockDiv = document.createElement("div");
|
||||
blockDiv.classList.add("editor-block");
|
||||
blockDiv.setAttribute("data-type", type);
|
||||
|
||||
// Wenn es ein existierendes Server-Bild beim Laden ist, Pfad im globalen Array sichern
|
||||
if (type === "image" && value && typeof value === 'string' && value.startsWith('uploads/')) {
|
||||
initialImages.push(value);
|
||||
blockDiv.setAttribute("data-value", value);
|
||||
}
|
||||
|
||||
// Löschen-Button
|
||||
const deleteBtn = document.createElement("button");
|
||||
deleteBtn.type = "button";
|
||||
deleteBtn.innerHTML = "✕";
|
||||
deleteBtn.classList.add("delete-block-btn");
|
||||
deleteBtn.addEventListener("click", () => {
|
||||
// ANPASSUNG 2B: Logik hier komplett geleert. Das '✕' entfernt den Block jetzt nur noch sicher aus dem HTML.
|
||||
blockDiv.remove();
|
||||
});
|
||||
blockDiv.appendChild(deleteBtn);
|
||||
|
||||
if (type === "text") {
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.placeholder = "Schreibe deinen Textblock...";
|
||||
textarea.value = value;
|
||||
blockDiv.appendChild(textarea);
|
||||
} else if (type === "image") {
|
||||
const fileInput = document.createElement("input");
|
||||
fileInput.type = "file";
|
||||
fileInput.accept = "image/*";
|
||||
|
||||
const imgPreview = document.createElement("img");
|
||||
imgPreview.style.maxWidth = "200px";
|
||||
imgPreview.style.display = "block";
|
||||
imgPreview.style.marginTop = "10px";
|
||||
|
||||
if (value && typeof value === 'string') {
|
||||
if (value.startsWith('uploads/') || value.startsWith('data:image/')) {
|
||||
imgPreview.src = value;
|
||||
blockDiv.setAttribute("data-value", value);
|
||||
}
|
||||
}
|
||||
|
||||
fileInput.addEventListener("change", function() {
|
||||
if (this.files && this.files[0]) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
imgPreview.src = e.target.result;
|
||||
blockDiv.setAttribute("data-value", e.target.result);
|
||||
}
|
||||
reader.readAsDataURL(this.files[0]);
|
||||
}
|
||||
});
|
||||
|
||||
blockDiv.appendChild(fileInput);
|
||||
blockDiv.appendChild(imgPreview);
|
||||
}
|
||||
|
||||
container.appendChild(blockDiv);
|
||||
}
|
||||
|
||||
// beim Abschicken verbleibende Blöcke auslesen UND gelöschte Bilder ermitteln
|
||||
form.addEventListener("submit", function(e) {
|
||||
const blocks = [];
|
||||
const currentImages = [];
|
||||
|
||||
// alle aktuell im Formular verbliebenen Blöcke scannen
|
||||
container.querySelectorAll(".editor-block").forEach(blockDiv => {
|
||||
const type = blockDiv.getAttribute("data-type");
|
||||
let value = "";
|
||||
|
||||
if (type === "text") {
|
||||
value = blockDiv.querySelector("textarea").value;
|
||||
} else if (type === "image") {
|
||||
|
||||
const imgTag = blockDiv.querySelector("img");
|
||||
if (imgTag) {
|
||||
const srcValue = imgTag.getAttribute("src") || "";
|
||||
// Wenn es ein neues Bild ist, nutzen wir das data-value (Base64)
|
||||
if (srcValue.startsWith('data:image/')) {
|
||||
value = blockDiv.getAttribute("data-value") || "";
|
||||
} else {
|
||||
value = srcValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Pfade sammeln, die der Nutzer NICHT gelöscht hat (für den Abgleich)
|
||||
if (value && value.startsWith('uploads/')) {
|
||||
currentImages.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
blocks.push({ type: type, value: value });
|
||||
});
|
||||
|
||||
// das reguläre unsichtbare Content-Feld befüllen
|
||||
hiddenContentInput.value = JSON.stringify(blocks);
|
||||
|
||||
// Differenz berechnen: Welche Bilder aus 'initialImages' fehlen in 'currentImages' ?
|
||||
const deletedImages = initialImages.filter(img => !currentImages.includes(img));
|
||||
|
||||
// das 'deleted_images'-Feld dynamisch befüllen und an den Controller senden
|
||||
let deletedInput = document.getElementById("deleted-images");
|
||||
if (!deletedInput) {
|
||||
deletedInput = document.createElement("input");
|
||||
deletedInput.type = "hidden";
|
||||
deletedInput.id = "deleted-images";
|
||||
deletedInput.name = "deleted_images";
|
||||
form.appendChild(deletedInput);
|
||||
}
|
||||
deletedInput.value = JSON.stringify(deletedImages);
|
||||
});
|
||||
|
||||
// Existierende Blöcke laden (stellt alte Daten aus der Session wieder her)
|
||||
try {
|
||||
const initialBlocks = JSON.parse(hiddenContentInput.value.trim());
|
||||
if (Array.isArray(initialBlocks)) {
|
||||
initialBlocks.forEach(b => {
|
||||
if (b.type === "image" && b.value && typeof b.value === 'string' && !b.value.startsWith('data:image/')) {
|
||||
let cleanPath = b.value.trim().replace(/\\\//g, '/'); // Verwandelt \/ in /
|
||||
|
||||
initialImages.push(cleanPath);
|
||||
addBlockElement(b.type, cleanPath);
|
||||
|
||||
} else {
|
||||
addBlockElement(b.type, b.value);
|
||||
}
|
||||
});
|
||||
console.log("Erfolgreich registrierte Start-Bilder:", initialImages);
|
||||
}
|
||||
} catch(e) {
|
||||
if (hiddenContentInput.value.trim() !== "") {
|
||||
addBlockElement("text", hiddenContentInput.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SICHERER START: Prüft, ob das HTML bereits bereit ist
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", initEditor);
|
||||
} else {
|
||||
// Falls das DOM schon fertig geladen ist, führen wir es direkt aus
|
||||
initEditor();
|
||||
}
|
||||
@@ -24,12 +24,6 @@ require_once '../validator/article-validator.php';
|
||||
$tags = $_POST['tags'] ?? '';
|
||||
|
||||
// -------------------------------- Validierung der Daten: -------------------------
|
||||
if (!articleAuthorValidator($author)) {
|
||||
$_SESSION["message"] = "author_not_valid";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleTitleValidator($title)) {
|
||||
$_SESSION["message"] = "invalid_title";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
@@ -64,6 +58,59 @@ require_once '../validator/article-validator.php';
|
||||
$cleanedTags = array_unique($cleanedTags);
|
||||
$cleanedTags = implode(',', $cleanedTags);
|
||||
}
|
||||
|
||||
// ----------------- Base64-Bilder verarbeiten und auf Server speichern -----------------
|
||||
$blocks = json_decode($content, true);
|
||||
$uploadDir = __DIR__ . '/../../uploads/';
|
||||
|
||||
if (!file_exists($uploadDir)) {
|
||||
mkdir($uploadDir, 0755, true);
|
||||
}
|
||||
|
||||
if (is_array($blocks)) {
|
||||
foreach ($blocks as &$block) {
|
||||
// sicherstellen, dass 'type' und 'value' existieren:
|
||||
if (isset($block['type']) && isset($block['value']) && $block['type'] === 'image' && str_starts_with($block['value'], 'data:image/')) {
|
||||
|
||||
// Base64-String zerlegen
|
||||
$parts = explode(',', $block['value']);
|
||||
|
||||
// falls der String korrupt ist und kein Komma hat
|
||||
if (count($parts) < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadata = $parts[0];
|
||||
$base64Data = $parts[1];
|
||||
|
||||
// Dateiendung ermitteln
|
||||
preg_match('/data:image\/(?<extension>.*?);/', $metadata, $matches);
|
||||
$extension = $matches['extension'] ?? 'jpg';
|
||||
if ($extension === 'jpeg') {
|
||||
$extension = 'jpg';
|
||||
}
|
||||
|
||||
// Eindeutigen Dateinamen generieren
|
||||
$fileName = 'img_' . uniqid() . '.' . $extension;
|
||||
$filePath = $uploadDir . $fileName;
|
||||
|
||||
// Datei im /uploads speichern:
|
||||
if (file_put_contents($filePath, base64_decode($base64Data)) !== false) {
|
||||
// temporären Base64-String durch den echten Pfad ersetzen
|
||||
$block['value'] = 'uploads/' . $fileName;
|
||||
} else {
|
||||
$_SESSION["message"] = "image_upload_error";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($block);
|
||||
}
|
||||
|
||||
// Aktualisiertes Array wieder in JSON konvertieren
|
||||
$finalContent = json_encode($blocks, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// ----------------- Übertragung der validierten Daten in ArticleManager: ---------------------------
|
||||
try {
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
@@ -72,7 +119,7 @@ require_once '../validator/article-validator.php';
|
||||
// Formulardaten nach erfolgreichem Erstellen aus der Session löschen
|
||||
unset($_SESSION["old_title"], $_SESSION["old_content"], $_SESSION["old_category"], $_SESSION["old_tags"]);
|
||||
|
||||
} catch (Exception $e){
|
||||
} catch (\Throwable $e){
|
||||
$_SESSION["message"] = "internal_error";
|
||||
header("location: ../../index.php?pfad=createArticle");
|
||||
exit();
|
||||
@@ -84,7 +131,4 @@ require_once '../validator/article-validator.php';
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -34,12 +34,6 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$tags = $_POST['tags'] ?? '';
|
||||
|
||||
// -------------------------------- Validierung der Daten: -------------------------
|
||||
if (!articleAuthorValidator($author)) {
|
||||
$_SESSION["message"] = "author_not_valid";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!articleTitleValidator($title)) {
|
||||
$_SESSION["message"] = "invalid_title";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
@@ -75,16 +69,91 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$cleanedTags = implode(',', $cleanedTags);
|
||||
}
|
||||
|
||||
// --------------------------------------- Base64-Bilder speichern ---------------------------------------------
|
||||
$blocks = json_decode($content, true);
|
||||
$uploadDir = __DIR__ . '/../../uploads/';
|
||||
|
||||
if (!file_exists($uploadDir)) {
|
||||
mkdir($uploadDir, 0755, true);
|
||||
}
|
||||
|
||||
// ----------------- Gelöschte Bilder über die JS-Löschliste entfernen ----------------- TODO: Gelöschte Bilder über die JS-Löschliste entfernen
|
||||
/*if (isset($_POST['deleted_images'])) {
|
||||
$deletedImages = json_decode($_POST['deleted_images'], true);
|
||||
|
||||
// Wir ermitteln den physisch echten, absoluten Pfad zum uploads-Ordner auf der Festplatte
|
||||
$uploadDir = realpath(__DIR__ . '/../../uploads') . DIRECTORY_SEPARATOR;
|
||||
|
||||
if (is_array($deletedImages)) {
|
||||
foreach ($deletedImages as $imagePath) {
|
||||
// Nur den reinen Dateinamen heraustrennen (z.B. img_65a123.jpg)
|
||||
$filename = basename($imagePath);
|
||||
$fullDeletePath = $uploadDir . $filename;
|
||||
|
||||
// Debugging & Löschen:
|
||||
if (file_exists($fullDeletePath)) {
|
||||
// Versuchen zu löschen. Wenn es fehlschlägt, Fehlermeldung erzwingen
|
||||
if (!@unlink($fullDeletePath)) {
|
||||
$error = error_get_last();
|
||||
die("Datei existiert, aber PHP darf sie nicht löschen! Grund: " . $error['message']);
|
||||
}
|
||||
} else {
|
||||
// Wenn PHP die Datei an diesem Pfad nicht findet, brechen wir zum Debuggen ab
|
||||
// die("PHP findet die Datei nicht unter dem Pfad: " . $fullDeletePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// ----------------------- NEU hinzugefügte Base64-Bilder: --------------------------
|
||||
if (is_array($blocks)) {
|
||||
foreach ($blocks as &$block) {
|
||||
// Prüfen, ob der Block ein Bild ist und ein NEUES Bild (Base64-Format) enthält
|
||||
if (isset($block['type']) && isset($block['value']) && $block['type'] === 'image' && is_string($block['value'])) {
|
||||
|
||||
if (str_starts_with($block['value'], 'data:image/')) {
|
||||
$parts = explode(',', $block['value']);
|
||||
if (count($parts) >= 2) {
|
||||
$metadata = $parts[0];
|
||||
$base64Data = $parts[1];
|
||||
|
||||
preg_match('/data:image\/(?<extension>.*?);/', $metadata, $matches);
|
||||
$extension = $matches['extension'] ?? 'jpg';
|
||||
if ($extension === 'jpeg') { $extension = 'jpg'; }
|
||||
|
||||
$fileName = 'img_' . uniqid() . '.' . $extension;
|
||||
$filePath = $uploadDir . $fileName;
|
||||
|
||||
if (file_put_contents($filePath, base64_decode($base64Data)) !== false) {
|
||||
$block['value'] = 'uploads/' . $fileName;
|
||||
} else {
|
||||
$_SESSION["message"] = "image_upload_error";
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($block);
|
||||
}
|
||||
|
||||
// Aktualisiertes Array wieder in JSON konvertieren
|
||||
$finalContent = json_encode($blocks, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// ----------------- Übertragung der validierten Daten in ArticleManager: ---------------------------
|
||||
try {
|
||||
$articleManager = ArticleManager::getInstance();
|
||||
$article = $articleManager->getArticle($id);
|
||||
$article->setTitle($title);
|
||||
$article->setContent($content);
|
||||
$article->setContent($finalContent);
|
||||
$article->setCategory($category);
|
||||
$article->setTags($cleanedTags);
|
||||
$articleManager->updateArticle($id ,$article, $author);
|
||||
} catch (Exception $e){
|
||||
|
||||
unset($_SESSION["old_title"], $_SESSION["old_content"], $_SESSION["old_category"], $_SESSION["old_tags"]);
|
||||
|
||||
} catch (\Throwable $e){
|
||||
$_SESSION["message"] = $e->getMessage();
|
||||
header("location: ../../index.php?pfad=updateArticle&id=$id");
|
||||
exit();
|
||||
|
||||
@@ -13,7 +13,7 @@ class ArticleManager
|
||||
/**
|
||||
* Diese Methode erstellt, falls noch keine existiert, eine Instanz einer ArticleManager-Implementierung und
|
||||
* erstellt Dummy-Beiträge.
|
||||
*
|
||||
*
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public static function getInstance()
|
||||
@@ -145,9 +145,17 @@ class ArticleManager
|
||||
// Verteilt die 10 Autoren gleichmäßig (ID 1 -> Autor 1, ID 10 -> Autor 10, ID 11 -> Autor 1)
|
||||
$authorEmail = $authors[($id - 1) % 10];
|
||||
|
||||
$blockStructure = [
|
||||
[
|
||||
'type' => 'text',
|
||||
'value' => $data[1] // Der originale Text aus dem Dummy-Array
|
||||
]
|
||||
];
|
||||
$jsonContent = json_encode($blockStructure, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$articleManager->addArticle(
|
||||
$data[0], // Titel
|
||||
$data[1], // Inhalt
|
||||
$jsonContent, // Inhalt
|
||||
$authorEmail, // Rotierende Autoren-E-Mail
|
||||
$data[2], // Kategorie
|
||||
$data[3] // Tags
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Prüft, ob der Autor auch der Eigentümer des Beitrags ist.
|
||||
* @param $author
|
||||
* @return true
|
||||
* TODO: Implement this.
|
||||
*/
|
||||
function articleAuthorValidator($author)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob der Titel die folgenden Bedingungen erfüllt:
|
||||
* Buchstaben von a-z; A-Z
|
||||
@@ -33,19 +22,73 @@ function articleTitleValidator($title)
|
||||
}
|
||||
|
||||
/**
|
||||
* Prüft, ob der Contenttext 10-7000 Zeichen enthält.
|
||||
* @param $content
|
||||
* Prüft, ob der Content valides JSON ist UND ob alle enthaltenen Blöcke
|
||||
* die inhaltlichen Kriterien erfüllen:
|
||||
* Textblöcke sind nicht leer
|
||||
* Bilder sind in Bildblöcken vorhanden
|
||||
*
|
||||
* @param mixed $content Der zu prüfende JSON-String
|
||||
* @return bool
|
||||
*/
|
||||
function articleContentValidator($content)
|
||||
{
|
||||
$content = trim($content);
|
||||
$zeichenAnzahl = mb_strlen($content);
|
||||
if ($zeichenAnzahl <= 7000 && $zeichenAnzahl >= 10) {
|
||||
return true;
|
||||
}else{
|
||||
// 1. Grundlegende Typprüfung
|
||||
if (!is_string($content)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. Formale JSON-Prüfung (Kompatibel mit PHP 8.2)
|
||||
$blocks = json_decode($content, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. Inhaltliche Validierung der einzelnen Blöcke
|
||||
// Falls das JSON zwar valide, aber kein Array ist (z.B. nur ein String/Zahl)
|
||||
if (!is_array($blocks)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mindestens ein Block sollte vorhanden sein (optional, verhindert leere Beiträge)
|
||||
if (empty($blocks)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($blocks as $block) {
|
||||
// Jeder Block muss die Keys 'type' und 'value' besitzen
|
||||
if (!isset($block['type']) || !isset($block['value'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = $block['type'];
|
||||
$value = $block['value'];
|
||||
|
||||
if ($type === 'text') {
|
||||
// Validierung für Text: Darf nach dem Trimmen nicht leer sein
|
||||
if (trim($value) === '') {
|
||||
return false;
|
||||
}
|
||||
} elseif ($type === 'image') {
|
||||
// Validierung für Bild: Muss entweder mit uploads/ starten (Bestand)
|
||||
// oder mit data:image/ beginnen (neues Base64-Bild aus dem Editor)
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$isValidPath = str_starts_with($value, 'uploads/');
|
||||
$isValidBase64 = str_starts_with($value, 'data:image/');
|
||||
|
||||
if (!$isValidPath && !$isValidBase64) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Unbekannter Blocktyp wird zur Sicherheit abgewiesen
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Wenn alle Prüfungen bestanden wurden
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# Verhindert das Auflisten aller Dateien im Ordner
|
||||
Options -Indexes
|
||||
|
||||
# Schaltet die PHP-Ausführung in diesem Ordner komplett ab
|
||||
<FilesMatch "\.(php|php[0-9]|phtml|pl|py|jsp|sh|cgi)$">
|
||||
Order Deny,Allow
|
||||
Deny from all
|
||||
</FilesMatch>
|
||||
|
||||
# erlaubt nur den Zugriff auf folgende Dateien:
|
||||
<FilesMatch "\.(?i:jpg|jpeg|png|gif|webp|ico)$">
|
||||
Order Allow,Deny
|
||||
Allow from all
|
||||
</FilesMatch>
|
||||
Reference in New Issue
Block a user