Site Builder
Editing:
modulesggg-rss.php
writable 0666
<?php /************************************************************************** * RSS MODULE – Latest Posts * ---------------------------------------------------------------------- * • Uses server‑side cache when < $ttl seconds old * • Falls back to spinner + JS fetch via /rss-proxy.php (which also updates cache) **************************************************************************/ $ttl = 3600; // cache life (1 hour) /* ---------- 1. Load profile ---------- */ if (!isset($profile) || !is_array($profile)) { $json = dirname(__DIR__, 2) . '/profile.json'; $profile = is_readable($json) ? json_decode(file_get_contents($json), true) : []; } $slug = $profile['slug'] ?? ''; $rssURL = $profile['website_rss'] ?? ''; $name = $profile['display_name'] ?? $profile['handle'] ?? ''; $isPremium = !empty($profile['premium']) && strtolower($profile['premium'])!=='off'; /* Free listing upsell? Flip to true if you want spinner for free tier too */ if (!$isPremium || !$rssURL) { return; } /* cache file lives alongside profile folder */ $cacheFn = dirname(__DIR__, 2) . "/rss-cache.json"; /* decide render mode */ $useCache = is_file($cacheFn) && filemtime($cacheFn) > time() - $ttl; $data = $useCache ? json_decode(file_get_contents($cacheFn), true) : null; $items = $data['items'] ?? []; ?> <section class="rs-shell"> <div class="rs-card"> <h2>📰 Latest Posts</h2> <?php if ($items): /* ---------- server‑side render ---------- */ ?> <ul class="rs-list"> <?php foreach ($items as $it): ?> <li> <a class="rs-title" href="<?= htmlspecialchars($it['link']) ?>" target="_blank" rel="noopener"> <?= htmlspecialchars($it['title']) ?> </a> <?php if (!empty($it['date'])): ?> <span class="rs-date"> <?= date('M j, Y', strtotime($it['date'])) ?> </span> <?php endif; ?> </li> <?php endforeach; ?> </ul> <?php else: /* ---------- spinner + JS fetch ---------- */ ?> <div id="rsSpinner" class="rs-spin"> <span class="dot"></span><span class="dot"></span><span class="dot"></span> Fetching news… </div> <?php endif; ?> </div> </section> <style> /* card wrapper */ .rs-shell{margin:2.6rem auto;max-width:clamp(480px,70vw,720px);width:100%; font-family:system-ui,Arial,sans-serif} .rs-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);text-align:center} .rs-card h2{margin:0 0 1.1rem;font-size:1.35rem;font-weight:700;color:#102a66} /* list */ /* match Recommended Links spacing */ .rs-list{ list-style:none; padding:0; margin:0 auto; /* centered like before */ max-width:430px; text-align:left; } .rs-list li{ margin:1.15em 0; /* ↖ identical to .ln-list li */ } .rs-title{font-size:1.04rem;color:#1a0dab;text-decoration:none} .rs-title:hover{text-decoration:underline} .rs-date{display:block;font-size:.82rem;color:#555;margin-top:.18em} /* spinner */ .rs-spin{display:inline-flex;align-items:center;gap:.45em;font-size:1.05rem;color:#666} .rs-spin .dot{width:.55em;height:.55em;border-radius:50%;background:#bcd; animation:rspin 1s infinite alternate} .rs-spin .dot:nth-child(2){animation-delay:.2s} .rs-spin .dot:nth-child(3){animation-delay:.4s} @keyframes rspin{to{opacity:.25;transform:scale(.6)}} </style> <?php if (!$useCache): /* ---------- JS fetch + cache ------------ */ ?> <script defer> window.addEventListener('load', ()=>{ const sec = document.querySelector('.rs-card'); const spin = document.getElementById('rsSpinner'); fetch(`/rss-proxy.php?slug=<?= urlencode($slug) ?>&feed=<?= urlencode($rssURL) ?>`) .then(r=>r.ok?r.json():Promise.reject(r.status)) .then(d=>{ const items=d.items||[]; if(!items.length){spin.textContent='No recent posts.';return;} const ul=document.createElement('ul'); ul.className='rs-list'; items.slice(0,10).forEach(it=>{ const li=document.createElement('li'); const a=document.createElement('a'); a.className='rs-title'; a.href=it.link; a.target='_blank'; a.rel='noopener'; a.textContent=it.title||it.link; li.appendChild(a); if(it.date){ const s=document.createElement('span'); s.className='rs-date'; s.textContent=new Date(it.date).toLocaleDateString(undefined, {month:'short',day:'numeric',year:'numeric'}); li.appendChild(s); } ul.appendChild(li); }); spin.replaceWith(ul); }) .catch(()=>spin.textContent=`News cannot be fetched at this time.`); }); </script> <?php endif; ?>
Save changes
Create folder
writable 0777
Create
Cancel