Index: INSTALL.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/css/INSTALL.txt,v
retrieving revision 1.4
diff -u -p -r1.4 INSTALL.txt
--- INSTALL.txt	26 Dec 2008 15:20:36 -0000	1.4
+++ INSTALL.txt	4 May 2010 21:16:51 -0000
@@ -4,10 +4,8 @@ INSTALL INSTRUCTIONS FOR CSS MODULE
 
 - Copy the css module folder into the sites/all/modules directory or sites/example.com/modules directory. 
 - Login as site administrator
-- Activate the css module as usual (Administer > Site building > Modules)
-- Activate the css editing for the node types you need (Administer > Content management > Content types)
+- Activate the css module as usual (Administer > Modules)
+- Add CSS fields to the node types you need (Administer > Content management > Content types)
 - Enable the "create css for nodes" permissions *only* for the administrator groups (trusted users, see below)
 
 IMPORTANT: note that the CSS editing permissions should be given only to trusted users (administrators). Malicious users which have this permission might break your site design and also introduce security issues (XSS).
-
-
Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/css/README.txt,v
retrieving revision 1.4
diff -u -p -r1.4 README.txt
--- README.txt	26 Dec 2008 15:20:36 -0000	1.4
+++ README.txt	4 May 2010 21:16:51 -0000
@@ -3,12 +3,12 @@
 CSS MODULE
 -----
 
-The CSS module adds, for users with enough permissions and enabled nodes, a CSS field on the node creation page.
+The CSS module adds, for users with enough permissions, a CSS field on the entity (node, user, etc.) creation and edit pages.
 
 Users might insert CSS rules in the CSS node field and those rules will be parsed on the node viewing.
-This way CSS experienced users might create complex CSS based designs for nodes contents.
+This way CSS experienced users might create complex CSS based designs for entity contents.
 
-IMPORTANT: note that the CSS editing permissions should be given only to trusted users (administrators). Malicious users which have this permission might broke your site design and also introduce security issues (XSS).
+IMPORTANT: note that the CSS editing permissions should be given only to trusted users (administrators). Malicious users which have this permission might break your site design and also introduce security issues (XSS).
 
 
 For installation instructions see INSTALL.txt
Index: css.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/css/css.info,v
retrieving revision 1.3
diff -u -p -r1.3 css.info
--- css.info	26 Dec 2008 15:20:36 -0000	1.3
+++ css.info	4 May 2010 21:16:51 -0000
@@ -1,5 +1,6 @@
 ; $Id: css.info,v 1.3 2008/12/26 15:20:36 fax8 Exp $
 name = CSS
-description = Permits adding CSS rules to node contents.
+description = Permits adding CSS styling to specific entities.
 package = Content
-core = "6.x"
\ No newline at end of file
+core = 7.x
+files[] = css.module
\ No newline at end of file
Index: css.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/css/css.module,v
retrieving revision 1.4
diff -u -p -r1.4 css.module
--- css.module	26 Dec 2008 15:20:36 -0000	1.4
+++ css.module	4 May 2010 21:16:51 -0000
@@ -10,42 +10,21 @@
  * @updated to Drupal 5 by Christopher Skauss <christopher skauss at gmail dot com>
  * @modified drupal 5 Version by Whispero
  * @updated for Drupal 6 by Joshua Chan <josh at joshuachan dot ca>
