--- includes/common.inc.original 2008-07-02 18:15:54.000000000 +0200
+++ includes/common.inc 2008-07-03 18:54:12.000000000 +0200
@@ -1457,32 +1457,56 @@ function drupal_add_css($path = NULL, $t
*/
function drupal_get_css($css = NULL) {
$output = '';
+ // modified by brahms as a workaround for IE issue on http://drupal.org/node/228818
+ // the patch for Drupal 5.7 can be found in brahms comment#26 on this issue
+ $no_module_preprocess = '';
+ $no_theme_preprocess = '';
if (!isset($css)) {
$css = drupal_add_css();
}
$preprocess_css = variable_get('preprocess_css', FALSE);
+ $combine_css = variable_get('combine_css', FALSE);
+ $combine_max_css = variable_get('combine_max_css', 0);
+
$directory = file_directory_path();
$is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC);
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 ($combine_css) {
+ $no_module_preprocess_media = array();
+ $no_theme_preprocess_media = array();
+ $output_media = array();
+ }
foreach ($types as $type => $files) {
foreach ($types[$type] as $file => $preprocess) {
if (!$preprocess || !($is_writable && $preprocess_css)) {
// 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 ($combine_css) {
+ $no_module_preprocess_media[] = '@import "'. base_path() . $file .'";';
+ } 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 ($combine_css) {
+ $no_theme_preprocess_media[] = '@import "'. base_path() . $file .'";';
+ } else {
+ $no_theme_preprocess .= '' ."\n";
+ }
}
else {
- $output .= '' ."\n";
+ if ($combine_css) {
+ $output_media[] = '@import "'. base_path() . $file .'";';
+ } else {
+ $output .= '' ."\n";
+ }
}
}
}
@@ -1491,10 +1515,79 @@ 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 ($combine_css) {
+ $output_media[] = '@import "'. base_path() . $preprocess_file .'";';
+ } else {
+ $output .= ''. "\n";
+ }
+ }
+
+ if ($combine_css && $no_module_preprocess_media) {
+ if ($combine_max_css > 0 ) {
+ $i = 1;
+ $importgroup = '';
+ foreach ($no_module_preprocess_media as $importfile) {
+ $importgroup .= $importfile ."\n";
+ if ($i < $combine_max_css) {
+ $i++;
+ } else {
+ $no_module_preprocess .= ''. "\n";
+ $importgroup = '';
+ $i = 1;
+ }
+ }
+ if (!empty($importgroup)) {
+ $no_module_preprocess .= ''. "\n";
+ }
+ } else {
+ $no_module_preprocess .= ''. "\n";
+ }
+ }
+
+ if ($combine_css && $no_theme_preprocess_media) {
+ if ($combine_max_css > 0 ) {
+ $i = 1;
+ $importgroup = '';
+ foreach ($no_theme_preprocess_media as $importfile) {
+ $importgroup .= $importfile ."\n";
+ if ($i < $combine_max_css) {
+ $i++;
+ } else {
+ $no_theme_preprocess .= ''. "\n";
+ $importgroup = '';
+ $i = 1;
+ }
+ }
+ if (!empty($importgroup)) {
+ $no_theme_preprocess .= ''. "\n";
+ }
+ } else {
+ $no_theme_preprocess .= ''. "\n";
+ }
}
- }
+ if ($combine_css && $output_media) {
+ if ($combine_max_css > 0 ) {
+ $i = 1;
+ $importgroup = '';
+ foreach ($output_media as $importfile) {
+ $importgroup .= $importfile ."\n";
+ if ($i < $combine_max_css) {
+ $i++;
+ } else {
+ $output .= ''. "\n";
+ $importgroup = '';
+ $i = 1;
+ }
+ }
+ if (!empty($importgroup)) {
+ $output .= ''. "\n";
+ }
+ } else {
+ $output .= ''. "\n";
+ }
+ }
+ }
return $no_module_preprocess . $output . $no_theme_preprocess;
}
--- modules/system/_system.module.original 2008-07-03 18:49:28.000000000 +0200
+++ modules/system/system.module 2008-07-03 18:54:56.000000000 +0200
@@ -703,13 +703,46 @@ function system_performance_settings() {
'#options' => array(t('Disabled'), t('Enabled')),
'#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."),
);
-
+// added by rkl as a workaround for IE issue on http://drupal.org/node/228818 - BEGIN
+ $form['bandwidth_optimizations']['combine_css'] = array(
+ '#type' => 'radios',
+ '#title' => t('Combine CSS files per media type'),
+ '#default_value' => intval(variable_get('combine_css', FALSE)),
+ '#options' => array(t('Disabled'), t('Enabled')),
+ '#description' => t("Internet Explorer ignores css stylesheets after 30 link/style tags (see this issue on drupal.org. By enabling this option all import links for css files are combined into one <style> tag per media type to reduce the number of tags."),
+ );
+ $form['bandwidth_optimizations']['combine_max_css'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Max. number of CSS files inside one style tag'),
+ '#default_value' => intval(variable_get('combine_max_css', 0)),
+ '#size' => 2,
+ '#maxlength' => 2,
+ '#description' => t("It is recommended to use a value of 30, this works best in Internet Explorer. You should not group together more than 30 CSS stylesheets. If you set this value too low, you might end in trouble getting more than 30 style tags. The value 0 means \"no limitation\""),
+ '#field_suffix' => t('CSS stylesheets')
+ );
+// added by rkl as a workaround for IE issue on http://drupal.org/node/228818 - END
$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['combine_css'] == '1') {
+ // TCP allows the port to be between 0 and 65536 inclusive
+ if (!is_numeric($form_values['combine_max_css'])) {
+ form_set_error('combine_max_css', t('Max. number of CSS files inside one style tag is invalid. It must be a number between 0 and 99.'));
+ }
+ elseif ($form_values['combine_max_css'] < 0 || $form_values['combine_max_css'] >= 99) {
+ form_set_error('combine_max_css', t('Max. number of CSS files inside one style tag is invalid. It must be a number between 0 and 99'));
+ }
+ }
+}
+
function system_file_system_settings() {
$form['file_directory_path'] = array(