Kommentarfunktion für Nutzer einschränken

This commit is contained in:
2026-06-15 23:22:00 +02:00
parent 901232b683
commit e20b59b43d
4 changed files with 40 additions and 103 deletions
+13 -41
View File
@@ -14,28 +14,17 @@ if (isset($_GET["id"])) {
foreach ($comments as $comment) {
if ($comment->isReply()) {
$parentId = $comment->getParentCommentId();
if (!isset($repliesByParent[$parentId])) {
$repliesByParent[$parentId] = [];
}
$repliesByParent[$parentId][] = $comment;
} else {
$mainComments[] = $comment;
}
}
} catch (Exception $e) {
$_SESSION["message"] = "internal_error";
}
}
?>
<!--
Seite: Anzeige für Beiträge
Funktion: Stellt einen übergebenen Beitrag dar.
-->
<main class="article-view-container">
<?php if (isset($_SESSION["message"]) && $_SESSION["message"] == "internal_error"): ?>
<p class="alert-message is-error">
@@ -43,28 +32,9 @@ if (isset($_GET["id"])) {
</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"]); ?>
<div class="article-view-top-section">
<?php if (isset($category) && !empty($category)): ?>
<span class="article-view-category"><?php echo htmlspecialchars($category); ?></span>
<?php endif; ?>
@@ -80,7 +50,6 @@ if (isset($_GET["id"])) {
</span>
<?php endif; ?>
</div>
</div>
<div class="article-view-content">
@@ -107,8 +76,7 @@ if (isset($_GET["id"])) {
<span class="article-view-tag-item">
<?php echo htmlspecialchars($trimmedTag); ?>
</span>
<?php
endif;
<?php endif;
endforeach;
?>
</div>
@@ -129,12 +97,14 @@ if (isset($_GET["id"])) {
<p><?php echo nl2br(htmlspecialchars($comment->getContent())); ?></p>
<button type="button"
class="reply-button"
data-comment-id="<?php echo htmlspecialchars($comment->getId()); ?>"
data-author="<?php echo htmlspecialchars($comment->getAuthor()); ?>">
Antworten
</button>
<?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()])): ?>
@@ -182,8 +152,10 @@ if (isset($_GET["id"])) {
</button>
</form>
<?php else: ?>
<p>Du musst angemeldet sein, um einen Kommentar zu schreiben.</p>
<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>