index.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. // Start session for language preference
  3. session_start();
  4. require_once '../includes/config.php';
  5. require_once '../includes/database.php';
  6. require_once '../includes/publication.php';
  7. require_once '../includes/translation.php';
  8. // Translation system is auto-initialized when translation.php is included
  9. $publication = new Publication();
  10. // Get search query
  11. $search = $_GET['search'] ?? '';
  12. $category = $_GET['category'] ?? '';
  13. $page = max(1, (int)($_GET['page'] ?? 1));
  14. $limit = 10;
  15. $offset = ($page - 1) * $limit;
  16. // Get publications
  17. if ($search) {
  18. $publications = $publication->search($search, 'published');
  19. $totalPublications = count($publications);
  20. } elseif ($category) {
  21. $publications = $publication->getByCategory($category, 'published');
  22. $totalPublications = count($publications);
  23. } else {
  24. $publications = $publication->getAll('published', $limit, $offset);
  25. $totalPublications = $publication->db->fetch("SELECT COUNT(*) as count FROM publications WHERE status = 'published'")['count'];
  26. }
  27. // Get categories for sidebar
  28. $categories = $publication->getCategories();
  29. // Calculate pagination
  30. $totalPages = ceil($totalPublications / $limit);
  31. ?>
  32. <!DOCTYPE html>
  33. <html lang="<?php echo Translation::getCurrentLang(); ?>">
  34. <head>
  35. <meta charset="UTF-8">
  36. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  37. <title><?php echo SITE_TITLE; ?></title>
  38. <link rel="stylesheet" href="../css/style.css">
  39. </head>
  40. <body>
  41. <header class="site-header">
  42. <div class="container">
  43. <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
  44. <nav class="main-nav">
  45. <a href="index.php"><?php echo t('nav_home'); ?></a>
  46. <a href="categories.php"><?php echo t('nav_categories'); ?></a>
  47. <a href="search.php"><?php echo t('nav_search'); ?></a>
  48. </nav>
  49. <?php echo Translation::getLanguageSwitcher('index.php'); ?>
  50. </div>
  51. </header>
  52. <div class="container">
  53. <div class="content-layout">
  54. <aside class="sidebar">
  55. <div class="sidebar-section">
  56. <h3><?php echo t('search'); ?></h3>
  57. <form method="get" class="search-form">
  58. <input type="text" name="search" placeholder="<?php echo t('search_placeholder'); ?>"
  59. value="<?php echo htmlspecialchars($search); ?>">
  60. <button type="submit" class="btn btn-sm"><?php echo t('search'); ?></button>
  61. </form>
  62. </div>
  63. <div class="sidebar-section">
  64. <h3><?php echo t('categories'); ?></h3>
  65. <ul class="category-list">
  66. <li>
  67. <a href="index.php" <?php echo empty($category) ? 'class="active"' : ''; ?>>
  68. <?php echo t('all_categories'); ?>
  69. </a>
  70. </li>
  71. <?php foreach ($categories as $cat): ?>
  72. <li>
  73. <a href="index.php?category=<?php echo urlencode($cat['name']); ?>"
  74. <?php echo $category === $cat['name'] ? 'class="active"' : ''; ?>>
  75. <?php echo htmlspecialchars($cat['name']); ?>
  76. <span class="count">(<?php echo $cat['publication_count']; ?>)</span>
  77. </a>
  78. </li>
  79. <?php endforeach; ?>
  80. </ul>
  81. </div>
  82. </aside>
  83. <main class="main-content">
  84. <?php if ($search): ?>
  85. <h2><?php echo t('search_results'); ?> "<?php echo htmlspecialchars($search); ?>"</h2>
  86. <p class="results-count"><?php echo t('found_count', ['count' => $totalPublications]); ?></p>
  87. <?php elseif ($category): ?>
  88. <h2><?php echo t('category'); ?>: <?php echo htmlspecialchars($category); ?></h2>
  89. <p class="results-count"><?php echo $totalPublications; ?> <?php echo t('publication_count'); ?></p>
  90. <?php else: ?>
  91. <h2><?php echo t('latest_publications'); ?></h2>
  92. <?php endif; ?>
  93. <?php if (empty($publications)): ?>
  94. <p><?php echo t('no_publications_found'); ?></p>
  95. <?php else: ?>
  96. <div class="publication-list">
  97. <?php foreach ($publications as $pub): ?>
  98. <article class="publication-summary">
  99. <h3>
  100. <a href="publication.php?id=<?php echo $pub['id']; ?>">
  101. <?php echo htmlspecialchars($pub['title']); ?>
  102. </a>
  103. </h3>
  104. <?php if ($pub['summary']): ?>
  105. <p class="summary"><?php echo htmlspecialchars($pub['summary']); ?></p>
  106. <?php endif; ?>
  107. <div class="meta">
  108. <span class="author"><?php echo t('by_author', ['author' => htmlspecialchars($pub['author'])]); ?></span>
  109. <span class="date"><?php echo t('on_date', ['date' => date('F j, Y', strtotime($pub['created_at']))]); ?></span>
  110. <?php if ($pub['categories']): ?>
  111. <span class="categories">
  112. <?php foreach (explode(',', $pub['categories']) as $cat): ?>
  113. <a href="index.php?category=<?php echo urlencode(trim($cat)); ?>" class="category-tag">
  114. <?php echo htmlspecialchars(trim($cat)); ?>
  115. </a>
  116. <?php endforeach; ?>
  117. </span>
  118. <?php endif; ?>
  119. </div>
  120. </article>
  121. <?php endforeach; ?>
  122. </div>
  123. <?php if (!$search && !$category && $totalPages > 1): ?>
  124. <div class="pagination">
  125. <?php if ($page > 1): ?>
  126. <a href="?page=<?php echo $page - 1; ?>" class="pagination-link">« Previous</a>
  127. <?php endif; ?>
  128. <?php for ($i = 1; $i <= $totalPages; $i++): ?>
  129. <?php if ($i == $page): ?>
  130. <span class="pagination-current"><?php echo $i; ?></span>
  131. <?php else: ?>
  132. <a href="?page=<?php echo $i; ?>" class="pagination-link"><?php echo $i; ?></a>
  133. <?php endif; ?>
  134. <?php endfor; ?>
  135. <?php if ($page < $totalPages): ?>
  136. <a href="?page=<?php echo $page + 1; ?>" class="pagination-link">Next »</a>
  137. <?php endif; ?>
  138. </div>
  139. <?php endif; ?>
  140. <?php endif; ?>
  141. </main>
  142. </div>
  143. </div>
  144. <footer class="site-footer">
  145. <div class="container">
  146. <p><a href="/admin/" style="text-decoration:none">&copy;</a> <?php echo date('Y'); ?> <?php echo SITE_TITLE; ?>. All rights reserved.</p>
  147. </div>
  148. </footer>
  149. </body>
  150. </html>