diff --git a/bridges/NordbayernBridge.php b/bridges/NordbayernBridge.php index e6608406..8fe7f5a8 100644 --- a/bridges/NordbayernBridge.php +++ b/bridges/NordbayernBridge.php @@ -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 '
'; + } + } + return ''; + } + private function getUseFullContent($rawContent) { $content = ''; foreach($rawContent->children as $element) { if($element->tag === 'p' || $element->tag === 'h3') { $content .= $element; - } - if($element->tag === 'main') { + } else if($element->tag === 'main') { $content .= self::getUseFullContent($element->find('article', 0)); - } - if($element->tag === 'header') { + } else if($element->tag === 'header') { $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; } - 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) { $item = array(); $article = getSimpleHTMLDOM($link); defaultLinkTo($article, self::URI); - + $content = $article->find('article[id=article]', 0); $item['uri'] = $link; - $author = $article->find('[class=article__author extrabold]', 0); + $author = $article->find('[id="openAuthor"]', 0); if ($author) { $item['author'] = $author->plaintext; } @@ -105,38 +111,17 @@ class NordbayernBridge extends BridgeAbstract { } $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'] .= ''; - } - if ($article->find('section[class*=article__richtext]', 0) == null) { $content = $article->find('div[class*=modul__teaser]', 0) ->find('p', 0); $item['content'] .= $content; } else { - $content = $article->find('section[class*=article__richtext]', 0) - ->find('div', 0)->find('div', 0); + //$content = $article->find('section[class*=article__richtext]', 0) + // ->find('div', 0)->find('div', 0); + $content = $article->find('article', 0); $item['content'] .= self::getUseFullContent($content); } - for($i = 1; $i < count($images); $i++) { - $item['content'] .= ''; - } - // exclude police reports if desired if($this->getInput('policeReports') || !str_contains($item['content'], 'Hier geht es zu allen aktuellen Polizeimeldungen.')) {