protocol_relative_urls.module in Protocol Relative URLs 7
File
protocol_relative_urls.module
View source
<?php
function protocol_relative_urls_file_url_alter(&$url) {
global $base_url;
static $relative_base_url = NULL, $relative_base_length = NULL;
$scheme = file_uri_scheme($url);
if (!$relative_base_url || !$relative_base_length) {
$relative_base_url = '//' . file_uri_target($base_url);
$relative_base_length = strlen($relative_base_url);
}
if (!$scheme && substr($url, 0, $relative_base_length) == $relative_base_url) {
return;
}
if (!$scheme || $scheme == 'public') {
if (!$scheme) {
$path = $url;
}
else {
$wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
$path = $wrapper
->getDirectoryPath() . '/' . file_uri_target($url);
}
$path = str_replace('\\', '/', $path);
$url = $base_url . '/' . $path;
}
$protocols = array(
'http',
'https',
);
$scheme = file_uri_scheme($url);
if ($scheme && in_array($scheme, $protocols)) {
$url = '//' . file_uri_target($url);
}
}
function protocol_relative_urls_module_implements_alter(&$implementations, $hook) {
if ($hook === 'file_url_alter' && array_key_exists('protocol_relative_urls', $implementations)) {
$item = $implementations['protocol_relative_urls'];
unset($implementations['protocol_relative_urls']);
$implementations['protocol_relative_urls'] = $item;
}
}