Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1077 diff -u -p -r1.1077 common.inc --- includes/common.inc 4 Jan 2010 23:08:34 -0000 1.1077 +++ includes/common.inc 6 Jan 2010 00:54:06 -0000 @@ -3281,16 +3281,8 @@ function drupal_get_css($css = NULL) { // If CSS preprocessing is off, we still need to output the styles. // Additionally, go through any remaining styles if CSS preprocessing is on // and output the non-cached ones. - $css_element = array( - '#tag' => 'link', - '#attributes' => array( - 'type' => 'text/css', - 'rel' => 'stylesheet', - ), - ); - $rendered_css = array(); - $inline_css = ''; - $external_css = ''; + $files = array(); + $inline = array(); $preprocess_items = array(); foreach ($css as $data => $item) { // Loop through each of the stylesheets, including them appropriately based @@ -3299,28 +3291,22 @@ function drupal_get_css($css = NULL) { case 'file': // Depending on whether aggregation is desired, include the file. if (!$item['preprocess'] || !($is_writable && $preprocess_css)) { - $element = $css_element; - $element['#attributes']['media'] = $item['media']; - $element['#attributes']['href'] = file_create_url($item['data']) . $query_string; - $rendered_css[] = theme('html_tag', array('element' => $element)); + $files[] = array('media' => $item['media'], 'href' => file_create_url($item['data']) . $query_string, 'external' => FALSE); } else { $preprocess_items[$item['media']][] = $item; // Mark the position of the preprocess element, // it should be at the position of the first preprocessed file. - $rendered_css['preprocess'] = ''; + $files['preprocess_' . $item['media']] = NULL; } break; case 'inline': // Include inline stylesheets. - $inline_css .= drupal_load_stylesheet_content($item['data'], $item['preprocess']); + $inline[] = drupal_load_stylesheet_content($item['data'], $item['preprocess']); break; case 'external': // Preprocessing for external CSS files is ignored. - $element = $css_element; - $element['#attributes']['media'] = $item['media']; - $element['#attributes']['href'] = $item['data']; - $external_css .= theme('html_tag', array('element' => $element)); + $files[] = array('media' => $item['media'], 'href' => $item['data'], 'external' => TRUE); break; } } @@ -3329,24 +3315,13 @@ function drupal_get_css($css = NULL) { foreach ($preprocess_items as $media => $items) { // Prefix filename to prevent blocking by firewalls which reject files // starting with "ad*". - $element = $css_element; - $element['#attributes']['media'] = $media; $filename = 'css_' . md5(serialize($items) . $query_string) . '.css'; - $element['#attributes']['href'] = file_create_url(drupal_build_css_cache($items, $filename)); - $rendered_css['preprocess'] .= theme('html_tag', array('element' => $element)); + $files['preprocess_' . $media] .= array('media' => $item['media'], 'href' => file_create_url(drupal_build_css_cache($items, $filename)), 'external' => FALSE); } } - // Enclose the inline CSS with the style tag if required. - if (!empty($inline_css)) { - $element = $css_element; - $element['#tag'] = 'style'; - $element['#value'] = $inline_css; - unset($element['#attributes']['rel']); - $inline_css = "\n" . theme('html_tag', array('element' => $element)); - } - // Output all the CSS files with the inline stylesheets showing up last. - return implode($rendered_css) . $external_css . $inline_css; + // Output all the CSS files. + return theme('stylesheets', array('files' => $files, 'inline' => $inline)); } /** @@ -5485,6 +5460,9 @@ function drupal_common_theme() { 'html_tag' => array( 'render element' => 'element', ), + 'stylesheets' => array( + 'variables' => array('files' => array(), 'inline' => array()), + ), // from theme.maintenance.inc 'maintenance_page' => array( 'variables' => array('content' => NULL, 'show_messages' => TRUE), Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.563 diff -u -p -r1.563 theme.inc --- includes/theme.inc 5 Jan 2010 18:56:48 -0000 1.563 +++ includes/theme.inc 6 Jan 2010 00:54:06 -0000 @@ -2033,6 +2033,81 @@ function theme_html_tag($variables) { } /** + * Generate the LINK and STYLE tags for adding CSS stylesheets to the page. + * + * @param $variables + * An associative array containing: + * - files: An array of CSS files to include. Each item in the array has the + * following keys: + * - media: The media for which the CSS file is appropriate. + * - href: The URL of the CSS file. + * - external: Boolean. TRUE if the CSS file is external to the website (if + * it was added to drupal_add_css() using 'external' for the type option). + * - inline: An array of inline CSS content. Each item in the array is a CSS + * string. + * + * @ingroup themeable + */ +function theme_stylesheets($variables) { + $output = ''; + + // Defaults for LINK and STYLE elements. + $link_element_defaults = array( + '#tag' => 'link', + '#attributes' => array( + 'type' => 'text/css', + 'rel' => 'stylesheet', + ), + ); + $style_element_defaults = array( + '#tag' => 'style', + '#attributes' => array( + 'type' => 'text/css', + ), + ); + + // IE chokes on more than 31 stylesheets added with a LINK tag: + // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx. + $files_to_link = array_slice($variables['files'], 0, 31); + $files_to_import = array_slice($variables['files'], 31); + + // Add the LINK tags. + foreach ($files_to_link as $file) { + $element = $link_element_defaults; + $element['#attributes']['media'] = $file['media']; + $element['#attributes']['href'] = $file['href']; + $output .= theme('html_tag', array('element' => $element)); + } + + // Add remaining CSS files with a STYLE tag. On a production website, CSS + // aggregation should be turned on, because lots of files to load increases + // network traffic and slows down page load. With aggregation turned on, it's + // very unlikely that there would be >31 CSS files, so they would all be + // loaded with LINK tags. However, during development, CSS aggregation is + // often turned off, a site using many modules can easily have pages that use + // >31 stylesheets, and for these pages to display correctly in IE, the + // remaining CSS files must be added using a STYLE tag. + if (!empty($files_to_import)) { + $import = ''; + foreach ($files_to_import as $file) { + $import .= '@import url("' . $file['href'] . '") ' . $file['media'] . ";\n"; + } + $element = $style_element_defaults; + $element['#value'] = $import; + $output .= theme('html_tag', array('element' => $element)); + } + + // Add inline CSS content. + if (!empty($variables['inline'])) { + $element = $style_element_defaults; + $element['#value'] = implode($variables['inline']); + $output .= theme('html_tag', array('element' => $element)); + } + + return $output; +} + +/** * Returns code that emits the 'more' link used on blocks. * * @param $variables