function stage_file_proxy_get_file_remote_url in Stage File Proxy 7
Fetches the remote URL for a stage file proxy-processed file.
@todo Should this be run through check_url()?
Parameters
string $relative_path: The path to the requested resource relative to the files directory. This may include a query string already.
array $options: An optional array to pass through to url().
Return value
bool|string The remote URL or FALSE if an origin server is not provided.
2 calls to stage_file_proxy_get_file_remote_url()
- stage_file_proxy_fetch_file in ./
stage_file_proxy.module - Downloads a public file from the origin site.
- stage_file_proxy_process_file_uri in ./
stage_file_proxy.module - Checks to see if a file should be downloaded from the origin site.
File
- ./
stage_file_proxy.module, line 272 - Stage File Proxy Module.
Code
function stage_file_proxy_get_file_remote_url($relative_path, array $options = array()) {
$base_url =& drupal_static(__FUNCTION__);
if (!isset($base_url)) {
$base_url = FALSE;
$server = rtrim(variable_get('stage_file_proxy_origin'), '/');
// Quit if we are the origin. Ignore http(s) in the origin comparison.
if (preg_replace('#^[a-z]*://#', '', $server) == preg_replace('#^[a-z]*://#', '', $GLOBALS['base_url'])) {
return FALSE;
}
if ($server) {
$base_url = $server . '/';
}
if ($dir = trim(variable_get('stage_file_proxy_origin_dir', _stage_file_proxy_file_dir()), '/')) {
$base_url .= drupal_encode_path($dir) . '/';
}
}
if (empty($base_url)) {
return FALSE;
}
$url = $base_url . drupal_encode_path($relative_path);
$options += array(
'external' => TRUE,
);
// Pass through the current query string, if the file is the same as the
// current request.
if ($relative_path === $_GET['q']) {
$options['query'] = drupal_get_query_parameters();
}
return url($url, $options);
}