Site Builder
Editing:
modules-qhhhhhhhr.php
writable 0666
<?php /************************************************************************** * QR + vCard MODULE (v6 – caches qr.png inside each profile folder) * ---------------------------------------------------------------------- * This version never shows the qr‑proxy URL unless the first‑time fetch * fails. After one successful load, <img src> is always /social/<slug>/ * qr.png or /ph/<digits>/qr.png. **************************************************************************/ /* 1. Pull $profile if the helper is available */ if (!isset($profile) && function_exists('get_profile')) { $profile = get_profile(); } /* 2. Basic sanity checks -------------------------------------------------- */ $name = $profile['display_name'] ?? $profile['handle'] ?? ''; $handle = ltrim($profile['handle'] ?? '', '@'); $slug = $profile['slug'] ?? ''; $email = $profile['email'] ?? ''; $phone = $profile['phone'] ?? ''; $digits = preg_replace('/\D/', '', $phone); if (!$name || !$email) return; // nothing useful to encode /* 3. Build vCard ---------------------------------------------------------- */ $vcardLines = [ 'BEGIN:VCARD', 'VERSION:3.0', 'FN:' . $name, 'NICKNAME:' . $handle, 'EMAIL;TYPE=internet:' . $email, 'URL;TYPE=profile:https://bestdealon.com/social/' . $slug . '/', ]; if (!empty($profile['website'])) { $vcardLines[] = 'URL;TYPE=website:' . $profile['website']; } if ($digits) { $vcardLines[] = 'TEL;TYPE=CELL:' . $digits; } $vcardLines[] = 'END:VCARD'; $vcard = implode("\n", $vcardLines); /* 4. Decide image source -------------------------------------------------- */ $root = $_SERVER['DOCUMENT_ROOT']; // e.g. /home/bestdealon/public_html $qrSrc = null; // will hold final <img src> if ($slug) { $webPath = "/social/$slug/qr.png"; } elseif ($digits) { $webPath = "/ph/$digits/qr.png"; } else { // cannot derive a per‑profile cache path – fall back to proxy always $qrSrc = '/qr-proxy.php?data=' . rawurlencode($vcard); } if ($qrSrc === null) { // normal profile‑based path $filePath = $root . $webPath; @mkdir(dirname($filePath), 0775, true); // ensure folder exists $qrSrc = $webPath; // optimistic – assume cached PNG if (!is_readable($filePath)) { // cache miss → fetch once $proxy = '/qr-proxy.php?data=' . rawurlencode($vcard); $png = @file_get_contents($proxy); // silent network errors if ($png && strncmp($png, "\x89PNG", 4) === 0) { @file_put_contents($filePath, $png, LOCK_EX); } if (!is_readable($filePath)) { // write failed – use proxy URL $qrSrc = $proxy; } } } ?> <!-- ============ 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> <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> </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) */ document.getElementById('dlBtn').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