Siteβ―Builder
Editing:
addbusiness.php
writable 0666
<?php // ---- SET THIS TO YOUR GOOGLE API KEY ---- $GOOGLE_PLACES_API_KEY = 'AIzaSyBRHLCq9BMH2LWzuYeOLjYV3SPgH7APcao'; // ----------------------------------------- // Returns US state abbreviation by lat/lon using your state-bounds.json function get_state_by_latlon($lat, $lon) { $bounds_file = $_SERVER['DOCUMENT_ROOT'] . '/geo/json-data/states-bounds.json'; if (!file_exists($bounds_file)) return ''; $bounds_data = json_decode(file_get_contents($bounds_file), true); foreach($bounds_data as $b) { if ($lat >= $b['minLat'] && $lat <= $b['maxLat'] && $lon >= $b['minLon'] && $lon <= $b['maxLon']) return $b['state']; } return ''; } // AJAX endpoint: Lookup phone with Google Places API if (isset($_GET['ajax']) && $_GET['ajax']==='lookup' && isset($_GET['phone'])) { $phone = preg_replace('/\D/', '', $_GET['phone']); $phone = strlen($phone) === 10 ? "+1".$phone : $phone; $fields = "formatted_address,name,place_id,geometry,types,website,formatted_phone_number"; $url = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=" . urlencode($phone) . "&inputtype=phonenumber&fields=$fields&key=$GOOGLE_PLACES_API_KEY"; $resp = json_decode(file_get_contents($url), true); if (!empty($resp['candidates'][0])) { $c = $resp['candidates'][0]; echo json_encode([ 'found' => true, 'name' => $c['name'] ?? '', 'address' => $c['formatted_address'] ?? '', 'website' => $c['website'] ?? '', 'phone' => $c['formatted_phone_number'] ?? $_GET['phone'], 'lat' => $c['geometry']['location']['lat'] ?? '', 'lon' => $c['geometry']['location']['lng'] ?? '', ]); } else { echo json_encode(['found'=>false]); } exit; } // Handle business submission $msg = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['phone'])) { $data = [ 'name' => trim($_POST['name']), 'slogan' => trim($_POST['slogan']), 'description' => trim($_POST['description']), 'address' => trim($_POST['address']), 'city' => trim($_POST['city']), 'state' => trim($_POST['state']), 'zip' => trim($_POST['zip']), 'phone' => preg_replace('/\D/', '', $_POST['phone']), 'website' => trim($_POST['website']), 'tags' => array_filter(array_map('trim', explode(',', $_POST['tags']))), 'location_tags' => array_filter(array_map('trim', explode(',', $_POST['location_tags'] ?? ''))) ]; $phone10 = substr($data['phone'],-10); if (strlen($phone10) !== 10) $msg = "Phone must be 10 digits!"; else { $dir = $_SERVER['DOCUMENT_ROOT'] . "/ph/$phone10"; if (!is_dir($dir)) mkdir($dir, 0777, true); $file = $dir . "/new-business.json"; file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); // Generate index.php (simple card) $index = $dir . "/index.php"; $html = "<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'><title>{$data['name']} | BestDealOn</title> <meta name='viewport' content='width=device-width,initial-scale=1'><style> body{font-family:sans-serif;background:#f5f8fb;color:#1b334a;} .card{max-width:500px;margin:2em auto;background:#fff;border-radius:16px;box-shadow:0 2px 18px #dde3fa33;padding:2em 1.4em;} h1{color:#284dd7;} .info{margin:1.1em 0;color:#365983;} .footer{text-align:center;margin:2em 0 0 0;color:#888;} </style></head><body> <div class='card'><h1>".htmlspecialchars($data['name'])."</h1> <div class='info'>".htmlspecialchars($data['address'])."<br>" . htmlspecialchars($data['city']).", ".htmlspecialchars($data['state'])." ".htmlspecialchars($data['zip'])."<br>" . htmlspecialchars($data['phone'])."</div> <div class='info'>".htmlspecialchars($data['description'])."</div> ".($data['website'] ? "<div class='info'><a href='".htmlspecialchars($data['website'])."'>".htmlspecialchars($data['website'])."</a></div>":"")." </div> <div class='footer'>Business page auto-generated by BestDealOn.com</div> </body></html>"; file_put_contents($index, $html); $msg = "β Business added! <a href='/ph/$phone10/'>View page</a>"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Add Your Business | BestDealOn</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="robots" content="noindex,follow"> <style> body {background:#f5f8fb;font-family:system-ui,Arial,sans-serif;margin:0;color:#234;} h1 {text-align:center;color:#2257a2;} .wrap {max-width:520px;margin:2.7em auto;background:#fff;padding:2em 2em 2em 2em;border-radius:17px;box-shadow:0 2px 18px #dde3fa33;} .cta {background:#ecfbf1;border-radius:10px;padding:1em 1.1em;margin-bottom:2em;font-size:1.08em;color:#175e35;text-align:center;} input[type=text],input[type=tel],textarea,select { width:100%;padding:.7em;border-radius:7px;border:1.4px solid #b7c2df;margin-bottom:1.13em;font-size:1.08em;} input[type=submit],button {padding:.7em 1.4em;font-size:1.1em;font-weight:700;background:#2357d7;color:#fff;border:none;border-radius:8px;cursor:pointer;} input[type=submit]:hover,button:hover {background:#0a3798;} .lab {font-weight:600;margin-bottom:.2em;display:block;} .msg {text-align:center;margin-bottom:1.4em;font-size:1.07em;} #lookup-btn {margin-bottom:1.2em;} @media (max-width:600px){.wrap{padding:1em .1em 1em .1em;max-width:99vw;}} </style> <script> let userLat = '', userLon = '', userState = '', userCity = ''; function locateMe() { if (!navigator.geolocation) { alert("Geolocation not supported."); return; } document.getElementById('geo-status').textContent = "Locating..."; navigator.geolocation.getCurrentPosition(function(pos) { userLat = pos.coords.latitude; userLon = pos.coords.longitude; fetch('/geo/json-data/states-bounds.json').then(r=>r.json()).then(bounds=>{ let st = ''; bounds.forEach(function(b){ if (userLat >= b.minLat && userLat <= b.maxLat && userLon >= b.minLon && userLon <= b.maxLon) st=b.state; }); if(st) { userState = st; document.getElementById('state').value = st; document.getElementById('geo-status').textContent = "State detected: "+st+"."; } else { document.getElementById('geo-status').textContent = "Not in USA/States."; } }); // City detection (optional): Here you can use a reverse geocode API if you want to auto-fill city }, function(){ document.getElementById('geo-status').textContent = "Failed."; }); } function lookupPhone() { let phone = document.getElementById('phone').value.replace(/\D/g,''); if(phone.length!==10){ alert('Enter a 10-digit phone number'); return; } document.getElementById('lookup-btn').disabled = true; document.getElementById('lookup-btn').textContent = "Looking up..."; fetch('?ajax=lookup&phone='+phone) .then(r=>r.json()) .then(data=>{ document.getElementById('lookup-btn').disabled = false; document.getElementById('lookup-btn').textContent = "Lookup Business by Phone"; if(data.found){ document.getElementById('name').value = data.name; document.getElementById('address').value = data.address; document.getElementById('website').value = data.website; document.getElementById('phone').value = data.phone.replace(/\D/g,''); document.getElementById('lat').value = data.lat; document.getElementById('lon').value = data.lon; document.getElementById('result-info').textContent = "Business found! Please complete missing info and submit."; } else { document.getElementById('result-info').textContent = "No business found, please fill in manually."; } }); } </script> </head> <body> <div class="wrap"> <h1>Add Your Business</h1> <div class="cta"> π Congratulations on growing your business! <br> Add your business to <b>BestDealOn</b> and get discovered by customers in your city and state. <br> <button type="button" onclick="locateMe()">π Detect My Location</button> <span id="geo-status" style="margin-left:1em;color:#1a61aa;"></span> </div> <?php if($msg): ?><div class="msg" style="color:<?=strpos($msg,'β ')!==false?'green':'red'?>"><?= $msg ?></div><?php endif; ?> <form method="post" autocomplete="off"> <label class="lab" for="phone">Business Phone (10 digits)</label> <input type="tel" id="phone" name="phone" pattern="\d{10}" maxlength="10" required placeholder="e.g. 7276101188"> <button type="button" id="lookup-btn" onclick="lookupPhone()">Lookup Business by Phone</button> <span id="result-info" style="display:block;margin:.4em 0 1em 0;color:#176e34;"></span> <input type="hidden" name="lat" id="lat"><input type="hidden" name="lon" id="lon"> <label class="lab" for="name">Business Name</label> <input type="text" id="name" name="name" maxlength="80" required> <label class="lab" for="slogan">Slogan (optional)</label> <input type="text" id="slogan" name="slogan" maxlength="120"> <label class="lab" for="description">Description</label> <textarea id="description" name="description" maxlength="500" required></textarea> <label class="lab" for="address">Street Address</label> <input type="text" id="address" name="address" maxlength="120" required> <label class="lab" for="city">City</label> <input type="text" id="city" name="city" maxlength="40" required> <label class="lab" for="state">State (2-letter code)</label> <input type="text" id="state" name="state" maxlength="2" required> <label class="lab" for="zip">ZIP Code</label> <input type="text" id="zip" name="zip" maxlength="12" required> <label class="lab" for="website">Website (optional)</label> <input type="text" id="website" name="website" maxlength="120"> <label class="lab" for="tags">Business Tags (comma separated)</label> <input type="text" id="tags" name="tags" maxlength="120" placeholder="e.g. Restaurant, Pizza, Delivery"> <label class="lab" for="location_tags">Location Tags (city, state, zip, comma separated)</label> <input type="text" id="location_tags" name="location_tags" maxlength="120" placeholder="e.g. Seminole, FL, 33772"> <input type="submit" value="Add My Business π"> </form> </div> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel