| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- require_once '../includes/config.php';
- require_once '../includes/database.php';
- require_once '../includes/publication.php';
- require_once '../includes/translation.php';
- // Start session for language preference
- session_start();
- // Initialize translation system
- $translation = Translation::getInstance();
- $publication = new Publication();
- // Get search query
- $search = $_GET['search'] ?? '';
- $category = $_GET['category'] ?? '';
- $page = max(1, (int)($_GET['page'] ?? 1));
- $limit = 10;
- $offset = ($page - 1) * $limit;
- // Get publications
- if ($search) {
- $publications = $publication->search($search, 'published');
- $totalPublications = count($publications);
- } elseif ($category) {
- $publications = $publication->getByCategory($category, 'published');
- $totalPublications = count($publications);
- } else {
- $publications = $publication->getAll('published', $limit, $offset);
- $totalPublications = $publication->db->fetch("SELECT COUNT(*) as count FROM publications WHERE status = 'published'")['count'];
- }
- // Get categories for sidebar
- $categories = $publication->getCategories();
- // Calculate pagination
- $totalPages = ceil($totalPublications / $limit);
- ?>
- <!DOCTYPE html>
- <html lang="<?php echo getCurrentLanguage(); ?>">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title><?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"><?php echo t('nav_home'); ?></a>
- <a href="categories.php"><?php echo t('nav_categories'); ?></a>
- <a href="search.php"><?php echo t('nav_search'); ?></a>
- </nav>
- <?php echo $translation->getLanguageSwitcher('index.php'); ?>
- </div>
- </header>
- <div class="container">
- <div class="content-layout">
- <aside class="sidebar">
- <div class="sidebar-section">
- <h3><?php echo t('search'); ?></h3>
- <form method="get" class="search-form">
- <input type="text" name="search" placeholder="<?php echo t('search_placeholder'); ?>"
- value="<?php echo htmlspecialchars($search); ?>">
- <button type="submit" class="btn btn-sm"><?php echo t('search'); ?></button>
- </form>
- </div>
- <div class="sidebar-section">
- <h3><?php echo t('categories'); ?></h3>
- <ul class="category-list">
- <li>
- <a href="index.php" <?php echo empty($category) ? 'class="active"' : ''; ?>>
- <?php echo t('all_categories'); ?>
- </a>
- </li>
- <?php foreach ($categories as $cat): ?>
- <li>
- <a href="index.php?category=<?php echo urlencode($cat['name']); ?>"
- <?php echo $category === $cat['name'] ? 'class="active"' : ''; ?>>
- <?php echo htmlspecialchars($cat['name']); ?>
- <span class="count">(<?php echo $cat['publication_count']; ?>)</span>
- </a>
- </li>
- <?php endforeach; ?>
- </ul>
- </div>
- </aside>
- <main class="main-content">
- <?php if ($search): ?>
- <h2><?php echo t('search_results'); ?> "<?php echo htmlspecialchars($search); ?>"</h2>
- <p class="results-count"><?php echo t('found_count', ['count' => $totalPublications]); ?></p>
- <?php elseif ($category): ?>
- <h2><?php echo t('category'); ?>: <?php echo htmlspecialchars($category); ?></h2>
- <p class="results-count"><?php echo $totalPublications; ?> <?php echo t('publication_count'); ?></p>
- <?php else: ?>
- <h2><?php echo t('latest_publications'); ?></h2>
- <?php endif; ?>
- <?php if (empty($publications)): ?>
- <p><?php echo t('no_publications_found'); ?></p>
- <?php else: ?>
- <div class="publication-list">
- <?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"><?php echo t('by_author', ['author' => htmlspecialchars($pub['author'])]); ?></span>
- <span class="date"><?php echo t('on_date', ['date' => 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="index.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 (!$search && !$category && $totalPages > 1): ?>
- <div class="pagination">
- <?php if ($page > 1): ?>
- <a href="?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="?page=<?php echo $i; ?>" class="pagination-link"><?php echo $i; ?></a>
- <?php endif; ?>
- <?php endfor; ?>
- <?php if ($page < $totalPages): ?>
- <a href="?page=<?php echo $page + 1; ?>" class="pagination-link">Next »</a>
- <?php endif; ?>
- </div>
- <?php endif; ?>
- <?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>
- </body>
- </html>
|