From 97eebfb562f80de0d6e1c665a2eb49b7841fb837 Mon Sep 17 00:00:00 2001 From: Niehztog Date: Thu, 2 Jan 2025 17:44:36 +0100 Subject: [PATCH] [BlizzardNewsBridge] fix BlizzardNewsBridge (#4379) * fix BlizzardNewsBridge * fix linter warnings * fix linter warnings * fix linter warnings --- bridges/BlizzardNewsBridge.php | 68 +++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/bridges/BlizzardNewsBridge.php b/bridges/BlizzardNewsBridge.php index 993492d4..4d82b318 100644 --- a/bridges/BlizzardNewsBridge.php +++ b/bridges/BlizzardNewsBridge.php @@ -1,6 +1,6 @@ getInput('locale'); if ('zh-cn' === $locale) { - return 'https://cn.news.blizzard.com'; + $baseUrl = 'https://cn.news.blizzard.com' . self::API_PATH; + } else { + $baseUrl = 'https://news.blizzard.com/' . $locale . self::API_PATH; } - return 'https://news.blizzard.com/' . $locale; + return $baseUrl .= http_build_query([ + 'feedCxpProductIds' => self::PRODUCT_IDS + ]); + } + + public function collectData() + { + $feedContent = json_decode(getContents($this->getSourceUrl()), true); + + foreach ($feedContent['feed']['contentItems'] as $entry) { + $properties = $entry['properties']; + + $item = []; + + $item['title'] = $this->filterChars($properties['title']); + $item['content'] = $this->filterChars($properties['summary']); + $item['uri'] = $properties['newsUrl']; + $item['author'] = $this->filterChars($properties['author']); + $item['timestamp'] = strtotime($properties['lastUpdated']); + $item['enclosures'] = [$properties['staticAsset']['imageUrl']]; + $item['categories'] = [$this->filterChars($properties['cxpProduct']['title'])]; + + $this->items[] = $item; + } + } + + private function filterChars($content) + { + return htmlspecialchars($content, ENT_XML1); } public function getIcon() { return <<