Site Builder
Editing:
modules-qr-socialonly.php
writable 0666
<?php /************************************************************************** * QR + vCard MODULE (v10 — gold card, one‑shot PNG cache, no proxy) * ---------------------------------------------------------------------- * • FIRST build only: calls the *public* QR‑server API directly, * saves /social/<slug>/qr.png (no proxy PHP include, no echo). * • Subsequent builds: read & serve that PNG; browser never sees a * broken link because the file is written before HTML is flushed. * • No TTL logic – any future full‑site rebuild will regenerate the * PNG automatically if it is missing. **************************************************************************/ if (!isset($profile) && function_exists('get_profile')) { $profile = get_profile(); } $name = $profile['display_name'] ?? $profile['handle'] ?? ''; $handle = ltrim($profile['handle'] ?? '', '@'); $slug = $profile['slug'] ?? ''; $email = $profile['email'] ?? ''; $phone = $profile['phone'] ?? ''; if (!$name || !$email || !$slug) return; // nothing useful to encode /* Build vCard ---------------------------------------------------------*/ $vcard = "BEGIN:VCARD\n" . "VERSION:3.0\n" . "FN:$name\n" . "NICKNAME:$handle\n" . "EMAIL;TYPE=internet:$email\n" . "URL;TYPE=profile:https://bestdealon.com/social/$slug/\n"; if (!empty($profile['website'])) { $vcard .= "URL;TYPE=website:{$profile['website']}\n"; } if (preg_match('/\d{10,}/', $phone)) { $digits = preg_replace('/\D/','', $phone); $vcard .= "TEL;TYPE=CELL:$digits\n"; } $vcard .= "END:VCARD"; /* Ensure QR PNG exists ------------------------------------------------*/ $root = rtrim($_SERVER['DOCUMENT_ROOT'],'/'); $pngWeb = "/social/$slug/qr.png"; $pngFile = $root . $pngWeb; if (!is_readable($pngFile)) { @mkdir(dirname($pngFile), 0775, true); $api = 'https://api.qrserver.com/v1/create-qr-code/?size=170x170&data=' . rawurlencode($vcard); $png = @file_get_contents($api); if ($png && strncmp($png, "\x89PNG", 4) === 0) { @file_put_contents($pngFile, $png, LOCK_EX); } } if (!is_readable($pngFile)) return; // abort silently if still missing $qrSrc = $pngWeb; ?> <!-- ============ 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> </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 blob = new Blob([<?= json_encode($vcard) ?>], {type:'text/vcard'}); const href = URL.createObjectURL(blob); document.getElementById('dlBtn').addEventListener('click', () => { const a = Object.assign(document.createElement('a'), {href, download:'<?= $handle ?: "contact" ?>.vcf'}); document.body.appendChild(a); a.click(); a.remove(); setTimeout(()=>URL.revokeObjectURL(href), 9000); }); })(); </script>
Save changes
Create folder
writable 0777
Create
Cancel