public static function MailFormatHelper::absoluteMailUrls in Simplenews 3.x
Same name and namespace in other branches
- 8.2 src/Mail/MailFormatHelper.php \Drupal\simplenews\Mail\MailFormatHelper::absoluteMailUrls()
- 8 src/Mail/MailFormatHelper.php \Drupal\simplenews\Mail\MailFormatHelper::absoluteMailUrls()
Replaces URLs with absolute URLs.
File
- src/
Mail/ MailFormatHelper.php, line 46
Class
- MailFormatHelper
- Extended mail formatter helpers.
Namespace
Drupal\simplenews\MailCode
public static function absoluteMailUrls($match) {
global $base_url, $base_path;
$regexp =& drupal_static(__FUNCTION__);
$url = $label = '';
if ($match) {
if (empty($regexp)) {
$regexp = '@^' . preg_quote($base_path, '@') . '@';
}
list(, $url, $label) = $match;
$url = strpos($url, '://') ? $url : preg_replace($regexp, $base_url . '/', $url);
// If the link is formed by Drupal's URL filter, we only return the URL.
// The URL filter generates a label out of the original URL.
if (strpos($label, '...') === mb_strlen($label) - 3) {
// Remove ellipsis from end of label.
$label = mb_substr($label, 0, mb_strlen($label) - 3);
}
if (strpos($url, $label) !== FALSE) {
return $url;
}
return $label . ' ' . $url;
}
}