Siteβ―Builder
Editing:
index.php
writable 0666
<?php /************************************************************************** * UNIVERSAL PROMPTS EDITOR (business + social) * ---------------------------------------------------------------------- * © 2025Β BestDealOnΒ βΒ free to modify. * Requires PHPΒ 8.1+ *************************************************************************/ /* ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ *1οΈβ£ Resolve which profile we are editing * β’ Business β 10β to 15βdigit phone * β’ Social β @slug (letters, numbers, _ and -) * βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */ $ph = $_GET['ph'] ?? ''; // query ?ph=########## $slug = $_GET['user'] ?? ''; // query ?user=rfsafe $path = $_SERVER['REQUEST_URI']; /* try to grab from /ph/##########/β¦ */ if (!$ph && preg_match('#/ph/(\d{10,15})(?:/|$)#', $path, $m)) $ph = $m[1]; /* try to grab from /social/<slug>/β¦ or /@slug/β¦ */ if (!$slug && preg_match('#/(?:social|@)([A-Za-z0-9_-]+)(?:/|$)#', $path, $m)) $slug = $m[1]; /* if script lives *inside* the folder itself */ if (!$ph && !$slug) { $parent = basename(dirname(__FILE__)); if (preg_match('/^\d{10,15}$/', $parent)) $ph = $parent; elseif (preg_match('/^[A-Za-z0-9_-]+$/', $parent)) $slug = $parent; } $root = $_SERVER['DOCUMENT_ROOT']; if ($ph) { $dir = "$root/ph/$ph"; $file = "$dir/prompts.json"; $label = $ph; } elseif ($slug){ $dir = "$root/social/$slug"; $file = "$dir/prompts.json"; $label = "@$slug"; } else { // nothing resolved β ask user lookup(); // exits } /* directory must exist (otherwise 404) */ if (!is_dir($dir)) { http_response_code(404); exit('Profile not found'); } /* βββββββββββββββββββββββββββββ helper: landing form βββββββββ */ function lookup($err=''){ ?><!DOCTYPE html><html><head><meta charset="utf-8"><title>Edit Prompts</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <style> body{font-family:system-ui,Arial,sans-serif;background:#f5f8fb;margin:0;color:#234} .wrap{max-width:480px;margin:3em auto;background:#fff;padding:2em;border-radius:18px; box-shadow:0 2px 18px #dde3fa55;text-align:center} h1{font-size:1.5em;margin-bottom:.9em} input{width:100%;padding:.7em;border:1.4px solid #b7c2df;border-radius:7px;font-size:1.05em} button{margin-top:1em;padding:.7em 1.6em;font-size:1.05em;background:#2357d7;color:#fff; font-weight:700;border:none;border-radius:8px;cursor:pointer} .err{color:#c00;margin-bottom:.8em} </style></head><body> <div class="wrap"> <h1>LookΒ upΒ Profile</h1> <?php if($err) echo "<div class='err'>$err</div>"; ?> <form method="get"> <input type="text" name="ph" placeholder="10βdigit phone" style="margin-bottom:.65em"> <input type="text" name="user" placeholder="@username"> <button type="submit">LoadΒ Prompts</button> </form> </div></body></html><?php exit; } /* βββββββββββββββββββββββββββββ load existing prompts βββββββββ */ $prompts = is_file($file) ? json_decode(file_get_contents($file), true, 512, JSON_THROW_ON_ERROR) : []; if (!is_array($prompts)) $prompts = []; /* normalise to array of objects with a βpromptβ key */ $prompts = array_values(array_map(fn($p)=> is_string($p)? ['prompt'=>$p] : $p, $prompts)); /* βββββββββββββββββββββββββββββ AJAX save endpoint ββββββββββββ */ if ($_SERVER['REQUEST_METHOD']==='POST'){ $raw = file_get_contents('php://input'); $arr = json_decode($raw, true); if (!is_array($arr)){ http_response_code(400); exit('Bad JSON'); } /* strip empty prompts */ $arr = array_values(array_filter($arr, fn($o)=>isset($o['prompt']) && trim($o['prompt'])!=='')); /* ensure dir exists */ if (!is_dir($dir)) { mkdir($dir, 0775, true); } /* write prettyβprinted JSON */ file_put_contents($file, json_encode($arr, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOCK_EX); echo '{"success":true}'; exit; } /* βββββββββββββββββββββββββββββ HTML page βββββββββββββββββββββ */ ?><!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"><title>Edit Prompts β <?= htmlspecialchars($label) ?></title> <meta name="viewport" content="width=device-width,initial-scale=1"> <style> :root{--bg:#f6f8fb;--fg:#234;--accent:#2357d7;--accent-dk:#1347c0;--warn:#c6262e} body{margin:0;font-family:system-ui,Arial,sans-serif;background:var(--bg);color:var(--fg)} .top{background:#eee;padding:.8em 1.2em;font-weight:900} h1{font-size:1.45rem;margin:0} .container{max-width:800px;margin:2rem auto;padding:0 1rem} button{cursor:pointer;border:none;font-weight:700;border-radius:8px} #list{list-style:none;padding:0;margin:0} .item{background:#fffbe6;border:2px solid #ffd973;padding:1rem;border-radius:12px; box-shadow:0 2px 12px #f5db9c40;margin-bottom:1rem;display:flex;flex-direction:column;gap:.6rem} .item.dragging{opacity:.55} .item textarea{width:100%;padding:.6em;border:1px solid #b7c2df;border-radius:6px;font-size:1rem} .row-btns{display:flex;gap:.6rem;margin-top:.2rem} .move{background:#aac8ff;color:#103e9d;padding:.4rem .7rem} .del{background:#ffd5d5;color:var(--warn);padding:.4rem .7rem} .add{background:var(--accent);color:#fff;padding:.55rem 1.2rem;font-size:1rem} .save{background:#ef8f13;color:#fff;padding:.6rem 1.6rem;font-size:1.05rem} #msg{margin-top:1rem;font-weight:600} </style> </head><body> <div class="top"><a href="/" style="text-decoration:none;color:#2a3ca5">BestDealOn</a> » EditΒ Prompts</div> <div class="container"> <h1>Prompts forΒ <?= htmlspecialchars($label) ?></h1> <ul id="list"></ul> <button id="addBtn" class="add">+Β AddΒ Prompt</button> <div style="margin-top:2rem;text-align:right"> <button id="saveBtn" class="save">SaveΒ Prompts</button> </div> <div id="msg"></div> </div> <script> /* ---------- initial data from PHP --------- */ const prompts = <?= json_encode($prompts, JSON_UNESCAPED_SLASHES) ?>; const list = document.getElementById('list'); /* ---------- helpers ----------------------- */ function escapeHtml(s){ return s.replace(/[&<>"']/g,m=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[m])); } function makeItem(obj={prompt:''}){ const li=document.createElement('li'); li.className='item'; li.draggable=true; li.innerHTML=`<textarea rows="3" class="prompt" placeholder="Prompt textβ¦">${escapeHtml(obj.prompt||'')}</textarea> <div class="row-btns"> <button class="move up">β</button> <button class="move down">β</button> <button class="del">β</button> </div>`; return li; } /* ---------- render existing list ---------- */ prompts.forEach(o=>list.appendChild(makeItem(o))); if (!prompts.length) list.appendChild(makeItem()); /* ---------- drag & drop ------------------- */ let dragEl=null; list.addEventListener('dragstart',e=>{dragEl=e.target;dragEl.classList.add('dragging');}); list.addEventListener('dragend', e=>{dragEl.classList.remove('dragging');dragEl=null;}); list.addEventListener('dragover', e=>{ e.preventDefault(); const after=[...list.querySelectorAll('.item:not(.dragging)')] .find(li=>e.clientY < li.getBoundingClientRect().top + li.offsetHeight/2); list.insertBefore(dragEl, after||null); }); /* ---------- buttons ----------------------- */ document.getElementById('addBtn').onclick=()=>list.appendChild(makeItem()); list.addEventListener('click',e=>{ const li=e.target.closest('.item'); if(!li) return; if (e.target.classList.contains('del')) li.remove(); if (e.target.classList.contains('up')) li.previousElementSibling&&list.insertBefore(li,li.previousElementSibling); if (e.target.classList.contains('down')) li.nextElementSibling&&list.insertBefore(li.nextElementSibling,li); }); /* ---------- save -------------------------- */ document.getElementById('saveBtn').onclick=async()=>{ const arr=[...list.children].map(li=>({prompt:li.querySelector('.prompt').value.trim()})) .filter(o=>o.prompt); const r = await fetch(location.href,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(arr)}); const msg=document.getElementById('msg'); msg.textContent=r.ok?'Saved!':'Error saving'; msg.style.color=r.ok?'green':'red'; setTimeout(()=>msg.textContent='',2500); }; </script> <script src="/js/promptinator-auto.js" defer></script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel