« Back to History
post_view.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php // post_view.php — FINAL STABLE VERSION // Shayari display SAME as before, only image interval logic added correctly /* ================= DB ================= */ if (!isset($pdo) || !($pdo instanceof PDO)) { $pdo = new PDO( "mysql:host=localhost;dbname=u410576661_shayari;charset=utf8mb4", "u410576661_shayari", "Shayari@9898", [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ] ); } /* ================= HELPERS ================= */ require_once __DIR__ . '/lib/helpers.php'; /* ================= SHAYARI EXTRACT ================= */ function extract_shayari_blocks(string $html): array { $html = trim($html); if ($html === '') return []; // WordPress <p> blocks if (stripos($html, '<p') !== false) { $dom = new DOMDocument(); @$dom->loadHTML('<?xml encoding="utf-8" ?>' . $html); $out = []; foreach ($dom->getElementsByTagName('p') as $p) { $t = trim($p->textContent); if ($t !== '') $out[] = $t; } if ($out) return $out; } // fallback: line breaks $html = preg_replace('#<br\s*/?>#i', "\n", $html); $txt = trim(strip_tags($html)); $arr = preg_split("/\n\s*\n+/", $txt); return array_values(array_filter(array_map('trim', $arr))); } /* ================= LOAD POST ================= */ $post = null; if (isset($_GET['id']) && ctype_digit($_GET['id'])) { $st = $pdo->prepare("SELECT * FROM posts WHERE id=? LIMIT 1"); $st->execute([(int)$_GET['id']]); $post = $st->fetch(); } elseif (!empty($_GET['slug'])) { $st = $pdo->prepare("SELECT * FROM posts WHERE slug=? LIMIT 1"); $st->execute([trim($_GET['slug'])]); $post = $st->fetch(); } if (!$post) { http_response_code(404); exit('Post not found'); } /* ================= SHAYARI TEXTS ================= */ $texts = extract_shayari_blocks($post['body_html'] ?? ''); /* ================= IMAGE RULES (ONLY SOURCE) ================= */ $rule = fetch_post_image_rule($pdo, (int)$post['id']); $interval = (int)($rule['image_interval'] ?? 0); $mode = $rule['image_mode'] ?? 'sequential'; $reuse = (int)($rule['image_reuse'] ?? 0); $folder = $rule['folder_name'] ?? null; /* ================= LOAD IMAGES ================= */ $images = []; if ($folder) { $images = get_images_from_specific_folder( $folder, $_SERVER['DOCUMENT_ROOT'] . '/shayari/uploads', 'shayari/uploads' ); } /* ================= INTERLEAVE (FIXED LOGIC) ================= */ $items = []; $shayariCount = 0; $imgIndex = 0; foreach ($texts as $t) { // Always push shayari $items[] = [ 'type' => 'text', 'content' => $t ]; $shayariCount++; // Image only at interval if ( $interval > 0 && $images && ($shayariCount % $interval === 0) ) { $img = $images[$imgIndex] ?? null; if ($img) { $items[] = [ 'type' => 'image', 'content' => $img ]; } // image reuse handling $imgIndex++; if ($reuse && $imgIndex >= count($images)) { $imgIndex = 0; } } } /* ================= DESIGN (POST LEVEL) ================= */ $DESIGNS = [ 'shayari-box--orange', 'shayari-box--heart', 'shayari-box--yellow-cloud', 'shayari-box--pink-soft', 'shayari-box--dark-card', 'shayari-box--outline', 'shayari-box--blue-ribbon', 'shayari-box--sticker', 'shayari-box--gradient', 'shayari-box--dashed' ]; $postStyle = trim($post['box_style'] ?? ''); $designClass = $postStyle ? 'shayari-box--' . $postStyle : $DESIGNS[array_rand($DESIGNS)]; ?> <!doctype html> <html lang="hi"> <head> <meta charset="utf-8"> <title><?= htmlspecialchars($post['title']) ?></title> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="stylesheet" href="/shayari/assets/shayari_box.css"> <link rel="stylesheet" href="/shayari/assets/post_view.css"> </head> <body> <div class="pv-page-wrap"> <div class="pv-category-banner"> <span><?= htmlspecialchars($post['title']) ?></span> </div> <div class="pv-grid"> <?php foreach ($items as $it): ?> <?php if ($it['type'] === 'text'): ?> <!-- SHAYARI CARD --> <div class="pv-card"> <div class="shayari-box <?= htmlspecialchars($designClass) ?>"> <?= nl2br(htmlspecialchars($it['content'])) ?> </div> </div> <?php elseif ($it['type'] === 'image'): ?> <!-- IMAGE CARD (FIXED) --> <div class="pv-card"> <div class="shayari-box image-box"> <img src="<?= htmlspecialchars($it['content']) ?>" alt="" loading="lazy" > </div> </div> <?php endif; ?> <?php endforeach; ?> </div> </div> </body> </html>