Files
html/api/ambre-tool-site.php

90 lines
4.0 KiB
PHP

<?php
/**
* ambre-tool-site.php — Full SaaS landing page generator
*/
header('Content-Type: application/json');
/* SESSION_CONTEXT_INJECTED v1 */
require_once __DIR__ . '/ambre-session-context.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['ok'=>false,'error'=>'POST only']); exit; }
$input = json_decode(file_get_contents('php://input'), true);
$topic = trim($input['topic'] ?? '');
if (strlen($topic) < 3) { echo json_encode(['ok'=>false,'error'=>'topic too short']); exit; }
$topic = substr($topic, 0, 400);
$prompt = "Expert frontend designer SaaS. Genere une landing page COMPLETE premium pour: \"$topic\"\n\n"
. "Sections obligatoires (dans cet ordre):\n"
. "1. Header sticky avec logo, menu (5-6 items), CTA button\n"
. "2. Hero section avec headline + sub-headline + 2 CTA + visual mockup/illustration\n"
. "3. Logo bar (6-8 companies trust)\n"
. "4. Features grid (6 features avec icons SVG, titres, descriptions)\n"
. "5. How it works (3-4 etapes numerotees)\n"
. "6. Testimonials (3 cards avec rating 5 etoiles, photo avatar circulaire initiales, nom, entreprise)\n"
. "7. Pricing table (3 tiers: Starter/Pro/Enterprise) avec features check/cross\n"
. "8. FAQ accordeon (5-6 questions)\n"
. "9. CTA final section\n"
. "10. Footer riche (4 colonnes links + newsletter + social)\n\n"
. "Tech:\n"
. "- Tailwind CSS via CDN\n"
. "- HTML complet standalone <!DOCTYPE html>\n"
. "- Mobile responsive (breakpoints sm/md/lg)\n"
. "- Dark/light mode toggle avec localStorage ... NON, pas localStorage. Juste toggle simple via class.\n"
. "- Palette: indigo/purple/slate pour bg, emerald pour succes CTAs\n"
. "- Hover effects (scale, shadow, color transitions)\n"
. "- Smooth scroll anchors\n"
. "- Animations CSS (fade-in, slide-up)\n"
. "- Typography: Inter / system-ui\n"
. "- Design ultra moderne 2026\n"
. "- Contenu realiste et coherent avec le sujet\n"
. "- Pas de localStorage, pas de fetch externe\n\n"
. "RETOURNE UNIQUEMENT LE CODE HTML complet (sans backticks)";
$prompt = wvia_context_for_prompt() . $prompt;
$ch = curl_init('http://127.0.0.1:4000/v1/chat/completions');
curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode([
'model' => 'auto',
'messages' => [['role'=>'user', 'content'=>$prompt]],
'max_tokens' => 12000, 'temperature' => 0.75
]),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_TIMEOUT => 180,
]);
$resp = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http !== 200) { echo json_encode(['ok'=>false,'error'=>"LLM HTTP $http"]); exit; }
$data = json_decode($resp, true);
$html = $data['choices'][0]['message']['content'] ?? '';
$html = preg_replace('/^```(?:html)?\s*\n/', '', $html);
$html = preg_replace('/\n```\s*$/', '', trim($html));
if (stripos($html, '<!DOCTYPE') === false && stripos($html, '<html') === false) {
echo json_encode(['ok'=>false,'error'=>'invalid HTML','preview'=>substr($html,0,300)]); exit;
}
$filename = 'site-' . substr(md5($topic . microtime(true)), 0, 10) . '.html';
$outpath = '/var/www/html/files/' . $filename;
if (!is_dir('/var/www/html/files')) { mkdir('/var/www/html/files', 0755, true); }
file_put_contents($outpath, $html);
// SESSION LINK DOC
if (isset($outpath) && isset($filename)) {
$__wvia_title = isset($doc) && isset($doc['title']) ? $doc['title'] : (isset($spec) && isset($spec['title']) ? $spec['title'] : (isset($deck) && isset($deck['title']) ? $deck['title'] : (isset($topic) ? $topic : 'Document')));
wvia_link_doc('/files/' . $filename, 'site', $__wvia_title);
if (isset($topic)) wvia_append_turn('user', $topic);
wvia_append_turn('assistant', '[SITE generated: ' . ($__wvia_title ?: 'doc') . ']');
}
echo json_encode([
'ok'=>true,
'url'=>'/files/'.$filename,
'preview_url'=>'/files/'.$filename,
'title'=>'Landing Page - ' . substr($topic, 0, 50),
'topic'=>$topic,
'size_kb'=>round(filesize($outpath)/1024, 1),
'lines'=>substr_count($html, "\n"),
]);