fixed duplicate enclosure images (#265)
* fixed duplicate enclosure images * added comment * Update xExtension-ImageProxy/extension.php --------- Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
This commit is contained in:
parent
15d66caafb
commit
c726958f3f
1 changed files with 10 additions and 2 deletions
|
|
@ -124,12 +124,20 @@ final class ImageProxyExtension extends Minz_Extension {
|
||||||
$imgs = $doc->getElementsByTagName('img');
|
$imgs = $doc->getElementsByTagName('img');
|
||||||
foreach ($imgs as $img) {
|
foreach ($imgs as $img) {
|
||||||
if ($img->hasAttribute('src')) {
|
if ($img->hasAttribute('src')) {
|
||||||
$newSrc = self::getProxyImageUri($img->getAttribute('src'));
|
$src = $img->getAttribute('src');
|
||||||
|
$newSrc = self::getProxyImageUri($src);
|
||||||
|
/*
|
||||||
|
Due to the URL change, FreshRSS is not aware of already rendered enclosures.
|
||||||
|
Adding data-xextension-imageproxy-original-src / srcset ensures that original URLs are present in the content for the renderer check FreshRSS_Entry->containsLink.
|
||||||
|
*/
|
||||||
|
$img->setAttribute('data-xextension-imageproxy-original-src', $src);
|
||||||
$img->setAttribute('src', $newSrc);
|
$img->setAttribute('src', $newSrc);
|
||||||
}
|
}
|
||||||
if ($img->hasAttribute('srcset')) {
|
if ($img->hasAttribute('srcset')) {
|
||||||
$newSrcSet = preg_replace_callback('/(?:([^\s,]+)(\s*(?:\s+\d+[wx])(?:,\s*)?))/', fn (array $matches) => self::getSrcSetUris($matches), $img->getAttribute('srcset'));
|
$srcSet = $img->getAttribute('srcset');
|
||||||
|
$newSrcSet = preg_replace_callback('/(?:([^\s,]+)(\s*(?:\s+\d+[wx])(?:,\s*)?))/', fn (array $matches) => self::getSrcSetUris($matches), $srcSet);
|
||||||
if ($newSrcSet != null) {
|
if ($newSrcSet != null) {
|
||||||
|
$img->setAttribute('data-xextension-imageproxy-original-srcset', $srcSet);
|
||||||
$img->setAttribute('srcset', $newSrcSet);
|
$img->setAttribute('srcset', $newSrcSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue