Index: filter.install
===================================================================
--- filter.install	(.../base/modules/filter)	(revision 3552)
+++ filter.install	(.../demo/modules/filter)	(working copy)
@@ -82,6 +82,26 @@
     'primary key' => array('format'),
     'unique keys' => array('name' => array('name')),
   );
+  $schema['filter_formats_roles'] = array(
+    'description' => t('Relation table between filter_formats and roles.'),
+    'fields' => array(
+      'format' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('Foreign key: The {filter_formats}.format to which this role has access.'),
+      ),
+      'rid' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('Foreign key: The {roles}.rid to which this access applies.'),
+      ),
+    ),
+    'indexes' => array(
+      'fr' = > array('format', 'rid'),
+    ),
+  );
 
   $schema['cache_filter'] = drupal_get_schema_unprocessed('system', 'cache');
   $schema['cache_filter']['description'] = t('Cache table for the Filter module to store already filtered pieces of text, identified by input format and md5 hash of the text.');
Index: filter.info
===================================================================
--- filter.info	(.../base/modules/filter)	(revision 3552)
+++ filter.info	(.../demo/modules/filter)	(working copy)
@@ -5,8 +5,8 @@
 version = VERSION
 core = 6.x
 
-; Information added by drupal.org packaging script on 2008-04-09
-version = "6.2"
+; Information added by drupal.org packaging script on 2008-07-09
+version = "6.3"
 project = "drupal"
-datestamp = "1207776008"
+datestamp = "1215640509"
 
Index: filter.admin.inc
===================================================================
--- filter.admin.inc	(.../base/modules/filter)	(revision 3552)
+++ filter.admin.inc	(.../demo/modules/filter)	(working copy)
@@ -23,7 +23,7 @@
     $roles = array();
     foreach (user_roles() as $rid => $name) {
       // Prepare a roles array with roles that may access the filter.
-      if (strstr($format->roles, ",$rid,")) {
+      if (in_array($rid,$format->roles)) {
         $roles[] = $name;
       }
     }
@@ -113,7 +113,7 @@
   );
 
   foreach (user_roles() as $rid => $name) {
-    $checked = strstr($format->roles, ",$rid,");
+    $checked = in_array($rid,$format->roles);
     $form['roles'][$rid] = array('#type' => 'checkbox',
       '#title' => $name,
       '#default_value' => ($default || $checked),
@@ -215,14 +215,15 @@
     }
   }
   if (!empty($form_state['values']['default_format'])) {
-    $roles = ','. implode(',', array_keys(user_roles())) .',';
+    $roles = array_keys(user_roles());
   }
-  else {
-    $roles = ','. implode(',', $roles) .',';
+
+  db_query("UPDATE {filter_formats} SET cache = %d, name='%s' WHERE format = %d", $cache, $name, $format);
+  db_query("DELETE FROM {filter_formats_roles} WHERE format = %d", $format );
+  foreach ( $roles as $rid ) {
+    db_query("INSERT INTO {filter_formats_roles} (format,rid) VALUES (%d,%d)", $format, $rid);
   }
 
-  db_query("UPDATE {filter_formats} SET cache = %d, name='%s', roles = '%s' WHERE format = %d", $cache, $name, $roles, $format);
-
   cache_clear_all($format .':', 'cache_filter', TRUE);
 
   // If a new filter was added, return to the main list of filters. Otherwise, stay on edit filter page to show new changes.
@@ -266,6 +267,7 @@
  */
 function filter_admin_delete_submit($form, &$form_state) {
   db_query("DELETE FROM {filter_formats} WHERE format = %d", $form_state['values']['format']);
+  db_query("DELETE FROM {filter_formats_roles} WHERE format = %d", $form_state['values']['format']);
   db_query("DELETE FROM {filters} WHERE format = %d", $form_state['values']['format']);
 
   $default = variable_get('filter_default_format', 1);
Index: filter.module
===================================================================
--- filter.module	(.../base/modules/filter)	(revision 3552)
+++ filter.module	(.../demo/modules/filter)	(working copy)
@@ -1,5 +1,5 @@
 <?php
-// $Id: filter.module,v 1.204.2.1 2008/04/09 21:11:47 goba Exp $
+// $Id: filter.module,v 1.204.2.2 2008/07/09 21:48:28 goba Exp $
 
 /**
  * @file
@@ -298,23 +298,28 @@
   if (!isset($formats)) {
     $formats = array();
 
-    $query = 'SELECT * FROM {filter_formats}';
+    $query = 'SELECT ff.*, ffr.rid FROM {filter_formats} ff JOIN {filter_formats_roles} ffr ON ff.format = ffr.format';
 
     // Build query for selecting the format(s) based on the user's roles.
     $args = array();
     if (!$all) {
       $where = array();
       foreach ($user->roles as $rid => $role) {
-        $where[] = "roles LIKE '%%,%d,%%'";
+        $where[] = "ffr.rid = %d";
         $args[] = $rid;
       }
-      $query .= ' WHERE '. implode(' OR ', $where) .' OR format = %d';
-      $args[] = variable_get('filter_default_format', 1);
+      $query .= ' WHERE '. implode(' OR ', $where);
     }
 
     $result = db_query($query, $args);
-    while ($format = db_fetch_object($result)) {
-      $formats[$format->format] = $format;
+    while ($format = db_fetch_array($result)) {
+      if ( !isset($formats[$format['format']]) ) {
+        $formats[$format['format']]->format = $format['format'];
+        $formats[$format['format']]->name = $format['name'];
+        $formats[$format['format']]->cache = $format['cache'];
+        $formats[$format['format']]->roles = array();
+      }
+      $formats[$format['format']]->roles[] = $format['rid'];
     }
   }
   if (isset($index)) {
@@ -932,7 +937,7 @@
  * for scripts and styles.
  */
 function filter_xss_admin($string) {
-  return filter_xss($string, array('a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'div', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'object', 'ol', 'p', 'param', 'pre', 'q', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'tt', 'ul', 'var'));
+  return filter_xss($string, array('a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'div', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'ol', 'p', 'param', 'pre', 'q', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'tt', 'ul', 'var'));
 }
 
 /**
