1
0
Files
Bridges/GenshinImpactNewsBridge.php
Akamaru efbc4f60da Übernehme Bridges von Brawl
- GenshinImpactNewsBridge
- HolonometriaMangaBridge
- PokemonGOBridge
2025-07-03 21:32:20 +02:00

102 lines
3.3 KiB
PHP

<?php
class GenshinImpactNewsBridge extends BridgeAbstract
{
const MAINTAINER = 'Brawl, Akamaru';
const NAME = 'Genshin Impact News';
const URI = 'https://sg-public-api-static.hoyoverse.com/content_v2_user/app/a1b1f9d3315447cc/getContentList';
const CACHE_TIMEOUT = 3600; // 3600 = 1h
const DESCRIPTION = 'Get the latest news from Genshin Impact!';
const PARAMETERS = array(
array(
'lang' => array(
'name' => 'Language',
'type' => 'list',
'values' => array(
'English' => 'en-us',
'繁體中文' => 'zh-tw',
'한국어' => 'ko-kr',
'日本語' => 'ja-jp',
'Français' => 'fr-fr',
'Deutsch' => 'de-de',
'Português' => 'pt-pt',
'Español' => 'es-es',
'Русский' => 'ru-ru',
'Bahasa Indonesia' => 'id-id',
'Tiếng Việt' => 'vi-vn',
'ไทย' => 'th-th',
),
'required' => true
),
'limit' => array(
'name' => 'Limit',
'type' => 'number',
'required' => false,
'defaultValue' => 10
)
)
);
private $pageUrl = self::URI;
public function getURI()
{
return $this->pageUrl;
}
public function collectData()
{
// Eingaben prüfen
$lang = $this->getInput('lang');
if (empty($lang)) {
returnClientError('Ungültige Sprache: ' . $lang);
}
$limit = $this->getInput('limit');
if (empty($limit)) {
$limit = 10;
}
// Neue API-URL zusammenbauen
$query = http_build_query([
'iAppId' => 32,
'iChanId' => 395, // Standard-News-Kanal, ggf. anpassbar
'iPageSize' => $limit,
'iPage' => 1,
'sLangKey' => $lang
]);
$jsonUrl = self::URI . '?' . $query;
$json = getContents($jsonUrl)
or returnServerError('Konnte die Genshin-News nicht abrufen.');
$data = json_decode($json);
if (!isset($data->data->list)) {
returnServerError('Ungültige Antwortstruktur.');
}
$this->pageUrl = 'https://genshin.hoyoverse.com/' . $lang . '/news';
foreach ($data->data->list as $element) {
$article_title = $element->sTitle;
$article_uid = $element->iInfoId;
$article_uri = $this->pageUrl . '/detail/' . $article_uid;
$article_timestamp = strtotime($element->dtStartTime);
$article_content = $element->sIntro;
$item = array();
$item['uri'] = $article_uri;
$item['title'] = $article_title;
$item['timestamp'] = $article_timestamp;
$item['content'] = $article_content;
// Thumbnail aus sExt->banner
if (!empty($element->sExt)) {
$ext = json_decode($element->sExt);
if (isset($ext->banner) && is_array($ext->banner) && isset($ext->banner[0]->url)) {
$item['enclosures'] = array($ext->banner[0]->url);
}
}
$this->items[] = $item;
}
}
}