Compare commits

..

1 Commits

Author SHA1 Message Date
niklas.ortmann bd125c851f Update showArticle-controller.php 2026-07-17 15:53:15 +02:00
3 changed files with 24 additions and 86 deletions
+13 -63
View File
@@ -2,81 +2,31 @@
include_once "php/controller/showCategory-controller.php";
?>
<div class="s-res-main-content">
<div class="s-res-header">
<!-- Kategorie-Titel im exakten Stil der Suchergebnisse -->
<h1 class="s-res-main-title">Kategorie: <?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : 'Unbekannt'; ?></h1>
<p class="s-res-meta">Beiträge in dieser Kategorie</p>
</div>
<main>
<?php include_once "includes/alertMessages.php"?>
<h1><?php if (isset($category) && !empty($category)){ echo htmlspecialchars($category); } ?></h1>
<!-- Die Artikel-Liste -->
<div class="s-res-list">
<?php if (isset($articles) && !empty($articles)): ?>
<?php
if (!empty($articles)): ?>
<?php foreach ($articles as $article): ?>
<div class="s-res-item">
<div class="s-res-content">
<!-- Titel als klickbarer Link wie im Original -->
<h2 class="s-res-item-title">
<a href="#" class="s-res-link">
<?php echo (isset($article) && !empty($article->getTitle())) ? htmlspecialchars($article->getTitle()) : 'Kein Titel'; ?>
<a href="index.php?pfad=showArticle&id=<?php echo $article->getId(); ?>" class="s-res-link">
<?php echo htmlspecialchars($article->getTitle()); ?>
</a>
</h2>
<!-- Die fehlende Meta-Zeile für Autor und Likes für das richtige Design -->
<div class="s-res-meta-row">
<p class="s-res-author">
von <span class="s-res-author-name"><?php echo (isset($article) && !empty($article->getAuthor())) ? htmlspecialchars($article->getAuthor()) : 'Anonym'; ?></span>
</p>
<!-- Likes Anzeige (Falls dein Objekt getLikes() oder getLikeCount() hat) -->
<span class="s-res-likes">
&#x2764; <?php echo (isset($article) && !empty($article->getLikes())) ? htmlspecialchars($article->getLikes()) : '0'; ?>
</span>
<p class="s-res-author">Von: <span class="s-res-author-name"><?php echo htmlspecialchars($article->getAuthor()); ?></span></p>
</div>
<!-- Beschreibungstext -->
<p style="margin-top: 0.5rem; color: #4a5568;">
<?php echo (isset($article) && !empty($article->getContent())) ? htmlspecialchars($article->getContent()) : 'Kein Inhalt'; ?>
</p>
</div>
<!-- Der originale Pfeil rechts -->
<div class="s-res-arrow">&rarr;</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<p class="s-res-meta">Keine Artikel in dieser Kategorie gefunden.</p>
<?php
else: ?>
<p> Es sind noch keine Beiträge in dieser Kategorie enthalten.</p>
<?php endif; ?>
</div>
<!-- Der Paginator -->
<?php if (isset($totalPages) && $totalPages > 1): ?>
<div class="s-res-pagination-footer">
<div></div> <!-- Hält die Buttons auf der rechten Seite -->
<form id="search-form-id" action="index.php" method="GET" style="display: inline;">
<input type="hidden" name="pfad" value="showCategory">
<input type="hidden" name="category" value="<?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : ''; ?>">
<input type="hidden" id="s-res-page-input" name="page" value="<?php echo (isset($page) && !empty($page)) ? $page : 1; ?>">
<div class="s-res-page-navigation">
<?php $currentPage = $page ?? 1; ?>
<button type="button" class="s-res-page-btn" data-page="<?php echo $currentPage - 1; ?>" <?php echo ($currentPage <= 1) ? 'disabled' : ''; ?>>
&laquo; Zurück
</button>
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<button type="button"
class="s-res-page-btn <?php echo ($i === $currentPage) ? 's-res-page-btn-active' : ''; ?>"
data-page="<?php echo $i; ?>"
<?php echo ($i === $currentPage) ? 'disabled' : ''; ?>>
<?php echo $i; ?>
</button>
<?php endfor; ?>
<button type="button" class="s-res-page-btn" data-page="<?php echo $currentPage + 1; ?>" <?php echo ($currentPage >= $totalPages) ? 'disabled' : ''; ?>>
Weiter &raquo;
</button>
</div>
</form>
</div>
<?php endif; ?>
</div>
</main>
@@ -25,6 +25,14 @@ if (isset($_GET["id"]) && !empty($_GET["id"])){
exit();
}
if($_GET["pfad"] == "updateArticle"){
if($article->getAuthor() != $_SESSION["user"]){
$_SESSION["message"] = "unauthorized_access";
header("location: ../../index.php");
exit();
}
}
$commentManager = CommentManager::getInstance();
$comments = $commentManager->getCommentsByArticle($_GET["id"]);
+2 -22
View File
@@ -1,39 +1,19 @@
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
require_once 'php/model/Article.php';
require_once 'php/model/ArticleManager.php';
require_once 'php/validator/article-validator.php';
if (isset($_GET["category"]) && !empty($_GET["category"]) && articleCategoryValidator($_GET["category"])){
$category = $_GET["category"];
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
if ($page < 1) { $page = 1; }
try {
$articleManager = ArticleManager::getInstance();
$allArticles = $articleManager->getArticlesByCategory($category);
// Paginierung konfigurieren
$limit = 10; // Wie viele Artikel pro Seite?
$totalArticles = count($allArticles);
$totalPages = ceil($totalArticles / $limit);
if ($page > $totalPages && $totalPages > 0) { $page = $totalPages; }
$offset = ($page - 1) * $limit;
$articles = array_slice($allArticles, $offset, $limit);
$articles = $articleManager->getArticlesByCategory($category);
} catch (Exception $e) {
$_SESSION["message"] = "internal_error";
include_once "content/404.php";
exit();
}
} else {
}else{
$_SESSION["message"] = "invalid_category";
include_once "content/404.php";
exit();