Skip to content

Commit

Permalink
[CdactionBridge] Add new bridge (#2431)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszkane authored Jan 30, 2022
1 parent c1c998d commit 09fac3a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bridges/CdactionBridge.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 09fac3a

Please sign in to comment.