index.php 7.7 KB

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