Site Builder
Editing:
modulyyes-qr.php
writable 0666
<?php /************************************************************************** * QR + vCard MODULE (v7 — single‑source path, no digit branch) * ---------------------------------------------------------------------- * Key points * • Uses ONE canonical path derived from the profile‑URL line we embed in * the vCard. We strip the domain and append /qr.png — that’s it. * • Removes the phone/"digits" logic that caused confusion; every profile * lives under its slug at /social/<slug>/qr.png (exactly the path you * see after the domain in the vCard URL). * • On first load, calls /qr-proxy.php?data=… to build the PNG, then * serves the clean path for all future requests. **************************************************************************/ /* 1. Pull $profile if helper exists ------------------------------------- */ 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); // may still add TEL line if (!$name || !$email || !$slug) return; // need these three /* 3. Build the vCard ----------------------------------------------------- */ $profileUrl = 'https://bestdealon.com/social/' . $slug . '/'; $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']; } if ($digits) { $vcardLines[] = 'TEL;TYPE=CELL:' . $digits; } $vcardLines[] = 'END:VCARD'; $vcard = implode("\n", $vcardLines); /* 4. Derive the QR cache path from the URL line ------------------------- */ $webDir = rtrim(parse_url($profileUrl, PHP_URL_PATH), '/'); // e.g. /social/fsafe $webPath = $webDir . '/qr.png'; // /social/fsafe/qr.png $root = $_SERVER['DOCUMENT_ROOT']; $filePath= $root . $webPath; // absolute file @mkdir(dirname($filePath), 0775, true); // ensure folder $qrSrc = $webPath; // default if (!is_readable($filePath)) { /* cache miss → fetch once */ $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)) { /* write failed — fall back */ $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