publication.php 5.4 KB

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