2022-07-07 16:12:35 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HytaleBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'Hytale Bridge';
|
|
|
|
const URI = 'https://hytale.com/news';
|
|
|
|
const DESCRIPTION = 'All blog posts from Hytale\'s news blog.';
|
|
|
|
const MAINTAINER = 'llamasblade';
|
|
|
|
|
2022-07-10 22:06:41 +03:00
|
|
|
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)#';
|
2022-07-07 16:12:35 +03:00
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
2022-07-21 21:33:00 +03:00
|
|
|
$blogPosts = json_decode(getContents(self::_API_URL_PUBLISHED));
|
|
|
|
$length = count($blogPosts);
|
2022-07-07 16:12:35 +03:00
|
|
|
|
2024-04-16 18:58:05 +03:00
|
|
|
for ($i = 0; $i < $length; $i += 3) {
|
2022-07-21 21:33:00 +03:00
|
|
|
$slug = $blogPosts[$i]->slug;
|
2022-07-07 16:12:35 +03:00
|
|
|
|
2022-07-21 21:33:00 +03:00
|
|
|
$blogPost = json_decode(getContents(self::_API_URL_BLOG_POST . $slug));
|
2022-07-07 16:12:35 +03:00
|
|
|
|
2024-04-16 18:58:05 +03:00
|
|
|
if (property_exists($blogPost, 'next')) {
|
|
|
|
$this->addBlogPost($blogPost->next);
|
2022-07-21 21:33:00 +03:00
|
|
|
}
|
2022-07-07 16:12:35 +03:00
|
|
|
|
2022-07-21 21:33:00 +03:00
|
|
|
$this->addBlogPost($blogPost);
|
2022-07-10 22:06:41 +03:00
|
|
|
|
2024-04-16 18:58:05 +03:00
|
|
|
if (property_exists($blogPost, 'previous')) {
|
|
|
|
$this->addBlogPost($blogPost->previous);
|
2022-07-21 21:33:00 +03:00
|
|
|
}
|
|
|
|
}
|
2022-07-10 22:06:41 +03:00
|
|
|
|
2024-04-16 18:58:05 +03:00
|
|
|
if (($length >= 3) && ($length % 3 == 0)) {
|
|
|
|
$slug = $blogPosts[$length - 1]->slug;
|
2022-07-10 22:06:41 +03:00
|
|
|
|
2022-07-21 21:33:00 +03:00
|
|
|
$blogPost = json_decode(getContents(self::_API_URL_BLOG_POST . $slug));
|
2024-04-16 18:58:05 +03:00
|
|
|
|
2022-07-21 21:33:00 +03:00
|
|
|
$this->addBlogPost($blogPost);
|
|
|
|
}
|
|
|
|
}
|
2022-07-10 22:06:41 +03:00
|
|
|
|
2022-07-21 21:33:00 +03:00
|
|
|
private function addBlogPost($blogPost)
|
|
|
|
{
|
|
|
|
$item = [];
|
|
|
|
|
|
|
|
$splittedTimestamp = explode('-', $blogPost->publishedAt);
|
|
|
|
$year = $splittedTimestamp[0];
|
|
|
|
$month = $splittedTimestamp[1];
|
|
|
|
$slug = $blogPost->slug;
|
|
|
|
$uri = 'https://hytale.com/news/' . $year . '/' . $month . '/' . $slug;
|
|
|
|
|
|
|
|
$item['uri'] = $uri;
|
|
|
|
$item['title'] = $blogPost->title;
|
|
|
|
$item['author'] = $blogPost->author;
|
|
|
|
$item['timestamp'] = $blogPost->publishedAt;
|
|
|
|
$item['content'] = $blogPost->body;
|
2022-07-07 16:12:35 +03:00
|
|
|
|
2022-07-21 21:33:00 +03:00
|
|
|
$blogCoverS3Key = $blogPost->coverImage->s3Key;
|
|
|
|
$coverImagesURLs = [
|
|
|
|
self::_BLOG_COVER_URL . $blogCoverS3Key,
|
|
|
|
self::_BLOG_THUMB_URL . $blogCoverS3Key,
|
|
|
|
];
|
|
|
|
|
|
|
|
if (preg_match_all(self::_IMG_REGEX, $blogPost->body, $bodyImagesURLs)) {
|
|
|
|
$item['enclosures'] = array_merge($coverImagesURLs, $bodyImagesURLs[0]);
|
|
|
|
} else {
|
|
|
|
$item['enclosures'] = $coverImagesURLs;
|
2022-07-07 16:12:35 +03:00
|
|
|
}
|
2022-07-21 21:33:00 +03:00
|
|
|
|
|
|
|
$this->items[] = $item;
|
2022-07-07 16:12:35 +03:00
|
|
|
}
|
|
|
|
}
|