From 215e174305ef33d7733406bbf19a23bd2c892b41 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 2 Jul 2025 16:08:19 +0200 Subject: Stream context for fetching XML (RSS) data --- providers/XmlFeed.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/providers/XmlFeed.php b/providers/XmlFeed.php index 0ac5e6f..1af65e2 100644 --- a/providers/XmlFeed.php +++ b/providers/XmlFeed.php @@ -21,8 +21,20 @@ abstract class XmlFeed extends \Providers\Provider { abstract protected function _parseFeedContent($feed); + protected function _fetchFeedContent($url) { + $userAgent = file_get_contents('../config/user-agent'); + $context = stream_context_create([ + 'http' => [ + 'method' => "GET", + 'header' => "Accept: text/html,application/xml,application/xhtml+xml,text/xml\r\nAccept-Language: en;1=0.7\r\nUser-Agent: " . $userAgent, + ] + ]); + return trim(file_get_contents($url, FALSE, $context)); + } + protected function _fetchItems() { - $this->_feedXml = new \SimpleXMLElement($this->_feedUrl, 0, TRUE); + $feedContent = $this->_fetchFeedContent($this->_feedUrl); + $this->_feedXml = new \SimpleXMLElement($feedContent); return $this->_parseFeedContent($this->_feedXml); } -- cgit v1.3.1