journal.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 t('journal'); ?> - <?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="journal.php" class="active"><?php echo t('journal'); ?></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('journal.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="journal.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="journal.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('journal'); ?></h2>
  93. <p class="journal-description"><?php echo t('journal_description'); ?></p>
  94. <?php endif; ?>
  95. <?php if (empty($publications)): ?>
  96. <p><?php echo t('no_publications_found'); ?></p>
  97. <?php else: ?>
  98. <div class="publication-list">
  99. <?php foreach ($publications as $pub): ?>
  100. <article class="publication-summary">
  101. <h3>
  102. <a href="publication.php?id=<?php echo $pub['id']; ?>">
  103. <?php echo htmlspecialchars($pub['title']); ?>
  104. </a>
  105. </h3>
  106. <?php if ($pub['summary']): ?>
  107. <p class="summary"><?php echo htmlspecialchars($pub['summary']); ?></p>
  108. <?php endif; ?>
  109. <div class="meta">
  110. <span class="author"><?php echo t('by_author', ['author' => htmlspecialchars($pub['author'])]); ?></span>
  111. <span class="date"><?php echo t('on_date', ['date' => date('F j, Y', strtotime($pub['created_at']))]); ?></span>
  112. <?php if ($pub['categories']): ?>
  113. <span class="categories">
  114. <?php foreach (explode(',', $pub['categories']) as $cat): ?>
  115. <a href="journal.php?category=<?php echo urlencode(trim($cat)); ?>" class="category-tag">
  116. <?php echo htmlspecialchars(trim($cat)); ?>
  117. </a>
  118. <?php endforeach; ?>
  119. </span>
  120. <?php endif; ?>
  121. </div>
  122. </article>
  123. <?php endforeach; ?>
  124. </div>
  125. <?php if (!$search && !$category && $totalPages > 1): ?>
  126. <div class="pagination">
  127. <?php if ($page > 1): ?>
  128. <a href="?page=<?php echo $page - 1; ?>" class="pagination-link">« Previous</a>
  129. <?php endif; ?>
  130. <?php for ($i = 1; $i <= $totalPages; $i++): ?>
  131. <?php if ($i == $page): ?>
  132. <span class="pagination-current"><?php echo $i; ?></span>
  133. <?php else: ?>
  134. <a href="?page=<?php echo $i; ?>" class="pagination-link"><?php echo $i; ?></a>
  135. <?php endif; ?>
  136. <?php endfor; ?>
  137. <?php if ($page < $totalPages): ?>
  138. <a href="?page=<?php echo $page + 1; ?>" class="pagination-link">Next »</a>
  139. <?php endif; ?>
  140. </div>
  141. <?php endif; ?>
  142. <?php endif; ?>
  143. </main>
  144. </div>
  145. </div>
  146. <footer class="site-footer">
  147. <div class="container">
  148. <p><a href="/admin/" style="text-decoration:none">&copy;</a> <?php echo date('Y'); ?> <?php echo SITE_TITLE; ?>. All rights reserved.</p>
  149. </div>
  150. </footer>
  151. </body>
  152. </html>