### Eclipse Workspace Patch 1.0
#P Drupal Head
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.766
diff -u -r1.766 common.inc
--- includes/common.inc	14 May 2008 13:15:09 -0000	1.766
+++ includes/common.inc	16 May 2008 21:44:07 -0000
@@ -1581,8 +1581,10 @@
 /**
  * Adds a CSS file to the stylesheet queue.
  *
- * @param $path
- *   (optional) The path to the CSS file relative to the base_path(), e.g.,
+ * @param $data
+ *   (optional) If given, the value depends on the $type parameter:
+ *   - 'inline': The CSS code that should be placed in the given scope.
+ *   - 'module' or 'theme': Path to the file relative to base_path(), e.g.,
  *   /modules/devel/devel.css.
  *
  *   Modules should always prefix the names of their CSS files with the module
@@ -1599,13 +1601,13 @@
  *   should contain overrides for properties which should be reversed or
  *   otherwise different in a right-to-left display.
  * @param $type
- *   (optional) The type of stylesheet that is being added. Types are: module
- *   or theme.
+ *   (optional) The type of stylesheet that is being added. Types are: module,
+ *   theme or inline.
  * @param $media
  *   (optional) The media type for the stylesheet, e.g., all, print, screen.
  * @param $preprocess
- *   (optional) Should this CSS file be aggregated and compressed if this
- *   feature has been turned on under the performance section?
+ *   (optional) Should the CSS be aggregated and compressed if this feature
+ *   has been turned on under the performance section?
  *
  *   What does this actually mean?
  *   CSS preprocessing is the process of aggregating a bunch of separate CSS
@@ -1629,21 +1631,21 @@
  * @return
  *   An array of CSS files.
  */
