diff --git a/PunishingGrayRavenNewsBridge.php b/PunishingGrayRavenNewsBridge.php new file mode 100644 index 0000000..f48e5f3 --- /dev/null +++ b/PunishingGrayRavenNewsBridge.php @@ -0,0 +1,96 @@ +apiBaseUrl . '/ArticleMenu.json'; + $menuJson = getContents($menuUrl); + $menuData = json_decode($menuJson, true); + + if (!is_array($menuData)) { + returnServerError('Could not parse ArticleMenu.json'); + } + + // Sort by createTime descending (newest first) + usort($menuData, function ($a, $b) { + $timeA = strtotime($a['createTime'] ?? '1970-01-01'); + $timeB = strtotime($b['createTime'] ?? '1970-01-01'); + return $timeB - $timeA; + }); + + // Limit to 10 most recent articles + $menuData = array_slice($menuData, 0, 10); + + // Fetch detailed information for each article + foreach ($menuData as $articleMeta) { + $articleId = $articleMeta['articleId']; + + // Fetch the detailed article JSON + $articleUrl = $this->apiBaseUrl . '/article/' . $articleId . '.json'; + + try { + $articleJson = getContents($articleUrl); + $articleData = json_decode($articleJson, true); + + if (!$articleData) { + continue; // Skip if article data is invalid + } + + $item = []; + + // Title + $item['title'] = $articleData['articleTitle'] ?? $articleMeta['articleTitle'] ?? 'Untitled'; + + // Content (with cover image if available) + $content = ''; + if (!empty($articleData['contentCover'])) { + $content .= '