[ 'name' => 'Language', 'type' => 'list', 'values' => [ 'English' => 'en', 'Japanese' => 'jp', 'Korean' => 'kr', 'Traditional Chinese (Taiwan)' => 'tw', 'Simplified Chinese' => 'cn' ], 'defaultValue' => 'en' ], 'tag' => [ 'name' => 'Category', 'type' => 'list', 'values' => [ 'All' => 'all', 'Notice' => 'notice', 'Event' => 'event', 'Maintenance' => 'maintenance', 'Known Issues' => 'issue', 'Developer Notes' => 'dev_note', 'Package Deals' => 'package_deal' ], 'defaultValue' => 'all' ], 'limit' => [ 'name' => 'Items Limit', 'type' => 'number', 'defaultValue' => 20 ] ] ]; public function collectData() { $lang = $this->getInput('language'); $tag = $this->getInput('tag'); $limit = $this->getInput('limit') ?: 20; // Fetch JSON from API $url = "https://www.browndust2.com/api/newsData_{$lang}.json"; $json = getContents($url); $data = json_decode($json, true); if (!isset($data['data']) || !is_array($data['data'])) { throw new \Exception('Invalid API response'); } $items = $data['data']; // Filter by tag if not "all" if ($tag !== 'all') { $items = array_filter($items, function ($item) use ($tag) { return isset($item['attributes']['tag']) && $item['attributes']['tag'] === $tag; }); } // Reverse array for newest first $items = array_reverse($items); // Limit items $items = array_slice($items, 0, $limit); // Build feed items foreach ($items as $newsItem) { $attr = $newsItem['attributes']; $item = [ 'title' => $attr['subject'] ?? 'No Title', 'uri' => $this->getItemUrl($newsItem['id'], $lang), 'timestamp' => isset($attr['publishedAt']) ? strtotime($attr['publishedAt']) : time(), 'content' => $attr['NewContent'] ?? $attr['content'] ?? '', 'categories' => isset($attr['tag']) ? [$attr['tag']] : [], 'uid' => (string)$newsItem['id'], 'author' => 'Neowiz' ]; $this->items[] = $item; } } private function getItemUrl($id, $lang) { $localeMap = [ 'en' => 'en-us', 'jp' => 'ja-jp', 'kr' => 'ko-kr', 'tw' => 'zh-tw', 'cn' => 'zh-cn' ]; $locale = $localeMap[$lang] ?? 'en-us'; return "https://www.browndust2.com/{$locale}/news/view?id={$id}"; } }