set_cache_location(__DIR__ . '/cache'); // 1. Get feeds $stmt = $pdo->query("SELECT id, rss_url FROM feeds"); $feeds_list = $stmt->fetchAll(); foreach ($feeds_list as $row) { $feed->set_feed_url($row['rss_url']); $feed->init(); $feed->handle_content_type(); foreach ($feed->get_items() as $item) { // FIX: Decode HTML entities so "AT&T" becomes "AT&T" $title = html_entity_decode($item->get_title(), ENT_QUOTES | ENT_HTML5); $desc = html_entity_decode($item->get_description(), ENT_QUOTES | ENT_HTML5); $link = $item->get_permalink(); $date = $item->get_date('Y-m-d H:i:s'); if (!$date) { $date = date('Y-m-d H:i:s'); } $sql = "INSERT IGNORE INTO items (feed_id, title, link, description, pub_date) VALUES (?, ?, ?, ?, ?)"; $stmtInsert = $pdo->prepare($sql); $stmtInsert->execute([$row['id'], $title, $link, $desc, $date]); } } // --- CLEANUP ROUTINE --- // Delete articles older than 30 days, BUT KEEP items marked as 'is_saved' $days_to_keep = 30; $sql_cleanup = "DELETE FROM items WHERE pub_date < DATE_SUB(NOW(), INTERVAL ? DAY) AND is_saved = 0"; $stmtCleanup = $pdo->prepare($sql_cleanup); $stmtCleanup->execute([$days_to_keep]); // ----------------------- // 2. Redirect back to dashboard immediately header("Location: index.php"); exit; ?>