Files
silly-rss/php/actualites.php
T
paraandClaude Sonnet 5 8205bfdffc Add PHP variant: no-cron, request-time feed generation for shared hosting
Same imio.smartweb JSON API as the Python script, but each feed regenerates
on demand (15 min file cache) instead of via cron, so it works on plain
PHP shared hosting with no server config access. Also adds facebook.php,
a caching proxy for the user's FetchRSS Atom feed so all three feeds live
under one domain and can be shared as stable URLs.

Tested with PHP 8.3 CLI: valid XML, real data (40 news, 12 events, proxied
Facebook feed).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-25 22:05:26 +02:00

51 lines
1.5 KiB
PHP

<?php
require __DIR__ . '/common.php';
const SITE = 'https://www.silly.be';
const NEWS_API = SITE . '/actualites/@results';
const PAGE_SIZE = 20;
const MAX_PAGES = 2; // jusqu'a 40 items
function fetch_all_news(): array
{
$items = [];
for ($page = 0; $page < MAX_PAGES; $page++) {
$bStart = $page * PAGE_SIZE;
$url = NEWS_API . '?b_size=' . PAGE_SIZE . '&b_start=' . $bStart;
$data = json_decode(http_get($url), true);
$pageItems = $data['items'] ?? [];
if (empty($pageItems)) {
break;
}
$items = array_merge($items, $pageItems);
if (count($items) >= ($data['items_total'] ?? 0)) {
break;
}
}
return $items;
}
function build_news_feed(): string
{
$items = [];
foreach (fetch_all_news() as $item) {
$id = $item['id'] ?? '';
$summary = strip_html($item['description_fr'] ?? $item['description'] ?? null);
$items[] = [
'title' => $item['title_fr'] ?? $item['title'] ?? '(sans titre)',
'link' => SITE . '/actualites?news=' . rawurlencode($id),
'guid' => $item['UID'] ?? $id,
'pubDate' => $item['effective'] ?? $item['created'] ?? null,
'description' => $summary,
];
}
return build_rss(
'Silly.be - Actualités',
SITE . '/actualites',
'Actualités de la commune de Silly (Belgique)',
$items
);
}
serve_cached_feed('actualites', 'build_news_feed');