From 409d2145385dba0d7fdb1ef1d8bf8a66a6c9addb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Sun, 4 Feb 2024 11:15:54 +0100 Subject: [PATCH] test inlining --- lib/inliner.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/inliner.php b/lib/inliner.php index d10154f..7342400 100644 --- a/lib/inliner.php +++ b/lib/inliner.php @@ -11,9 +11,16 @@ function inlineLocalStylesFromHref($inputString) { $cssContent = preg_replace_callback('/url\(["\']?(\/.*?|.*?)["\']?\)/i', function($urlMatch) use ($cssDir) { $url = $urlMatch[1]; - $absolutePath = $cssDir . '/' . $url; - $relativePath = ltrim(substr($absolutePath, strlen($_SERVER['DOCUMENT_ROOT'])), '/'); - return 'url("' . $relativePath . '")'; + + // Check if the URL starts with any protocol or // + if (!preg_match('/^([a-zA-Z]+:)?\/\//', $url)) { + $absolutePath = $cssDir . '/' . $url; + $relativePath = ltrim(substr($absolutePath, strlen($_SERVER['DOCUMENT_ROOT'])), '/'); + return 'url("' . $relativePath . '")'; + } else { + // If the URL starts with a protocol or //, leave it unchanged + return 'url("' . $url . '")'; + } }, $cssContent); // Minify the CSS content