Index: auto_username.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/auto_username/auto_username.module,v
retrieving revision 1.1
diff -u -p -r1.1 auto_username.module
--- auto_username.module	7 Apr 2008 21:09:17 -0000	1.1
+++ auto_username.module	10 Apr 2008 01:01:24 -0000
@@ -1,5 +1,6 @@
 <?php
-// ; $Id $
+// $Id$
+
 
 define('AUN_PUNCTUATION_REMOVE', 0);
 define('AUN_PUNCTUATION_REPLACE', 1);
@@ -17,11 +18,8 @@ function auto_username_perm() {
  */
 function auto_username_menu($may_cache) {
   $items = array();
-  
-  if ($may_cache) {
-    
-  }
-  else {
+
+  if (!$may_cache) {
     $items[] = array(
       'path' => 'admin/user/auto-username',
       'title' => t('Username rules'),
@@ -31,14 +29,13 @@ function auto_username_menu($may_cache) 
       'access' => user_access('configure username patterns'),
     );
   }
-  
+
   return $items;
 }
 
-
 function auto_username_configuration() {
   $form = array();
-  
+
   // The basic pattern.  Always supports PHP, as there's little value in not doing so.
   $form['aun_pattern'] = array(
     '#type' => 'textarea',
@@ -46,7 +43,7 @@ function auto_username_configuration() {
     '#description' => t('Enter the pattern for usernames.  You may use any of the tokens listed below.'),
     '#default_value' => variable_get('aun_pattern', ''),
   );
-  
+
   // General module configuration.
   $form['aun_settings'] = array(
     '#type' => 'fieldset',
@@ -86,16 +83,16 @@ function auto_username_configuration() {
   );
 
   $options = array(
-    AUN_PUNCTUATION_REMOVE => t('Remove'), 
-    AUN_PUNCTUATION_REPLACE => t('Replace by separator'), 
-    AUN_PUNCTUATION_DO_NOTHING => t('No action (do not replace)')
+    AUN_PUNCTUATION_REMOVE => t('Remove'),
+    AUN_PUNCTUATION_REPLACE => t('Replace by separator'),
+    AUN_PUNCTUATION_DO_NOTHING => t('No action (do not replace)'),
   );
   $form['punctuation'] = array(
-    '#type' => 'fieldset', 
+    '#type' => 'fieldset',
     '#title' => t('Punctuation settings'),
     '#description' => t('The following replacement rules will be applied to each token.'),
     '#collapsible' => TRUE,
-    '#collapsed' => TRUE
+    '#collapsed' => TRUE,
   );
   foreach (auto_username_punctuation_chars() as $name => $details) {
     $form['punctuation']['aun_punctuation_'. $name] = array(
@@ -116,11 +113,10 @@ function auto_username_configuration() {
   $form['token_help']['help'] = array(
     '#value' => theme('token_help', 'user'),
   );
-  
+
   return system_settings_form($form);
 }
 
-
 /**
  * Implementation of hook_user().
  */
@@ -135,18 +131,19 @@ function auto_username_user($op, &$edit,
       if ($error = user_validate_name($new_name)) {
         form_set_error('name', $error);
       }
-      
+
       // Add a serial to the name for uniqueness.
       $counter = 1;
       $base_name = $new_name;
       while (db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $account->uid, $new_name)) > 0) {
         $new_name = $base_name . $counter++;
       }
-      
       break;
+
     case 'insert':
       db_query("UPDATE {users} SET name='%s' WHERE uid=%d", array($new_name, $account->uid));
       break;
+
     case 'after_update':
       // Only process on update if we're configured to do so.
       // We have to use after_update here instead of the 'update' op because
@@ -164,11 +161,12 @@ function auto_username_user($op, &$edit,
  *
  * @param $account
  *   The user object to process.
+ *
  * @return The new name for the user object.
  */
 function _auto_username_patternprocessor($account) {
   $output = '';
-  // Because token.module doesn't let us escape individual tokens, we have to 
+  // Because token.module doesn't let us escape individual tokens, we have to
   // bypass its normal processing routine.  This pattern is borrowed almost
   // entirely from pathauto.
   $placeholders = auto_username_get_placeholders('user', $account);
@@ -185,14 +183,14 @@ function _auto_username_patternprocessor
 
 /**
  * Get the placeholders to use for string translation.
- * 
+ *
  * This function is largely stolen from pathauto.
  *
  * @param $type
  * @param $object
  */
 function auto_username_get_placeholders($type, $object) {
-  $full = token_get_values($type, $object, TRUE);
+  $full   = token_get_values($type, $object, TRUE);
   $tokens = token_prepare_tokens($full->tokens);
   $values = auto_username_clean_token_values($full);
   return array('tokens' => $tokens, 'values' => $values);
@@ -200,12 +198,12 @@ function auto_username_get_placeholders(
 
 /**
  * Cleans tokens so they are PHP-friendly.
- * 
+ *
  * This function is largely stolen from pathauto.
- * 
+ *
  * @param $values
  *   An array of token values that need to be "cleaned" for use in the URL.
- * 
+ *
  */
 function auto_username_clean_token_values($full) {
   foreach ($full->values as $key => $value) {
@@ -216,11 +214,12 @@ function auto_username_clean_token_value
 
 /**
  * Clean up a string value to have only alphanumeric and separator values.
- * 
+ *
  * This function is largely stolen from pathauto.
- * 
+ *
  * @param $string
  *   A string to clean.
+ *
  * @return
  *   The cleaned string.
  */
@@ -230,12 +229,12 @@ function auto_username_cleanstring($stri
     "a", "an", "as", "at", "before", "but", "by", "for", "from",
     "is", "in", "into", "like", "of", "off", "on", "onto", "per",
     "since", "than", "the", "this", "that", "to", "up", "via",
-    "with"
+    "with",
   );
 
   // Replace or drop punctuation based on user settings.
-  $separator = variable_get('aun_separator', '-');
-  $output = $string;
+  $separator   = variable_get('aun_separator', '-');
+  $output      = $string;
   $punctuation = auto_username_punctuation_chars();
   foreach ($punctuation as $name => $details) {
     $action = variable_get('aun_punctuation_'. $name, 0);
@@ -252,7 +251,7 @@ function auto_username_cleanstring($stri
   }
 
   // Reduce to the subset of ASCII96 letters and numbers
-  if (variable_get('aun_reduce_ascii', FALSE)) { 
+  if (variable_get('aun_reduce_ascii', FALSE)) {
     $pattern = '/[^a-zA-Z0-9\/]+/ ';
     $output = preg_replace($pattern, $separator, $output);
   }
@@ -274,12 +273,12 @@ function auto_username_cleanstring($stri
     $output = preg_replace("/\s+/", $separator, $output);
   }
 
-  // In preparation for pattern matching, 
+  // In preparation for pattern matching,
   // escape the separator if and only if it is not alphanumeric)
   if (isset($separator)) {
-    if (preg_match('/^[^'. PREG_CLASS_ALNUM .']+$/uD',$separator)) {
+    if (preg_match('/^[^'. PREG_CLASS_ALNUM .']+$/uD', $separator)) {
       $seppattern = $separator;
-    } 
+    }
     else {
       $seppattern = '\\'. $separator;
     }
@@ -288,7 +287,6 @@ function auto_username_cleanstring($stri
 
     // Replace multiple separators with a single one
     $output = preg_replace("/$seppattern+/", "$separator", $output);
-
   }
 
 
@@ -314,7 +312,7 @@ function auto_username_form_alter($form_
   }
 
   if ('user_edit' == $form_id) {
-    // The username may not be editable 
+    // The username may not be editable
     if (isset($form['account']['name'])) {
       $form['account']['name'] = array(
         '#type' => 'value',
@@ -324,16 +322,15 @@ function auto_username_form_alter($form_
   }
 }
 
-
 /**
  * Returns an array of arrays for punctuation values keyed by a name.
- * 
+ *
  * Including the value and a textual description
  * Can and should be expanded to include "all" non text punctuation values
- * 
+ *
  * This method is ripped verbatim from pathauto, until this functionality can
  * be pushed down into token.module.
- * 
+ *
  */
 function auto_username_punctuation_chars() {
   $punctuation = array();
@@ -378,10 +375,9 @@ function auto_username_punctuation_chars
 if (!function_exists('profile_token_values')) {
   /**
    * Implementation of hook_token_values()
-   * 
-   * We have to fill in support for profile fields, which by rights should be 
+   *
+   * We have to fill in support for profile fields, which by rights should be
    * in token itself.  Hopefully this can be moved back into token module later.
-   * 
    */
   function profile_token_values($type, $object = NULL, $options = array()) {
     $values = array();
@@ -402,7 +398,7 @@ if (!function_exists('profile_token_valu
           global $user;
           $account = user_load(array('uid' => $user->uid));
         }
-        
+
         $result = db_query("SELECT * FROM {profile_fields} ORDER BY category, weight");
         while ($record = db_fetch_object($result)) {
           $name = isset($account->{$record->name}) ? $account->{$record->name} : '';
@@ -413,11 +409,11 @@ if (!function_exists('profile_token_valu
     }
     return $values;
   }
-  
+
   /**
    * Implementation of hook_token_list()
-   * 
-   * We have to fill in support for profile fields, which by rights should be 
+   *
+   * We have to fill in support for profile fields, which by rights should be
    * in token itself.  Hopefully this can be moved back into token module later.
    */
   function profile_token_list($type = 'all') {
@@ -428,8 +424,9 @@ if (!function_exists('profile_token_valu
         $tokens['user'][$record->name .'-raw'] = $record->title;
         $tokens['user'][$record->name .'-filtered'] = t('@field (filtered)', array('@field' => $record->title));
       }
-      
+
       return $tokens;
     }
   }
 }
+
