From 8ff39f64f7554de110cb4296e199789d9fa7f5a8 Mon Sep 17 00:00:00 2001 From: ORelio Date: Fri, 20 Oct 2023 13:31:52 +0200 Subject: [PATCH] [html] add data-orig-file tag (#3777) Add support for data-orig-file tag in convertLazyLoading() Remplace end() with array_key_last() as discussed in #3769 Fix typo in comment --- lib/html.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/html.php b/lib/html.php index ba8067a6..1de581d9 100644 --- a/lib/html.php +++ b/lib/html.php @@ -249,7 +249,7 @@ function convertLazyLoading($dom) // Example: convert "header640.png 640w, header960.png 960w, header1024.png 1024w" to "header1024.png" $srcset_to_src = function ($srcset) { $sources = explode(',', $srcset); - $last_entry = trim(end($sources)); + $last_entry = trim($sources[array_key_last($sources)]); $url = explode(' ', $last_entry)[0]; return $url; }; @@ -262,12 +262,15 @@ function convertLazyLoading($dom) $img->src = $srcset_to_src($img->getAttribute('data-srcset')); } elseif (!empty($img->getAttribute('data-lazy-src'))) { $img->src = $img->getAttribute('data-lazy-src'); + } elseif (!empty($img->getAttribute('data-orig-file'))) { + $img->src = $img->getAttribute('data-orig-file'); } elseif (!empty($img->getAttribute('srcset'))) { $img->src = $srcset_to_src($img->getAttribute('srcset')); } else { continue; // Proceed to next element without removing attributes } - foreach (['loading', 'decoding', 'srcset', 'data-src', 'data-srcset'] as $attr) { + // Remove attributes that may be processed by the client (data-* are not) + foreach (['loading', 'decoding', 'srcset'] as $attr) { if ($img->hasAttribute($attr)) { $img->removeAttribute($attr); } @@ -284,7 +287,7 @@ function convertLazyLoading($dom) $img->tag = 'img'; } // Adding/removing node would change its position inside the parent element, - // So instead we rewrite the node in-place though the outertext attribute + // So instead we rewrite the node in-place through the outertext attribute $picture->outertext = $img->outertext; } }