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

[PhoronixBridge] support multipage and embed benchmarks #2522

Merged
merged 5 commits into from
Mar 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 46 additions & 3 deletions bridges/PhoronixBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,60 @@ class PhoronixBridge extends FeedExpander {
const URI = 'https://www.phoronix.com';
const CACHE_TIMEOUT = 3600;
const DESCRIPTION = 'RSS feed for Linux news website Phoronix';
const PARAMETERS = array(array(
'n' => array(
'name' => 'Limit',
'type' => 'number',
'required' => false,
'title' => 'Maximum number of items to return',
'defaultValue' => 10
),
'svgAsImg' => array(
'name' => 'SVG in "image" tag',
'type' => 'checkbox',
'title' => 'Some benchmarks are exported as SVG with "object" tag,
but some RSS readers don\'t support this. "img" tag are supported by most browsers',
'defaultValue' => false
),
));

public function collectData(){
$this->collectExpandableDatas('https://www.phoronix.com/rss.php', 15);
$this->collectExpandableDatas('https://www.phoronix.com/rss.php', $this->getInput('n'));
}

protected function parseItem($newsItem){
$item = parent::parseItem($newsItem);
// $articlePage gets the entire page's contents
$articlePage = getSimpleHTMLDOM($newsItem->link);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$articlePage = getSimpleHTMLDOM($newsItem->link);
$articlePage = getSimpleHTMLDOM($newsItem->link);
$articlePage = defaultLinkTo($articlePage, $this->getURI());

Copy link
Contributor

Choose a reason for hiding this comment

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

this should fix the issue that the posts have a category image which's link is relative:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

defaultLinkTo description

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review and the suggestion. I didn't notice this because TT-RSS was doing the job itself…

$article = $articlePage->find('.content', 0);
$item['content'] = $article;
$articlePage = defaultLinkTo($articlePage, $this->getURI());
// Extract final link. From Facebook's like plugin.
parse_str(parse_url($articlePage->find('iframe[src^=//www.facebook.com/plugins]', 0), PHP_URL_QUERY), $facebookQuery);
if (array_key_exists('href', $facebookQuery)) {
$newsItem->link = $facebookQuery['href'];
}
$item['content'] = $this->extractContent($articlePage);

$pages = $articlePage->find('.pagination a[!title]');
foreach ($pages as $page) {
$pageURI = urljoin($newsItem->link, html_entity_decode($page->href));
$page = getSimpleHTMLDOM($pageURI);
$item['content'] .= $this->extractContent($page);
}
return $item;
}

private function extractContent($page){
$content = $page->find('.content', 0);
$objects = $content->find('script[src^=//openbenchmarking.org]');
foreach ($objects as $object) {
$objectSrc = preg_replace('/p=0/', 'p=2', $object->src);
if ($this->getInput('svgAsImg')) {
$object->outertext = '<a href="' . $objectSrc . '"><img src="' . $objectSrc . '"/></a>';
} else {
$object->outertext = '<object data="' . $objectSrc . '" type="image/svg+xml"></object>';
}
}
$content = stripWithDelimiters($content, '<script', '</script>');
return $content;
}
}