Compare commits

..

5 Commits

Author SHA1 Message Date
niklas.ortmann 1dd128d480 Update showCategory.php 2026-07-17 16:59:36 +02:00
niklas.ortmann dca716ddc5 Update showCategory-controller.php 2026-07-17 16:59:34 +02:00
niklas.ortmann c1dd4fce2b Update showCategory.php 2026-07-17 16:41:09 +02:00
niklas.ortmann 16cfa92721 Update showCategory.php 2026-07-17 16:29:11 +02:00
niklas.ortmann 3b2ed78c1c Update showCategory.php 2026-07-17 16:16:14 +02:00
3 changed files with 74 additions and 33 deletions
+51 -22
View File
@@ -2,31 +2,60 @@
include_once "php/controller/showCategory-controller.php";
?>
<main>
<?php include_once "includes/alertMessages.php"?>
<div class="category-results-container">
<!-- Kategorie-Titel sicher ausgeben -->
<h1>Kategorie: <?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : 'Unbekannt'; ?></h1>
<h1><?php if (isset($category) && !empty($category)){ echo htmlspecialchars($category); } ?></h1>
<div class="s-res-list">
<?php
if (!empty($articles)): ?>
<!-- 1. Die Artikel-Liste ausgeben -->
<div class="articles-list">
<?php if (isset($articles) && !empty($articles)): ?>
<?php foreach ($articles as $article): ?>
<div class="s-res-item">
<div class="s-res-content">
<h2 class="s-res-item-title">
<a href="index.php?pfad=showArticle&id=<?php echo $article->getId(); ?>" class="s-res-link">
<?php echo htmlspecialchars($article->getTitle()); ?>
</a>
</h2>
<p class="s-res-author">Von: <span class="s-res-author-name"><?php echo htmlspecialchars($article->getAuthor()); ?></span></p>
</div>
<div class="s-res-arrow">&rarr;</div>
</div>
<article class="article-item">
<!-- Sichere Objektausrufe über die Getter-Methoden -->
<h2><?php echo (isset($article) && !empty($article->getTitle())) ? htmlspecialchars($article->getTitle()) : 'Kein Titel'; ?></h2>
<p><?php echo (isset($article) && !empty($article->getContent())) ? htmlspecialchars($article->getContent()) : 'Kein Inhalt'; ?></p>
</article>
<?php endforeach; ?>
<?php
else: ?>
<p> Es sind noch keine Beiträge in dieser Kategorie enthalten.</p>
<?php else: ?>
<p>Keine Artikel in dieser Kategorie gefunden.</p>
<?php endif; ?>
</div>
</main>
<!-- 2. Der Paginator (Greift nur, wenn mehr als eine Seite existiert) -->
<?php if (isset($totalPages) && $totalPages > 1): ?>
<form id="search-form-id" action="index.php" method="GET" style="display: inline;">
<!-- Pfad und Kategorie als versteckte Felder mitsenden -->
<input type="hidden" name="pfad" value="showCategory">
<input type="hidden" name="category" value="<?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : ''; ?>">
<!-- Das Feld, das dein JS-Paginator befüllt (Nutzt Kurzform ?? für Fallback) -->
<input type="hidden" id="s-res-page-input" name="page" value="<?php echo (isset($page) && !empty($page)) ? $page : 1; ?>">
<!-- Die Navigations-Buttons -->
<div class="s-res-page-navigation">
<!-- Zurück-Button -->
<?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>
<!-- Seitenzahlen generieren -->
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<button type="button"
class="s-res-page-btn <?php echo ($i === $currentPage) ? 'active' : ''; ?>"
data-page="<?php echo $i; ?>"
<?php echo ($i === $currentPage) ? 'disabled' : ''; ?>>
<?php echo $i; ?>
</button>
<?php endfor; ?>
<!-- Vor-Button -->
<button type="button" class="s-res-page-btn" data-page="<?php echo $currentPage + 1; ?>" <?php echo ($currentPage >= $totalPages) ? 'disabled' : ''; ?>>
Weiter &raquo;
</button>
</div>
</form>
<?php endif; ?>
</div>
@@ -25,14 +25,6 @@ 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"]);
+23 -3
View File
@@ -1,21 +1,41 @@
<?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();
$articles = $articleManager->getArticlesByCategory($category);
$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);
} 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();
}
?>
?>