1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 08:15:55 +00:00

better support for image srcset attributes as discussed in https://community.tt-rss.org/t/problem-with-img-srcset/3519

This commit is contained in:
Andrew Dolgov
2020-06-15 11:58:59 +03:00
parent 697418f863
commit 6eb94f1e13
3 changed files with 43 additions and 25 deletions

View File

@@ -314,22 +314,19 @@ class DiskCache {
}
if ($entry->hasAttribute("srcset")) {
$tokens = explode(",", $entry->getAttribute('srcset'));
$matches = RSSUtils::decode_srcset($entry->getAttribute('srcset'));
for ($i = 0; $i < count($tokens); $i++) {
$token = trim($tokens[$i]);
list ($url, $width) = explode(" ", $token, 2);
$cached_filename = sha1($url);
for ($i = 0; $i < count($matches); $i++) {
$cached_filename = sha1($matches[$i]["url"]);
if ($cache->exists($cached_filename)) {
$tokens[$i] = $cache->getUrl($cached_filename) . " " . $width;
$matches[$i]["url"] = $cache->getUrl($cached_filename);
$need_saving = true;
}
}
$entry->setAttribute("srcset", implode(", ", $tokens));
$entry->setAttribute("srcset", RSSUtils::encode_srcset($matches));
}
}