diff --git a/bridges/Drive2ruBridge.php b/bridges/Drive2ruBridge.php new file mode 100644 index 00000000000..cbe6a156f7f --- /dev/null +++ b/bridges/Drive2ruBridge.php @@ -0,0 +1,67 @@ + array( + 'name' => 'Ссылка на страницу с бортжурналом', + 'type' => 'text', + 'required' => true, + 'title' => 'Например: https://www.drive2.ru/experience/suzuki/g4895/', + 'exampleValue' => 'https://www.drive2.ru/experience/suzuki/g4895/' + ), + 'full_articles' => array( + 'name' => 'Загружать в ленту полный текст', + 'type' => 'checkbox', + ) + ) + ); + + private $title; + + public function collectData(){ + $url = $this->getInput('url'); + $validUrl = '/^https:\/\/www.drive2.ru\/experience/'; + if (!preg_match($validUrl, $url)) returnServerError('Invalid url'); + $html = getSimpleHTMLDOM($this->getInput('url')); + $this->title = $html->find('title', 0)->innertext; + $articles = $html->find('div.js-entity'); + foreach ($articles as $article) { + $item = array(); + $item['title'] = $article->find('a.c-link--text', 0)->plaintext; + $item['uri'] = urljoin(self::URI, $article->find('a.c-link--text', 0)->href); + if($this->getInput('full_articles')) { + $content = getSimpleHTMLDOM($item['uri'])->find('div.c-post__body', 0); + foreach($content->find('div, span') as $ds) + foreach ($ds->getAllAttributes() as $attr => $val) + $ds->removeAttribute($attr); + foreach ($content->find('script') as $node) + $node->outertext = ''; + foreach ($content->find('iframe') as $node) + $node->outertext = '' . $node->src . ''; + $item['content'] = $content->innertext; + } else { + $content = $article->find('div.c-post-preview__lead', 0); + if (!is_null($content)) + $item['content'] = preg_replace('!\s+!', ' ', str_replace('Читать дальше', '', $content->plaintext)) . + '
Читать далее'; + else $item['content'] = ''; + } + $item['author'] = $article->find('a.c-username--wrap', 0)->plaintext; + $item['enclosures'][] = $article->find('img', 1)->src; + $this->items[] = $item; + } + } + + public function getName() { + return $this->title ?: parent::getName(); + } + + public function getIcon() { + return 'https://www.drive2.ru/favicon.ico'; + } +}