Siteβ―Builder
Editing:
moreverynice.php
writable 0666
<?php // more.php // ββ CONFIGURATION ββ define('COOKIE_NAME','openai_key'); define('COOKIE_TTL', 30 * 24 * 3600); // 30 days define('SECRET', __FILE__); // change for your own salt // β SIMPLE ENCRYPT/DECRYPT β function encrypt_val($v) { $method = 'aes-128-ctr'; $key = substr(hash('sha256', SECRET, true), 0, 16); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method)); $ct = openssl_encrypt($v, $method, $key, 0, $iv); return base64_encode("$ct::$iv"); } function decrypt_val($c) { @list($ct, $iv) = explode('::', base64_decode($c), 2); $method = 'aes-128-ctr'; $key = substr(hash('sha256', SECRET, true), 0, 16); return openssl_decrypt($ct, $method, $key, 0, $iv); } // β HANDLE KEY SAVE/DELETE β $msg = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_key'])) { $raw = trim($_POST['api_key']); $opts = ['http' => ['method' => 'GET', 'header' => "Authorization: Bearer $raw\r\n", 'timeout' => 10]]; if (@file_get_contents('https://api.openai.com/v1/models', false, stream_context_create($opts))) { setcookie(COOKIE_NAME, encrypt_val($raw), time() + COOKIE_TTL, '/', '', isset($_SERVER['HTTPS']), true); $msg = "β Key saved!"; } else { $msg = "β Invalid key."; } } if (isset($_GET['delete_key'])) { setcookie(COOKIE_NAME, '', time() - 3600, '/', '', isset($_SERVER['HTTPS']), true); header("Location: {$_SERVER['PHP_SELF']}"); exit; } // β PARAMETERS & AUTH β $type = $_GET['type'] ?? 'B'; $scope = $_GET['scope'] ?? 'general'; $word = trim($_GET['word'] ?? ''); $count = intval($_GET['count'] ?? 5); $def = intval($_GET['def'] ?? 1); $model = in_array($_GET['model'] ?? '', ['gpt-3.5-turbo','gpt-4o-mini','gpt-4']) ? $_GET['model'] : 'gpt-3.5-turbo'; $count = max(1, min(15, $count)); $def = max(1, min($count, $def)); $cookie = $_COOKIE[COOKIE_NAME] ?? ''; $key = $cookie ? decrypt_val($cookie) : ''; $items = []; // sanitize seed into option name $nm = preg_replace('/[^a-z0-9_]+/', '_', strtolower($word)); // β FETCH AI TOKENS (non-numeric) β if ($key && $word && $type !== 'Dnum') { $payload = [ 'model' => $model, 'messages' => [ ['role' => 'system', 'content' => "You are a helpful assistant that replies ONLY with a comma-separated list of {$scope}, no extra text."], ['role' => 'user', 'content' => "List up to {$count} {$scope} variations for '{$word}'"] ], 'max_tokens' => 60, 'temperature'=> 0.3, 'stop' => ["\n"] ]; $ch = curl_init('https://api.openai.com/v1/chat/completions'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer '.$key, 'Content-Type: application/json'], CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_TIMEOUT => 15, ]); $resp = curl_exec($ch); curl_close($ch); $data = json_decode($resp, true); $raw = array_filter(array_map('trim', explode(',', $data['choices'][0]['message']['content'] ?? ''))); array_unshift($raw, $word); $items = array_slice(array_unique($raw), 0, $count); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Promptinator Simple</title> <style> body { font-family:sans-serif; max-width:600px; margin:2rem auto; } label { display:inline-block; width:120px; vertical-align:top; } input, select, button { margin:4px 0; padding:6px; } #relation-row, #count-row, #tokens-section { margin:10px 0; } .token { display:inline-block; background:#eee; padding:4px 8px; margin:3px; border-radius:4px; } .token span { margin-left:6px; color:red; cursor:pointer; } pre { background:#f6f6f6; padding:8px; white-space:pre-wrap; } #modal { display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); align-items:center; justify-content:center; } #modal .inner { background:#fff; padding:20px; border-radius:6px; } </style> </head> <body> <h2>1) OpenAI API Key</h2> <?php if($msg): ?><p><strong><?=htmlspecialchars($msg)?></strong></p><?php endif; ?> <?php if(!$key): ?> <form method="post"> <input type="password" name="api_key" placeholder="sk-..." required> <button name="save_key">Save & validate</button> </form> <?php else: ?> <p>Key saved. <a href="?delete_key=1">Delete key</a></p> <p><em>Using model: <strong><?=htmlspecialchars($model)?></strong></em></p> <?php endif; ?> <?php if($key): ?> <h2>2) Configure</h2> <form id="cfg" method="get"> <label>Model</label> <select name="model" onchange="this.form.submit()"> <option value="gpt-3.5-turbo"<?= $model==='gpt-3.5-turbo'?' selected':''?>>Good (GPT-3.5-turbo)</option> <option value="gpt-4o-mini"<?= $model==='gpt-4o-mini'?' selected':''?>>Better (GPT-4.1-mini)</option> <option value="gpt-4"<?= $model==='gpt-4'?' selected':''?>>Best (GPT-4)</option> </select><br> <label>Type</label> <select id="type" name="type"> <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> <option value="Dnum"<?= $type==='Dnum'?' selected':'' ?>>Dropdown Numeric</option> </select><br> <div id="relation-row"> <label>Relation</label> <select id="scope" name="scope"> <option value="general"<?= $scope==='general'?' selected':'' ?>>General</option> <option value="broad"<?= $scope==='broad'?' selected':'' ?>>Broad</option> <option value="narrow"<?= $scope==='narrow'?' selected':'' ?>>Narrow</option> <option value="longtail"<?= $scope==='longtail'?' selected':'' ?>>Long-tail</option> <option value="shorttail"<?= $scope==='shorttail'?' selected':'' ?>>Short-tail</option> </select> </div> <div id="count-row"> <label>Count</label> <select id="count" name="count"> <?php for($i=1; $i<=15; $i++): ?> <option value="<?=$i?>"<?=$i===$count?' selected':''?>><?=$i?></option> <?php endfor; ?> </select> </div> <div id="num-box" style="display:none;"> <label>Max</label><input id="max" type="number" min="1" max="15" value="<?= $count ?>"><br> <label>Default</label><input id="def" type="number" min="1" max="<?= $count ?>" value="<?= $def ?>"><br> <label>Option Name</label><input id="opt" type="text" placeholder="optional"><br> </div> <div id="seed-box"> <label>Seed</label><input id="seed" name="word" value="<?=htmlspecialchars($word)?>"><br> <button id="gen">Generate</button> </div> </form> <div id="tokens-section"> <h3>3) Tokens</h3> <div id="tokens"></div> <button id="change">Change Default</button> </div> <h3>4) Preview</h3> <pre id="shortcode"></pre> <!-- Default picker modal --> <div id="modal"><div class="inner"> <h3>Select new default</h3> <select id="picker"></select><br> <button id="save">Save</button> <button id="cancel">Cancel</button> </div></div> <script> (() => { const typeEl = document.getElementById('type'), relation = document.getElementById('relation-row'), countRow = document.getElementById('count-row'), seedBox = document.getElementById('seed-box'), numBox = document.getElementById('num-box'), tokensSec= document.getElementById('tokens-section'), countEl = document.getElementById('count'), maxEl = document.getElementById('max'), defEl = document.getElementById('def'), optEl = document.getElementById('opt'), tokensEl = document.getElementById('tokens'), scEl = document.getElementById('shortcode'), changeBtn= document.getElementById('change'), genBtn = document.getElementById('gen'), nm = "<?= $nm ?>", modal = document.getElementById('modal'), picker = document.getElementById('picker'), saveBtn = document.getElementById('save'), cancelBtn= document.getElementById('cancel'); let items = <?= json_encode($items) ?>; function renderTokens() { tokensEl.innerHTML = ''; items.forEach((t,i) => { const sp = document.createElement('span'); sp.className = 'token'; sp.textContent = t; const x = document.createElement('span'); x.textContent = 'Γ'; x.onclick = () => { items.splice(i,1); renderTokens(); update(); }; sp.appendChild(x); tokensEl.appendChild(sp); }); } function update() { const t = typeEl.value, ps = items.join('|'), df = items[0]||'', cnt= parseInt(countEl.value,10), mx = parseInt(maxEl.value,10), dm = parseInt(defEl.value,10), opt= optEl.value||nm; let prefix = t; if (t==='Dtxt' || t==='Dnum') prefix = 'D'; let sc = ''; if (prefix==='D' && t==='Dnum') { items = []; for(let i=1;i<=mx;i++) items.push(i.toString()); renderTokens(); sc = `[D-${opt}-${mx}~${dm}~]`; } else if (prefix==='D') { sc = `[D-${opt}-|${ps}|~${df}~]`; } else if (items.length) { sc = `[${prefix}-${opt}-|${ps}|~${df}~]`; } scEl.textContent = sc; } typeEl.onchange = () => { const isNum = typeEl.value==='Dnum'; relation.style.display = isNum ? 'none':'block'; countRow.style.display = isNum ? 'none':'block'; seedBox.style.display = isNum ? 'none':'block'; numBox.style.display = isNum ? 'block':'none'; tokensSec.style.display = isNum ? 'none':'block'; update(); }; countEl.onchange = () => document.getElementById('cfg').submit(); [maxEl, defEl, optEl].forEach(el=>el.oninput=update); genBtn.onclick = e=>{e.preventDefault(); if(typeEl.value!=='Dnum') document.getElementById('cfg').submit();}; changeBtn.onclick = ()=>{ picker.innerHTML=''; items.forEach(t=>{const o=document.createElement('option');o.value=o.textContent=t;picker.appendChild(o);}); modal.style.display='flex'; }; saveBtn.onclick=()=>{const v=picker.value,i=items.indexOf(v); if(i>-1){items.splice(i,1);items.unshift(v);} renderTokens();update();modal.style.display='none';}; cancelBtn.onclick=()=>modal.style.display='none'; renderTokens(); update(); typeEl.onchange(); })(); </script> <?php endif; ?> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel