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 .= '

'; } $content .= $articleData['articleContent'] ?? ''; $item['content'] = $content; // URI $item['uri'] = self::URI . '/' . $articleId; // Timestamp if (isset($articleMeta['createTime'])) { $item['timestamp'] = strtotime($articleMeta['createTime']); } elseif (isset($articleMeta['startTime'])) { $item['timestamp'] = strtotime($articleMeta['startTime']); } // Categories if (isset($articleData['articleTypeName'])) { $item['categories'] = [$articleData['articleTypeName']]; } // Author $item['author'] = 'PGR Team'; // UID $item['uid'] = 'pgr-' . $articleId; $this->items[] = $item; } catch (Exception $e) { // Skip articles that fail to load continue; } } } }