rss-bridge/bridges/CarThrottleBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
3.2 KiB
PHP
Raw Normal View History

<?php
2023-08-25 13:34:35 +03:00
class CarThrottleBridge extends BridgeAbstract
{
2023-08-25 13:34:35 +03:00
const NAME = 'Car Throttle';
const URI = 'https://www.carthrottle.com/';
const DESCRIPTION = 'Get the latest car-related news from Car Throttle.';
const MAINTAINER = 't0stiman';
2024-02-04 20:28:12 +03:00
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()
{
2024-02-04 20:28:12 +03:00
$this->items = [];
$this->handleCategory('news');
$this->handleCategory('reviews');
$this->handleCategory('features');
$this->handleCategory2('videos', 'video');
$this->handleCategory('gaming');
}
2024-02-04 20:28:12 +03:00
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);
2023-08-25 13:34:35 +03:00
//for each post
2024-02-04 20:28:12 +03:00
foreach ($categoryPage->find('div.cmg-card') as $post) {
2023-08-25 13:34:35 +03:00
$item = [];
2024-02-04 20:28:12 +03:00
$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;
2023-08-25 13:34:35 +03:00
$item['title'] = $titleElement->innertext;
2023-12-21 11:24:22 +03:00
$articlePage = getSimpleHTMLDOMCached($item['uri']);
2024-02-04 20:28:12 +03:00
$item['author'] = $this->parseAuthor($articlePage);
$articleImage = $articlePage->find('div.block-layout-field-image')[0];
$article = $articlePage->find('div.block-layout-body')[1];
2023-08-25 13:34:35 +03:00
//remove ads
foreach ($article->find('aside') as $ad) {
2024-02-04 20:28:12 +03:00
$ad->outertext = '';
}
$summary = $articlePage->find('div.summary')[0];
2024-02-04 20:28:12 +03:00
//these are supposed to be hidden
foreach ($article->find('.visually-hidden') as $found) {
2024-02-04 20:28:12 +03:00
$found->outertext = '';
}
2023-10-12 20:49:04 +03:00
$item['content'] = $summary . $articleImage . $article;
2023-08-25 13:34:35 +03:00
array_push($this->items, $item);
}
}
2024-02-04 20:28:12 +03:00
private function parseAuthor($articlePage)
{
$authorDivs = $articlePage->find('div address');
if (!$authorDivs) {
return '';
}
$a = $authorDivs[0]->find('a')[0];
2024-02-04 20:28:12 +03:00
if ($a) {
return $a->innertext;
}
return $authorDivs[0]->innertext;
}
}