function _mimemail_url in Mime Mail 5
Same name and namespace in other branches
- 6 mimemail.inc \_mimemail_url()
- 7 mimemail.inc \_mimemail_url()
Helper function to format urls
Parameters
$url an url:
Return value
an absolute url, sans mailto:
2 calls to _mimemail_url()
- _mimemail_expand_links in ./
mimemail.inc - Callback for preg_replace_callback()
- _mimemail_file in ./
mimemail.inc - Helper function to extract local files
File
- ./
mimemail.inc, line 494
Code
function _mimemail_url($url, $embed_file = NULL) {
global $base_url;
$url = urldecode($url);
// If the URL is absolute or a mailto, return it as-is.
if (strpos($url, '://') || preg_match('!mailto:!', $url)) {
$url = str_replace(' ', '%20', $url);
return $url;
}
$url = preg_replace('!^' . base_path() . '!', '', $url, 1);
// If we're processing to embed the file, we're done here so return.
if ($embed_file) {
return $url;
}
if (!preg_match('!^\\?q=*!', $url)) {
$strip_clean = TRUE;
}
$url = str_replace('?q=', '', $url);
list($url, $fragment) = explode('#', $url, 2);
list($path, $query) = explode('?', $url, 2);
// If we're dealing with an intra-document reference, return it.
if (empty($path) && !empty($fragment)) {
return '#' . $fragment;
}
// If we have not yet returned, then let's clean things up and leave.
$url = url($path, $query, $fragment, TRUE);
// If url() added a ?q= where there should not be one, remove it.
if ($strip_clean) {
$url = preg_replace('!\\?q=!', '', $url);
}
$url = str_replace('+', '%20', $url);
return $url;
}