index.php 9.5 KB

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