Two bugs found by testing real links from the feed: - Link format was wrong (?news=<internal-id>), landing on the general listing instead of the article. Traced the real network call the site makes when opening an item and found the actual pattern: /actualites/<slug>?u=<UID> (agenda: /agenda/<slug>?u=<UID>), where the JS router reads the `u` query param to fetch @results?UID=...&fullobjects=1. - Description only used the short teaser (description_fr) even though the API response already includes the full rich-text body (text_fr.data) and attachments (items[].file.download) in the same call — no extra request needed, just wasn't being used. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
76 lines
2.4 KiB
PHP
76 lines
2.4 KiB
PHP
<?php
|
|
require __DIR__ . '/common.php';
|
|
|
|
const SITE = 'https://www.silly.be';
|
|
const EVENTS_API = SITE . '/agenda/@results';
|
|
const PAGE_SIZE = 20;
|
|
const MAX_PAGES = 2;
|
|
|
|
function fetch_all_events(): array
|
|
{
|
|
$items = [];
|
|
for ($page = 0; $page < MAX_PAGES; $page++) {
|
|
$bStart = $page * PAGE_SIZE;
|
|
$url = EVENTS_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 format_event_meta(array $item): string
|
|
{
|
|
$parts = [];
|
|
$start = !empty($item['start']) ? new DateTime($item['start']) : null;
|
|
$end = !empty($item['end']) ? new DateTime($item['end']) : null;
|
|
|
|
if ($start) {
|
|
$parts[] = !empty($item['whole_day'])
|
|
? 'Le ' . $start->format('d/m/Y')
|
|
: 'Le ' . $start->format('d/m/Y à H:i');
|
|
}
|
|
if ($end && (!$start || $end->format('Y-m-d') !== $start->format('Y-m-d'))) {
|
|
$parts[] = "jusqu'au " . $end->format('d/m/Y H:i');
|
|
}
|
|
$address = implode(', ', array_filter([$item['street'] ?? null, $item['zipcode'] ?? null, $item['city'] ?? null]));
|
|
if ($address) {
|
|
$parts[] = "Lieu : $address";
|
|
}
|
|
return implode(' — ', $parts);
|
|
}
|
|
|
|
function build_events_feed(): string
|
|
{
|
|
$items = [];
|
|
foreach (fetch_all_events() as $item) {
|
|
$id = basename(rtrim($item['@id'] ?? '', '/'));
|
|
$title = $item['title_fr'] ?? $item['title'] ?? '(sans titre)';
|
|
$uid = $item['UID'] ?? $id;
|
|
$meta = format_event_meta($item);
|
|
$description = ($meta !== '' ? '<p>' . htmlspecialchars($meta, ENT_QUOTES, 'UTF-8') . '</p>' : '')
|
|
. full_body_html($item);
|
|
$items[] = [
|
|
'title' => $title,
|
|
'link' => SITE . '/agenda/' . slugify($title) . '?u=' . rawurlencode($uid),
|
|
'guid' => $uid,
|
|
'pubDate' => $item['created'] ?? $item['start'] ?? null,
|
|
'description' => $description,
|
|
];
|
|
}
|
|
return build_rss(
|
|
'Silly.be - Agenda',
|
|
SITE . '/agenda',
|
|
"Agenda / événements de la commune de Silly (Belgique)",
|
|
$items
|
|
);
|
|
}
|
|
|
|
serve_cached_feed('agenda', 'build_events_feed');
|