Skip to content

Commit

Permalink
[5.1] version 1
Browse files Browse the repository at this point in the history
  • Loading branch information
brianteeman committed Dec 2, 2023
1 parent f94bd4e commit 41b559d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions libraries/src/Mail/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,25 @@ public static function convertRelativeToAbsoluteUrls($content)
self::checkContent($content);
}

// Replace relative links, image sources with absolute Urls
// Replace relative links, image sources with absolute Urls and lazyloading
$protocols = '[a-zA-Z0-9\-]+:';
$attributes = ['href=', 'src=', 'poster='];
$attributes = ['href=', 'src=', 'poster=', 'loading='];

foreach ($attributes as $attribute) {
if (strpos($content, $attribute) !== false) {
// If the attribute is 'loading=', remove loading="lazy"
if ($attribute === 'loading=') {
$content = preg_replace('/\s' . $attribute . '"lazy"/i', '', $content);
} else {
// Define a regular expression pattern for matching relative URLs in the specified attribute
$regex = '#\s' . $attribute . '"(?!/|' . $protocols . '|\#|\')([^"]*)"#m';

// Replace relative URLs with absolute URLs using the siteUrl variable
$content = preg_replace($regex, ' ' . $attribute . '"' . $siteUrl . '$1"', $content);

}
self::checkContent($content);
}
}

return $content;
}

Expand Down

0 comments on commit 41b559d

Please sign in to comment.