diff options
author | emkael <emkael@tlen.pl> | 2025-07-02 16:08:19 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2025-07-02 16:08:19 +0200 |
commit | 215e174305ef33d7733406bbf19a23bd2c892b41 (patch) | |
tree | 81b93c234e760cb5b58ddb2654e8b2fbe13b7507 | |
parent | 37d70d7fcae8c1488b5265cd56fddfa687875c21 (diff) |
Stream context for fetching XML (RSS) data
-rw-r--r-- | providers/XmlFeed.php | 14 |
1 files changed, 13 insertions, 1 deletions
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); } |