-function drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preprocess = TRUE) {
+function drupal_add_css($data = NULL, $type = 'module', $media = 'all', $preprocess = TRUE) {
   static $css = array();
   global $language;
 
   // Create an array of CSS files for each media type first, since each type needs to be served
   // to the browser differently.
-  if (isset($path)) {
+  if (isset($data)) {
     // This check is necessary to ensure proper cascading of styles and is faster than an asort().
     if (!isset($css[$media])) {
-      $css[$media] = array('module' => array(), 'theme' => array());
+      $css[$media] = array('module' => array(), 'theme' => array(), 'inline' => array());
     }
-    $css[$media][$type][$path] = $preprocess;
+    $css[$media][$type][$data] = $preprocess;
 
     // If the current language is RTL, add the CSS file with RTL overrides.
-    if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
+    if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && $type != 'inline') {
       $rtl_path = str_replace('.css', '-rtl.css', $path);
       if (file_exists($rtl_path)) {
         $css[$media][$type][$rtl_path] = $preprocess;
@@ -1683,6 +1685,7 @@
   }
   $no_module_preprocess = '';
   $no_theme_preprocess = '';
+  $no_inline_preprocess = '';
 
   $preprocess_css = (variable_get('preprocess_css', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update'));
   $directory = file_directory_path();
@@ -1697,7 +1700,7 @@
   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.
-    foreach ($types as $type => $files) {
+    foreach ($types as $type => $data) {
       if ($type == 'module') {
         // Setup theme overrides for module styles.
         $theme_styles = array();
@@ -1705,40 +1708,50 @@
           $theme_styles[] = basename($theme_style);
         }
       }
-      foreach ($types[$type] as $file => $preprocess) {
+      foreach ($types[$type] as $data => $preprocess) {
         // If the theme supplies its own style using the name of the module style, skip its inclusion.
         // This includes any RTL styles associated with its main LTR counterpart.
-        if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($file)), $theme_styles)) {
+        if ($type == 'module' && in_array(str_replace('-rtl.css', '.css', basename($data)), $theme_styles)) {
           // Unset the file to prevent its inclusion when CSS aggregation is enabled.
-          unset($types[$type][$file]);
+          unset($types[$type][$data]);
           continue;
         }
         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 .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . base_path() . $file . $query_string . '" />' . "\n";
+            $no_module_preprocess .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . base_path() . $data . $query_string . '" />' . "\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 .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . base_path() . $file . $query_string . '" />' . "\n";
+            $no_theme_preprocess .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . base_path() . $data . $query_string . '" />' . "\n";
+          }
+          // If inline CSS is being added, add it after the theme CSS is added.
+          else if ($type == 'inline') {
+            $no_inline_preprocess .= drupal_process_stylesheet_content($data);
           }
           else {
-            $output .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . base_path() . $file . $query_string . '" />' . "\n";
+            $output .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . base_path() . $data . $query_string . '" />' . "\n";
           }
         }
       }
     }
 
     if ($is_writable && $preprocess_css) {
+    echo 'hi';
       $filename = md5(serialize($types) . $query_string) . '.css';
       $preprocess_file = drupal_build_css_cache($types, $filename);
       $output .= '<link type="text/css" rel="stylesheet" media="' . $media . '" href="' . base_path() . $preprocess_file . '" />' . "\n";
     }
   }
+    
+  // If we are adding some non-preprocessed inline CSS, then be sure to stick on the prefix and suffix.
+  if (!empty($no_inline_preprocess)) {
+    $no_inline_preprocess = '<style type="text/css">' . $no_inline_preprocess . '</style>';
+  }
 
-  return $no_module_preprocess . $output . $no_theme_preprocess;
+  return $no_module_preprocess . $output . $no_theme_preprocess . $no_inline_preprocess;
 }
 
 /**
@@ -1761,15 +1774,20 @@
 
   if (!file_exists($csspath . '/' . $filename)) {
     // Build aggregate CSS file.
-    foreach ($types as $type) {
-      foreach ($type as $file => $cache) {
+    foreach ($types as $type => $css) {
+      foreach ($css as $file => $cache) {
         if ($cache) {
-          $contents = drupal_load_stylesheet($file, TRUE);
-          // Return the path to where this CSS file originated from.
-          $base = base_path() . dirname($file) . '/';
-          _drupal_build_css_path(NULL, $base);
-          // Prefix all paths within this CSS file, ignoring external and absolute paths.
-          $data .= preg_replace_callback('/url\([\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\)/i', '_drupal_build_css_path', $contents);
+          if ($type == 'inline') {
+            $data .= drupal_process_stylesheet_content($file, TRUE);
+          }
+          else {
+            $contents = drupal_load_stylesheet($file, TRUE);
+            // Return the path to where this CSS file originated from.
+            $base = base_path() . dirname($file) . '/';
+            _drupal_build_css_path(NULL, $base);
+            // Prefix all paths within this CSS file, ignoring external and absolute paths.
+            $data .= preg_replace_callback('/url\([\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\)/i', '_drupal_build_css_path', $contents);
+          }
         }
       }
     }
@@ -1842,21 +1860,9 @@
     // Change to the current stylesheet's directory.
     $cwd = getcwd();
     chdir(dirname($file));
-
-    // Replaces @import commands with the actual stylesheet content.
-    // This happens recursively but omits external files.
-    $contents = preg_replace_callback('/@import\s*(?:url\()?[\'"]?(?![a-z]+:)([^\'"\()]+)[\'"]?\)?;/', '_drupal_load_stylesheet', $contents);
-    // Remove multiple charset declarations for standards compliance (and fixing Safari problems).
-    $contents = preg_replace('/^@charset\s+[\'"](\S*)\b[\'"];/i', '', $contents);
-
-    if ($_optimize) {
-      // Perform some safe CSS optimizations.
-      $contents = preg_replace('<
-        \s*([@{}:;,]|\)\s|\s\()\s* |  # Remove whitespace around separators, but keep space around parentheses.
-        /\*([^*\\\\]|\*(?!/))+\*/ |   # Remove comments that are not CSS hacks.
-        [\n\r]                        # Remove line breaks.
-        >x', '\1', $contents);
-    }
+    
+    // Process the stylesheet content
+    $contents = drupal_process_stylesheet_content($contents, $_optimize);
 
     // Change back directory.
     chdir($cwd);
@@ -1866,6 +1872,34 @@
 }
 
 /**
+ * Processes the content of a stylesheet, resolving all @import stylesheets.
+ *
+ * @param $contents
+ *   The content of the stylesheet.
+ * @param $optimize
+ *   Defines if CSS contents should be compressed or not.
+ * @return
+ *   Contents of the stylesheet including the imported stylesheets.
+ */
+function drupal_process_stylesheet_content($contents, $optimize = FALSE) {
+  // Replaces @import commands with the actual stylesheet content.
+  // This happens recursively but omits external files.
+  $contents = preg_replace_callback('/@import\s*(?:url\()?[\'"]?(?![a-z]+:)([^\'"\()]+)[\'"]?\)?;/', '_drupal_load_stylesheet', $contents);
+  // Remove multiple charset declarations for standards compliance (and fixing Safari problems).
+  $contents = preg_replace('/^@charset\s+[\'"](\S*)\b[\'"];/i', '', $contents);
+
+  if ($optimize) {
+    // Perform some safe CSS optimizations.
+    $contents = preg_replace('<
+      \s*([@{}:;,]|\)\s|\s\()\s* |  # Remove whitespace around separators, but keep space around parentheses.
+      /\*([^*\\\\]|\*(?!/))+\*/ |   # Remove comments that are not CSS hacks.
+      [\n\r]                        # Remove line breaks.
+      >x', '\1', $contents);
+  }
+  return $contents;
+}
+
+/**
  * Loads stylesheets recursively and returns contents with corrected paths.
  *
  * This function is used for recursive loading of stylesheets and
