? css.revisions.patch Index: css.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/css/css.install,v retrieving revision 1.1 diff -u -r1.1 css.install --- css.install 2 Nov 2008 15:16:09 -0000 1.1 +++ css.install 19 Jan 2009 10:59:21 -0000 @@ -1,6 +1,6 @@ * @modified drupal 5 Version by Whispero * - * To store this extra information, we need an auxiliary database table. + * See DB schema in css.install. * - * Database definition: - * @code - CREATE TABLE css ( - nid int(10) unsigned NOT NULL default '0', - css text NULL default NULL, - PRIMARY KEY (nid) - ) - * @endcode */ /** @@ -103,7 +95,7 @@ function css_nodeapi(&$node, $op, $teaser = NULL, $page = 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 @@ -116,15 +108,22 @@ // Now that the form has been properly completed, it is time to commit the new // data to the database. case 'insert': - db_query('INSERT INTO {css} (nid, css) VALUES (%d, "%s")', $node->nid, $node->css_css); + if(!empty($node->css_css)) { // if we have some css rules we insert it into the DB + db_query('INSERT INTO {css} (vid,nid, css) VALUES (%d, %d, "%s")', $node->vid, $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); - db_query('INSERT INTO {css} (nid, css) VALUES (%d, "%s")', $node->nid, $node->css_css); + if ($node->revision) { //If a new node revision is being added then insert a new row. + db_query('INSERT INTO {css} (vid,nid, css) VALUES (%d, %d, "%s")', $node->vid, $node->nid, $node->css_css); + } + else { + db_query('DELETE FROM {css} WHERE vid = %d', $node->vid); + db_query('INSERT INTO {css} (vid, nid, css) VALUES (%d, %d, "%s")', $node->vid, $node->nid, $node->css_css); + } break; // If the node is being deleted, we need this opportunity to clean up after @@ -132,11 +131,15 @@ case 'delete': db_query('DELETE FROM {css} WHERE nid = %d', $node->nid); break; + + case 'delete revision': + db_query('DELETE FROM {css} WHERE vid = %d', $node->vid); + 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)); + $object = db_fetch_object(db_query('SELECT css FROM {css} WHERE vid = %d', $node->vid)); return array('css_css' => $object->css); break; @@ -154,7 +157,7 @@ } } else { - theme('css_import', $node->nid); + theme('css_import', $node->vid); } break; } @@ -165,11 +168,11 @@ * 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)); +function css_get($vid = 0) { + if (is_numeric($vid) && $vid > 0) { + $object = db_fetch_object(db_query('SELECT css, timestamp FROM {css} c, {node_revisions} nr WHERE nr.vid = %d AND nr.vid = c.vid', $vid)); if($object) { - $date = gmdate('D, d M Y H:i:s', $object->changed) .' GMT'; + $date = gmdate('D, d M Y H:i:s', $object->timestamp) .' GMT'; header("Last-Modified: $date"); drupal_set_header('Content-Type: text/css; charset=utf-8'); print(css_sanitize($object->css)); @@ -209,12 +212,12 @@ * We use a theme function for this to let themers able * to customize the behaviour of importing. */ -function theme_css_import($nid) { +function theme_css_import($vid) { // let's link the CSS file to the HTML: - // we use $path = '?q=css/get/' . $nid as without ?q= the hook would be called only when clean urls are enabled (mod_rewrite active) + // we use $path = '?q=css/get/' . $vid as without ?q= the hook would be called only when clean urls are enabled (mod_rewrite active) // we use $type = theme as we want to be parsed after module rules, so that we can override module defined rules // we use $preprocess = FALSE as we don't want to cache the CSS rules. - drupal_add_css('?q=css/get/' . $nid, 'theme', 'all', FALSE); + drupal_add_css('?q=css/get/' . $vid, 'theme', 'all', FALSE); }