|
Server IP : 2a02:4780:2b:1556:0:9c6:43c4:d / Your IP : 216.73.217.162 Web Server : LiteSpeed System : Linux us-bos-web1456.main-hosting.eu 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64 User : u163988420 ( 163988420) PHP Version : 8.5.4 Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail, proc_open MySQL : OFF | cURL : ON | WGET : ON | Perl : OFF | Python : OFF Directory (0755) : /home/u163988420/domains/awskotra.in/../dnnindia.news/public_html/AACSITE/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
include 'includes/header.php';
// ── Query params ──────────────────────────────────────────────
$query = trim($_GET['q'] ?? '');
$catFilter = trim($_GET['cat'] ?? 'all');
$sort = trim($_GET['sort'] ?? 'relevance');
$page = max(1, (int)($_GET['page'] ?? 1));
$perPage = 6;
// ── Search logic ──────────────────────────────────────────────
function highlightMatch(string $text, string $query): string
{
if (!$query) return htmlspecialchars($text);
$safe = htmlspecialchars($text);
$safeQ = preg_quote(htmlspecialchars($query), '/');
return preg_replace(
'/(' . $safeQ . ')/ui',
'<mark>$1</mark>',
$safe
);
}
$results = [];
if ($query != '') {
foreach ($articles as $article) {
$score = 0;
if (stripos($article['title'], $query) !== false) {
$score += 3;
}
if (stripos($article['excerpt'], $query) !== false) {
$score += 2;
}
if (stripos($article['content'], $query) !== false) {
$score += 1;
}
if (stripos($article['category_name'], $query) !== false) {
$score += 2;
}
if ($score > 0) {
$article['_score'] = $score;
$results[] = $article;
}
}
}
// ── Category filter ───────────────────────────────────────────
$allResultCats = array_unique(array_column($results, 'category_name'));
if ($catFilter !== 'all') {
$results = array_values(array_filter(
$results,
fn($r) => $r['category_name'] === $catFilter
));
}
// ── Sort ─────────────────────────────────────────────────────
if ($sort === 'relevance') {
usort($results, fn($a, $b) => $b['_score'] <=> $a['_score']);
} elseif ($sort === 'latest') {
} elseif ($sort === 'popular') {
usort($results, function ($a, $b) {
$va = (float) preg_replace('/[^0-9.]/', '', $a['views']);
$vb = (float) preg_replace('/[^0-9.]/', '', $b['views']);
return $vb <=> $va;
});
}
// ── Pagination ────────────────────────────────────────────────
$totalResults = count($results);
$totalPages = (int) ceil($totalResults / $perPage);
$page = min($page, max(1, $totalPages));
$offset = ($page - 1) * $perPage;
$pageResults = array_slice($results, $offset, $perPage);
function pageUrl(int $p, string $q, string $cat, string $sort): string
{
return 'search.php?q=' . urlencode($q)
. '&cat=' . urlencode($cat)
. '&sort=' . urlencode($sort)
. '&page=' . $p;
}
// ── Suggestions (popular searches) ───────────────────────────
$suggestions = ['अजमेर', 'राजस्थान', 'राजनीति', 'खेल', 'मनोरंजन', 'शिक्षा', 'व्यापार', 'स्वास्थ्य'];
$pageTitle = $query ? "खोज: {$query}" : 'खोज';
?>
<style>
/* ============================================================
SEARCH PAGE
============================================================ */
/* ── Hero / Search Bar ───── */
.srch-hero {
background: linear-gradient(135deg, #07152b 0%, #0e1f3f 55%, #1a0829 100%);
padding: 64px 0 0;
position: relative;
overflow: hidden;
}
.srch-hero::before {
content: '';
position: absolute;
top: -120px;
right: -120px;
width: 480px;
height: 480px;
border-radius: 50%;
background: radial-gradient(circle, rgba(225, 29, 72, .14) 0%, transparent 70%);
pointer-events: none;
}
.srch-hero::after {
content: '';
position: absolute;
bottom: -60px;
left: 10%;
width: 300px;
height: 300px;
border-radius: 50%;
background: radial-gradient(circle, rgba(99, 102, 241, .08) 0%, transparent 70%);
pointer-events: none;
}
.srch-breadcrumb {
color: #475569;
font-size: 13px;
margin-bottom: 22px;
}
.srch-breadcrumb a {
color: #94a3b8;
transition: .2s;
}
.srch-breadcrumb a:hover {
color: #fff;
}
.srch-breadcrumb span {
margin: 0 8px;
color: #334155;
}
.srch-hero h1 {
font-size: 42px;
font-weight: 900;
color: #fff;
margin-bottom: 8px;
line-height: 1.2;
}
.srch-hero h1 em {
font-style: normal;
color: #fb7185;
}
.srch-hero .sub {
color: #64748b;
font-size: 14.5px;
margin-bottom: 32px;
}
/* Search form */
.srch-form-wrap {
max-width: 780px;
position: relative;
z-index: 2;
}
.srch-form {
display: flex;
background: #fff;
border-radius: 60px;
overflow: hidden;
box-shadow: 0 16px 50px rgba(0, 0, 0, .25), 0 0 0 1px rgba(255, 255, 255, .06);
}
.srch-form input {
flex: 1;
padding: 18px 28px;
font-size: 16px;
font-family: 'Noto Sans Devanagari', sans-serif;
border: none;
outline: none;
color: #0f172a;
background: transparent;
}
.srch-form input::placeholder {
color: #94a3b8;
}
.srch-form button {
background: #e11d48;
color: #fff;
border: none;
padding: 14px 28px;
font-size: 18px;
cursor: pointer;
transition: .25s;
border-radius: 0 60px 60px 0;
display: flex;
align-items: center;
gap: 10px;
font-family: 'Noto Sans Devanagari', sans-serif;
font-size: 14px;
font-weight: 700;
white-space: nowrap;
}
.srch-form button:hover {
background: #be123c;
}
/* Suggestions */
.srch-suggestions {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
padding: 20px 0 28px;
}
.srch-sug-label {
color: #475569;
font-size: 13px;
font-weight: 600;
white-space: nowrap;
}
.srch-sug-pill {
display: inline-block;
background: rgba(255, 255, 255, .07);
border: 1px solid rgba(255, 255, 255, .12);
color: #cbd5e1;
padding: 6px 14px;
border-radius: 30px;
font-size: 13px;
font-weight: 600;
transition: .25s;
}
.srch-sug-pill:hover {
background: #e11d48;
color: #fff;
border-color: #e11d48;
}
/* Tab underline */
.srch-tab-bar {
background: rgba(255, 255, 255, .04);
border-top: 1px solid rgba(255, 255, 255, .07);
padding: 0;
}
.srch-tabs {
display: flex;
gap: 0;
overflow-x: auto;
scrollbar-width: none;
}
.srch-tabs::-webkit-scrollbar {
display: none;
}
.srch-tab {
padding: 14px 22px;
font-size: 14px;
font-weight: 700;
color: #64748b;
border: none;
background: none;
cursor: pointer;
white-space: nowrap;
border-bottom: 3px solid transparent;
transition: .2s;
font-family: 'Noto Sans Devanagari', sans-serif;
}
.srch-tab:hover {
color: #cbd5e1;
}
.srch-tab.active {
color: #fff;
border-bottom-color: #e11d48;
}
/* ── Filters bar ─────────── */
.srch-filters-bar {
background: #fff;
padding: 14px 0;
border-bottom: 1px solid #e2e8f0;
position: sticky;
top: 68px;
z-index: 99;
box-shadow: 0 2px 12px rgba(0, 0, 0, .05);
}
.srch-filters-inner {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
flex-wrap: wrap;
}
.srch-cat-pills {
display: flex;
gap: 8px;
flex-wrap: wrap;
align-items: center;
}
.srch-cat-pill {
border: 1.5px solid #e2e8f0;
background: #fff;
padding: 7px 16px;
border-radius: 40px;
font-size: 13px;
font-weight: 700;
color: #334155;
font-family: 'Noto Sans Devanagari', sans-serif;
cursor: pointer;
transition: .2s;
display: inline-flex;
align-items: center;
gap: 6px;
text-decoration: none;
}
.srch-cat-pill:hover,
.srch-cat-pill.active {
background: #e11d48;
color: #fff;
border-color: #e11d48;
}
.srch-sort-wrap {
display: flex;
align-items: center;
gap: 10px;
flex-shrink: 0;
}
.srch-sort-label {
font-size: 13px;
color: #64748b;
font-weight: 600;
white-space: nowrap;
}
.srch-sort-select {
border: 1.5px solid #e2e8f0;
border-radius: 40px;
padding: 7px 14px;
font-size: 13px;
font-weight: 700;
color: #334155;
outline: none;
background: #fff;
font-family: 'Noto Sans Devanagari', sans-serif;
cursor: pointer;
}
/* ── Results section ─────── */
.srch-results-section {
padding: 40px 0 80px;
background: #f1f5f9;
}
/* Results count */
.srch-count-bar {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 28px;
flex-wrap: wrap;
gap: 12px;
}
.srch-count-text {
font-size: 15px;
color: #64748b;
font-weight: 600;
}
.srch-count-text strong {
color: #0f172a;
}
.srch-count-text mark {
background: rgba(225, 29, 72, .12);
color: #e11d48;
border-radius: 4px;
padding: 1px 5px;
font-style: normal;
}
/* Result card */
.srch-card {
background: #fff;
border-radius: 20px;
overflow: hidden;
display: flex;
box-shadow: 0 4px 20px rgba(0, 0, 0, .07);
transition: .3s;
margin-bottom: 20px;
}
.srch-card:hover {
transform: translateY(-4px);
box-shadow: 0 16px 40px rgba(0, 0, 0, .11);
}
.srch-card-img {
width: 240px;
flex-shrink: 0;
overflow: hidden;
}
.srch-card-img img {
width: 100%;
height: 100%;
object-fit: cover;
transition: .4s;
}
.srch-card:hover .srch-card-img img {
transform: scale(1.06);
}
.srch-card-body {
padding: 24px 28px;
display: flex;
flex-direction: column;
justify-content: center;
flex: 1;
}
.srch-card-cat {
display: inline-flex;
align-items: center;
gap: 6px;
background: rgba(225, 29, 72, .1);
color: #e11d48;
padding: 4px 12px;
border-radius: 20px;
font-size: 11.5px;
font-weight: 800;
margin-bottom: 12px;
width: fit-content;
}
.srch-card-title {
font-size: 19px;
font-weight: 800;
color: #0f172a;
line-height: 1.5;
margin-bottom: 10px;
}
.srch-card-title mark {
background: rgba(251, 113, 133, .15);
color: #be123c;
border-radius: 3px;
padding: 0 3px;
}
.srch-card-excerpt {
font-size: 14px;
color: #64748b;
line-height: 1.7;
margin-bottom: 16px;
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
}
.srch-card-excerpt mark {
background: rgba(251, 113, 133, .12);
color: #be123c;
border-radius: 3px;
}
.srch-card-meta {
display: flex;
align-items: center;
gap: 18px;
flex-wrap: wrap;
}
.srch-card-meta span {
display: flex;
align-items: center;
gap: 6px;
color: #94a3b8;
font-size: 13px;
}
.srch-card-meta i {
color: #e11d48;
}
.srch-card-link {
display: inline-flex;
align-items: center;
gap: 6px;
color: #e11d48;
font-size: 13.5px;
font-weight: 700;
transition: .2s;
margin-left: auto;
}
.srch-card-link:hover {
gap: 10px;
color: #be123c;
}
/* ── Empty state ─────────── */
.srch-empty {
text-align: center;
padding: 80px 20px;
background: #fff;
border-radius: 24px;
box-shadow: 0 4px 20px rgba(0, 0, 0, .06);
}
.srch-empty-icon {
width: 90px;
height: 90px;
border-radius: 24px;
background: #fef2f2;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 24px;
font-size: 40px;
color: #fca5a5;
}
.srch-empty h3 {
font-size: 22px;
font-weight: 800;
color: #0f172a;
margin-bottom: 12px;
}
.srch-empty p {
color: #64748b;
font-size: 14.5px;
line-height: 1.8;
max-width: 440px;
margin: 0 auto 28px;
}
.srch-empty .try-label {
font-size: 13px;
color: #94a3b8;
font-weight: 600;
margin-bottom: 12px;
}
.srch-empty-pills {
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: center;
}
.srch-empty-pill {
display: inline-block;
border: 1.5px solid #e2e8f0;
background: #fff;
color: #334155;
padding: 7px 16px;
border-radius: 30px;
font-size: 13px;
font-weight: 700;
transition: .2s;
text-decoration: none;
}
.srch-empty-pill:hover {
background: #e11d48;
color: #fff;
border-color: #e11d48;
}
/* ── Initial state (no query) */
.srch-initial {
text-align: center;
padding: 80px 20px;
}
.srch-initial-icon {
width: 100px;
height: 100px;
border-radius: 28px;
background: linear-gradient(135deg, rgba(225, 29, 72, .1), rgba(225, 29, 72, .05));
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 24px;
font-size: 44px;
color: #e11d48;
border: 2px solid rgba(225, 29, 72, .1);
}
.srch-initial h3 {
font-size: 24px;
font-weight: 800;
color: #0f172a;
margin-bottom: 10px;
}
.srch-initial p {
color: #64748b;
font-size: 15px;
margin-bottom: 32px;
}
.srch-popular-grid {
display: flex;
gap: 10px;
flex-wrap: wrap;
justify-content: center;
max-width: 560px;
margin: 0 auto;
}
.srch-pop-card {
display: inline-flex;
align-items: center;
gap: 8px;
background: #fff;
color: #334155;
padding: 10px 18px;
border-radius: 40px;
font-size: 13.5px;
font-weight: 700;
border: 1.5px solid #e2e8f0;
text-decoration: none;
transition: .25s;
box-shadow: 0 2px 8px rgba(0, 0, 0, .05);
}
.srch-pop-card i {
color: #e11d48;
font-size: 13px;
}
.srch-pop-card:hover {
background: #e11d48;
color: #fff;
border-color: #e11d48;
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(225, 29, 72, .2);
}
.srch-pop-card:hover i {
color: #fff;
}
/* ── Pagination ──────────── */
.srch-pagination {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin-top: 40px;
flex-wrap: wrap;
}
.pg-btn {
width: 42px;
height: 42px;
border-radius: 12px;
background: #fff;
border: 1.5px solid #e2e8f0;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
font-weight: 700;
color: #334155;
text-decoration: none;
transition: .2s;
}
.pg-btn:hover {
background: rgba(225, 29, 72, .07);
border-color: #e11d48;
color: #e11d48;
}
.pg-btn.active {
background: #e11d48;
color: #fff;
border-color: #e11d48;
}
.pg-btn.disabled {
opacity: .4;
pointer-events: none;
}
.pg-dots {
color: #94a3b8;
font-size: 14px;
padding: 0 4px;
}
/* ── Related articles ────── */
.srch-related {
padding: 50px 0 70px;
background: #fff;
}
.srch-related-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 24px;
}
.srch-rel-card {
border-radius: 16px;
overflow: hidden;
box-shadow: 0 4px 16px rgba(0, 0, 0, .07);
transition: .3s;
background: #f8fafc;
}
.srch-rel-card:hover {
transform: translateY(-4px);
box-shadow: 0 12px 30px rgba(0, 0, 0, .1);
}
.srch-rel-img {
height: 170px;
overflow: hidden;
}
.srch-rel-img img {
width: 100%;
height: 100%;
object-fit: cover;
transition: .4s;
}
.srch-rel-card:hover .srch-rel-img img {
transform: scale(1.06);
}
.srch-rel-body {
padding: 16px 18px;
}
.srch-rel-cat {
display: inline-block;
background: rgba(225, 29, 72, .1);
color: #e11d48;
padding: 3px 10px;
border-radius: 16px;
font-size: 11px;
font-weight: 800;
margin-bottom: 8px;
}
.srch-rel-title {
font-size: 14.5px;
font-weight: 700;
color: #0f172a;
line-height: 1.5;
margin-bottom: 10px;
}
.srch-rel-meta {
font-size: 12px;
color: #94a3b8;
display: flex;
align-items: center;
gap: 6px;
}
.srch-rel-meta i {
color: #e11d48;
}
/* ── Responsive ──────────── */
@media(max-width:991px) {
.srch-related-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media(max-width:768px) {
.srch-hero h1 {
font-size: 28px;
}
.srch-hero {
padding: 48px 0 0;
}
.srch-card {
flex-direction: column;
}
.srch-card-img {
width: 100%;
height: 200px;
}
.srch-card-body {
padding: 18px 20px;
}
.srch-card-title {
font-size: 16px;
}
.srch-filters-bar {
top: 60px;
}
}
@media(max-width:576px) {
.srch-form input {
padding: 15px 18px;
font-size: 14px;
}
.srch-form button span {
display: none;
}
.srch-form button {
padding: 14px 20px;
border-radius: 0 60px 60px 0;
}
.srch-related-grid {
grid-template-columns: 1fr;
}
.srch-filters-inner {
gap: 10px;
}
}
</style>
<!-- ============================================================
HERO — search bar
============================================================ -->
<section class="srch-hero">
<div class="container" style="position:relative;z-index:2;">
<!-- Breadcrumb -->
<div class="srch-breadcrumb">
<a href="index.php">होम</a>
<span>/</span>
<span style="color:#94a3b8">खोज</span>
</div>
<!-- Heading -->
<?php if ($query): ?>
<h1>"<em><?php echo htmlspecialchars($query); ?></em>" के परिणाम</h1>
<p class="sub">
<?php if ($totalResults > 0): ?>
<?php echo $totalResults; ?> खबरें मिलीं · पेज <?php echo $page; ?> / <?php echo max(1, $totalPages); ?>
<?php else: ?>
कोई परिणाम नहीं मिला
<?php endif; ?>
</p>
<?php else: ?>
<h1>खबर खोजें <i class="bi bi-search" style="font-size:32px;color:#fb7185;vertical-align:middle;"></i></h1>
<p class="sub">अजमेर, राजस्थान और देश-दुनिया की कोई भी खबर खोजें</p>
<?php endif; ?>
<!-- Search Form -->
<div class="srch-form-wrap">
<form class="srch-form" method="GET" action="search.php">
<input
type="text"
name="q"
value="<?php echo htmlspecialchars($query); ?>"
placeholder="खबर का शीर्षक, श्रेणी या कीवर्ड लिखें..."
id="heroSearchInput"
autocomplete="off">
<button type="submit">
<i class="bi bi-search"></i>
<span>खोजें</span>
</button>
</form>
<!-- Live suggestions dropdown -->
<div id="liveSuggest" style="
display:none;
position:absolute; left:0; right:0;
top:calc(100% + 8px);
background:#fff;
border-radius:16px;
box-shadow:0 20px 60px rgba(0,0,0,.2);
overflow:hidden;
z-index:200;
border:1px solid rgba(0,0,0,.06);
"></div>
</div>
<!-- Suggestion Pills -->
<div class="srch-suggestions">
<span class="srch-sug-label"><i class="bi bi-fire" style="color:#fb7185;margin-right:4px;"></i> लोकप्रिय:</span>
<?php foreach ($suggestions as $s): ?>
<a href="search.php?q=<?php echo urlencode($s); ?>" class="srch-sug-pill"><?php echo $s; ?></a>
<?php endforeach; ?>
</div>
</div>
</section>
<?php if ($query): ?>
<!-- ============================================================
FILTER BAR
============================================================ -->
<div class="srch-filters-bar">
<div class="container">
<div class="srch-filters-inner">
<div class="srch-cat-pills">
<a href="search.php?q=<?php echo urlencode($query); ?>&cat=all&sort=<?php echo urlencode($sort); ?>"
class="srch-cat-pill <?php echo $catFilter === 'all' ? 'active' : ''; ?>">
<i class="bi bi-grid-fill" style="font-size:11px;"></i> सभी
<span style="font-size:11px;opacity:.7;">(<?php echo count($results) + ($catFilter !== 'all' ? array_sum(array_map(fn($c) => 1, array_filter($results, fn($r) => true))) : 0); ?>)</span>
</a>
<?php foreach ($allResultCats as $rcat): ?>
<?php
$catCount = count(array_filter(
// count from full results before category filter
array_filter($results, fn($r) => $catFilter === 'all' || $r['category_name'] === $catFilter),
fn($r) => $r['category_name'] === $rcat
));
// Recount from all results
$allForCat = array_filter(
array_filter($articles, function ($a) use ($query) {
$q = mb_strtolower($query, 'UTF-8');
return str_contains(mb_strtolower($a['title'], 'UTF-8'), $q)
|| str_contains(mb_strtolower($a['excerpt'], 'UTF-8'), $q)
|| str_contains(mb_strtolower($a['category_name'], 'UTF-8'), $q)
|| str_contains(mb_strtolower($a['content'], 'UTF-8'), $q);
}),
fn($r) => $r['category_name'] === $rcat
);
?>
<a href="search.php?q=<?php echo urlencode($query); ?>&cat=<?php echo urlencode($rcat); ?>&sort=<?php echo urlencode($sort); ?>"
class="srch-cat-pill <?php echo $catFilter === $rcat ? 'active' : ''; ?>">
<?php echo $rcat; ?>
<span style="font-size:11px;opacity:.7;">(<?php echo count($allForCat); ?>)</span>
</a>
<?php endforeach; ?>
</div>
<div class="srch-sort-wrap">
<span class="srch-sort-label">क्रमबद्ध:</span>
<select class="srch-sort-select" onchange="applySort(this.value)">
<option value="relevance" <?php echo $sort === 'relevance' ? 'selected' : ''; ?>>प्रासंगिकता</option>
<option value="latest" <?php echo $sort === 'latest' ? 'selected' : ''; ?>>नवीनतम</option>
</select>
</div>
</div>
</div>
</div>
<!-- ============================================================
RESULTS
============================================================ -->
<section class="srch-results-section">
<div class="container">
<?php if ($totalResults > 0): ?>
<!-- Count bar -->
<div class="srch-count-bar">
<p class="srch-count-text">
<strong><?php echo $totalResults; ?></strong> परिणाम मिले
"<mark><?php echo htmlspecialchars($query); ?></mark>" के लिए
<?php if ($catFilter !== 'all'): ?>
· श्रेणी: <strong><?php echo htmlspecialchars($catFilter); ?></strong>
<?php endif; ?>
</p>
<span style="font-size:13px;color:#94a3b8;">पेज <?php echo $page; ?> / <?php echo $totalPages; ?></span>
</div>
<!-- Cards -->
<?php foreach ($pageResults as $r): ?>
<article class="srch-card">
<div class="srch-card-img">
<img src="admin/uploads/articles/<?php echo $r['image']; ?>" alt="<?php echo htmlspecialchars($r['title']); ?>" loading="lazy">
</div>
<div class="srch-card-body">
<div class="srch-card-cat">
<i class="bi bi-tag-fill" style="font-size:10px;"></i>
<a href="category.php?slug=<?php echo $r['category_slug']; ?>" style="color:inherit;text-decoration:none;">
<?php echo $r['category_name']; ?>
</a>
</div>
<h2 class="srch-card-title">
<a href="article.php?slug=<?php echo $r['slug']; ?>" style="color:inherit;text-decoration:none;">
<?php echo highlightMatch($r['title'], $query); ?>
</a>
</h2>
<p class="srch-card-excerpt"><?php echo highlightMatch($r['excerpt'], $query); ?></p>
<div class="srch-card-meta">
<span>
<i class="bi bi-clock-fill"></i>
<?php echo date('d M Y', strtotime($r['created_at'])); ?>
</span>
<span><i class="bi bi-person-fill"></i> <?php echo $r['author']; ?></span>
<a href="article.php?slug=<?php echo $r['slug']; ?>" class="srch-card-link">
पढ़ें <i class="bi bi-arrow-right"></i>
</a>
</div>
</div>
</article>
<?php endforeach; ?>
<!-- Pagination -->
<?php if ($totalPages > 1): ?>
<div class="srch-pagination">
<!-- Prev -->
<a href="<?php echo pageUrl($page - 1, $query, $catFilter, $sort); ?>"
class="pg-btn <?php echo $page <= 1 ? 'disabled' : ''; ?>">
<i class="bi bi-chevron-left"></i>
</a>
<?php
$range = 2;
for ($p = 1; $p <= $totalPages; $p++):
if ($p === 1 || $p === $totalPages || abs($p - $page) <= $range):
?>
<?php if ($p > 1 && $p < $totalPages && abs($p - $page) === $range + 1): ?>
<span class="pg-dots">…</span>
<?php endif; ?>
<a href="<?php echo pageUrl($p, $query, $catFilter, $sort); ?>"
class="pg-btn <?php echo $p === $page ? 'active' : ''; ?>">
<?php echo $p; ?>
</a>
<?php
endif;
endfor;
?>
<!-- Next -->
<a href="<?php echo pageUrl($page + 1, $query, $catFilter, $sort); ?>"
class="pg-btn <?php echo $page >= $totalPages ? 'disabled' : ''; ?>">
<i class="bi bi-chevron-right"></i>
</a>
</div>
<?php endif; ?>
<?php else: ?>
<!-- Empty state -->
<div class="srch-empty">
<div class="srch-empty-icon"><i class="bi bi-search"></i></div>
<h3>"<?php echo htmlspecialchars($query); ?>" के लिए कोई खबर नहीं मिली</h3>
<p>कृपया अलग कीवर्ड से खोजें, वर्तनी जांचें, या नीचे दी गई श्रेणियों में से चुनें।</p>
<p class="try-label">इन्हें आजमाएं:</p>
<div class="srch-empty-pills">
<?php foreach ($suggestions as $s): ?>
<a href="search.php?q=<?php echo urlencode($s); ?>" class="srch-empty-pill"><?php echo $s; ?></a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
</section>
<!-- ============================================================
RELATED / LATEST ARTICLES (shown when results exist)
============================================================ -->
<?php if ($totalResults > 0): ?>
<section class="srch-related">
<div class="container">
<div class="an-section-heading" style="margin-bottom:28px;">
<div class="accent-bar"></div>
<h2>और खबरें पढ़ें</h2>
<a href="index.php" class="see-all">सभी देखें <i class="bi bi-arrow-right"></i></a>
</div>
<div class="srch-related-grid">
<?php
// Pick 3 articles NOT in current results
$resultIds = array_column($results, 'id');
$related = array_filter($articles, fn($a) => !in_array($a['id'], $resultIds));
$related = array_slice(array_values($related), 0, 3);
foreach ($related as $rel):
?>
<a href="article.php?slug=<?php echo $rel['slug']; ?>" class="srch-rel-card" style="text-decoration:none;">
<div class="srch-rel-img">
<img src="admin/uploads/articles/<?php echo $rel['image']; ?>" alt="<?php echo htmlspecialchars($rel['title']); ?>" loading="lazy">
</div>
<div class="srch-rel-body">
<div class="srch-rel-cat"><?php echo $rel['category_name']; ?></div>
<div class="srch-rel-title"><?php echo $rel['title']; ?></div>
<div class="srch-rel-meta"><i class="bi bi-clock-fill"></i> <?php echo date('d M Y', strtotime($r['created_at'])); ?></div>
</div>
</a>
<?php endforeach; ?>
</div>
</div>
</section>
<?php endif; ?>
<?php else: ?>
<!-- ============================================================
INITIAL STATE — no query yet
============================================================ -->
<section class="srch-results-section">
<div class="container">
<div class="srch-initial">
<div class="srch-initial-icon"><i class="bi bi-search"></i></div>
<h3>क्या खोज रहे हैं?</h3>
<p>ऊपर सर्च बॉक्स में कोई भी कीवर्ड लिखें और अजमेर की हर खबर पाएं।</p>
<div class="srch-popular-grid">
<?php foreach ($suggestions as $s): ?>
<a href="search.php?q=<?php echo urlencode($s); ?>" class="srch-pop-card">
<i class="bi bi-trending-up"></i> <?php echo $s; ?>
</a>
<?php endforeach; ?>
</div>
</div>
<!-- Show latest articles as discovery -->
<div style="margin-top:60px;">
<div class="an-section-heading" style="margin-bottom:28px;">
<div class="accent-bar"></div>
<h2>ताज़ा खबरें</h2>
<a href="index.php" class="see-all">सभी देखें <i class="bi bi-arrow-right"></i></a>
</div>
<div class="srch-related-grid">
<?php foreach (array_slice($articles, 0, 3) as $art): ?>
<a href="article.php?slug=<?php echo $art['slug']; ?>" class="srch-rel-card" style="text-decoration:none;">
<div class="srch-rel-img">
<img src="admin/uploads/articles/<?php echo $art['image']; ?>" alt="<?php echo htmlspecialchars($art['title']); ?>" loading="lazy">
</div>
<div class="srch-rel-body">
<div class="srch-rel-cat"><?php echo $art['category_name']; ?></div>
<div class="srch-rel-title"><?php echo $art['title']; ?></div>
<div class="srch-rel-meta"><i class="bi bi-clock-fill"></i> <?php echo date('d M Y', strtotime($art['created_at'])); ?></div>
</div>
</a>
<?php endforeach; ?>
</div>
</div>
</div>
</section>
<?php endif; ?>
<script>
// ── Sort redirect ─────────────────────────────────────────────
function applySort(val) {
const url = new URL(window.location.href);
url.searchParams.set('sort', val);
url.searchParams.set('page', '1');
window.location.href = url.toString();
}
// ── Live suggestions ──────────────────────────────────────────
const input = document.getElementById('heroSearchInput');
const liveSugBox = document.getElementById('liveSuggest');
const articleData = <?php echo json_encode(array_map(
fn($a) => [
'title' => $a['title'],
'category_name' => $a['category_name'],
'slug' => $a['slug']
],
$articles
)); ?>;
let debounceTimer;
input.addEventListener('input', () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => showSuggestions(input.value.trim()), 200);
});
input.addEventListener('keydown', (e) => {
if (e.key === 'Escape') hideSuggestions();
});
document.addEventListener('click', (e) => {
if (!input.closest('.srch-form-wrap').contains(e.target)) hideSuggestions();
});
function showSuggestions(q) {
if (!q || q.length < 2) {
hideSuggestions();
return;
}
const qL = q.toLowerCase();
const matches = articleData
.filter(a =>
a.title.toLowerCase().includes(qL) ||
a.category.toLowerCase().includes(qL)
)
.slice(0, 6);
if (!matches.length) {
hideSuggestions();
return;
}
liveSugBox.innerHTML = matches.map(m => `
<a href="article.php?slug=${m.slug}"
style="display:flex;align-items:center;gap:12px;padding:12px 18px;color:#0f172a;
text-decoration:none;transition:.15s;border-bottom:1px solid #f1f5f9;"
onmouseover="this.style.background='#fef2f2'"
onmouseout="this.style.background=''"
>
<i class="bi bi-newspaper" style="color:#e11d48;font-size:15px;flex-shrink:0;"></i>
<span style="flex:1;font-size:14px;font-weight:600;line-height:1.4;">
${highlight(m.title, q)}
</span>
<span style="font-size:11.5px;background:rgba(225,29,72,.09);color:#e11d48;
padding:3px 10px;border-radius:12px;font-weight:700;flex-shrink:0;">
${m.category}
</span>
</a>
`).join('') +
`<a href="search.php?q=${encodeURIComponent(q)}"
style="display:flex;align-items:center;justify-content:center;gap:8px;
padding:12px 18px;color:#e11d48;font-size:13.5px;font-weight:700;
text-decoration:none;background:#fef2f2;"
onmouseover="this.style.background='#fee2e2'"
onmouseout="this.style.background='#fef2f2'"
>
<i class="bi bi-search"></i> "${q}" सभी परिणाम देखें
</a>`;
liveSugBox.style.display = 'block';
}
function hideSuggestions() {
liveSugBox.style.display = 'none';
}
function highlight(text, q) {
const safe = text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
const safeQ = q.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return safe.replace(new RegExp(`(${safeQ})`, 'gi'), '<mark style="background:rgba(251,113,133,.2);color:#be123c;border-radius:3px;padding:0 2px;">$1</mark>');
}
</script>
<?php include 'includes/footer.php'; ?>