publication.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // Start session for language preference
  3. if (session_status() === PHP_SESSION_NONE) {
  4. session_start();
  5. }
  6. require_once '../includes/config.php';
  7. require_once '../includes/database.php';
  8. require_once '../includes/publication.php';
  9. require_once '../includes/translation.php';
  10. // Translation system is auto-initialized when translation.php is included
  11. $publication = new Publication();
  12. $id = (int)($_GET['id'] ?? 0);
  13. $pub = $publication->getById($id);
  14. if (!$pub || $pub['status'] !== 'published') {
  15. http_response_code(404);
  16. echo '<h1>' . t('error_publication_not_found') . '</h1>';
  17. echo '<p>' . t('error_publication_not_found_description') . '</p>';
  18. exit;
  19. }
  20. // Get related publications
  21. $relatedPublications = [];
  22. if ($pub['categories_array']) {
  23. $firstCategory = $pub['categories_array'][0];
  24. $relatedPublications = $publication->getByCategory($firstCategory, 'published');
  25. // Remove current publication from related list
  26. $relatedPublications = array_filter($relatedPublications, function($p) use ($id) {
  27. return $p['id'] != $id;
  28. });
  29. // Limit to 3 related publications
  30. $relatedPublications = array_slice($relatedPublications, 0, 3);
  31. }
  32. ?>
  33. <!DOCTYPE html>
  34. <html lang="en">
  35. <head>
  36. <meta charset="UTF-8">
  37. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  38. <title><?php echo htmlspecialchars($pub['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('publication.php?id=' . $id); ?>
  51. </div>
  52. </header>
  53. <div class="container">
  54. <article class="publication-full">
  55. <header class="publication-header">
  56. <h1><?php echo htmlspecialchars($pub['title']); ?></h1>
  57. <div class="publication-meta">
  58. <span class="author">By <?php echo htmlspecialchars($pub['author']); ?></span>
  59. <span class="date"><?php echo date('F j, Y', strtotime($pub['created_at'])); ?></span>
  60. <?php if ($pub['published_at']): ?>
  61. <span class="published-date">Published <?php echo date('F j, Y', strtotime($pub['published_at'])); ?></span>
  62. <?php endif; ?>
  63. </div>
  64. <?php if ($pub['categories_array']): ?>
  65. <div class="publication-categories">
  66. <?php foreach ($pub['categories_array'] as $category): ?>
  67. <a href="index.php?category=<?php echo urlencode(trim($category)); ?>" class="category-tag">
  68. <?php echo htmlspecialchars(trim($category)); ?>
  69. </a>
  70. <?php endforeach; ?>
  71. </div>
  72. <?php endif; ?>
  73. </header>
  74. <div class="publication-content">
  75. <?php if ($pub['summary']): ?>
  76. <div class="publication-summary">
  77. <p><?php echo htmlspecialchars($pub['summary']); ?></p>
  78. </div>
  79. <?php endif; ?>
  80. <div class="publication-body">
  81. <?php echo $pub['content']; ?>
  82. </div>
  83. </div>
  84. </article>
  85. <?php if (!empty($relatedPublications)): ?>
  86. <section class="related-publications">
  87. <h2><?php echo t('related_publications'); ?></h2>
  88. <div class="publication-grid">
  89. <?php foreach ($relatedPublications as $related): ?>
  90. <article class="publication-card">
  91. <h3>
  92. <a href="publication.php?id=<?php echo $related['id']; ?>">
  93. <?php echo htmlspecialchars($related['title']); ?>
  94. </a>
  95. </h3>
  96. <?php if ($related['summary']): ?>
  97. <p class="summary"><?php echo htmlspecialchars($related['summary']); ?></p>
  98. <?php endif; ?>
  99. <div class="meta">
  100. <span class="author"><?php echo htmlspecialchars($related['author']); ?></span>
  101. <span class="date"><?php echo date('M j, Y', strtotime($related['created_at'])); ?></span>
  102. </div>
  103. </article>
  104. <?php endforeach; ?>
  105. </div>
  106. </section>
  107. <?php endif; ?>
  108. <div class="publication-actions">
  109. <a href="index.php" class="btn"><?php echo t('back_to_publications'); ?></a>
  110. </div>
  111. </div>
  112. <footer class="site-footer">
  113. <div class="container">
  114. <p>&copy; <?php echo date('Y'); ?> <?php echo SITE_TITLE; ?>. All rights reserved.</p>
  115. </div>
  116. </footer>
  117. </body>
  118. </html>