Site Builder
Editing:
index1.php
writable 0666
<?php // ---------------------------------------------------- // RF Safe – Single‑Prompt Article Generator (v1.0) // Reuses Promptinator sidebar / API‑key flow // ---------------------------------------------------- // 🔑 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 { $m = 'aes-128-ctr'; $k = substr(hash('sha256', SECRET, true), 0, 16); $iv = random_bytes(openssl_cipher_iv_length($m)); return base64_encode(openssl_encrypt($v, $m, $k, 0, $iv)."::".$iv); } function decrypt_val(string $c): string { [$ct,$iv] = explode('::', base64_decode($c), 2); $m = 'aes-128-ctr'; $k = substr(hash('sha256', SECRET, true), 0, 16); return openssl_decrypt($ct, $m, $k, 0, $iv); } // ---------- Handle API‑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); header('Location: '.$_SERVER['REQUEST_URI']); exit; } $msg = '❌ Invalid key.'; } if (isset($_GET['delete_key'])) { setcookie(COOKIE_NAME,'',time()-3600,'/','',isset($_SERVER['HTTPS']),true); header('Location: '.$_SERVER['PHP_SELF']); exit; } // ---------- Logged‑in vars ---------- $key = isset($_COOKIE[COOKIE_NAME]) ? decrypt_val($_COOKIE[COOKIE_NAME]) : ''; // sidebar model select (optional) $allowed_models = ['gpt-3.5-turbo', 'gpt-4o-mini', 'gpt-4']; $model = in_array($_POST['model'] ?? ($_GET['model'] ?? ''), $allowed_models, true) ? ($_POST['model'] ?? $_GET['model']) : 'gpt-3.5-turbo'; // ---------- Generate article if requested ---------- $article = ''; if ($key && $_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['generate_article'])) { // Sanitize inputs $topic = trim($_POST['topic'] ?? ''); $headings = max(1, min(10, intval($_POST['sections'] ?? 3))); $paragraphs = max(1, min(10, intval($_POST['paragraphs'] ?? 2))); $language = trim($_POST['language'] ?? 'English'); $style = trim($_POST['style'] ?? 'Creative'); $tone = trim($_POST['tone'] ?? 'Neutral'); $prompt_text = trim($_POST['prompt'] ?? ''); // Build payload & call OpenAI $payload = [ 'model' => $model, 'messages' => [ ['role'=>'system','content'=>'You are a seasoned content writer. Return exactly the formatted article requested.'], ['role'=>'user', 'content' => $prompt_text] ], 'max_tokens' => 2048, 'temperature' => 0.8 ]; $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=>60 ]); $resp = curl_exec($ch); curl_close($ch); $data = json_decode($resp,true); $article = $data['choices'][0]['message']['content'] ?? '⚠️ No content returned.'; } ?> <!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{ --accent:#4f8cff; --accent-d:#275dbe; } body{display:flex;min-height:100vh;margin:0;background:#f5f7fa;font-family:system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif;} /* Sidebar (same vibe) */ .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.7rem;color:var(--accent);} .sidebar button, .sidebar input, .sidebar select{width:100%;padding:.7rem;border-radius:.6rem;border:none;font-size:1rem;} .sidebar button{background:var(--accent);color:#fff;cursor:pointer;} .sidebar button:hover{background:var(--accent-d);} .sidebar-status{display:flex;align-items:center;gap:.5ch;font-size:1rem;} .sidebar-status span{color:#72eb99;font-size:1.2em;} .logout{margin-top:auto;text-align:center;color:#fff;text-decoration:none;font-weight:600;} /* Main */ .main{flex:1;display:flex;justify-content:center;padding:2rem;} .panel{width:100%;max-width:900px;background:#fff;border-radius:.75rem;box-shadow:0 4px 22px rgba(0,0,0,.08);padding:2rem;display:grid;gap:1.5rem;} .grid-2{display:grid;grid-template-columns:1fr 1fr;gap:1rem;} textarea{min-height:140px;font-family:inherit;} #result{min-height:320px;white-space:pre-wrap;} .copy-btn{background:var(--accent);color:#fff;border:none;border-radius:.6rem;padding:.5rem 1rem;cursor:pointer;} .copy-btn:hover{background:var(--accent-d);} @media(max-width:768px){body{flex-direction:column;} .sidebar{flex:none;width:100%;order:2;} .main{order:1;padding:1rem;} .grid-2{grid-template-columns:1fr;} } </style> </head> <body> <!-- ░░ 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 & Login</button> </form> <div style="font-size:.9rem;color:#aaa;"><?= $msg ?: 'Your key is stored only in a local cookie.' ?></div> <a href="https://platform.openai.com/api-keys" target="_blank" style="color:var(--accent);font-size:.9rem;">👉 Get an API key</a> <?php else: ?> <div class="sidebar-status"><span>●</span> Logged in</div> <form method="get" id="model-form"> <label style="font-size:.9rem;">Model</label> <select name="model" onchange="this.form.submit()"> <?php foreach($allowed_models as $m): ?> <option value="<?=$m?>" <?= $model===$m?'selected':''?>><?=$m?></option> <?php endforeach; ?> </select> </form> <a href="?delete_key=1" class="logout">Logout</a> <?php endif; ?> </div> <!-- ░░ MAIN ░░ --> <div class="main"> <div class="panel"> <?php if(!$key): ?> <h2>Welcome.</h2> <p>Enter your OpenAI API key on the left to start generating full articles from a single prompt.</p> <?php else: ?> <h2>Single‑Prompt Article Generator</h2> <form id="gen-form" method="post"> <input type="hidden" name="generate_article" value="1"> <input type="hidden" name="model" value="<?=htmlspecialchars($model)?>"> <label>Topic *</label> <textarea name="topic" id="topic" placeholder="e.g. The rise of Li‑Fi technology" required><?= htmlspecialchars($_POST['topic'] ?? '') ?></textarea> <label>Keywords (comma-separated) <input name="keywords" id="keywords" placeholder="li-fi, rf safety, photonic communication"> </label> <div class="grid-2"> <div> <label># Headings</label> <select name="sections" id="sections"> <?php for($i=1;$i<=10;$i++): ?> <option value="<?=$i?>" <?= ((int)($_POST['sections']??3)===$i)?'selected':''?>><?=$i?></option> <?php endfor; ?> </select> </div> <div> <label># Paragraphs / Heading</label> <select name="paragraphs" id="paragraphs"> <?php for($i=1;$i<=10;$i++): ?> <option value="<?=$i?>" <?= ((int)($_POST['paragraphs']??2)===$i)?'selected':''?>><?=$i?></option> <?php endfor; ?> </select> </div> </div> <div class="grid-2"> <div> <label>Language</label> <select name="language" id="language"> <?php $langs=['English','Spanish','French','German','Italian','Portuguese']; foreach($langs as $l): ?> <option value="<?=$l?>" <?= ($_POST['language']??'English')===$l?'selected':''?>><?=$l?></option> <?php endforeach; ?> </select> </div> <div> <label>Writing Style</label> <select name="style" id="style"> <?php $styles=['Informative','Descriptive','Creative','Narrative','Persuasive','Reflective','Argumentative','Analytical','Evaluative','Journalistic']; foreach($styles as $s): ?> <option value="<?=$s?>" <?= ($_POST['style']??'Creative')===$s?'selected':''?>><?=$s?></option> <?php endforeach; ?> </select> </div> </div> <label>Writing Tone</label> <select name="tone" id="tone"> <?php $tones=['Neutral','Formal','Assertive','Cheerful','Humorous','Informal','Inspirational','Professional','Confluent','Emotional']; foreach($tones as $t): ?> <option value="<?=$t?>" <?= ($_POST['tone']??'Neutral')===$t?'selected':''?>><?=$t?></option> <?php endforeach; ?> </select> <!-- Prompt preview / copy --> <label>Prompt Preview</label> <textarea id="prompt" name="prompt" readonly style="background:#f7f9fc;min-height:120px;"></textarea> <button type="button" class="copy-btn" id="copy-prompt">Copy Prompt</button> <button type="submit" style="margin-top:1rem;">Generate Article</button> </form> <!-- Result --> <?php if($article): ?> <h3>Generated Article</h3> <textarea id="result" readonly><?= htmlspecialchars($article) ?></textarea> <button type="button" class="copy-btn" id="copy-article">Copy Article</button> <?php endif; ?> <?php endif; ?> </div> </div> <script> // Build dynamic prompt as user tweaks knobs (function(){ const els = ['topic','sections','paragraphs','language','style','tone']; const area = document.getElementById('prompt'); const hidden = area; // same field – textarea is submitted function build(){ const v = (id)=>document.getElementById(id)?.value.trim(); const topic = v('topic'); const headings = v('sections'); const paras = v('paragraphs'); const lang = v('language'); const style = v('style'); const tone = v('tone'); const p = `Write a ${tone.toLowerCase()} ${style.toLowerCase()} article in ${lang} on the topic "${topic}".\n\n`+ `• Create a compelling title.\n`+ `• Structure the body into ${headings} sections, each with an H2 heading.\n`+ `• Under each heading, write ${paras} well‑developed paragraph${paras>1?'s':''}.\n`+ `• After the body, add a short excerpt summarizing the article (label it \"Excerpt\").\n`+ `Return the full article in Markdown format.`; area.value = p; } els.forEach(id=>document.getElementById(id)?.addEventListener('input',build)); build(); })(); // Copy helpers function addCopy(btnId,srcId){ const b=document.getElementById(btnId),s=document.getElementById(srcId); if(!b||!s)return; b.onclick=()=>{ navigator.clipboard.writeText(s.value||s.textContent).then(()=>{ const t=b.textContent;b.textContent='Copied!';setTimeout(()=>b.textContent=t,1500); }); }; } addCopy('copy-prompt','prompt'); addCopy('copy-article','result'); </script> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel