Site Builder
Editing:
tools-promptinator1111.php
writable 0666
<?php /********************************************************************** * Promptinator — Business AI Tool (toolbar edition, Aug 2025) **********************************************************************/ require_once $_SERVER['DOCUMENT_ROOT'] . '/openai/init.php'; ai_handle_key_post(); // save / delete key /* -------- query params / defaults (same as before, minus model) --- */ $controlOpts = ['B','C','Dtxt']; $type = in_array($_GET['type'] ??'', $controlOpts) ? $_GET['type'] : 'B'; $scope = $_GET['scope'] ?? 'general'; $word = trim($_GET['word'] ?? ''); $count = max(1, min(15, intval($_GET['count'] ?? 5))); /* -------- generate candidate list via ai_chat() ------------------- */ $items = []; if (ai_has_key() && $word && in_array($type, ['B','C','Dtxt'])) { /* build the prompt exactly like before, but as one user string */ $prompt = "You are a helpful assistant that replies ONLY with a " . "comma‑separated list of {$scope} variations, no extra words.\n" . "List up to {$count} {$scope} variations for '{$word}'."; $raw = array_filter(array_map('trim', explode(',', ai_chat($prompt)) )); array_unshift($raw, $word); // ensure seed word is first $items = array_slice(array_unique($raw), 0, $count); } ?> <!doctype html> <html lang="en"><head> <meta charset="utf-8"> <title>Promptinator – AI Toolbox</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <style> :root{ --bg:#f1f4fb; --brand:#004cff; --brand-d:#0841c4; --card:#fff; --shadow:0 6px 30px rgba(0,0,0,.08); --dark:#121720;--green:#5af287; --red:#e24d4b; --radius:26px; font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif; } body{margin:0;background:var(--bg);color:#111;min-height:100vh;display:flex;flex-direction:column} .breadcrumb{background:#eee;padding:.6rem 1rem;font-weight:600} .breadcrumb a{color:var(--brand);text-decoration:none} main{width:100%;max-width:900px;margin:2.2rem auto;padding:0 1rem;flex:1} .tool-card{background:var(--card);border-radius:var(--radius);box-shadow:var(--shadow); padding:2rem;display:grid;gap:1.6rem} /* ---------- form -------------------------------------------------- */ #cfg{display:grid;gap:1.4rem;grid-template-columns:1fr 1fr} #cfg .full{grid-column:1/-1} label{font-weight:600;font-size:.95rem} select,input[type=text]{width:100%;padding:.8rem 1rem;border:1px solid #d0d6e7; border-radius:10px;font-size:1rem} select:focus,input:focus{outline:none;border-color:var(--brand)} #gen{justify-self:start;padding:.75rem 2rem;background:var(--brand);color:#fff;border:none; border-radius:10px;font-size:1rem;cursor:pointer} .seed-wrap{position:relative} .seed-wrap input{padding-right:3rem;font-size:1.05rem;height:58px;} /* bigger field */ .micBtn{ position:absolute;right:.8rem;top:50%;transform:translateY(-50%); background:none;border:none;font-size:1.4rem;cursor:pointer; } /* ---------- token & shortcode blocks ------------------------------ */ #tokens{display:flex;flex-wrap:wrap;gap:.5rem} .token{position:relative;background:#e8efff;color:#003c9e;padding:.5rem 1.4rem .5rem .9rem; border-radius:20px;font-weight:600;font-size:.95rem} .token .remove{position:absolute;right:4px;top:-2px;cursor:pointer;color:var(--red)} #shortcode{background:#0d111a;color:#fff;border-radius:10px;padding:1.3rem; font-family:ui-monospace,monospace;font-size:.95rem;white-space:pre-wrap} .action-row{display:flex;gap:1rem} .action-row button{padding:.7rem 1.4rem;background:var(--brand);color:#fff;border:none; border-radius:9px;cursor:pointer;flex:1} .action-row button:hover{background:var(--brand-d)} .action-row .csv{display:none} /* ---------- responsive ------------------------------------------- */ @media(max-width:640px){ #cfg{grid-template-columns:1fr} #gen{justify-self:stretch;text-align:center} } </style> </head> <body> <!-- breadcrumb --> <nav class="breadcrumb"> <a href="/members/dashboard.php">Dashboard</a> » <a href="/ai-tools/tools.php">AI Toolbox</a> » Promptinator <a href="/<?= htmlspecialchars($_SESSION['slug'] ?? '') ?>/" style="float:right">View Site</a> </nav> <?php ai_render_key_bar(); ?><!-- universal key / model bar --> <main> <?php if (!ai_has_key()): ?> <div class="tool-card" style="text-align:center"> <h2>Get started</h2> <p>Save your OpenAI API key in the black bar above to unlock Promptinator.</p> </div> <?php else: ?> <div class="tool-card"> <!-- generation form --> <h2>Generate options</h2> <form id="cfg" method="get" autocomplete="off"> <input type="hidden" id="typeHidden" name="type" value="<?= htmlspecialchars($type) ?>"> <div class="seed-wrap full"> <label for="seed">Seed word</label> <input id="seed" name="word" value="<?= htmlspecialchars($word) ?>" placeholder="e.g. shoes"> <button type="button" id="mic" class="micBtn">🎤</button> </div> <div> <label for="scope">Relation</label> <select id="scope" name="scope"> <?php foreach (['general','broad','narrow','longtail','shorttail'] as $rel) { $sel = $rel === $scope ? 'selected' : ''; echo "<option $sel>$rel</option>"; } ?> </select> </div> <div> <label for="count">Count</label> <select id="count" name="count"> <?php for ($i=1;$i<=15;$i++) echo "<option ".($i==$count?'selected':'').">$i</option>"; ?> </select> </div> <div> <label for="ctype">Control type</label> <select id="ctype"> <option value="B" <?= $type==='B' ?'selected':'' ?>>Radio</option> <option value="C" <?= $type==='C' ?'selected':'' ?>>Checkbox</option> <option value="Dtxt" <?= $type==='Dtxt' ?'selected':'' ?>>Dropdown Text</option> </select> </div> <button id="gen" class="full">Generate</button> </form> <!-- tokens / shortcode --> <div id="tokens-area" style="<?= $items ? '' : 'display:none' ?>"> <h3>Tokens</h3> <div id="tokens"></div> <label for="def">Default value</label> <select id="def"></select> <pre id="shortcode"></pre> <div class="action-row"> <button class="copy" onclick="copyTxt('shortcode')">Copy Shortcode</button> <button class="copy csv" id="csvBtn" onclick="copyCsv()">Copy CSV</button> </div> </div> </div> <?php endif; ?> </main> <script> (()=>{ /* ---------- helpers ---------- */ const $=q=>document.querySelector(q); const items = <?= json_encode($items, JSON_UNESCAPED_SLASHES) ?>; const tokensBox=$('#tokens'), defSel =$('#def'), scEl =$('#shortcode'), csvBtn =$('#csvBtn'); /* ---------- rendering ---------- */ function renderTokens(){ tokensBox.innerHTML=''; items.forEach((t,i)=>{ const s=document.createElement('span'); s.className='token'; s.textContent=t; const x=document.createElement('span'); x.className='remove'; x.textContent='×'; x.onclick=()=>{ items.splice(i,1); updateAll(); }; s.appendChild(x); tokensBox.appendChild(s); }); } function renderDefault(){ defSel.innerHTML=''; items.forEach(t=>{ const o=document.createElement('option'); o.value=t; o.textContent=t; defSel.appendChild(o); }); defSel.value = items[0] || ''; } function updateShortcode(){ const t = $('#typeHidden').value; const ps = items.join('|'); const df = items[0] || ''; const opt = ($('#seed').value.trim() || 'seed').replace(/\s+/g,'-'); const prefix = (t==='Dtxt') ? 'D' : t; scEl.textContent = `[${prefix}-${opt}-|${ps}|~${df}~]`; } function updateAll(){ renderTokens(); renderDefault(); updateShortcode(); $('#tokens-area').style.display = items.length ? 'block' : 'none'; csvBtn.style.display = items.length ? 'block' : 'none'; } updateAll(); /* ---------- control‑type switch (no reload) ---------- */ $('#ctype').onchange = e=>{ $('#typeHidden').value = e.target.value; updateShortcode(); }; /* ---------- default picker re‑order ---------- */ defSel.onchange = ()=>{ const v = defSel.value; const idx = items.indexOf(v); if (idx>0){ items.splice(idx,1); items.unshift(v); } updateAll(); }; /* ---------- copy helpers ---------- */ window.copyTxt = id=>{ navigator.clipboard.writeText($('#'+id).textContent).then(()=>{ const btn = event.target, old = btn.textContent; btn.textContent = '✔ Copied'; setTimeout(()=>btn.textContent=old,1200); }); }; window.copyCsv = ()=>{ navigator.clipboard.writeText(items.join(', ')).then(()=>{ const old = csvBtn.textContent; csvBtn.textContent='✔ Copied'; setTimeout(()=>csvBtn.textContent=old,1200); }); }; /* ---------- microphone (inside input) ---------- */ const mic = $('#mic'); if (mic) { const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; if (!SpeechRecognition) mic.style.display='none'; else { const rec = new SpeechRecognition(); rec.lang = 'en-US'; rec.interimResults = false; mic.onclick = ()=>{ mic.textContent='🎤…'; try{ rec.start(); }catch{} }; rec.onresult = e=>{ $('#seed').value = e.results[0][0].transcript; mic.textContent='🎤'; updateShortcode(); }; } } })(); </script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel