Siteβ―Builder
Editing:
index2.php
writable 0666
<?php // ------------------------------------------------------------- // RFΒ Safe β SingleβPrompt Article Generator (v1.2 β keyword links) // ------------------------------------------------------------- // βΈ Adds optional **LinkΒ URL** field. // βΈ If provided, the prompt instructs the model to hyperlink each keyword // (exactly once) to that URL. // βΈ Keywords field still weaves terms naturally. // βΈ Reβuses Promptinator sidebar for APIβkey / model / type. // ------------------------------------------------------------- // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // COOKIEβBASED KEY STORAGE (unchanged) const COOKIE_NAME = 'openai_key'; const COOKIE_TTL = 30 * 24 * 3600; // 30 days const SECRET = __FILE__; function encrypt_val(string $v): string { $method = 'aes-128-ctr'; $key = substr(hash('sha256', SECRET, true), 0, 16); $iv = random_bytes(openssl_cipher_iv_length($method)); return base64_encode(openssl_encrypt($v, $method, $key, 0, $iv).'::'.$iv); } function decrypt_val(string $c): string { [$ct,$iv] = explode('::', base64_decode($c), 2) + [null,null]; if(!$ct||!$iv) return ''; $method='aes-128-ctr'; $key = substr(hash('sha256', SECRET, true), 0, 16); return openssl_decrypt($ct, $method, $key, 0, $iv) ?: ''; } // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // SIMPLE POST HANDLER β CHAT COMPLETION (single prompt) $msg = ''; $html = ''; if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['generate'])) { $cookie = $_COOKIE[COOKIE_NAME] ?? ''; $key = $cookie ? decrypt_val($cookie) : ''; if (!$key) { $msg = 'βΒ Missing API key.'; } else { $model = $_POST['model'] ?? 'gpt-3.5-turbo'; $topic = trim($_POST['topic'] ?? ''); $sections = intval($_POST['sections'] ?? 3); $paras = intval($_POST['paras'] ?? 3); $lang = $_POST['lang'] ?? 'English'; $style = $_POST['style'] ?? 'Creative'; $tone = $_POST['tone'] ?? 'Neutral'; $keywords = trim($_POST['keywords'] ?? ''); $linkurl = trim($_POST['linkurl'] ?? ''); $kwText = $keywords ? " Include the following keywords naturally throughout the article: $keywords." : ''; $linkText = ($keywords && $linkurl) ? " Hyperlink each keyword exactly once to $linkurl in markdown format." : ''; $userPrompt = "Write an $lang article in a $tone tone using a $style writing style on the topic \"$topic\". " . "Structure it into $sections sections with $paras paragraphs per section." . $kwText . $linkText . " After the body, include a short excerpt labelled 'Excerpt'. Return ONLY the article in Markdown."; $payload = [ 'model' => $model, 'messages' => [ ['role'=>'user','content'=>$userPrompt] ], 'max_tokens' => max(600, $sections*$paras*160), 'temperature' => 0.7 ]; $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=>45 ]); $resp = curl_exec($ch); curl_close($ch); $data = json_decode($resp,true); $html = $data['choices'][0]['message']['content'] ?? 'βΒ No content returned.'; } } // LANGUAGE / STYLE / TONE LISTS (static) $langs = ['English','Spanish','German','French','Italian','Portuguese','Dutch']; $styles = ['Creative','Informative','Narrative','Persuasive','Analytical','Journalistic']; $tones = ['Neutral','Cheerful','Humorous','Assertive','Inspirational','Professional','Emotional']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Article Generator β Promptinator</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"> <style> :root{--blue:#4f8cff;--blue-d:#275dbe;--grey:#23253a;--grey-l:#f5f7fa;--radius:.75rem} *{box-sizing:border-box} body{margin:0;display:flex;min-height:100vh;font-family:system-ui,sans-serif;background:var(--grey-l)} .sidebar{flex:0 0 280px;background:#181c23;color:#fff;padding:2rem;display:flex;flex-direction:column;gap:1.25rem} .sidebar h1{margin:0;font-size:1.6rem;color:var(--blue)} .main{flex:1;padding:2rem;display:flex;justify-content:center;align-items:flex-start} .panel{background:#fff;border-radius:var(--radius);box-shadow:0 4px 24px rgba(0,0,0,.08);padding:2rem;max-width:760px;width:100%;display:grid;gap:1.25rem} label{font-weight:600} textarea#article{min-height:340px;font-family:"Fira Code",monospace} button.copy{background:var(--blue);color:#fff;border:none;border-radius:var(--radius);padding:.6rem 1.2rem;cursor:pointer} @media(max-width:800px){body{flex-direction:column}.sidebar{width:100%;order:2}.main{order:1;padding:1rem}} </style> </head> <body> <!-- ββββββββββ SIDEBAR (login) --> <div class="sidebar"> <h1>Promptinator</h1> <?php $cookie=$_COOKIE[COOKIE_NAME]??''; $key=$cookie?decrypt_val($cookie):''; if(!$key):?> <form method="post" autocomplete="off"> <input type="password" name="api_key" placeholder="sk-..." required> <button name="save_key">SaveΒ &Β Login</button> <a href="https://platform.openai.com/api-keys" target="_blank" style="font-size:.9rem;color:var(--blue)">πΒ Get your API Key</a> </form> <small><?= $msg ?: 'Your key is stored only in a browser cookie.' ?></small> <?php else:?> <div style="font-size:.95rem"><span style="color:#72eb99">β</span>Β LoggedΒ in</div> <a href="?delete_key=1" style="color:#fff;text-decoration:none;font-size:.9rem">Logout</a> <?php endif;?> </div> <!-- ββββββββββ MAIN PANEL --> <div class="main"> <div class="panel"> <h2>Create an Article</h2> <?php if(!$key):?> <p>Please enter your OpenAI key in the sidebar to continue.</p> <?php else:?> <form method="post" id="frm"> <input type="hidden" name="model" value="gpt-4o-mini"> <label>Topic <input name="topic" id="topic" placeholder="e.g. Benefits of LiβFi Technology" required> </label> <label>Keywords (commaβseparated) <input name="keywords" id="keywords" placeholder="li-fi, rf safety, photonic communication"> </label> <label>Link URL (optional) <input name="linkurl" id="linkurl" type="url" placeholder="https://example.com"> </label> <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:1rem"> <label>#Β Sections <select name="sections" id="sections"> <?php for($i=1;$i<=8;$i++):?><option value="<?=$i?>" <?=$i==3?'selected':''?>><?=$i?></option><?php endfor;?> </select> </label> <label>#Β Paragraphs / Section <select name="paras" id="paras"> <?php for($i=1;$i<=6;$i++):?><option value="<?=$i?>" <?=$i==3?'selected':''?>><?=$i?></option><?php endfor;?> </select> </label> <label>Language <select name="lang" id="lang"> <?php foreach($langs as $l):?><option value="<?=$l?>"><?=$l?></option><?php endforeach;?> </select> </label> <label>Style <select name="style" id="style"> <?php foreach($styles as $s):?><option value="<?=$s?>" <?= $s==='Creative'?'selected':''?>><?=$s?></option><?php endforeach;?> </select> </label> <label>Tone <select name="tone" id="tone"> <?php foreach($tones as $t):?><option value="<?=$t?>" <?= $t==='Neutral'?'selected':''?>><?=$t?></option><?php endforeach;?> </select> </label> </div> <label>Prompt Preview <textarea id="prompt" readonly style="min-height:120px"></textarea> </label> <button type="button" class="copy" id="copyPrompt">CopyΒ Prompt</button> <button name="generate" style="margin-top:1rem">Generate Article</button> </form> <?php if($html):?> <label>Article Markdown <textarea id="article" readonly><?= htmlspecialchars($html) ?></textarea> </label> <button type="button" class="copy" id="copyArticle">CopyΒ Article</button> <?php endif;?> <?php endif;?> </div> </div> <script> (function(){ const get = id=>document.getElementById(id); const els = ['topic','keywords','linkurl','sections','paras','lang','style','tone'].map(get); const promptBox = get('prompt'); const copyPrompt = get('copyPrompt'); function build(){ const topic = get('topic').value.trim(); if(!topic){promptBox.value='';return;} const kw = get('keywords').value.trim(); const linkurl = get('linkurl').value.trim(); const ns = get('sections').value; const np = get('paras').value; const lang = get('lang').value; const style = get('style').value; const tone = get('tone').value; const kwText = kw?` Include the following keywords naturally throughout the article: ${kw}.`:''; const linkText= (kw&&linkurl)?` Hyperlink each keyword exactly once to ${linkurl} in markdown format.`:''; promptBox.value = `Write an ${lang} article in a ${tone} tone using a ${style} writing style on the topic "${topic}". `+ `Structure it into ${ns} sections with ${np} paragraphs per section.`+ kwText + linkText + ` After the body, include a short excerpt labelled 'Excerpt'. Return ONLY the article in Markdown.`; } els.forEach(el=>el&&el.addEventListener('input',build)); build(); if(copyPrompt) copyPrompt.addEventListener('click',()=>{ navigator.clipboard.writeText(promptBox.value).then(()=>copyPrompt.textContent='Copied!'); setTimeout(()=>copyPrompt.textContent='Copy Prompt',1500); }); const copyArt = document.getElementById('copyArticle'); if(copyArt){ copyArt.addEventListener('click',()=>{ navigator.clipboard.writeText(document.getElementById('article').value).then(()=>copyArt.textContent='Copied!'); setTimeout(()=>copyArt.textContent='Copy Article',1500); }); } })(); </script> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel