diff --git a/bridges/SkyArteBridge.php b/bridges/SkyArteBridge.php new file mode 100644 index 00000000..fb038ddf --- /dev/null +++ b/bridges/SkyArteBridge.php @@ -0,0 +1,146 @@ +url as $entry) { + $url = trim((string) $entry->loc); + if (!$url) { + continue; + } + + $json = $this->getJson($url); + if (!$json) { + continue; + } + + $event = $this->parseEventData($json); + + $this->items[] = [ + 'title' => $event['title'], + 'uri' => $url, + 'uid' => $url, + 'timestamp' => trim((string) $entry->lastmod), + 'content' => $event['content'], + 'categories' => $event['categories'], + 'enclosures' => $event['enclosures'], + ]; + + if (++$count >= self::MAX_ARTICLES) { + break; + } + } + } + + private function getJson(string $url): ?array + { + $html = getSimpleHTMLDOMCached($url, 259200); // 3 days + + if (!$html) { + return null; + } + + $script = $html->find('script#__NEXT_DATA__', 0); + if (!$script) { + return null; + } + + $decoded = json_decode($script->innertext, true); + return is_array($decoded) ? $decoded : null; + } + + private function parseEventData(array $json): array + { + $props = $json['props']['pageProps']['data'] ?? []; + $card = $props['card'] ?? []; + $info = $props['info'] ?? []; + + $event = [ + 'title' => $card['title']['typography']['text'] ?? '(untitled)', + 'content' => '', + 'categories' => [], + 'enclosures' => [], + ]; + + // Artist & Curators + $artist = $info['artist']['text'] ?? ''; + $curators = []; + if (!empty($info['curators']) && is_array($info['curators'])) { + foreach ($info['curators'] as $c) { + $curators[] = $c['text'] ?? ''; + } + } + + // Location, Dates, Categories + $location = ''; + $dates = ''; + if (!empty($card['informations']) && is_array($card['informations'])) { + foreach ($card['informations'] as $block) { + $icon = $block['iconRight']['Icon'] ?? ''; + if ($icon === 'SvgLocation') { + $location = $block['textRight']['text'] ?? ''; + } + if ($icon === 'SvgEventEmpty') { + $dates = $block['textRight']['text'] ?? ''; + } + if (!empty($block['badge']['label']['text'])) { + $event['categories'][] = $block['badge']['label']['text']; + } + } + } + + // Enclosure + if (!empty($card['image']['src'])) { + $event['enclosures'][] = $card['image']['src']; + } + + // HTML content + $content = ''; + if ($artist) { + $content .= '

Artista: ' . htmlspecialchars($artist) . '

'; + } + + if ($curators) { + $content .= '

Curatori: ' . htmlspecialchars(implode(', ', $curators)) . '

'; + } + + if ($location) { + $content .= '

Luogo: ' . htmlspecialchars($location) . '

'; + } + + if ($dates) { + $content .= '

Periodo: ' . htmlspecialchars($dates) . '

'; + } + + $description = $props['description'] ?? ''; + if ($description) { + $description = preg_replace('~

(.*?)

~i', '$1', $description); + $description = nl2br($description); + $content .= '


' . $description . '

'; + } + + $event['content'] = $content; + return $event; + } +}