Neu: Brown Dust 2 News Bridge
This commit is contained in:
114
BrownDust2Bridge.php
Normal file
114
BrownDust2Bridge.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
class BrownDust2Bridge extends BridgeAbstract
|
||||
{
|
||||
const NAME = 'Brown Dust 2 News';
|
||||
const URI = 'https://www.browndust2.com';
|
||||
const DESCRIPTION = 'Returns news articles from Brown Dust 2 official website';
|
||||
const MAINTAINER = 'Akamaru';
|
||||
|
||||
public function getIcon()
|
||||
{
|
||||
return 'https://www.google.com/s2/favicons?domain=browndust2.com&sz=32';
|
||||
}
|
||||
|
||||
const PARAMETERS = [
|
||||
[
|
||||
'language' => [
|
||||
'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}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user