? css-1.4-1.4.2.4.diff
Index: css.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/css/css.module,v
retrieving revision 1.4
retrieving revision 1.4.2.4
diff -u -p -r1.4 -r1.4.2.4
--- css.module	26 Dec 2008 15:20:36 -0000	1.4
+++ css.module	4 May 2010 07:55:38 -0000	1.4.2.4
@@ -1,5 +1,5 @@
 <?php
-// $Id: css.module,v 1.4 2008/12/26 15:20:36 fax8 Exp $
+// $Id: css.module,v 1.4.2.4 2010/05/04 07:55:38 fax8 Exp $
 
 /**
  * @file
@@ -26,8 +26,8 @@
 /**
  * Implementation of hook_help().
  */
-function css_help($section) {
-  switch ($section) {
+function css_help($path, $arg) {
+  switch ($path) {
     case 'admin/modules#description':
       // This description is shown in the listing at admin/modules.
       return t('A module which add customizable CSS support.');
@@ -64,13 +64,19 @@ function css_perm() {
  */ 
 function css_form_alter(&$form, $form_state, $form_id) {
   //Add a text area to the form where users will put their csses rules.
-  if (user_access('create css for nodes') && variable_get('css__'.$form['#node']->type, FALSE)) {
+  if (user_access('create css for nodes') && variable_get('css__' . $form['#node']->type, FALSE)) {
     if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
       $node = $form['#node'];
-      // _form_form code follows:
-      $form['css_css'] = array(
+      // create a fieldset so we can collapse it
+      $form['css_fieldset'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('CSS Rules'),
+        '#collapsible' => TRUE,
+        '#collapsed' => empty($node->css_css), // show uncollapsed if we have some css rule set
+      );
+      $form['css_fieldset']['css_css'] = array(
           '#type' => 'textarea',
-          '#title' => t('CSS'),
+          '#title' => t('CSS Rules'),
           '#default_value' => $node->css_css,
           '#cols' => 60,
           '#rows' => 10,
@@ -83,11 +89,12 @@ function css_form_alter(&$form, $form_st
   // Create a settings on content types configuration page
   // which enable to activate/deactivate css editing for a node type	
   if (isset($form['#node_type']) && 'node_type_form' == $form_id) {
-    $form['workflow']['css_'.$node->type] = array(
+    $form['workflow']['css_' . $node->type] = array(
           '#type' => 'checkbox',
           '#title' => t('Enable CSS Editing.'),
           '#return_value' => 1,
-          '#default_value' => variable_get('css__'.$form['#node_type']->type, FALSE),
+          '#default_value' => variable_get('css__' . $form['#node_type']->type, FALSE),
+          '#description' => t('Users with the <em>create css for nodes</em> permission will be able to edit CSS rules to be applied to this node type.'),
     );
   }
 } 
@@ -113,7 +120,7 @@ function css_nodeapi(&$node, $op, $tease
       // Now that the form has been properly completed, it is time to commit the new
       // data to the database.
       case 'insert':
-        if (!empty($node->css_css)) {
+        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);
         }
         break;
@@ -122,9 +129,11 @@ function css_nodeapi(&$node, $op, $tease
       // one, this operation gets called instead. We use a DELETE then INSERT rather
       // than an UPDATE just in case the rating didn't exist for some reason.
       case 'update':
-        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);
+        if (user_access('create css for nodes')) {
+          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);
+          }
         }
         break;
 
@@ -149,22 +158,30 @@ function css_nodeapi(&$node, $op, $tease
           // 'validate' immediately followed by 'view' means this is a preview
           if ($node->css_css) {
             $css = '<style type="text/css" media="all"> '.
-                   css_sanitize($node->css_css, 'preview').
+                   css_sanitize($node->css_css, 'preview') .
                    ' </style>';
             drupal_set_html_head($css, 'preview');
           }
-        } else {
+        }
+        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
           if (!empty($node->css_css)) {
-            $link = url('css/get/'.$node->nid);
-            drupal_add_link(array(
+            $attributes = array(
               'type' => 'text/css',
               'rel' => 'stylesheet',
               'media' => 'all',
-              'href' => $link,
-            ));
+              '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);
           }
         }
         break;
