Site Builder
Editing:
index.php
writable 0666
<?php /********************************************************************** * Business‑Tools – Dynamic Prompts (Promptinator shell) • Aug 2025 * ------------------------------------------------------------------ * Path: /ai‑tools/tools-dynamic-prompts.php *********************************************************************/ declare(strict_types=1); /* ── 0. OpenAI shared helpers (key bar) ─────────────────────────── */ require_once $_SERVER['DOCUMENT_ROOT'].'/openai/init.php'; ai_handle_key_post(); // handle save / delete key /* ── 1. Locate profile.json ───────────────────────────────────── */ $ph = $_GET['ph'] ?? ''; // e.g. ?ph=1234567890 $slug = $_GET['user'] ?? ''; // e.g. ?user=rfsafe $uri = $_SERVER['REQUEST_URI']; /* patterns inside the URL … */ if (!$ph && preg_match('#/ph/(\d{10,15})(?:/|$)#', $uri, $m)) $ph = $m[1]; if (!$slug && preg_match('#/(?:social|@)([A-Za-z0-9_-]+)(?:/|$)#', $uri, $m)) $slug = $m[1]; /* fallback: script *inside* the folder */ 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; } /* resolve folder & readable profile path */ $root = rtrim($_SERVER['DOCUMENT_ROOT'],'/'); $dir = ''; $webBase = ''; // used for the “edit in place” window label if ($ph) { $dir = "$root/ph/$ph"; $webBase = "/$ph/"; } if ($slug) { $dir = "$root/social/$slug"; $webBase = "/social/$slug/"; } $profilePath = ($dir && is_readable($dir.'/profile.json')) ? $dir.'/profile.json' : null; $profile = $profilePath ? json_decode(file_get_contents($profilePath), true) : []; /* ── 2. Load prompts.json (local to *this* folder) ─────────────── */ function get_prompts(): array { $file = __DIR__.'/prompts.json'; if (!is_readable($file)) return []; // no prompts yet → empty UI $data = json_decode(file_get_contents($file), true); return is_array($data) ? $data : []; } $prompts = get_prompts(); // always an array – maybe empty /* helper: first 4 words as label */ $label = static function(string $t): string { return preg_replace('/\s+/', ' ', implode(' ', array_slice(explode(' ', trim($t)), 0, 4))).'…'; }; if ($_SERVER['REQUEST_METHOD']==='POST' && ($_GET['ajax']??'')==='1') { header('Content-Type: application/json; charset=utf-8'); if (!ai_has_key()) { echo json_encode(['error'=>'No API key']); exit; } $prompt = trim($_POST['prompt'] ?? ''); $html = $prompt ? ai_chat($prompt) : ''; echo json_encode(['html'=>$html ?: '(empty response)']); exit; } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Dynamic Prompts • Promptinator</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <?php /* ---- Pico‑flavoured styles & Promptinator card shell ---- */ ?> <style> :root{ --bg:#f1f4fb; --card:#fff; --gold:#ffb63b; --shadow:0 6px 30px rgba(0,0,0,.08); font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif; } body{margin:0;min-height:100vh;background:var(--bg);display:flex;flex-direction:column;color:#111} .breadcrumb{background:#ececec;font-weight:600;padding:.7rem 1.2rem} .breadcrumb a{color:#004cff;text-decoration:none} .pi-shell{ width:90%;max-width:720px;margin:2.6rem auto;padding:1.8rem 1.6rem; background:var(--card);border:3.5px solid var(--gold);border-radius:27px;box-shadow:var(--shadow) } .pi-shell label{display:block;margin:0 0 .6rem;font-weight:700;color:#0d4ca2;font-size:.95rem} .pi-shell select{ width:100%;padding:.6rem .75rem;font-size:1rem;border:1px solid #ccd;border-radius:9px; background:#fcfdff;appearance:none;cursor:pointer } .pi-holder{margin-top:1.4rem} </style> <link rel="stylesheet" href="/promptinator.css"> <?php /* preload Promptinator module once per full page */ ?> <link rel="modulepreload" href="/dynamicPromptinator.js"> <script> /* expose profile data for {{profile.xyz}} tokens */ window.profileData = <?= json_encode($profile, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) ?>; </script> </head> <body> <nav class="breadcrumb"> <a href="/">Download</a> » <a href="/ai-tools/tools.php">AI Toolbox</a> » Dynamic Prompts <a href="<?= htmlspecialchars($webBase) ?>" style="float:right">View Site</a> </nav> <?php /* ---------- shared black OpenAI key‑bar ---------- */ ?> <?php ai_render_key_bar(); ?> <?php require_once $_SERVER['DOCUMENT_ROOT'].'/ai-tools/share.php'; ?> <main> <section class="pi-shell"> <label for="piSelect">Choose a prompt:</label> <select id="piSelect"> <?php foreach ($prompts as $i => $p): ?> <option value="<?= $i ?>"><?= htmlspecialchars($label($p['prompt'])) ?></option> <?php endforeach; ?> <?php if (!$prompts): ?><option selected disabled>(no prompts yet)</option><?php endif;?> </select> <div id="piHolder" class="pi-holder"></div> </section> </main> <script type="module"> (()=>{ /* PHP delivered $prompts as JS array of prompt strings */ const prompts = <?= json_encode(array_column($prompts,'prompt'), JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP) ?>; const sel = document.getElementById('piSelect'); const holder = document.getElementById('piHolder'); function render(i = 0){ holder.innerHTML = '<div class="Promptinator" edit="1" think="1" data-prompt>' + (prompts[i] || '') + '</div>'; const boot = P => P.init({ mount: holder.firstElementChild }); /* Promptinator may already be on the page from another tool */ if (window.Promptinator?.init) boot(window.Promptinator); else import('/dynamicPromptinator.js').then(m=>boot(m.default||m.Promptinator)); } render(+sel.value || 0); sel.addEventListener('change', () => render(+sel.value || 0)); })(); </script> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel