Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HardwareInfoBridge] Created a bridge for hardware.info #2232

Merged
merged 3 commits into from
Aug 10, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions bridges/HardwareInfoBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
class HardwareInfoBridge extends FeedExpander
{
const NAME = 'Hardware Info Bridge';
const URI = 'https://HardwareInfo.net/';
const DESCRIPTION = 'Tech news from hardware.info (Dutch)';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardware.info or hardware.net? First does not resolve for real, second has problems with certificate.

Copy link
Contributor Author

@t0stiman t0stiman Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://hardware.info/ , which redirects to https://nl.hardware.info/
i put the wrong value in URI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const MAINTAINER = 't0stiman';

public function collectData()
{
$this->collectExpandableDatas('https://nl.hardware.info/updates/all.rss', 20);
}

protected function parseItem($feedItem)
{
$item = parent::parseItem($feedItem);

//get full article
$articlePage = getSimpleHTMLDOMCached('$feedItem->link');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'$feedItem->link' should be without quotes at all.
That is why bridge errors "Could not resolve host: $feedItem->link"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops... fixed


$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 = '<a href="' . $iframeUrl . '">' . $iframeUrl . '</a>';
}
}

$item['content'] = $article;
return $item;
}
}