Compare commits

...

84 Commits

Author SHA1 Message Date
niklas.ortmann 4f8d11881d Merge pull request 'home zeigt nun dynamisch die Kategorien an' (#35) from Startseite into dev
Reviewed-on: #35
2026-06-17 12:08:10 +02:00
niklas.ortmann 5c924d3277 Update profile.php 2026-06-17 12:06:49 +02:00
niklas.ortmann 7f703a8386 Update profile.php 2026-06-17 12:03:25 +02:00
niklas.ortmann f063ea4741 Update profile.php 2026-06-17 12:02:41 +02:00
niklas.ortmann ca643dd298 Update profile.php 2026-06-17 12:02:20 +02:00
niklas.ortmann e19225e49e Update profile.php 2026-06-17 12:01:38 +02:00
niklas.ortmann 9ffbca679e Update profile.php 2026-06-17 12:00:59 +02:00
niklas.ortmann d90a10e462 Update profile.php 2026-06-17 12:00:36 +02:00
niklas.ortmann b6f25d041b Anmerkungen von Maximilian zu Blatt 04
Ist der PHP-Code gut verständlich und übersichtlich strukturiert? Beinahe vollständig. ArticleManager::getInstance() erzeugt Dummy-Daten direkt beim Abruf der Instanz; etwas unübersichtlich, aber im Kontext der Dummy-Daten nicht zu gewichten (heißt es wird nicht negativ angerechnet).

Wie ist die Code-Qualität? Teilweise. articleAuthorValidator() ist mit TODO versehen und gibt immer true zurück. In home.php wird $dummy3->getId() aufgerufen, bevor geprüft wird, ob $dummy3 überhaupt existiert.

Wird redundanter Code vermieden? Teilweise. Die Kategorie-Listen stehen mehrfach separat in createArticle.php, updateArticle.php, navbar.php und article-validator.php. Fehlerausgaben für Artikel-Erstellung und Artikel-Bearbeitung sind ebenfalls fast identisch doppelt vorhanden.

Findet eine adäquate Trennung von PHP-Code und HTML-Code statt? Beinahe vollständig. In den Views werden teilweise noch Controller direkt eingebunden, z. B. profile.php bindet profile-controller.php ein und updateArticle.php nutzt showArticle-controller.php, um Daten zu laden (kann man theoretisch so machen, an dieser Stelle ist die Trennung dann aber nicht mehr wirklich sauber auf einem fundamentalen Level).

Ist eine Trennung in Model, View und Controller ersichtlich und auch korrekt durchgeführt? Teilweise. content-Dateien übernehmen teilweise Routing-/Controller-Aufgaben. Views binden Controller selbst ein.

Wurde das DAO-Pattern korrekt umgesetzt? Ok hier und da mit extends ein wenig fragwürdig aber kein Fehler.

Werden Sessions korrekt eingesetzt? Ok. session_start() wird mehrfach aufgerufen, z. B. in index.php, navbar.php, home-controller.php und search-results.php. Nach Login oder Registrierung wird keine neue Session-ID erzeugt (dies ist kein muss).

Findet in jedem Skript falls notwendig zunächst eine Authentifizierung angemeldeter Nutzer statt? Teilweise. createArticle-controller.php prüft bei direktem Aufruf nicht, ob ein Nutzer angemeldet ist. updateArticle-controller.php prüft ebenfalls nicht zu Beginn sauber die Authentifizierung. Die Authentifizierung liegt teilweise nur in der Formularseite, nicht im verarbeitenden Controller.

Ist bei „Eintrag bearbeiten/löschen“ sichergestellt, dass nur der Eigentümer den Eintrag verändern kann? Beinahe vollständig. Die eigentliche Aktualisierung prüft den Autor. Das Bearbeitungsformular updateArticle.php kann aber von jedem eingeloggten Nutzer mit fremder Artikel-ID geöffnet werden.

Werden in jedem Skript alle GET- bzw. POST-Parameter überprüft und ggf. auf Validität überprüft? Nein. pfad in index.php wird nicht per Whitelist validiert. id in showArticle-controller.php und updateArticle-controller.php wird nicht als gültige numerische ID geprüft. sort in search-results-controller.php wird nicht gegen erlaubte Werte validiert.

Werden bei Eingabefehlern durch den Nutzer die von ihm eingegebenen Daten bei der erneuten Formularanzeige übernommen? Teilweise. In createArticle.php wird old_category zwar gespeichert, aber nicht wieder im Dropdown ausgewählt (in updateArticle.php als TODO vermerkt). Beim Login wird die eingegebene E-Mail-Adresse nach einem Fehler nicht erneut angezeigt.

Wird eine adäquate Überprüfung von potentiellen Fehlern und Fehlerbehandlung durchgeführt? Teilweise. LocalArticleManager::saveArticle() prüft nicht, ob file_put_contents() erfolgreich war. getAllArticles() ignoriert fehlerhaftes JSON und gibt dann einfach ein leeres Array zurück. home-controller.php gibt im Fehlerfall direkt die Exception-Message aus.

Erfolgen bei Aktionen des Nutzers sowohl positive als auch negative Meldungen auf der nachfolgend angezeigten Seite? Teilweise. Nach erfolgreichem Login oder Registrierung gibt es keine sichtbare Erfolgsmeldung. Nach erfolgreicher Profiländerung gibt es ebenfalls keine positive Meldung. Beim Löschen des Accounts erfolgt nur eine Weiterleitung ohne Feedback.

Werden alle Eingabedaten beim Einbau in die HTML-Seite mit htmlspecialchars bzw. htmlentities HTML-kodiert? Beinahe vollständig. In home.php werden die Titel der Dummy-/Artikel-Links ohne htmlspecialchars() ausgegeben.

Werden alle Eingabedaten beim Einbau in eine URL mit urlencode URL-kodiert? Ok. Artikel-IDs werden mehrfach direkt in URLs eingesetzt, z. B. in profile.php, search-results.php und showCategory.php (Anmerkung: Rechne ich hier nicht negativ an). Auch die Formular-Action in updateArticle.php baut die ID ohne urlencode() in die URL ein (rechne ich ebenfalls nicht negativ an).
2026-06-17 11:58:49 +02:00
niklas.ortmann 4321c4bee5 home zeigt nun dynamisch die Kategorien an 2026-06-17 11:31:23 +02:00
niklas.ortmann d1b3641754 Update dataSources.local.xml 2026-06-17 11:11:19 +02:00
niklas.ortmann 5281c1bc7d Merge branch 'erweiterterEditor' into dev 2026-06-17 10:30:01 +02:00
niklas.ortmann aae78bf479 Update ArticleManager.php 2026-06-17 10:24:48 +02:00
niklas.ortmann af17764346 Merge pull request 'Forum implementiert' (#34) from Forum into dev
Reviewed-on: #34
Reviewed-by: niklas.ortmann <ortmann.niklas@yahoo.de>
2026-06-17 10:24:24 +02:00
caroline.slt a8d321609d Reviewänderungen 2026-06-16 22:31:49 +02:00
caroline.slt 23ccbe2d02 Reviewänderungen 2026-06-16 22:09:17 +02:00
caroline.slt 47239016c5 Fehlerbehebung 2026-06-16 00:02:06 +02:00
caroline.slt f4f6960b9d Kommentare im Profil anzeigen 2026-06-15 23:55:10 +02:00
caroline.slt c4c299eed6 Fehlerbehebung 2026-06-15 23:41:28 +02:00
caroline.slt e20b59b43d Kommentarfunktion für Nutzer einschränken 2026-06-15 23:22:00 +02:00
caroline.slt 901232b683 Antwortmöglichkeit 2026-06-15 22:59:44 +02:00
caroline.slt 40c5fa69f5 Antwortmöglichkeit 2026-06-15 22:58:22 +02:00
caroline.slt 7694396454 Antwortmöglichkeit 2026-06-15 22:56:00 +02:00
caroline.slt dafc149bba Antwortmöglichkeit 2026-06-15 22:50:55 +02:00
caroline.slt f23ec27247 Antwortmöglichkeit 2026-06-15 22:47:50 +02:00
caroline.slt efb179dec2 Antwortmöglichkeit 2026-06-15 22:41:05 +02:00
caroline.slt 86222aa92e Antwortmöglichkeit 2026-06-15 22:37:50 +02:00
caroline.slt a5fb5cd360 Antwortmöglichkeit 2026-06-15 22:35:42 +02:00
caroline.slt 6f6e53a483 Antwortmöglichkeit 2026-06-15 22:32:00 +02:00
caroline.slt f13a2c6f1e css design 2026-06-15 22:17:44 +02:00
caroline.slt 59012cacfb css design 2026-06-15 22:14:51 +02:00
caroline.slt 21c5471d73 fehlerkorrektur 2026-06-15 22:08:46 +02:00
caroline.slt e1ee70b46f ajax implementiert 2026-06-15 21:54:06 +02:00
caroline.slt eb56b8d6a0 Implementierung 2026-06-15 21:45:17 +02:00
niklas.ortmann d597046f41 Merge pull request 'Paginator in der search-results implementiert mit js' (#32) from Search_Paginator into dev
Reviewed-on: #32
2026-06-14 23:42:29 +02:00
niklas.ortmann ae1c873536 Merge pull request 'Beitrag erstellen oder bearbeiten: Bei einer Fehlermeldung wird die Kategorie nicht mehr zurückgesetzt' (#31) from bugfix_KategorieNichtZuruecksetzen into dev
Reviewed-on: #31
2026-06-14 23:42:20 +02:00
niklas.ortmann 1f7a2a77f6 dummy-Einträge 2026-06-14 23:37:42 +02:00
niklas.ortmann 9269465f6b Update README.md 2026-06-14 23:37:30 +02:00
niklas.ortmann 883adfd242 Update updateArticle-controller.php 2026-06-14 23:32:33 +02:00
niklas.ortmann 1e890f9a28 Update updateArticle-controller.php 2026-06-14 23:31:42 +02:00
niklas.ortmann 2bb13d2e8c revert f3f042b3b9
revert debugging
2026-06-14 23:30:32 +02:00
niklas.ortmann cb02e05d55 Update createArticle-controller.php 2026-06-14 23:27:30 +02:00
niklas.ortmann 05777f6109 revert 7d9aae2a59
revert Update createArticle-controller.php
2026-06-14 23:25:55 +02:00
niklas.ortmann f3f042b3b9 debugging 2026-06-14 23:16:26 +02:00
niklas.ortmann dfb13b1f96 Update editor.js 2026-06-14 23:13:46 +02:00
niklas.ortmann 6fa5038589 Update editor.js 2026-06-14 23:09:49 +02:00
niklas.ortmann 55f53e3346 Update editor.js 2026-06-14 23:06:00 +02:00
niklas.ortmann f36037d36d debugging 2026-06-14 23:02:53 +02:00
niklas.ortmann 500bca80c1 Update editor.js 2026-06-14 23:00:21 +02:00
niklas.ortmann fc0361ed3a debugging 2026-06-14 23:00:19 +02:00
niklas.ortmann df1485ce49 Update updateArticle-controller.php 2026-06-14 22:53:49 +02:00
niklas.ortmann b8bceb31c6 debugging 2026-06-14 22:51:05 +02:00
niklas.ortmann f0308c3505 Update updateArticle.php 2026-06-14 22:49:48 +02:00
niklas.ortmann e7ece1ed13 Update updateArticle-controller.php 2026-06-14 22:47:05 +02:00
niklas.ortmann 8ed7f7ec8f gelöschte Bilder entfernen 2026-06-14 22:41:16 +02:00
niklas.ortmann feaef4a624 gelöschte Bilder aus /uploads löschen 2026-06-14 22:23:06 +02:00
niklas.ortmann 7d9aae2a59 Update createArticle-controller.php 2026-06-14 22:18:08 +02:00
niklas.ortmann a88f8ca638 Update updateArticle-controller.php 2026-06-14 22:12:12 +02:00
niklas.ortmann be6a5f9add Update article-validator.php 2026-06-14 22:12:10 +02:00
niklas.ortmann ed4498578d Update alertMessages.php 2026-06-14 22:10:13 +02:00
niklas.ortmann 118be50b3c Update alertMessages.php 2026-06-14 22:01:15 +02:00
niklas.ortmann 1e2184ae20 Update showArticle.php 2026-06-14 22:01:14 +02:00
niklas.ortmann 8c1e1a64bf Update article-validator.php 2026-06-14 21:59:19 +02:00
niklas.ortmann b9c28968fe Create .htaccess 2026-06-14 21:54:35 +02:00
niklas.ortmann 703d8d7519 Update editor.js 2026-06-14 21:50:28 +02:00
niklas.ortmann 8e52d99ba4 Update updateArticle-controller.php 2026-06-14 21:42:58 +02:00
niklas.ortmann d4020671c1 updateArticle 2026-06-14 21:39:09 +02:00
niklas.ortmann 5c432e5801 showArticle-Anpassungen 2026-06-14 13:09:38 +02:00
niklas.ortmann aac13297de testing 2026-06-14 13:05:55 +02:00
niklas.ortmann f60a4a4f60 Update article-validator.php 2026-06-14 13:05:20 +02:00
niklas.ortmann 0ed4de74b0 Update createArticle-controller.php 2026-06-14 13:03:14 +02:00
niklas.ortmann 48bd26342a debugging 2026-06-14 12:59:58 +02:00
niklas.ortmann b8e884a5aa Update createArticle-controller.php 2026-06-14 12:53:46 +02:00
niklas.ortmann 1dbef5ca4b Update createArticle-controller.php 2026-06-14 12:42:29 +02:00
niklas.ortmann e43ae7f96a Update editor.js 2026-06-14 11:01:13 +02:00
niklas.ortmann eab256d17f Update editor.js 2026-06-14 10:59:10 +02:00
niklas.ortmann bbdcbbf0ce Update editor.js 2026-06-14 10:55:33 +02:00
niklas.ortmann ec9bc3fe1f css 2026-06-14 10:53:21 +02:00
niklas.ortmann 80f92a384e erweiterter Beitragseditor
content ist nun im json-Format
Bilder können hochgeladen werden
Textblöcke können im Editor angehangen werden
2026-06-14 10:44:17 +02:00
niklas.ortmann f9c1c67a38 Update ArticleManager.php 2026-06-13 11:58:25 +02:00
NOrtmann1 f2ef3c08a7 Update createArticle.php 2026-06-11 15:36:45 +02:00
NOrtmann1 8a66e8af3f Update updateArticle.php 2026-06-11 12:25:18 +02:00
NOrtmann1 41d1cc6013 Update updateArticle.php 2026-06-11 12:12:40 +02:00
NOrtmann1 c9c6a4ae81 Update dataSources.local.xml 2026-06-11 12:12:35 +02:00
26 changed files with 2034 additions and 161 deletions
+4 -1
View File
@@ -7,7 +7,7 @@
## Login-Informationen für Dummy-User ## Login-Informationen für Dummy-User
`Anmeldename, Passwort, Mailadresse`: `Anmeldename, Passwort, Mailadresse`:
- `max.mustermann, test12345, mustermann@web.de` - `max.mustermann, test12345, max.mustermann@web.de`
## Weitere Voraussetzungen zur Nutzung ## Weitere Voraussetzungen zur Nutzung
- Per Klick auf das Logo gelangt man auf die Home-Seite. - Per Klick auf das Logo gelangt man auf die Home-Seite.
@@ -18,6 +18,9 @@
- Bitte auf die gesetzten TODO's achten. Wenn Inhalte fehlen, sind sie i.d.R. als TODO kommentiert. - 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 - Die Suchseite und Kategorieseite packen momentan alle passenden Beiträge untereinander. Später sollen zunächst 10
Ergebnisse auf einer Seite angezeigt werden. 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.
- id in showArticle-controller.php und updateArticle-controller.php wird nicht als gültige numerische ID geprüft.
- sort in search-results-controller.php wird nicht gegen erlaubte Werte validiert.
## Besonderheiten des Projektes ## Besonderheiten des Projektes
- Es wurde ein einfacher Beitrags-Editor erstellt. Mit diesem können Beiträge erstellt oder bearbeitet werden. - Es wurde ein einfacher Beitrags-Editor erstellt. Mit diesem können Beiträge erstellt oder bearbeitet werden.
+214 -28
View File
@@ -17,8 +17,28 @@ if (!isset($_SESSION["user"])) {
<input type="text" id="title" name="title" <input type="text" id="title" name="title"
value="<?php echo htmlspecialchars($_SESSION['old_title'] ?? ''); unset($_SESSION['old_title']); ?>" value="<?php echo htmlspecialchars($_SESSION['old_title'] ?? ''); unset($_SESSION['old_title']); ?>"
placeholder="Titel hier eingeben" required> 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> </main>
<!-- Seitenleiste --> <!-- Seitenleiste -->
@@ -31,45 +51,211 @@ if (!isset($_SESSION["user"])) {
<div class="sidebar-block"> <div class="sidebar-block">
<label for="category">Kategorie <span class="required">*</span></label> <label for="category">Kategorie <span class="required">*</span></label>
<select id="category" name="category" required> <select id="category" name="category" required>
<option value="" 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"> <optgroup label="Sprachen">
<option value="deutsch">Deutsch</option> <option value="deutsch" <?php
<option value="englisch">Englisch</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="franzoesisch">Französisch</option> if ($_SESSION['old_category'] === 'deutsch') { echo 'selected'; }
<option value="latein">Latein</option> } elseif (isset($category) && !empty($category)) {
<option value="literatur">Literatur</option> 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>
<optgroup label="MINT"> <optgroup label="MINT">
<option value="mathe">Mathematik</option> <option value="mathe" <?php
<option value="biologie">Biologie</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="chemie">Chemie</option> if ($_SESSION['old_category'] === 'mathe') { echo 'selected'; }
<option value="physik">Physik</option> } elseif (isset($category) && !empty($category)) {
<option value="informatik">Informatik</option> if ($category === 'mathe') { echo 'selected'; }
<option value="astronomie">Astronomie</option> }
?>>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>
<optgroup label="Gesellschaft & Werte"> <optgroup label="Gesellschaft & Werte">
<option value="geschichte">Geschichte</option> <option value="geschichte" <?php
<option value="erdkunde">Erdkunde</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="sozialkunde">Sozialkunde</option> if ($_SESSION['old_category'] === 'geschichte') { echo 'selected'; }
<option value="wirtschaft">Wirtschaftskunde</option> } elseif (isset($category) && !empty($category)) {
<option value="religion">Religion</option> if ($category === 'geschichte') { echo 'selected'; }
<option value="ethik">Ethikunterricht</option> }
<option value="philosophie">Philosophie</option> ?>>Geschichte</option>
<option value="psychologie">Psychologie</option> <option value="erdkunde" <?php
<option value="kunst">Kunst</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="musik">Musik</option> if ($_SESSION['old_category'] === 'erdkunde') { echo 'selected'; }
<option value="theater">Theater</option> } 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>
<optgroup label="Technik & Praxis"> <optgroup label="Technik & Praxis">
<option value="technik">Technik</option> <option value="technik" <?php
<option value="werken">Werken</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="hauswirtschaft">Hauswirtschaft</option> if ($_SESSION['old_category'] === 'technik') { echo 'selected'; }
<option value="sport">Sport</option> } 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> </optgroup>
<?php
if (isset($_SESSION['old_category'])) {
unset($_SESSION['old_category']);
}
?>
</select> </select>
</div> </div>
+27 -21
View File
@@ -19,28 +19,34 @@ include_once 'php/controller/home-controller.php';
sea takimata sanctus est Lorem ipsum dolor sit amet. sea takimata sanctus est Lorem ipsum dolor sit amet.
</p> </p>
<!-- Flexbox --> <!-- Flexbox für aktive Kategorien -->
<div class="flexbox"> <div class="flexbox">
<div class="container"> <?php
<a href="index.php?pfad=showCategory&category=informatik" class="category-link">Informatik</a> if (!empty($categoriesWithArticles) && is_array($categoriesWithArticles)):
<div class="article-link"> foreach ($categoriesWithArticles as $category):
<a href="index.php?pfad=showArticle&id=<?php echo $dummy3->getId()?>"><?php if(isset($dummy3)){echo $dummy3->getTitle();}else{echo "Fehler: Beitrag nicht gefunden!";} ?></a> ?>
</div> <div class="container">
</div> <a href="index.php?pfad=showCategory&category=<?php echo htmlspecialchars($category['slug']); ?>" class="category-link">
<?php echo htmlspecialchars($category['name']); ?>
</a>
<div class="container"> <!-- die 5 neuesten Beiträge der Kategorie -->
<a href="index.php?pfad=showCategory&category=mathe" class="category-link">Mathe</a> <div class="article-links-wrapper">
<div class="article-link"> <?php foreach ($category['articles'] as $article): ?>
<a href="index.php?pfad=showArticle&id=<?php echo $dummy1->getId()?>"><?php if(isset($dummy1)){echo $dummy1->getTitle();}else{echo "Fehler: Beitrag nicht gefunden!";} ?></a> <div class="article-link">
</div> <a href="index.php?pfad=showArticle&id=<?php echo htmlspecialchars($article->getId()); ?>">
</div> <?php echo htmlspecialchars($article->getTitle()); ?>
</a>
<div class="container"> </div>
<a href="index.php?pfad=showCategory&category=physik" class="category-link">Physik</a> <?php endforeach; ?>
<div class="article-link"> </div>
<a href="index.php?pfad=showArticle&id=<?php echo $dummy2->getId()?>"><?php if(isset($dummy2)){echo $dummy2->getTitle();}else{echo "Fehler: Beitrag nicht gefunden!";} ?></a> </div>
</div> <?php
</div> endforeach;
else:
?>
<p>Aktuell sind keine Beiträge in den Kategorien vorhanden.</p>
<?php endif; ?>
</div> </div>
</main> </main>
+50 -7
View File
@@ -7,8 +7,8 @@ $isEditMode = (isset($_GET["edit"]) && $_GET["edit"] === "1") || !empty($error);
<main class="form-page"> <main class="form-page">
<div class="flexbox"> <div class="flexbox">
<div class="container"> <div class="container">
<?php include_once "includes/alertMessages.php" ?>
<?php if (!empty($error)): ?> <?php if (!empty($error)): ?>
<p class="alert-message is-error"> <p class="alert-message is-error">
@@ -93,8 +93,6 @@ $isEditMode = (isset($_GET["edit"]) && $_GET["edit"] === "1") || !empty($error);
<div class="container"> <div class="container">
<?php include_once "includes/alertMessages.php"?>
<h2 class="section-title">Meine Beiträge</h2> <h2 class="section-title">Meine Beiträge</h2>
<div class="articles-list"> <div class="articles-list">
@@ -157,7 +155,9 @@ $isEditMode = (isset($_GET["edit"]) && $_GET["edit"] === "1") || !empty($error);
</a> </a>
<form action="php/controller/deleteArticle-controller.php" method="POST"> <form action="php/controller/deleteArticle-controller.php" method="POST">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($userArticle->getID()); ?>"> <input type="hidden"
name="id"
value="<?php echo htmlspecialchars($userArticle->getID()); ?>">
<button type="submit" <button type="submit"
class="button" class="button"
@@ -165,7 +165,6 @@ $isEditMode = (isset($_GET["edit"]) && $_GET["edit"] === "1") || !empty($error);
Löschen Löschen
</button> </button>
</form> </form>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
@@ -180,10 +179,54 @@ $isEditMode = (isset($_GET["edit"]) && $_GET["edit"] === "1") || !empty($error);
</button> </button>
<?php endif; ?> <?php endif; ?>
<?php unset($_SESSION["message"]); ?>
</div> </div>
</div> </div>
<div class="container">
<div class="comments-section">
<h2 class="section-title">Meine Kommentare</h2>
<!-- Liste aller Kommentare des Nutzers -->
<div class="comments-list">
<?php if (isset($userComments) && count($userComments) > 0): ?>
<?php foreach ($userComments as $comment): ?>
<div class="article-item">
<!-- Erstellungsdatum des Kommentars -->
<div class="article-meta">
<span class="article-date">
<?php echo htmlspecialchars($comment->getCreated()); ?>
</span>
</div>
<!-- Inhalt des Kommentars -->
<p>
<?php echo nl2br(htmlspecialchars($comment->getContent())); ?>
</p>
<!-- Link zum Beitrag, unter dem der Kommentar geschrieben wurde -->
<a href="index.php?pfad=showArticle&id=<?php echo htmlspecialchars($comment->getArticleId()); ?>"
class="edit-link-button">
Zum Beitrag
</a>
</div>
<?php endforeach; ?>
<?php else: ?>
<p>Du hast noch keine Kommentare geschrieben.</p>
<?php endif; ?>
</div>
</div>
</div>
<?php unset($_SESSION["message"]); ?>
</div> </div>
</main> </main>
+130 -31
View File
@@ -1,37 +1,36 @@
<?php <?php
include_once 'php/controller/showArticle-controller.php'; include_once 'php/controller/showArticle-controller.php';
require_once 'php/model/CommentManager.php';
$comments = [];
$mainComments = [];
$repliesByParent = [];
if (isset($_GET["id"])) {
try {
$commentManager = CommentManager::getInstance();
$comments = $commentManager->getCommentsByArticle($_GET["id"]);
foreach ($comments as $comment) {
if ($comment->isReply()) {
$parentId = $comment->getParentCommentId();
$repliesByParent[$parentId][] = $comment;
} else {
$mainComments[] = $comment;
}
}
} catch (Exception $e) {
$_SESSION["message"] = "internal_error";
}
}
?> ?>
<!-- <!--
Seite: Anzeige für Beiträge Seite: Anzeige für Beiträge
Funktion: Stellt einen übergebenen Beitrag dar. Funktion: Stellt einen übergebenen Beitrag dar.
--> -->
<!-- Hauptcontainer für die Beitragsansicht (Ausschließlich der Content-Bereich) --> <!-- Hauptcontainer für die Beitragsansicht (Ausschließlich der Content-Bereich) -->
<main class="article-view-container"> <main class="article-view-container">
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?> <?php include_once "includes/alertMessages.php"?>
<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"]);
?>
<!-- Metadaten & Titel --> <!-- Metadaten & Titel -->
<div class="article-view-top-section"> <div class="article-view-top-section">
@@ -39,6 +38,7 @@ include_once 'php/controller/showArticle-controller.php';
<?php if (isset($category) && !empty($category)): ?> <?php if (isset($category) && !empty($category)): ?>
<span class="article-view-category"><?php echo htmlspecialchars($category); ?></span> <span class="article-view-category"><?php echo htmlspecialchars($category); ?></span>
<?php endif; ?> <?php endif; ?>
<h1 class="article-view-title"> <h1 class="article-view-title">
<?php if (isset($title)) { echo htmlspecialchars($title); } ?> <?php if (isset($title)) { echo htmlspecialchars($title); } ?>
</h1> </h1>
@@ -54,8 +54,33 @@ include_once 'php/controller/showArticle-controller.php';
<!-- Beitrags-Inhalt --> <!-- Beitrags-Inhalt -->
<div class="article-view-content"> <div class="article-view-content">
<?php if (isset($content)): ?> <?php if (isset($content)): ?>
<!-- nl2br für Zeilenumbrüche --> <?php
<div class="article-view-body"><?php echo nl2br(htmlspecialchars($content)); ?></div> // 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; ?> <?php endif; ?>
</div> </div>
@@ -80,5 +105,79 @@ include_once 'php/controller/showArticle-controller.php';
</div> </div>
<?php endif; ?> <?php endif; ?>
</main> <section class="article-comments-section">
<h2>Kommentare</h2>
<div id="comments-list">
<?php if (!empty($mainComments)): ?>
<?php foreach ($mainComments as $comment): ?>
<div class="comment-item" data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>">
<p>
<strong><?php echo htmlspecialchars($comment->getAuthor()); ?></strong>
<span><?php echo htmlspecialchars($comment->getCreated()); ?></span>
</p>
<p><?php echo nl2br(htmlspecialchars($comment->getContent())); ?></p>
<?php if (isset($_SESSION["user_email"])): ?>
<button type="button"
class="reply-button"
data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>"
data-author="<?php echo htmlspecialchars($comment->getAuthor()); ?>">
Antworten
</button>
<?php endif; ?>
<div class="comment-replies">
<?php if (isset($repliesByParent[$comment->getId()])): ?>
<?php foreach ($repliesByParent[$comment->getId()] as $reply): ?>
<div class="comment-item comment-reply">
<p>
<strong><?php echo htmlspecialchars($reply->getAuthor()); ?></strong>
<span><?php echo htmlspecialchars($reply->getCreated()); ?></span>
</p>
<p><?php echo nl2br(htmlspecialchars($reply->getContent())); ?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p class="no-comments-message">
Noch keine Kommentare vorhanden.
</p>
<?php endif; ?>
</div>
<?php if (isset($_SESSION["user_email"])): ?>
<form id="comment-form">
<input type="hidden"
name="article_id"
value="<?php echo htmlspecialchars($_GET["id"] ?? ""); ?>">
<input type="hidden"
name="parent_comment_id"
id="parent-comment-id"
value="">
<p id="reply-info" class="reply-info" style="display: none;"></p>
<textarea name="content"
id="comment-content"
placeholder="Schreibe einen Kommentar..."
required></textarea>
<button type="submit" class="button">
Kommentar senden
</button>
</form>
<?php else: ?>
<div class="comment-login-hint">
<p>Melde dich an, um einen Kommentar zu schreiben.</p>
<a href="index.php?pfad=login" class="button">Jetzt anmelden</a>
</div>
<?php endif; ?>
</section>
</main>
+220 -29
View File
@@ -10,7 +10,7 @@ include_once 'php/controller/showArticle-controller.php';
Seite: Beitrag erstellen Seite: Beitrag erstellen
Inhalt: Formular für die Erstellung eines neuen Beitrags 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"> <main class="editor-main">
<?php include_once "includes/alertMessages.php"?> <?php include_once "includes/alertMessages.php"?>
@@ -26,8 +26,33 @@ include_once 'php/controller/showArticle-controller.php';
?>" ?>"
placeholder="Titel hier eingeben" required> 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> </main>
<!-- Seitenleiste --> <!-- Seitenleiste -->
@@ -40,45 +65,211 @@ include_once 'php/controller/showArticle-controller.php';
<div class="sidebar-block"> <div class="sidebar-block">
<label for="category">Kategorie <span class="required">*</span></label> <label for="category">Kategorie <span class="required">*</span></label>
<select id="category" name="category" required> <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"> <optgroup label="Sprachen">
<option value="deutsch">Deutsch</option> <option value="deutsch" <?php
<option value="englisch">Englisch</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="franzoesisch">Französisch</option> if ($_SESSION['old_category'] === 'deutsch') { echo 'selected'; }
<option value="latein">Latein</option> } elseif (isset($category) && !empty($category)) {
<option value="literatur">Literatur</option> 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>
<optgroup label="MINT"> <optgroup label="MINT">
<option value="mathe">Mathematik</option> <option value="mathe" <?php
<option value="biologie">Biologie</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="chemie">Chemie</option> if ($_SESSION['old_category'] === 'mathe') { echo 'selected'; }
<option value="physik">Physik</option> } elseif (isset($category) && !empty($category)) {
<option value="informatik">Informatik</option> if ($category === 'mathe') { echo 'selected'; }
<option value="astronomie">Astronomie</option> }
?>>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>
<optgroup label="Gesellschaft & Werte"> <optgroup label="Gesellschaft & Werte">
<option value="geschichte">Geschichte</option> <option value="geschichte" <?php
<option value="erdkunde">Erdkunde</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="sozialkunde">Sozialkunde</option> if ($_SESSION['old_category'] === 'geschichte') { echo 'selected'; }
<option value="wirtschaft">Wirtschaftskunde</option> } elseif (isset($category) && !empty($category)) {
<option value="religion">Religion</option> if ($category === 'geschichte') { echo 'selected'; }
<option value="ethik">Ethikunterricht</option> }
<option value="philosophie">Philosophie</option> ?>>Geschichte</option>
<option value="psychologie">Psychologie</option> <option value="erdkunde" <?php
<option value="kunst">Kunst</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="musik">Musik</option> if ($_SESSION['old_category'] === 'erdkunde') { echo 'selected'; }
<option value="theater">Theater</option> } 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>
<optgroup label="Technik & Praxis"> <optgroup label="Technik & Praxis">
<option value="technik">Technik</option> <option value="technik" <?php
<option value="werken">Werken</option> if (isset($_SESSION['old_category']) && !empty($_SESSION['old_category'])) {
<option value="hauswirtschaft">Hauswirtschaft</option> if ($_SESSION['old_category'] === 'technik') { echo 'selected'; }
<option value="sport">Sport</option> } 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> </optgroup>
<?php
if (isset($_SESSION['old_category'])) {
unset($_SESSION['old_category']);
}
?>
</select> </select>
</div> </div>
+133
View File
@@ -90,6 +90,135 @@
padding: 18px 12px; 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) */ /* Responsive Anpassungen unter 760px (für z.B. Smartphones) */
@media (max-width: 760px) { @media (max-width: 760px) {
.article-editor-scope.editor-container { .article-editor-scope.editor-container {
@@ -113,4 +242,8 @@
border-left: none; border-left: none;
border-top: 1px solid #e0e0e0; border-top: 1px solid #e0e0e0;
} }
.article-editor-scope .editor-block textarea {
min-height: 150px;
}
} }
+124
View File
@@ -105,6 +105,37 @@
cursor: default; 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) */ /* Responsive Anpassungen unter 760px (für z.B. Smarticlephones) */
@media (max-width: 760px) { @media (max-width: 760px) {
.article-view-container { .article-view-container {
@@ -116,3 +147,96 @@
font-size: 1.85rem; font-size: 1.85rem;
} }
} }
/* --- KOMMENTARE --- */
.article-comments-section {
margin-top: 3rem;
padding-top: 2rem;
border-top: 1px solid #e2e8f0;
}
.article-comments-section h2 {
font-size: 2rem;
margin-bottom: 1.5rem;
}
#comments-list {
margin-bottom: 2rem;
}
.comment-item {
background-color: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 10px;
padding: 1rem 1.25rem;
margin-bottom: 1rem;
}
#comment-form {
width: 100%;
display: flex;
flex-direction: column;
gap: 1rem;
}
#comment-content {
width: 100%;
min-height: 130px;
padding: 1rem;
border: 1px solid #cbd5e1;
border-radius: 8px;
font-size: 1rem;
font-family: inherit;
resize: vertical;
}
#comment-form .button {
width: 100%;
}
.reply-button {
display: inline-block;
margin-top: 0.75rem;
background: none;
border: none;
color: #2563eb;
font-weight: 700;
cursor: pointer;
padding: 0;
font-size: 0.95rem;
}
.reply-button:hover {
text-decoration: underline;
}
.comment-replies {
margin-top: 1rem;
margin-left: 2rem;
padding-left: 1rem;
border-left: 3px solid #cbd5e1;
}
.comment-reply {
background-color: #eef6ff;
margin-top: 1rem;
}
.reply-info {
margin: 0.5rem 0;
color: #475569;
font-weight: 600;
}
.comment-login-hint {
margin-top: 2rem;
padding: 1.5rem;
background-color: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 10px;
text-align: center;
}
.comment-login-hint p {
margin-bottom: 1rem;
}
+16 -1
View File
@@ -15,7 +15,7 @@
<?php endif; ?> <?php endif; ?>
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_content"): ?> <?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_content"): ?>
<p class="alert-message is-error"> <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> </p>
<?php endif; ?> <?php endif; ?>
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_category"): ?> <?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "invalid_category"): ?>
@@ -63,6 +63,21 @@
Dein Beitrag wurde erfolgreich veröffentlicht! Dein Beitrag wurde erfolgreich veröffentlicht!
</p> </p>
<?php endif; ?> <?php endif; ?>
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "article_updated"): ?>
<p class="alert-message is-success">
Der Beitrag wurde erfolgreich bearbeitet und gespeichert.
</p>
<?php endif; ?>
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "profile_updated"): ?>
<p class="alert-message is-success">
Das Profil wurde erfolgreich bearbeitet.
</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 <?php
unset($_SESSION["message"]); unset($_SESSION["message"]);
?> ?>
+2
View File
@@ -53,6 +53,8 @@ if ($pfad === "deleteAccount") {
<link rel="stylesheet" href="css/message.css"> <link rel="stylesheet" href="css/message.css">
<script src="js/paginator.js" async></script> <script src="js/paginator.js" async></script>
<script src="js/comments.js" defer></script>
<script src="js/editor.js" async></script>
<title>EduForge</title> <title>EduForge</title>
</head> </head>
+137
View File
@@ -0,0 +1,137 @@
/**
* Initialisiert die Kommentarfunktion.
*
* Kommentare werden per AJAX gespeichert,
* ohne dass die Seite neu geladen werden muss.
*/
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("comment-form");
const commentsList = document.getElementById("comments-list");
const commentContent = document.getElementById("comment-content");
const parentCommentInput = document.getElementById("parent-comment-id");
const replyInfo = document.getElementById("reply-info");
if (!form || !commentsList || !commentContent || !parentCommentInput || !replyInfo) {
return;
}
/**
* Aktiviert einen einzelnen Antworten-Button.
*
* @param {HTMLButtonElement} button Antworten-Button
*/
function registerReplyButton(button) {
button.addEventListener("click", function () {
parentCommentInput.value = button.dataset.commentId;
replyInfo.textContent = "Antwort auf " + button.dataset.author;
replyInfo.style.display = "block";
commentContent.focus();
});
}
/**
* Registriert alle bereits vorhandenen Antwort-Buttons.
*/
document.querySelectorAll(".reply-button").forEach(function (button) {
registerReplyButton(button);
});
/**
* Sendet Kommentare per AJAX an den Server.
*/
form.addEventListener("submit", function (event) {
event.preventDefault();
const formData = new FormData(form);
const parentCommentId = parentCommentInput.value;
fetch("php/ajax/add-comment.php", {
method: "POST",
body: formData
})
.then(response => response.json())
.then(data => {
if (!data.success) {
alert(data.message);
return;
}
const emptyMessage = commentsList.querySelector(".no-comments-message");
if (emptyMessage) {
emptyMessage.remove();
}
const commentElement = document.createElement("div");
commentElement.classList.add("comment-item");
if (parentCommentId) {
commentElement.classList.add("comment-reply");
commentElement.innerHTML = `
<p>
<strong>${escapeHtml(data.author)}</strong>
<span>${escapeHtml(data.created)}</span>
</p>
<p>${escapeHtml(data.content).replace(/\n/g, "<br>")}</p>
`;
const parentReplies = document.querySelector(
`.comment-item[data-comment-id="${parentCommentId}"] .comment-replies`
);
if (parentReplies) {
parentReplies.appendChild(commentElement);
}
} else {
commentElement.dataset.commentId = data.commentId;
commentElement.innerHTML = `
<p>
<strong>${escapeHtml(data.author)}</strong>
<span>${escapeHtml(data.created)}</span>
</p>
<p>${escapeHtml(data.content).replace(/\n/g, "<br>")}</p>
<button type="button"
class="reply-button"
data-comment-id="${escapeHtml(data.commentId)}"
data-author="${escapeHtml(data.author)}">
Antworten
</button>
<div class="comment-replies"></div>
`;
commentsList.prepend(commentElement);
const newReplyButton = commentElement.querySelector(".reply-button");
if (newReplyButton) {
registerReplyButton(newReplyButton);
}
}
commentContent.value = "";
parentCommentInput.value = "";
replyInfo.textContent = "";
replyInfo.style.display = "none";
})
.catch(() => {
alert("Kommentar konnte nicht gesendet werden.");
});
});
/**
* Entfernt HTML-Sonderzeichen aus Nutzereingaben.
*
* @param {string} text Zu bereinigender Text
* @returns {string} Sicherer Text
*/
function escapeHtml(text) {
const div = document.createElement("div");
div.textContent = text;
return div.innerHTML;
}
});
+179
View File
@@ -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();
}
+58
View File
@@ -0,0 +1,58 @@
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
header("Content-Type: application/json");
require_once "../model/CommentManager.php";
if (!isset($_SESSION["user_email"])) {
echo json_encode([
"success" => false,
"message" => "Du musst angemeldet sein, um zu kommentieren."
]);
exit();
}
$articleId = $_POST["article_id"] ?? null;
$content = trim($_POST["content"] ?? "");
$parentCommentId = $_POST["parent_comment_id"] ?? null;
if ($parentCommentId === "" || $parentCommentId === "0") {
$parentCommentId = null;
}
if (empty($articleId) || empty($content)) {
echo json_encode([
"success" => false,
"message" => "Kommentar darf nicht leer sein."
]);
exit();
}
try {
$commentManager = CommentManager::getInstance();
$commentId = $commentManager->addComment(
$articleId,
$_SESSION["user_email"],
$content,
$parentCommentId
);
echo json_encode([
"success" => true,
"commentId" => $commentId,
"author" => $_SESSION["user_email"],
"content" => $content,
"created" => date("Y-m-d H:i:s"),
"parentCommentId" => $parentCommentId
]);
} catch (Exception $e) {
echo json_encode([
"success" => false,
"message" => "Kommentar konnte nicht gespeichert werden."
]);
}
+58 -10
View File
@@ -6,6 +6,10 @@ require_once '../model/LocalArticleManager.php';
require_once '../model/ArticleManager.php'; require_once '../model/ArticleManager.php';
require_once '../validator/article-validator.php'; require_once '../validator/article-validator.php';
if (!isset($_SESSION["user"])) {
header("Location: index.php?pfad=login");
exit();
}
if ($_SERVER["REQUEST_METHOD"] === "POST") { if ($_SERVER["REQUEST_METHOD"] === "POST") {
$_SESSION["old_title"] = $_POST["title"] ?? ''; $_SESSION["old_title"] = $_POST["title"] ?? '';
$_SESSION["old_content"] = $_POST["content"] ?? ''; $_SESSION["old_content"] = $_POST["content"] ?? '';
@@ -24,12 +28,6 @@ require_once '../validator/article-validator.php';
$tags = $_POST['tags'] ?? ''; $tags = $_POST['tags'] ?? '';
// -------------------------------- Validierung der Daten: ------------------------- // -------------------------------- Validierung der Daten: -------------------------
if (!articleAuthorValidator($author)) {
$_SESSION["message"] = "author_not_valid";
header("location: ../../index.php?pfad=createArticle");
exit();
}
if (!articleTitleValidator($title)) { if (!articleTitleValidator($title)) {
$_SESSION["message"] = "invalid_title"; $_SESSION["message"] = "invalid_title";
header("location: ../../index.php?pfad=createArticle"); header("location: ../../index.php?pfad=createArticle");
@@ -64,6 +62,59 @@ require_once '../validator/article-validator.php';
$cleanedTags = array_unique($cleanedTags); $cleanedTags = array_unique($cleanedTags);
$cleanedTags = implode(',', $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: --------------------------- // ----------------- Übertragung der validierten Daten in ArticleManager: ---------------------------
try { try {
$articleManager = ArticleManager::getInstance(); $articleManager = ArticleManager::getInstance();
@@ -72,7 +123,7 @@ require_once '../validator/article-validator.php';
// Formulardaten nach erfolgreichem Erstellen aus der Session löschen // Formulardaten nach erfolgreichem Erstellen aus der Session löschen
unset($_SESSION["old_title"], $_SESSION["old_content"], $_SESSION["old_category"], $_SESSION["old_tags"]); unset($_SESSION["old_title"], $_SESSION["old_content"], $_SESSION["old_category"], $_SESSION["old_tags"]);
} catch (Exception $e){ } catch (\Throwable $e){
$_SESSION["message"] = "internal_error"; $_SESSION["message"] = "internal_error";
header("location: ../../index.php?pfad=createArticle"); header("location: ../../index.php?pfad=createArticle");
exit(); exit();
@@ -84,7 +135,4 @@ require_once '../validator/article-validator.php';
exit(); exit();
} }
} }
?> ?>
@@ -6,6 +6,11 @@ if (session_status() === PHP_SESSION_NONE) {
require_once __DIR__ . "/../model/UserManager.php"; require_once __DIR__ . "/../model/UserManager.php";
require_once __DIR__ . "/../model/ArticleManager.php"; require_once __DIR__ . "/../model/ArticleManager.php";
if (!isset($_SESSION["user"])) {
header("Location: index.php?pfad=login");
exit();
}
/* /*
Deregistrierung Deregistrierung
Funktion: Entfernt User aus der Datenbank und beendet die Session Funktion: Entfernt User aus der Datenbank und beendet die Session
@@ -5,6 +5,11 @@ if (session_status() === PHP_SESSION_NONE) {
require_once __DIR__ . "/../model/ArticleManager.php"; require_once __DIR__ . "/../model/ArticleManager.php";
if (!isset($_SESSION["user"])) {
header("Location: index.php?pfad=login");
exit();
}
if ($_SERVER["REQUEST_METHOD"] === "POST") { if ($_SERVER["REQUEST_METHOD"] === "POST") {
if (isset($_SESSION["user_email"])) { if (isset($_SESSION["user_email"])) {
+35 -5
View File
@@ -6,14 +6,44 @@ require_once 'php/model/Article.php';
require_once 'php/model/ArticleManager.php'; require_once 'php/model/ArticleManager.php';
require_once 'php/model/LocalArticleManager.php'; require_once 'php/model/LocalArticleManager.php';
$categoriesWithArticles = [];
$allowedCategories = [
'deutsch', 'englisch', 'franzoesisch', 'latein', 'literatur',
'mathe', 'biologie', 'chemie', 'physik', 'informatik', 'astronomie',
'geschichte', 'erdkunde', 'sozialkunde', 'wirtschaft', 'religion',
'ethik', 'philosophie', 'psychologie', 'kunst', 'musik', 'theater',
'technik', 'werken', 'hauswirtschaft', 'sport'
];
try { try {
$articleManager = ArticleManager::getInstance(); $articleManager = ArticleManager::getInstance();
// Beziehen der Dummy-Beiträge aus dem ArticleManager:
$dummy1 = $articleManager->getArticle(1); foreach ($allowedCategories as $categorySlug) {
$dummy2 = $articleManager->getArticle(2); $allCategoryArticles = $articleManager->getArticlesByCategory($categorySlug);
$dummy3 = $articleManager->getArticle(3);
// nur Kategorien, die Beiträge enthält:
if (!empty($allCategoryArticles) && is_array($allCategoryArticles)) {
// Beiträge nach Erstellungsdatum sortieren:
usort($allCategoryArticles, function($a, $b) {
$dateA = strtotime($a->getCreationDate());
$dateB = strtotime($b->getCreationDate());
return $dateB <=> $dateA; // Absteigende Sortierung
});
// auf die 5 zuletzt hinzugefügten Beiträge begrenzen:
$limitedArticles = array_slice($allCategoryArticles, 0, 5);
$categoriesWithArticles[] = [
'slug' => $categorySlug,
'name' => ucfirst($categorySlug), // Erster Buchstabe groß für die Ansicht
'articles' => $limitedArticles
];
}
}
} catch (Exception $e){ } catch (Exception $e){
$_SESSION["message"] = "internal_error"; $_SESSION["message"] = "internal_error";
echo "Fehler aufgetreten: " . $e->getMessage();
} }
?> ?>
+5
View File
@@ -3,6 +3,7 @@
require_once "php/model/UserManager.php"; require_once "php/model/UserManager.php";
require_once "php/model/Article.php"; require_once "php/model/Article.php";
require_once "php/model/ArticleManager.php"; require_once "php/model/ArticleManager.php";
require_once "php/model/CommentManager.php";
require_once "php/validator/user-validator.php"; require_once "php/validator/user-validator.php";
$error = null; $error = null;
@@ -62,6 +63,7 @@ try {
$_SESSION["user"] = $vorname . " " . $nachname; $_SESSION["user"] = $vorname . " " . $nachname;
$_SESSION["user_email"] = $newEmail; $_SESSION["user_email"] = $newEmail;
$_SESSION["message"] = "profile_updated";
header("Location: index.php?pfad=profile"); header("Location: index.php?pfad=profile");
exit(); exit();
} else { } else {
@@ -76,6 +78,9 @@ try {
$articleManager = ArticleManager::getInstance(); $articleManager = ArticleManager::getInstance();
$userArticles = $articleManager->getArticlesByAuthor($_SESSION["user_email"]); $userArticles = $articleManager->getArticlesByAuthor($_SESSION["user_email"]);
$commentManager = CommentManager::getInstance();
$userComments = $commentManager->getCommentsByAuthor($_SESSION["user_email"]);
if (!isset($userArticles)) { if (!isset($userArticles)) {
$_SESSION["message"] = "user_has_no_articles"; $_SESSION["message"] = "user_has_no_articles";
} }
+96 -8
View File
@@ -8,6 +8,11 @@ require_once '../model/ArticleManager.php';
require_once '../model/Article.php'; require_once '../model/Article.php';
require_once '../validator/article-validator.php'; require_once '../validator/article-validator.php';
if (!isset($_SESSION["user"])) {
header("Location: index.php?pfad=login");
exit();
}
if ($_SERVER["REQUEST_METHOD"] === "POST") { if ($_SERVER["REQUEST_METHOD"] === "POST") {
$_SESSION["old_title"] = $_POST["title"] ?? ''; $_SESSION["old_title"] = $_POST["title"] ?? '';
$_SESSION["old_content"] = $_POST["content"] ?? ''; $_SESSION["old_content"] = $_POST["content"] ?? '';
@@ -22,6 +27,20 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
exit(); exit();
} }
try {
$articleManager = ArticleManager::getInstance();
$article = $articleManager->getArticle($id);
if ($article->getAuthor() != $_SESSION["user"]->getUsername()) {
$_SESSION["message"] = "unauthorized_access";
header("location: ../../index.php");
exit();
}
} catch (Exception $e) {
$_SESSION["message"] = $e->getMessage();
header("location: ../../index.php?pfad=updateArticle&id=$id");
exit();
}
if (!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){ if (!isset($_POST["title"]) ||!isset($_POST["content"]) || !isset($_POST["category"])){
$_SESSION["message"] = "missing_parameters"; $_SESSION["message"] = "missing_parameters";
header("location: ../../index.php?pfad=updateArticle&id=$id"); header("location: ../../index.php?pfad=updateArticle&id=$id");
@@ -34,12 +53,6 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
$tags = $_POST['tags'] ?? ''; $tags = $_POST['tags'] ?? '';
// -------------------------------- Validierung der Daten: ------------------------- // -------------------------------- Validierung der Daten: -------------------------
if (!articleAuthorValidator($author)) {
$_SESSION["message"] = "author_not_valid";
header("location: ../../index.php?pfad=updateArticle&id=$id");
exit();
}
if (!articleTitleValidator($title)) { if (!articleTitleValidator($title)) {
$_SESSION["message"] = "invalid_title"; $_SESSION["message"] = "invalid_title";
header("location: ../../index.php?pfad=updateArticle&id=$id"); header("location: ../../index.php?pfad=updateArticle&id=$id");
@@ -75,16 +88,91 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
$cleanedTags = implode(',', $cleanedTags); $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: --------------------------- // ----------------- Übertragung der validierten Daten in ArticleManager: ---------------------------
try { try {
$articleManager = ArticleManager::getInstance(); $articleManager = ArticleManager::getInstance();
$article = $articleManager->getArticle($id); $article = $articleManager->getArticle($id);
$article->setTitle($title); $article->setTitle($title);
$article->setContent($content); $article->setContent($finalContent);
$article->setCategory($category); $article->setCategory($category);
$article->setTags($cleanedTags); $article->setTags($cleanedTags);
$articleManager->updateArticle($id ,$article, $author); $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(); $_SESSION["message"] = $e->getMessage();
header("location: ../../index.php?pfad=updateArticle&id=$id"); header("location: ../../index.php?pfad=updateArticle&id=$id");
exit(); exit();
+10 -2
View File
@@ -13,7 +13,7 @@ class ArticleManager
/** /**
* Diese Methode erstellt, falls noch keine existiert, eine Instanz einer ArticleManager-Implementierung und * Diese Methode erstellt, falls noch keine existiert, eine Instanz einer ArticleManager-Implementierung und
* erstellt Dummy-Beiträge. * erstellt Dummy-Beiträge.
* *
* @throws InternalServerErrorException * @throws InternalServerErrorException
*/ */
public static function getInstance() 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) // Verteilt die 10 Autoren gleichmäßig (ID 1 -> Autor 1, ID 10 -> Autor 10, ID 11 -> Autor 1)
$authorEmail = $authors[($id - 1) % 10]; $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( $articleManager->addArticle(
$data[0], // Titel $data[0], // Titel
$data[1], // Inhalt $jsonContent, // Inhalt
$authorEmail, // Rotierende Autoren-E-Mail $authorEmail, // Rotierende Autoren-E-Mail
$data[2], // Kategorie $data[2], // Kategorie
$data[3] // Tags $data[3] // Tags
+115
View File
@@ -0,0 +1,115 @@
<?php
/**
* Repräsentiert einen Kommentar unter einem Beitrag.
*
* Ein Kommentar kann entweder ein Hauptkommentar sein
* oder eine Antwort auf einen anderen Kommentar.
*
* @author Caroline Schulte
*/
class Comment
{
private int $id;
private int $articleId;
private ?int $parentCommentId;
private string $author;
private string $content;
private string $created;
/**
* Erstellt einen neuen Kommentar.
*
* @param int $id Eindeutige ID des Kommentars
* @param int $articleId ID des zugehörigen Beitrags
* @param int|null $parentCommentId ID des Eltern-Kommentars oder null
* @param string $author Autor des Kommentars
* @param string $content Inhalt des Kommentars
* @param string $created Erstellungsdatum des Kommentars
*/
public function __construct(
int $id,
int $articleId,
?int $parentCommentId,
string $author,
string $content,
string $created
) {
$this->id = $id;
$this->articleId = $articleId;
$this->parentCommentId = $parentCommentId;
$this->author = $author;
$this->content = $content;
$this->created = $created;
}
/**
* Gibt die ID des Kommentars zurück.
*
* @return int Kommentar-ID
*/
public function getId(): int
{
return $this->id;
}
/**
* Gibt die ID des zugehörigen Beitrags zurück.
*
* @return int Beitrags-ID
*/
public function getArticleId(): int
{
return $this->articleId;
}
/**
* Gibt die ID des Eltern-Kommentars zurück.
*
* @return int|null ID des Eltern-Kommentars oder null
*/
public function getParentCommentId(): ?int
{
return $this->parentCommentId;
}
/**
* Gibt zurück, ob der Kommentar eine Antwort ist.
*
* @return bool true wenn der Kommentar eine Antwort ist, sonst false
*/
public function isReply(): bool
{
return $this->parentCommentId !== null && $this->parentCommentId !== 0;
}
/**
* Gibt den Autor des Kommentars zurück.
*
* @return string Autor
*/
public function getAuthor(): string
{
return $this->author;
}
/**
* Gibt den Inhalt des Kommentars zurück.
*
* @return string Kommentarinhalt
*/
public function getContent(): string
{
return $this->content;
}
/**
* Gibt das Erstellungsdatum des Kommentars zurück.
*
* @return string Erstellungsdatum
*/
public function getCreated(): string
{
return $this->created;
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
require_once "DatabaseCommentManager.php";
/**
* Zentrale Zugriffsschicht für Kommentare.
*
* Die Anwendung arbeitet ausschließlich
* mit dem CommentManager und kennt die
* konkrete Speicherimplementierung nicht.
*
* @author Caroline Schulte
*/
class CommentManager
{
/**
* Gibt die aktive Kommentarverwaltung zurück.
*
* @return CommentManagerDAO
*/
public static function getInstance()
{
return DatabaseCommentManager::getInstance();
}
}
+54
View File
@@ -0,0 +1,54 @@
<?php
require_once "Comment.php";
/**
* Schnittstelle für die Verwaltung von Kommentaren.
*
* Definiert die grundlegenden Methoden zum
* Speichern und Laden von Kommentaren.
*
* @author Caroline Schulte
*/
interface CommentManagerDAO
{
/**
* Speichert einen neuen Kommentar zu einem Beitrag.
*
* Optional kann eine parentCommentId übergeben werden,
* wenn der Kommentar eine Antwort auf einen anderen Kommentar ist.
*
* @param int $articleId ID des Beitrags
* @param string $author Autor des Kommentars
* @param string $content Inhalt des Kommentars
* @param int|null $parentCommentId ID des Eltern-Kommentars oder null
*
* @return int ID des neu gespeicherten Kommentars
*/
public function addComment(
$articleId,
$author,
$content,
$parentCommentId = null
);
/**
* Gibt alle Kommentare eines Beitrags zurück.
*
* @param int $articleId ID des Beitrags
*
* @return Comment[] Liste der Kommentare
*/
public function getCommentsByArticle(
$articleId
);
/**
* Gibt alle Kommentare eines Autors zurück.
*
* @param string $author E-Mail-Adresse des Autors
*
* @return Comment[] Liste der Kommentare
*/
public function getCommentsByAuthor($author);
}
+257
View File
@@ -0,0 +1,257 @@
<?php
require_once "CommentManagerDAO.php";
require_once "Comment.php";
/**
* Verwaltet die Speicherung und das Laden von Kommentaren
* über eine SQLite-Datenbank.
*
* @author Caroline Schulte
*/
class DatabaseCommentManager implements CommentManagerDAO
{
private static $instance = null;
/**
* Erstellt die Kommentartabelle, falls diese noch nicht existiert.
*/
public function __construct()
{
try {
$db = $this->getConnection();
$db->exec("
CREATE TABLE IF NOT EXISTS comments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
article_id INTEGER NOT NULL,
parent_comment_id INTEGER NULL,
author TEXT NOT NULL,
content TEXT NOT NULL,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
");
$columns = $db->query("PRAGMA table_info(comments);")->fetchAll(PDO::FETCH_ASSOC);
$hasParentColumn = false;
foreach ($columns as $column) {
if ($column["name"] === "parent_comment_id") {
$hasParentColumn = true;
break;
}
}
if (!$hasParentColumn) {
$db->exec("ALTER TABLE comments ADD COLUMN parent_comment_id INTEGER NULL;");
}
} catch (PDOException $e) {
throw new RuntimeException("internal_error");
}
}
/**
* Baut die Verbindung zur SQLite-Datenbank auf.
*
* @return PDO Datenbankverbindung
*/
private function getConnection()
{
try {
$dsn = 'sqlite:' . __DIR__ . '/../../db/comments.db';
$db = new PDO($dsn, null, null);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
} catch (PDOException $e) {
throw new RuntimeException("internal_error");
}
}
/**
* Gibt die Singleton-Instanz zurück.
*
* @return DatabaseCommentManager
*/
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new DatabaseCommentManager();
}
return self::$instance;
}
/**
* Speichert einen neuen Kommentar oder eine Antwort.
*
* @param int $articleId ID des Beitrags
* @param string $author Autor des Kommentars
* @param string $content Inhalt des Kommentars
* @param int|null $parentCommentId ID des Eltern-Kommentars oder null
*
* @return int ID des neu gespeicherten Kommentars
*/
public function addComment(
$articleId,
$author,
$content,
$parentCommentId = null
) {
try {
$db = $this->getConnection();
if ($parentCommentId === "" || $parentCommentId === 0 || $parentCommentId === "0") {
$parentCommentId = null;
}
$sql = "
INSERT INTO comments (
article_id,
parent_comment_id,
author,
content
)
VALUES (
:articleId,
:parentCommentId,
:author,
:content
)
";
$command = $db->prepare($sql);
$command->execute([
":articleId" => $articleId,
":parentCommentId" => $parentCommentId,
":author" => $author,
":content" => $content
]);
return intval($db->lastInsertId());
} catch (PDOException $e) {
throw new RuntimeException("internal_error");
}
}
/**
* Lädt alle Kommentare eines Beitrags.
*
* @param int $articleId ID des Beitrags
*
* @return Comment[]
*/
public function getCommentsByArticle($articleId)
{
try {
$db = $this->getConnection();
$sql = "
SELECT
id,
article_id,
CASE
WHEN parent_comment_id IS NULL THEN NULL
WHEN parent_comment_id = '' THEN NULL
WHEN parent_comment_id = 0 THEN NULL
ELSE parent_comment_id
END AS parent_comment_id,
author,
content,
created
FROM comments
WHERE article_id = :articleId
ORDER BY created ASC
";
$command = $db->prepare($sql);
$command->execute([":articleId" => $articleId]);
return $this->mapRowsToComments($command);
} catch (PDOException $e) {
throw new RuntimeException("internal_error");
}
}
/**
* Lädt alle Kommentare eines Autors.
*
* @param string $author E-Mail-Adresse des Autors
*
* @return Comment[]
*/
public function getCommentsByAuthor($author)
{
try {
$db = $this->getConnection();
$sql = "
SELECT
id,
article_id,
CASE
WHEN parent_comment_id IS NULL THEN NULL
WHEN parent_comment_id = '' THEN NULL
WHEN parent_comment_id = 0 THEN NULL
ELSE parent_comment_id
END AS parent_comment_id,
author,
content,
created
FROM comments
WHERE author = :author
ORDER BY created DESC
";
$command = $db->prepare($sql);
$command->execute([":author" => $author]);
return $this->mapRowsToComments($command);
} catch (PDOException $e) {
throw new RuntimeException("internal_error");
}
}
/**
* Wandelt Datenbankzeilen in Comment-Objekte um.
*
* @param PDOStatement $command Ausgeführtes Statement
*
* @return Comment[]
*/
private function mapRowsToComments($command)
{
$comments = [];
while ($row = $command->fetch(PDO::FETCH_ASSOC)) {
$parentCommentId = null;
if (
isset($row["parent_comment_id"])
&& $row["parent_comment_id"] !== null
&& $row["parent_comment_id"] !== ""
&& intval($row["parent_comment_id"]) !== 0
) {
$parentCommentId = intval($row["parent_comment_id"]);
}
$comments[] = new Comment(
intval($row["id"]),
intval($row["article_id"]),
$parentCommentId,
$row["author"],
$row["content"],
$row["created"]
);
}
return $comments;
}
}
+61 -18
View File
@@ -1,16 +1,5 @@
<?php <?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: * Prüft, ob der Titel die folgenden Bedingungen erfüllt:
* Buchstaben von a-z; A-Z * Buchstaben von a-z; A-Z
@@ -33,19 +22,73 @@ function articleTitleValidator($title)
} }
/** /**
* Prüft, ob der Contenttext 10-7000 Zeichen enthält. * Prüft, ob der Content valides JSON ist UND ob alle enthaltenen Blöcke
* @param $content * 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 * @return bool
*/ */
function articleContentValidator($content) function articleContentValidator($content)
{ {
$content = trim($content); // 1. Grundlegende Typprüfung
$zeichenAnzahl = mb_strlen($content); if (!is_string($content)) {
if ($zeichenAnzahl <= 7000 && $zeichenAnzahl >= 10) {
return true;
}else{
return false; 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;
} }
/** /**
+14
View File
@@ -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>