Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Drive2ru] Add new bridge #2116

Merged
merged 7 commits into from
May 23, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions bridges/Drive2ruBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
class Drive2ruBridge extends BridgeAbstract {

const MAINTAINER = 'dotter-ak ';
const NAME = 'Бортжурналы на Drive2.ru';
const URI = 'https://drive2.ru/';
const DESCRIPTION = 'Лента бортжурналов по выбранной марке или машине. Также работает с фильтром по категориям';
const PARAMETERS = array(
array(
'url' => array(
'name' => 'Ссылка на страницу с бортжурналом',
'type' => 'text',
'required' => true,
'title' => 'Например: https://www.drive2.ru/experience/suzuki/g4895/',
'exampleValue' => 'https://www.drive2.ru/experience/suzuki/g4895/'
),
)
);

public function collectData(){
$html = getSimpleHTMLDOM($this->getInput('url')) or returnServerError('No results for this query.');
dotter-ak marked this conversation as resolved.
Show resolved Hide resolved
dotter-ak marked this conversation as resolved.
Show resolved Hide resolved
$articles = $html->find('div.js-entity');
foreach ($articles as $article) {
$item = array();
$item['title'] = $article->find('a.c-link--text', 0)->plaintext;
$item['uri'] = self::URI . $article->find('a.c-link--text', 0)->href;
dotter-ak marked this conversation as resolved.
Show resolved Hide resolved
$item['content'] = str_replace("<button class=\"c-post-preview__more r-button-unstyled c-link c-link--text\" data-action=\"post.show\" data-ym-target=\"post_read\">Читать дальше</button>","",$article->find('div.c-post-preview__lead', 0)) ."<br><a href=\"".$item['uri']."\">Читать далее</a>";
$item['author'] = $article->find('a.c-username--wrap', 0)->plaintext;
$item['enclosures'][] = $article->find('img', 1)->src;
$this->items[] = $item;
}
}

public function getName() {
if($this->getInput('url')) {
$html = getSimpleHTMLDOM($this->getInput('url'));
return $html->find('title', 0)->plaintext;
}
return parent::getName();
}

public function getIcon() {
return 'https://www.drive2.ru/favicon.ico';
}
}