aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sebastian Wolf <117176763+swofl@users.noreply.github.com> 2024-11-23 18:54:21 +0100
committerGravatar GitHub <noreply@github.com> 2024-11-23 18:54:21 +0100
commita6e8760726c468d48ea45a3bb94577b7b94c08a8 (patch)
tree610ed3ef21cc616fa2f3ee0eeba1b841ad23e575
parent9457e075f6a15c702bed94cf84b62ce949815dc9 (diff)
downloadrss-bridge-a6e8760726c468d48ea45a3bb94577b7b94c08a8.tar.gz
rss-bridge-a6e8760726c468d48ea45a3bb94577b7b94c08a8.tar.zst
rss-bridge-a6e8760726c468d48ea45a3bb94577b7b94c08a8.zip
[FragDenStaatBridge] add new bridge (#4330)
-rw-r--r--bridges/FragDenStaatBridge.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/bridges/FragDenStaatBridge.php b/bridges/FragDenStaatBridge.php
new file mode 100644
index 00000000..aee1885c
--- /dev/null
+++ b/bridges/FragDenStaatBridge.php
@@ -0,0 +1,78 @@
+<?php
+
+class FragDenStaatBridge extends BridgeAbstract
+{
+ const MAINTAINER = 'swofl';
+ const NAME = 'FragDenStaat';
+ const URI = 'https://fragdenstaat.de';
+ const CACHE_TIMEOUT = 2 * 60 * 60; // 2h
+ const DESCRIPTION = 'Get latest blog posts from FragDenStaat Exklusiv';
+ const PARAMETERS = [ [
+ 'qLimit' => [
+ 'name' => 'Query Limit',
+ 'title' => 'Amount of articles to query',
+ 'type' => 'number',
+ 'defaultValue' => 5,
+ ],
+ ] ];
+
+ protected function parseTeaser($teaser)
+ {
+ $result = [];
+
+ $header = $teaser->find('h3 > a', 0);
+ $result['title'] = $header->plaintext;
+ $result['uri'] = static::URI . $header->href;
+ $result['enclosures'] = [];
+ $result['enclosures'][] = $teaser->find('img', 0)->src;
+ $result['uid'] = hash('sha256', $result['title']);
+ $result['timestamp'] = strtotime($teaser->find('time', 0)->getAttribute('datetime'));
+
+ return $result;
+ }
+
+ public function collectData()
+ {
+ $html = getSimpleHTMLDOM(self::URI . '/artikel/exklusiv/');
+
+ $queryLimit = (int) $this->getInput('qLimit');
+ if ($queryLimit > 12) {
+ $queryLimit = 12;
+ }
+
+ $teasers = [];
+
+ $teaserElements = $html->find('article');
+
+ for ($i = 0; $i < $queryLimit; $i++) {
+ array_push($teasers, $this->parseTeaser($teaserElements[$i]));
+ }
+
+ foreach ($teasers as $article) {
+ $articleHtml = getSimpleHTMLDOMCached($article['uri'], static::CACHE_TIMEOUT * 6);
+ $articleCore = $articleHtml->find('article.blog-article', 0);
+
+ $content = '';
+
+ $lead = $articleCore->find('div.lead > p', 0)->innertext;
+
+ $content .= '<h2>' . $lead . '</h2>';
+
+ foreach ($articleCore->find('div.blog-content > p, div.blog-content > h3') as $paragraph) {
+ $content .= $paragraph->outertext;
+ }
+
+ $article['content'] = '<img src="' . $article['enclosures'][0] . '"/>' . $content;
+
+ $article['author'] = '';
+
+ foreach ($articleCore->find('a[rel="author"]') as $author) {
+ $article['author'] .= $author->innertext . ', ';
+ }
+
+ $article['author'] = rtrim($article['author'], ', ');
+
+ $this->items[] = $article;
+ }
+ }
+}