2021-08-10 21:00:32 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2021-08-10 21:00:32 +03:00
|
|
|
class HardwareInfoBridge extends FeedExpander
|
|
|
|
{
|
2022-07-01 16:10:30 +03:00
|
|
|
const NAME = 'Hardware Info Bridge';
|
|
|
|
const URI = 'https://nl.hardware.info/';
|
|
|
|
const DESCRIPTION = 'Tech news from hardware.info (Dutch)';
|
|
|
|
const MAINTAINER = 't0stiman';
|
2024-02-04 20:28:12 +03:00
|
|
|
const DONATION_URI = 'https://ko-fi.com/tostiman';
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2023-10-13 01:25:34 +03:00
|
|
|
$this->collectExpandableDatas('https://nl.hardware.info/updates/all.rss', 10);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2023-10-13 02:59:05 +03:00
|
|
|
protected function parseItem(array $item)
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2023-10-13 01:25:34 +03:00
|
|
|
$itemUrl = $item['uri'];
|
|
|
|
$articlePage = getSimpleHTMLDOMCached($itemUrl);
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
$article = $articlePage->find('div.article__content', 0);
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
//everything under the social bar is not part of the article, remove it
|
|
|
|
$reachedEndOfArticle = false;
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
foreach ($article->find('*') as $child) {
|
|
|
|
if (
|
|
|
|
!$reachedEndOfArticle && isset($child->attr['class'])
|
|
|
|
&& $child->attr['class'] == 'article__content__social-bar'
|
|
|
|
) {
|
|
|
|
$reachedEndOfArticle = true;
|
|
|
|
}
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
if ($reachedEndOfArticle) {
|
|
|
|
$child->outertext = '';
|
|
|
|
}
|
|
|
|
}
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
//get rid of some more elements we don't need
|
|
|
|
$to_remove_selectors = [
|
|
|
|
'script',
|
|
|
|
'div.incontent',
|
|
|
|
'div.article__content__social-bar',
|
|
|
|
'div#revealNewsTip',
|
|
|
|
'div.article__previous_next'
|
|
|
|
];
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
foreach ($to_remove_selectors as $selector) {
|
|
|
|
foreach ($article->find($selector) as $found) {
|
|
|
|
$found->outertext = '';
|
|
|
|
}
|
|
|
|
}
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
// convert iframes to links. meant for embedded YouTube videos.
|
|
|
|
foreach ($article->find('iframe') as $found) {
|
|
|
|
$iframeUrl = $found->getAttribute('src');
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
if ($iframeUrl) {
|
|
|
|
$found->outertext = '<a href="' . $iframeUrl . '">' . $iframeUrl . '</a>';
|
|
|
|
}
|
|
|
|
}
|
2021-08-10 21:00:32 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
$item['content'] = $article;
|
|
|
|
return $item;
|
|
|
|
}
|
2021-08-10 21:00:32 +03:00
|
|
|
}
|