Update add-comment.php
This commit is contained in:
@@ -4,6 +4,8 @@ if (session_status() === PHP_SESSION_NONE) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require_once "../model/CommentManager.php";
|
require_once "../model/CommentManager.php";
|
||||||
|
require_once "../model/ArticleManager.php";
|
||||||
|
require_once "../../includes/csrf.php";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prüft, ob die Anfrage durch JavaScript per AJAX gesendet wurde.
|
* Prüft, ob die Anfrage durch JavaScript per AJAX gesendet wurde.
|
||||||
@@ -96,6 +98,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.
|
* Weitere Formulardaten einlesen.
|
||||||
*/
|
*/
|
||||||
@@ -128,6 +141,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 === "") {
|
if ($content === "") {
|
||||||
sendCommentResponse(
|
sendCommentResponse(
|
||||||
false,
|
false,
|
||||||
@@ -152,6 +177,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 {
|
try {
|
||||||
$commentManager = CommentManager::getInstance();
|
$commentManager = CommentManager::getInstance();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user