| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- require_once '../includes/config.php';
- require_once '../includes/database.php';
- require_once '../includes/publication.php';
- $publication = new Publication();
- $query = $_GET['q'] ?? '';
- $page = max(1, (int)($_GET['page'] ?? 1));
- $limit = 10;
- $offset = ($page - 1) * $limit;
- $results = [];
- $totalResults = 0;
- if ($query) {
- $results = $publication->search($query, 'published');
- $totalResults = count($results);
-
- // Apply pagination
- $results = array_slice($results, $offset, $limit);
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Search - <?php echo SITE_TITLE; ?></title>
- <link rel="stylesheet" href="../css/style.css">
- </head>
- <body>
- <header class="site-header">
- <div class="container">
- <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
- <nav class="main-nav">
- <a href="index.php">Home</a>
- <a href="categories.php">Categories</a>
- <a href="search.php">Search</a>
- </nav>
- </div>
- </header>
- <div class="container">
- <main class="main-content">
- <h2>Search Publications</h2>
-
- <form method="get" class="search-form-large">
- <input type="text" name="q" placeholder="Search for publications..."
- value="<?php echo htmlspecialchars($query); ?>" required>
- <button type="submit" class="btn btn-primary">Search</button>
- </form>
- <?php if ($query): ?>
- <div class="search-results">
- <h3>Search Results for "<?php echo htmlspecialchars($query); ?>"</h3>
-
- <?php if (empty($results)): ?>
- <p>No publications found matching your search.</p>
- <?php else: ?>
- <p class="results-count">Found <?php echo $totalResults; ?> publications</p>
-
- <div class="publication-list">
- <?php foreach ($results as $pub): ?>
- <article class="publication-summary">
- <h3>
- <a href="publication.php?id=<?php echo $pub['id']; ?>">
- <?php echo htmlspecialchars($pub['title']); ?>
- </a>
- </h3>
-
- <?php if ($pub['summary']): ?>
- <p class="summary"><?php echo htmlspecialchars($pub['summary']); ?></p>
- <?php endif; ?>
-
- <div class="meta">
- <span class="author">By <?php echo htmlspecialchars($pub['author']); ?></span>
- <span class="date"><?php echo date('F j, Y', strtotime($pub['created_at'])); ?></span>
- <?php if ($pub['categories']): ?>
- <span class="categories">
- <?php foreach (explode(',', $pub['categories']) as $cat): ?>
- <a href="index.php?category=<?php echo urlencode(trim($cat)); ?>" class="category-tag">
- <?php echo htmlspecialchars(trim($cat)); ?>
- </a>
- <?php endforeach; ?>
- </span>
- <?php endif; ?>
- </div>
- </article>
- <?php endforeach; ?>
- </div>
- <?php $totalPages = ceil($totalResults / $limit); ?>
- <?php if ($totalPages > 1): ?>
- <div class="pagination">
- <?php if ($page > 1): ?>
- <a href="?q=<?php echo urlencode($query); ?>&page=<?php echo $page - 1; ?>" class="pagination-link">« Previous</a>
- <?php endif; ?>
- <?php for ($i = 1; $i <= $totalPages; $i++): ?>
- <?php if ($i == $page): ?>
- <span class="pagination-current"><?php echo $i; ?></span>
- <?php else: ?>
- <a href="?q=<?php echo urlencode($query); ?>&page=<?php echo $i; ?>" class="pagination-link"><?php echo $i; ?></a>
- <?php endif; ?>
- <?php endfor; ?>
- <?php if ($page < $totalPages): ?>
- <a href="?q=<?php echo urlencode($query); ?>&page=<?php echo $page + 1; ?>" class="pagination-link">Next »</a>
- <?php endif; ?>
- </div>
- <?php endif; ?>
- <?php endif; ?>
- </div>
- <?php endif; ?>
- </main>
- </div>
- <footer class="site-footer">
- <div class="container">
- <p>© <?php echo date('Y'); ?> <?php echo SITE_TITLE; ?>. All rights reserved.</p>
- </div>
- </footer>
- </body>
- </html>
|