- *
- * To store this extra information, we need an auxiliary database table.
- *
- * Database definition:
- * @code
-   CREATE TABLE css (
-      nid int(10) unsigned NOT NULL default '0',
-      css text NULL default NULL,
-      PRIMARY KEY (nid)
-    )
- * @endcode
+ * @updated for Drupal 7 by Scott Reynen
  */
 
 /**
- * Implementation of hook_help().
- */
-function css_help($section) {
-  switch ($section) {
-    case 'admin/modules#description':
-      // This description is shown in the listing at admin/modules.
-      return t('A module which add customizable CSS support.');
-  }
-}
-
-/**
- * Implementation of hook_menu()
+ * Implements hook_menu().
  */
 function css_menu() {
+
   $items = array();
-  // defines the callback for getting the css file. we use
-  // css/get as path instead of only css to avoid that in some
-  // installs users have yet a directory called css
-  $items['css/get'] = array(
+
+  $items['css/get/%/%/%/%'] = array(
     'title' => 'css',
     'path' => 'css/get', 
     'page callback' => 'css_get',
+    'page arguments' => array(2, 3, 4, 5),
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
@@ -53,164 +32,170 @@ function css_menu() {
 }
 
 /**
- * Implementation of hook_perm()
+ * Returns the CSS for the given field.
+ * Last-Modified header is set to let browsers cache the css.
  */
-function css_perm() {
-  return array('create css for nodes');
-} 
-
-/**
- * Implemenation of hook_form_alter()
- */ 
-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 (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
-      $node = $form['#node'];
-      // _form_form code follows:
-      $form['css_css'] = array(
-          '#type' => 'textarea',
-          '#title' => t('CSS'),
-          '#default_value' => $node->css_css,
-          '#cols' => 60,
-          '#rows' => 10,
-          '#description' => t('Insert here the css rules for this node. You can use css defined for other nodes using <em>@import "?q=css/get/x";</em> where x is the identification number of the node which contains the css you want to use.'),
-          '#attributes' => NULL,
-          '#required' => FALSE,
-      );
-    }
-  }
-  // 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(
-          '#type' => 'checkbox',
-          '#title' => t('Enable CSS Editing.'),
-          '#return_value' => 1,
-          '#default_value' => variable_get('css__'.$form['#node_type']->type, FALSE),
-    );
-  }
-} 
-
-/**
- * Implementation of hook_nodeapi().
- */
-function css_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  static $prev_op = NULL;
-
-  if (variable_get('css__'. $node->type, FALSE)) { // check that CSS editing is enabled for the given node type
-    switch ($op) {
-
-      // Controls for valid input data
-      case 'validate':
-        // Check for potentially malicious tags
-        $pattern = '~<\s*\/?\s*(style|script|meta)\s*.*?>~i';
-        if (preg_match($pattern, $node->css_css)) {
-          form_set_error('css_css', t('Please do not include any tags.'));
-        }
-        break;
-
-      // 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)) {
-          db_query("INSERT INTO {css} (nid, css) VALUES (%d, '%s')", $node->nid, $node->css_css);
-        }
-        break;
-
-      // If the form was called to edit an existing node rather than create a new
-      // 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);
-        }
-        break;
-
-      // If the node is being deleted, we need this opportunity to clean up after
-      // ourselves.
-      case 'delete':
-        db_query('DELETE FROM {css} WHERE nid = %d', $node->nid);
-        break;
-
-      // Now we need to take care of loading one of the extended nodes from the
-      // database. An array containing our extra field needs to be returned.
-      case 'load':
-        $object = db_fetch_object(db_query('SELECT css FROM {css} WHERE nid = %d', $node->nid));
-        return array('css_css' => $object->css);
-        break;
-
-      // Using nodeapi('view') is more appropriate than using a filter here, because
-      // filters transform user-supplied content, whereas we are extending it with
-      // additional information.
-      case 'view':
-        if ($prev_op == 'validate') {
-          // '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').
-                   ' </style>';
-            drupal_set_html_head($css, 'preview');
-          }
-        } 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.
-          if (!empty($node->css_css)) {
-            $link = url('css/get/'.$node->nid);
-            drupal_add_link(array(
-              'type' => 'text/css',
-              'rel' => 'stylesheet',
-              'media' => 'all',
-              'href' => $link,
-            ));
-          }
-        }
-        break;
-    }
+function css_get($entity_type, $entity_id, $field_name, $delta) {
 
-    $prev_op = $op; // used to determine Preview state
-  }
-}
+  $entities = entity_load($entity_type, array($entity_id));
+  $entity = $entities[$entity_id];
+  $field = $entity->{$field_name};
+  $instance = $field['und'][$delta]; // Will this break on multi-lingual entities?
+
+  $date = (isset($entity->changed)) ? $entity->changed : time();
+
+  drupal_add_http_header('Last-Modified', gmdate('D, d M Y H:i:s', $date) .' GMT');
+  drupal_add_http_header('Content-Type' ,'text/css; charset=utf-8');
+  print($instance['value']);
+
+} // css_get
 
 /**
- * Return the css attached to the node.
- * Last-Modified header is set to let browsers cache the css.
+ * Implements hook_field_info().
+ *
+ * Instance settings:
+ *   - value: 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));
-    }
-  }
-}
+function css_field_info() {
+
+  return array(
+    'css' => array(
+      'label' => t('Custom CSS'),
+      'description' => t('This field applies custom CSS.'),
+      'instance_settings' => array('value' => ''),
+      'default_widget' => 'css_widget',
+      'default_formatter' => 'css_default',
+    ),
+  );
+
+} // css_field_info
 
 /**
- * Remove harmful code from CSS.
+ * Implements hook_field_schema().
  */
