[CdactionBridge] Add new bridge (#2431)

This commit is contained in:
Tomasz Kane 2022-01-30 09:52:00 +01:00 committed by GitHub
parent c1c998dd13
commit 09fac3aa35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
class CdactionBridge extends BridgeAbstract {
const NAME = 'CD-ACTION bridge';
const URI = 'https://cdaction.pl/newsy';
const DESCRIPTION = 'Fetches the latest news.';
const MAINTAINER = 'tomaszkane';
public function collectData() {
$html = getSimpleHTMLDOM($this->getURI());
$newsJson = $html->find('script#__NEXT_DATA__', 0)->innertext;
if (!$newsJson = json_decode($newsJson)) {
return;
}
foreach ($newsJson->props->pageProps->dehydratedState->queries[1]->state->data->results as $news) {
$item = array();
$item['uri'] = $this->getURI() . '/' . $news->slug;
$item['title'] = $news->title;
$item['timestamp'] = $news->publishedAt;
$item['author'] = $news->editor->fullName;
$item['content'] = $news->lead;
$item['enclosures'][] = $news->bannerUrl;
$item['categories'] = array_column($news->tags, 'name');
$item['uid'] = $news->id;
$this->items[] = $item;
}
}
}