Update HidiveBridge.php

Changed request from file_get_contents to getContent
This commit is contained in:
peppy6582 2025-01-11 13:19:31 -06:00 committed by GitHub
parent 183909aa4d
commit 7aca073859
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,13 +2,13 @@
class HidiveBridge extends BridgeAbstract {
const NAME = 'HIDIVE News Bridge';
const URI = 'https://news.hidive.com/';
const DESCRIPTION = 'Returns the latest news from HIDIVE';
const DESCRIPTION = 'Fetches the latest news from HIDIVE.';
const MAINTAINER = 'Your Name';
const CACHE_TIMEOUT = 3600; // 1 hour cache
public function collectData() {
$apiUrl = 'https://apigw.hidive.com/news/news';
// Define POST payload
$postData = json_encode([
'take' => 9,
@ -26,7 +26,7 @@ class HidiveBridge extends BridgeAbstract {
'Referer: https://news.hidive.com/'
];
// Create a stream context
// Prepare the HTTP options for getContents
$options = [
'http' => [
'method' => 'POST',
@ -36,16 +36,14 @@ class HidiveBridge extends BridgeAbstract {
]
];
$context = stream_context_create($options);
// Use getContents for the HTTP request
$response = getContents($apiUrl, $options);
// Execute the request
$response = file_get_contents($apiUrl, false, $context);
if ($response === false) {
returnServerError('Unable to fetch data from HIDIVE API.');
}
// Decode the response
// Decode the JSON response
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
returnServerError('Failed to decode JSON: ' . json_last_error_msg());
@ -54,17 +52,17 @@ class HidiveBridge extends BridgeAbstract {
// Process each news item
foreach ($data as $item) {
$newsItem = [];
// Clean and format the data
$excerpt = isset($item['excerpt']) ? ltrim($item['excerpt']) : '';
$seoUrl = isset($item['seoUrl']) ? 'https://news.hidive.com' . $item['seoUrl'] : '';
$image = isset($item['image']) ? 'https:' . $item['image'] : '';
// Create feed item
$newsItem['uri'] = $seoUrl;
$newsItem['title'] = $item['title'] ?? '';
$newsItem['timestamp'] = strtotime($item['releaseDate'] ?? '');
// Construct content with image and excerpt
$content = '';
if ($image) {
@ -72,19 +70,19 @@ class HidiveBridge extends BridgeAbstract {
htmlspecialchars($item['title'] ?? '') . '">';
}
$content .= '<p>' . htmlspecialchars($excerpt) . '</p>';
$newsItem['content'] = $content;
// Add categories if available
if (isset($item['categories']) && is_array($item['categories'])) {
$newsItem['categories'] = $item['categories'];
}
// Add author if available
if (isset($item['author'])) {
$newsItem['author'] = $item['author'];
}
$this->items[] = $newsItem;
}
}