97 lines
3.2 KiB
PHP
97 lines
3.2 KiB
PHP
<?php
|
|
|
|
class PunishingGrayRavenNewsBridge extends BridgeAbstract
|
|
{
|
|
const NAME = 'Punishing: Gray Raven News';
|
|
const URI = 'https://pgr.kurogame.net/news';
|
|
const DESCRIPTION = 'Returns news articles from Punishing: Gray Raven';
|
|
const MAINTAINER = 'Akamaru';
|
|
const CACHE_TIMEOUT = 3600; // 1 hour
|
|
|
|
private $apiBaseUrl = 'https://media-cdn-zspms.kurogame.net/pnswebsite/website2.0/json/G167';
|
|
|
|
public function getIcon()
|
|
{
|
|
return 'https://www.google.com/s2/favicons?domain=pgr.kurogame.net&sz=32';
|
|
}
|
|
|
|
public function collectData()
|
|
{
|
|
// Fetch the article menu
|
|
$menuUrl = $this->apiBaseUrl . '/ArticleMenu.json';
|
|
$menuJson = getContents($menuUrl);
|
|
$menuData = json_decode($menuJson, true);
|
|
|
|
if (!is_array($menuData)) {
|
|
returnServerError('Could not parse ArticleMenu.json');
|
|
}
|
|
|
|
// Sort by createTime descending (newest first)
|
|
usort($menuData, function ($a, $b) {
|
|
$timeA = strtotime($a['createTime'] ?? '1970-01-01');
|
|
$timeB = strtotime($b['createTime'] ?? '1970-01-01');
|
|
return $timeB - $timeA;
|
|
});
|
|
|
|
// Limit to 10 most recent articles
|
|
$menuData = array_slice($menuData, 0, 10);
|
|
|
|
// Fetch detailed information for each article
|
|
foreach ($menuData as $articleMeta) {
|
|
$articleId = $articleMeta['articleId'];
|
|
|
|
// Fetch the detailed article JSON
|
|
$articleUrl = $this->apiBaseUrl . '/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'] ?? 'Untitled';
|
|
|
|
// Content (with cover image if available)
|
|
$content = '';
|
|
if (!empty($articleData['contentCover'])) {
|
|
$content .= '<p><img src="' . $articleData['contentCover'] . '" /></p>';
|
|
}
|
|
$content .= $articleData['articleContent'] ?? '';
|
|
$item['content'] = $content;
|
|
|
|
// URI
|
|
$item['uri'] = self::URI . '/' . $articleId;
|
|
|
|
// Timestamp
|
|
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'] = 'PGR Team';
|
|
|
|
// UID
|
|
$item['uid'] = 'pgr-' . $articleId;
|
|
|
|
$this->items[] = $item;
|
|
|
|
} catch (Exception $e) {
|
|
// Skip articles that fail to load
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|