Siteβ―Builder
Editing:
more1.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 β $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."; } } // β HANDLE KEY DELETE β if (isset($_GET['delete_key'])) { setcookie(COOKIE_NAME,'', time()-3600, '/', '', isset($_SERVER['HTTPS']), true); header("Location: {$_SERVER['PHP_SELF']}"); exit; } // β COLLECT PARAMETERS β $type = $_GET['type'] ?? 'B'; // B, C, Dtxt, Dnum $scope = $_GET['scope'] ?? 'general'; // relation $word = trim($_GET['word'] ?? ''); // seed word $cookie= $_COOKIE[COOKIE_NAME] ?? ''; $key = $cookie ? decrypt_val($cookie) : ''; $items = []; // sanitize the seed into an option-name (letters, numbers, underscores) $nm = preg_replace('/[^a-z0-9_]+/','_', strtolower($word)); // β FETCH SYNONYMS via Chat Completions β if ($key && $word) { $payload = [ 'model' => 'gpt-3.5-turbo', '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 only the {$scope} 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, ]); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); $text = $data['choices'][0]['message']['content'] ?? ''; $raw = array_filter(array_map('trim', explode(',', $text))); array_unshift($raw, $word); // seed first $items = array_values(array_unique($raw)); // unique } ?> <!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:80px; vertical-align:top; } select, input, button { margin-bottom:8px; padding:4px; } .token { display:inline-block; background:#eee; padding:4px 8px; margin:3px; border-radius:4px; } pre { background:#f6f6f6; padding:8px; } </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 is saved. <a href="?delete_key=1">Delete key</a></p> <p><em>Using model: <strong>gpt-3.5-turbo</strong></em></p> <?php endif; ?> <?php if($key): ?> <h2>2) Generate Synonyms</h2> <form method="get"> <label for="type">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> <label for="scope">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><br> <label for="word">Seed</label> <input id="word" name="word" value="<?=htmlspecialchars($word)?>"> <button>Go</button> </form> <?php if(count($items)): ?> <h3>3) Select Token</h3> <select id="token_select" style="width:100%;padding:8px;"> <?php foreach($items as $i => $it): ?> <option value="<?=htmlspecialchars($it)?>" <?= $i===0?'selected':''?>> <?=htmlspecialchars($it)?> </option> <?php endforeach; ?> </select> <button id="change_default">Change Default</button> <h3>4) Shortcode Preview</h3> <pre id="shortcode"> <?php // Build serverβside initial preview $prefix = str_starts_with($type,'D') ? 'D' : $type; if ($prefix==='D') { if ($type==='Dnum') { // numeric dropdown $max = intval($_GET['max'] ?? 5); $def = htmlspecialchars($items[0]); echo "[D-{$nm}-{$max}~{$def}~]"; } else { // text dropdown $def = htmlspecialchars($items[0]); echo "[D-{$nm}-|".implode('|',array_map('htmlspecialchars',$items))."|~{$def}~]"; } } else { // B or C $def = htmlspecialchars($items[0]); echo "[{$prefix}-{$nm}-|".implode('|',array_map('htmlspecialchars',$items))."|~{$def}~]"; } ?> </pre> <script> document.addEventListener('DOMContentLoaded', ()=>{ const typeSel = document.getElementById('type'), scopeSel = document.getElementById('scope'), tokenSel = document.getElementById('token_select'), preview = document.getElementById('shortcode'), btn = document.getElementById('change_default'), nm = "<?= $nm ?>"; function updateShortcode(){ const t = typeSel.value, def = tokenSel.value, opts = Array.from(tokenSel.options).map(o=>o.value), ps = opts.join('|'), prefix = t.startsWith('D') ? 'D' : t; let sc = ''; if(prefix==='D'){ if(t==='Dnum'){ // keep max at 5 default sc = `[D-${nm}-5~${def}~]`; } else { sc = `[D-${nm}-|${ps}|~${def}~]`; } } else { sc = `[${prefix}-${nm}-|${ps}|~${def}~]`; } preview.textContent = sc; } typeSel.addEventListener('change', updateShortcode); tokenSel.addEventListener('change', updateShortcode); btn.addEventListener('click', ()=>{ const def = tokenSel.value; const rem = Array.from(tokenSel.options) .map(o=>o.value) .filter(v=>v!==def); rem.unshift(def); tokenSel.innerHTML = ''; rem.forEach((v,i)=>{ const o = document.createElement('option'); o.value = o.textContent = v; if(i===0) o.selected = true; tokenSel.appendChild(o); }); updateShortcode(); }); }); </script> <?php endif; ?> <?php endif; ?> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel