Site Builder
Editing:
tools-qr.php
writable 0666
<?php /************************************************************************** * QR + vCard MODULE (v13 — business fixes & social loop) * ---------------------------------------------------------------------- * • Generates /ph/<digits>/qr.png or /social/<slug>/qr.png on first run * • Builds a vCard tailored to Business vs Social profiles * • Injects ALL social URLs as extra “URL;TYPE=<platform>: …” lines **************************************************************************/ if (!isset($profile) && function_exists('get_profile')) { $profile = get_profile(); } /* ---------- helper --------------------------------------------------- */ $norm = static function(string $url): string { $url = trim($url); if (!$url) return ''; if (!preg_match('#^https?://#i', $url)) $url = 'https://' . $url; return preg_replace('#^(https?://)+#i', 'https://', $url); }; /* ---------- detect profile type & key vars --------------------------- */ $slug = $profile['slug'] ?? ''; $isBusiness = preg_match('/^\d{10}$/', $slug) || isset($profile['name']); /* Fall‑back slug for business if not defined */ if ($isBusiness && !$slug && !empty($profile['phone']) && preg_match('/\d{10}/', $profile['phone'], $m)) { $slug = $m[0]; // use the 10‑digit phone } if ($isBusiness) { $bizName = $profile['name'] ?? $profile['display_name'] ?? ''; if (!$bizName) return; // nothing to encode $phone = $profile['phone'] ?? ''; $email = $profile['email'] ?? ''; $addr = $profile['address'] ?? ''; $city = $profile['city'] ?? ''; $state = $profile['state'] ?? ''; $zip = $profile['zip'] ?? ''; $siteURL = $norm($profile['website'] ?? ''); $profileURL = "https://bestdealon.com/ph/$slug/"; } else { $name = $profile['display_name'] ?? $profile['handle'] ?? ''; $handle = ltrim($profile['handle'] ?? '', '@'); $email = $profile['email'] ?? ''; if (!$name || !$email) return; $phone = $profile['phone'] ?? ''; $siteURL = $norm($profile['website'] ?? ''); $profileURL = "https://bestdealon.com/social/$slug/"; } /* ---------- build vCard --------------------------------------------- */ $v = "BEGIN:VCARD\nVERSION:3.0\n"; if ($isBusiness) { $v .= "N:$bizName;;;;\n"; $v .= "FN:$bizName\nORG:$bizName\n"; if ($phone) $v .= "TEL;TYPE=WORK,VOICE:" . preg_replace('/\D/','',$phone) . "\n"; if ($addr || $city || $state || $zip) { $v .= "ADR;TYPE=WORK:;;$addr;$city;$state;$zip;USA\n"; } $v .= "URL;TYPE=profile:$profileURL\n"; if ($siteURL) $v .= "URL;TYPE=website:$siteURL\n"; if ($email) $v .= "EMAIL;TYPE=internet:$email\n"; } else { $v .= "FN:$name\n"; if ($handle) $v .= "NICKNAME:$handle\n"; $v .= "EMAIL;TYPE=internet:$email\n"; $v .= "URL;TYPE=profile:$profileURL\n"; if ($siteURL) $v .= "URL;TYPE=website:$siteURL\n"; if ($phone) $v .= "TEL;TYPE=CELL:" . preg_replace('/\D/','',$phone) . "\n"; } /* ----- add all social URLs (both types) ------------------------------ */ if (!empty($profile['channels']['social']) && is_array($profile['channels']['social'])) { foreach ($profile['channels']['social'] as $platform => $url) { $url = $norm($url); if ($url) $v .= "URL;TYPE=$platform:$url\n"; } } $v .= "END:VCARD"; /* ---------- ensure QR PNG exists ------------------------------------ */ $root = rtrim($_SERVER['DOCUMENT_ROOT'], '/'); $pngWeb = $isBusiness ? "/ph/$slug/qr.png" : "/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($v); $png = @file_get_contents($api); if ($png && strncmp($png, "\x89PNG", 4) === 0) { @file_put_contents($pngFile, $png, LOCK_EX); } } if (!is_readable($pngFile)) return; // last‑ditch: abort /* ---------- output --------------------------------------------------- */ ?> <section class="qr-shell"> <div class="qr-card"> <img src="<?= htmlspecialchars($pngWeb) ?>" width="170" height="170" alt="QR code for <?= htmlspecialchars($isBusiness ? $bizName : $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 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> (() => { const blob = new Blob([<?= json_encode($v) ?>], {type: 'text/vcard'}); const href = URL.createObjectURL(blob); document.getElementById('dlBtn').addEventListener('click', () => { const a = Object.assign(document.createElement('a'), { href, download: '<?= $isBusiness ? preg_replace("/\\s+/", "_", $bizName) : ($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