Siteβ―Builder
Editing:
ai-guide.php
writable 0666
<?php // --------- Get all states and categories for selectors ---------- $stateFile = $_SERVER['DOCUMENT_ROOT'].'/geo/json-data/states-bounds.json'; $catFile = $_SERVER['DOCUMENT_ROOT'].'/geo/allcategories.json'; $states = file_exists($stateFile) ? json_decode(file_get_contents($stateFile), true) : []; $categories = file_exists($catFile) ? json_decode(file_get_contents($catFile), true) : []; $letters = range('A','Z'); // Build a flat list of all categories for autocomplete $allCats = []; foreach($categories as $catlist) foreach($catlist as $row) $allCats[] = $row['name']; sort($allCats); $city = isset($_GET['city']) ? preg_replace('/[^A-Za-z0-9\- ]/', '', $_GET['city']) : ''; $state = isset($_GET['state']) ? strtoupper(preg_replace('/[^A-Za-z]/','',$_GET['state'])) : ''; $type = isset($_GET['type']) ? trim($_GET['type']) : ''; $userQ = isset($_GET['q']) ? trim($_GET['q']) : ''; // Prompt file as template $promptFile = $_SERVER['DOCUMENT_ROOT'] . '/geo/pages/cat-location-prompt.txt'; $promptTemplate = is_readable($promptFile) ? file_get_contents($promptFile) : ''; $defaultPrompt = str_replace( ['{type}', '{city}', '{state}'], [$type ?: '[category]', $city ?: '[city]', $state ?: '[state]'], $promptTemplate ); if ($userQ) { $aiPrompt = $defaultPrompt . "\nUser question: $userQ"; } else { $aiPrompt = $defaultPrompt; } $chatGPTurl = "https://chatgpt.com/?prompt=" . urlencode($aiPrompt); // --- Example trending/smart suggestions $exampleQs = []; if ($type && $city) { $exBase = htmlspecialchars($type) . ' in ' . htmlspecialchars($city); $exampleQs = [ "What do locals look for when choosing $type in $city?", "How do I avoid scams when hiring a $type service in $city?", "What are the best questions to ask a $type provider in $city?", "Are there unique local considerations for $type in $city?" ]; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>BestDealOn AI Local Guide | Ask AI About Your Area</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="description" content="Chat with AI about any local business, service or city. Get personalized tips and insights for your area, powered by BestDealOnβs directory and OpenAI."> <style> body { background:#f6faff; font-family:system-ui,Arial,sans-serif; margin:0; color:#203855;} .top { background:#fff; box-shadow:0 2px 14px 0 rgba(40,80,130,.07); padding:1.6em 0 1.3em; text-align:center; } .logo { font-weight:900; font-size:1.3em; letter-spacing:-.5px; color:#5016A8; } .ai-guide { background:#fff; max-width:650px; margin:2.5em auto 1.7em; border-radius:18px; box-shadow:0 2px 14px 0 rgba(70,100,180,.10); padding:2.3em 2.3em 2em 2.3em;} .ai-guide h1 { font-size:2.05em; color:#1274d1; margin-bottom:.7em;} .ai-guide label {font-weight:600;} .row { display:flex; gap:1.2em; margin-bottom:1.2em;} .row > div { flex:1; } input, select, textarea { width:100%; font-size:1.07em; border-radius:8px; border:1px solid #bdd2f7; padding:.65em .7em; margin-top:.17em; } input[type="submit"] { margin-top:.7em; font-weight:700; background:#5b36ff; color:#fff; border:none; transition:background .15s;} input[type="submit"]:hover { background:#3943d2;} .suggests { margin:1.3em 0 1em; } .suggests span { font-weight:600; color:#3570a1;} .suggests a { margin-right:.9em; color:#2a50b8; text-decoration:underline;} .suggests a:hover { color:#e11e9c;} .aimsg { background:#eaf2ff; border:1.3px solid #93bbfa; border-radius:10px; margin:1.8em auto 2.5em auto; padding:1.7em 1.5em 1.35em 1.5em; text-align:center; max-width:650px;} .aimsg .label { color:#2464a8; font-weight:700; font-size:1.09em; margin-bottom:.7em; } .aimsg .prompt-preview { font-family:monospace; background:#f9fafd; border:1px dashed #b9d1fc; color:#1e4158; border-radius:8px; margin:.7em 0 1.1em; padding:.8em 1em; font-size:1em;} .aimsg .gptbtn { display:inline-block; padding:.6em 2em; font-size:1.11em; font-weight:700; color:#fff; background:#1274d1; border-radius:7px; text-decoration:none; margin-top:.6em;} .aimsg .gptbtn:hover { background:#2457b5;} .recentq { margin:1.8em auto 0; max-width:670px; background:#fcf9ea; border:1px solid #eed97d; border-radius:9px; padding:1.2em 1.2em;} .recentq span { color:#bc900b; font-weight:700;} #locate-me-btn {margin-bottom:.5em;font-weight:700;background:#1274d1;color:#fff;padding:.6em 1.8em;border-radius:9px;font-size:1.09em;border:none;cursor:pointer;} #locate-me-btn:disabled {opacity:.55;cursor:progress;} #geo-status {margin-left:.7em;color:#136e43;font-weight:600;} @media (max-width:700px) {.ai-guide, .aimsg, .recentq {max-width:99vw; padding:.7em;} .row {flex-direction:column;gap:.1em;}} </style> </head> <body> <div class="top"> <div class="logo">BEST <span style="color:#00c853">DEAL</span> <span style="color:#ff1744">ON</span> <span style="font-weight:400;color:#999">AI Local Guide</span></div> <div style="color:#5276d1;font-weight:600;margin-top:.33em;">Ask AI about any business, service, or city in America!</div> </div> <div class="ai-guide"> <button id="locate-me-btn">π Use My Location</button> <span id="geo-status"></span> <h1>Ask AI for Local Insights</h1> <form method="get" action=""> <div class="row"> <div> <label for="city">City:</label> <input name="city" id="city" required value="<?= htmlspecialchars($city) ?>" autocomplete="off" placeholder="e.g. Seminole"> </div> <div> <label for="state">State:</label> <select name="state" id="state" required> <option value="">-- Select --</option> <?php foreach($states as $st): ?> <option value="<?= htmlspecialchars($st['state']) ?>"<?= $state==$st['state']?' selected':'' ?>><?= htmlspecialchars($st['name']) ?></option> <?php endforeach; ?> </select> </div> </div> <div class="row"> <div> <label for="type">Business Category/Type:</label> <input list="catlist" name="type" id="type" required value="<?= htmlspecialchars($type) ?>" autocomplete="off" placeholder="e.g. Roofing Materials"> <datalist id="catlist"> <?php foreach($allCats as $cat): ?><option value="<?= htmlspecialchars($cat) ?>"><?php endforeach; ?> </datalist> </div> <div> <label for="q">Your question (optional):</label> <input type="text" name="q" id="q" value="<?= htmlspecialchars($userQ) ?>" placeholder="e.g. How do I pick the best?"> </div> </div> <input type="submit" value="Ask AI"> </form> <?php if ($type && $city && $state): ?> <div class="suggests"><span>Try these:</span> <?php foreach($exampleQs as $q): ?> <a href="?city=<?= urlencode($city) ?>&state=<?= urlencode($state) ?>&type=<?= urlencode($type) ?>&q=<?= urlencode($q) ?>"><?= htmlspecialchars($q) ?></a> <?php endforeach; ?> </div> <?php endif; ?> </div> <?php if ($type && $city && $state): ?> <div class="aimsg"> <div class="label">Your personalized AI prompt:</div> <div class="prompt-preview"><?= nl2br(htmlspecialchars($aiPrompt)) ?></div> <a class="gptbtn" href="<?= htmlspecialchars($chatGPTurl) ?>" target="_blank" rel="noopener">π§ Open in ChatGPT</a> <div style="font-size:.98em;color:#888;margin-top:1.05em;"> (Opens a new tab with this prompt pre-filled in ChatGPT. No login required for ChatGPT 4o/free users.) </div> <div style="margin-top:1.3em;"> <a href="/geo/USA/<?= htmlspecialchars($state) ?>/<?= htmlspecialchars(ucfirst(strtolower(str_replace(' ', '-', $city)))) ?>/business.php?type=<?= urlencode(strtolower(str_replace(' ', '-', $type))) ?>" style="font-size:.99em;color:#236dd2;font-weight:700;text-decoration:underline;">Find <?= htmlspecialchars($type) ?> businesses in <?= htmlspecialchars($city) ?>, <?= htmlspecialchars($state) ?> →</a> </div> </div> <?php endif; ?> <div class="recentq"> <span>Why is this page special?</span> <div style="font-size:.98em;line-height:1.6;margin-top:.6em;"> β’ You can ask AI about *any* business type in *any* city or state in America.<br> β’ Use our smart suggestions, or type your own question!<br> β’ Every prompt is tailored using BestDealOn's directory knowledge and location context.<br> β’ Share the page with friends, or try out different categories instantly.<br> <b>BestDealOn makes next-generation, AI-driven local discovery effortless and fun!</b> </div> </div> <script> const stateBoundsUrl = '/geo/json-data/states-bounds.json'; const getCityUrl = state => '/geo/json-data/' + state + '.json'; document.getElementById('locate-me-btn').onclick = function() { let btn = this, stat = document.getElementById('geo-status'); btn.disabled = true; btn.textContent = 'Detecting...'; stat.textContent = ''; if (!navigator.geolocation) { stat.textContent = 'Geolocation not supported.'; btn.disabled=false; btn.textContent='π Use My Location'; return; } navigator.geolocation.getCurrentPosition(function(pos) { let lat = pos.coords.latitude, lon = pos.coords.longitude; fetch(stateBoundsUrl).then(r=>r.json()).then(bounds=>{ let found = bounds.find(st => lat >= st.minLat && lat <= st.maxLat && lon >= st.minLon && lon <= st.maxLon ); if (!found) { stat.textContent = 'Could not detect your state.'; btn.disabled=false; btn.textContent='π Use My Location'; return; } // Get nearest city in state fetch(getCityUrl(found.state)).then(r=>r.json()).then(cities=>{ let best = null, minDist = 1e9; for (let c of cities) { let d = Math.hypot(lat-c.lat, lon-c.lon); if (d < minDist) { minDist = d; best = c; } } if (best) { document.getElementById('city').value = best.city; document.getElementById('state').value = found.state; stat.textContent = `Detected: ${best.city}, ${found.state}`; btn.textContent = 'β Location Set!'; setTimeout(()=>{btn.textContent='π Use My Location'; btn.disabled=false;}, 1400); } else { stat.textContent = 'No city found in your area.'; btn.disabled=false; btn.textContent='π Use My Location'; } }); }); }, function(err) { stat.textContent = "Location failed: " + err.message; btn.disabled=false; btn.textContent='π Use My Location'; }); }; </script> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel