diff options
| author | 2025-08-01 08:30:49 +0200 | |
|---|---|---|
| committer | 2025-08-01 08:30:49 +0200 | |
| commit | e915ebe46ecc76bd00e19a9cc63764ff2e277315 (patch) | |
| tree | 4cb7caf3c8ad5328dab45097c3f92acabc621f5b /lib/lib_rss.php | |
| parent | 188cc0d063b15be22cdd230b808c0bce5cff68e7 (diff) | |
Rework fetch favicons (#7767)
* Use main function `httpGet()` instead of local one;
* Use HTTP cache, also between users;
* Do not default to feed URL when there is no website URL
TODO for later: consider supporting Atom's `<icon>` and RSS 2.0's `<image>` https://github.com/FreshRSS/FreshRSS/issues/7774
Diffstat (limited to 'lib/lib_rss.php')
| -rw-r--r-- | lib/lib_rss.php | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 25405017a..8954f9921 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -432,13 +432,9 @@ function sanitizeHTML(string $data, string $base = '', ?int $maxLength = null): function cleanCache(int $hours = 720): void { // N.B.: GLOB_BRACE is not available on all platforms - $files = array_merge( - glob(CACHE_PATH . '/*.html', GLOB_NOSORT) ?: [], - glob(CACHE_PATH . '/*.json', GLOB_NOSORT) ?: [], - glob(CACHE_PATH . '/*.spc', GLOB_NOSORT) ?: [], - glob(CACHE_PATH . '/*.xml', GLOB_NOSORT) ?: []); + $files = glob(CACHE_PATH . '/*.*', GLOB_NOSORT) ?: []; foreach ($files as $file) { - if (substr($file, -10) === 'index.html') { + if (str_ends_with($file, 'index.html')) { continue; } $cacheMtime = @filemtime($file); @@ -543,7 +539,7 @@ function enforceHtmlBase(string $html, string $href): string { } /** - * @param string $type {html,json,opml,xml} + * @param string $type {html,ico,json,opml,xml} * @param array<string,mixed> $attributes * @param array<int,mixed> $curl_options * @return array{body:string,effective_url:string,redirect_count:int,fail:bool} @@ -574,7 +570,7 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a syslog(LOG_INFO, 'FreshRSS GET ' . $type . ' ' . \SimplePie\Misc::url_remove_credentials($url)); } - $accept = '*/*;q=0.8'; + $accept = ''; switch ($type) { case 'json': $accept = 'application/json,application/feed+json,application/javascript;q=0.9,text/javascript;q=0.8,*/*;q=0.7'; @@ -585,6 +581,9 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a case 'xml': $accept = 'application/xml,application/xhtml+xml,text/xml;q=0.9,*/*;q=0.8'; break; + case 'ico': + $accept = 'image/x-icon,image/vnd.microsoft.icon,image/ico,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.1'; + break; case 'html': default: $accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; @@ -673,9 +672,13 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a } elseif (!is_string($body) || strlen($body) === 0) { $body = ''; } else { - $body = trim($body, " \n\r\t\v"); // Do not trim \x00 to avoid breaking a BOM - if ($type !== 'json') { + if (in_array($type, ['html', 'json', 'opml', 'xml'], true)) { + $body = trim($body, " \n\r\t\v"); // Do not trim \x00 to avoid breaking a BOM + } + if (in_array($type, ['html', 'xml', 'opml'], true)) { $body = enforceHttpEncoding($body, $c_content_type); + } + if (in_array($type, ['html'], true)) { $body = enforceHtmlBase($body, $c_effective_url); } } |
