« Back to History
bulk_post_create.php
|
20260921_175631.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/config.php'; if (!function_exists('db_connect')) { die('db_connect() not found'); } $pdo = db_connect(); $msg = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = trim($_POST['title'] ?? ''); $slug = trim($_POST['slug'] ?? ''); $status = 'published'; $box_style = trim($_POST['box_style'] ?? ''); $meta_title = trim($_POST['meta_title'] ?? ''); $meta_description = trim($_POST['meta_description'] ?? ''); $meta_keywords = trim($_POST['meta_keywords'] ?? ''); $shayari_boxes = $_POST['shayari'] ?? []; if ($title === '' || $slug === '' || empty($shayari_boxes)) { $msg = 'Title, slug aur kam se kam 1 shayari required hai'; } else { $body = []; foreach ($shayari_boxes as $s) { $t = trim($s); if ($t !== '') { $body[] = '<p>' . htmlspecialchars($t, ENT_QUOTES, 'UTF-8') . '</p>'; } } if (!$body) { $msg = 'Sab shayari box empty hain'; } else { $st = $pdo->prepare(" INSERT INTO posts (title, slug, status, body_html, box_style, meta_title, meta_description, meta_keywords) VALUES (?, ?, ?, ?, ?, ?, ?, ?) "); try { $st->execute([ $title, $slug, $status, implode("\n", $body), $box_style !== '' ? $box_style : null, $meta_title !== '' ? $meta_title : null, $meta_description !== '' ? $meta_description : null, $meta_keywords !== '' ? $meta_keywords : null ]); $msg = '✅ Post created successfully'; } catch (PDOException $e) { $msg = '❌ DB Error: ' . $e->getMessage(); } } } } ?> <!doctype html> <html lang="hi"> <head> <meta charset="utf-8"> <title>Bulk Post Creator</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="/shayari/assets/admin.css"> <style> .wrap{max-width:1100px;margin:30px auto} .box{background:#fff;border:1px solid #ddd;border-radius:6px;padding:20px} input,textarea,select{width:100%;padding:8px;border:1px solid #ccc;margin-bottom:10px} textarea{min-height:90px} .actions{display:flex;gap:10px;margin-bottom:10px} button{padding:7px 14px;background:#2271b1;color:#fff;border:none;border-radius:4px;cursor:pointer} button:hover{background:#135e96} .notice{font-weight:600;margin-bottom:10px} .small{width:160px} </style> </head> <body> <div class="wrap"> <div class="box"> <h2>Bulk Post Creator</h2> <?php if ($msg): ?> <p class="notice"><?= htmlspecialchars($msg) ?></p> <?php endif; ?> <form method="post"> <label>Post Title</label> <input name="title" required> <label>Post Slug (unique)</label> <input name="slug" required> <label>Box Style (optional)</label> <select name="box_style"> <option value="">Default / Auto</option> <option value="orange">Orange</option> <option value="heart">Heart</option> <option value="yellow-cloud">Yellow Cloud</option> <option value="pink-soft">Pink Soft</option> <option value="dark-card">Dark Card</option> <option value="outline">Outline</option> <option value="blue-ribbon">Blue Ribbon</option> <option value="sticker">Sticker</option> <option value="gradient">Gradient</option> <option value="dashed">Dashed</option> </select> <label>Meta Title</label> <input name="meta_title"> <label>Meta Description</label> <textarea name="meta_description" rows="2"></textarea> <label>Meta Keywords</label> <textarea name="meta_keywords" rows="2"></textarea> <hr> <div class="actions"> <input type="number" id="boxCount" class="small" placeholder="Number of shayari boxes"> <button type="button" onclick="addBoxes()">Add Boxes</button> </div> <select id="insertMode" class="small"> <option value="bottom">Add Bottom</option> <option value="top">Add Top</option> </select> <div id="shayariArea"> <textarea name="shayari[]" placeholder="Shayari 1" required></textarea> </div> <br> <button type="submit">Save Post</button> </form> </div> </div> <script> const area = document.getElementById('shayariArea'); /* =============================== CONFIG ================================ */ function getInsertMode(){ return document.getElementById('insertMode')?.value || 'bottom'; } /* =============================== CREATE BOX ================================ */ function createBox(value = ''){ const box = document.createElement('div'); box.className = 'shayari-box'; box.draggable = true; box.innerHTML = ` <div style="display:flex;justify-content:space-between;align-items:center"> <span style="cursor:move">↕</span> <button type="button" class="delBtn">✖</button> </div> <textarea name="shayari[]"></textarea> `; const ta = box.querySelector('textarea'); ta.value = value; /* delete */ box.querySelector('.delBtn').onclick = () => { if (area.querySelectorAll('textarea').length <= 1) return; box.remove(); }; return box; } /* =============================== MANUAL ADD BOXES ================================ */ function addBoxes(){ const c = parseInt(document.getElementById('boxCount').value); if (!c || c < 1) return; for (let i = 0; i < c; i++) { const box = createBox(); if (getInsertMode() === 'top') { area.prepend(box); } else { area.appendChild(box); } } } /* =============================== ENTER → PARAGRAPH BREAK ================================ */ area.addEventListener('keydown', function(e){ if (e.target.tagName !== 'TEXTAREA') return; if (e.key === 'Enter') { const ta = e.target; const pos = ta.selectionStart; const val = ta.value; // detect empty line (double enter) if (pos >= 1 && val[pos - 1] === '\n') { e.preventDefault(); // remove extra newline ta.value = val.slice(0, pos - 1) + val.slice(pos); const box = createBox(); if (getInsertMode() === 'top') { area.prepend(box); } else { ta.closest('.shayari-box').after(box); } box.querySelector('textarea').focus(); } } }); /* =============================== PASTE → PARAGRAPH SPLIT (FIXED) ================================ */ area.addEventListener('paste', function(e){ const firstTA = area.querySelector('textarea'); if (e.target !== firstTA) return; // let browser paste first setTimeout(() => { const raw = firstTA.value; // split ONLY on empty line const parts = raw .split(/\n\s*\n+/) .map(p => p.trim()) .filter(Boolean); if (parts.length <= 1) return; // first paragraph stays firstTA.value = parts[0]; // rest → new boxes for (let i = 1; i < parts.length; i++) { const box = createBox(parts[i]); if (getInsertMode() === 'top') { area.prepend(box); } else { area.appendChild(box); } } }, 0); }); /* =============================== DRAG & DROP REORDER ================================ */ let dragBox = null; area.addEventListener('dragstart', e => { dragBox = e.target.closest('.shayari-box'); }); area.addEventListener('dragover', e => { e.preventDefault(); const target = e.target.closest('.shayari-box'); if (!dragBox || !target || dragBox === target) return; const rect = target.getBoundingClientRect(); const after = (e.clientY - rect.top) > rect.height / 2; area.insertBefore(dragBox, after ? target.nextSibling : target); }); </script> </body> </html>