From b59414f836682b8448645bbf566bcd311114a684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Sun, 4 Feb 2024 10:39:04 +0100 Subject: [PATCH] test inlining --- lib/inliner.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/inliner.php b/lib/inliner.php index 6beaf73..ac130af 100644 --- a/lib/inliner.php +++ b/lib/inliner.php @@ -14,22 +14,18 @@ function inlineLocalStylesFromHref($inputString) { // Get the content of the local CSS file $cssContent = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/' . $href); - // Replace url() declarations in the CSS content with inline data + // Replace url() declarations in the CSS content with updated paths $cssContent = preg_replace_callback('/url\(["\']?\/(.*?)(?:[?#].*?)?["\']?\)/i', function($urlMatch) { // Extract the URL value $url = $urlMatch[1]; - echo "Hehe: $url"; - // Get the content of the external file specified in the url() - $fileContent = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/' . $url); + // Modify the path as needed + $modifiedPath = '/new/path/' . $url; - // Base64 encode the content for inline use - $base64Content = base64_encode($fileContent); + // Create the updated url() declaration + $updatedUrlDeclaration = 'url("' . $modifiedPath . '")'; - // Create the inline data URI - $dataUri = 'url("data:application/octet-stream;base64,' . $base64Content . '")'; - - return $dataUri; + return $updatedUrlDeclaration; }, $cssContent); // Create an inline style tag with the modified CSS content