Site Builder
Editing:
business.php
writable 0666
<?php // --------- Geo and type detection ---------- $uriParts = array_values(array_filter(explode('/', trim($_SERVER['REQUEST_URI'],'/')))); if (count($uriParts) < 4 || $uriParts[0] !== 'geo') { http_response_code(404); exit('Invalid path'); } [$_ , $country, $state, $cityRaw] = $uriParts; $city = urldecode($cityRaw); function pretty_city($slug) { return ucwords(str_replace('-', ' ', $slug)); } function breadcrumb_city_slug($city) { $slug = strtolower(str_replace(' ', '-', $city)); return ucfirst($slug); } $prettyCity = pretty_city($city); $typeRaw = isset($_GET['type']) ? $_GET['type'] : ''; $typeTag = trim(str_replace(['-', '_'], [' ', ' '], $typeRaw)); $typeTag = ucwords(strtolower($typeTag)); $typeUrlSlug = strtolower(str_replace(' ', '-', $typeTag)); // --------- Business data ---------- $citySlug = strtolower(preg_replace('/\s+/', '-', $city)); $jsonFile = __DIR__ . "/{$citySlug}-biz-list.json"; $bizList = is_readable($jsonFile) ? (json_decode(file_get_contents($jsonFile), true) ?: []) : []; // --------- Geo position meta from location.txt --------- $lat = $lon = ''; $locFile = __DIR__ . "/location.txt"; if (is_readable($locFile)) { [$lat, $lon] = preg_split('/[ ,]+/', trim(file_get_contents($locFile))) + ['', '']; } // --------- Find matching businesses for this tag (case-insensitive) $matches = []; if ($bizList && $typeTag) { foreach ($bizList as $biz) { $tags = array_map('strtolower', $biz['tags'] ?? []); if (in_array(strtolower($typeTag), $tags)) $matches[] = $biz; } } $canonicalBase = 'https://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']); $canonicalPath = rtrim($canonicalBase, '/\\') . '/business.php?type=' . urlencode(strtolower($typeTag)); // --------- SEO/Meta variables ---------- $ad_headline = "$typeTag in $prettyCity, $state"; $categoryDesc = "Discover the best $typeTag, local favorites, and top-rated businesses in $prettyCity, $state. Whether you’re a resident or just passing through, our directory brings you the leading $typeTag options near you."; $ad_blurb = "<strong>Want to get noticed by $prettyCity $typeTag seekers?</strong> Showcase your $typeTag business at the top of this page and reach customers who are searching for you. <a href='/advertise.php?geo=".urlencode("{$citySlug}-{$state}-advertising")."&type=".urlencode($typeTag)."'>Start here</a> to claim your featured spot!"; $extra_keywords = strtolower($typeTag . ", $prettyCity, $state, advertising, marketing, directory, " . $typeTag . " in $prettyCity, " . $typeTag . " in $state"); $pageTitle = "$typeTag in $prettyCity, $state | BestDealOn Directory"; $pageDesc = "Find, compare, and advertise $typeTag in $prettyCity, $state. Connect with local customers searching for $typeTag, and promote your business in our city directory."; $og_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // --------- Suggestion box for other searches ---------- function search_prompt($type, $city, $state) { $q = trim($type . ' in ' . $city . ', ' . $state); return preg_replace('/\s+/', ' ', $q); } $searchPrompt = search_prompt($typeTag, $prettyCity, $state); $searchUrl = [ "Google" => "https://www.google.com/search?q=" . urlencode($searchPrompt), "MSN" => "https://www.bing.com/search?q=" . urlencode($searchPrompt), "Yahoo" => "https://search.yahoo.com/search?p=" . urlencode($searchPrompt), "ChatGPT"=> "https://chatgpt.com/?prompt=" . urlencode($searchPrompt) ]; function local_deals_box($searchPrompt, $searchUrl) { return ' <div style="background:#fffbe9;border:1.5px solid #f5c867;border-radius:10px;max-width:400px; margin:2em auto 2em auto;padding:1.2em 1.1em;text-align:center;box-shadow:0 2px 10px 0 rgba(200,150,50,0.06);"> <div style="font-size:1.12em;font-weight:700;color:#c78c15;margin-bottom:.5em;"> Look for more local deals on: </div> <div style="display:flex;justify-content:center;gap:.7em;flex-wrap:wrap;"> <a href="'.$searchUrl['Google'].'" target="_blank" rel="noopener" style="color:#1965d3;font-weight:600;text-decoration:none;">Try Google</a> <a href="'.$searchUrl['MSN'].'" target="_blank" rel="noopener" style="color:#177b3b;font-weight:600;text-decoration:none;">Try MSN</a> <a href="'.$searchUrl['Yahoo'].'" target="_blank" rel="noopener" style="color:#8800b2;font-weight:600;text-decoration:none;">Try Yahoo</a> <a href="'.$searchUrl['ChatGPT'].'" target="_blank" rel="noopener" style="color:#0a7ca9;font-weight:600;text-decoration:none;">Try ChatGPT</a> </div> <div style="margin-top:.7em;font-size:.97em;color:#bba242;"> <span>Search: </span> <span style="color:#444">'.htmlspecialchars($searchPrompt).'</span> </div> </div> '; } // --- Suggested Categories --- $relatedCats = []; $allCatFile = $_SERVER['DOCUMENT_ROOT'] . '/geo/allcategories.json'; if (file_exists($allCatFile)) { $allcats = json_decode(file_get_contents($allCatFile), true) ?: []; $words = array_filter( preg_split('/\s+/', strtolower($typeTag)), function($w){ return strlen($w) > 2; } ); $firstLetter = strtoupper($typeTag[0]); $related = isset($allcats[$firstLetter]) ? $allcats[$firstLetter] : []; $found = []; foreach($related as $row) { $name = $row['name']; $name_lc = strtolower($name); if (strcasecmp($name, $typeTag) === 0) continue; foreach($words as $w) { if ($w && strpos($name_lc, $w)!==false) { $found[$name] = true; break; } } } $relatedCats = array_keys($found); natcasesort($relatedCats); $relatedCats = array_slice($relatedCats,0,18); } // Optional: suggest other categories $topCategories = [ "Restaurants", "Home Services", "Real Estate", "Automotive", "Lawyers", "Dentists", "Plumbers", "HVAC", "Roofing", "Landscaping", "Electricians", "Insurance", "Medical", "Gyms", "Contractors" ]; // --------- Load AI prompt from ABSOLUTE path --------- $promptFile = $_SERVER['DOCUMENT_ROOT'] . '/geo/pages/cat-location-prompt.txt'; $promptTemplate = is_readable($promptFile) ? file_get_contents($promptFile) : ''; $aiPrompt = str_replace( ['{type}', '{city}', '{state}'], [$typeTag, $prettyCity, $state], $promptTemplate ); $chatGPTurl = "https://chatgpt.com/?prompt=" . urlencode($aiPrompt); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title><?= htmlspecialchars($pageTitle) ?></title> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="description" content="<?= htmlspecialchars($pageDesc) ?>"> <meta name="keywords" content="<?= htmlspecialchars($extra_keywords) ?>"> <link rel="canonical" href="<?= htmlspecialchars($canonicalPath) ?>" /> <meta property="og:title" content="<?= htmlspecialchars($pageTitle) ?>"> <meta property="og:description" content="<?= htmlspecialchars($pageDesc) ?>"> <meta property="og:type" content="website"> <meta property="og:locale" content="en_US"> <meta property="og:url" content="<?= htmlspecialchars($og_url) ?>"> <meta name="geo.placename" content="<?= htmlspecialchars("$prettyCity, $state") ?>"> <meta name="geo.region" content="<?= htmlspecialchars("US-$state") ?>"> <?php if($lat && $lon): ?> <meta name="geo.position" content="<?= htmlspecialchars("$lat;$lon") ?>"> <meta name="ICBM" content="<?= htmlspecialchars("$lat, $lon") ?>"> <meta property="og:latitude" content="<?= htmlspecialchars($lat) ?>"> <meta property="og:longitude" content="<?= htmlspecialchars($lon) ?>"> <?php endif; ?> <style> body { background:#f5f8fb; font-family:system-ui,Arial,sans-serif; margin:0; color:#273549;} .top-bar{display:flex;justify-content:space-between;align-items:center;background:#eee;padding:.5rem 1rem;font-size:.875rem;} .logo{font-weight:900;letter-spacing:-.5px;text-decoration:none;line-height:1;} .logo span{display:inline-block;white-space:pre;} .logo .b{color:#551A8B;} .logo .d{color:#00c853;} .logo .o{color:#ff1744;} nav.breadcrumb a{color:#0366d6;text-decoration:none;} nav.breadcrumb span{margin:0 .25rem;} .biz-blurb { background:#f4f7ff; border-radius:16px; max-width:700px; margin:2.5rem auto 2rem; padding:2rem 2.2rem 1.7rem 2.2rem; box-shadow:0 2px 12px 0 rgba(48,65,105,.08); border:1.5px solid #e6e8fa; } .biz-blurb h1 { color:#3759be; font-size:1.45rem; margin-bottom:.65rem; } .biz-blurb strong { color:#294; } .biz-blurb ul { margin:1em 0 .5em 1.5em; padding:0; } .biz-blurb li { margin-bottom:.36em; color:#314a6b; line-height:1.5;} .biz-blurb .cta-link { font-weight:700; color:#5b36ff; text-decoration:underline; } .biz-blurb .cta-link:hover { color:#3943d2;} .biz-card {background:#fff;border-radius:12px;box-shadow:0 1px 7px 0 rgba(100,105,135,.09);padding:1.1em 1.2em 1.2em 1.2em;max-width:680px;margin:1.8em auto 1em;} .biz-card h2 { margin:.3em 0 .2em 0; color:#3943d2; font-size:1.15rem;} .biz-card .biz-meta { color:#444; font-size:.95em; margin-bottom:.3em;} .tags {display:flex;flex-wrap:wrap;gap:.5rem;margin-top:.5rem;} .tags a.tag {background:#5b36ff;color:#fff;padding:.25rem .6rem;font-size:.75rem;border-radius:.5rem;text-decoration:none;cursor:pointer;} .tags a.tag:hover { background: #3943d2;} .related-cats { margin:2.1em auto 1.4em auto; background:#fafdfe; border:1.2px solid #c6dcfd; border-radius:10px; padding:1.1em 1.4em; max-width:680px; } .related-cats-title { color:#236dd2; font-size:1.13em; font-weight:700; margin-bottom:.7em; } .related-cats-links { display:flex; flex-wrap:wrap; gap:1em 2.2em; } .related-cats-links a { color:#285ca5; text-decoration:underline; font-size:1.08em; } .related-cats-links a:hover { color:#e11e9c;} @media (max-width: 600px) {.biz-blurb { max-width:99vw; padding:1em; } .biz-card { max-width:99vw; padding:.7em; } } </style> </head> <body> <!-- HEADER with LOGO and BREADCRUMB --> <div class="top-bar"> <a class="logo" href="/"><span class="b">BEST </span><span class="d">DEAL </span><span class="o">ON</span></a> <nav class="breadcrumb" aria-label="Breadcrumb"> <a href="/">Index</a><span>/</span> <a href="/geo/<?= htmlspecialchars($country) ?>/<?= htmlspecialchars($state) ?>/"><?= htmlspecialchars($state) ?></a><span>/</span> <a href="/geo/<?= htmlspecialchars($country) ?>/<?= htmlspecialchars($state) ?>/<?= breadcrumb_city_slug($prettyCity) ?>/"> <?= htmlspecialchars($prettyCity) ?> </a><span>/</span> <span><?= htmlspecialchars($typeTag) ?></span> </nav> </div> <?php // 1st business (if any) always at top $first = null; if ($matches) { $first = array_shift($matches); ?> <div class="biz-card"> <h2><?= htmlspecialchars($first['name']) ?></h2> <?php if(!empty($first['slogan'])): ?><div class="biz-meta"><?= htmlspecialchars($first['slogan']) ?></div><?php endif; ?> <div class="biz-meta"> <?= htmlspecialchars($first['address'] ?? '') ?><br> <?= htmlspecialchars($first['city'] ?? '') ?>, <?= htmlspecialchars($first['state'] ?? '') ?> <?= htmlspecialchars($first['zip'] ?? '') ?><br> <?php if(!empty($first['phone'])): ?><a href="tel:<?= htmlspecialchars($first['phone']) ?>"><?= htmlspecialchars($first['phone']) ?></a><?php endif; ?> <?php if(!empty($first['website'])): ?> | <a href="<?= htmlspecialchars($first['website']) ?>" target="_blank" rel="noopener">Website</a><?php endif; ?> </div> <div><?= htmlspecialchars($first['description'] ?? '') ?></div> <?php if(!empty($first['tags'])): ?> <div class="tags"> <?php foreach($first['tags'] as $t): $tagSlug = strtolower(str_replace([' ', '_'], '-', $t)); $tagLink = "business.php?type=" . urlencode($tagSlug); $seoTitle = "See all " . htmlspecialchars($t) . " businesses in " . htmlspecialchars($prettyCity) . ", " . htmlspecialchars($state); ?> <a class="tag" href="<?= htmlspecialchars($tagLink) ?>" title="<?= $seoTitle ?>"><?= htmlspecialchars($t) ?></a> <?php endforeach; ?> </div> <?php endif; ?> </div> <?php } ?> <!-- Show deals/search engines + AI block (ALWAYS under first business, or at top if no businesses) --> <?= local_deals_box($searchPrompt, $searchUrl) ?> <!-- AI-powered ChatGPT prompt block (from template file) --> <div style="background:#eaf2ff;border:1.5px solid #93bbfa;border-radius:10px;max-width:630px;margin:2em auto 2em auto;padding:1.45em 1.4em 1.2em 1.4em;text-align:center;box-shadow:0 2px 10px 0 rgba(40,100,180,0.06);"> <div style="font-size:1.18em;font-weight:700;color:#2b51a2;margin-bottom:.6em;"> <span style="color:#1274d1;">💡 Discover AI‑powered local insights</span> </div> <div style="font-size:1.08em;line-height:1.5;color:#16355a;margin-bottom:1.15em;"> Want instant, expert advice for <strong><?= htmlspecialchars($typeTag) ?> in <?= htmlspecialchars($prettyCity) ?>, <?= htmlspecialchars($state) ?></strong>?<br> Click below to instantly prompt <strong>OpenAI ChatGPT</strong> for smart local tips, must‑ask questions, what to watch for, and how to get the best deal.<br> <span style="color:#6b8cd6;">BestDealOn is the first directory to empower you with next‑generation intelligence for your real‑world decisions.</span> </div> <a href="<?= htmlspecialchars($chatGPTurl) ?>" target="_blank" rel="noopener" style="display:inline-block;padding:.65em 2.1em;font-size:1.16em;font-weight:700;color:#fff;background:#1274d1;border-radius:7px;text-decoration:none;box-shadow:0 2px 8px #aebfff22;transition:background .15s;"> 🧠 Get Local Tips from ChatGPT </a> <div style="font-size:.98em;color:#888;margin-top:.95em;"> (No login required for ChatGPT 4o/free users. New tab opens to a ready‑to‑use local prompt.) </div> </div> <!-- AD SALES PITCH BLOCK ALWAYS AFTER FIRST BUSINESS --> <div class="biz-blurb"> <h1><?= htmlspecialchars($ad_headline) ?></h1> <p><?= htmlspecialchars($categoryDesc) ?></p> <p><?= $ad_blurb ?></p> <ul> <li>Find <?= htmlspecialchars($typeTag) ?> in <?= htmlspecialchars($prettyCity) ?>, <?= htmlspecialchars($state) ?></li> <li>Advertise <?= htmlspecialchars($typeTag) ?> services in <?= htmlspecialchars($prettyCity) ?>, <?= htmlspecialchars($state) ?></li> <li>See top <?= htmlspecialchars($typeTag) ?> businesses near you</li> <li><a class="cta-link" href="/advertise.php?geo=<?= urlencode("{$citySlug}-{$state}-advertising") ?>&type=<?= urlencode($typeTag) ?>">Get listed or claim this spot!</a></li> </ul> <?php if ($first || $matches): ?> <div style="font-size:1.11em;color:#273549;font-weight:600;margin-top:1.3em;">Featured <?= htmlspecialchars($typeTag) ?> Businesses in <?= htmlspecialchars($prettyCity) ?>, <?= htmlspecialchars($state) ?>:</div> <?php elseif (empty($matches)): ?> <div style="font-size:1.05em;color:#e27c00;font-weight:600;margin-top:1.3em;"> No <?= htmlspecialchars($typeTag) ?> businesses listed in <?= htmlspecialchars($prettyCity) ?>, <?= htmlspecialchars($state) ?> yet. <a class="cta-link" href="/advertise.php?geo=<?= urlencode("{$citySlug}-{$state}-advertising") ?>&type=<?= urlencode($typeTag) ?>">Be the first to advertise <?= htmlspecialchars($typeTag) ?> here!</a> </div> <?php endif; ?> </div> <!-- SUGGESTED CATEGORIES BLOCK --> <div class="related-cats"> <div class="related-cats-title">Suggested Categories:</div> <div class="related-cats-links"> <?php if ($relatedCats): foreach($relatedCats as $cat): $slug = strtolower(trim(preg_replace('/[^a-z0-9]+/i', '-', $cat), '-')); ?> <a href="business.php?type=<?= urlencode($slug) ?>"><?= htmlspecialchars($cat) ?></a> <?php endforeach; else: ?> <span style="color:#c12d2d">No related categories found.</span> <?php endif; ?> </div> </div> <?php // Remaining businesses foreach ($matches as $biz): ?> <div class="biz-card"> <h2><?= htmlspecialchars($biz['name']) ?></h2> <?php if(!empty($biz['slogan'])): ?><div class="biz-meta"><?= htmlspecialchars($biz['slogan']) ?></div><?php endif; ?> <div class="biz-meta"> <?= htmlspecialchars($biz['address'] ?? '') ?><br> <?= htmlspecialchars($biz['city'] ?? '') ?>, <?= htmlspecialchars($biz['state'] ?? '') ?> <?= htmlspecialchars($biz['zip'] ?? '') ?><br> <?php if(!empty($biz['phone'])): ?><a href="tel:<?= htmlspecialchars($biz['phone']) ?>"><?= htmlspecialchars($biz['phone']) ?></a><?php endif; ?> <?php if(!empty($biz['website'])): ?> | <a href="<?= htmlspecialchars($biz['website']) ?>" target="_blank" rel="noopener">Website</a><?php endif; ?> </div> <div><?= htmlspecialchars($biz['description'] ?? '') ?></div> <?php if(!empty($biz['tags'])): ?> <div class="tags"> <?php foreach($biz['tags'] as $t): $tagSlug = strtolower(str_replace([' ', '_'], '-', $t)); $tagLink = "business.php?type=" . urlencode($tagSlug); $seoTitle = "See all " . htmlspecialchars($t) . " businesses in " . htmlspecialchars($prettyCity) . ", " . htmlspecialchars($state); ?> <a class="tag" href="<?= htmlspecialchars($tagLink) ?>" title="<?= $seoTitle ?>"><?= htmlspecialchars($t) ?></a> <?php endforeach; ?> </div> <?php endif; ?> </div> <?php endforeach; ?> <!-- ALWAYS: CATEGORIES, OTHER LOCAL SERVICES, AND DEALS BOX AT THE BOTTOM --> <div class="biz-blurb" style="background:#f6fbff;margin-top:2em;"> <div style="margin-bottom:1em;"> <a href="/geo/categories.php?country=<?= urlencode($country) ?>&state=<?= urlencode($state) ?>&city=<?= urlencode($prettyCity) ?>" style="font-weight:700;color:#3e60c7;text-decoration:underline;font-size:1.07em;"> ← View All Categories </a> </div> <div style="font-size:1.09em;margin-bottom:.7em;">Looking for other local services?</div> <ul> <?php foreach($topCategories as $cat): if (strcasecmp($cat, $typeTag) == 0) continue; $catSlug = strtolower(str_replace(' ', '-', $cat)); ?> <li> <a href="business.php?type=<?= urlencode($catSlug) ?>" title="See all <?= htmlspecialchars($cat) ?> businesses in <?= htmlspecialchars($prettyCity) ?>, <?= htmlspecialchars($state) ?>"> <?= htmlspecialchars($cat) ?> in <?= htmlspecialchars($prettyCity) ?>, <?= htmlspecialchars($state) ?> </a> </li> <?php endforeach; ?> </ul> </div> <!-- Always show the deals box at very bottom --> <?= local_deals_box($searchPrompt, $searchUrl) ?> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel