Open
Description
Bridge request
General information
-
Host URI for the bridge (i.e.
https://github.com
):
https://www.wn.de
-
Which information would you like to see?
Title, Date, Text, Pictures -
How should the information be displayed/formatted?
Text ordered as on website -
Which of the following parameters do you expect?
- Title
- URI (link to the original article)
- Author
- Timestamp
- Content (the content of the article)
- Enclosures (pictures, videos, etc...)
- Categories (categories, tags, etc...)
Options
- Limit number of returned items
- Default limit: 5
- Load full articles
- Cache articles (articles are stored in a local cache on first request): yes
- Cache timeout (max = 24 hours): 24 hours
- Balance requests (RSS-Bridge uses cached versions to reduce bandwith usage)
- Timeout (default = 5 minutes, max = 24 hours): 5 minutes
Code
Please review my code below. It should work but I'm not sure if there are any optimizations because I'm new to writing bridges.
<?php
class WestfaelischeNachrichtenBridge extends FeedExpander {
const MAINTAINER = 'redcluster';
const NAME = 'Westfälische Nachrichten Bridge';
const URI = 'https://wn.de/';
const CACHE_TIMEOUT = 3600; // 1h
const DESCRIPTION = 'Returns the full articles instead of only the intro';
const PARAMETERS = array(array(
'category' => array(
'name' => 'Category',
'type' => 'list',
'values' => array(
'Alle Nachrichten'
=> 'https://www.wn.de/rss/feed',
'Ascheberg'
=> 'https://www.wn.de/rss/feed?subcategory=/muensterland/kreis-coesfeld/ascheberg',
'Drensteinfurt'
=> 'https://www.wn.de/rss/feed?subcategory=/muensterland/kreis-warendorf/drensteinfurt'
)
),
'limit' => array(
'name' => 'Limit',
'type' => 'number',
'required' => false,
'title' => 'Specify number of full articles to return',
'defaultValue' => 5
)
));
const LIMIT = 5;
public function collectData() {
$this->collectExpandableDatas(
$this->getInput('category'),
$this->getInput('limit') ?: static::LIMIT
);
}
protected function parseItem($feedItem) {
$item = parent::parseItem($feedItem);
$uri = $item['uri'];
$article = getSimpleHTMLDOMCached($uri)
or returnServerError('Could not open article: ' . $uri);
if ($article) {
$article = defaultLinkTo($article, $uri);
$item = $this->addArticleToItem($item, $article);
}
return $item;
}
private function addArticleToItem($item, $article) {
if($author = $article->find('p[class="fp-article-heading__author"]', 0))
$item['author'] = $author->plaintext;
$city = $article->find('p[class="fp-article-heading__city"]', 0)->innertext;
$excerpt = $article->find('p[class="fp-article-heading__excerpt"]', 0)->innertext;
$content = $article->find('p[class="fp-paragraph"]', 0)->innertext;
$pictureUrl = $item['enclosures'][0];
$picture = "<img src=\"" . $pictureUrl . "\">";
$content = "";
foreach($article->find('p[class="fp-paragraph"]') as $element) {
$content .= $element->innertext . "\n\n";
}
$item['content'] = $city." - ".$excerpt." \n".$picture." \n".$content;
$item['uid'] = $item['title'];
return $item;
}
}