Siteβ―Builder
Editing:
search2.php
writable 0666
<?php /********************************************************************** * Public Search page powered by Promptinator β’ SeptΒ 2025 * ------------------------------------------------------------------ * Example URL: * /search.php?user=rfsafe&tag=Restart+the+NTP+carcinogenicity+program *********************************************************************/ declare(strict_types=1); /* ββ 0. Shared helpers ------------------------------------------------ */ require_once $_SERVER['DOCUMENT_ROOT'].'/openai/init.php'; ai_handle_key_post(); // OpenAIβkey black bar /* ββ 1. Resolve profile.json exactly like toolsβdynamicβprompts.php β */ $ph = $_GET['ph'] ?? ''; $slug = $_GET['user'] ?? ''; $uri = $_SERVER['REQUEST_URI']; if (!$ph && preg_match('#/ph/(\d{10,15})(?:/|$)#',$uri,$m)) $ph = $m[1]; if (!$slug && preg_match('#/(?:social|@)([A-Za-z0-9_-]+)(?:/|$)#',$uri,$m)) $slug=$m[1]; if (!$ph && !$slug) { $parent = basename(dirname(__FILE__)); if (preg_match('/^\d{10,15}$/',$parent)) $ph = $parent; elseif (preg_match('/^[A-Za-z0-9_-]+$/',$parent)) $slug = $parent; } $root = rtrim($_SERVER['DOCUMENT_ROOT'],'/'); $dir = ''; if ($ph) $dir="$root/ph/$ph"; if ($slug) $dir="$root/social/$slug"; $profilePath = ($dir && is_readable($dir.'/profile.json')) ? $dir.'/profile.json' : null; $profile = $profilePath ? json_decode(file_get_contents($profilePath), true) : []; /* ββ 2. (Optional) global prompts.json in same folder -------------- */ $promptsFile = __DIR__.'/prompts.json'; $prompts = (is_readable($promptsFile)) ? json_decode(file_get_contents($promptsFile), true) : []; /* Fallback single prompt if no prompts.json is present */ define('SEARCH_PROMPT', <<<TXT You are a helpful research assistant for [name]. Write a **concise** answer about: [topic] β’ Format: [B-format-|bullet list|short summary|FAQ|detailed overview-~short summary~] β’ Focus on: [C-focus-|health implications|latest news|practical tips|product suggestions-] Always mention [name] and provide 1 outbound link if relevant. TXT); /* Helper for prompt labels */ $label = static fn(string $t):string => preg_replace('/\s+/',' ',implode(' ',array_slice(explode(' ',trim($t)),0,4))).'β¦'; ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Smart Search β’ Promptinator</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="stylesheet" href="/promptinator.css"> <link rel="modulepreload" href="/dynamicPromptinator.js"> <style> :root{--bg:#f1f4fb;--card:#fff;--gold:#ffb63b;--shadow:0 6px 30px rgba(0,0,0,.08); font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;} body{margin:0;min-height:100vh;background:var(--bg);display:flex;flex-direction:column;color:#111} .shell{width:clamp(280px,90%,720px);margin:2.4rem auto;padding:1.8rem 1.6rem; background:var(--card);border:3.5px solid var(--gold);border-radius:27px;box-shadow:var(--shadow)} .shell h1{margin-top:0} .shell label{font-weight:700;margin-bottom:.4rem;display:block;color:#0d4ca2} .shell input[type=text]{width:100%;padding:.55rem .7rem;font-size:1rem;border:1px solid #ccd;border-radius:9px} .shell button{margin-top:.8rem;background:#004cff;color:#fff;border:none;border-radius:8px; padding:.55rem 1.5rem;font-weight:600;cursor:pointer} .pi-holder{margin-top:1.4rem} .model-banner{margin:.8rem 0 1.4rem;padding:.4rem .7rem;background:#eef;border-left:4px solid #5c3bff} </style> <script> /* expose profile data so Promptinator tokens can use them */ window.profileData = <?= json_encode($profile, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) ?>; </script> </head> <body> <?php ai_render_key_bar(); ?> <main class="shell"> <h1>KnowledgeΒ Search</h1> <?php /* Current model banner (if MeowΒ AI or similar is installed) */ if(function_exists('mwai_get_option')) { $model = mwai_get_option('ai_default_model') ?: 'N/A'; echo '<div class="model-banner"><strong>Current AI model:</strong> '.esc_html($model).'</div>'; } ?> <!-- Search box --> <form id="topicForm" method="get" style="margin-bottom:1.6rem;"> <input type="hidden" name="user" value="<?= htmlspecialchars($slug) ?>"> <label for="topic">What do you want to explore?</label> <input id="topic" type="text" name="tag" placeholder="e.g. RF exposure on sleep quality" value="<?= isset($_GET['tag']) ? htmlspecialchars($_GET['tag']) : '' ?>"> <button>Ask AI</button> </form> <!-- Prompt selector only if prompts.json exists --> <?php if($prompts): ?> <label for="promptSel">Choose a template:</label> <select id="promptSel"> <?php foreach($prompts as $i=>$p): ?> <option value="<?= $i ?>"><?= htmlspecialchars($label($p['prompt'])) ?></option> <?php endforeach; ?> </select> <?php endif; ?> <div id="piHolder" class="pi-holder"></div> </main> <script type="module"> (()=>{ const holder = document.getElementById('piHolder'); const topicInp = document.getElementById('topic'); const form = document.getElementById('topicForm'); const promptSel= document.getElementById('promptSel'); /* PHP array of prompts (may be empty) */ const PROMPTS = <?php echo $prompts ? json_encode(array_column($prompts,'prompt'), JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP) : '[]'; ?>; const FALLBACK_PROMPT = <?= json_encode(SEARCH_PROMPT, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP) ?>; function buildPromptTemplate(){ if(PROMPTS.length){ const idx = +promptSel.value || 0; return PROMPTS[idx] || FALLBACK_PROMPT; } return FALLBACK_PROMPT; } function render(){ const topic = topicInp.value.trim(); /* Build the DIV with [topic] token replaced with the actual search term as default */ const tpl = buildPromptTemplate(); const inject= tpl.replace('[topic]', topic || 'β¦'); holder.innerHTML = '<div class="Promptinator" edit="1" think="1" data-prompt>'+inject+'</div>'; const boot = P=>P.init({ mount: holder.firstElementChild }); if(window.Promptinator?.init) boot(window.Promptinator); else import('/dynamicPromptinator.js') .then(m=>boot(m.default||m.Promptinator)); } /* Initial render if tag param is present */ if(topicInp.value) render(); form.addEventListener('submit', e=>{ e.preventDefault(); /* keep tag in URL for bookmarking */ const url = new URL(location.href); url.searchParams.set('tag', topicInp.value); history.replaceState(null,'',url); render(); }); promptSel?.addEventListener('change', render); })(); </script> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel