2019-02-12 17:12:04 +03:00
|
|
|
<?php
|
2022-04-13 00:37:05 +03:00
|
|
|
|
2019-02-12 17:12:04 +03:00
|
|
|
class RoadAndTrackBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const MAINTAINER = 'teromene';
|
|
|
|
const NAME = 'Road And Track Bridge';
|
|
|
|
const URI = 'https://www.roadandtrack.com/';
|
|
|
|
const CACHE_TIMEOUT = 86400; // 24h
|
|
|
|
const DESCRIPTION = 'Returns the latest news from Road & Track.';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-02-12 17:12:04 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2019-05-08 22:57:59 +03:00
|
|
|
$page = getSimpleHTMLDOM(self::URI);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-13 00:37:05 +03:00
|
|
|
$limit = 5;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-13 00:37:05 +03:00
|
|
|
foreach ($page->find('a.enk2x9t2') as $article) {
|
2019-05-08 22:57:59 +03:00
|
|
|
$this->items[] = $this->fetchArticle($article->href);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-13 00:37:05 +03:00
|
|
|
if (count($this->items) >= $limit) {
|
|
|
|
break;
|
|
|
|
}
|
2019-05-08 22:57:59 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2019-05-08 22:57:59 +03:00
|
|
|
private function fixImages($content)
|
|
|
|
{
|
2019-11-01 20:06:38 +03:00
|
|
|
$enclosures = [];
|
2019-05-08 22:57:59 +03:00
|
|
|
foreach ($content->find('img') as $image) {
|
|
|
|
$image->src = explode('?', $image->getAttribute('data-src'))[0];
|
|
|
|
$enclosures[] = $image->src;
|
2019-02-12 17:12:04 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-08 22:57:59 +03:00
|
|
|
foreach ($content->find('.embed-image-wrap, .content-lede-image-wrap') as $imgContainer) {
|
|
|
|
$imgContainer->style = '';
|
2019-02-12 17:12:04 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-08 22:57:59 +03:00
|
|
|
return $enclosures;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-08 22:57:59 +03:00
|
|
|
private function fetchArticle($articleLink)
|
|
|
|
{
|
|
|
|
$articleLink = self::URI . $articleLink;
|
|
|
|
$article = getSimpleHTMLDOM($articleLink);
|
|
|
|
$item = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-04-13 00:37:05 +03:00
|
|
|
$title = $article->find('.content-hed', 0);
|
|
|
|
if ($title) {
|
|
|
|
$item['title'] = $title->innertext;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-08 22:57:59 +03:00
|
|
|
$item['author'] = $article->find('.byline-name', 0)->innertext;
|
|
|
|
$item['timestamp'] = strtotime($article->find('.content-info-date', 0)->getAttribute('datetime'));
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-08 22:57:59 +03:00
|
|
|
$content = $article->find('.content-container', 0);
|
2022-04-13 00:37:05 +03:00
|
|
|
if ($content->find('.content-rail', 0) !== null) {
|
2019-05-08 22:57:59 +03:00
|
|
|
$content->find('.content-rail', 0)->innertext = '';
|
2022-04-13 00:37:05 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-08 22:57:59 +03:00
|
|
|
$enclosures = $this->fixImages($content);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-05-08 22:57:59 +03:00
|
|
|
$item['enclosures'] = $enclosures;
|
|
|
|
$item['content'] = $content;
|
|
|
|
return $item;
|
2019-02-12 17:12:04 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-02-12 17:12:04 +03:00
|
|
|
private function getArticleContent($article)
|
|
|
|
{
|
|
|
|
return getContents($article->contentUrl);
|
|
|
|
}
|
|
|
|
}
|