Site Builder
Editing:
modules-coupon.php
writable 0666
<?php /************************************************************************** * COUPON MODULE – Sponsors / Affiliate deals (RESPONSIVE v2) * ---------------------------------------------------------------------- * • Reads ../../coupon.json (adjacent to profile.json) * • Width now matches other gold cards on tiny screens **************************************************************************/ /* 1) Locate coupon.json */ $coupons = get_coupon(); if (!$coupons) return; /* 3) (Optional) profile handle for “recommended by …” */ $handle = $profile['handle'] ?? ''; ?> <!-- ========== SPONSORS & DEALS ========== --> <section class="cp-wrap"> <?php $name = $profile['name'] ?? ($profile['handle'] ?? 'This business'); /* 1) Title ------------------------------------------------*/ if ($handle) { // influencer $title = '🔥 ' . htmlspecialchars($handle) . '’s Sponsors and Affiliates'; $blurb = sprintf( 'Discover hand‑picked offers from brands that %1$s personally recommends. ' . 'Every deal is curated to give you amazing savings on products your favourite influencer truly loves and trusts. ' . 'By taking advantage of these offers, you directly support %1$s in creating more of the authentic, quality content you enjoy — win‑win!', htmlspecialchars($handle) ); } else { // business $title = '🔥 Best Deals Curated by ' . htmlspecialchars($name); $blurb = sprintf( 'Explore exclusive promotions and limited‑time offers hand‑selected by %1$s to give you the best value on must‑have products and services. ' . 'Our team vets every deal to ensure unbeatable pricing and genuine quality. ' . 'Have questions or need a custom quote? <strong>Get in touch today</strong> — we’re ready to help you save and succeed!', htmlspecialchars($name) ); } ?> <a name="coupon"></a><h2><?= $title ?></h2> <p><?= $blurb ?></p> <?php foreach ($coupons as $i=>$c): $title = $c['title'] ?? ''; $code = $c['code'] ?? ''; $link = $c['link'] ?? ''; $expiry = $c['expiry'] ?? ''; $descRaw = trim($c['desc'] ?? ''); if (!$title) continue; $descLimit = 160; $hasMore = mb_strlen($descRaw,'UTF-8') > $descLimit; $descShort = nl2br(htmlspecialchars(mb_substr($descRaw,0,$descLimit,'UTF-8'))); $descFull = nl2br(htmlspecialchars($descRaw)); /* element‑specific IDs */ $card = "cpCard$i"; $dID = "cpDesc$i"; $rID = "read$i"; $lID = "less$i"; $pID = "print$i"; $sID = "share$i"; ?> <style> /* print‑only tweaks for EACH card */ @media print{ #<?= $card ?> .cp-toolbar, #<?= $card ?> .cp-btn, #<?= $card ?> #<?= $rID ?>, #<?= $card ?> #<?= $lID ?>{display:none!important} #<?= $card ?> .d-screen{display:none!important} #<?= $card ?> .d-print {display:block!important} } #<?= $card ?> .d-print{display:none} </style> <div class="cp-card" id="<?= $card ?>" itemscope itemtype="https://schema.org/Offer"> <div class="cp-head">Recommended by <?= htmlspecialchars($name) ?></div> <h3 class="cp-title" itemprop="name"><?= htmlspecialchars($title) ?></h3> <p class="cp-desc d-screen" id="<?= $dID ?>" itemprop="description"> <?php if ($hasMore): ?> <?= $descShort ?> <button id="<?= $rID ?>" class="cp-more">Read more</button> <?php else: ?> <?= $descFull ?> <?php endif; ?> </p> <p class="cp-desc d-print"><?= $descFull ?></p> <div class="cp-row"><span>Coupon Code:</span><code><?= htmlspecialchars($code) ?></code></div> <div class="cp-row"><span>Expires:</span><em><?= htmlspecialchars($expiry ?: 'No Expiry') ?></em></div> <?php if ($link): ?> <p style="text-align:center;margin:1rem 0 0"> <a href="<?= htmlspecialchars($link) ?>" target="_blank" rel="noopener" class="cp-deal">Get Deal Now »</a> </p> <?php endif; ?> <div class="cp-toolbar"> <button id="<?= $pID ?>" class="cp-btn">🖨️ Print</button> <button id="<?= $sID ?>" class="cp-btn">📤 Share</button> </div> </div> <script> /* Expand / collapse, print, share – per‑card IIFE */ (()=>{ const full = <?= json_encode($descFull) ?>; const short = <?= json_encode($descShort) ?>; const desc = document.getElementById('<?= $dID ?>'); const rd = document.getElementById('<?= $rID ?>'); <?php if ($hasMore): ?> rd.onclick = () => { desc.innerHTML = full + '<button id="<?= $lID ?>" class="cp-more">Show less</button>'; document.getElementById('<?= $lID ?>').onclick = () => { desc.innerHTML = short + rd.outerHTML; document.getElementById('<?= $rID ?>').onclick = rd.onclick; }; }; <?php endif; ?> /* print */ document.getElementById('<?= $pID ?>').onclick = ()=>{ const html = document.getElementById('<?= $card ?>').outerHTML; const w = window.open('','w','width=600,height=800'); w.document.write('<html><head><title>Print Coupon</title><style>body{font-family:system-ui,Arial,sans-serif;margin:0;padding:1.2rem;background:#f5f8fb}</style></head><body>'+html+'</body></html>'); w.document.close(); setTimeout(()=>{w.print();w.close();},250); }; /* share (WebShare API fallback to clipboard) */ document.getElementById('<?= $sID ?>').onclick = async e=>{ const url = location.href.split('#')[0]+'#<?= $card ?>'; try{ if(navigator.share){ await navigator.share({title:<?= json_encode($title) ?>,url}); }else{ await navigator.clipboard.writeText(url); e.target.textContent='✅ Copied!';setTimeout(()=>e.target.textContent='📤 Share',1500); } }catch{} }; })(); </script> <?php endforeach; ?> </section> <?php /* ---------- BEGIN structured‑data drop‑in (place near </body>) ---------- */ if (isset($coupons, $profile) && is_array($coupons) && $coupons) { // Determine who is recommending the deals $brandName = ''; if (!empty($profile['handle'])) { // influencer $brandName = ltrim($profile['handle'], '@'); } elseif (!empty($profile['name'])) { // business $brandName = $profile['name']; } /* Build an array of “Offer” objects that search engines understand */ $offers = []; foreach ($coupons as $c) { if (empty($c['title'])) continue; // skip blanks $offers[] = [ '@type' => 'Offer', 'name' => $c['title'], 'description' => $c['desc'] ?? '', 'url' => $c['link'] ?? '', 'priceCurrency' => 'USD', 'price' => '0', // coupon = saving 'availability' => 'https://schema.org/InStock', 'validThrough' => !empty($c['expiry']) ? date('c', strtotime($c['expiry'])) : null, 'seller' => [ '@type' => 'Organization', 'name' => $brandName ], 'identifier' => [ '@type' => 'PropertyValue', 'name' => 'Coupon Code', 'value' => $c['code'] ?? '' ] ]; } if ($offers) { $graph = [ '@context' => 'https://schema.org', '@graph' => $offers ]; echo '<script type="application/ld+json">' . json_encode($graph, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT) . '</script>'; } } /* ---------- END structured‑data drop‑in -------------------------------- */ ?> <style> /* ========== SCOPED COUPON STYLES ========== */ .cp-wrap{ padding:1.6rem 0; border-bottom:1px solid #e4e9f3; font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif } .cp-wrap h2{ margin:.1em 0 1rem; font-size:1.35rem; font-weight:700; color:#102a66; text-align:center } /* --- gold card --- */ .cp-card{ box-sizing:border-box; /* ✅ makes padding part of width */ max-width:clamp(280px,90vw,720px); width:100%; margin:2.4rem auto; padding:2rem 1.8rem 1.4rem; background:#fff; border:3.5px solid #ffb63b; border-radius:27px; box-shadow:0 10px 38px #f5db9c3c; overflow:hidden } /* a touch tighter on tiny phones */ @media(max-width:440px){ .cp-card{padding:1.5rem 1rem} } .cp-head{ font-weight:800; font-size:1.05em; color:#194285; border-bottom:1px solid #ef8f13; padding-bottom:.15em; margin-bottom:1.1em; text-align:center } .cp-title{ font-size:1.2em; font-weight:800; color:#df6200; margin:0 0 .6em; text-align:center } .cp-desc{font-size:1.05em;color:#3a3232;margin:0 0 1.3em;line-height:1.55} .cp-more{background:none;border:none;padding:0;margin-left:.3em;color:#2574bc;font-size:.95em;text-decoration:underline;cursor:pointer} .cp-row{ display:flex;gap:1.1em;align-items:center;margin-bottom:.5em;font-size:1.05em; flex-wrap:wrap } .cp-row span{font-weight:700;color:#ab2d00} .cp-row code{ background:#ffefc1;border-radius:9px;padding:.28em 1.2em; font-family:monospace;color:#a95600;font-weight:700;white-space:nowrap } .cp-row em{font-style:normal;color:#a75608;font-weight:600} .cp-deal{ display:inline-block; background:#2357d7; color:#fff; padding:.55em 1.9em; border-radius:8px; font-weight:700; font-size:1.06rem; text-decoration:none } .cp-deal:hover{background:#1e4dbf} .cp-toolbar{ display:flex;justify-content:center;gap:1.2em;margin:1.15em 0 0;flex-wrap:wrap } .cp-btn{ padding:.65em 1.6em; border-radius:11px; font-size:1.05em; font-weight:700; border:none; cursor:pointer; box-shadow:0 1px 5px #ffeebb50; background:#ffeebb; color:#000 } .cp-btn:hover{background:#ffd96e} </style>
Save changes
Create folder
writable 0777
Create
Cancel