Site Builder
Editing:
tools-promptinator3.php
writable 0666
<?php /************************************************************************** * Promptinator – AI business tool (BestDealOn) ©2025 BestDealOn * Folder: /public_html/ai-tools/business-tools/promptinator * File : tools-promptinator.php **************************************************************************/ require_once $_SERVER['DOCUMENT_ROOT'].'/members/lib/auth.php'; require_login(); /* ---------- CONFIG ---------------------------------------------------- */ define('COOKIE_NAME','openai_key'); define('COOKIE_TTL', 30*24*3600); // 30 days define('SECRET', __FILE__); // per‑file key for AES function enc($v){ $k = substr(hash('sha256', SECRET, true),0,16); $iv = random_bytes(openssl_cipher_iv_length('aes-128-ctr')); return base64_encode(openssl_encrypt($v,'aes-128-ctr',$k,0,$iv)."::$iv"); } function dec($c){ $k = substr(hash('sha256', SECRET, true),0,16); [$ct,$iv] = explode('::',base64_decode($c),2)+[null,null]; return $ct && $iv ? openssl_decrypt($ct,'aes-128-ctr',$k,0,$iv) : ''; } /* ---------- save / delete key ---------------------------------------- */ $msg = ''; if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['save_key'])){ $raw = trim($_POST['api_key']); $ctx = stream_context_create(['http'=>[ 'method'=>'GET', 'header'=>"Authorization: Bearer $raw\r\n", 'timeout'=>8 ]]); if (@file_get_contents('https://api.openai.com/v1/models',false,$ctx)){ setcookie(COOKIE_NAME, enc($raw), time()+COOKIE_TTL,'/','',isset($_SERVER['HTTPS']),true); header('Location: '.$_SERVER['REQUEST_URI']); exit; }else $msg='❌ Invalid key.'; } if (isset($_GET['del'])){ setcookie(COOKIE_NAME,'',time()-3600,'/','',isset($_SERVER['HTTPS']),true); header('Location: '.$_SERVER['PHP_SELF']); exit; } /* ---------- runtime settings ----------------------------------------- */ $key = isset($_COOKIE[COOKIE_NAME]) ? dec($_COOKIE[COOKIE_NAME]) : ''; $models= ['gpt-3.5-turbo','gpt-4o-mini','gpt-4']; $types = ['B','C','Dtxt']; $model = in_array($_GET['model']??'',$models,true)?$_GET['model']:'gpt-3.5-turbo'; $type = in_array($_GET['type'] ??'',$types ,true)?$_GET['type'] :'B'; $scope = $_GET['scope'] ?? 'general'; $word = trim($_GET['word'] ?? ''); $count = max(1,min(15,intval($_GET['count']??5))); /* ---------- call OpenAI ---------------------------------------------- */ $items=[]; if($key && $word){ $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=>1, CURLOPT_HTTPHEADER=>['Authorization: Bearer '.$key,'Content-Type: application/json'], CURLOPT_POST=>1,CURLOPT_POSTFIELDS=>json_encode($payload),CURLOPT_TIMEOUT=>12]); $resp=curl_exec($ch); curl_close($ch); $raw = array_filter(array_map('trim',explode(',',$resp ? json_decode($resp,true)['choices'][0]['message']['content']??'' : ''))); array_unshift($raw,$word); // include seed first $items=array_slice(array_unique($raw),0,$count); } ?> <!doctype html><html lang=en><head> <meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"> <title>Promptinator – AI Toolbox</title> <link rel=stylesheet href="/members/css/ai-core.css"><!-- 📌 shared palette --> <style> /* ---- page‑specific tweaks, rest comes from ai-core.css -------------- */ .sidebar{background:#111826;color:#fff;max-width:300px;border-radius:1rem;padding:2rem} .sidebar h1{margin:0 0 1rem;font-size:1.7rem;color:#ffb63b} .sidebar select,.sidebar input{width:100%;padding:.7rem;border-radius:.65rem;background:#182236;border:1px solid #293348;color:#fff;font-size:1rem} .sidebar button{width:100%;padding:.75rem;border:none;border-radius:.65rem;font-weight:700;cursor:pointer;background:#0066ff;color:#fff;margin-top:.75rem} .sidebar button:hover{background:#0052d1} .sidebar .tiny{font-size:.85rem;color:#a5aec6;margin-top:.4rem} .main-panel{background:#fff;border-radius:1rem;padding:2rem;box-shadow:0 0 30px #0001;max-width:830px;width:100%} .token{background:#eaf2ff;color:#244d9e;border-radius:1.25rem;padding:.35rem .9rem;margin:.2rem .35rem;display:inline-block;position:relative;font-weight:600} .token .remove{position:absolute;right:6px;top:0;font-weight:bold;cursor:pointer;color:#d04a3f} pre#shortcode{background:#0f172a;color:#fff;border-radius:.75rem;padding:1.3rem 1.6rem;font-size:1rem} label{font-weight:600;margin:.4rem 0 .15rem;display:block} select,input[type=text]{border:1px solid #cdd4e3;border-radius:.6rem;padding:.65rem;font-size:1rem;width:100%} #gen{background:#0066ff;color:#fff;padding:.75rem 1.8rem;border:none;border-radius:.65rem;font-weight:700;cursor:pointer;margin-top:1rem} #mic-btn{cursor:pointer;margin-left:.3rem} </style> </head><body> <?php /* breadcrumb */ ?> <div class="crumbs" style="padding:.8rem 1.2rem;background:#eee"> <a href="/">BestDealOn</a> » <a href="/members/dashboard.php">Dashboard</a> » <a href="/ai-tools/tools.php">AI Toolbox</a> » Promptinator <a href="/<?=$me['site_slug']??''?>/" style="float:right">View Site</a> </div> <div style="display:flex;gap:2.2rem;flex-wrap:wrap;justify-content:center;margin:2.5rem auto;max-width:1120px"> <!--------------- SIDEBAR ---------------> <div class="sidebar"> <h1>Promptinator</h1> <?php if(!$key): ?> <form method=post autocomplete=off> <input type=password name=api_key placeholder="sk-..." required> <button name=save_key>Save key</button> <div class=tiny> <?= $msg ?: 'Your key is encrypted & stored only in this browser.'?><br> <a href="https://platform.openai.com/api-keys" target=_blank style="color:#4da3ff">Get an OpenAI key →</a> </div> </form> <?php else: ?> <div style="margin:.3rem 0 1rem;color:#72eb99;font-size:.95rem">● API key saved</div> <form id=modelForm> <label>Model</label> <select id=selModel name=model onchange="modelChange()"> <?php foreach($models as $m): ?> <option value="<?=$m?>"<?=$m===$model?' selected':''?>><?=$m?></option> <?php endforeach;?> </select> </form> <form id=typeForm> <label>Control type</label> <select id=selType name=type onchange="typeChange()"> <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> </form> <button id="copySC" onclick="copyShort()">Copy Shortcode</button> <button id="copyCSV" style="display:<?=count($items)?'block':'none'?>" onclick="copyCsv()">Copy CSV</button> <a href="?del=1" style="display:block;margin-top:1rem;color:#4da3ff;text-align:center">Delete key</a> <?php endif;?> </div> <!--------------- MAIN ---------------> <div class="main-panel"> <?php if(!$key): ?> <h2>Get started</h2> <p>Save your API key on the left to unlock Promptinator.</p> <?php else: ?> <h2>Generate options</h2> <form id="cfg" method=get autocomplete=off style="display:grid;gap:1.3rem;grid-template-columns:1fr 1fr"> <input type=hidden id=model name=model value="<?=htmlspecialchars($model)?>"> <input type=hidden id=type name=type value="<?=htmlspecialchars($type)?>"> <div style="grid-column:1/3"> <label>Seed word <span id=mic-btn title="Dictate">🎤</span></label> <input type=text id=seed name=word placeholder="e.g. shoes" value="<?=htmlspecialchars($word)?>"> </div> <div> <label>Relation</label> <select id=scope name=scope> <?php foreach(['general','broad','narrow','longtail','shorttail'] as $r) echo "<option value=\"$r\"".($scope===$r?' selected':'').'>'.$r.'</option>'; ?> </select> </div> <div> <label>Count</label> <select id=count name=count onchange="document.getElementById('cfg').submit()"> <?php for($i=1;$i<=15;$i++) echo "<option".($i==$count?' selected':'').">$i</option>";?> </select> </div> <button id=gen onclick="event.preventDefault();document.getElementById('cfg').submit()">Generate</button> </form> <div style="margin-top:2rem"> <h3>Tokens</h3> <div id=tokens></div> <label style="margin-top:1rem">Default value</label> <select id=defSel style="margin-bottom:1rem"></select> <pre id=shortcode></pre> </div> <?php endif;?> </div> <!-- /main-panel --> </div> <!-- /flex wrap container --> <script> // ================= helpers ================ const items = <?=json_encode($items)?>; const typeInp=document.getElementById('type'), modelInp=document.getElementById('model'); function modelChange(){modelInp.value=document.getElementById('selModel').value;document.getElementById('cfg').submit();} function typeChange(){typeInp.value=document.getElementById('selType').value;document.getElementById('cfg').submit();} function renderUI(){ const tokWrap=document.getElementById('tokens'); if(!tokWrap) return; tokWrap.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);renderUI();}; s.appendChild(x);tokWrap.appendChild(s); }); const defSel=document.getElementById('defSel'); defSel.innerHTML=''; items.forEach(t=>{ const o=document.createElement('option');o.value=t;o.textContent=t;defSel.appendChild(o); }); defSel.onchange=()=>{const v=defSel.value;items.unshift(...items.splice(items.indexOf(v),1));renderUI();} if(items[0]) defSel.value=items[0]; const pref=(typeInp.value==='Dtxt')?'D':typeInp.value, sc=`[${pref}-${document.getElementById('seed').value||'seed'}-|${items.join('|')}|~${items[0]??''}~]`; document.getElementById('shortcode').textContent=sc; document.getElementById('copyCSV').style.display=items.length?'block':'none'; } function copyShort(){navigator.clipboard.writeText(document.getElementById('shortcode').textContent).then(()=>{btnFlash('copySC');});} function copyCsv(){navigator.clipboard.writeText(items.join(', ')).then(()=>{btnFlash('copyCSV');});} function btnFlash(id){const b=document.getElementById(id);const t=b.textContent;b.textContent='Copied!';setTimeout(()=>b.textContent=t,1400);} renderUI(); // ---- microphone (optional) ------------- document.addEventListener('DOMContentLoaded',()=>{ const mic=document.getElementById('mic-btn');if(!mic)return; const SR=window.SpeechRecognition||window.webkitSpeechRecognition;if(!SR){mic.remove();return;} const rec=new SR();rec.lang='en-US';rec.interimResults=false;rec.maxAlternatives=1; mic.onclick=()=>{mic.textContent='🎤…';rec.start();}; rec.onresult=e=>{document.getElementById('seed').value=e.results[0][0].transcript;mic.textContent='🎤';}; rec.onerror =()=>{mic.textContent='🎤';}; }); </script> </body></html>
Save changes
Create folder
writable 0777
Create
Cancel