--- css.module
+++ (clipboard)
@@ -118,10 +118,11 @@
         break;
 
       // Now that the form has been properly completed, it is time to commit the new
-      // data to the database.
+      // data to the database and file system.
       case 'insert':
         if (!empty($node->css_css) && user_access('create css for nodes')) {
           db_query("INSERT INTO {css} (nid, css) VALUES (%d, '%s')", $node->nid, $node->css_css);
+          css_save_file($node->css_css, $node->nid);
         }
         break;
 
@@ -133,6 +134,7 @@
           db_query("DELETE FROM {css} WHERE nid = %d", $node->nid);
           if (!empty($node->css_css)) {
             db_query("INSERT INTO {css} (nid, css) VALUES (%d, '%s')", $node->nid, $node->css_css);
+            css_save_file($node->css_css, $node->nid);
           }
         }
         break;
@@ -141,6 +143,7 @@
       // ourselves.
       case 'delete':
         db_query('DELETE FROM {css} WHERE nid = %d', $node->nid);
+        file_delete(file_create_path('css_css') .'/'. $node->nid .'.css');
         break;
 
       // Now we need to take care of loading one of the extended nodes from the
@@ -164,24 +167,9 @@
           }
         }
         else {
-          // Drupal 6 seems to check for the physical existence of CSS files
-          // before allowing them to be added. We have to include the virtual
-          // CSS file manually since it does not really exist.
-          // To keep the order consistent with Drupal 5 version of CSS module
-          // we had to implement something kind of hacky below. For more details
-          // see http://drupal.org/node/351764
+          // Include the CSS file.
           if (!empty($node->css_css)) {
-            $attributes = array(
-              'type' => 'text/css',
-              'rel' => 'stylesheet',
-              'media' => 'all',
-              'href' => url('css/get/' . $node->nid),
-            );
-            $link = '<link'. drupal_attributes($attributes) .' />';
-            $css = "\n//--><!]]>\n"."</script>\n".
-           $link . "\n".
-           '<script type="text/javascript">'."\n<!--//--><![CDATA[//><!--\n";
-           drupal_add_js($css, 'inline', 'header', FALSE, FALSE, FALSE);
+            drupal_add_css(file_create_path('css_css') .'/'. $node->nid .'.css', 'theme');
           }
         }
         break;
@@ -192,22 +180,6 @@
 }
 
 /**
- * Return the css attached to the node.
- * Last-Modified header is set to let browsers cache the css.
- */
-function css_get($nid = 0) {
-  if (is_numeric($nid) && $nid > 0) {
-    $object = db_fetch_object(db_query('SELECT css, changed FROM {css} c, {node} n WHERE n.nid = %d AND n.nid = c.nid', $nid));
-    if ($object) {
-      $date = gmdate('D, d M Y H:i:s', $object->changed) .' GMT';
-      header("Last-Modified: $date");
-      drupal_set_header('Content-Type: text/css; charset=utf-8');
-      print(css_sanitize($object->css));
-    }
-  }
-}
-
-/**
  * Remove harmful code from CSS.
  */
 function css_sanitize($css, $type = 'view') {
@@ -231,3 +203,12 @@
   
   return $css;
 }
+
+/**
+ * Saves CSS in a file.
+ */
+function css_save_file($css, $nid) {
+  $css_path = file_create_path('css_css');
+  file_check_directory($css_path, FILE_CREATE_DIRECTORY) or mkdir($css_path, 0755, TRUE);
+  file_save_data(css_sanitize($css), $css_path .'/'. $nid .'.css', FILE_EXISTS_REPLACE);
+}
