123 lines
4.2 KiB
PHP
123 lines
4.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
class RadioGongWuerzburgBridge extends BridgeAbstract
|
|
{
|
|
const NAME = 'Radio Gong Würzburg News';
|
|
const URI = 'https://www.radiogong.com/';
|
|
const DESCRIPTION = 'Aktuelle Nachrichten von Radio Gong Würzburg';
|
|
const MAINTAINER = 'Akamaru';
|
|
const CACHE_TIMEOUT = 3600; // 1 Stunde
|
|
|
|
public function getIcon()
|
|
{
|
|
return 'https://www.google.com/s2/favicons?domain=www.radiogong.com&sz=32';
|
|
}
|
|
|
|
public function collectData()
|
|
{
|
|
$url = 'https://www.radiogong.com/aktuelles/news';
|
|
$html = getSimpleHTMLDOM($url);
|
|
|
|
if (!$html) {
|
|
throw new \Exception('Konnte die Radio Gong Würzburg News-Seite nicht laden: ' . $url);
|
|
}
|
|
|
|
// Finde alle News-Artikel
|
|
$newsItems = $html->find('.teaser-list-item');
|
|
|
|
if (empty($newsItems)) {
|
|
throw new \Exception('Keine News-Artikel gefunden auf der Seite');
|
|
}
|
|
|
|
foreach ($newsItems as $newsItem) {
|
|
$item = [];
|
|
|
|
// Link und Titel extrahieren
|
|
$link = $newsItem->find('a', 0);
|
|
if (!$link) {
|
|
continue;
|
|
}
|
|
|
|
$item['uri'] = $link->href;
|
|
if (strpos($item['uri'], 'http') !== 0) {
|
|
$item['uri'] = self::URI . ltrim($item['uri'], '/');
|
|
}
|
|
|
|
// Titel aus h3
|
|
$titleElement = $newsItem->find('h3', 0);
|
|
if ($titleElement) {
|
|
$item['title'] = trim($titleElement->plaintext);
|
|
} else {
|
|
continue; // Überspringe Artikel ohne Titel
|
|
}
|
|
|
|
// Caption mit Datum und Kategorie extrahieren
|
|
// Format: "30.11.2025, 19:17 Uhr in Lokales"
|
|
$caption = $newsItem->find('.caption', 0);
|
|
if ($caption) {
|
|
$captionText = trim($caption->plaintext);
|
|
|
|
// Datum extrahieren (DD.MM.YYYY, HH:MM Uhr)
|
|
if (preg_match('/(\d{2})\.(\d{2})\.(\d{4}),\s+(\d{2}):(\d{2})\s+Uhr/', $captionText, $matches)) {
|
|
$day = $matches[1];
|
|
$month = $matches[2];
|
|
$year = $matches[3];
|
|
$hour = $matches[4];
|
|
$minute = $matches[5];
|
|
|
|
// Erstelle Timestamp
|
|
$item['timestamp'] = strtotime("$year-$month-$day $hour:$minute:00");
|
|
}
|
|
|
|
// Kategorie extrahieren (Text nach "in ")
|
|
if (preg_match('/in\s+(.+)$/i', $captionText, $categoryMatch)) {
|
|
$item['categories'] = [trim($categoryMatch[1])];
|
|
}
|
|
}
|
|
|
|
// Bild extrahieren
|
|
$image = $newsItem->find('img', 0);
|
|
if ($image) {
|
|
// Verwende data-srcset falls vorhanden, sonst src
|
|
$imageUrl = null;
|
|
|
|
if (isset($image->{'data-srcset'}) && !empty($image->{'data-srcset'})) {
|
|
// Nimm das erste Bild aus dem srcset
|
|
$srcset = $image->{'data-srcset'};
|
|
if (preg_match('/^(https?:\/\/[^\s]+)/', $srcset, $imageMatch)) {
|
|
$imageUrl = $imageMatch[1];
|
|
}
|
|
} elseif (isset($image->src) && !empty($image->src) && strpos($image->src, 'data:image') !== 0) {
|
|
// Nur normale URLs verwenden, keine base64-codierten Bilder
|
|
$imageUrl = $image->src;
|
|
}
|
|
|
|
if ($imageUrl) {
|
|
// Bereinige die URL (entferne .webp falls vorhanden und nimm die jpg-Variante)
|
|
$imageUrl = str_replace('.webp', '', $imageUrl);
|
|
|
|
$item['enclosures'] = [$imageUrl];
|
|
$item['content'] = '<img src="' . htmlspecialchars($imageUrl) . '" alt="' . htmlspecialchars($item['title']) . '">';
|
|
}
|
|
}
|
|
|
|
// Fallback für Timestamp
|
|
if (!isset($item['timestamp'])) {
|
|
$item['timestamp'] = time();
|
|
}
|
|
|
|
// Autor setzen
|
|
$item['author'] = 'Radio Gong Würzburg';
|
|
|
|
$this->items[] = $item;
|
|
|
|
// Limitiere auf 20 Artikel
|
|
if (count($this->items) >= 20) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|