Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.808 diff -u -p -r1.808 common.inc --- includes/common.inc 12 Oct 2008 19:03:04 -0000 1.808 +++ includes/common.inc 13 Oct 2008 19:43:35 -0000 @@ -1634,6 +1634,42 @@ function drupal_get_path($type, $name) { function base_path() { return $GLOBALS['base_path']; } +/** + * Returns a rewritten file URL. Allows you to serve files from different + * servers than the server on which Drupal is hosted. + * + * @param $file_path + * Path to a file, relative to the root directory. E.g.: "misc/jquery.js". + * @param $absolute_url + * Whether to generate an absolute URL or not. + * @param $query_string + * This variable will be appended to the file url as a query string, this is + * useful particularly for CSS files when you want to control their caching. + * E.g.: "?string". + * @return + * A valid file URL. + */ +function file_url($file_path, $absolute_url = FALSE, $query_string = FALSE) { + $file_url = FALSE; + + foreach (module_implements('file_server') as $module) { + $file_url = module_invoke($module, 'file_server', 'url', $file_path, $absolute_url); + // If the URL rewriting function sucesfully generated a URL, we can stop + // trying to find a server that can serve the file. + if (!empty($file_url)) { + break; + } + } + + // Always fall back to Drupal's default file server, to guarantee a working + // file URL. + if (empty($file_url)) { + $prefix = isset($absolute_url) ? $GLOBALS['base_url'] . '/' : base_path(); + $file_url = $prefix . $file_path; + } + + return $file_url . $query_string; +} /** * Add a tag to the page's HEAD. @@ -1785,15 +1821,15 @@ function drupal_get_css($css = NULL) { // If a CSS file is not to be preprocessed and it's a module CSS file, it needs to *always* appear at the *top*, // regardless of whether preprocessing is on or off. if (!$preprocess && $type == 'module') { - $no_module_preprocess .= '' . "\n"; + $no_module_preprocess .= '' . "\n"; } // If a CSS file is not to be preprocessed and it's a theme CSS file, it needs to *always* appear at the *bottom*, // regardless of whether preprocessing is on or off. elseif (!$preprocess && $type == 'theme') { - $no_theme_preprocess .= '' . "\n"; + $no_theme_preprocess .= '' . "\n"; } else { - $output .= '' . "\n"; + $output .= '' . "\n"; } } } @@ -1803,7 +1839,7 @@ function drupal_get_css($css = NULL) { if ($is_writable && $preprocess_css) { $filename = md5(serialize($types) . $query_string) . '.css'; $preprocess_file = drupal_build_css_cache($types, $filename); - $output .= '' . "\n"; + $output .= '' . "\n"; } } @@ -2137,7 +2173,8 @@ function drupal_get_js($scope = 'header' // Additionally, go through any remaining scripts if JS preprocessing is on and output the non-cached ones. foreach ($data as $path => $info) { if (!$info['preprocess'] || !$is_writable || !$preprocess_js) { - $no_preprocess[$type] .= '\n"; + $no_preprocess[$type] .= '\n"; + } else { $files[$path] = $info; Index: includes/file.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/file.inc,v retrieving revision 1.139 diff -u -p -r1.139 file.inc --- includes/file.inc 12 Oct 2008 04:30:05 -0000 1.139 +++ includes/file.inc 13 Oct 2008 19:43:35 -0000 @@ -98,7 +98,7 @@ function file_create_url($path) { } switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) { case FILE_DOWNLOADS_PUBLIC: - return $GLOBALS['base_url'] . '/' . file_directory_path() . '/' . str_replace('\\', '/', $path); + return file_url(file_directory_path() . '/' . str_replace('\\', '/', $path), TRUE); case FILE_DOWNLOADS_PRIVATE: return url('system/files/' . $path, array('absolute' => TRUE)); } Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.438 diff -u -p -r1.438 theme.inc --- includes/theme.inc 12 Oct 2008 04:30:05 -0000 1.438 +++ includes/theme.inc 13 Oct 2008 19:43:35 -0000 @@ -934,24 +934,25 @@ function theme_get_setting($setting_name if ($settings['toggle_logo']) { if ($settings['default_logo']) { - $settings['logo'] = base_path() . dirname($theme_object->filename) . '/logo.png'; + $settings['logo'] = file_url(dirname($theme_object->filename) . '/logo.png'); + } elseif ($settings['logo_path']) { - $settings['logo'] = base_path() . $settings['logo_path']; + $settings['logo'] = file_url($settings['logo_path']); } } if ($settings['toggle_favicon']) { if ($settings['default_favicon']) { if (file_exists($favicon = dirname($theme_object->filename) . '/favicon.ico')) { - $settings['favicon'] = base_path() . $favicon; + $settings['favicon'] = file_url($favicon); } else { - $settings['favicon'] = base_path() . 'misc/favicon.ico'; + $settings['favicon'] = file_url('misc/favicon.ico'); } } elseif ($settings['favicon_path']) { - $settings['favicon'] = base_path() . $settings['favicon_path']; + $settings['favicon'] = file_url($settings['favicon_path']); } else { $settings['toggle_favicon'] = FALSE; @@ -1169,8 +1170,7 @@ function theme_links($links, $attributes function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) { if (!$getsize || (is_file($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) { $attributes = drupal_attributes($attributes); - $url = (url($path) == $path) ? $path : (base_path() . $path); - return '' . check_plain($alt) . ''; + return '' . check_plain($alt) . ''; } }