-function css_sanitize($css, $type = 'view') {
-  switch ($type) {
-    case 'view':
-      // Are there any security vulnerabilites from external CSS files?
+function css_field_schema($field) {
+
+  switch ($field['type']) {
+
+    case 'css':
+      $columns = array(
+        'value' => array(
+          'type' => 'text',
+          'size' => 'big',
+          'not null' => FALSE,
+        ),
+      );
       break;
 
-    case 'preview':
-      // Catch potentially malicious code
-      $patterns = array(
-        '~<\s*(/?)\s*(style|script|meta)\s*>~i',
+  } // switch
+
+  return array(
+    'columns' => $columns,
+  );
+
+} // css_field_schema
+
+/**
+ * Implements hook_field_widget_info().
+ */
+function css_field_widget_info() {
+
+  return array(
+    'css_widget' => array(
+      'label' => t('CSS'),
+      'field types' => array('css'),
+    ),
+  );
+
+} // css_field_widget_info
+
+/**
+ * Implements hook_field_widget_form().
+ */
+function css_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) {
+
+  $element = $base;
+  
+  switch ($instance['widget']['type']) {
+
+    case 'css_widget':
+      $element = $base + array(
+        'value' => array(
+          '#title' => t('CSS'),
+          '#type' => 'textarea',
+          '#rows' => 10,
+          '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
+        ),
       );
-      $css = preg_replace($patterns, '<$1FILTERED $2>', $css);
       break;
 
-    default:
-      $css = '';
+  } // switch
+
+  return $element;
+
+} // css_field_widget_form
+
+/**
+ * Implements hook_field_validate().
+ */
+function css_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
+
+  /**
+   * Todo:
+   * - Validate CSS
+   */
+
+} // css_field_validate
+
+/**
+ * Implements hook_field_is_empty().
+ */
+function css_field_is_empty($item, $field) {
+
+  if (empty($item['value'])) {
+    return TRUE;
+  } // if
+
+  return FALSE;
+
+} // css_field_is_empty
+
+/**
+ * Implements hook_field_formatter_info().
+ */
+function css_field_formatter_info() {
+
+  return array(
+    'css_default' => array(
+      'label' => t('Default'),
+      'field types' => array('css'),
+    ),
+  );
+
+} // css_field_formatter_info
+
+/**
+ * Implements hook_field_formatter_view().
+ */
+function css_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
+
+  $element = array();
+
+  $id_info = entity_extract_ids($entity_type, $entity);
+
+  switch ($display['type']) {
+    case 'css_default':
+
+      foreach ($items as $delta => $item) {
+        if (!empty($item['value'])) {
+          drupal_add_css('css/get/' . $entity_type . '/' . $id_info[0] . '/' . $field['field_name'] . '/' . $delta);
+        } // if
+      } // foreach
+
       break;
-  }
-  
-  return $css;
-}
+
+  } // switch
+
+  return $element;
+
+} // css_field_formatter_view
