mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-14 20:21:14 +03:00
Fix car throttle bridge (#3925)
This commit is contained in:
parent
7c89712837
commit
d175bab58e
3 changed files with 99 additions and 21 deletions
|
@ -6,46 +6,122 @@ class CarThrottleBridge extends BridgeAbstract
|
|||
const URI = 'https://www.carthrottle.com/';
|
||||
const DESCRIPTION = 'Get the latest car-related news from Car Throttle.';
|
||||
const MAINTAINER = 't0stiman';
|
||||
const DONATION_URI = 'https://ko-fi.com/tostiman';
|
||||
|
||||
const PARAMETERS = [
|
||||
'Show articles from these categories:' => [
|
||||
'news' => [
|
||||
'name' => 'news',
|
||||
'type' => 'checkbox'
|
||||
],
|
||||
'reviews' => [
|
||||
'name' => 'reviews',
|
||||
'type' => 'checkbox'
|
||||
],
|
||||
'features' => [
|
||||
'name' => 'features',
|
||||
'type' => 'checkbox'
|
||||
],
|
||||
'videos' => [
|
||||
'name' => 'videos',
|
||||
'type' => 'checkbox'
|
||||
],
|
||||
'gaming' => [
|
||||
'name' => 'gaming',
|
||||
'type' => 'checkbox'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
$news = getSimpleHTMLDOMCached(self::URI . 'news');
|
||||
$this->items = [];
|
||||
|
||||
$this->items[] = [];
|
||||
$this->handleCategory('news');
|
||||
$this->handleCategory('reviews');
|
||||
$this->handleCategory('features');
|
||||
$this->handleCategory2('videos', 'video');
|
||||
$this->handleCategory('gaming');
|
||||
}
|
||||
|
||||
private function handleCategory($category)
|
||||
{
|
||||
if ($this->getInput($category)) {
|
||||
$this->getArticles($category);
|
||||
}
|
||||
}
|
||||
|
||||
private function handleCategory2($categoryParameter, $categoryURLname)
|
||||
{
|
||||
if ($this->getInput($categoryParameter)) {
|
||||
$this->getArticles($categoryURLname);
|
||||
}
|
||||
}
|
||||
|
||||
private function getArticles($category)
|
||||
{
|
||||
$categoryPage = getSimpleHTMLDOMCached(self::URI . $category);
|
||||
|
||||
//for each post
|
||||
foreach ($news->find('div.cmg-card') as $post) {
|
||||
foreach ($categoryPage->find('div.cmg-card') as $post) {
|
||||
$item = [];
|
||||
|
||||
$titleElement = $post->find('div.title a.cmg-link')[0];
|
||||
$item['uri'] = self::URI . $titleElement->getAttribute('href');
|
||||
$titleElement = $post->find('div.title a')[0];
|
||||
$post_uri = self::URI . $titleElement->getAttribute('href');
|
||||
|
||||
if (!isset($post_uri) || $post_uri == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item['uri'] = $post_uri;
|
||||
$item['title'] = $titleElement->innertext;
|
||||
|
||||
$articlePage = getSimpleHTMLDOMCached($item['uri']);
|
||||
|
||||
$authorDiv = $articlePage->find('div.author div');
|
||||
if ($authorDiv) {
|
||||
$item['author'] = $authorDiv[1]->innertext;
|
||||
}
|
||||
$item['author'] = $this->parseAuthor($articlePage);
|
||||
|
||||
$articleElement = $articlePage->find('article')[0];
|
||||
|
||||
$dinges = $articlePage->find('div.main-body')[0] ?? null;
|
||||
//remove ads
|
||||
if ($dinges) {
|
||||
foreach ($dinges->find('aside') as $ad) {
|
||||
$ad->outertext = '';
|
||||
$dinges->save();
|
||||
}
|
||||
foreach ($articleElement->find('aside') as $ad) {
|
||||
$ad->outertext = '';
|
||||
}
|
||||
|
||||
$var = $articlePage->find('div.summary')[0] ?? '';
|
||||
$var1 = $articlePage->find('figure.main-image')[0] ?? '';
|
||||
$dinges1 = $dinges ?? '';
|
||||
$summary = $articleElement->find('div.summary')[0];
|
||||
|
||||
$item['content'] = $var .
|
||||
$var1 .
|
||||
$dinges1;
|
||||
//remove header so we are left with the article content
|
||||
foreach ($articleElement->find('header') as $found) {
|
||||
$found->outertext = '';
|
||||
}
|
||||
|
||||
//remove comments (registering on carthrottle.com is impossible so the comment sections are empty anyway)
|
||||
foreach ($articleElement->find('#lbs-comments') as $found) {
|
||||
$found->outertext = '';
|
||||
}
|
||||
|
||||
//these are supposed to be hidden
|
||||
foreach ($articleElement->find('.visually-hidden') as $found) {
|
||||
$found->outertext = '';
|
||||
}
|
||||
|
||||
$item['content'] = $summary . $articleElement;
|
||||
|
||||
array_push($this->items, $item);
|
||||
}
|
||||
}
|
||||
|
||||
private function parseAuthor($articlePage)
|
||||
{
|
||||
$authorDivs = $articlePage->find('div address');
|
||||
if (!$authorDivs) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$a = $authorDivs[0]->find('a');
|
||||
if ($a) {
|
||||
return $a->innertext;
|
||||
}
|
||||
|
||||
return $authorDivs[0]->innertext;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ class HardwareInfoBridge extends FeedExpander
|
|||
const URI = 'https://nl.hardware.info/';
|
||||
const DESCRIPTION = 'Tech news from hardware.info (Dutch)';
|
||||
const MAINTAINER = 't0stiman';
|
||||
const DONATION_URI = 'https://ko-fi.com/tostiman';
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
|
|
|
@ -6,6 +6,7 @@ class RaceDepartmentBridge extends FeedExpander
|
|||
const URI = 'https://racedepartment.com/';
|
||||
const DESCRIPTION = 'Get the latest (sim)racing news from RaceDepartment.';
|
||||
const MAINTAINER = 't0stiman';
|
||||
const DONATION_URI = 'https://ko-fi.com/tostiman';
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue