diff --git a/bridges/HidiveBridge.php b/bridges/HidiveBridge.php new file mode 100644 index 00000000..e60dfe44 --- /dev/null +++ b/bridges/HidiveBridge.php @@ -0,0 +1,103 @@ + 9, + 'skip' => 0, + 'filter' => new stdClass() + ]); + + // Define headers + $headers = [ + 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:133.0) Gecko/20100101 Firefox/133.0', + 'Accept: */*', + 'Accept-Language: en-US,en;q=0.5', + 'Content-Type: application/json', + 'Origin: https://news.hidive.com', + 'Referer: https://news.hidive.com/' + ]; + + // Create a stream context + $options = [ + 'http' => [ + 'method' => 'POST', + 'header' => implode("\r\n", $headers), + 'content' => $postData, + 'ignore_errors' => true + ] + ]; + + $context = stream_context_create($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 + $data = json_decode($response, true); + if (json_last_error() !== JSON_ERROR_NONE) { + returnServerError('Failed to decode JSON: ' . json_last_error_msg()); + } + + // 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) { + $content .= '' . 
+                           htmlspecialchars($item['title'] ?? '') . ''; + } + $content .= '

' . htmlspecialchars($excerpt) . '

'; + + $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; + } + } + + public function getName() { + return self::NAME; + } + + public function getURI() { + return self::URI; + } + + public function getIcon() { + return 'https://www.hidive.com/favicon.ico'; + } +}