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