From ea8dd3f54b069e9db2ff0df6942fb9600ba47ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matic=20=C5=A0ulc?= Date: Thu, 28 Mar 2024 13:59:02 +0100 Subject: [PATCH] Added proxy configuration dashboard widgets (RSS) --- .../System/Dashboard/Widget/Feed.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/src/Revolution/Processors/System/Dashboard/Widget/Feed.php b/core/src/Revolution/Processors/System/Dashboard/Widget/Feed.php index 1c80540dd51..8db6d363b05 100644 --- a/core/src/Revolution/Processors/System/Dashboard/Widget/Feed.php +++ b/core/src/Revolution/Processors/System/Dashboard/Widget/Feed.php @@ -62,6 +62,11 @@ public function loadFeed($url) $this->modx->cacheManager->writeTree($cachePath); } + $proxy_config = $this->buildProxyOptions(); + if (!empty($proxy_config)) { + $feed->set_curl_options($proxy_config); + } + $feed->set_cache_location($cachePath); $feed->set_useragent($this->modx->getVersionData()['full_version']); $feed->set_feed_url($url); @@ -115,4 +120,28 @@ public function getFileChunk($tpl, array $placeholders = []) return $output; } + + /** + * Build configuration for the SimplePie client based on configuration settings. + * + * @return array The proxy configuration. + */ + private function buildProxyOptions() + { + $config = []; + $proxyHost = $this->modx->getOption('proxy_host', null, ''); + if (!empty($proxyHost)) { + $config['CURLOPT_PROXY'] = $proxyHost; + $proxyPort = $this->modx->getOption('proxy_port', null, ''); + if (!empty($proxyPort)) { + $config['CURLOPT_PROXY'] .= ':' . $proxyPort; + } + $proxyUsername = $this->modx->getOption('proxy_username', null, ''); + if (!empty($proxyUsername)) { + $proxyPassword = $this->modx->getOption('proxy_password', null, ''); + $config['CURLOPT_PROXYUSERPWD'] = $proxyUsername . ':' . $proxyPassword; + } + } + return $config; + } }