From 60d04cb151efa988a7f15553f588d7b55e83610c Mon Sep 17 00:00:00 2001 From: Ben Jeavons Date: Mon, 21 Mar 2011 16:15:51 -0400 Subject: [PATCH] Issue #969824 by Wim Leers: Use file_create_url() instead of base_path() --- fusion_core/template.php | 60 +++++++++++++++++++++++++++++++++++---------- 1 files changed, 46 insertions(+), 14 deletions(-) diff --git a/fusion_core/template.php b/fusion_core/template.php index 3eab681..4934299 100644 --- a/fusion_core/template.php +++ b/fusion_core/template.php @@ -103,20 +103,44 @@ function fusion_core_preprocess_page(&$vars) { // Add grid, color, ie6, ie7, ie8 & local stylesheets, including inherited & rtl versions $grid_style = '/css/' . theme_get_setting('theme_grid'); $themes = fusion_core_theme_paths($theme_key); - $vars['setting_styles'] = $vars['ie6_styles'] = $vars['ie7_styles'] = $vars['ie8_styles'] = $vars['local_styles'] = ''; + $style_categories = array( + // category => file basename + 'setting' => $grid_style, + 'ie6' => 'css/ie6-fixes', + 'ie7' => 'css/ie7-fixes', + 'ie8' => 'css/ie8-fixes', + 'local' => 'css/local', + ); + // Initialize. + $css_files = array(); + foreach (array_keys($style_categories) as $category) { + $vars[$category . '_styles'] = ''; + } + // Find all CSS files that should be added. foreach ($themes as $name => $path) { - $link = '' . "\n" : ''; - $vars['ie6_styles'] .= (file_exists($path . '/css/ie6-fixes.css')) ? $link . '/css/ie6-fixes.css" />' . "\n" : ''; - $vars['ie7_styles'] .= (file_exists($path . '/css/ie7-fixes.css')) ? $link . '/css/ie7-fixes.css" />' . "\n" : ''; - $vars['ie8_styles'] .= (file_exists($path . '/css/ie8-fixes.css')) ? $link . '/css/ie8-fixes.css" />' . "\n" : ''; - $vars['local_styles'] .= (file_exists($path . '/css/local.css')) ? $link . '/css/local.css" />' . "\n" : ''; - if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) { - $vars['setting_styles'] .= (file_exists($path . $grid_style . '-rtl.css')) ? $link . $grid_style . '-rtl.css" />' . "\n" : ''; - $vars['ie6_styles'] .= (file_exists($path . '/css/ie6-fixes-rtl.css')) ? $link . '/css/ie6-fixes-rtl.css" />' . "\n" : ''; - $vars['ie7_styles'] .= (file_exists($path . '/css/ie7-fixes-rtl.css')) ? $link . '/css/ie7-fixes-rtl.css" />' . "\n" : ''; - $vars['ie8_styles'] .= (file_exists($path . '/css/ie8-fixes-rtl.css')) ? $link . '/css/ie8-fixes-rtl.css" />' . "\n" : ''; - $vars['local_styles'] .= (file_exists($path . '/css/local-rtl.css')) ? $link . '/css/local-rtl.css" />' . "\n" : ''; + foreach ($style_categories as $category => $file_basename) { + // Check if a CSS file for this style category exists. + if (file_exists($path . $file_basename . '.css')) { + $css_files[$category] = $path . $file_basename . '.css'; + } + // Check if a CSS file for this style category, but in RTL, exists. + if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($path . $file_basename . '-rtl.css')) { + $css_files[$category] = $path . $file_basename . '-rtl.css'; + } + } + } + $link_prefix = '' . "\n"; + // Add all found CSS files to their corresponding style categories. + foreach ($css_files as $category => $css_file) { + // Use the file_create_url() function to create file URLs when it's + // available, to add automatic support for CDN integration. + // This is also the way it will work in Drupal 7. + if (module_exists('cdn')) { + $vars[$category . '_styles'] .= $link_prefix . file_create_url($css_file) . $link_suffix; + } + else { + $vars[$category . '_styles'] .= $link_prefix . base_path() . $css_file . $link_suffix; } } @@ -132,7 +156,15 @@ function fusion_core_preprocess_page(&$vars) { $imports = array(); foreach ($types as $files) { foreach ($files as $file => $preprocess) { - $imports[] = '@import "'. base_path() . $file .'";'; + // Use the file_create_url() function to create file URLs when it's + // available, to add automatic support for CDN integration. + // This is also the way it will work in Drupal 7. + if (module_exists('cdn')) { + $imports[] = '@import "'. file_create_url($file) .'";'; + } + else { + $imports[] = '@import "'. base_path() . $file .'";'; + } if (count($imports) == 30) { $styles .= $prefix . implode("\n", $imports) . $suffix; $imports = array(); -- 1.7.2