Site Builder
Editing:
moduvvles-rss.php
writable 0666
<?php /************************************************************************** * RSS MODULE (v6 — gold card, **single‑run HTML cache**, no TTL logic) * ---------------------------------------------------------------------- * • FIRST build only: downloads the RSS/JSON feed directly (no proxy), * renders <ul> markup, saves it as /social/<slug>/rss-cache.html. * • Subsequent builds: just read that HTML file and echo it. No expiry * check; whenever the whole microsite is rebuilt the snippet refreshes. * • Zero JSON‑parsing overhead for cached views; fastest possible. **************************************************************************/ if (function_exists('get_profile')) { $profile = get_profile(); } /* 1) Load profile only if caller hasn’t supplied it */ if (!isset($profile) || !is_array($profile)) { $json = dirname(__DIR__, 2) . '/profile.json'; $profile = is_readable($json) ? json_decode(file_get_contents($json), true) : []; } /* ---- configuration --------------------------------------------------- */ $feedUrl = $profile['website_rss']; $maxItems = 10; // how many posts to show // Get the current URL path (excluding domain and query string) $root = rtrim($_SERVER['DOCUMENT_ROOT'], '/'); if ($profile['name']) { $slug = $profile['phone'] $dir = "$root/ph/$slug"; } else { $slug = $profile['handle'] $dir = "$root/social/$slug"; } $htmlFile = "$dir/rss-cache.html"; /* ---- helper: fetch & build <ul> HTML --------------------------------- */ function fetch_feed_html(string $url, int $max): string { $ctx = stream_context_create([ 'http' => ['timeout'=>4], 'https' => ['timeout'=>4] ]); $raw = @file_get_contents($url, false, $ctx); if (!$raw) return '<p>No recent posts.</p>'; libxml_use_internal_errors(true); $xml = simplexml_load_string($raw, 'SimpleXMLElement', LIBXML_NOCDATA); $items = []; if ($xml && isset($xml->channel->item)) { foreach ($xml->channel->item as $it) { $items[] = [ 'title' => (string)$it->title, 'link' => (string)$it->link, 'date' => (string)$it->pubDate ]; if (count($items) >= $max) break; } } else { $json = json_decode($raw, true); if ($json && isset($json['items'])) { foreach ($json['items'] as $it) { $items[] = [ 'title' => $it['title'] ?? '', 'link' => $it['url'] ?? $it['external_url'] ?? '', 'date' => $it['date_published'] ?? '' ]; if (count($items) >= $max) break; } } } if (!$items) return '<p>No recent posts.</p>'; $html = "<ul class=\"rs-list\">"; foreach ($items as $it) { $title = htmlspecialchars($it['title'] ?: 'Untitled'); $url = htmlspecialchars($it['link'] ?: '#'); $date = $it['date'] ? date('M j, Y', strtotime($it['date'])) : ''; $html .= "<li><a class=\"rs-title\" href=\"$url\" target=\"_blank\" rel=\"noopener\">$title</a>"; if ($date) $html .= " <span class=\"rs-date\">$date</span>"; $html .= "</li>"; } return $html.'</ul>'; } /* ---- ensure cached HTML exists --------------------------------------- */ if (!is_readable($htmlFile)) { @mkdir($dir, 0775, true); $html = fetch_feed_html($feedUrl, $maxItems); file_put_contents($htmlFile, $html, LOCK_EX); } /* ---- load cached HTML ------------------------------------------------- */ $cachedHtml = is_readable($htmlFile) ? file_get_contents($htmlFile) : '<p>No recent posts.</p>'; ?> <section class="rs-shell"> <div class="rs-card"> <h2>📰 Latest Posts</h2> <?= $cachedHtml ?> </div> </section> <style> /* gold card scaffold (matches qr-card) */ .rs-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} .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)} .rs-card h2{margin:0 0 1.1rem;font-size:1.35rem;font-weight:700;color:#102a66} /* list styling */ .rs-list{list-style:none;padding:0;margin:0 auto;max-width:430px;text-align:left} .rs-list li{margin:1.15em 0} .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} </style>
Save changes
Create folder
writable 0777
Create
Cancel