mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-09 16:38:50 +00:00
[NordbayernBridge] Fix Bridge (#2675)
This commit is contained in:
parent
9b82ff352d
commit
adeaede930
@ -47,48 +47,54 @@ class NordbayernBridge extends BridgeAbstract {
|
|||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
private function getValidImage($picture) {
|
||||||
|
$img = $picture->find('img', 0);
|
||||||
|
if ($img) {
|
||||||
|
$imgUrl = $img->src;
|
||||||
|
if(($imgUrl != '/img/nb/logo-vnp.png') &&
|
||||||
|
($imgUrl != '/img/nn/logo-vnp.png') &&
|
||||||
|
($imgUrl != '/img/nb/logo-nuernberger-nachrichten.png') &&
|
||||||
|
($imgUrl != '/img/nb/logo-nordbayern.png') &&
|
||||||
|
($imgUrl != '/img/nn/logo-nuernberger-nachrichten.png') &&
|
||||||
|
($imgUrl != '/img/nb/logo-erlanger-nachrichten.png')) {
|
||||||
|
return '<br><img src="' . $imgUrl . '">';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
private function getUseFullContent($rawContent) {
|
private function getUseFullContent($rawContent) {
|
||||||
$content = '';
|
$content = '';
|
||||||
foreach($rawContent->children as $element) {
|
foreach($rawContent->children as $element) {
|
||||||
if($element->tag === 'p' || $element->tag === 'h3') {
|
if($element->tag === 'p' || $element->tag === 'h3') {
|
||||||
$content .= $element;
|
$content .= $element;
|
||||||
}
|
} else if($element->tag === 'main') {
|
||||||
if($element->tag === 'main') {
|
|
||||||
$content .= self::getUseFullContent($element->find('article', 0));
|
$content .= self::getUseFullContent($element->find('article', 0));
|
||||||
}
|
} else if($element->tag === 'header') {
|
||||||
if($element->tag === 'header') {
|
|
||||||
$content .= self::getUseFullContent($element);
|
$content .= self::getUseFullContent($element);
|
||||||
|
} else if($element->tag === 'div' &&
|
||||||
|
!str_contains($element->class, 'article__infobox') &&
|
||||||
|
!str_contains($element->class, 'authorinfo')) {
|
||||||
|
$content .= self::getUseFullContent($element);
|
||||||
|
} else if($element->tag == 'section' &&
|
||||||
|
(str_contains($element->class, 'article__richtext') ||
|
||||||
|
str_contains($element->class, 'article__context'))) {
|
||||||
|
$content .= self::getUseFullContent($element);
|
||||||
|
} else if($element->tag == 'picture') {
|
||||||
|
$content .= self::getValidImage($element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getValidImages($pictures) {
|
|
||||||
|
|
||||||
if(empty($pictures)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
$images = array();
|
|
||||||
for ($i = 0; $i < count($pictures); $i++) {
|
|
||||||
$img = $pictures[$i]->find('img', 0);
|
|
||||||
if ($img) {
|
|
||||||
$imgUrl = $img->src;
|
|
||||||
if (strcmp($imgUrl, 'https://www.nordbayern.de/img/nb/logo-vnp.png') !== 0) {
|
|
||||||
array_push($images, $imgUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $images;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function handleArticle($link) {
|
private function handleArticle($link) {
|
||||||
$item = array();
|
$item = array();
|
||||||
$article = getSimpleHTMLDOM($link);
|
$article = getSimpleHTMLDOM($link);
|
||||||
defaultLinkTo($article, self::URI);
|
defaultLinkTo($article, self::URI);
|
||||||
|
$content = $article->find('article[id=article]', 0);
|
||||||
$item['uri'] = $link;
|
$item['uri'] = $link;
|
||||||
|
|
||||||
$author = $article->find('[class=article__author extrabold]', 0);
|
$author = $article->find('[id="openAuthor"]', 0);
|
||||||
if ($author) {
|
if ($author) {
|
||||||
$item['author'] = $author->plaintext;
|
$item['author'] = $author->plaintext;
|
||||||
}
|
}
|
||||||
@ -105,38 +111,17 @@ class NordbayernBridge extends BridgeAbstract {
|
|||||||
}
|
}
|
||||||
$item['content'] = '';
|
$item['content'] = '';
|
||||||
|
|
||||||
//first get images from content
|
|
||||||
$pictures = $article->find('picture');
|
|
||||||
$images = self::getValidImages($pictures);
|
|
||||||
if(!empty($images)) {
|
|
||||||
// If there is an author info block
|
|
||||||
// the first immage will be the portrait of the author
|
|
||||||
// and not the article banner. The banner in this
|
|
||||||
// case will be the second image.
|
|
||||||
// Also skip first image, as its always NN logo.
|
|
||||||
if ($article->find('a[id="openAuthor"]', 0) == null) {
|
|
||||||
$bannerUrl = isset($images[1]) ? $images[1] : null;
|
|
||||||
} else {
|
|
||||||
$bannerUrl = isset($images[2]) ? $images[2] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$item['content'] .= '<img src="' . $bannerUrl . '">';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($article->find('section[class*=article__richtext]', 0) == null) {
|
if ($article->find('section[class*=article__richtext]', 0) == null) {
|
||||||
$content = $article->find('div[class*=modul__teaser]', 0)
|
$content = $article->find('div[class*=modul__teaser]', 0)
|
||||||
->find('p', 0);
|
->find('p', 0);
|
||||||
$item['content'] .= $content;
|
$item['content'] .= $content;
|
||||||
} else {
|
} else {
|
||||||
$content = $article->find('section[class*=article__richtext]', 0)
|
//$content = $article->find('section[class*=article__richtext]', 0)
|
||||||
->find('div', 0)->find('div', 0);
|
// ->find('div', 0)->find('div', 0);
|
||||||
|
$content = $article->find('article', 0);
|
||||||
$item['content'] .= self::getUseFullContent($content);
|
$item['content'] .= self::getUseFullContent($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
for($i = 1; $i < count($images); $i++) {
|
|
||||||
$item['content'] .= '<img src="' . $images[$i] . '">';
|
|
||||||
}
|
|
||||||
|
|
||||||
// exclude police reports if desired
|
// exclude police reports if desired
|
||||||
if($this->getInput('policeReports') ||
|
if($this->getInput('policeReports') ||
|
||||||
!str_contains($item['content'], 'Hier geht es zu allen aktuellen Polizeimeldungen.')) {
|
!str_contains($item['content'], 'Hier geht es zu allen aktuellen Polizeimeldungen.')) {
|
||||||
|
Loading…
Reference in New Issue
Block a user