Compare commits

..

5 Commits

3 changed files with 33 additions and 74 deletions
+22 -51
View File
@@ -2,60 +2,31 @@
include_once "php/controller/showCategory-controller.php"; include_once "php/controller/showCategory-controller.php";
?> ?>
<div class="category-results-container"> <main>
<!-- Kategorie-Titel sicher ausgeben --> <?php include_once "includes/alertMessages.php"?>
<h1>Kategorie: <?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : 'Unbekannt'; ?></h1>
<!-- 1. Die Artikel-Liste ausgeben --> <h1><?php if (isset($category) && !empty($category)){ echo htmlspecialchars($category); } ?></h1>
<div class="articles-list">
<?php if (isset($articles) && !empty($articles)): ?> <div class="s-res-list">
<?php
if (!empty($articles)): ?>
<?php foreach ($articles as $article): ?> <?php foreach ($articles as $article): ?>
<article class="article-item"> <div class="s-res-item">
<!-- Sichere Objektausrufe über die Getter-Methoden --> <div class="s-res-content">
<h2><?php echo (isset($article) && !empty($article->getTitle())) ? htmlspecialchars($article->getTitle()) : 'Kein Titel'; ?></h2> <h2 class="s-res-item-title">
<p><?php echo (isset($article) && !empty($article->getContent())) ? htmlspecialchars($article->getContent()) : 'Kein Inhalt'; ?></p> <a href="index.php?pfad=showArticle&id=<?php echo $article->getId(); ?>" class="s-res-link">
</article> <?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>
<?php endforeach; ?> <?php endforeach; ?>
<?php else: ?> <?php
<p>Keine Artikel in dieser Kategorie gefunden.</p> else: ?>
<p> Es sind noch keine Beiträge in dieser Kategorie enthalten.</p>
<?php endif; ?> <?php endif; ?>
</div> </div>
<!-- 2. Der Paginator (Greift nur, wenn mehr als eine Seite existiert) --> </main>
<?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,6 +25,14 @@ if (isset($_GET["id"]) && !empty($_GET["id"])){
exit(); exit();
} }
if($_GET["pfad"] == "updateArticle"){
if($article->getAuthor() != $_SESSION["user_email"]){
$_SESSION["message"] = "unauthorized_access";
header("location: index.php");
exit();
}
}
$commentManager = CommentManager::getInstance(); $commentManager = CommentManager::getInstance();
$comments = $commentManager->getCommentsByArticle($_GET["id"]); $comments = $commentManager->getCommentsByArticle($_GET["id"]);
+1 -21
View File
@@ -1,33 +1,13 @@
<?php <?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
require_once 'php/model/Article.php'; require_once 'php/model/Article.php';
require_once 'php/model/ArticleManager.php'; require_once 'php/model/ArticleManager.php';
require_once 'php/validator/article-validator.php'; require_once 'php/validator/article-validator.php';
if (isset($_GET["category"]) && !empty($_GET["category"]) && articleCategoryValidator($_GET["category"])){ if (isset($_GET["category"]) && !empty($_GET["category"]) && articleCategoryValidator($_GET["category"])){
$category = $_GET["category"]; $category = $_GET["category"];
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
if ($page < 1) { $page = 1; }
try { try {
$articleManager = ArticleManager::getInstance(); $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) { } catch (Exception $e) {
$_SESSION["message"] = "internal_error"; $_SESSION["message"] = "internal_error";
include_once "content/404.php"; include_once "content/404.php";