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

[RaceDepartmentBridge] added a bridge for racedepartment.com #1681

Merged
merged 5 commits into from
Dec 13, 2020
Merged
Changes from 3 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
55 changes: 55 additions & 0 deletions bridges/RaceDepartmentBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
class RaceDepartmentBridge extends FeedExpander {
const NAME = 'RaceDepartment News';
const URI = 'https://racedepartment.com/';
const DESCRIPTION = 'Get the latest (sim)racing news from RaceDepartment.';
const MAINTAINER = 't0stiman';

public function collectData() {
$this->collectExpandableDatas('https://www.racedepartment.com/news/archive.rss', 10);
}

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

//fetch page
$articlePage = getSimpleHTMLDOMCached($feedItem->link)
or returnServerError('Could not retrieve ' . $feedItem->link);
//extract article
$item['content'] = $articlePage->find('div.thfeature_firstPost', 0);

//convert iframes to links. meant for embedded videos.
foreach($item['content']->find('iframe') as $found) {
$pattern = '/src="(.+?)"/i';
if(preg_match($pattern, $found->outertext, $match)) {
$iframeUrl = $match[1];
$found->outertext = '<a href="' . $iframeUrl . '">' . $iframeUrl . '</a>';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to use regex to get src value

            $iframeUrl = $found->getAttribute("src");                                                                                 
            if ($iframeUrl) {                                                                                                         
                $found->outertext = '<a href="' . $iframeUrl . '">' . $iframeUrl . '</a>';                                            
            }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

}

//get rid of some elements we don't need
$to_remove_selectors = array(
'div.p-title', //title
'ul.listInline', //Thread starter, Start date
'div.rd_news_article_share_buttons',
'div.thfeature_firstPost-author',
'div.reactionsBar',
'footer',
'div.message-lastEdit',
'section.message-attachments'
);

foreach($to_remove_selectors as $selector) {
foreach($item['content']->find($selector) as $found) {
$found->outertext = '';
}
}

//category
$forumPath = $articlePage->find('div.breadcrumb', 0);
$pathElements = $forumPath->find('span');
$item['categories'] = array(end($pathElements)->innertext);

return $item;
}
}