true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 15, CURLOPT_USERAGENT => 'Mozilla/5.0', CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false ]); $data = curl_exec($ch); curl_close($ch); } if(!$data){ $context = stream_context_create([ 'http' => ['header' => 'User-Agent: Mozilla/5.0'] ]); $data = @file_get_contents($url, false, $context); } if($data){ file_put_contents($cacheFile,$data); return $data; } return false; } function mapCategory($item){ $cats = []; if(isset($item->category)){ foreach($item->category as $c){ $raw = trim((string)$c); if($raw==='') continue; $lc = strtolower($raw); if(str_contains($lc,'technology')) $cats[]='Tech'; elseif(str_contains($lc,'business')||str_contains($lc,'market')||str_contains($lc,'finance')) $cats[]='Business'; elseif(str_contains($lc,'world')||str_contains($lc,'politic')) $cats[]='World'; elseif(str_contains($lc,'science')) $cats[]='Science'; elseif(str_contains($lc,'health')) $cats[]='Health'; elseif(str_contains($lc,'sport')) $cats[]='Sports'; else $cats[] = ucwords($raw); } } return $cats ?: ['Uncategorized']; } function parseFeeds($allFeeds,$dir,$ttl,$selectedCategory){ $items=[]; foreach($allFeeds as $feeds){ foreach($feeds as $f){ $xmlStr = fetchFeed($f,$dir.'/'.md5($f).'.xml',$ttl); if(!$xmlStr) continue; $xml=@simplexml_load_string($xmlStr); if(!$xml) continue; // Support both RSS and Atom $entries = $xml->channel->item ?? $xml->entry ?? []; foreach($entries as $i){ $cat = mapCategory($i); // do NOT filter here (frontend handles filtering) // if($selectedCategory !== 'All News' && !in_array($selectedCategory, $cat)) continue; $link = isset($i->link['href']) ? (string)$i->link['href'] : (string)$i->link; $desc = isset($i->summary) ? (string)$i->summary : (string)$i->description; $items[]=[ "title"=>(string)$i->title, "link"=>$link, "desc"=>strip_tags($desc), "date"=>(string)($i->pubDate ?? $i->updated), "source"=>preg_replace('/^www\./','',parse_url($link,PHP_URL_HOST)), "categories"=>$cat ]; } } } // fallback if feeds fail if(empty($items)){ $items[]=[ "title"=>"Feed unavailable", "link"=>"#", "desc"=>"RSS feeds could not be loaded. Check hosting or network.", "date"=>date('r'), "source"=>"system", "category"=>"System" ]; } usort($items,function($a,$b){return strtotime($b['date'])-strtotime($a['date']);}); return $items; } if(isset($_GET['api'])){ header('Content-Type: application/json'); $cat=$_GET['cat'] ?? 'All News'; echo json_encode(parseFeeds($FEEDS,$CACHE_DIR,$CACHE_TTL,$cat)); exit; } ?> News Dashboard

📰 News

LIVE