1
0
Files
Bridges/SnowbreakNewsBridge.php

87 lines
2.8 KiB
PHP

<?php
class SnowbreakNewsBridge extends BridgeAbstract {
const NAME = 'Snowbreak: Containment Zone News';
const URI = 'https://snowbreak.amazingseasun.com';
const DESCRIPTION = 'Returns the latest news from Snowbreak: Containment Zone';
const MAINTAINER = 'Akamaru';
const CACHE_TIMEOUT = 21600; // 6 hours
const PARAMETERS = [
'Category' => [
'category' => [
'name' => 'Category',
'type' => 'list',
'values' => [
'News' => '613',
'Updates' => '614',
'Events' => '615',
'All' => 'all'
],
'defaultValue' => '613'
]
]
];
const FAVICON = 'https://snowbreak.amazingseasun.com/p/zt/2023/07/13/index/static/favicon.ico';
public function collectData() {
$category = $this->getInput('category');
$articles = [];
if ($category === 'all') {
// Fetch all categories
$categories = ['613', '614', '615'];
foreach ($categories as $cat) {
$articles = array_merge($articles, $this->fetchCategory($cat));
}
} else {
$articles = $this->fetchCategory($category);
}
// Sort articles by date (newest first)
usort($articles, function($a, $b) {
return $b['inputtime'] - $a['inputtime'];
});
foreach ($articles as $article) {
$item = [];
$item['title'] = $article['title'];
// Convert inputtime to timestamp
$item['timestamp'] = $article['inputtime'];
$item['uri'] = $article['url'];
$item['content'] = $article['content'];
$item['author'] = 'Amazing Seasun';
if (!empty($article['thumb'])) {
$item['enclosures'] = [$article['thumb']];
}
$this->items[] = $item;
}
}
private function fetchCategory($category) {
$api_url = 'https://snowbreak.amazingseasun.com/api.php?op=search_api&action=get_article_list&catid=' .
$category . '&num=50&moreinfo=1';
$json = getContents($api_url);
$data = json_decode($json, true);
if (!isset($data['data']['list']) || !is_array($data['data']['list'])) {
return [];
}
return $data['data']['list'];
}
public function getName() {
$category = $this->getInput('category');
$categories = [
'613' => 'News',
'614' => 'Updates',
'615' => 'Events',
'all' => 'All'
];
$categoryName = $categories[$category] ?? 'Unknown';
return 'Snowbreak: Containment Zone - ' . $categoryName;
}
}