This commit is contained in:
2026-07-19 21:14:01 +02:00
committed by Caroline Schulte
24 changed files with 378 additions and 82 deletions
+50
View File
@@ -5,6 +5,8 @@ if (session_status() === PHP_SESSION_NONE) {
require_once "../model/CommentManager.php";
require_once "../model/UserManager.php";
require_once "../model/ArticleManager.php";
require_once "../../includes/csrf.php";
/**
* Prüft, ob die Anfrage durch JavaScript per AJAX gesendet wurde.
@@ -41,6 +43,7 @@ function sendCommentResponse(
$additionalData
)
);
exit();
}
@@ -96,6 +99,17 @@ if (!isset($_SESSION["user_email"])) {
);
}
/*
* CSRF-Token prüfen, bevor irgendeine Änderung vorgenommen wird.
*/
if (!csrf_verify()) {
sendCommentResponse(
false,
"Deine Sitzung ist abgelaufen. Bitte lade die Seite neu und versuche es erneut.",
$articleId !== false ? $articleId : null
);
}
/*
* Weitere Formulardaten einlesen.
*/
@@ -128,6 +142,18 @@ if ($articleId === false || $articleId === null) {
);
}
/*
* Der Beitrag muss tatsächlich existieren.
*/
$existingArticle = ArticleManager::getInstance()->getArticle($articleId);
if ($existingArticle === null) {
sendCommentResponse(
false,
"Der zugehörige Beitrag wurde nicht gefunden.",
null
);
}
if ($content === "") {
sendCommentResponse(
false,
@@ -152,6 +178,30 @@ if (
);
}
/*
* Falls eine Eltern-ID angegeben wurde, muss dieser Kommentar
* tatsächlich existieren und zum selben Beitrag gehören.
*/
if ($parentCommentId !== null) {
$existingComments = CommentManager::getInstance()->getCommentsByArticle($articleId);
$parentExists = false;
foreach ($existingComments as $existingComment) {
if ($existingComment->getId() === $parentCommentId) {
$parentExists = true;
break;
}
}
if (!$parentExists) {
sendCommentResponse(
false,
"Der ausgewählte Kommentar wurde nicht gefunden.",
$articleId
);
}
}
try {
$commentManager = CommentManager::getInstance();