aboutsummaryrefslogtreecommitdiff
path: root/bridges/FallGuysBridge.php
blob: 1e5274841de57212b1cc549391f1b09ced8364e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php

class FallGuysBridge extends BridgeAbstract
{
    const MAINTAINER = 'User123698745';
    const NAME = 'Fall Guys';
    const BASE_URI = 'https://www.fallguys.com';
    const URI = self::BASE_URI . '/news';
    const CACHE_TIMEOUT = 600; // 10min
    const DESCRIPTION = 'News from the Fall Guys website';
    const DEFAULT_LOCALE = 'en-US';
    const PARAMETERS = [
        [
            'locale' => [
                'name' => 'Language',
                'type' => 'list',
                'values' => [
                    'English' => 'en-US',
                    'لعربية' => 'ar',
                    'Deutsch' => 'de',
                    'Español (Spain)' => 'es-ES',
                    'Español (LA)' => 'es-MX',
                    'Français' => 'fr',
                    'Italiano' => 'it',
                    '日本語' => 'ja',
                    '한국어' => 'ko',
                    'Polski' => 'pl',
                    'Português (Brasil)' => 'pt-BR',
                    'Русский' => 'ru',
                    'Türkçe' => 'tr',
                    '简体中文' => 'zh-CN',
                ],
                'defaultValue' => self::DEFAULT_LOCALE,
            ]
        ]
    ];

    public function collectData()
    {
        $html = getSimpleHTMLDOM(self::getURI());

        $data = json_decode($html->find('#__NEXT_DATA__', 0)->innertext);

        foreach ($data->props->pageProps->newsList as $newsItem) {
            $headerDescription = property_exists($newsItem->header, 'description') ? $newsItem->header->description : '';
            $headerImage = $newsItem->header->image->src;

            $contentImages = [$headerImage];

            $content = <<<HTML
            <p>{$headerDescription}</p>
            <p><img src="{$headerImage}"></p>
            HTML;

            foreach ($newsItem->content->items as $contentItem) {
                if (property_exists($contentItem, 'articleCopy')) {
                    if (property_exists($contentItem->articleCopy, 'title')) {
                        $title = $contentItem->articleCopy->title;

                        $content .= <<<HTML
                        <h2>{$title}</h2>
                        HTML;
                    }

                    $text = $contentItem->articleCopy->copy;

                    $content .= <<<HTML
                    <p>{$text}</p>
                    HTML;
                } elseif (property_exists($contentItem, 'articleImage')) {
                    $image = $contentItem->articleImage->imageSrc;

                    if ($image != $headerImage) {
                        $contentImages[] = $image;

                        $content .= <<<HTML
                        <p><img src="{$image}"></p>
                        HTML;
                    }
                } elseif (property_exists($contentItem, 'embeddedVideo')) {
                    $mediaOptions = $contentItem->embeddedVideo->mediaOptions;
                    $mainContentOptions = $contentItem->embeddedVideo->mainContentOptions;

                    if (count($mediaOptions) == count($mainContentOptions)) {
                        for ($i = 0; $i < count($mediaOptions); $i++) {
                            if (property_exists($mediaOptions[$i], 'youtubeVideo')) {
                                $videoUrl = 'https://youtu.be/' . $mediaOptions[$i]->youtubeVideo->contentId;
                                $image = $mainContentOptions[$i]->image->src ?? '';

                                $content .= '<p>';

                                if ($image != $headerImage) {
                                    $contentImages[] = $image;

                                    $content .= <<<HTML
                                    <a href="{$videoUrl}"><img src="{$image}"></a><br>
                                    HTML;
                                }

                                $content .= <<<HTML
                                <i>(Video: <a href="{$videoUrl}">{$videoUrl}</a>)</i>
                                HTML;

                                $content .= '</p>';
                            }
                        }
                    }
                }
            }

            $item = [
                'uid' => $newsItem->_id,
                'uri' => self::getURI() . '/' . $newsItem->_slug,
                'title' => $newsItem->_title,
                'timestamp' => $newsItem->lastModified,
                'content' => $content,
                'enclosures' => $contentImages,
            ];

            $this->items[] = $item;
        }
    }

    public function getURI()
    {
        $locale = $this->getInput('locale') ?? self::DEFAULT_LOCALE;
        return self::BASE_URI . '/' . $locale . '/news';
    }

    public function getIcon()
    {
        return self::BASE_URI . '/favicon.ico';
    }
}