2022-03-22 23:15:40 +03:00
|
|
|
<?php
|
|
|
|
|
2023-08-25 13:34:35 +03:00
|
|
|
class CarThrottleBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2023-08-25 13:34:35 +03:00
|
|
|
const NAME = 'Car Throttle';
|
|
|
|
const URI = 'https://www.carthrottle.com/';
|
2022-03-22 23:15:40 +03:00
|
|
|
const DESCRIPTION = 'Get the latest car-related news from Car Throttle.';
|
|
|
|
const MAINTAINER = 't0stiman';
|
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
2023-08-25 13:34:35 +03:00
|
|
|
$news = getSimpleHTMLDOMCached(self::URI . 'news')
|
|
|
|
or returnServerError('could not retrieve page');
|
2022-03-22 23:15:40 +03:00
|
|
|
|
2023-08-25 13:34:35 +03:00
|
|
|
$this->items[] = [];
|
2022-03-22 23:15:40 +03:00
|
|
|
|
2023-08-25 13:34:35 +03:00
|
|
|
//for each post
|
|
|
|
foreach ($news->find('div.cmg-card') as $post) {
|
|
|
|
$item = [];
|
2022-03-22 23:15:40 +03:00
|
|
|
|
2023-08-25 13:34:35 +03:00
|
|
|
$titleElement = $post->find('div.title a.cmg-link')[0];
|
|
|
|
$item['uri'] = self::URI . $titleElement->getAttribute('href');
|
|
|
|
$item['title'] = $titleElement->innertext;
|
2022-03-22 23:15:40 +03:00
|
|
|
|
2023-08-25 13:34:35 +03:00
|
|
|
$articlePage = getSimpleHTMLDOMCached($item['uri'])
|
|
|
|
or returnServerError('could not retrieve page');
|
2022-03-22 23:15:40 +03:00
|
|
|
|
2023-10-12 20:49:04 +03:00
|
|
|
$authorDiv = $articlePage->find('div.author div');
|
|
|
|
if ($authorDiv) {
|
|
|
|
$item['author'] = $authorDiv[1]->innertext;
|
|
|
|
}
|
2022-03-22 23:15:40 +03:00
|
|
|
|
2023-10-12 20:49:04 +03:00
|
|
|
$dinges = $articlePage->find('div.main-body')[0] ?? null;
|
2023-08-25 13:34:35 +03:00
|
|
|
//remove ads
|
2023-10-12 20:49:04 +03:00
|
|
|
if ($dinges) {
|
|
|
|
foreach ($dinges->find('aside') as $ad) {
|
|
|
|
$ad->outertext = '';
|
|
|
|
$dinges->save();
|
|
|
|
}
|
2022-03-22 23:15:40 +03:00
|
|
|
}
|
|
|
|
|
2023-10-12 20:49:04 +03:00
|
|
|
$var = $articlePage->find('div.summary')[0] ?? '';
|
|
|
|
$var1 = $articlePage->find('figure.main-image')[0] ?? '';
|
|
|
|
$dinges1 = $dinges ?? '';
|
|
|
|
|
|
|
|
$item['content'] = $var .
|
|
|
|
$var1 .
|
|
|
|
$dinges1;
|
2022-03-22 23:15:40 +03:00
|
|
|
|
2023-08-25 13:34:35 +03:00
|
|
|
array_push($this->items, $item);
|
|
|
|
}
|
2022-03-22 23:15:40 +03:00
|
|
|
}
|
|
|
|
}
|