Site Builder
Editing:
indexoookkkkk.php
writable 0666
<?php // ----------- 1. Load and merge phone numbers from query and cookie (robust, no wipe bug) ----------- $biznums = []; if (isset($_GET['ph'])) { $ph_string = preg_replace('/[^\d\-]/', '', $_GET['ph']); $incoming = array_values(array_filter(explode('-', $ph_string), function($n){ return preg_match('/^\d{10}$/', $n); })); if ( count($incoming) === 1 && isset($_COOKIE['mybizlist']) && strlen(trim($_COOKIE['mybizlist'])) > 0 ) { $cookie_biznums = array_values(array_filter(explode('-', $_COOKIE['mybizlist']), function($n){ return preg_match('/^\d{10}$/', $n); })); if (in_array($incoming[0], $cookie_biznums) && count($cookie_biznums) > 0) { // Already in list—ignore URL param, just use cookie $biznums = $cookie_biznums; } elseif (!in_array($incoming[0], $cookie_biznums) && count($cookie_biznums) > 0) { // Not in list—merge and redirect $merged = $cookie_biznums; $merged[] = $incoming[0]; $merged = array_unique($merged); header("Location: /my-list/?ph=" . implode('-', $merged)); exit; } else { // Fallback, just use the one number $biznums = $incoming; } } else { $biznums = $incoming; } } elseif (isset($_COOKIE['mybizlist'])) { $biznums = array_values(array_filter(explode('-', $_COOKIE['mybizlist']), function($n){ return preg_match('/^\d{10}$/', $n); })); } $biznums = array_values(array_unique($biznums)); // ----------- 2. Keep cookie in sync ----------- if (count($biznums)) setcookie('mybizlist', implode('-', $biznums), time()+60*60*24*30, '/'); // ----------- 3. Load business data ----------- $businesses = []; foreach ($biznums as $ph) { $bizfile = __DIR__ . "/../ph/$ph/business.json"; if (is_readable($bizfile)) { $businesses[$ph] = json_decode(file_get_contents($bizfile), true); $businesses[$ph]['ph'] = $ph; } } // ----------- 4. All tags for filtering ----------- $all_tags = []; foreach ($businesses as $b) if (!empty($b['tags']) && is_array($b['tags'])) $all_tags = array_merge($all_tags, $b['tags']); $all_tags = array_unique($all_tags); sort($all_tags); function format_phone($n) { $n = preg_replace('/\D/', '', $n); return strlen($n)===10 ? "(".substr($n,0,3).") ".substr($n,3,3)."-".substr($n,6) : $n; } function badge($paid) { return $paid ? '<span class="badge premium">Premium</span>' : '<span class="badge free">Free</span>'; } $query_url = '/my-list/'; if ($biznums) $query_url .= '?ph=' . implode('-', $biznums); $full_compare_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$query_url"; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Compare Businesses | BestDealOn</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <style> body {font-family:system-ui,Arial,sans-serif; margin:0; background:#f6fafd; color:#193050;} .top-bar { display:flex; align-items:center; background:#eef4fa; padding:.77em 1.2em .77em 1em; box-shadow:0 1px 8px #d3e9ff24; border-bottom:1.5px solid #e2eefd; margin-bottom:.5em; } .logo{font-weight:900;letter-spacing:-.5px;text-decoration:none;line-height:1;font-size:1.27em;} .logo .b{color:#551A8B;} .logo .d{color:#00c853;} .logo .o{color:#ff1744;} .breadcrumb a{color:#0366d6;text-decoration:none;} .breadcrumb span{margin:0 .25em;} .add-biz-btn { margin-left:auto; background:#1c90f3; color:#fff; font-weight:600; font-size:.99em; padding:.63em 1.6em; border-radius:7px; text-decoration:none; box-shadow:0 1px 5px #d3e9ff70; transition:.13s; } .add-biz-btn:hover { background:#156bc1;} @media (max-width:600px){ .top-bar {flex-direction:column; gap:.4em;} .add-biz-btn {margin-left:0;margin-top:.7em;} } h1{margin:1.15em 0 .4em .7em;font-size:1.41em;} .grid-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 2em; max-width: 1400px; margin: 1.6em auto 1.6em auto; padding: 0 1em; } .compare-card { background:#fff; border-radius:22px; box-shadow:0 2px 16px #dde3fa26; padding:1.7em 1.3em; position:relative; transition:.16s; margin-bottom:1.2em;} .compare-card .remove-x { position:absolute; top:13px; right:18px; color:#e8513f; font-size:1.35em; font-weight:bold; cursor:pointer; background:rgba(245,245,245,.7); border-radius:99px; padding:.13em .47em .09em .47em; border:1.2px solid #f1dad6; transition:.15s; } .compare-card .remove-x:hover { background:#ffeaeb; } .tags {margin:.8em 0 0 0;} .tag {display:inline-block; background:#e5f0fd; color:#0d3e7e; border-radius:15px; padding:.13em .78em; margin:0 .10em .16em 0; font-size:.98em;} .badge {font-size:.96em;font-weight:600;padding:.15em .75em .19em .75em;border-radius:2em;margin-left:.9em;vertical-align:middle;} .badge.free {background:#e7f3fa;color:#146b90;border:1.3px solid #b5d5e6;} .badge.premium {background:#fdf2d8;color:#a25e0b;border:1.3px solid #eed399;} .show-more-link {margin-left:.4em;font-size:.99em;text-decoration:underline;color:#2585b4;cursor:pointer;} .sortbar {margin:1.1em auto 0 1.1em;display:flex;max-width:380px;} .sortbar select{font-size:1em;padding:.44em 1.1em;border-radius:7px;border:1.5px solid #dde3fa;} .copy-link-row {margin:1.6em auto 1.5em auto; text-align:center;} .copy-link-btn {background:#2e9ee4;color:#fff;font-weight:700;font-size:1.1em;padding:.8em 2.2em;border-radius:10px;border:none;cursor:pointer;box-shadow:0 1px 7px #c8e1ff44;} .copy-link-btn:hover {background:#1b7bc1;} #copied-msg {display:none;color:#268030;font-weight:600;margin-left:1.3em;} .footer {text-align:center;font-size:.97em;color:#688; margin:3em 0 1em 0;} .footer a{color:#0366d6;} @media (max-width:900px) { .grid-row{grid-template-columns:1fr;} .compare-card{min-width:96vw;max-width:99vw;} } </style> </head> <body> <!-- HEADER & NAV --> <div class="top-bar"> <a class="logo" href="/geo/"> <span class="b">BEST </span><span class="d">DEAL </span><span class="o">ON</span> </a> <nav class="breadcrumb" aria-label="Breadcrumb" style="display:inline-block;margin-left:1.7em;"> <a href="/geo/">Home</a> <span>/</span> <span style="color:#193050;font-weight:600;">My List</span> </nav> <a href="/geo/" class="add-biz-btn">+ Add a Business</a> </div> <div class="sortbar"> <select id="tagFilter"> <option value="">Filter by Tag</option> <?php foreach($all_tags as $t): ?> <option value="<?= htmlspecialchars($t) ?>"><?= htmlspecialchars($t) ?></option> <?php endforeach; ?> </select> </div> <div class="copy-link-row"> <button class="copy-link-btn" onclick="copyLink()"> 📋 Copy Link to This List </button> <span id="copied-msg">Copied!</span> <div style="font-size:.98em;color:#333;margin-top:.38em;"> Bookmark or share this list: <span id="compareUrl"><?= htmlspecialchars($full_compare_url) ?></span> </div> </div> <?php if (empty($businesses)): ?> <p style='color:red;font-size:1.13em;text-align:center;'>No business data found for your selection.<br>Try adding businesses to your compare list from a business profile page.</p> <?php endif; ?> <div class="grid-row" id="compareRow"> <?php foreach ($businesses as $b): ?> <?php $paid = is_readable(__DIR__ . "/../ph/{$b['ph']}/business.json"); $profileUrl = "/ph/{$b['ph']}/"; ?> <div class="compare-card" data-ph="<?= htmlspecialchars($b['ph']) ?>"> <span class="remove-x" title="Remove from list" onclick="removeBiz('<?= htmlspecialchars($b['ph']) ?>')">×</span> <div style="font-size:1.19em;font-weight:700;margin-bottom:.17em;"> <a href="<?= htmlspecialchars($profileUrl) ?>" style="color:#1a36b7;text-decoration:none;"> <?= htmlspecialchars($b['name'] ?? 'Business') ?> </a> </div> <div style="font-style:italic;color:#3c62b8;margin-bottom:.28em;"><?= htmlspecialchars($b['slogan'] ?? '') ?></div> <div><b>Phone:</b> <?= format_phone($b['ph']) ?></div> <div><b>Address:</b> <?= htmlspecialchars($b['address'] ?? '') ?></div> <div><b>City/State:</b> <?= htmlspecialchars($b['city'] ?? '') ?><?= $b['state'] ? ', ' . htmlspecialchars($b['state']) : '' ?></div> <div><b>Website:</b> <?php if(!empty($b['website'])):?><a href="<?= htmlspecialchars($b['website']) ?>" target="_blank"><?= htmlspecialchars($b['website']) ?></a><?php endif;?></div> <div class="tags" id="tags-<?= $b['ph'] ?>"> <?php $tagCount = !empty($b['tags']) ? count($b['tags']) : 0; if ($tagCount): foreach ($b['tags'] as $i => $tag): $hidden = $i >= 2 ? 'style="display:none"' : ''; echo '<span class="tag" '.$hidden.'>'.htmlspecialchars($tag).'</span>'; endforeach; if ($tagCount > 2): echo '<a href="javascript:void(0)" class="show-more-link" onclick="showMoreTags(\''. $b['ph'] .'\', this)">Show more</a>'; endif; endif; // Show the premium/free badge at the end of the tags row echo badge($paid); ?> </div> </div> <?php endforeach; ?> </div> <!-- FOOTER --> <div class="footer"> Business list page auto-generated by BestDealOn.com — <a href="/geo/">Browse Businesses</a> </div> <script> // Remove a business (update cookie and redirect with new ph list as query string) function removeBiz(ph) { // Get the current list from query string or cookie let list = []; let match = location.search.match(/[?&]ph=([\d\-]+)/); if (match) { list = match[1].split('-'); } else if (document.cookie.match(/mybizlist=([^;]+)/)) { list = document.cookie.match(/mybizlist=([^;]+)/)[1].split('-'); } list = list.filter(item => item !== ph && item.length === 10); // Set updated cookie document.cookie = "mybizlist=" + list.join('-') + ";path=/;max-age=" + (60*60*24*30); // Redirect to new compare URL using query string if (list.length) { window.location.href = '/my-list/?ph=' + list.join('-'); } else { window.location.href = '/my-list/'; } } // Tag filter document.getElementById('tagFilter').addEventListener('change', function(){ var val = this.value; document.querySelectorAll('.compare-card').forEach(function(card){ if(!val || Array.from(card.querySelectorAll('.tag')).some(t => t.textContent === val)) { card.style.display = ''; } else { card.style.display = 'none'; } }); }); // Copy list link function copyLink() { var el = document.createElement('textarea'); el.value = document.getElementById('compareUrl').textContent.trim(); document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); document.getElementById('copied-msg').style.display = 'inline'; setTimeout(() => {document.getElementById('copied-msg').style.display = 'none';}, 2200); } // Show more/less tags function showMoreTags(ph, link) { var tagsDiv = document.getElementById('tags-' + ph); if (!tagsDiv) return; var hiddenTags = tagsDiv.querySelectorAll('.tag[style*="display:none"]'); var isHidden = hiddenTags.length > 0; if (isHidden) { hiddenTags.forEach(function(tag) { tag.style.display = ''; }); link.textContent = "Show less"; } else { var tags = tagsDiv.querySelectorAll('.tag'); tags.forEach(function(tag, i){ if(i>=2) tag.style.display = 'none'; }); link.textContent = "Show more"; } } </script> </body> </html>
Save changes
Create folder
writable 0777
Create
Cancel