From 0b526bfe395d18234f41a5724c90662f2aab80b4 Mon Sep 17 00:00:00 2001 From: User123698745 Date: Sat, 9 Nov 2024 02:23:12 +0100 Subject: [PATCH] [DRKBlutspendeBridge] add new bridge --- bridges/DRKBlutspendeBridge.php | 85 +++++++++++++++++++++++++++++++++ lib/utils.php | 8 ++++ 2 files changed, 93 insertions(+) create mode 100644 bridges/DRKBlutspendeBridge.php diff --git a/bridges/DRKBlutspendeBridge.php b/bridges/DRKBlutspendeBridge.php new file mode 100644 index 00000000000..3d935514c61 --- /dev/null +++ b/bridges/DRKBlutspendeBridge.php @@ -0,0 +1,85 @@ + [ + 'term' => [ + 'name' => 'PLZ / Ort', + 'required' => true, + 'exampleValue' => '12555', + ], + 'radius' => [ + 'name' => 'Umkreis in km', + 'type' => 'number', + 'exampleValue' => 10, + ], + 'limit_days' => [ + 'name' => 'Limit von Tagen', + 'title' => 'Nur Termine innerhalb der nächsten x Tagen', + 'type' => 'number', + 'exampleValue' => 28, + ], + 'limit_items' => [ + 'name' => 'Limit von Terminen', + 'title' => 'Nicht mehr als x Termine', + 'type' => 'number', + 'required' => true, + 'defaultValue' => 20, + ] + ] + ]; + + public function collectData() + { + $term = $this->getInput('term') ?? ''; + $radius = $this->getInput('radius') ?? ''; + $limitDays = intval($this->getInput('limit_days')); + $dateTo = $limitDays > 0 ? date('Y-m-d', time() + (60 * 60 * 24 * $limitDays)) : ''; + $url = self::URI . '/blutspendetermine/termine.rss?date_to=' . $dateTo . '&radius=' . $radius . '&term=' . $term; + $limitItems = intval($this->getInput('limit_items')); + $this->collectExpandableDatas($url, $limitItems); + } + + protected function parseItem(array $item) + { + $html = getSimpleHTMLDOM($item['uri']); + + $detailsElement = $html->find('.details', 0); + + $dateElement = $detailsElement->find('.datum', 0); + $dateLines = explode_lines($dateElement->plaintext); + + $addressElement = $detailsElement->find('.adresse', 0); + $addressLines = explode_lines($addressElement->plaintext); + + $infoElement = $detailsElement->find('.angebote > h4 + p', 0); + $info = $infoElement ? $infoElement->innertext : ''; + + $imageElements = $detailsElement->find('.fotos img'); + + $item['title'] = $dateLines[0] . ' ' . $dateLines[1] . ' ' . $addressLines[0] . ' - ' . $addressLines[1]; + + $item['content'] = <<{$dateLines[0]} {$dateLines[1]}

+

{$addressElement->innertext}

+

{$info}

+ HTML; + + foreach ($imageElements as $imageElement) { + $src = $imageElement->getAttribute('src'); + $item['content'] .= <<

+ HTML; + } + + $item['description'] = null; + + return $item; + } +} diff --git a/lib/utils.php b/lib/utils.php index 07806e7c256..851c2cfe9e1 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -147,6 +147,14 @@ function is_html(string $text): bool return strlen(strip_tags($text)) !== strlen($text); } +/** + * Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by line breaks. + */ +function explode_lines(string $text): array +{ + return array_map('trim', preg_split('/(\s*(\r\n|\n|\r)\s*)+/', $text)); +} + /** * Determines the MIME type from a URL/Path file extension. *