:: **Zploit** v1.0 | Current Path: **/home/iictguj2/indiadealfinder.com/public_html/**
:: Editing File: search.php
<?php include('includes/db.php'); ?> <?php include('header.php'); ?> <div class="container"> <h2>Search Results</h2> <style> /* You can retain the same styling for your grid and cards from index.php */ .deals-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 20px; margin-top: 20px; } @media (max-width: 992px) { .deals-grid { grid-template-columns: repeat(3, 1fr); } } @media (max-width: 600px) { .deals-grid { grid-template-columns: repeat(2, 1fr); } } .deal-card { background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); padding: 15px; display: flex; flex-direction: column; transition: 0.3s; } .deal-card:hover { box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15); } .deal-image { width: 100%; height: 160px; object-fit: cover; border-radius: 6px; margin-bottom: 12px; } .deal-title { font-size: 18px; margin: 0 0 10px 0; color: #333; } .deal-description { flex-grow: 1; font-size: 14px; color: #555; margin-bottom: 10px; max-height: 60px; overflow: hidden; } .deal-category, .deal-expires { font-size: 12px; color: #999; margin-bottom: 8px; } .grab-deal-btn { background-color: #007bff; color: white; padding: 10px; text-align: center; border-radius: 5px; font-weight: bold; text-decoration: none; transition: background-color 0.3s ease; } .grab-deal-btn:hover { background-color: #0056b3; } .like-btn { background: none; border: none; color: #007bff; cursor: pointer; font-size: 14px; padding: 0; margin-bottom: 10px; } .like-btn:hover { text-decoration: underline; } .pagination { margin-top: 30px; text-align: center; } .pagination a { display: inline-block; padding: 8px 12px; margin: 0 4px; background: #007bff; color: white; border-radius: 4px; text-decoration: none; } .pagination a:hover { background: #0056b3; } .pagination .current-page { font-weight: bold; background: #0056b3; } </style> <?php function truncateTitle($text, $maxWords = 12, $maxChars = 48) { $text = html_entity_decode($text); $words = preg_split('/\s+/', $text); if (count($words) > $maxWords) { $words = array_slice($words, 0, $maxWords); $truncated = implode(' ', $words); if (strlen($truncated) > $maxChars) { $truncated = mb_substr($truncated, 0, $maxChars); $truncated = rtrim($truncated); } return htmlspecialchars($truncated) . '...'; } else { if (strlen($text) > $maxChars) { $truncated = mb_substr($text, 0, $maxChars); $truncated = rtrim($truncated); return htmlspecialchars($truncated) . '...'; } else { return htmlspecialchars($text); } } } // Pagination setup $limit = 20; $page = isset($_GET['page']) && is_numeric($_GET['page']) ? intval($_GET['page']) : 1; $offset = ($page - 1) * $limit; if (isset($_GET['q'])) { $q = $conn->real_escape_string($_GET['q']); // Count total search results $countRes = $conn->query("SELECT COUNT(*) AS total FROM deals WHERE (title LIKE '%$q%' OR description LIKE '%$q%') AND is_active = 1"); $totalDeals = $countRes->fetch_assoc()['total']; $totalPages = ceil($totalDeals / $limit); // SQL query for search results $sql = "SELECT deals.*, categories.name AS category FROM deals LEFT JOIN categories ON deals.category_id = categories.id WHERE (deals.title LIKE '%$q%' OR deals.description LIKE '%$q%') AND is_active = 1 ORDER BY created_at DESC LIMIT $limit OFFSET $offset"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo '<div class="deals-grid">'; while ($row = $result->fetch_assoc()) { // Deal expiry logic if (empty($row['expires_at'])) { $created_at = strtotime($row['created_at']); $now = time(); $diff = $now - $created_at; $expire_str = ($diff > (7 * 24 * 60 * 60)) ? "<span style='color:red;'>Expired</span>" : "<span style='color:green;'>Soon</span>"; } else { $expires = strtotime($row['expires_at']); $now = time(); $diff = $expires - $now; $expire_str = $diff > 0 ? floor($diff / (60 * 60 * 24)) . "d " . floor(($diff % (60 * 60 * 24)) / 3600) . "h " . floor(($diff % 3600) / 60) . "m left" : "<span style='color:red;'>Expired</span>"; } // Image handling $image = !empty($row['image']) ? (strpos($row['image'], 'http://') === 0 || strpos($row['image'], 'https://') === 0 ? $row['image'] : 'uploads/' . $row['image']) : 'placeholder.jpg'; // Affiliate URL $affiliate_url = $row['affiliate_url'] ?? ''; $prefix = 'https://dealofthedayindia.com/go.php?'; if (strpos($affiliate_url, $prefix) === 0) { $affiliate_url = substr($affiliate_url, strlen($prefix)); } // Output deal card echo "<div class='deal-card'>"; echo "<img class='deal-image' src='$image' alt='" . htmlspecialchars($row['title']) . "' />"; echo "<h3 class='deal-title'><a href='deal.php?id={$row['id']}' style='text-decoration:none; color:inherit;'>" . truncateTitle($row['title']) . "</a></h3>"; echo "<div class='deal-description'>" . substr(strip_tags($row['description']), 0, 150) . "...</div>"; echo "<div class='deal-category'><strong>Category:</strong> " . htmlspecialchars($row['category']) . "</div>"; echo "<div class='deal-expires'><strong>Expires In:</strong> $expire_str</div>"; if ($row['mrp_price'] && $row['deal_price']) { echo "<div class='price-info'> <p><strong>MRP:</strong> <span class='strike'>₹" . number_format($row['mrp_price'], 2) . "</span></p> <p><strong>Deal Price:</strong> <span class='deal-price'>₹" . number_format($row['deal_price'], 2) . "</span></p>"; if ($row['discount_percent']) { echo "<p><strong>Discount:</strong> <span class='discount'>" . $row['discount_percent'] . "% OFF</span></p>"; } echo "</div>"; } echo "<button class='like-btn' data-id='{$row['id']}'>👍 Like (<span id='like-count-{$row['id']}'>{$row['likes']}</span>)</button>"; echo "<a class='grab-deal-btn' href='$affiliate_url' target='_blank' rel='noopener noreferrer'>Grab Deal</a>"; echo "</div>"; } echo '</div>'; } else { echo "<p>No results found for '<strong>" . htmlspecialchars($_GET['q']) . "</strong>'.</p>"; } // Pagination if ($totalPages > 1) { echo '<div class="pagination">'; for ($i = 1; $i <= $totalPages; $i++) { echo "<a href='search.php?q=$q&page=$i'" . ($i == $page ? " class='current-page'" : "") . ">$i</a>"; } echo '</div>'; } } else { echo "<p>Please enter a search query.</p>"; } ?> </div> <?php include('footer.php'); ?>