From f3f934ed8b7e99d298361c026b457811f9364053 Mon Sep 17 00:00:00 2001 From: t0stiman <18124323+t0stiman@users.noreply.github.com> Date: Tue, 10 Aug 2021 20:00:32 +0200 Subject: [PATCH] [HardwareInfoBridge] Add bridge (#2232) --- bridges/HardwareInfoBridge.php | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 bridges/HardwareInfoBridge.php diff --git a/bridges/HardwareInfoBridge.php b/bridges/HardwareInfoBridge.php new file mode 100644 index 00000000..ae79e0fd --- /dev/null +++ b/bridges/HardwareInfoBridge.php @@ -0,0 +1,66 @@ +collectExpandableDatas('https://nl.hardware.info/updates/all.rss', 20); + } + + protected function parseItem($feedItem) + { + $item = parent::parseItem($feedItem); + + //get full article + $articlePage = getSimpleHTMLDOMCached($feedItem->link); + + $article = $articlePage->find('div.article__content', 0); + + //everything under the social bar is not part of the article, remove it + $reachedEndOfArticle = false; + + foreach($article->find('*') as $child) { + + if(!$reachedEndOfArticle && isset($child->attr['class']) + && $child->attr['class'] == 'article__content__social-bar') { + $reachedEndOfArticle = true; + } + + if($reachedEndOfArticle) { + $child->outertext = ''; + } + } + + //get rid of some more elements we don't need + $to_remove_selectors = array( + 'script', + 'div.incontent', + 'div.article__content__social-bar', + 'div#revealNewsTip', + 'div.article__previous_next' + ); + + foreach($to_remove_selectors as $selector) { + foreach($article->find($selector) as $found) { + $found->outertext = ''; + } + } + + // convert iframes to links. meant for embedded YouTube videos. + foreach($article->find('iframe') as $found) { + + $iframeUrl = $found->getAttribute('src'); + + if ($iframeUrl) { + $found->outertext = '' . $iframeUrl . ''; + } + } + + $item['content'] = $article; + return $item; + } +}