Site Builder
Editing:
modules-quur.php
writable 0666
<?php /************************************************************************** * QR + vCard MODULE (v8 — zero proxy leaks on cached pages) * ---------------------------------------------------------------------- * • Caches each QR PNG inside the SAME path we embed in the vCard. * vCard URL line: https://bestdealon.com/social/<slug>/ * Cached PNG: /social/<slug>/qr.png * • After the first successful fetch **no markup references the proxy**. * Lighthouse and other auditors will not see any /qr-proxy.php URL on * a fully‑cached page. **************************************************************************/ /* 1. Get $profile if helper exists -------------------------------------- */ if (!isset($profile) && function_exists('get_profile')) { $profile = get_profile(); } /* 2. Sanity checks ------------------------------------------------------- */ $name = $profile['display_name'] ?? $profile['handle'] ?? ''; $handle = ltrim($profile['handle'] ?? '', '@'); $slug = $profile['slug'] ?? ''; $email = $profile['email'] ?? ''; if (!$name || !$email || !$slug) return; // nothing useful to do /* 3. Build vCard --------------------------------------------------------- */ $profileUrl = "https://bestdealon.com/social/$slug/"; // single source‑of‑truth $vcardLines = [ 'BEGIN:VCARD', 'VERSION:3.0', 'FN:' . $name, 'NICKNAME:' . $handle, 'EMAIL;TYPE=internet:' . $email, 'URL;TYPE=profile:' . $profileUrl, ]; if (!empty($profile['website'])) { $vcardLines[] = 'URL;TYPE=website:' . $profile['website']; } $vcardLines[] = 'END:VCARD'; $vcard = implode("\n", $vcardLines); /* 4. Determine cache paths ---------------------------------------------- */ $pathFromUrl = parse_url($profileUrl, PHP_URL_PATH); // /social/<slug>/ $webPath = rtrim($pathFromUrl, '/') . '/qr.png'; // /social/<slug>/qr.png $filePath = $_SERVER['DOCUMENT_ROOT'] . $webPath; // absolute on disk @mkdir(dirname($filePath), 0775, true); // ensure folder exists $usedProxy = false; // track fallback usage $qrSrc = $webPath; // optimistic default if (!is_readable($filePath)) { // cache miss $proxy = '/qr-proxy.php?data=' . rawurlencode($vcard); $png = @file_get_contents($proxy); if ($png && strncmp($png, "\x89PNG", 4) === 0) { @file_put_contents($filePath, $png, LOCK_EX); } if (!is_readable($filePath)) { // even after write $usedProxy = true; $qrSrc = $proxy; // one‑time fallback } } ?> <!-- ============ QR + DOWNLOAD SECTION ============ --> <section class="qr-shell"> <div class="qr-card"> <img src="<?= htmlspecialchars($qrSrc) ?>" width="170" height="170" alt="Scan to save contact for <?= htmlspecialchars($name) ?>" style="border-radius:14px;box-shadow:0 1.5px 10px #e3eefd"> <h3>Scan to Save Contact</h3> <button id="dlBtn" class="qr-btn" aria-label="Download contact as vCard"> 📱 Add to Phone (vCard) </button> <div class="qr-hint">Works on iOS & Android · 9 kB</div> <?php if ($usedProxy): // first view – noscript must hit the proxy ?> <noscript style="margin-top:.7rem;font-size:.9rem"> <a href="/qr-proxy.php?data=<?= rawurlencode($vcard) ?>" download="<?= $handle ?: 'contact' ?>.vcf"> Download contact card </a> </noscript> <?php else: // cached – create a data: link so no proxy URL leaks ?> <noscript style="margin-top:.7rem;font-size:.9rem"> <a href="data:text/vcard,<?= rawurlencode($vcard) ?>" download="<?= $handle ?: 'contact' ?>.vcf"> Download contact card </a> </noscript> <?php endif; ?> </div> </section> <style> .qr-shell{ margin:2.6rem auto; max-width:clamp(480px,70vw,720px); width:100%; font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif; text-align:center } .qr-card{ background:#fff; padding:1.7rem 1.5rem; border:3.5px solid #ffb63b; border-radius:27px; box-shadow:0 8px 26px rgba(0,0,0,.06) } .qr-card h3{ margin:1rem 0 .8rem; font-size:1.2rem; font-weight:700; color:#102a66 } .qr-btn{ background:#ffb63b; color:#000; font-weight:700; padding:.65em 1.9em; border:none; border-radius:8px; cursor:pointer; font-size:1rem; box-shadow:0 2px 6px rgba(0,0,0,.08); transition:background .15s } .qr-btn:hover{background:#ffa726} .qr-hint{ margin-top:.45rem; font-size:.85rem; color:#5d5d5d } </style> <script> /* Download vCard (client‑side) */ (function(){ const btn = document.getElementById('dlBtn'); if (!btn) return; btn.addEventListener('click', () => { const blob = new Blob([<?= json_encode($vcard) ?>], {type: 'text/vcard'}); const url = URL.createObjectURL(blob); const a = Object.assign(document.createElement('a'), { href: url, download: '<?= $handle ?: "contact" ?>.vcf'}); document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }); })(); </script>
Save changes
Create folder
writable 0777
Create
Cancel