diff --git a/php/actualites.php b/php/actualites.php index aed86da..ab8b87d 100644 --- a/php/actualites.php +++ b/php/actualites.php @@ -30,13 +30,14 @@ function build_news_feed(): string $items = []; foreach (fetch_all_news() as $item) { $id = $item['id'] ?? ''; - $summary = strip_html($item['description_fr'] ?? $item['description'] ?? null); + $title = $item['title_fr'] ?? $item['title'] ?? '(sans titre)'; + $uid = $item['UID'] ?? $id; $items[] = [ - 'title' => $item['title_fr'] ?? $item['title'] ?? '(sans titre)', - 'link' => SITE . '/actualites?news=' . rawurlencode($id), - 'guid' => $item['UID'] ?? $id, + 'title' => $title, + 'link' => SITE . '/actualites/' . slugify($title) . '?u=' . rawurlencode($uid), + 'guid' => $uid, 'pubDate' => $item['effective'] ?? $item['created'] ?? null, - 'description' => $summary, + 'description' => full_body_html($item), ]; } return build_rss( diff --git a/php/agenda.php b/php/agenda.php index 4e68771..f2006bb 100644 --- a/php/agenda.php +++ b/php/agenda.php @@ -51,13 +51,15 @@ function build_events_feed(): string $items = []; foreach (fetch_all_events() as $item) { $id = basename(rtrim($item['@id'] ?? '', '/')); - $summary = strip_html($item['description_fr'] ?? $item['description'] ?? null); + $title = $item['title_fr'] ?? $item['title'] ?? '(sans titre)'; + $uid = $item['UID'] ?? $id; $meta = format_event_meta($item); - $description = implode(' | ', array_filter([$meta, $summary])); + $description = ($meta !== '' ? '

' . htmlspecialchars($meta, ENT_QUOTES, 'UTF-8') . '

' : '') + . full_body_html($item); $items[] = [ - 'title' => $item['title_fr'] ?? $item['title'] ?? '(sans titre)', - 'link' => SITE . '/agenda?event=' . rawurlencode($id), - 'guid' => $item['UID'] ?? $id, + 'title' => $title, + 'link' => SITE . '/agenda/' . slugify($title) . '?u=' . rawurlencode($uid), + 'guid' => $uid, 'pubDate' => $item['created'] ?? $item['start'] ?? null, 'description' => $description, ]; diff --git a/php/common.php b/php/common.php index b9eb3ac..f4a3113 100644 --- a/php/common.php +++ b/php/common.php @@ -98,6 +98,56 @@ function strip_html(?string $text): string return trim(preg_replace('/\s+/', ' ', $text)); } +/** + * Reproduit le slug d'URL genere par le site (cosmetique : le routeur + * JS de silly.be lit en realite le parametre `u` pour savoir quel item + * afficher, pas ce segment de chemin - mais autant coller a l'URL + * "officielle" telle qu'on la voit dans la barre d'adresse). + */ +function slugify(string $text): string +{ + $ascii = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $text); + if ($ascii === false) { + $ascii = $text; + } + $ascii = strtolower($ascii); + $ascii = preg_replace('/[^a-z0-9]+/', '-', $ascii); + return trim($ascii, '-'); +} + +/** + * Construit le HTML des liens vers les pieces jointes (PDF, etc.) + * renvoyees par l'API dans le champ "items" de chaque actualite/evenement. + */ +function attachments_html(array $item): string +{ + $html = ''; + foreach ($item['items'] ?? [] as $sub) { + $url = $sub['file']['download'] ?? $sub['targetUrl'] ?? null; + if (!$url) { + continue; + } + $label = $sub['title'] ?? basename($url); + $html .= '

' + . htmlspecialchars($label, ENT_QUOTES, 'UTF-8') . '

'; + } + return $html; +} + +/** + * Corps HTML complet d'un item (texte riche + pieces jointes), avec + * repli sur le resume court si le texte complet est vide. + */ +function full_body_html(array $item): string +{ + $body = trim($item['text_fr']['data'] ?? ''); + if ($body === '') { + $summary = strip_html($item['description_fr'] ?? $item['description'] ?? null); + $body = $summary !== '' ? '

' . htmlspecialchars($summary, ENT_QUOTES, 'UTF-8') . '

' : ''; + } + return $body . attachments_html($item); +} + function rfc822(?string $isoDate): string { try {