Created
January 17, 2013 23:01
-
-
Save joshkoenig/4560704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function file_create_url($path) { | |
<<<<<<< HEAD | |
// Clean up Windows paths. | |
$old_path = $path = str_replace('\\', '/', $path); | |
drupal_alter('file_url', $path); | |
// If any module has altered the path, then return the alteration. | |
if ($path != $old_path) { | |
return $path; | |
======= | |
// Strip file_directory_path from $path. We only include relative paths in URLs. | |
if (strpos($path, file_directory_path() .'/') === 0) { | |
$path = trim(substr($path, strlen(file_directory_path())), '\\/'); | |
>>>>>>> b3ecb6e33f1d6edbbd8759b850a6aaa46760f9c6 | |
} | |
// Otherwise serve the file from Drupal's web server. This point will only | |
// be reached when either no custom_file_url_rewrite() function has been | |
// defined, or when that function returned FALSE, thereby indicating that it | |
// cannot (or doesn't wish to) rewrite the URL. This is typically because | |
// the file doesn't match some conditions to be served from a CDN or static | |
// file server, or because the file has not yet been synced to the CDN or | |
// static file server. | |
// Shipped files. | |
if (strpos($path, file_directory_path() . '/') !== 0) { | |
return base_path() . $path; | |
} | |
// Created files. | |
else { | |
switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) { | |
case FILE_DOWNLOADS_PUBLIC: | |
return $GLOBALS['base_url'] . '/' . $path; | |
case FILE_DOWNLOADS_PRIVATE: | |
// Strip file_directory_path from $path. Private downloads' URLs are | |
// rewritten to be served relatively to system/files (which is a menu | |
// callback that streams the file) instead of relatively to the file | |
// directory path. | |
$path = file_directory_strip($path); | |
return url('system/files/' . $path, array('absolute' => TRUE)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment