Siteβ―Builder
Editing:
modules-rssoooook.php
writable 0666
<?php /************************************************************************** * RSSΒ MODULE (v8Β βΒ no fileβcache, same HTML/CSS) * ---------------------------------------------------------------------- * β’ Every build: fetch RSS or JSON feed β render <ul> list (maxΒ $maxItems) * β’ If the feed URL is missing or produces zero items, we output nothing; * this prevents a blank card from showing. * β’ No fileβsystem cache is written β the outer pageβlevel caching you * already use will handle performance. * β’ Compatible with /ph/<phone>/β¦ and /social/<handle>/β¦ profiles. **************************************************************************/ if (!function_exists('get_profile')) { return; // hardβexit if helper missing } $profile = get_profile(); /* βββ workβout profile folder (business vs social) βββββββββββββββββ */ $root = rtrim($_SERVER['DOCUMENT_ROOT'],'/'); if (isset($profile['name'])) { // business $slug = preg_replace('/\D/','',$profile['phone']); if ($slug === '') return; $dir = "$root/ph/$slug"; } else { // social $slug = ltrim($profile['handle'] ?? '', '@'); if ($slug === '') return; $dir = "$root/social/$slug"; } /* βββ feed URL ββββββββββββββββββββββββββββββββββββββββββββββββββββββ */ $feedUrl = trim($profile['website_rss'] ?? ''); if ($feedUrl === '') return; // nothing to do $maxItems = 10; // show at most 10 links $timeoutSec = 5; echo "$feedUrl"; /* βββ fetch + build helper ββββββββββββββββββββββββββββββββββββββββββ */ function render_feed(string $url,int $limit,int $timeout): string { $ctx = stream_context_create([ 'http' => ['timeout'=>$timeout], 'https' => ['timeout'=>$timeout] ]); $raw = @file_get_contents($url,false,$ctx); if (!$raw) return ''; $items = []; /* β try XML (RSS / Atom) β */ libxml_use_internal_errors(true); if ($xml = simplexml_load_string($raw,'SimpleXMLElement',LIBXML_NOCDATA)) { /* RSSβ―2.0 */ foreach ($xml->channel->item ?? [] as $it) { $items[] = [ 'title'=>(string)($it->title ?? ''), 'link' =>(string)($it->link ?? ''), 'date' =>(string)($it->pubDate ?? '') ]; if (count($items) >= $limit) break; } /* Atom */ foreach ($xml->entry ?? [] as $it) { $items[] = [ 'title'=>(string)($it->title ?? ''), 'link' =>(string)($it->link['href'] ?? ''), 'date' =>(string)($it->updated ?? $it->published ?? '') ]; if (count($items) >= $limit) break; } } /* β try JSON Feed 1.1 β */ if (!$items && ($json = json_decode($raw,true)) && 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) >= $limit) break; } } if (!$items) return ''; // nothing usable /* build HTML list */ $out = '<ul class="rs-list">'; foreach ($items as $it) { $title = htmlspecialchars($it['title'] ?: 'Untitled'); $link = htmlspecialchars($it['link'] ?: '#'); $date = $it['date'] ? date('M j, Y', strtotime($it['date'])) : ''; $out .= '<li><a class="rs-title" href="'.$link.'" target="_blank" rel="noopener">' . $title . '</a>'; if ($date) $out .= ' <span class="rs-date">'.$date.'</span>'; $out .= '</li>'; } return $out.'</ul>'; } /* βββ build feed every time βββββββββββββββββββββββββββββββββββββββββ */ $feedHtml = render_feed($feedUrl, $maxItems, $timeoutSec); if ($feedHtml === '') return; // do not show empty card ?> <section class="rs-shell"> <div class="rs-card"> <h2>π° Latest Posts</h2> <?= $feedHtml ?> </div> </section> <style> .rs-shell{margin:2.4rem 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.6rem 1.4rem;border:3.5px solid #ffb63b; border-radius:27px;box-shadow:0 8px 22px rgba(0,0,0,.05)} .rs-card h2{margin:0 0 1.1rem;font-size:1.33rem;font-weight:700;color:#102a66} .rs-list{list-style:none;padding:0;margin:0 auto;max-width:430px;text-align:left} .rs-list li{margin:1.05em 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} @media(prefers-color-scheme:dark){ .rs-card{background:#1a1f2b;border-color:#ffb63b;box-shadow:0 6px 18px #0006} .rs-title{color:#96b5ff} .rs-date{color:#aaa} } </style>
Save changes
Create folder
writable 0777
Create
Cancel