.*?
([^<]+)<\/title>.*?([^<]+)<\/link>.*?([^<]+)<\/pubDate>/s', $rss, $m, PREG_SET_ORDER);
$articles = [];
foreach (array_slice($m, 0, 10) as $item) {
$articles[] = ['title' => html_entity_decode($item[1]), 'url' => $item[2], 'date' => date('Y-m-d', strtotime($item[3]))];
}
echo json_encode(['ok' => true, 'source' => 'FeedDough RSS', 'articles' => $articles, 'count' => count($articles)]);
} else {
// Fallback: cached articles
$cached = json_decode(@file_get_contents(__DIR__ . '/feeddough-cache.json'), true) ?: [];
echo json_encode(['ok' => true, 'source' => 'cache', 'articles' => $cached, 'count' => count($cached)]);
}
} elseif ($action === 'search') {
$q = $_GET['q'] ?? 'AI';
// Search via SearXNG
$r = @file_get_contents("http://127.0.0.1:8080/search?q=site:feeddough.com+" . urlencode($q) . "&format=json");
$d = json_decode($r, true);
$results = [];
foreach (($d['results'] ?? []) as $item) {
$results[] = ['title' => $item['title'] ?? '', 'url' => $item['url'] ?? '', 'excerpt' => $item['content'] ?? ''];
}
echo json_encode(['ok' => true, 'query' => $q, 'results' => $results]);
} elseif ($action === 'brief') {
// Morning brief: aggregate news for WEVIA daily brief
$rss = @file_get_contents('https://feeddough.com/feed/');
$articles = [];
if ($rss) {
preg_match_all('/- .*?([^<]+)<\/title>/s', $rss, $m);
$articles = array_slice($m[1] ?? [], 0, 5);
}
$brief = "📰 WEVIA Morning Brief\n\n";
foreach ($articles as $i => $t) {
$brief .= ($i+1) . ". " . html_entity_decode($t) . "\n";
}
echo json_encode(['ok' => true, 'brief' => $brief]);
}