| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- <?php
- require_once '../includes/config.php';
- require_once '../includes/database.php';
- require_once '../includes/publication.php';
- $publication = new Publication();
- $category = $_GET['category'] ?? '';
- $page = max(1, (int)($_GET['page'] ?? 1));
- $limit = 10;
- $offset = ($page - 1) * $limit;
- // Get categories for sidebar
- $categories = $publication->getCategories();
- // Get publications for selected category or all categories
- if ($category) {
- $publications = $publication->getByCategory($category, 'published');
- $totalPublications = count($publications);
- // Apply pagination
- $publications = array_slice($publications, $offset, $limit);
- $currentCategory = $category;
- } else {
- // Show all publications when no specific category is selected
- $publications = $publication->getAll('published', $limit, $offset);
- $totalPublications = $publication->db->fetch("SELECT COUNT(*) as count FROM publications WHERE status = 'published'")['count'];
- $currentCategory = '';
- }
- // Calculate pagination
- $totalPages = ceil($totalPublications / $limit);
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Categories - <?php echo SITE_TITLE; ?></title>
- <link rel="stylesheet" href="../css/style.css">
- </head>
- <body>
- <header class="site-header">
- <div class="container">
- <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
- <nav class="main-nav">
- <a href="index.php">Home</a>
- <a href="categories.php" class="active">Categories</a>
- <a href="search.php">Search</a>
- </nav>
- </div>
- </header>
- <div class="container">
- <div class="content-layout">
- <aside class="sidebar">
- <div class="sidebar-section">
- <h3>Search</h3>
- <form method="get" action="search.php" class="search-form">
- <input type="text" name="q" placeholder="Search publications...">
- <button type="submit" class="btn btn-sm">Search</button>
- </form>
- </div>
- <div class="sidebar-section">
- <h3>Categories</h3>
- <ul class="category-list">
- <li>
- <a href="categories.php" <?php echo empty($currentCategory) ? 'class="active"' : ''; ?>>
- All Categories
- </a>
- </li>
- <?php foreach ($categories as $cat): ?>
- <li>
- <a href="categories.php?category=<?php echo urlencode($cat['name']); ?>"
- <?php echo $currentCategory === $cat['name'] ? 'class="active"' : ''; ?>>
- <?php echo htmlspecialchars($cat['name']); ?>
- <span class="count">(<?php echo $cat['publication_count']; ?>)</span>
- </a>
- </li>
- <?php endforeach; ?>
- </ul>
- </div>
- <div class="sidebar-section">
- <h3>Category Stats</h3>
- <div class="category-stats">
- <div class="stat-item">
- <span class="stat-label">Total Categories:</span>
- <span class="stat-value"><?php echo count($categories); ?></span>
- </div>
- <div class="stat-item">
- <span class="stat-label">Total Publications:</span>
- <span class="stat-value">
- <?php echo array_sum(array_column($categories, 'publication_count')); ?>
- </span>
- </div>
- </div>
- </div>
- </aside>
- <main class="main-content">
- <div class="page-header">
- <h2>
- <?php if ($currentCategory): ?>
- Category: <?php echo htmlspecialchars($currentCategory); ?>
- <?php else: ?>
- All Categories
- <?php endif; ?>
- </h2>
-
- <?php if ($currentCategory): ?>
- <a href="categories.php" class="btn btn-secondary">View All Categories</a>
- <?php endif; ?>
- </div>
- <?php if ($currentCategory): ?>
- <div class="category-info">
- <?php
- $categoryInfo = array_filter($categories, function($cat) use ($currentCategory) {
- return $cat['name'] === $currentCategory;
- });
- $categoryInfo = reset($categoryInfo);
- ?>
- <?php if ($categoryInfo && $categoryInfo['description']): ?>
- <div class="category-description">
- <p><?php echo htmlspecialchars($categoryInfo['description']); ?></p>
- </div>
- <?php endif; ?>
-
- <p class="results-count">
- <?php echo $totalPublications; ?> publications in this category
- </p>
- </div>
- <?php else: ?>
- <div class="category-overview">
- <h3>Category Overview</h3>
- <div class="category-grid">
- <?php foreach ($categories as $cat): ?>
- <?php if ($cat['publication_count'] > 0): ?>
- <div class="category-card">
- <h4>
- <a href="categories.php?category=<?php echo urlencode($cat['name']); ?>">
- <?php echo htmlspecialchars($cat['name']); ?>
- </a>
- </h4>
- <?php if ($cat['description']): ?>
- <p class="category-description">
- <?php echo htmlspecialchars(substr($cat['description'], 0, 150)) . (strlen($cat['description']) > 150 ? '...' : ''); ?>
- </p>
- <?php endif; ?>
- <div class="category-meta">
- <span class="publication-count"><?php echo $cat['publication_count']; ?> publications</span>
- <a href="categories.php?category=<?php echo urlencode($cat['name']); ?>" class="view-link">
- View Publications
- </a>
- </div>
- </div>
- <?php endif; ?>
- <?php endforeach; ?>
- </div>
- </div>
- <?php endif; ?>
- <?php if ($currentCategory && !empty($publications)): ?>
- <div class="publication-list">
- <h3>Publications in <?php echo htmlspecialchars($currentCategory); ?></h3>
- <?php foreach ($publications as $pub): ?>
- <article class="publication-summary">
- <h3>
- <a href="publication.php?id=<?php echo $pub['id']; ?>">
- <?php echo htmlspecialchars($pub['title']); ?>
- </a>
- </h3>
-
- <?php if ($pub['summary']): ?>
- <p class="summary"><?php echo htmlspecialchars($pub['summary']); ?></p>
- <?php endif; ?>
-
- <div class="meta">
- <span class="author">By <?php echo htmlspecialchars($pub['author']); ?></span>
- <span class="date"><?php echo date('F j, Y', strtotime($pub['created_at'])); ?></span>
- <?php if ($pub['categories']): ?>
- <span class="categories">
- <?php foreach (explode(',', $pub['categories']) as $cat): ?>
- <a href="categories.php?category=<?php echo urlencode(trim($cat)); ?>" class="category-tag">
- <?php echo htmlspecialchars(trim($cat)); ?>
- </a>
- <?php endforeach; ?>
- </span>
- <?php endif; ?>
- </div>
- </article>
- <?php endforeach; ?>
- </div>
- <?php if ($totalPages > 1): ?>
- <div class="pagination">
- <?php if ($page > 1): ?>
- <a href="?category=<?php echo urlencode($currentCategory); ?>&page=<?php echo $page - 1; ?>" class="pagination-link">« Previous</a>
- <?php endif; ?>
- <?php for ($i = 1; $i <= $totalPages; $i++): ?>
- <?php if ($i == $page): ?>
- <span class="pagination-current"><?php echo $i; ?></span>
- <?php else: ?>
- <a href="?category=<?php echo urlencode($currentCategory); ?>&page=<?php echo $i; ?>" class="pagination-link"><?php echo $i; ?></a>
- <?php endif; ?>
- <?php endfor; ?>
- <?php if ($page < $totalPages): ?>
- <a href="?category=<?php echo urlencode($currentCategory); ?>&page=<?php echo $page + 1; ?>" class="pagination-link">Next »</a>
- <?php endif; ?>
- </div>
- <?php endif; ?>
- <?php elseif ($currentCategory): ?>
- <p>No publications found in this category.</p>
- <?php endif; ?>
- </main>
- </div>
- </div>
- <footer class="site-footer">
- <div class="container">
- <p>© <?php echo date('Y'); ?> <?php echo SITE_TITLE; ?>. All rights reserved.</p>
- </div>
- </footer>
- <style>
- .page-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 2rem;
- }
-
- .category-info {
- background: #f8f9fa;
- padding: 1.5rem;
- border-radius: 0.5rem;
- margin-bottom: 2rem;
- border-left: 4px solid #007bff;
- }
-
- .category-description {
- margin-bottom: 1rem;
- }
-
- .category-description p {
- margin: 0;
- color: #495057;
- }
-
- .category-overview {
- margin-bottom: 2rem;
- }
-
- .category-grid {
- display: grid;
- grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
- gap: 1.5rem;
- margin-top: 1.5rem;
- }
-
- .category-card {
- background: white;
- padding: 1.5rem;
- border-radius: 0.5rem;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
- border: 1px solid #dee2e6;
- }
-
- .category-card h4 {
- margin-bottom: 1rem;
- }
-
- .category-card h4 a {
- color: #007bff;
- text-decoration: none;
- }
-
- .category-card h4 a:hover {
- text-decoration: underline;
- }
-
- .category-card .category-description {
- color: #6c757d;
- margin-bottom: 1rem;
- font-size: 0.875rem;
- }
-
- .category-meta {
- display: flex;
- justify-content: space-between;
- align-items: center;
- font-size: 0.875rem;
- }
-
- .publication-count {
- color: #6c757d;
- font-weight: 500;
- }
-
- .view-link {
- color: #007bff;
- text-decoration: none;
- }
-
- .view-link:hover {
- text-decoration: underline;
- }
-
- .category-stats {
- background: white;
- padding: 1rem;
- border-radius: 0.375rem;
- border: 1px solid #dee2e6;
- }
-
- .stat-item {
- display: flex;
- justify-content: space-between;
- margin-bottom: 0.5rem;
- }
-
- .stat-item:last-child {
- margin-bottom: 0;
- }
-
- .stat-label {
- color: #6c757d;
- font-size: 0.875rem;
- }
-
- .stat-value {
- font-weight: 600;
- color: #495057;
- }
-
- @media (max-width: 768px) {
- .page-header {
- flex-direction: column;
- gap: 1rem;
- align-items: stretch;
- }
-
- .category-grid {
- grid-template-columns: 1fr;
- }
-
- .category-meta {
- flex-direction: column;
- gap: 0.5rem;
- align-items: flex-start;
- }
- }
- </style>
- </body>
- </html>
|