1
0
Files
Bridges/GirlsFrontline2ExiliumNewsBridge.php
2025-11-21 14:08:29 +01:00

78 lines
2.6 KiB
PHP

<?php
class GirlsFrontline2ExiliumNewsBridge extends BridgeAbstract
{
const NAME = "Girls' Frontline 2: Exilium News";
const URI = 'https://gf2exilium.sunborngame.com/main/noticeMore';
const DESCRIPTION = "Returns news articles from Girls' Frontline 2: Exilium";
const MAINTAINER = 'Akamaru';
const CACHE_TIMEOUT = 3600; // 1 hour
private $apiBaseUrl = 'https://gf2-web-us-api.sunborngame.com/website';
public function getIcon()
{
return 'https://www.google.com/s2/favicons?domain=gf2exilium.sunborngame.com&sz=32';
}
public function collectData()
{
// Fetch the news list
$listUrl = $this->apiBaseUrl . '/news_list/0?page=1&limit=10';
$listJson = getContents($listUrl);
$listData = json_decode($listJson, true);
if (!isset($listData['data']['list']) || !is_array($listData['data']['list'])) {
returnServerError('Could not find list array in news list response');
}
foreach ($listData['data']['list'] as $newsItem) {
$newsId = $newsItem['Id'];
// Fetch detailed news content
$newsUrl = $this->apiBaseUrl . '/news/' . $newsId;
try {
$newsJson = getContents($newsUrl);
$newsData = json_decode($newsJson, true);
if (!$newsData || !isset($newsData['data'])) {
continue; // Skip if news data is invalid
}
$article = $newsData['data'];
$item = [];
// Title
$item['title'] = $article['Title'] ?? $newsItem['Title'] ?? 'Untitled';
// Content
$item['content'] = $article['Content'] ?? '';
// URI - construct a link to the news page
$typeId = $article['Type'] ?? $newsItem['Type'] ?? 0;
$item['uri'] = 'https://gf2exilium.sunborngame.com/NewsInfo?id=' . $newsId . '&typeId=' . $typeId;
// Timestamp
if (isset($article['Date'])) {
$item['timestamp'] = strtotime($article['Date']);
} elseif (isset($newsItem['Date'])) {
$item['timestamp'] = strtotime($newsItem['Date']);
}
// Author
$item['author'] = 'Operations Team';
// UID
$item['uid'] = 'gf2-exilium-' . $newsId;
$this->items[] = $item;
} catch (Exception $e) {
// Skip articles that fail to load
continue;
}
}
}
}