--- includes/common.inc.original 2008-01-22 09:36:50.000000000 +0100 +++ includes/common.inc 2008-07-05 21:50:52.000000000 +0200 @@ -1460,10 +1460,14 @@ function drupal_get_css($css = NULL) { if (!isset($css)) { $css = drupal_add_css(); } + $no_module_preprocess = ''; + $no_theme_preprocess = ''; $preprocess_css = variable_get('preprocess_css', FALSE); $directory = file_directory_path(); $is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC); + $group_css_enable = variable_get('group_css_enable', FALSE); + $group_css_limit = variable_get('group_css_limit', 0); foreach ($css as $media => $types) { // If CSS preprocessing is off, we still need to output the styles. @@ -1474,15 +1478,27 @@ 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"; + if ($group_css_enable) { + $no_module_preprocess_media[] = '@import "'. base_path() . $file . $query_string .'";'; + } else { + $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. else if (!$preprocess && $type == 'theme') { - $no_theme_preprocess .= '' ."\n"; + if ($group_css_enable) { + $no_theme_preprocess_media[] = '@import "'. base_path() . $file . $query_string .'";'; + } else { + $no_theme_preprocess .= '' ."\n"; + } } else { - $output .= '' ."\n"; + if ($group_css_enable) { + $output_media[] = '@import "'. base_path() . $file . $query_string .'";'; + } else { + $output .= '' ."\n"; + } } } } @@ -1491,7 +1507,80 @@ function drupal_get_css($css = NULL) { if ($is_writable && $preprocess_css) { $filename = md5(serialize($types)) .'.css'; $preprocess_file = drupal_build_css_cache($types, $filename); - $output .= ''. "\n"; + if ($group_css_enable) { + $output_media[] = '@import "'. base_path() . $preprocess_file .'";'; + } else { + $output .= ''. "\n"; + } + + + } + + if ($group_css_enable && $no_module_preprocess_media) { + if ($group_css_limit > 0 ) { + $i = 1; + $importgroup = ''; + foreach ($no_module_preprocess_media as $importfile) { + $importgroup .= $importfile ."\n"; + if ($i < $group_css_limit) { + $i++; + } else { + $no_module_preprocess .= ''. "\n"; + $importgroup = ''; + $i = 1; + } + } + if (!empty($importgroup)) { + $no_module_preprocess .= ''. "\n"; + } + } else { + $no_module_preprocess .= ''. "\n"; + } + } + + if ($group_css_enable && $no_theme_preprocess_media) { + if ($group_css_limit > 0 ) { + $i = 1; + $importgroup = ''; + foreach ($no_theme_preprocess_media as $importfile) { + $importgroup .= $importfile ."\n"; + if ($i < $group_css_limit) { + $i++; + } else { + $no_theme_preprocess .= ''. "\n"; + $importgroup = ''; + $i = 1; + } + } + if (!empty($importgroup)) { + $no_theme_preprocess .= ''. "\n"; + } + } else { + $no_theme_preprocess .= ''. "\n"; + } + } + + if ($group_css_enable && $output_media) { + if ($group_css_limit > 0 ) { + $i = 1; + $importgroup = ''; + foreach ($output_media as $importfile) { + $importgroup .= $importfile ."\n"; + if ($i < $group_css_limit) { + $i++; + } else { + $output .= ''. "\n"; + $importgroup = ''; + $i = 1; + } + } + if (!empty($importgroup)) { + $output .= ''. "\n"; + } + } else { + $output .= ''. "\n"; + } + } } --- modules/system/system.module.original 2008-01-29 00:00:44.000000000 +0100 +++ modules/system/system.module 2008-07-05 21:51:38.000000000 +0200 @@ -704,12 +704,50 @@ function system_performance_settings() { '#description' => t("Some Drupal modules include their own CSS files. When these modules are enabled, each module's CSS file adds an additional HTTP request to the page, which can increase the load time of each page. These HTTP requests can also slightly increase server load. It is recommended to only turn this option on when your site is in production, as it can interfere with theme development. This option is disabled if you have not set up your files directory, or if your download method is set to private."), ); + $form['group_css'] = array( + '#type' => 'fieldset', + '#title' => t('Group CSS files'), + '#description' => '

' . t('Internet Explorer 6 and 7 ignore css stylesheets after 30 <style> or <link> tags (see Microsoft Knowledge Base 262161 and this issue on drupal.org.', array('@url_kb' => 'http://support.microsoft.com/kb/262161/en-us', '@title_kb' => 'All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer', '@url_issue' => 'http://drupal.org/node/228818', '@title_issue' => 'IE: Stylesheets ignored after 30 link/style tags')) . '

' . '

' . t('The following options provide the possibility to group multiple CSS files per media type into single <style> tags. Because Internet Explorer 6 and 7 also do not process more than 30 CSS files inside one <style> tag, the second option allows to limit the number of CSS files per <style> tag.') . '

' + ); + + $form['group_css']['group_css_enable'] = array( + '#type' => 'radios', + '#title' => t('Group CSS files per media type'), + '#default_value' => intval(variable_get('group_css_enable', FALSE)), + '#options' => array(t('Disabled'), t('Enabled')), + '#description' => t("It is recommended to enable this option if more than 30 CSS stylesheets have to be loaded."), + ); + $form['group_css']['group_css_limit'] = array( + '#type' => 'textfield', + '#title' => t('Limit for the number of CSS files inside each style tag'), + '#default_value' => intval(variable_get('group_css_limit', 0)), + '#size' => 2, + '#maxlength' => 2, + '#description' => t("It is recommended to limit the number of CSS files to 30 if grouping CSS files per media type is enabled. The value 0 means \"no limit\""), + '#field_suffix' => t('CSS stylesheets') + ); + $form['#submit']['system_settings_form_submit'] = array(); $form['#submit']['drupal_clear_css_cache'] = array(); return system_settings_form($form); } +/** + * Validate the submitted performance form. + */ +function system_performance_settings_validate($form_id, $form_values) { + // Validate the combine css settings + if ($form_values['group_css_enable'] == '1') { + if (!is_numeric($form_values['group_css_limit'])) { + form_set_error('group_css_limit', t('The limit for the number of CSS files inside each style tag is invalid. It must be a number between 0 and 99.')); + } + elseif ($form_values['group_css_limit'] < 0 || $form_values['group_css_limit'] > 99) { + form_set_error('group_css_limit', t('The limit for the number of CSS files inside each style tag is invalid. It must be a number between 0 and 99.')); + } + } +} + function system_file_system_settings() { $form['file_directory_path'] = array(