-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
<?php | ||
|
||
class CarThrottleBridge extends FeedExpander | ||
class CarThrottleBridge extends BridgeAbstract | ||
{ | ||
const NAME = 'Car Throttle '; | ||
const URI = 'https://www.carthrottle.com'; | ||
const NAME = 'Car Throttle'; | ||
const URI = 'https://www.carthrottle.com/'; | ||
const DESCRIPTION = 'Get the latest car-related news from Car Throttle.'; | ||
const MAINTAINER = 't0stiman'; | ||
|
||
public function collectData() | ||
{ | ||
$this->collectExpandableDatas('https://www.carthrottle.com/rss', 10); | ||
} | ||
$news = getSimpleHTMLDOMCached(self::URI . 'news') | ||
or returnServerError('could not retrieve page'); | ||
|
||
protected function parseItem($feedItem) | ||
{ | ||
$item = parent::parseItem($feedItem); | ||
$this->items[] = []; | ||
|
||
//fetch page | ||
$articlePage = getSimpleHTMLDOMCached($feedItem->link) | ||
or returnServerError('Could not retrieve ' . $feedItem->link); | ||
//for each post | ||
foreach ($news->find('div.cmg-card') as $post) { | ||
$item = []; | ||
|
||
$subtitle = $articlePage->find('p.standfirst', 0); | ||
$article = $articlePage->find('div.content_field', 0); | ||
$titleElement = $post->find('div.title a.cmg-link')[0]; | ||
$item['uri'] = self::URI . $titleElement->getAttribute('href'); | ||
$item['title'] = $titleElement->innertext; | ||
|
||
$item['content'] = str_get_html($subtitle . $article); | ||
$articlePage = getSimpleHTMLDOMCached($item['uri']) | ||
or returnServerError('could not retrieve page'); | ||
|
||
//convert <iframe>s to <a>s. meant for embedded videos. | ||
foreach ($item['content']->find('iframe') as $found) { | ||
$iframeUrl = $found->getAttribute('src'); | ||
$item['author'] = $articlePage->find('div.author div')[1]->innertext; | ||
|
||
if ($iframeUrl) { | ||
$found->outertext = '<a href="' . $iframeUrl . '">' . $iframeUrl . '</a>'; | ||
$dinges = $articlePage->find('div.main-body')[0]; | ||
//remove ads | ||
foreach ($dinges->find('aside') as $ad) { | ||
$ad->outertext = ''; | ||
$dinges->save(); | ||
} | ||
} | ||
|
||
//remove scripts from the text | ||
foreach ($item['content']->find('script') as $remove) { | ||
$remove->outertext = ''; | ||
} | ||
$item['content'] = $articlePage->find('div.summary')[0] . | ||
$articlePage->find('figure.main-image')[0] . | ||
$dinges; | ||
|
||
return $item; | ||
//add the item to the list | ||
array_push($this->items, $item); | ||
} | ||
} | ||
} |