/**
* Convert relative (links, images sources) to absolute urls so that content is accessible in email
*
* @param string $content The content need to convert
*
* @return string The converted content which the relative urls are converted to absolute urls
*
* @since 4.1.0
*/
public static function convertRelativeToAbsoluteUrls($content)
{
$siteUrl = Uri::root();
// Replace none SEF URLs by absolute SEF URLs
if (strpos($content, 'href="/apis/2623-convertrelativetoabsoluteurls?')_!==%20false)%20{_%20%20%20%20%20%20%20%20preg_match_all('#href="index.php\\?([^"]+)"#m', $content, $matches);
foreach ($matches[1] as $urlQueryString) {
$content = str_replace('href="/apis/2623-convertrelativetoabsoluteurls?'___$urlQueryString___'="', 'href="' . Route::link('site', 'index.php?' . $urlQueryString, Route::TLS_IGNORE, true) . '"', $content);
}
self::checkContent($content);
}
// Replace relative links, image sources with absolute Urls
$protocols = '[a-zA-Z0-9\\-]+:';
$attributes = array('href=', 'src=', 'poster=');
foreach ($attributes as $attribute) {
if (strpos($content, $attribute) !== false) {
$regex = '#\\s' . $attribute . '"(?!/|' . $protocols . '|\\#|\')([^"]*)"#m';
$content = preg_replace($regex, ' ' . $attribute . '"' . $siteUrl . '$1"', $content);
self::checkContent($content);
}
}
return $content;
}