publication.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. require_once '../includes/config.php';
  3. require_once '../includes/database.php';
  4. require_once '../includes/publication.php';
  5. $publication = new Publication();
  6. $id = (int)($_GET['id'] ?? 0);
  7. $pub = $publication->getById($id);
  8. if (!$pub || $pub['status'] !== 'published') {
  9. http_response_code(404);
  10. echo '<h1>Publication Not Found</h1>';
  11. echo '<p>The requested publication could not be found.</p>';
  12. exit;
  13. }
  14. // Get related publications
  15. $relatedPublications = [];
  16. if ($pub['categories_array']) {
  17. $firstCategory = $pub['categories_array'][0];
  18. $relatedPublications = $publication->getByCategory($firstCategory, 'published');
  19. // Remove current publication from related list
  20. $relatedPublications = array_filter($relatedPublications, function($p) use ($id) {
  21. return $p['id'] != $id;
  22. });
  23. // Limit to 3 related publications
  24. $relatedPublications = array_slice($relatedPublications, 0, 3);
  25. }
  26. ?>
  27. <!DOCTYPE html>
  28. <html lang="en">
  29. <head>
  30. <meta charset="UTF-8">
  31. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  32. <title><?php echo htmlspecialchars($pub['title']); ?> - <?php echo SITE_TITLE; ?></title>
  33. <link rel="stylesheet" href="../css/style.css">
  34. </head>
  35. <body>
  36. <header class="site-header">
  37. <div class="container">
  38. <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
  39. <nav class="main-nav">
  40. <a href="index.php">Home</a>
  41. <a href="categories.php">Categories</a>
  42. <a href="search.php">Search</a>
  43. </nav>
  44. </div>
  45. </header>
  46. <div class="container">
  47. <article class="publication-full">
  48. <header class="publication-header">
  49. <h1><?php echo htmlspecialchars($pub['title']); ?></h1>
  50. <div class="publication-meta">
  51. <span class="author">By <?php echo htmlspecialchars($pub['author']); ?></span>
  52. <span class="date"><?php echo date('F j, Y', strtotime($pub['created_at'])); ?></span>
  53. <?php if ($pub['published_at']): ?>
  54. <span class="published-date">Published <?php echo date('F j, Y', strtotime($pub['published_at'])); ?></span>
  55. <?php endif; ?>
  56. </div>
  57. <?php if ($pub['categories_array']): ?>
  58. <div class="publication-categories">
  59. <?php foreach ($pub['categories_array'] as $category): ?>
  60. <a href="index.php?category=<?php echo urlencode(trim($category)); ?>" class="category-tag">
  61. <?php echo htmlspecialchars(trim($category)); ?>
  62. </a>
  63. <?php endforeach; ?>
  64. </div>
  65. <?php endif; ?>
  66. </header>
  67. <div class="publication-content">
  68. <?php if ($pub['summary']): ?>
  69. <div class="publication-summary">
  70. <p><?php echo htmlspecialchars($pub['summary']); ?></p>
  71. </div>
  72. <?php endif; ?>
  73. <div class="publication-body">
  74. <?php echo nl2br(htmlspecialchars($pub['content'])); ?>
  75. </div>
  76. </div>
  77. </article>
  78. <?php if (!empty($relatedPublications)): ?>
  79. <section class="related-publications">
  80. <h2>Related Publications</h2>
  81. <div class="publication-grid">
  82. <?php foreach ($relatedPublications as $related): ?>
  83. <article class="publication-card">
  84. <h3>
  85. <a href="publication.php?id=<?php echo $related['id']; ?>">
  86. <?php echo htmlspecialchars($related['title']); ?>
  87. </a>
  88. </h3>
  89. <?php if ($related['summary']): ?>
  90. <p class="summary"><?php echo htmlspecialchars($related['summary']); ?></p>
  91. <?php endif; ?>
  92. <div class="meta">
  93. <span class="author"><?php echo htmlspecialchars($related['author']); ?></span>
  94. <span class="date"><?php echo date('M j, Y', strtotime($related['created_at'])); ?></span>
  95. </div>
  96. </article>
  97. <?php endforeach; ?>
  98. </div>
  99. </section>
  100. <?php endif; ?>
  101. <div class="publication-actions">
  102. <a href="index.php" class="btn">Back to Publications</a>
  103. </div>
  104. </div>
  105. <footer class="site-footer">
  106. <div class="container">
  107. <p>&copy; <?php echo date('Y'); ?> <?php echo SITE_TITLE; ?>. All rights reserved.</p>
  108. </div>
  109. </footer>
  110. </body>
  111. </html>