137 lines
4.7 KiB
PHP
137 lines
4.7 KiB
PHP
<?php
|
|
|
|
class WutheringWavesNewsBridge extends BridgeAbstract
|
|
{
|
|
const NAME = 'Wuthering Waves News';
|
|
const URI = 'https://wutheringwaves.kurogames.com/main/news';
|
|
const ICON = 'https://www.google.com/s2/favicons?domain=wutheringwaves.kurogames.com&sz=32';
|
|
const DESCRIPTION = 'Returns news articles from Wuthering Waves';
|
|
const MAINTAINER = 'Akamaru';
|
|
const CACHE_TIMEOUT = 3600; // 1 hour
|
|
|
|
const PARAMETERS = [
|
|
[
|
|
'language' => [
|
|
'name' => 'Language',
|
|
'type' => 'list',
|
|
'values' => [
|
|
'English' => 'en',
|
|
'Deutsch' => 'de',
|
|
'Japanese' => 'jp',
|
|
'Korean' => 'kr',
|
|
'Traditional Chinese' => 'zh-tw',
|
|
'Spanish' => 'es',
|
|
'French' => 'fr'
|
|
],
|
|
'defaultValue' => 'en'
|
|
]
|
|
]
|
|
];
|
|
|
|
private $apiBaseUrl = 'https://hw-media-cdn-mingchao.kurogame.com/akiwebsite/website2.0/json/G152';
|
|
|
|
public function collectData()
|
|
{
|
|
$language = $this->getInput('language');
|
|
|
|
// Fetch the main menu JSON to get the article list
|
|
$menuUrl = $this->apiBaseUrl . '/' . $language . '/MainMenu.json';
|
|
$menuJson = getContents($menuUrl);
|
|
$menuData = json_decode($menuJson, true);
|
|
|
|
if (!isset($menuData['article']) || !is_array($menuData['article'])) {
|
|
returnServerError('Could not find article array in MainMenu.json');
|
|
}
|
|
|
|
// Deduplicate articles by articleId
|
|
$uniqueArticles = [];
|
|
foreach ($menuData['article'] as $article) {
|
|
$articleId = $article['articleId'];
|
|
|
|
// Keep the article with the highest sortingMark if duplicates exist
|
|
if (!isset($uniqueArticles[$articleId]) ||
|
|
$article['sortingMark'] > $uniqueArticles[$articleId]['sortingMark']) {
|
|
$uniqueArticles[$articleId] = $article;
|
|
}
|
|
}
|
|
|
|
// Sort by sortingMark (descending - higher is newer)
|
|
usort($uniqueArticles, function ($a, $b) {
|
|
return $b['sortingMark'] - $a['sortingMark'];
|
|
});
|
|
|
|
// Limit to 10 most recent articles
|
|
$uniqueArticles = array_slice($uniqueArticles, 0, 10);
|
|
|
|
// Fetch detailed information for each article
|
|
foreach ($uniqueArticles as $articleMeta) {
|
|
$articleId = $articleMeta['articleId'];
|
|
|
|
// Fetch the detailed article JSON
|
|
$articleUrl = $this->apiBaseUrl . '/' . $language . '/article/' . $articleId . '.json';
|
|
|
|
try {
|
|
$articleJson = getContents($articleUrl);
|
|
$articleData = json_decode($articleJson, true);
|
|
|
|
if (!$articleData) {
|
|
continue; // Skip if article data is invalid
|
|
}
|
|
|
|
$item = [];
|
|
|
|
// Title
|
|
$item['title'] = $articleData['articleTitle'] ?? $articleMeta['articleTitle'];
|
|
|
|
// Content (HTML is already provided in the API)
|
|
$item['content'] = $articleData['articleContent'] ?? '';
|
|
|
|
// URI - construct a link to the news page
|
|
$item['uri'] = self::URI . '/' . $articleId;
|
|
|
|
// Timestamp - use createTime or startTime from the main menu data
|
|
if (isset($articleMeta['createTime'])) {
|
|
$item['timestamp'] = strtotime($articleMeta['createTime']);
|
|
} elseif (isset($articleMeta['startTime'])) {
|
|
$item['timestamp'] = strtotime($articleMeta['startTime']);
|
|
}
|
|
|
|
// Categories
|
|
if (isset($articleData['articleTypeName'])) {
|
|
$item['categories'] = [$articleData['articleTypeName']];
|
|
}
|
|
|
|
// Author
|
|
$item['author'] = 'Kuro Games';
|
|
|
|
// UID
|
|
$item['uid'] = 'wuthering-waves-' . $articleId;
|
|
|
|
$this->items[] = $item;
|
|
|
|
} catch (Exception $e) {
|
|
// Skip articles that fail to load
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
$language = $this->getInput('language');
|
|
if ($language) {
|
|
$languageNames = [
|
|
'en' => 'English',
|
|
'de' => 'Deutsch',
|
|
'jp' => 'Japanese',
|
|
'kr' => 'Korean',
|
|
'zh-tw' => 'Traditional Chinese',
|
|
'es' => 'Spanish',
|
|
'fr' => 'French'
|
|
];
|
|
return self::NAME . ' (' . ($languageNames[$language] ?? $language) . ')';
|
|
}
|
|
return self::NAME;
|
|
}
|
|
}
|