aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Feed.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-03-10 23:04:17 +0100
committerGravatar GitHub <noreply@github.com> 2024-03-10 23:04:17 +0100
commitd0072b9fb73a6582c98c7b5a44daf2d6ca39636e (patch)
treebf1992ca2ca7c6ae65c5a63bdb66bf2f4b7850a6 /app/Models/Feed.php
parent01eaaed9bb2268bc1d0509ca4f33d4b075634c9a (diff)
Refactor some cURL options and use CURLOPT_USERPWD (#6177)
* Refactor some cURL options and use CURLOPT_USERPWD fix https://github.com/FreshRSS/FreshRSS/issues/6176 * Fixes
Diffstat (limited to 'app/Models/Feed.php')
-rw-r--r--app/Models/Feed.php44
1 files changed, 22 insertions, 22 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index b8425e86b..a957c8d10 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -174,6 +174,16 @@ class FreshRSS_Feed extends Minz_Model {
];
}
}
+
+ /** @return array<int,mixed> */
+ public function curlOptions(): array {
+ $curl_options = [];
+ if ($this->httpAuth !== '') {
+ $curl_options[CURLOPT_USERPWD] = htmlspecialchars_decode($this->httpAuth, ENT_QUOTES);
+ }
+ return $curl_options;
+ }
+
public function inError(): bool {
return $this->error;
}
@@ -348,11 +358,8 @@ class FreshRSS_Feed extends Minz_Model {
Minz_Exception::ERROR
);
} else {
+ $simplePie = customSimplePie($this->attributes(), $this->curlOptions());
$url = htmlspecialchars_decode($this->url, ENT_QUOTES);
- if ($this->httpAuth != '') {
- $url = preg_replace('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $url) ?? '';
- }
- $simplePie = customSimplePie($this->attributes());
if (substr($url, -11) === '#force_feed') {
$simplePie->force_feed(true);
$url = substr($url, 0, -11);
@@ -636,16 +643,12 @@ class FreshRSS_Feed extends Minz_Model {
return null;
}
$feedSourceUrl = htmlspecialchars_decode($this->url, ENT_QUOTES);
- if ($this->httpAuth != '') {
- $feedSourceUrl = preg_replace('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $feedSourceUrl);
- }
if ($feedSourceUrl == null) {
return null;
}
- $cachePath = FreshRSS_Feed::cacheFilename($feedSourceUrl, $this->attributes(), $this->kind());
$httpAccept = 'json';
- $json = httpGet($feedSourceUrl, $cachePath, $httpAccept, $this->attributes());
+ $json = httpGet($feedSourceUrl, $this->cacheFilename(), $httpAccept, $this->attributes(), $this->curlOptions());
if (strlen($json) <= 0) {
return null;
}
@@ -672,9 +675,6 @@ class FreshRSS_Feed extends Minz_Model {
return null;
}
$feedSourceUrl = htmlspecialchars_decode($this->url, ENT_QUOTES);
- if ($this->httpAuth != '') {
- $feedSourceUrl = preg_replace('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $feedSourceUrl);
- }
if ($feedSourceUrl == null) {
return null;
}
@@ -698,9 +698,8 @@ class FreshRSS_Feed extends Minz_Model {
return null;
}
- $cachePath = FreshRSS_Feed::cacheFilename($feedSourceUrl, $this->attributes(), $this->kind());
- $html = httpGet($feedSourceUrl, $cachePath,
- $this->kind() === FreshRSS_Feed::KIND_XML_XPATH ? 'xml' : 'html', $this->attributes());
+ $httpAccept = $this->kind() === FreshRSS_Feed::KIND_XML_XPATH ? 'xml' : 'html';
+ $html = httpGet($feedSourceUrl, $this->cacheFilename(), $httpAccept, $this->attributes(), $this->curlOptions());
if (strlen($html) <= 0) {
return null;
}
@@ -892,15 +891,16 @@ class FreshRSS_Feed extends Minz_Model {
}
/**
- * @param array<string,mixed> $attributes
+ * @param string $url Overridden URL. Will default to the feed URL.
* @throws FreshRSS_Context_Exception
*/
- public static function cacheFilename(string $url, array $attributes, int $kind = FreshRSS_Feed::KIND_RSS): string {
- $simplePie = customSimplePie($attributes);
+ public function cacheFilename(string $url = ''): string {
+ $simplePie = customSimplePie($this->attributes(), $this->curlOptions());
+ $url = $url ?: htmlspecialchars_decode($this->url);
$filename = $simplePie->get_cache_filename($url);
- if ($kind === FreshRSS_Feed::KIND_HTML_XPATH) {
+ if ($this->kind === FreshRSS_Feed::KIND_HTML_XPATH) {
return CACHE_PATH . '/' . $filename . '.html';
- } elseif ($kind === FreshRSS_Feed::KIND_XML_XPATH) {
+ } elseif ($this->kind === FreshRSS_Feed::KIND_XML_XPATH) {
return CACHE_PATH . '/' . $filename . '.xml';
} else {
return CACHE_PATH . '/' . $filename . '.spc';
@@ -908,12 +908,12 @@ class FreshRSS_Feed extends Minz_Model {
}
public function clearCache(): bool {
- return @unlink(FreshRSS_Feed::cacheFilename($this->url, $this->attributes(), $this->kind));
+ return @unlink($this->cacheFilename());
}
/** @return int|false */
public function cacheModifiedTime() {
- $filename = FreshRSS_Feed::cacheFilename($this->url, $this->attributes(), $this->kind);
+ $filename = $this->cacheFilename();
clearstatcache(true, $filename);
return @filemtime($filename);
}