42 lines
1.8 KiB
PHP
42 lines
1.8 KiB
PHP
<?php
|
|
class StellaSoraBridge extends BridgeAbstract {
|
|
const MAINTAINER = 'Akamaru';
|
|
const NAME = 'Stella Sora News';
|
|
const URI = 'https://stellasora.global/news/';
|
|
const CACHE_TIMEOUT = 21600; // 6h
|
|
const DESCRIPTION = 'Get the latest news from Stella Sora (Global)';
|
|
|
|
public function getIcon() {
|
|
return 'https://novaweb-usstatic.yo-star.com/h5/favicon.png';
|
|
}
|
|
|
|
public function collectData() {
|
|
$apiUrl = 'https://stellasora.global/api/resource/news?index=1&size=999&type=latest';
|
|
$json = getContents($apiUrl)
|
|
or returnServerError('Could not fetch Stella Sora news.');
|
|
$data = json_decode($json);
|
|
if (!isset($data->data->rows)) {
|
|
returnServerError('Invalid API response structure.');
|
|
}
|
|
foreach ($data->data->rows as $element) {
|
|
$item = array();
|
|
$item['uri'] = $element->link;
|
|
$item['title'] = $element->title;
|
|
$item['timestamp'] = isset($element->publishTime) ? intval($element->publishTime / 1000) : time();
|
|
$item['author'] = 'Stella Sora';
|
|
$item['categories'] = array($element->typeLabel);
|
|
$item['enclosures'] = array($element->thumbnail);
|
|
$content = '';
|
|
if (!empty($element->thumbnail)) {
|
|
$content .= '<img src="' . htmlspecialchars($element->thumbnail) . '" alt="' . htmlspecialchars($element->title) . '"><br>';
|
|
}
|
|
if (!empty($element->description)) {
|
|
$desc = str_replace("\n", "<br>", $element->description);
|
|
$content .= '<div>' . $desc . '</div>';
|
|
}
|
|
$item['content'] = $content;
|
|
$item['uid'] = $element->id;
|
|
$this->items[] = $item;
|
|
}
|
|
}
|
|
}
|