From 27d1d47c6a0eb0337d3674497f50973f65dafda1 Mon Sep 17 00:00:00 2001 From: Tomasz Walburg Date: Thu, 20 Jan 2022 23:02:40 +0100 Subject: [PATCH 1/3] [Cdaction] Add new bridge For news on cdaction.pl website. --- bridges/CdactionBridge.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 bridges/CdactionBridge.php diff --git a/bridges/CdactionBridge.php b/bridges/CdactionBridge.php new file mode 100644 index 00000000000..c351bdb0c2c --- /dev/null +++ b/bridges/CdactionBridge.php @@ -0,0 +1,28 @@ +getURI()); + + $newsJson = $html->find('script#__NEXT_DATA__', 0)->innertext; + $newsJson = json_decode($newsJson); + foreach ($newsJson->props->pageProps->dehydratedState->queries[1]->state->data->results as $news) { + $item = []; + $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; + } + } +} From 543fdc4ae473be815695584e66a69eff4b724279 Mon Sep 17 00:00:00 2001 From: Tomasz Walburg Date: Fri, 21 Jan 2022 10:19:36 +0100 Subject: [PATCH 2/3] PHP compatibility change, remove array short syntax --- bridges/CdactionBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/CdactionBridge.php b/bridges/CdactionBridge.php index c351bdb0c2c..3a23efe7816 100644 --- a/bridges/CdactionBridge.php +++ b/bridges/CdactionBridge.php @@ -12,7 +12,7 @@ public function collectData() { $newsJson = $html->find('script#__NEXT_DATA__', 0)->innertext; $newsJson = json_decode($newsJson); foreach ($newsJson->props->pageProps->dehydratedState->queries[1]->state->data->results as $news) { - $item = []; + $item = array(); $item['uri'] = $this->getURI() . '/' . $news->slug; $item['title'] = $news->title; $item['timestamp'] = $news->publishedAt; From d6c69a10f9ebb09a2a4101c58f2081f9cb4e37ac Mon Sep 17 00:00:00 2001 From: Tomasz Walburg Date: Fri, 21 Jan 2022 10:20:48 +0100 Subject: [PATCH 3/3] Prevent foreach on null when getSimpleHTMLDOM fails --- bridges/CdactionBridge.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bridges/CdactionBridge.php b/bridges/CdactionBridge.php index 3a23efe7816..5b751a5bb69 100644 --- a/bridges/CdactionBridge.php +++ b/bridges/CdactionBridge.php @@ -10,7 +10,10 @@ public function collectData() { $html = getSimpleHTMLDOM($this->getURI()); $newsJson = $html->find('script#__NEXT_DATA__', 0)->innertext; - $newsJson = json_decode($newsJson); + 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;