function _cdn_generate_url_prefix_regex in CDN 6.2
Same name and namespace in other branches
- 7.2 cdn.fallback.inc \_cdn_generate_url_prefix_regex()
Generate the URL prefix regular expression, that supports all possible types of file URLs: root-relative, protocol-relative and absolute URLs.
3 calls to _cdn_generate_url_prefix_regex()
- cdn_html_alter_css_urls in ./
cdn.fallback.inc - Alter CSS file URLs in a piece of HTML.
- cdn_html_alter_image_urls in ./
cdn.fallback.inc - Alter image file URLs in a piece of HTML.
- cdn_html_alter_js_urls in ./
cdn.fallback.inc - Alter JS file URLs in a piece of HTML.
File
- ./
cdn.fallback.inc, line 98 - Fallback when hook_file_url_alter() is not available (i.e. when the core patch is not installed or when not using a patched Drupal distribution): use the Parallel module's logic (with some adaptations to be able to use the CDN module's logic…
Code
function _cdn_generate_url_prefix_regex() {
global $base_url;
static $url_prefix_regex;
if (!isset($url_prefix_regex)) {
$url_prefixes = array(
preg_quote(base_path()) . '(?!/)',
// Root-relative URL.
// Note: root-relative URL that isn't a protocol-relative URL. The
// negative lookahead for a trailing slash is relaly only necessary
// when this site is installed in the document root (i.e. when the base
// path equals "/"), because this would otherwise match *all* protocol-
// relative URLs, also those that already point to the CDN.
preg_quote('//' . $_SERVER['HTTP_HOST'] . base_path()),
// Protocol-relative URL.
preg_quote($base_url . '/'),
);
$regexes = array();
$farfuture = preg_quote('cdn/farfuture/');
foreach ($url_prefixes as $url_prefix) {
$regexes[] = $url_prefix . '(?!' . $farfuture . ')';
}
// The URL prefix regex that will match all URLs to the current site,
// except for those that already point to Far Future expiration URLs.
$url_prefix_regex = implode('|', $regexes);
}
return $url_prefix_regex;
}