From 64c8d4ad371882e51c1b26f550f0d1b8d438d017 Mon Sep 17 00:00:00 2001 From: llamasblade <69692580+llamasblade@users.noreply.github.com> Date: Sun, 10 Jul 2022 21:06:41 +0200 Subject: [PATCH] [HytaleBridge] Improve bridge contents (#2912) Co-authored-by: BuildTools --- bridges/HytaleBridge.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/bridges/HytaleBridge.php b/bridges/HytaleBridge.php index de58ab76..0433cab0 100644 --- a/bridges/HytaleBridge.php +++ b/bridges/HytaleBridge.php @@ -7,11 +7,15 @@ class HytaleBridge extends BridgeAbstract const DESCRIPTION = 'All blog posts from Hytale\'s news blog.'; const MAINTAINER = 'llamasblade'; - const _API_URL = 'https://hytale.com/api/blog/post/published'; + const _API_URL_PUBLISHED = 'https://hytale.com/api/blog/post/published'; + const _API_URL_BLOG_POST = 'https://hytale.com/api/blog/post/slug/'; + const _BLOG_THUMB_URL = 'https://cdn.hytale.com/variants/blog_thumb_'; + const _BLOG_COVER_URL = 'https://cdn.hytale.com/variants/blog_cover_'; + const _IMG_REGEX = '#https://cdn\.hytale\.com/\w+\.(?:jpg|png)#'; public function collectData() { - $blog_posts = json_decode(file_get_contents(self::_API_URL)); + $blog_posts = json_decode(getContents(self::_API_URL_PUBLISHED)); foreach ($blog_posts as $blog_post) { $item = []; @@ -27,7 +31,22 @@ class HytaleBridge extends BridgeAbstract $item['title'] = $blog_post->title; $item['author'] = $blog_post->author; $item['timestamp'] = $blog_post->publishedAt; - $item['content'] = $blog_post->bodyExcerpt; + + $blog_post_full = json_decode(getContents(self::_API_URL_BLOG_POST . $slug)); + + $item['content'] = $blog_post_full->body; + $blog_cover_s3_key = $blog_post_full->coverImage->s3Key; + + $cover_images_urls = [ + self::_BLOG_COVER_URL . $blog_cover_s3_key, + self::_BLOG_THUMB_URL . $blog_cover_s3_key, + ]; + + if (preg_match_all(self::_IMG_REGEX, $blog_post_full->body, $body_images_urls)) { + $item['enclosures'] = array_merge($cover_images_urls, $body_images_urls[0]); + } else { + $item['enclosures'] = $cover_images_urls; + } $this->items[] = $item; }