--- includes/common.inc.original 2008-04-09 23:11:44.000000000 +0200 +++ includes/common.inc 2008-07-05 21:42:42.000000000 +0200 @@ -1688,6 +1688,9 @@ function drupal_get_css($css = NULL) { $no_theme_preprocess = ''; $preprocess_css = (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update')); + $group_css_enable = variable_get('group_css_enable', FALSE); + $group_css_limit = variable_get('group_css_limit', 0); + $directory = file_directory_path(); $is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC); @@ -1700,6 +1703,11 @@ function drupal_get_css($css = NULL) { foreach ($css as $media => $types) { // 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. + if ($group_css_enable) { + $no_module_preprocess_media = array(); + $no_theme_preprocess_media = array(); + $output_media = array(); + } foreach ($types as $type => $files) { if ($type == 'module') { // Setup theme overrides for module styles. @@ -1718,15 +1726,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"; + } } } } @@ -1735,7 +1755,78 @@ 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"; + 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.admin.inc.original 2008-03-25 11:58:16.000000000 +0100 +++ modules/system/system.admin.inc 2008-07-05 21:43:40.000000000 +0200 @@ -1334,6 +1334,29 @@ function system_performance_settings() { '#description' => t('This option can interfere with module development and should only be enabled in a production environment.'), ); + $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['clear_cache'] = array( '#type' => 'fieldset', '#title' => t('Clear cached data'), @@ -1353,6 +1376,21 @@ function system_performance_settings() { } /** + * Validate the submitted performance form. + */ +function system_performance_settings_validate($form, &$form_state) { + // Validate the combine css settings + if ($form_state['values']['group_css_enable'] == '1') { + if (!is_numeric($form_state['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_state['values']['group_css_limit'] < 0 || $form_state['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.')); + } + } +} + +/** * Submit callback; clear system caches. * * @ingroup forms