Index: filter_default.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filter_default/filter_default.module,v
retrieving revision 1.2
diff -u -p -r1.2 filter_default.module
--- filter_default.module	5 Feb 2007 19:31:26 -0000	1.2
+++ filter_default.module	25 Aug 2007 20:27:18 -0000
@@ -2,7 +2,7 @@
 // $Id: filter_default.module,v 1.2 2007/02/05 19:31:26 bjaspan Exp $
 
 function filter_default_help($section = '') {
-  switch ($section) {		  
+  switch ($section) {
     case 'admin/modules#description':
       return t('Allows each role to have a default input format.');
   }
@@ -11,126 +11,107 @@ function filter_default_help($section = 
 function filter_default_menu($may_cache) {
   $items = array();
   if ($may_cache) {
-    $items[] = array
-      ('path' => 'admin/filters/default',
-       'title' => t('defaults'),
-       'callback' => 'filter_default_admin_defaults_form',
-       'type' => MENU_LOCAL_TASK,
-       'weight' => 0.5,
-       'access' => user_access('administer filters'),
+    $items[] = array('path' => 'admin/filters/default',
+      'title' => t('defaults'),
+      'callback' => 'filter_default_admin_defaults_form',
+      'type' => MENU_LOCAL_TASK,
+      'weight' => 0.5,
+      'access' => user_access('administer filters'),
     );
   }
   return $items;
 }
 
 function filter_default_admin_defaults_form() {
-  $form = array();
-
-  $roles = array(0 => '') + user_roles();
+  $form    = array();
+  
+  $roles   = array(0 => '') + user_roles();
   $formats = filter_formats();
   foreach ($formats as $format) {
     $format_list[$format->format] = $format->name;
   }
-
-  $form['help'] = array
-    ('#value' => t('<p>You may assign a default input format for each role '.
-		   'on your site.  Whenever a text input box with multiple '.
-		   'allowed input formats is displayed, the initially '.
-		   'selected input format will be set based on the '.
-		   'lowest-weighted role (as defined below) '.
-		   'that the user posseses.  '.
-		   'For a user that does not have any role indicated in '.
-		   'this table, the default input format will be the one '.
-		   'selected on the %list_link.</p>'.
-		   '<p>Note that this does <em>not</em> prevent the user '.
-		   'from selecting any other input format they are '.
-		   'authorized to use; it only sets the initially selected '.
-		   'format.</p>',
-		   array('%list_link' => l('list tab', 'admin/filters'))));
-
+  
+  $form['help'] = array(
+    '#value' => t('<p>You may assign a default input format for each role on your site.  Whenever a text input box with multiple allowed input formats is displayed, the initially selected input format will be set based on the lowest-weighted role (as defined below) that the user posseses. For a user that does not have any role indicated in this table, the default input format will be the one selected on the %list_link.</p>
+      <p>Note that this does <em>not</em> prevent the user from selecting any other input format they are authorized to use; it only sets the initially selected format.</p>', array('%list_link' => l('list tab', 'admin/filters')))
+  );
+  
   for ($i = 1; $i < count($roles); $i++) {
-    list($def_role, $def_format) = variable_get('filter_default_'.$i,
-						array());
-
-    $form['role_'.$i] = array
-      ('#type' => 'select',
-       '#options' => $roles,
-       '#default_value' => $def_role);
-    $form['format_'.$i] = array
-      ('#type' => 'select',
-       '#options' => $format_list,
-       '#default_value' => $def_format);
-  }
-  $form['submit'] = array
-    ('#type' => 'submit', 
-     '#value' => t('Save default roles'));
-
+    list($def_role, $def_format) = variable_get('filter_default_'. $i, array());
+    
+    $form['role_'. $i] = array(
+      '#type' => 'select',
+      '#options' => $roles,
+      '#default_value' => $def_role,
+    );
+    $form['format_'. $i] = array(
+      '#type' => 'select',
+      '#options' => $format_list,
+      '#default_value' => $def_format,
+    );
+  }
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save default roles'),
+  );
+  
   return drupal_get_form('filter_default_admin_defaults_form', $form);
 }
 
 function theme_filter_default_admin_defaults_form($form) {
-  $roles = user_roles();
-
+  $roles  = user_roles();
+  
   $header = array(t('Weight'), t('Role'), t('Default input format'));
-
-  $rows = array();
-  for ($i = 1; $i < count($roles)+1; $i++) {
-    $row = array();
-    $row[] = $i;
-    $row[] = form_render($form['role_'.$i]);
-    $row[] = form_render($form['format_'.$i]);
+  
+  $rows   = array();
+  for ($i = 1; $i < count($roles) + 1; $i++) {
+    $row    = array();
+    $row[]  = $i;
+    $row[]  = form_render($form['role_'. $i]);
+    $row[]  = form_render($form['format_'. $i]);
     $rows[] = $row;
   }
-
+  
   $output .= form_render($form['help']);
   $output .= theme('table', $header, $rows);
   $output .= form_render($form);
+  
   return $output;
 }
 
 function filter_default_admin_defaults_form_validate($form_id, $form) {
   $roles = user_roles();
   $formats = filter_formats();
-
-  for ($i = 1; $i < count($roles)+1; $i++) {
-    if ($form['role_'.$i] > 0 &&
-	(strpos($formats[$form['format_'.$i]]->roles,
-		','.$roles[$form['role_'.$i]].',') === FALSE &&
-	 strpos($formats[$form['format_'.$i]]->roles,
-		','.$form['role_'.$i].',') === FALSE)) {
-      form_set_error('format_'.$i,
-		     t('Role %role is not allowed to use format %format.',
-		       array('%role' =>
-			     theme('placeholder', 
-				   $roles[$form['role_'.$i]]),
-			     '%format' => 
-			     theme('placeholder',
-				   $formats[$form['format_'.$i]]->name))));
+  
+  for ($i = 1; $i < count($roles) + 1; ++$i) {
+    if ($form['role_'. $i] > 0) { 
+      if (strpos($formats[$form['format_'. $i]]->roles, ','. $roles[$form['role_'. $i]] .',') === FALSE && strpos($formats[$form['format_'. $i]]->roles, ','. $form['role_'. $i] .',') === FALSE) {
+        form_set_error('format_'. $i, t('Role %role is not allowed to use format %format.', array(
+          '%role' => theme('placeholder', $roles[$form['role_'. $i]]),
+          '%format' => theme('placeholder', $formats[$form['format_'. $i]]->name),
+        )));
+      }
     }
   }
 }
 
 function filter_default_admin_defaults_form_submit($form_id, $form) {
   $roles = user_roles();
-  for ($i = 1; $i < count($roles)+1; $i++) {
-    if ($form['role_'.$i] > 0) {
-      variable_set('filter_default_'.$i,
-		   array($form['role_'.$i], $form['format_'.$i]));
-    } else {
-      variable_del('filter_default_'.$i);
+  for ($i = 1; $i < count($roles) + 1; $i++) {
+    if ($form['role_'. $i] > 0) {
+      variable_set('filter_default_'. $i, array($form['role_'. $i], $form['format_'. $i]));
+    }
+    else {
+      variable_del('filter_default_'. $i);
     }
   }
 }
-  
+
 function _filter_default_form_alter_filters($default, &$form) {
-  if (is_array($form['#validate']) &&
-      array_key_exists('filter_form_validate', $form['#validate'])) {
-    
+  if (is_array($form['#validate']) && array_key_exists('filter_form_validate', $form['#validate'])) {
     foreach (element_children($form) as $el) {
-      if ($form[$el]['#type'] == 'radio' &&
-	  $form[$el]['#default_value'] == 
-	  variable_get('filter_default_format', FILTER_FORMAT_DEFAULT)) {
-	$form[$el]['#default_value'] = $default;
+      if ($form[$el]['#type'] == 'radio' && $form[$el]['#default_value'] == variable_get('filter_default_format', FILTER_FORMAT_DEFAULT)) {
+        $form[$el]['#default_value'] = $default;
       }
     }
   }
@@ -140,15 +121,16 @@ function _filter_default_form_alter_filt
     }
   }
 }
-  
+
 function filter_default_form_alter($form_id, &$form) {
   global $user;
   $roles = user_roles();
-  for ($i = 1; $i < count($roles)+1; $i++) {
-    list($role, $format) = variable_get('filter_default_'.$i, array());
+  for ($i = 1; $i < count($roles) + 1; $i++) {
+    list($role, $format) = variable_get('filter_default_'. $i, array());
     if (array_key_exists($role, $user->roles)) {
       _filter_default_form_alter_filters($format, $form);
       break;
     }
   }
 }
+
